From 0d7e7be7481ee0fe077257d48e130b768789a145 Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 5 Sep 2016 16:27:56 +0800 Subject: [PATCH] add option to disable devtools --- atom/browser/api/atom_api_web_contents.cc | 6 ++++++ atom/browser/api/atom_api_web_contents.h | 3 +++ atom/browser/api/atom_api_window.cc | 4 ++++ atom/common/options_switches.cc | 3 +++ atom/common/options_switches.h | 1 + 5 files changed, 17 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index f67926978d16..1defd8308a24 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -290,6 +290,9 @@ WebContents::WebContents(v8::Isolate* isolate, else if (options.Get("offscreen", &b) && b) type_ = OFF_SCREEN; + // Whether to disable DevTools. + options.Get("disableDevTools", &disable_devtools_); + // Obtain the session. std::string partition; mate::Handle session; @@ -940,6 +943,9 @@ void WebContents::OpenDevTools(mate::Arguments* args) { if (type_ == REMOTE) return; + if (disable_devtools_) + return; + std::string state; if (type_ == WEB_VIEW || !owner_window()) { state = "detach"; diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index a4d50efd3da1..5932badba487 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -323,6 +323,9 @@ class WebContents : public mate::TrackableObject, // Whether background throttling is disabled. bool background_throttling_; + // // Whether to disable devtools. + bool disable_devtools_; + DISALLOW_COPY_AND_ASSIGN(WebContents); }; diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 280e2fe414b4..ad551a79e322 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -84,6 +84,10 @@ Window::Window(v8::Isolate* isolate, v8::Local wrapper, if (options.Get("transparent", &transparent)) web_preferences.Set("transparent", transparent); + // Disable WebContents.OpenDevTools() ? + if (options.Get(options::kDisableDevTools, &value)) + web_preferences.Set(options::kDisableDevTools, value); + // Creates the WebContents used by BrowserWindow. auto web_contents = WebContents::Create(isolate, web_preferences); web_contents_.Reset(isolate, web_contents.ToV8()); diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 6b514599f085..8c229e087074 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -96,6 +96,9 @@ const char kNodeIntegration[] = "nodeIntegration"; // Instancd ID of guest WebContents. const char kGuestInstanceID[] = "guestInstanceId"; +// Diable openDevTools. +const char kDisableDevTools[] = "disableDevTools"; + // Web runtime features. const char kExperimentalFeatures[] = "experimentalFeatures"; const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures"; diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 54c638772887..1c0ae9e6b0fe 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -46,6 +46,7 @@ extern const char kBackgroundColor[]; extern const char kHasShadow[]; extern const char kFocusable[]; extern const char kWebPreferences[]; +extern const char kDisableDevTools[]; // WebPreferences. extern const char kZoomFactor[];