Add InspectableWebContentsViewDelegate

This commit is contained in:
Cheng Zhao 2015-06-25 12:29:34 +08:00
parent 9fb30b702a
commit f9dc87ba97
9 changed files with 71 additions and 38 deletions

View file

@ -1,9 +0,0 @@
#include "browser/inspectable_web_contents_delegate.h"
namespace brightray {
gfx::ImageSkia InspectableWebContentsDelegate::GetDevToolsWindowIcon() {
return gfx::ImageSkia();
}
} // namespace brightray

View file

@ -3,34 +3,20 @@
#include <string>
#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

View file

@ -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) {

View file

@ -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

View file

@ -0,0 +1,10 @@
#include "browser/inspectable_web_contents_view_delegate.h"
namespace brightray {
gfx::ImageSkia InspectableWebContentsViewDelegate::GetDevToolsWindowIcon() {
return gfx::ImageSkia();
}
} // namespace brightray

View 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_

View file

@ -3,6 +3,7 @@
#import <AppKit/AppKit.h>
#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() {

View file

@ -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(&params.wm_class_name, &params.wm_class_class);
if (GetDelegate())
GetDelegate()->GetDevToolsWindowWMClass(&params.wm_class_name, &params.wm_class_class);
#endif
devtools_window_->Init(params);

View file

@ -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',