From d9efc3b4bfdb8000ee917b6eaed261d929c0ad48 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 15:12:38 +0800 Subject: [PATCH] Move more methods to CommonWebContentsDelegate --- atom/browser/api/atom_api_web_contents.cc | 16 -------- atom/browser/api/atom_api_web_contents.h | 9 ----- atom/browser/common_web_contents_delegate.cc | 41 ++++++++++++++++++++ atom/browser/common_web_contents_delegate.h | 16 ++++++++ atom/browser/native_window.cc | 39 ------------------- atom/browser/native_window.h | 18 --------- 6 files changed, 57 insertions(+), 82 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 01d96921e06..bc5aba2f36b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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) { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 056e7f3f699..42ce299a462 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -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 web_dialog_helper_; - // Unique ID for a guest WebContents. int guest_instance_id_; diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 2360a9748c6..b1a660444e0 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -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& 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; diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index d383aac1ad0..6366e7410cc 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -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& 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 web_dialog_helper_; scoped_ptr dialog_manager_; // The stored InspectableWebContents object. diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index b286caf6c48..4f3fab7fcf1 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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& 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 diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 841bfe56b52..1726d9d372d 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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& 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 weak_factory_; - scoped_ptr web_dialog_helper_; - DISALLOW_COPY_AND_ASSIGN(NativeWindow); };