From 19ca0117354ed4aa1cf11b8723292ac61358081d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 24 Jun 2015 22:23:38 +0800 Subject: [PATCH] Discard is_guest_, use type_ instead --- atom/browser/api/atom_api_web_contents.cc | 32 +++++++++++++++++----------- atom/browser/api/atom_api_web_contents.h | 1 + atom/browser/common_web_contents_delegate.cc | 10 ++------- atom/browser/common_web_contents_delegate.h | 8 +------ atom/browser/native_window.cc | 3 +-- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 1163820..e5d31d7 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -149,8 +149,7 @@ WebContents::WebContents(brightray::InspectableWebContents* web_contents) } WebContents::WebContents(content::WebContents* web_contents) - : CommonWebContentsDelegate(false), - content::WebContentsObserver(web_contents), + : content::WebContentsObserver(web_contents), guest_opaque_(true), guest_host_(nullptr), auto_size_enabled_(false), @@ -161,8 +160,7 @@ WebContents::WebContents(content::WebContents* web_contents) } WebContents::WebContents(const mate::Dictionary& options) - : CommonWebContentsDelegate(true), - guest_opaque_(true), + : guest_opaque_(true), guest_host_(nullptr), auto_size_enabled_(false), is_full_page_plugin_(false), @@ -235,6 +233,10 @@ content::WebContents* WebContents::OpenURLFromTab( return CommonWebContentsDelegate::OpenURLFromTab(source, params); } +bool WebContents::IsPopupOrPanel(const content::WebContents* source) const { + return type_ == BROWSER_WINDOW; +} + void WebContents::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { @@ -412,7 +414,7 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) { } void WebContents::RenderViewReady() { - if (!is_guest()) + if (type_ != WEB_VIEW) return; // We don't want to accidentally set the opacity of an interstitial page. @@ -466,7 +468,7 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents, } void WebContents::Destroy() { - if (is_guest() && managed_web_contents()) { + if (type_ == WEB_VIEW && managed_web_contents()) { // When force destroying the "destroyed" event is not emitted. WebContentsDestroyed(); @@ -561,10 +563,11 @@ void WebContents::ExecuteJavaScript(const base::string16& code) { } void WebContents::OpenDevTools(mate::Arguments* args) { - if (!inspectable_web_contents()) + if (type_ == REMOTE) return; + bool detach = false; - if (is_guest()) { + if (type_ == WEB_VIEW) { detach = true; } else if (args && args->Length() == 1) { mate::Dictionary options; @@ -575,13 +578,14 @@ void WebContents::OpenDevTools(mate::Arguments* args) { } void WebContents::CloseDevTools() { - if (!inspectable_web_contents()) + if (type_ == REMOTE) return; + inspectable_web_contents()->CloseDevTools(); } bool WebContents::IsDevToolsOpened() { - if (!inspectable_web_contents()) + if (type_ == REMOTE) return false; return inspectable_web_contents()->IsDevToolsViewShowing(); } @@ -594,8 +598,9 @@ void WebContents::ToggleDevTools() { } void WebContents::InspectElement(int x, int y) { - if (!inspectable_web_contents()) + if (type_ == REMOTE) return; + OpenDevTools(nullptr); scoped_refptr agent( content::DevToolsAgentHost::GetOrCreateFor(web_contents())); @@ -603,8 +608,9 @@ void WebContents::InspectElement(int x, int y) { } void WebContents::InspectServiceWorker() { - if (!inspectable_web_contents()) + if (type_ == REMOTE) return; + for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) { if (agent_host->GetType() == content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { @@ -790,7 +796,7 @@ void WebContents::SetAllowTransparency(bool allow) { } bool WebContents::IsGuest() const { - return is_guest(); + return type_ == WEB_VIEW; } mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index d9e1e9c..be874d9 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -164,6 +164,7 @@ class WebContents : public mate::TrackableObject, content::WebContents* OpenURLFromTab( content::WebContents* source, const content::OpenURLParams& params) override; + bool IsPopupOrPanel(const content::WebContents* source) const override; void HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) override; diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 5ab8ed0..d66c7e0 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -107,9 +107,8 @@ void AppendToFile(const base::FilePath& path, } // namespace -CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest) - : is_guest_(is_guest), - owner_window_(nullptr), +CommonWebContentsDelegate::CommonWebContentsDelegate() + : owner_window_(nullptr), html_fullscreen_(false), native_fullscreen_(false) { } @@ -180,11 +179,6 @@ bool CommonWebContentsDelegate::CanOverscrollContent() const { return false; } -bool CommonWebContentsDelegate::IsPopupOrPanel( - const content::WebContents* source) const { - return !is_guest_; -} - content::JavaScriptDialogManager* CommonWebContentsDelegate::GetJavaScriptDialogManager( content::WebContents* source) { diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index a50f428..5f361c0 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -23,7 +23,7 @@ class CommonWebContentsDelegate : public brightray::DefaultWebContentsDelegate, public brightray::InspectableWebContentsDelegate { public: - explicit CommonWebContentsDelegate(bool is_guest); + CommonWebContentsDelegate(); virtual ~CommonWebContentsDelegate(); // Create a InspectableWebContents object and takes onwership of @@ -44,8 +44,6 @@ class CommonWebContentsDelegate return web_contents_.get(); } - bool is_guest() const { return is_guest_; } - protected: // content::WebContentsDelegate: content::WebContents* OpenURLFromTab( @@ -55,7 +53,6 @@ class CommonWebContentsDelegate 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( @@ -92,9 +89,6 @@ class CommonWebContentsDelegate // Set fullscreen mode triggered by html api. void SetHtmlApiFullscreen(bool enter_fullscreen); - // Whether this is guest WebContents or NativeWindow. - const bool is_guest_; - // The window that this WebContents belongs to. NativeWindow* owner_window_; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index e40459e..e635dae 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -85,8 +85,7 @@ std::string RemoveWhitespace(const std::string& str) { NativeWindow::NativeWindow(content::WebContents* web_contents, const mate::Dictionary& options) - : CommonWebContentsDelegate(false), - content::WebContentsObserver(web_contents), + : content::WebContentsObserver(web_contents), has_frame_(true), transparent_(false), enable_larger_than_screen_(false), -- 2.7.4