fix: use context counter as contextId (backport 3-0-x)
For sandboxed renderer it may not have a node::Environment in the context, using a increasing counter as contextId works for all cases.
This commit is contained in:
parent
8d9775b0b1
commit
136cf389e8
10 changed files with 68 additions and 25 deletions
|
@ -79,6 +79,8 @@ void AtomRendererClient::RunScriptsAtDocumentEnd(
|
|||
void AtomRendererClient::DidCreateScriptContext(
|
||||
v8::Handle<v8::Context> context,
|
||||
content::RenderFrame* render_frame) {
|
||||
RendererClientBase::DidCreateScriptContext(context, render_frame);
|
||||
|
||||
// Only allow node integration for the main frame, unless it is a devtools
|
||||
// extension page.
|
||||
if (!render_frame->IsMainFrame() && !IsDevToolsExtension(render_frame))
|
||||
|
|
|
@ -97,7 +97,7 @@ void InitializeBindings(v8::Local<v8::Object> binding,
|
|||
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(switches::kGuestInstanceID))
|
||||
b.Set(options::kGuestInstanceID,
|
||||
command_line->GetSwitchValueASCII(switches::kGuestInstanceID));
|
||||
command_line->GetSwitchValueASCII(switches::kGuestInstanceID));
|
||||
}
|
||||
|
||||
class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver {
|
||||
|
@ -153,6 +153,8 @@ void AtomSandboxedRendererClient::RenderViewCreated(
|
|||
void AtomSandboxedRendererClient::DidCreateScriptContext(
|
||||
v8::Handle<v8::Context> context,
|
||||
content::RenderFrame* render_frame) {
|
||||
RendererClientBase::DidCreateScriptContext(context, render_frame);
|
||||
|
||||
// Only allow preload for the main frame or
|
||||
// For devtools we still want to run the preload_bundle script
|
||||
if (!render_frame->IsMainFrame() && !IsDevTools(render_frame))
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "atom/common/color_util.h"
|
||||
#include "atom/common/context_counter.h"
|
||||
#include "atom/common/native_mate_converters/value_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "atom/renderer/atom_autofill_agent.h"
|
||||
|
@ -17,7 +18,9 @@
|
|||
#include "atom/renderer/guest_view_container.h"
|
||||
#include "atom/renderer/preferences_manager.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/process/process_handle.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "chrome/renderer/media/chrome_key_systems.h"
|
||||
#include "chrome/renderer/pepper/pepper_helper.h"
|
||||
#include "chrome/renderer/printing/print_web_view_helper.h"
|
||||
|
@ -46,6 +49,14 @@
|
|||
#include "atom/common/atom_constants.h"
|
||||
#endif // defined(ENABLE_PDF_VIEWER)
|
||||
|
||||
// This is defined in later versions of Chromium, remove this if you see
|
||||
// compiler complaining duplicate defines.
|
||||
#if defined(OS_WIN) || defined(OS_FUCHSIA)
|
||||
#define CrPRIdPid "ld"
|
||||
#else
|
||||
#define CrPRIdPid "d"
|
||||
#endif
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
@ -80,6 +91,19 @@ RendererClientBase::RendererClientBase() {
|
|||
|
||||
RendererClientBase::~RendererClientBase() {}
|
||||
|
||||
void RendererClientBase::DidCreateScriptContext(
|
||||
v8::Handle<v8::Context> context,
|
||||
content::RenderFrame* render_frame) {
|
||||
// global.setHidden("contextId", `${processId}-${GetNextContextId()}`)
|
||||
std::string context_id = base::StringPrintf(
|
||||
"%" CrPRIdPid "-%d", base::GetCurrentProcId(), GetNextContextId());
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
v8::Local<v8::String> key = mate::StringToSymbol(isolate, "contextId");
|
||||
v8::Local<v8::Private> private_key = v8::Private::ForApi(isolate, key);
|
||||
v8::Local<v8::Value> value = mate::ConvertToV8(isolate, context_id);
|
||||
context->Global()->SetPrivate(context, private_key, value);
|
||||
}
|
||||
|
||||
void RendererClientBase::AddRenderBindings(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Object> binding_object) {
|
||||
|
|
|
@ -21,7 +21,7 @@ class RendererClientBase : public content::ContentRendererClient {
|
|||
~RendererClientBase() override;
|
||||
|
||||
virtual void DidCreateScriptContext(v8::Handle<v8::Context> context,
|
||||
content::RenderFrame* render_frame) = 0;
|
||||
content::RenderFrame* render_frame);
|
||||
virtual void WillReleaseScriptContext(v8::Handle<v8::Context> context,
|
||||
content::RenderFrame* render_frame) = 0;
|
||||
virtual void DidClearWindowObject(content::RenderFrame* render_frame);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue