Merge pull request #7096 from minggo/add-option-to-disable-devtools
add option to disable devtools
This commit is contained in:
commit
4eba8094d4
4 changed files with 20 additions and 3 deletions
|
@ -261,7 +261,8 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||||
embedder_(nullptr),
|
embedder_(nullptr),
|
||||||
type_(REMOTE),
|
type_(REMOTE),
|
||||||
request_id_(0),
|
request_id_(0),
|
||||||
background_throttling_(true) {
|
background_throttling_(true),
|
||||||
|
enable_devtools_(true) {
|
||||||
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
|
||||||
|
|
||||||
Init(isolate);
|
Init(isolate);
|
||||||
|
@ -273,7 +274,8 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||||
: embedder_(nullptr),
|
: embedder_(nullptr),
|
||||||
type_(BROWSER_WINDOW),
|
type_(BROWSER_WINDOW),
|
||||||
request_id_(0),
|
request_id_(0),
|
||||||
background_throttling_(true) {
|
background_throttling_(true),
|
||||||
|
enable_devtools_(true) {
|
||||||
// Read options.
|
// Read options.
|
||||||
options.Get("backgroundThrottling", &background_throttling_);
|
options.Get("backgroundThrottling", &background_throttling_);
|
||||||
|
|
||||||
|
@ -290,6 +292,9 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||||
else if (options.Get("offscreen", &b) && b)
|
else if (options.Get("offscreen", &b) && b)
|
||||||
type_ = OFF_SCREEN;
|
type_ = OFF_SCREEN;
|
||||||
|
|
||||||
|
// Whether to enable DevTools.
|
||||||
|
options.Get("devTools", &enable_devtools_);
|
||||||
|
|
||||||
// Obtain the session.
|
// Obtain the session.
|
||||||
std::string partition;
|
std::string partition;
|
||||||
mate::Handle<api::Session> session;
|
mate::Handle<api::Session> session;
|
||||||
|
@ -940,6 +945,9 @@ void WebContents::OpenDevTools(mate::Arguments* args) {
|
||||||
if (type_ == REMOTE)
|
if (type_ == REMOTE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!enable_devtools_)
|
||||||
|
return;
|
||||||
|
|
||||||
std::string state;
|
std::string state;
|
||||||
if (type_ == WEB_VIEW || !owner_window()) {
|
if (type_ == WEB_VIEW || !owner_window()) {
|
||||||
state = "detach";
|
state = "detach";
|
||||||
|
@ -1006,6 +1014,9 @@ void WebContents::InspectElement(int x, int y) {
|
||||||
if (type_ == REMOTE)
|
if (type_ == REMOTE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!enable_devtools_)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!managed_web_contents()->GetDevToolsWebContents())
|
if (!managed_web_contents()->GetDevToolsWebContents())
|
||||||
OpenDevTools(nullptr);
|
OpenDevTools(nullptr);
|
||||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
scoped_refptr<content::DevToolsAgentHost> agent(
|
||||||
|
@ -1017,6 +1028,9 @@ void WebContents::InspectServiceWorker() {
|
||||||
if (type_ == REMOTE)
|
if (type_ == REMOTE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!enable_devtools_)
|
||||||
|
return;
|
||||||
|
|
||||||
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
||||||
if (agent_host->GetType() ==
|
if (agent_host->GetType() ==
|
||||||
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
||||||
|
|
|
@ -323,6 +323,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
// Whether background throttling is disabled.
|
// Whether background throttling is disabled.
|
||||||
bool background_throttling_;
|
bool background_throttling_;
|
||||||
|
|
||||||
|
// Whether to enable devtools.
|
||||||
|
bool enable_devtools_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
DISALLOW_COPY_AND_ASSIGN(WebContents);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,6 @@ Window::Window(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
|
||||||
v8::Local<v8::Value> transparent;
|
v8::Local<v8::Value> transparent;
|
||||||
if (options.Get("transparent", &transparent))
|
if (options.Get("transparent", &transparent))
|
||||||
web_preferences.Set("transparent", transparent);
|
web_preferences.Set("transparent", transparent);
|
||||||
|
|
||||||
// Creates the WebContents used by BrowserWindow.
|
// Creates the WebContents used by BrowserWindow.
|
||||||
auto web_contents = WebContents::Create(isolate, web_preferences);
|
auto web_contents = WebContents::Create(isolate, web_preferences);
|
||||||
web_contents_.Reset(isolate, web_contents.ToV8());
|
web_contents_.Reset(isolate, web_contents.ToV8());
|
||||||
|
|
|
@ -224,6 +224,7 @@ Possible values of the `titleBarStyle` option are:
|
||||||
|
|
||||||
The `webPreferences` option is an object that can have the following properties:
|
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
|
* `nodeIntegration` Boolean - Whether node integration is enabled. Default
|
||||||
is `true`.
|
is `true`.
|
||||||
* `preload` String - Specifies a script that will be loaded before other
|
* `preload` String - Specifies a script that will be loaded before other
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue