diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index bcf42553e98..ffca4a077ba 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -11,6 +11,7 @@ #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/value_converter.h" #include "base/strings/utf_string_conversions.h" +#include "brightray/browser/inspectable_web_contents.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" @@ -55,9 +56,9 @@ WebContents::WebContents(const mate::Dictionary& options) if (options.Get("isGuest", &is_guest) && is_guest) params.guest_delegate = this; - storage_.reset(content::WebContents::Create(params)); - storage_->SetDelegate(this); - Observe(storage_.get()); + storage_.reset(brightray::InspectableWebContents::Create(params)); + Observe(storage_->GetWebContents()); + web_contents()->SetDelegate(this); } WebContents::~WebContents() { @@ -368,6 +369,19 @@ void WebContents::ExecuteJavaScript(const base::string16& code) { web_contents()->GetMainFrame()->ExecuteJavaScript(code); } +void WebContents::OpenDevTools() { + storage_->SetCanDock(false); + storage_->ShowDevTools(); +} + +void WebContents::CloseDevTools() { + storage_->CloseDevTools(); +} + +bool WebContents::IsDevToolsOpened() { + return storage_->IsDevToolsViewShowing(); +} + bool WebContents::SendIPCMessage(const base::string16& channel, const base::ListValue& args) { return Send(new AtomViewMsg_Message(routing_id(), channel, args)); @@ -442,6 +456,9 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("setAutoSize", &WebContents::SetAutoSize) .SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency) .SetMethod("isGuest", &WebContents::is_guest) + .SetMethod("openDevTools", &WebContents::OpenDevTools) + .SetMethod("closeDevTools", &WebContents::CloseDevTools) + .SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened) .Build()); return mate::ObjectTemplateBuilder( diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 679f0c091df..c29221008c8 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -8,11 +8,16 @@ #include #include "atom/browser/api/event_emitter.h" +#include "brightray/browser/default_web_contents_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_observer.h" #include "native_mate/handle.h" +namespace brightray { +class InspectableWebContents; +} + namespace mate { class Dictionary; } @@ -57,6 +62,9 @@ class WebContents : public mate::EventEmitter, void SetUserAgent(const std::string& user_agent); void InsertCSS(const std::string& css); void ExecuteJavaScript(const base::string16& code); + void OpenDevTools(); + void CloseDevTools(); + bool IsDevToolsOpened(); bool SendIPCMessage(const base::string16& channel, const base::ListValue& args); @@ -175,7 +183,7 @@ class WebContents : public mate::EventEmitter, scoped_ptr extra_params_; // Stores the WebContents that managed by this class. - scoped_ptr storage_; + scoped_ptr storage_; // The WebContents that attaches this guest view. content::WebContents* embedder_web_contents_; diff --git a/atom/common/lib/init.coffee b/atom/common/lib/init.coffee index e3896af8a88..b8d67355c05 100644 --- a/atom/common/lib/init.coffee +++ b/atom/common/lib/init.coffee @@ -1,6 +1,7 @@ -path = require 'path' -timers = require 'timers' -Module = require 'module' +process = global.process +path = require 'path' +timers = require 'timers' +Module = require 'module' process.atomBinding = (name) -> try diff --git a/atom/renderer/lib/init.coffee b/atom/renderer/lib/init.coffee index 69bb0ac7c4d..011720e68b3 100644 --- a/atom/renderer/lib/init.coffee +++ b/atom/renderer/lib/init.coffee @@ -1,6 +1,7 @@ -path = require 'path' -url = require 'url' -Module = require 'module' +process = global.process +path = require 'path' +url = require 'url' +Module = require 'module' # Expose information of current process. process.type = 'renderer' @@ -83,3 +84,5 @@ else # global reference after they are done. process.once 'BIND_DONE', -> delete global.process + delete global.setImmediate + delete global.clearImmediate diff --git a/atom/renderer/lib/web-view.coffee b/atom/renderer/lib/web-view.coffee index 8061f9b049c..781a712a11e 100644 --- a/atom/renderer/lib/web-view.coffee +++ b/atom/renderer/lib/web-view.coffee @@ -517,7 +517,10 @@ registerWebViewElement = -> "isCrashed" "setUserAgent" "executeJavaScript" - "insertCSS" + "insertCSS", + "openDevTools", + "closeDevTools", + "isDevToolsOpened", "send" ] diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 10bc067df4b..7b801d9bd69 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -167,7 +167,19 @@ Injects CSS into guest page. * `code` String -Evaluate `code` in guest page. +Evaluates `code` in guest page. + +### ``.openDevTools() + +Opens a devtools window for guest page. + +### ``.closeDevTools() + +Closes the devtools window of guest page. + +### ``.isDevToolsOpened() + +Returns whether guest page has a devtools window attached. ### ``.send(channel[, args...]) diff --git a/vendor/brightray b/vendor/brightray index b90f13be24a..52b2a6bfac3 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit b90f13be24a006c55b7e1c935be492101ac2736c +Subproject commit 52b2a6bfac3e5e1527c0dcfba6f5a5d2aa6ad9dd