Add InspectableWebContentsDelegate.
This commit is contained in:
parent
967efaad58
commit
e3aaaf2643
5 changed files with 50 additions and 2 deletions
|
@ -43,6 +43,7 @@
|
||||||
'browser/download_manager_delegate.h',
|
'browser/download_manager_delegate.h',
|
||||||
'browser/inspectable_web_contents.cc',
|
'browser/inspectable_web_contents.cc',
|
||||||
'browser/inspectable_web_contents.h',
|
'browser/inspectable_web_contents.h',
|
||||||
|
'browser/inspectable_web_contents_delegate.h',
|
||||||
'browser/inspectable_web_contents_impl.cc',
|
'browser/inspectable_web_contents_impl.cc',
|
||||||
'browser/inspectable_web_contents_impl.h',
|
'browser/inspectable_web_contents_impl.h',
|
||||||
'browser/inspectable_web_contents_view.h',
|
'browser/inspectable_web_contents_view.h',
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
class InspectableWebContentsDelegate;
|
||||||
class InspectableWebContentsView;
|
class InspectableWebContentsView;
|
||||||
|
|
||||||
class InspectableWebContents {
|
class InspectableWebContents {
|
||||||
|
@ -23,6 +24,9 @@ class InspectableWebContents {
|
||||||
|
|
||||||
virtual void ShowDevTools() = 0;
|
virtual void ShowDevTools() = 0;
|
||||||
virtual bool IsDevToolsViewShowing() = 0;
|
virtual bool IsDevToolsViewShowing() = 0;
|
||||||
|
|
||||||
|
// The delegate manages its own life.
|
||||||
|
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
26
brightray/browser/inspectable_web_contents_delegate.h
Normal file
26
brightray/browser/inspectable_web_contents_delegate.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_
|
||||||
|
#define BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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_
|
|
@ -8,6 +8,7 @@
|
||||||
#include "browser/browser_client.h"
|
#include "browser/browser_client.h"
|
||||||
#include "browser/browser_context.h"
|
#include "browser/browser_context.h"
|
||||||
#include "browser/browser_main_parts.h"
|
#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.h"
|
||||||
|
|
||||||
#include "base/prefs/pref_registry_simple.h"
|
#include "base/prefs/pref_registry_simple.h"
|
||||||
|
@ -40,7 +41,8 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) {
|
||||||
|
|
||||||
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
InspectableWebContentsImpl::InspectableWebContentsImpl(
|
||||||
content::WebContents* web_contents)
|
content::WebContents* web_contents)
|
||||||
: web_contents_(web_contents) {
|
: web_contents_(web_contents),
|
||||||
|
delegate_(nullptr) {
|
||||||
auto context = static_cast<BrowserContext*>(
|
auto context = static_cast<BrowserContext*>(
|
||||||
web_contents_->GetBrowserContext());
|
web_contents_->GetBrowserContext());
|
||||||
dock_side_ = context->prefs()->GetString(kDockSidePref);
|
dock_side_ = context->prefs()->GetString(kDockSidePref);
|
||||||
|
@ -92,6 +94,9 @@ void InspectableWebContentsImpl::ShowDevTools() {
|
||||||
std::string());
|
std::string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (delegate_ && delegate_->DevToolsShow(dock_side_))
|
||||||
|
return;
|
||||||
|
|
||||||
view_->SetDockSide(dock_side_);
|
view_->SetDockSide(dock_side_);
|
||||||
view_->ShowDevTools();
|
view_->ShowDevTools();
|
||||||
}
|
}
|
||||||
|
@ -120,8 +125,13 @@ void InspectableWebContentsImpl::MoveWindow(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::SetDockSide(const std::string& side) {
|
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;
|
return;
|
||||||
|
} else if (!view_->SetDockSide(side)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
dock_side_ = side;
|
dock_side_ = side;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ class DevToolsClientHost;
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
class InspectableWebContentsDelegate;
|
||||||
class InspectableWebContentsView;
|
class InspectableWebContentsView;
|
||||||
|
|
||||||
class InspectableWebContentsImpl :
|
class InspectableWebContentsImpl :
|
||||||
|
@ -43,6 +44,10 @@ class InspectableWebContentsImpl :
|
||||||
virtual void ShowDevTools() OVERRIDE;
|
virtual void ShowDevTools() OVERRIDE;
|
||||||
virtual bool IsDevToolsViewShowing() OVERRIDE;
|
virtual bool IsDevToolsViewShowing() OVERRIDE;
|
||||||
|
|
||||||
|
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) {
|
||||||
|
delegate_ = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
content::WebContents* devtools_web_contents() {
|
content::WebContents* devtools_web_contents() {
|
||||||
return devtools_web_contents_.get();
|
return devtools_web_contents_.get();
|
||||||
}
|
}
|
||||||
|
@ -101,6 +106,8 @@ class InspectableWebContentsImpl :
|
||||||
|
|
||||||
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
scoped_ptr<DevToolsEmbedderMessageDispatcher> embedder_message_dispatcher_;
|
||||||
|
|
||||||
|
InspectableWebContentsDelegate* delegate_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl);
|
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue