From e3aaaf2643869f3aac727d61849808f035c215a6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 16:12:02 +0800 Subject: [PATCH] Add InspectableWebContentsDelegate. --- brightray/brightray.gyp | 1 + brightray/browser/inspectable_web_contents.h | 4 +++ .../inspectable_web_contents_delegate.h | 26 +++++++++++++++++++ .../browser/inspectable_web_contents_impl.cc | 14 ++++++++-- .../browser/inspectable_web_contents_impl.h | 7 +++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 brightray/browser/inspectable_web_contents_delegate.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 9504a57786f9..532011bc9558 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -43,6 +43,7 @@ 'browser/download_manager_delegate.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', + 'browser/inspectable_web_contents_delegate.h', 'browser/inspectable_web_contents_impl.cc', 'browser/inspectable_web_contents_impl.h', 'browser/inspectable_web_contents_view.h', diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 49a50bc5079b..b436c391ce30 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -5,6 +5,7 @@ namespace brightray { +class InspectableWebContentsDelegate; class InspectableWebContentsView; class InspectableWebContents { @@ -23,6 +24,9 @@ class InspectableWebContents { virtual void ShowDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; + + // The delegate manages its own life. + virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h new file mode 100644 index 000000000000..7ef79f60e0e3 --- /dev/null +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -0,0 +1,26 @@ +#ifndef BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_ +#define BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_ + +#include + +namespace brightray { + +class InspectableWebContentsDelegate { + public: + virtual ~InspectableWebContentsDelegate() {} + + // Called when the devtools is going to change the dock side, returning true + // to override the default behavior. + // Receiver should set |succeed| to |false| if it failed to handle this. + virtual bool DevToolsSetDockSide(const std::string& side, bool* succeed) { + return false; + } + + // Called when the devtools is going to be showed, returning true to override + // the default behavior. + virtual bool DevToolsShow(const std::string& side) { return false; } +}; + +} // namespace brightray + +#endif // BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_ diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index e972e568735c..cf73a26443d0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -8,6 +8,7 @@ #include "browser/browser_client.h" #include "browser/browser_context.h" #include "browser/browser_main_parts.h" +#include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_view.h" #include "base/prefs/pref_registry_simple.h" @@ -40,7 +41,8 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) - : web_contents_(web_contents) { + : web_contents_(web_contents), + delegate_(nullptr) { auto context = static_cast( web_contents_->GetBrowserContext()); dock_side_ = context->prefs()->GetString(kDockSidePref); @@ -92,6 +94,9 @@ void InspectableWebContentsImpl::ShowDevTools() { std::string()); } + if (delegate_ && delegate_->DevToolsShow(dock_side_)) + return; + view_->SetDockSide(dock_side_); view_->ShowDevTools(); } @@ -120,8 +125,13 @@ void InspectableWebContentsImpl::MoveWindow(int x, int y) { } void InspectableWebContentsImpl::SetDockSide(const std::string& side) { - if (!view_->SetDockSide(side)) + bool succeed = true; + if (delegate_ && delegate_->DevToolsSetDockSide(side, &succeed)) { + if (!succeed) // delegate failed to set dock side. + return; + } else if (!view_->SetDockSide(side)) { return; + } dock_side_ = side; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 53023204dd13..f48f0a47bcb5 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -23,6 +23,7 @@ class DevToolsClientHost; namespace brightray { +class InspectableWebContentsDelegate; class InspectableWebContentsView; class InspectableWebContentsImpl : @@ -43,6 +44,10 @@ class InspectableWebContentsImpl : virtual void ShowDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; + virtual void SetDelegate(InspectableWebContentsDelegate* delegate) { + delegate_ = delegate; + } + content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); } @@ -101,6 +106,8 @@ class InspectableWebContentsImpl : scoped_ptr embedder_message_dispatcher_; + InspectableWebContentsDelegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); };