Add InspectableWebContentsViewDelegate
This commit is contained in:
parent
9fb30b702a
commit
f9dc87ba97
9 changed files with 71 additions and 38 deletions
|
@ -1,9 +0,0 @@
|
||||||
#include "browser/inspectable_web_contents_delegate.h"
|
|
||||||
|
|
||||||
namespace brightray {
|
|
||||||
|
|
||||||
gfx::ImageSkia InspectableWebContentsDelegate::GetDevToolsWindowIcon() {
|
|
||||||
return gfx::ImageSkia();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace brightray
|
|
|
@ -3,34 +3,20 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "ui/gfx/image/image_skia.h"
|
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
class InspectableWebContentsDelegate {
|
class InspectableWebContentsDelegate {
|
||||||
public:
|
public:
|
||||||
virtual ~InspectableWebContentsDelegate() {}
|
virtual ~InspectableWebContentsDelegate() {}
|
||||||
|
|
||||||
// Returns the icon of devtools window.
|
|
||||||
virtual gfx::ImageSkia GetDevToolsWindowIcon();
|
|
||||||
|
|
||||||
// Requested by WebContents of devtools.
|
// Requested by WebContents of devtools.
|
||||||
virtual void DevToolsSaveToFile(
|
virtual void DevToolsSaveToFile(
|
||||||
const std::string& url, const std::string& content, bool save_as) {}
|
const std::string& url, const std::string& content, bool save_as) {}
|
||||||
virtual void DevToolsAppendToFile(
|
virtual void DevToolsAppendToFile(
|
||||||
const std::string& url, const std::string& content) {}
|
const std::string& url, const std::string& content) {}
|
||||||
virtual void DevToolsFocused() {}
|
|
||||||
virtual void DevToolsAddFileSystem() {}
|
virtual void DevToolsAddFileSystem() {}
|
||||||
virtual void DevToolsRemoveFileSystem(
|
virtual void DevToolsRemoveFileSystem(
|
||||||
const std::string& file_system_path) {}
|
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
|
} // namespace brightray
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "browser/browser_main_parts.h"
|
#include "browser/browser_main_parts.h"
|
||||||
#include "browser/inspectable_web_contents_delegate.h"
|
#include "browser/inspectable_web_contents_delegate.h"
|
||||||
#include "browser/inspectable_web_contents_view.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_reader.h"
|
||||||
#include "base/json/json_writer.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 the devtools can dock, "SetIsDocked" will be called by devtools itself.
|
||||||
if (!can_dock_)
|
if (!can_dock_)
|
||||||
SetIsDocked(DispatchCallback(), false);
|
SetIsDocked(DispatchCallback(), false);
|
||||||
|
|
||||||
if (delegate_)
|
|
||||||
delegate_->DevToolsOpened();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) {
|
void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) {
|
||||||
|
@ -510,9 +508,6 @@ void InspectableWebContentsImpl::WebContentsDestroyed() {
|
||||||
|
|
||||||
for (const auto& pair : pending_requests_)
|
for (const auto& pair : pending_requests_)
|
||||||
delete pair.first;
|
delete pair.first;
|
||||||
|
|
||||||
if (delegate_)
|
|
||||||
delegate_->DevToolsClosed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InspectableWebContentsImpl::AddMessageToConsole(
|
bool InspectableWebContentsImpl::AddMessageToConsole(
|
||||||
|
@ -552,8 +547,8 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) {
|
||||||
|
|
||||||
void InspectableWebContentsImpl::WebContentsFocused(
|
void InspectableWebContentsImpl::WebContentsFocused(
|
||||||
content::WebContents* contents) {
|
content::WebContents* contents) {
|
||||||
if (delegate_)
|
if (view_->GetDelegate())
|
||||||
delegate_->DevToolsFocused();
|
view_->GetDelegate()->DevToolsFocused();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) {
|
void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) {
|
||||||
|
|
|
@ -13,10 +13,21 @@ class View;
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
class InspectableWebContentsViewDelegate;
|
||||||
|
|
||||||
class InspectableWebContentsView {
|
class InspectableWebContentsView {
|
||||||
public:
|
public:
|
||||||
|
InspectableWebContentsView() : delegate_(nullptr) {}
|
||||||
virtual ~InspectableWebContentsView() {}
|
virtual ~InspectableWebContentsView() {}
|
||||||
|
|
||||||
|
// The delegate manages its own life.
|
||||||
|
void SetDelegate(InspectableWebContentsViewDelegate* delegate) {
|
||||||
|
delegate_ = delegate;
|
||||||
|
}
|
||||||
|
InspectableWebContentsViewDelegate* GetDelegate() const {
|
||||||
|
return delegate_;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(TOOLKIT_VIEWS)
|
#if defined(TOOLKIT_VIEWS)
|
||||||
// Returns the container control, which has devtools view attached.
|
// Returns the container control, which has devtools view attached.
|
||||||
virtual views::View* GetView() = 0;
|
virtual views::View* GetView() = 0;
|
||||||
|
@ -35,6 +46,9 @@ class InspectableWebContentsView {
|
||||||
virtual void SetIsDocked(bool docked) = 0;
|
virtual void SetIsDocked(bool docked) = 0;
|
||||||
virtual void SetContentsResizingStrategy(
|
virtual void SetContentsResizingStrategy(
|
||||||
const DevToolsContentsResizingStrategy& strategy) = 0;
|
const DevToolsContentsResizingStrategy& strategy) = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
InspectableWebContentsViewDelegate* delegate_; // weak references.
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
10
brightray/browser/inspectable_web_contents_view_delegate.cc
Normal file
10
brightray/browser/inspectable_web_contents_view_delegate.cc
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#include "browser/inspectable_web_contents_view_delegate.h"
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
|
||||||
|
gfx::ImageSkia InspectableWebContentsViewDelegate::GetDevToolsWindowIcon() {
|
||||||
|
return gfx::ImageSkia();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace brightray
|
||||||
|
|
28
brightray/browser/inspectable_web_contents_view_delegate.h
Normal file
28
brightray/browser/inspectable_web_contents_view_delegate.h
Normal file
|
@ -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_
|
|
@ -3,6 +3,7 @@
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
#include "browser/inspectable_web_contents.h"
|
#include "browser/inspectable_web_contents.h"
|
||||||
|
#include "browser/inspectable_web_contents_view_delegate.h"
|
||||||
#import "browser/mac/bry_inspectable_web_contents_view.h"
|
#import "browser/mac/bry_inspectable_web_contents_view.h"
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
@ -26,10 +27,14 @@ gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const {
|
||||||
|
|
||||||
void InspectableWebContentsViewMac::ShowDevTools() {
|
void InspectableWebContentsViewMac::ShowDevTools() {
|
||||||
[view_ setDevToolsVisible:YES];
|
[view_ setDevToolsVisible:YES];
|
||||||
|
if (GetDelegate())
|
||||||
|
GetDelegate()->DevToolsOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsViewMac::CloseDevTools() {
|
void InspectableWebContentsViewMac::CloseDevTools() {
|
||||||
[view_ setDevToolsVisible:NO];
|
[view_ setDevToolsVisible:NO];
|
||||||
|
if (GetDelegate())
|
||||||
|
GetDelegate()->DevToolsClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InspectableWebContentsViewMac::IsDevToolsViewShowing() {
|
bool InspectableWebContentsViewMac::IsDevToolsViewShowing() {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "browser/inspectable_web_contents_delegate.h"
|
#include "browser/inspectable_web_contents_delegate.h"
|
||||||
#include "browser/inspectable_web_contents_impl.h"
|
#include "browser/inspectable_web_contents_impl.h"
|
||||||
|
#include "browser/inspectable_web_contents_view_delegate.h"
|
||||||
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "ui/views/controls/webview/webview.h"
|
#include "ui/views/controls/webview/webview.h"
|
||||||
|
@ -27,9 +28,8 @@ class DevToolsWindowDelegate : public views::ClientView,
|
||||||
// A WidgetDelegate should be deleted on DeleteDelegate.
|
// A WidgetDelegate should be deleted on DeleteDelegate.
|
||||||
set_owned_by_client();
|
set_owned_by_client();
|
||||||
|
|
||||||
InspectableWebContentsDelegate* delegate = shell->inspectable_web_contents()->GetDelegate();
|
if (shell->GetDelegate())
|
||||||
if (delegate)
|
icon_ = shell->GetDelegate()->GetDevToolsWindowIcon();
|
||||||
icon_ = delegate->GetDevToolsWindowIcon();
|
|
||||||
}
|
}
|
||||||
virtual ~DevToolsWindowDelegate() {}
|
virtual ~DevToolsWindowDelegate() {}
|
||||||
|
|
||||||
|
@ -115,6 +115,8 @@ void InspectableWebContentsViewViews::ShowDevTools() {
|
||||||
devtools_web_view_->RequestFocus();
|
devtools_web_view_->RequestFocus();
|
||||||
Layout();
|
Layout();
|
||||||
}
|
}
|
||||||
|
if (GetDelegate())
|
||||||
|
GetDelegate()->DevToolsOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsViewViews::CloseDevTools() {
|
void InspectableWebContentsViewViews::CloseDevTools() {
|
||||||
|
@ -131,6 +133,8 @@ void InspectableWebContentsViewViews::CloseDevTools() {
|
||||||
devtools_web_view_->SetWebContents(NULL);
|
devtools_web_view_->SetWebContents(NULL);
|
||||||
Layout();
|
Layout();
|
||||||
}
|
}
|
||||||
|
if (GetDelegate())
|
||||||
|
GetDelegate()->DevToolsClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InspectableWebContentsViewViews::IsDevToolsViewShowing() {
|
bool InspectableWebContentsViewViews::IsDevToolsViewShowing() {
|
||||||
|
@ -153,9 +157,8 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) {
|
||||||
|
|
||||||
#if defined(USE_X11)
|
#if defined(USE_X11)
|
||||||
params.wm_role_name = "devtools";
|
params.wm_role_name = "devtools";
|
||||||
InspectableWebContentsDelegate* delegate = inspectable_web_contents()->GetDelegate();
|
if (GetDelegate())
|
||||||
if (delegate)
|
GetDelegate()->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class);
|
||||||
delegate->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
devtools_window_->Init(params);
|
devtools_window_->Init(params);
|
||||||
|
|
|
@ -22,8 +22,9 @@
|
||||||
'browser/devtools_ui.h',
|
'browser/devtools_ui.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.cc',
|
|
||||||
'browser/inspectable_web_contents_delegate.h',
|
'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.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',
|
||||||
|
|
Loading…
Reference in a new issue