Skip to content

Commit

Permalink
refactor: implement isRemoteModuleEnabled via getLastWebPreferences()
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Jul 12, 2019
1 parent 3529489 commit 925b131
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lib/browser/rpc-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ const isRemoteModuleEnabledCache = new WeakMap()

const isRemoteModuleEnabled = function (contents) {
if (!isRemoteModuleEnabledCache.has(contents)) {
isRemoteModuleEnabledCache.set(contents, contents._isRemoteModuleEnabled())
const webPreferences = contents.getLastWebPreferences() || {}
isRemoteModuleEnabledCache.set(contents, !!webPreferences.enableRemoteModule)
}

return isRemoteModuleEnabledCache.get(contents)
Expand Down
11 changes: 0 additions & 11 deletions shell/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2231,16 +2231,6 @@ v8::Local<v8::Value> WebContents::GetLastWebPreferences(
return mate::ConvertToV8(isolate, *web_preferences->last_preference());
}

bool WebContents::IsRemoteModuleEnabled() const {
if (web_contents()->GetVisibleURL().SchemeIs("devtools")) {
return false;
}
if (auto* web_preferences = WebContentsPreferences::From(web_contents())) {
return web_preferences->IsRemoteModuleEnabled();
}
return true;
}

v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow() const {
if (owner_window())
return BrowserWindow::From(isolate(), owner_window());
Expand Down Expand Up @@ -2449,7 +2439,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("_getPreloadPaths", &WebContents::GetPreloadPaths)
.SetMethod("getWebPreferences", &WebContents::GetWebPreferences)
.SetMethod("getLastWebPreferences", &WebContents::GetLastWebPreferences)
.SetMethod("_isRemoteModuleEnabled", &WebContents::IsRemoteModuleEnabled)
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
.SetMethod("inspectSharedWorker", &WebContents::InspectSharedWorker)
Expand Down
2 changes: 0 additions & 2 deletions shell/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
v8::Local<v8::Value> GetWebPreferences(v8::Isolate* isolate) const;
v8::Local<v8::Value> GetLastWebPreferences(v8::Isolate* isolate) const;

bool IsRemoteModuleEnabled() const;

// Returns the owner window.
v8::Local<v8::Value> GetOwnerBrowserWindow() const;

Expand Down

0 comments on commit 925b131

Please sign in to comment.