From d1e70e78269987a6b4d930d998e472850783f416 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 14:33:37 +0800 Subject: [PATCH] Add InspectableWebContents::GetDevToolsWebContents --- brightray/browser/inspectable_web_contents.h | 7 ++++--- .../browser/inspectable_web_contents_impl.cc | 18 +++++++++++------- .../browser/inspectable_web_contents_impl.h | 5 +---- .../mac/bry_inspectable_web_contents_view.mm | 12 +++++++----- .../inspectable_web_contents_view_views.cc | 6 ++++-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index dc22a37cada1..edf26ed117d4 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -28,6 +28,7 @@ class InspectableWebContents { virtual InspectableWebContentsView* GetView() const = 0; virtual content::WebContents* GetWebContents() const = 0; + virtual content::WebContents* GetDevToolsWebContents() const = 0; // The delegate manages its own life. virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; @@ -40,9 +41,9 @@ class InspectableWebContents { virtual void AttachTo(const scoped_refptr&) = 0; virtual void Detach() = 0; virtual void CallClientFunction(const std::string& function_name, - const base::Value* arg1, - const base::Value* arg2, - const base::Value* arg3) = 0; + const base::Value* arg1 = nullptr, + const base::Value* arg2 = nullptr, + const base::Value* arg3 = nullptr) = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 3dfffccbfb12..832768a8967e 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -183,6 +183,10 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { return web_contents_.get(); } +content::WebContents* InspectableWebContentsImpl::GetDevToolsWebContents() const { + return devtools_web_contents_.get(); +} + void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) { delegate_ = delegate; } @@ -287,7 +291,7 @@ void InspectableWebContentsImpl::ActivateWindow() { } void InspectableWebContentsImpl::CloseWindow() { - devtools_web_contents()->DispatchBeforeUnload(false); + GetDevToolsWebContents()->DispatchBeforeUnload(false); } void InspectableWebContentsImpl::LoadCompleted() { @@ -362,7 +366,7 @@ void InspectableWebContentsImpl::AppendToFile( } void InspectableWebContentsImpl::RequestFileSystems() { - devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( + GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript( base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); } @@ -398,17 +402,17 @@ void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& mess } void InspectableWebContentsImpl::ZoomIn() { - double level = GetZoomLevelForWebContents(devtools_web_contents()); - SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, false)); + double level = GetZoomLevelForWebContents(GetDevToolsWebContents()); + SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, false)); } void InspectableWebContentsImpl::ZoomOut() { - double level = GetZoomLevelForWebContents(devtools_web_contents()); - SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, true)); + double level = GetZoomLevelForWebContents(GetDevToolsWebContents()); + SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, true)); } void InspectableWebContentsImpl::ResetZoom() { - SetZoomLevelForWebContents(devtools_web_contents(), 0.); + SetZoomLevelForWebContents(GetDevToolsWebContents(), 0.); } void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index cb7738a72b97..d9af6cf12304 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -46,6 +46,7 @@ class InspectableWebContentsImpl : InspectableWebContentsView* GetView() const override; content::WebContents* GetWebContents() const override; + content::WebContents* GetDevToolsWebContents() const override; void SetDelegate(InspectableWebContentsDelegate* delegate) override; InspectableWebContentsDelegate* GetDelegate() const override; @@ -64,10 +65,6 @@ class InspectableWebContentsImpl : gfx::Rect GetDevToolsBounds() const; void SaveDevToolsBounds(const gfx::Rect& bounds); - content::WebContents* devtools_web_contents() { - return devtools_web_contents_.get(); - } - private: // DevToolsEmbedderMessageDispacher::Delegate void ActivateWindow() override; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index bb2e065d3379..7fb76539fc07 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -43,8 +43,9 @@ using namespace brightray; if (visible == devtools_visible_) return; - auto webContents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); - auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + auto inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents(); + auto webContents = inspectable_web_contents->GetWebContents(); + auto devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents(); auto devToolsView = devToolsWebContents->GetNativeView(); if (visible && devtools_docked_) { @@ -92,7 +93,8 @@ using namespace brightray; // Switch to new state. devtools_docked_ = docked; if (!docked) { - auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + auto inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents(); + auto devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents(); auto devToolsView = devToolsWebContents->GetNativeView(); auto styleMask = NSTitledWindowMask | NSClosableWindowMask | @@ -158,7 +160,7 @@ using namespace brightray; - (void)windowDidBecomeMain:(NSNotification*)notification { content::WebContents* web_contents = - inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents(); if (!web_contents) return; @@ -171,7 +173,7 @@ using namespace brightray; - (void)windowDidResignMain:(NSNotification*)notification { content::WebContents* web_contents = - inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents(); if (!web_contents) return; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 05344daf5504..b6079fb9ef69 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -104,12 +104,14 @@ void InspectableWebContentsViewViews::ShowDevTools() { devtools_visible_ = true; if (devtools_window_) { - devtools_window_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); + devtools_window_web_view_->SetWebContents( + inspectable_web_contents_->GetDevToolsWebContents()); devtools_window_->SetBounds(inspectable_web_contents()->GetDevToolsBounds()); devtools_window_->Show(); } else { devtools_web_view_->SetVisible(true); - devtools_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); + devtools_web_view_->SetWebContents( + inspectable_web_contents_->GetDevToolsWebContents()); devtools_web_view_->RequestFocus(); Layout(); }