Fix context menu for sandbox devtools (#11933)
This commit is contained in:
parent
67f052a6e1
commit
9d1527b1df
2 changed files with 26 additions and 15 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include "chrome/renderer/printing/print_web_view_helper.h"
|
#include "chrome/renderer/printing/print_web_view_helper.h"
|
||||||
#include "content/public/renderer/render_frame.h"
|
#include "content/public/renderer/render_frame.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
#include "third_party/WebKit/public/web/WebDocument.h"
|
||||||
#include "third_party/WebKit/public/web/WebKit.h"
|
#include "third_party/WebKit/public/web/WebKit.h"
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
@ -32,6 +33,11 @@ namespace {
|
||||||
const std::string kIpcKey = "ipcNative";
|
const std::string kIpcKey = "ipcNative";
|
||||||
const std::string kModuleCacheKey = "native-module-cache";
|
const std::string kModuleCacheKey = "native-module-cache";
|
||||||
|
|
||||||
|
bool IsDevTools(content::RenderFrame* render_frame) {
|
||||||
|
return render_frame->GetWebFrame()->GetDocument().Url()
|
||||||
|
.ProtocolIs("chrome-devtools");
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Object> GetModuleCache(v8::Isolate* isolate) {
|
v8::Local<v8::Object> GetModuleCache(v8::Isolate* isolate) {
|
||||||
mate::Dictionary global(isolate, isolate->GetCurrentContext()->Global());
|
mate::Dictionary global(isolate, isolate->GetCurrentContext()->Global());
|
||||||
v8::Local<v8::Value> cache;
|
v8::Local<v8::Value> cache;
|
||||||
|
@ -151,15 +157,14 @@ void AtomSandboxedRendererClient::RenderViewCreated(
|
||||||
void AtomSandboxedRendererClient::DidCreateScriptContext(
|
void AtomSandboxedRendererClient::DidCreateScriptContext(
|
||||||
v8::Handle<v8::Context> context, content::RenderFrame* render_frame) {
|
v8::Handle<v8::Context> context, content::RenderFrame* render_frame) {
|
||||||
|
|
||||||
// Only allow preload for the main frame
|
// Only allow preload for the main frame or
|
||||||
if (!render_frame->IsMainFrame())
|
// For devtools we still want to run the preload_bundle script
|
||||||
|
if (!render_frame->IsMainFrame() && !IsDevTools(render_frame))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||||
base::FilePath preload_script_path = command_line->GetSwitchValuePath(
|
base::FilePath preload_script_path = command_line->GetSwitchValuePath(
|
||||||
switches::kPreloadScript);
|
switches::kPreloadScript);
|
||||||
if (preload_script_path.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto isolate = context->GetIsolate();
|
auto isolate = context->GetIsolate();
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
|
|
@ -32,8 +32,6 @@ const preloadModules = new Map([
|
||||||
['timers', require('timers')]
|
['timers', require('timers')]
|
||||||
])
|
])
|
||||||
|
|
||||||
const preloadSrc = fs.readFileSync(preloadPath).toString()
|
|
||||||
|
|
||||||
// Pass different process object to the preload script(which should not have
|
// Pass different process object to the preload script(which should not have
|
||||||
// access to things like `process.atomBinding`).
|
// access to things like `process.atomBinding`).
|
||||||
const preloadProcess = new events.EventEmitter()
|
const preloadProcess = new events.EventEmitter()
|
||||||
|
@ -55,6 +53,11 @@ function preloadRequire (module) {
|
||||||
throw new Error('module not found')
|
throw new Error('module not found')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (window.location.protocol === 'chrome-devtools:') {
|
||||||
|
// Override some inspector APIs.
|
||||||
|
require('../renderer/inspector')
|
||||||
|
}
|
||||||
|
|
||||||
// Wrap the script into a function executed in global scope. It won't have
|
// Wrap the script into a function executed in global scope. It won't have
|
||||||
// access to the current scope, so we'll expose a few objects as arguments:
|
// access to the current scope, so we'll expose a few objects as arguments:
|
||||||
//
|
//
|
||||||
|
@ -74,13 +77,16 @@ function preloadRequire (module) {
|
||||||
// and any `require('electron')` calls in `preload.js` will work as expected
|
// and any `require('electron')` calls in `preload.js` will work as expected
|
||||||
// since browserify won't try to include `electron` in the bundle, falling back
|
// since browserify won't try to include `electron` in the bundle, falling back
|
||||||
// to the `preloadRequire` function above.
|
// to the `preloadRequire` function above.
|
||||||
const preloadWrapperSrc = `(function(require, process, Buffer, global, setImmediate) {
|
if (preloadPath) {
|
||||||
${preloadSrc}
|
const preloadSrc = fs.readFileSync(preloadPath).toString()
|
||||||
})`
|
const preloadWrapperSrc = `(function(require, process, Buffer, global, setImmediate) {
|
||||||
|
${preloadSrc}
|
||||||
|
})`
|
||||||
|
|
||||||
// eval in window scope:
|
// eval in window scope:
|
||||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2
|
// http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2
|
||||||
const geval = eval
|
const geval = eval
|
||||||
const preloadFn = geval(preloadWrapperSrc)
|
const preloadFn = geval(preloadWrapperSrc)
|
||||||
const {setImmediate} = require('timers')
|
const {setImmediate} = require('timers')
|
||||||
preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate)
|
preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue