Grant the devtools access to the extension origins

This commit is contained in:
Kevin Sawicki 2017-06-30 15:47:41 -07:00 committed by Aleksei Kuzmin
parent 4fc2b3e642
commit 34fff57646
3 changed files with 16 additions and 1 deletions

View file

@ -56,6 +56,7 @@
#include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/render_widget_host_view_base.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/view_messages.h" #include "content/common/view_messages.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/favicon_status.h" #include "content/public/browser/favicon_status.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_details.h"
@ -1253,7 +1254,7 @@ void WebContents::HasServiceWorker(
delete this; delete this;
} }
}; };
auto wrapped_callback = new WrappedCallback(callback); auto wrapped_callback = new WrappedCallback(callback);
context->CheckHasServiceWorker( context->CheckHasServiceWorker(
@ -1789,6 +1790,12 @@ v8::Local<v8::Value> WebContents::Debugger(v8::Isolate* isolate) {
return v8::Local<v8::Value>::New(isolate, debugger_); return v8::Local<v8::Value>::New(isolate, debugger_);
} }
void WebContents::GrantOriginAccess(const GURL& url) {
content::ChildProcessSecurityPolicy::GetInstance()->GrantOrigin(
web_contents()->GetMainFrame()->GetProcess()->GetID(),
url::Origin(url));
}
// static // static
void WebContents::BuildPrototype(v8::Isolate* isolate, void WebContents::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) { v8::Local<v8::FunctionTemplate> prototype) {
@ -1883,6 +1890,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
&WebContents::SetWebRTCIPHandlingPolicy) &WebContents::SetWebRTCIPHandlingPolicy)
.SetMethod("getWebRTCIPHandlingPolicy", .SetMethod("getWebRTCIPHandlingPolicy",
&WebContents::GetWebRTCIPHandlingPolicy) &WebContents::GetWebRTCIPHandlingPolicy)
.SetMethod("_grantOriginAccess", &WebContents::GrantOriginAccess)
.SetProperty("id", &WebContents::ID) .SetProperty("id", &WebContents::ID)
.SetProperty("session", &WebContents::Session) .SetProperty("session", &WebContents::Session)
.SetProperty("hostWebContents", &WebContents::HostWebContents) .SetProperty("hostWebContents", &WebContents::HostWebContents)

View file

@ -216,6 +216,10 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Returns the owner window. // Returns the owner window.
v8::Local<v8::Value> GetOwnerBrowserWindow(); v8::Local<v8::Value> GetOwnerBrowserWindow();
// Grants the child process the capability to access URLs with the origin of
// the specified URL.
void GrantOriginAccess(const GURL& url);
// Properties. // Properties.
int32_t ID() const; int32_t ID() const;
v8::Local<v8::Value> Session(v8::Isolate* isolate); v8::Local<v8::Value> Session(v8::Isolate* isolate);

View file

@ -285,6 +285,9 @@ const loadDevToolsExtensions = function (win, manifests) {
manifests.forEach(loadExtension) manifests.forEach(loadExtension)
const extensionInfoArray = manifests.map(manifestToExtensionInfo) const extensionInfoArray = manifests.map(manifestToExtensionInfo)
extensionInfoArray.forEach((extension) => {
win.devToolsWebContents._grantOriginAccess(extension.startPage)
})
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`) win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
} }