Merge pull request #7096 from minggo/add-option-to-disable-devtools

add option to disable devtools
This commit is contained in:
Cheng Zhao 2016-09-13 16:01:56 +09:00 committed by GitHub
commit 4eba8094d4
4 changed files with 20 additions and 3 deletions

View file

@ -261,7 +261,8 @@ WebContents::WebContents(v8::Isolate* isolate,
embedder_(nullptr),
type_(REMOTE),
request_id_(0),
background_throttling_(true) {
background_throttling_(true),
enable_devtools_(true) {
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
Init(isolate);
@ -273,7 +274,8 @@ WebContents::WebContents(v8::Isolate* isolate,
: embedder_(nullptr),
type_(BROWSER_WINDOW),
request_id_(0),
background_throttling_(true) {
background_throttling_(true),
enable_devtools_(true) {
// Read options.
options.Get("backgroundThrottling", &background_throttling_);
@ -290,6 +292,9 @@ WebContents::WebContents(v8::Isolate* isolate,
else if (options.Get("offscreen", &b) && b)
type_ = OFF_SCREEN;
// Whether to enable DevTools.
options.Get("devTools", &enable_devtools_);
// Obtain the session.
std::string partition;
mate::Handle<api::Session> session;
@ -940,6 +945,9 @@ void WebContents::OpenDevTools(mate::Arguments* args) {
if (type_ == REMOTE)
return;
if (!enable_devtools_)
return;
std::string state;
if (type_ == WEB_VIEW || !owner_window()) {
state = "detach";
@ -1006,6 +1014,9 @@ void WebContents::InspectElement(int x, int y) {
if (type_ == REMOTE)
return;
if (!enable_devtools_)
return;
if (!managed_web_contents()->GetDevToolsWebContents())
OpenDevTools(nullptr);
scoped_refptr<content::DevToolsAgentHost> agent(
@ -1017,6 +1028,9 @@ void WebContents::InspectServiceWorker() {
if (type_ == REMOTE)
return;
if (!enable_devtools_)
return;
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
if (agent_host->GetType() ==
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {

View file

@ -323,6 +323,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Whether background throttling is disabled.
bool background_throttling_;
// Whether to enable devtools.
bool enable_devtools_;
DISALLOW_COPY_AND_ASSIGN(WebContents);
};

View file

@ -83,7 +83,6 @@ Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
v8::Local<v8::Value> transparent;
if (options.Get("transparent", &transparent))
web_preferences.Set("transparent", transparent);
// Creates the WebContents used by BrowserWindow.
auto web_contents = WebContents::Create(isolate, web_preferences);
web_contents_.Reset(isolate, web_contents.ToV8());

View file

@ -224,6 +224,7 @@ Possible values of the `titleBarStyle` option are:
The `webPreferences` option is an object that can have the following properties:
* `devTools` Boolean - Whether to enable DevTools. If it is set to `false`, can not use `BrowserWindow.webContents.openDevTools()` to open DevTools. Default is `true`.
* `nodeIntegration` Boolean - Whether node integration is enabled. Default
is `true`.
* `preload` String - Specifies a script that will be loaded before other