Add InspectableWebContents::GetDevToolsWebContents

This commit is contained in:
Cheng Zhao 2015-06-05 14:33:37 +08:00
parent 9ab9b392d6
commit d1e70e7826
5 changed files with 27 additions and 21 deletions

View file

@ -28,6 +28,7 @@ class InspectableWebContents {
virtual InspectableWebContentsView* GetView() const = 0; virtual InspectableWebContentsView* GetView() const = 0;
virtual content::WebContents* GetWebContents() const = 0; virtual content::WebContents* GetWebContents() const = 0;
virtual content::WebContents* GetDevToolsWebContents() const = 0;
// The delegate manages its own life. // The delegate manages its own life.
virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0;
@ -40,9 +41,9 @@ class InspectableWebContents {
virtual void AttachTo(const scoped_refptr<content::DevToolsAgentHost>&) = 0; virtual void AttachTo(const scoped_refptr<content::DevToolsAgentHost>&) = 0;
virtual void Detach() = 0; virtual void Detach() = 0;
virtual void CallClientFunction(const std::string& function_name, virtual void CallClientFunction(const std::string& function_name,
const base::Value* arg1, const base::Value* arg1 = nullptr,
const base::Value* arg2, const base::Value* arg2 = nullptr,
const base::Value* arg3) = 0; const base::Value* arg3 = nullptr) = 0;
}; };
} // namespace brightray } // namespace brightray

View file

@ -183,6 +183,10 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const {
return web_contents_.get(); return web_contents_.get();
} }
content::WebContents* InspectableWebContentsImpl::GetDevToolsWebContents() const {
return devtools_web_contents_.get();
}
void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) { void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) {
delegate_ = delegate; delegate_ = delegate;
} }
@ -287,7 +291,7 @@ void InspectableWebContentsImpl::ActivateWindow() {
} }
void InspectableWebContentsImpl::CloseWindow() { void InspectableWebContentsImpl::CloseWindow() {
devtools_web_contents()->DispatchBeforeUnload(false); GetDevToolsWebContents()->DispatchBeforeUnload(false);
} }
void InspectableWebContentsImpl::LoadCompleted() { void InspectableWebContentsImpl::LoadCompleted() {
@ -362,7 +366,7 @@ void InspectableWebContentsImpl::AppendToFile(
} }
void InspectableWebContentsImpl::RequestFileSystems() { void InspectableWebContentsImpl::RequestFileSystems() {
devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(
base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])"));
} }
@ -398,17 +402,17 @@ void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& mess
} }
void InspectableWebContentsImpl::ZoomIn() { void InspectableWebContentsImpl::ZoomIn() {
double level = GetZoomLevelForWebContents(devtools_web_contents()); double level = GetZoomLevelForWebContents(GetDevToolsWebContents());
SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, false)); SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, false));
} }
void InspectableWebContentsImpl::ZoomOut() { void InspectableWebContentsImpl::ZoomOut() {
double level = GetZoomLevelForWebContents(devtools_web_contents()); double level = GetZoomLevelForWebContents(GetDevToolsWebContents());
SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, true)); SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, true));
} }
void InspectableWebContentsImpl::ResetZoom() { void InspectableWebContentsImpl::ResetZoom() {
SetZoomLevelForWebContents(devtools_web_contents(), 0.); SetZoomLevelForWebContents(GetDevToolsWebContents(), 0.);
} }
void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) { void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) {

View file

@ -46,6 +46,7 @@ class InspectableWebContentsImpl :
InspectableWebContentsView* GetView() const override; InspectableWebContentsView* GetView() const override;
content::WebContents* GetWebContents() const override; content::WebContents* GetWebContents() const override;
content::WebContents* GetDevToolsWebContents() const override;
void SetDelegate(InspectableWebContentsDelegate* delegate) override; void SetDelegate(InspectableWebContentsDelegate* delegate) override;
InspectableWebContentsDelegate* GetDelegate() const override; InspectableWebContentsDelegate* GetDelegate() const override;
@ -64,10 +65,6 @@ class InspectableWebContentsImpl :
gfx::Rect GetDevToolsBounds() const; gfx::Rect GetDevToolsBounds() const;
void SaveDevToolsBounds(const gfx::Rect& bounds); void SaveDevToolsBounds(const gfx::Rect& bounds);
content::WebContents* devtools_web_contents() {
return devtools_web_contents_.get();
}
private: private:
// DevToolsEmbedderMessageDispacher::Delegate // DevToolsEmbedderMessageDispacher::Delegate
void ActivateWindow() override; void ActivateWindow() override;

View file

@ -43,8 +43,9 @@ using namespace brightray;
if (visible == devtools_visible_) if (visible == devtools_visible_)
return; return;
auto webContents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); auto inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents();
auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); auto webContents = inspectable_web_contents->GetWebContents();
auto devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents();
auto devToolsView = devToolsWebContents->GetNativeView(); auto devToolsView = devToolsWebContents->GetNativeView();
if (visible && devtools_docked_) { if (visible && devtools_docked_) {
@ -92,7 +93,8 @@ using namespace brightray;
// Switch to new state. // Switch to new state.
devtools_docked_ = docked; devtools_docked_ = docked;
if (!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 devToolsView = devToolsWebContents->GetNativeView();
auto styleMask = NSTitledWindowMask | NSClosableWindowMask | auto styleMask = NSTitledWindowMask | NSClosableWindowMask |
@ -158,7 +160,7 @@ using namespace brightray;
- (void)windowDidBecomeMain:(NSNotification*)notification { - (void)windowDidBecomeMain:(NSNotification*)notification {
content::WebContents* web_contents = content::WebContents* web_contents =
inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents();
if (!web_contents) if (!web_contents)
return; return;
@ -171,7 +173,7 @@ using namespace brightray;
- (void)windowDidResignMain:(NSNotification*)notification { - (void)windowDidResignMain:(NSNotification*)notification {
content::WebContents* web_contents = content::WebContents* web_contents =
inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents();
if (!web_contents) if (!web_contents)
return; return;

View file

@ -104,12 +104,14 @@ void InspectableWebContentsViewViews::ShowDevTools() {
devtools_visible_ = true; devtools_visible_ = true;
if (devtools_window_) { 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_->SetBounds(inspectable_web_contents()->GetDevToolsBounds());
devtools_window_->Show(); devtools_window_->Show();
} else { } else {
devtools_web_view_->SetVisible(true); 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(); devtools_web_view_->RequestFocus();
Layout(); Layout();
} }