]> khamidou — GitHub mirrors - electron.git/commitdiff
Move more methods to CommonWebContentsDelegate
authorCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 07:12:38 +0000 (15:12 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 07:12:38 +0000 (15:12 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/common_web_contents_delegate.cc
atom/browser/common_web_contents_delegate.h
atom/browser/native_window.cc
atom/browser/native_window.h

index 01d96921e0639930ee5ef064bc593a0b17c937c9..bc5aba2f36b618ca8429dd109a5459557363a2ac 100644 (file)
@@ -9,7 +9,6 @@
 #include "atom/browser/atom_browser_client.h"
 #include "atom/browser/atom_browser_context.h"
 #include "atom/browser/native_window.h"
-#include "atom/browser/web_dialog_helper.h"
 #include "atom/browser/web_view_manager.h"
 #include "atom/common/api/api_messages.h"
 #include "atom/common/native_mate_converters/gfx_converter.h"
@@ -201,21 +200,6 @@ content::WebContents* WebContents::OpenURLFromTab(
   return web_contents();
 }
 
-void WebContents::RunFileChooser(content::WebContents* guest,
-                                 const content::FileChooserParams& params) {
-  if (!web_dialog_helper_)
-    web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest)));
-  web_dialog_helper_->RunFileChooser(guest, params);
-}
-
-void WebContents::EnumerateDirectory(content::WebContents* guest,
-                                     int request_id,
-                                     const base::FilePath& path) {
-  if (!web_dialog_helper_)
-    web_dialog_helper_.reset(new WebDialogHelper(GetWindowFromGuest(guest)));
-  web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
-}
-
 void WebContents::HandleKeyboardEvent(
     content::WebContents* source,
     const content::NativeWebKeyboardEvent& event) {
index 056e7f3f699cfa344184b14259bb997a8f693aef..42ce299a462152870776f57aefa32c55b0cf820b 100644 (file)
@@ -27,8 +27,6 @@ class Dictionary;
 
 namespace atom {
 
-class WebDialogHelper;
-
 namespace api {
 
 // A struct of parameters for SetSize(). The parameters are all declared as
@@ -148,11 +146,6 @@ class WebContents : public mate::EventEmitter,
   content::WebContents* OpenURLFromTab(
       content::WebContents* source,
       const content::OpenURLParams& params) override;
-  void RunFileChooser(content::WebContents* web_contents,
-                      const content::FileChooserParams& params) override;
-  void EnumerateDirectory(content::WebContents* web_contents,
-                          int request_id,
-                          const base::FilePath& path) override;
   void HandleKeyboardEvent(
       content::WebContents* source,
       const content::NativeWebKeyboardEvent& event) override;
@@ -231,8 +224,6 @@ class WebContents : public mate::EventEmitter,
   // Returns the default size of the guestview.
   gfx::Size GetDefaultSize() const;
 
-  scoped_ptr<WebDialogHelper> web_dialog_helper_;
-
   // Unique ID for a guest WebContents.
   int guest_instance_id_;
 
index 2360a9748c64ea1227498cf8ee4dec2b96aeb787..b1a660444e029b92e0e33f37929495313b223fad 100644 (file)
@@ -7,6 +7,8 @@
 #include "atom/browser/atom_javascript_dialog_manager.h"
 #include "atom/browser/native_window.h"
 #include "atom/browser/ui/file_dialog.h"
+#include "atom/browser/web_dialog_helper.h"
+#include "chrome/browser/ui/browser_dialogs.h"
 #include "content/public/browser/child_process_security_policy.h"
 #include "content/public/browser/render_process_host.h"
 #include "content/public/browser/render_view_host.h"
@@ -103,6 +105,22 @@ void CommonWebContentsDelegate::DestroyWebContents() {
   web_contents_.reset();
 }
 
+void CommonWebContentsDelegate::RequestToLockMouse(
+    content::WebContents* web_contents,
+    bool user_gesture,
+    bool last_unlocked_by_target) {
+  GetWebContents()->GotResponseToLockMouseRequest(true);
+}
+
+bool CommonWebContentsDelegate::CanOverscrollContent() const {
+  return false;
+}
+
+bool CommonWebContentsDelegate::IsPopupOrPanel(
+    const content::WebContents* source) const {
+  return !is_guest_;
+}
+
 content::JavaScriptDialogManager*
 CommonWebContentsDelegate::GetJavaScriptDialogManager(
     content::WebContents* source) {
@@ -112,6 +130,29 @@ CommonWebContentsDelegate::GetJavaScriptDialogManager(
   return dialog_manager_.get();
 }
 
+content::ColorChooser* CommonWebContentsDelegate::OpenColorChooser(
+    content::WebContents* web_contents,
+    SkColor color,
+    const std::vector<content::ColorSuggestion>& suggestions) {
+  return chrome::ShowColorChooser(web_contents, color);
+}
+
+void CommonWebContentsDelegate::RunFileChooser(
+    content::WebContents* guest,
+    const content::FileChooserParams& params) {
+  if (!web_dialog_helper_)
+    web_dialog_helper_.reset(new WebDialogHelper(owner_window_));
+  web_dialog_helper_->RunFileChooser(guest, params);
+}
+
+void CommonWebContentsDelegate::EnumerateDirectory(content::WebContents* guest,
+                                                   int request_id,
+                                                   const base::FilePath& path) {
+  if (!web_dialog_helper_)
+    web_dialog_helper_.reset(new WebDialogHelper(owner_window_));
+  web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
+}
+
 content::WebContents* CommonWebContentsDelegate::GetWebContents() const {
   if (!web_contents_)
     return nullptr;
index d383aac1ad008387707d508c49ffc5ab5a10bb91..6366e7410ccd1cd8dd6106af9f3285cb27b062a1 100644 (file)
@@ -15,6 +15,7 @@ namespace atom {
 
 class AtomJavaScriptDialogManager;
 class NativeWindow;
+class WebDialogHelper;
 
 class CommonWebContentsDelegate
     : public brightray::DefaultWebContentsDelegate,
@@ -45,8 +46,22 @@ class CommonWebContentsDelegate
 
  protected:
   // content::WebContentsDelegate:
+  void RequestToLockMouse(content::WebContents* web_contents,
+                          bool user_gesture,
+                          bool last_unlocked_by_target) override;
+  bool CanOverscrollContent() const override;
+  bool IsPopupOrPanel(const content::WebContents* source) const override;
   content::JavaScriptDialogManager* GetJavaScriptDialogManager(
       content::WebContents* source) override;
+  content::ColorChooser* OpenColorChooser(
+      content::WebContents* web_contents,
+      SkColor color,
+      const std::vector<content::ColorSuggestion>& suggestions) override;
+  void RunFileChooser(content::WebContents* web_contents,
+                      const content::FileChooserParams& params) override;
+  void EnumerateDirectory(content::WebContents* web_contents,
+                          int request_id,
+                          const base::FilePath& path) override;
 
   // brightray::InspectableWebContentsDelegate:
   void DevToolsSaveToFile(const std::string& url,
@@ -64,6 +79,7 @@ class CommonWebContentsDelegate
   // The window that this WebContents belongs to.
   NativeWindow* owner_window_;
 
+  scoped_ptr<WebDialogHelper> web_dialog_helper_;
   scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
 
   // The stored InspectableWebContents object.
index b286caf6c480f46b770d0ea4fa3ec34b8ad281fc..4f3fab7fcf10e6d50ba55e49b0084bd504a97136 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "atom/browser/atom_browser_context.h"
 #include "atom/browser/browser.h"
-#include "atom/browser/web_dialog_helper.h"
 #include "atom/browser/window_list.h"
 #include "atom/common/api/api_messages.h"
 #include "atom/common/atom_version.h"
@@ -29,7 +28,6 @@
 #include "brightray/browser/inspectable_web_contents.h"
 #include "brightray/browser/inspectable_web_contents_view.h"
 #include "chrome/browser/printing/print_view_manager_basic.h"
-#include "chrome/browser/ui/browser_dialogs.h"
 #include "content/browser/renderer_host/render_widget_host_impl.h"
 #include "content/public/browser/devtools_agent_host.h"
 #include "content/public/browser/invalidate_type.h"
@@ -637,38 +635,6 @@ void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
   }
 }
 
-content::ColorChooser* NativeWindow::OpenColorChooser(
-    content::WebContents* web_contents,
-    SkColor color,
-    const std::vector<content::ColorSuggestion>& suggestions) {
-  return chrome::ShowColorChooser(web_contents, color);
-}
-
-void NativeWindow::RunFileChooser(content::WebContents* web_contents,
-                                  const content::FileChooserParams& params) {
-  if (!web_dialog_helper_)
-    web_dialog_helper_.reset(new WebDialogHelper(this));
-  web_dialog_helper_->RunFileChooser(web_contents, params);
-}
-
-void NativeWindow::EnumerateDirectory(content::WebContents* web_contents,
-                                      int request_id,
-                                      const base::FilePath& path) {
-  if (!web_dialog_helper_)
-    web_dialog_helper_.reset(new WebDialogHelper(this));
-  web_dialog_helper_->EnumerateDirectory(web_contents, request_id, path);
-}
-
-void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
-                                      bool user_gesture,
-                                      bool last_unlocked_by_target) {
-  GetWebContents()->GotResponseToLockMouseRequest(true);
-}
-
-bool NativeWindow::CanOverscrollContent() const {
-  return false;
-}
-
 void NativeWindow::ActivateContents(content::WebContents* contents) {
   FocusOnWebView();
 }
@@ -697,11 +663,6 @@ void NativeWindow::CloseContents(content::WebContents* source) {
   window_unresposive_closure_.Cancel();
 }
 
-bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
-  // Only popup window can use things like window.moveTo.
-  return true;
-}
-
 void NativeWindow::RendererUnresponsive(content::WebContents* source) {
   // Schedule the unresponsive shortly later, since we may receive the
   // responsive event soon. This could happen after the whole application had
index 841bfe56b52ba3c1fd74b5d7415a3000ebb58908..1726d9d372d9792838024613c970da7ff0bb3f75 100644 (file)
@@ -49,7 +49,6 @@ class MenuModel;
 namespace atom {
 
 struct DraggableRegion;
-class WebDialogHelper;
 
 class NativeWindow : public CommonWebContentsDelegate,
                      public content::WebContentsObserver,
@@ -245,26 +244,11 @@ class NativeWindow : public CommonWebContentsDelegate,
   void BeforeUnloadFired(content::WebContents* tab,
                          bool proceed,
                          bool* proceed_to_fire_unload) override;
-  content::ColorChooser* OpenColorChooser(
-      content::WebContents* web_contents,
-      SkColor color,
-      const std::vector<content::ColorSuggestion>& suggestions) override;
-  void RunFileChooser(content::WebContents* web_contents,
-                      const content::FileChooserParams& params) override;
-  void EnumerateDirectory(content::WebContents* web_contents,
-                          int request_id,
-                          const base::FilePath& path) override;
-  void RequestToLockMouse(content::WebContents* web_contents,
-                          bool user_gesture,
-                          bool last_unlocked_by_target) override;
-  bool CanOverscrollContent() const override;
   void ActivateContents(content::WebContents* contents) override;
   void DeactivateContents(content::WebContents* contents) override;
   void MoveContents(content::WebContents* source,
                     const gfx::Rect& pos) override;
   void CloseContents(content::WebContents* source) override;
-  bool IsPopupOrPanel(
-      const content::WebContents* source) const override;
   void RendererUnresponsive(content::WebContents* source) override;
   void RendererResponsive(content::WebContents* source) override;
   void EnterFullscreenModeForTab(content::WebContents* source,
@@ -346,8 +330,6 @@ class NativeWindow : public CommonWebContentsDelegate,
 
   base::WeakPtrFactory<NativeWindow> weak_factory_;
 
-  scoped_ptr<WebDialogHelper> web_dialog_helper_;
-
   DISALLOW_COPY_AND_ASSIGN(NativeWindow);
 };