Merge branch 'webview-devtools' of https://github.com/project-infinium/atom-shell into project-infinium-webview-devtools
This commit is contained in:
commit
cf9f249f07
4 changed files with 39 additions and 1 deletions
|
@ -10,6 +10,9 @@
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "atom/common/native_mate_converters/string16_converter.h"
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
|
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||||
|
#include "brightray/browser/inspectable_web_contents.h"
|
||||||
|
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "content/public/browser/render_frame_host.h"
|
#include "content/public/browser/render_frame_host.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
|
@ -58,6 +61,9 @@ WebContents::WebContents(const mate::Dictionary& options)
|
||||||
storage_.reset(content::WebContents::Create(params));
|
storage_.reset(content::WebContents::Create(params));
|
||||||
storage_->SetDelegate(this);
|
storage_->SetDelegate(this);
|
||||||
Observe(storage_.get());
|
Observe(storage_.get());
|
||||||
|
|
||||||
|
inspectable_web_contents_.reset(
|
||||||
|
brightray::InspectableWebContents::Create(storage_.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents::~WebContents() {
|
WebContents::~WebContents() {
|
||||||
|
@ -368,6 +374,13 @@ void WebContents::ExecuteJavaScript(const base::string16& code) {
|
||||||
web_contents()->GetMainFrame()->ExecuteJavaScript(code);
|
web_contents()->GetMainFrame()->ExecuteJavaScript(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::OpenDevTools() {
|
||||||
|
inspectable_web_contents()->ShowDevTools();
|
||||||
|
|
||||||
|
// force the inspectable web contents to be undocked when it is opened.
|
||||||
|
inspectable_web_contents()->GetView()->SetIsDocked(false);
|
||||||
|
}
|
||||||
|
|
||||||
bool WebContents::SendIPCMessage(const base::string16& channel,
|
bool WebContents::SendIPCMessage(const base::string16& channel,
|
||||||
const base::ListValue& args) {
|
const base::ListValue& args) {
|
||||||
return Send(new AtomViewMsg_Message(routing_id(), channel, args));
|
return Send(new AtomViewMsg_Message(routing_id(), channel, args));
|
||||||
|
@ -442,6 +455,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
.SetMethod("setAutoSize", &WebContents::SetAutoSize)
|
.SetMethod("setAutoSize", &WebContents::SetAutoSize)
|
||||||
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
|
||||||
.SetMethod("isGuest", &WebContents::is_guest)
|
.SetMethod("isGuest", &WebContents::is_guest)
|
||||||
|
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
||||||
.Build());
|
.Build());
|
||||||
|
|
||||||
return mate::ObjectTemplateBuilder(
|
return mate::ObjectTemplateBuilder(
|
||||||
|
|
|
@ -11,12 +11,20 @@
|
||||||
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
#include "content/public/browser/browser_plugin_guest_delegate.h"
|
||||||
#include "content/public/browser/web_contents_delegate.h"
|
#include "content/public/browser/web_contents_delegate.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
|
#include "brightray/browser/default_web_contents_delegate.h"
|
||||||
|
#include "brightray/browser/inspectable_web_contents_delegate.h"
|
||||||
|
#include "brightray/browser/inspectable_web_contents_impl.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
class InspectableWebContents;
|
||||||
|
class InspectableWebContentsImpl;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
@ -57,6 +65,7 @@ class WebContents : public mate::EventEmitter,
|
||||||
void SetUserAgent(const std::string& user_agent);
|
void SetUserAgent(const std::string& user_agent);
|
||||||
void InsertCSS(const std::string& css);
|
void InsertCSS(const std::string& css);
|
||||||
void ExecuteJavaScript(const base::string16& code);
|
void ExecuteJavaScript(const base::string16& code);
|
||||||
|
void OpenDevTools();
|
||||||
bool SendIPCMessage(const base::string16& channel,
|
bool SendIPCMessage(const base::string16& channel,
|
||||||
const base::ListValue& args);
|
const base::ListValue& args);
|
||||||
|
|
||||||
|
@ -83,6 +92,11 @@ class WebContents : public mate::EventEmitter,
|
||||||
explicit WebContents(const mate::Dictionary& options);
|
explicit WebContents(const mate::Dictionary& options);
|
||||||
~WebContents();
|
~WebContents();
|
||||||
|
|
||||||
|
brightray::InspectableWebContentsImpl* inspectable_web_contents() const {
|
||||||
|
return static_cast<brightray::InspectableWebContentsImpl*>(
|
||||||
|
inspectable_web_contents_.get());
|
||||||
|
}
|
||||||
|
|
||||||
// mate::Wrappable:
|
// mate::Wrappable:
|
||||||
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
v8::Isolate* isolate) override;
|
v8::Isolate* isolate) override;
|
||||||
|
@ -180,6 +194,11 @@ class WebContents : public mate::EventEmitter,
|
||||||
// The WebContents that attaches this guest view.
|
// The WebContents that attaches this guest view.
|
||||||
content::WebContents* embedder_web_contents_;
|
content::WebContents* embedder_web_contents_;
|
||||||
|
|
||||||
|
// Notice that inspectable_web_contents_ must be placed after dialog_manager_,
|
||||||
|
// so we can make sure inspectable_web_contents_ is destroyed before
|
||||||
|
// dialog_manager_, otherwise a crash would happen.
|
||||||
|
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
||||||
|
|
||||||
// The size of the container element.
|
// The size of the container element.
|
||||||
gfx::Size element_size_;
|
gfx::Size element_size_;
|
||||||
|
|
||||||
|
|
|
@ -517,7 +517,8 @@ registerWebViewElement = ->
|
||||||
"isCrashed"
|
"isCrashed"
|
||||||
"setUserAgent"
|
"setUserAgent"
|
||||||
"executeJavaScript"
|
"executeJavaScript"
|
||||||
"insertCSS"
|
"insertCSS",
|
||||||
|
"openDevTools",
|
||||||
"send"
|
"send"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,10 @@ Injects CSS into guest page.
|
||||||
|
|
||||||
Evaluate `code` in guest page.
|
Evaluate `code` in guest page.
|
||||||
|
|
||||||
|
### `<webview>`.openDevTools()
|
||||||
|
|
||||||
|
Open a devtools instance for the webview's contents.
|
||||||
|
|
||||||
### `<webview>`.send(channel[, args...])
|
### `<webview>`.send(channel[, args...])
|
||||||
|
|
||||||
* `channel` String
|
* `channel` String
|
||||||
|
|
Loading…
Reference in a new issue