From 4ebe58df572897fe8d14397d069095445457a5d7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 3 Nov 2014 22:12:56 +0800 Subject: [PATCH] Also add closeDevTools and isDevToolsOpened for webview --- atom/browser/api/atom_api_web_contents.cc | 13 +++++++++++-- atom/browser/api/atom_api_web_contents.h | 12 +++++++----- atom/renderer/lib/web-view.coffee | 2 ++ docs/api/web-view-tag.md | 12 ++++++++++-- vendor/brightray | 2 +- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 6feb0fb1368..ffca4a077ba 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -10,9 +10,8 @@ #include "atom/common/native_mate_converters/gurl_converter.h" #include "atom/common/native_mate_converters/string16_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 "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" @@ -375,6 +374,14 @@ void WebContents::OpenDevTools() { 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)); @@ -450,6 +457,8 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .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 f8f6de9e7fd..c29221008c8 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -8,20 +8,20 @@ #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 "brightray/browser/default_web_contents_delegate.h" #include "native_mate/handle.h" -namespace mate { -class Dictionary; -} - namespace brightray { class InspectableWebContents; } +namespace mate { +class Dictionary; +} + namespace atom { namespace api { @@ -63,6 +63,8 @@ class WebContents : public mate::EventEmitter, 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); diff --git a/atom/renderer/lib/web-view.coffee b/atom/renderer/lib/web-view.coffee index e198c2b820f..781a712a11e 100644 --- a/atom/renderer/lib/web-view.coffee +++ b/atom/renderer/lib/web-view.coffee @@ -519,6 +519,8 @@ registerWebViewElement = -> "executeJavaScript" "insertCSS", "openDevTools", + "closeDevTools", + "isDevToolsOpened", "send" ] diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 55c524b0d9e..7b801d9bd69 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -167,11 +167,19 @@ Injects CSS into guest page. * `code` String -Evaluate `code` in guest page. +Evaluates `code` in guest page. ### ``.openDevTools() -Open a devtools instance for the webview's contents. +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 90d2649bdd0..52b2a6bfac3 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 90d2649bdd02ac544c79dc24802f7914370e833a +Subproject commit 52b2a6bfac3e5e1527c0dcfba6f5a5d2aa6ad9dd