diff --git a/brightray/browser/inspectable_web_contents_delegate.cc b/brightray/browser/inspectable_web_contents_delegate.cc deleted file mode 100644 index 81d395b5db37..000000000000 --- a/brightray/browser/inspectable_web_contents_delegate.cc +++ /dev/null @@ -1,9 +0,0 @@ -#include "browser/inspectable_web_contents_delegate.h" - -namespace brightray { - -gfx::ImageSkia InspectableWebContentsDelegate::GetDevToolsWindowIcon() { - return gfx::ImageSkia(); -} - -} // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index b193bd459dd0..606bfa9a4ea9 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -3,34 +3,20 @@ #include -#include "ui/gfx/image/image_skia.h" - namespace brightray { class InspectableWebContentsDelegate { public: virtual ~InspectableWebContentsDelegate() {} - // Returns the icon of devtools window. - virtual gfx::ImageSkia GetDevToolsWindowIcon(); - // Requested by WebContents of devtools. virtual void DevToolsSaveToFile( const std::string& url, const std::string& content, bool save_as) {} virtual void DevToolsAppendToFile( const std::string& url, const std::string& content) {} - virtual void DevToolsFocused() {} virtual void DevToolsAddFileSystem() {} virtual void DevToolsRemoveFileSystem( const std::string& file_system_path) {} - virtual void DevToolsOpened() {} - virtual void DevToolsClosed() {} - -#if defined(USE_X11) - // Called when creating devtools window. - virtual void GetDevToolsWindowWMClass( - std::string* name, std::string* class_name) {} -#endif }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f196efa0248c..fa62d3d202a6 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -10,6 +10,7 @@ #include "browser/browser_main_parts.h" #include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_view.h" +#include "browser/inspectable_web_contents_view_delegate.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" @@ -302,9 +303,6 @@ void InspectableWebContentsImpl::LoadCompleted() { // If the devtools can dock, "SetIsDocked" will be called by devtools itself. if (!can_dock_) SetIsDocked(DispatchCallback(), false); - - if (delegate_) - delegate_->DevToolsOpened(); } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { @@ -510,9 +508,6 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { for (const auto& pair : pending_requests_) delete pair.first; - - if (delegate_) - delegate_->DevToolsClosed(); } bool InspectableWebContentsImpl::AddMessageToConsole( @@ -552,8 +547,8 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { void InspectableWebContentsImpl::WebContentsFocused( content::WebContents* contents) { - if (delegate_) - delegate_->DevToolsFocused(); + if (view_->GetDelegate()) + view_->GetDelegate()->DevToolsFocused(); } void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 1675ec73688a..31c30e1f3286 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -13,10 +13,21 @@ class View; namespace brightray { +class InspectableWebContentsViewDelegate; + class InspectableWebContentsView { public: + InspectableWebContentsView() : delegate_(nullptr) {} virtual ~InspectableWebContentsView() {} + // The delegate manages its own life. + void SetDelegate(InspectableWebContentsViewDelegate* delegate) { + delegate_ = delegate; + } + InspectableWebContentsViewDelegate* GetDelegate() const { + return delegate_; + } + #if defined(TOOLKIT_VIEWS) // Returns the container control, which has devtools view attached. virtual views::View* GetView() = 0; @@ -35,6 +46,9 @@ class InspectableWebContentsView { virtual void SetIsDocked(bool docked) = 0; virtual void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) = 0; + + private: + InspectableWebContentsViewDelegate* delegate_; // weak references. }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_view_delegate.cc b/brightray/browser/inspectable_web_contents_view_delegate.cc new file mode 100644 index 000000000000..5906499da8c4 --- /dev/null +++ b/brightray/browser/inspectable_web_contents_view_delegate.cc @@ -0,0 +1,10 @@ +#include "browser/inspectable_web_contents_view_delegate.h" + +namespace brightray { + +gfx::ImageSkia InspectableWebContentsViewDelegate::GetDevToolsWindowIcon() { + return gfx::ImageSkia(); +} + +} // namespace brightray + diff --git a/brightray/browser/inspectable_web_contents_view_delegate.h b/brightray/browser/inspectable_web_contents_view_delegate.h new file mode 100644 index 000000000000..900857c7a108 --- /dev/null +++ b/brightray/browser/inspectable_web_contents_view_delegate.h @@ -0,0 +1,28 @@ +#ifndef BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_DELEGATE_H_ +#define BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_DELEGATE_H_ + +#include "ui/gfx/image/image_skia.h" + +namespace brightray { + +class InspectableWebContentsViewDelegate { + public: + virtual ~InspectableWebContentsViewDelegate() {} + + virtual void DevToolsFocused() {} + virtual void DevToolsOpened() {} + virtual void DevToolsClosed() {} + + // Returns the icon of devtools window. + virtual gfx::ImageSkia GetDevToolsWindowIcon(); + +#if defined(USE_X11) + // Called when creating devtools window. + virtual void GetDevToolsWindowWMClass( + std::string* name, std::string* class_name) {} +#endif +}; + +} // namespace brightray + +#endif // BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_DELEGATE_H_ diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index aeca189b7967..6cd08da2f6aa 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -3,6 +3,7 @@ #import #include "browser/inspectable_web_contents.h" +#include "browser/inspectable_web_contents_view_delegate.h" #import "browser/mac/bry_inspectable_web_contents_view.h" namespace brightray { @@ -26,10 +27,14 @@ gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const { void InspectableWebContentsViewMac::ShowDevTools() { [view_ setDevToolsVisible:YES]; + if (GetDelegate()) + GetDelegate()->DevToolsOpened(); } void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; + if (GetDelegate()) + GetDelegate()->DevToolsClosed(); } bool InspectableWebContentsViewMac::IsDevToolsViewShowing() { diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index b6079fb9ef69..52528efba7fa 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -2,6 +2,7 @@ #include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/inspectable_web_contents_view_delegate.h" #include "base/strings/utf_string_conversions.h" #include "ui/views/controls/webview/webview.h" @@ -27,9 +28,8 @@ class DevToolsWindowDelegate : public views::ClientView, // A WidgetDelegate should be deleted on DeleteDelegate. set_owned_by_client(); - InspectableWebContentsDelegate* delegate = shell->inspectable_web_contents()->GetDelegate(); - if (delegate) - icon_ = delegate->GetDevToolsWindowIcon(); + if (shell->GetDelegate()) + icon_ = shell->GetDelegate()->GetDevToolsWindowIcon(); } virtual ~DevToolsWindowDelegate() {} @@ -115,6 +115,8 @@ void InspectableWebContentsViewViews::ShowDevTools() { devtools_web_view_->RequestFocus(); Layout(); } + if (GetDelegate()) + GetDelegate()->DevToolsOpened(); } void InspectableWebContentsViewViews::CloseDevTools() { @@ -131,6 +133,8 @@ void InspectableWebContentsViewViews::CloseDevTools() { devtools_web_view_->SetWebContents(NULL); Layout(); } + if (GetDelegate()) + GetDelegate()->DevToolsClosed(); } bool InspectableWebContentsViewViews::IsDevToolsViewShowing() { @@ -153,9 +157,8 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { #if defined(USE_X11) params.wm_role_name = "devtools"; - InspectableWebContentsDelegate* delegate = inspectable_web_contents()->GetDelegate(); - if (delegate) - delegate->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class); + if (GetDelegate()) + GetDelegate()->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class); #endif devtools_window_->Init(params); diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index fda1bb8d1eff..8334e44cd5e8 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -22,8 +22,9 @@ 'browser/devtools_ui.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', - 'browser/inspectable_web_contents_delegate.cc', 'browser/inspectable_web_contents_delegate.h', + 'browser/inspectable_web_contents_view_delegate.cc', + 'browser/inspectable_web_contents_view_delegate.h', 'browser/inspectable_web_contents_impl.cc', 'browser/inspectable_web_contents_impl.h', 'browser/inspectable_web_contents_view.h',