Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Unified Diff: third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.cpp

Issue 2005433002: [Origin Trials] Install origin trial bindings on V8 context conditionally (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@track-ef-install
Patch Set: Switch to using ScriptState instead of explicit context/world Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.cpp
diff --git a/third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.cpp b/third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.cpp
index c40d500d2c139b046667da9014bfb1ddd2a59e58..de7ee0ea291cad15c7817ad077c42947d5e692ee 100644
--- a/third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.cpp
+++ b/third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.cpp
@@ -36,16 +36,22 @@
#include "bindings/core/v8/V8Uint8Array.h"
#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
#include "bindings/modules/v8/ToV8ForModules.h"
+#include "bindings/modules/v8/V8DedicatedWorkerGlobalScopePartial.h"
#include "bindings/modules/v8/V8IDBCursor.h"
#include "bindings/modules/v8/V8IDBCursorWithValue.h"
#include "bindings/modules/v8/V8IDBDatabase.h"
#include "bindings/modules/v8/V8IDBIndex.h"
#include "bindings/modules/v8/V8IDBKeyRange.h"
#include "bindings/modules/v8/V8IDBObjectStore.h"
+#include "bindings/modules/v8/V8NavigatorPartial.h"
+#include "bindings/modules/v8/V8ServiceWorkerGlobalScope.h"
+#include "bindings/modules/v8/V8SharedWorkerGlobalScopePartial.h"
+#include "bindings/modules/v8/V8WindowPartial.h"
#include "bindings/modules/v8/V8WorkletGlobalScope.h"
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/DOMArrayBufferView.h"
#include "core/dom/ExecutionContext.h"
+#include "core/origin_trials/OriginTrialContext.h"
#include "modules/indexeddb/IDBKey.h"
#include "modules/indexeddb/IDBKeyPath.h"
#include "modules/indexeddb/IDBKeyRange.h"
@@ -532,4 +538,53 @@ ExecutionContext* toExecutionContextForModules(v8::Local<v8::Context> context)
return nullptr;
}
+namespace {
+initializeOriginTrialsFunction s_originalInitializeOriginTrialsFunction = nullptr;
+}
+
+void initializeOriginTrialsForModules(ScriptState* scriptState)
+{
+ // TODO(iclelland): Generate all of this logic at compile-time, based on the
+ // configuration of origin trial enabled attibutes and interfaces in IDL
+ // files. (crbug.com/615060)
+ (*s_originalInitializeOriginTrialsFunction)(scriptState);
+
+ v8::Local<v8::Context> context = scriptState->context();
+ ExecutionContext* executionContext = toExecutionContext(context);
+ OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext, OriginTrialContext::DontCreateIfNotExists);
+ if (!originTrialContext)
+ return;
+
+ ScriptState::Scope scope(scriptState);
+ v8::Local<v8::Object> global = context->Global();
+ v8::Isolate* isolate = scriptState->isolate();
+ const DOMWrapperWorld& world = scriptState->world();
+ // TODO(iclelland): This is a placeholder for the real interface object,
+ // which we don't try to obtain at this time. (An assertion in the bindings
+ // generation code prevents it from actually being used.) It should be
+ // replaced with the actual interface if possible, in order to allow origin
+ // trials on static attributes. (crbug.com/614352)
haraken 2016/05/27 22:25:17 At which point is the placeholder (i.e., |interfac
iclelland 2016/05/30 12:15:35 This is probably unnecessarily confusing, and I ca
iclelland 2016/05/30 15:07:47 Done.
+ v8::Local<v8::Function> interface = v8::Function::New(context, nullptr).ToLocalChecked();
+
+ if (!originTrialContext->featureBindingsInstalled("DurableStorage") && (RuntimeEnabledFeatures::durableStorageEnabled() || originTrialContext->isFeatureEnabled("DurableStorage", nullptr))) {
+ if (executionContext->isDocument()) {
+ v8::Local<v8::String> navigatorName = v8::String::NewFromUtf8(isolate, "navigator", v8::NewStringType::kNormal).ToLocalChecked();
+ v8::Local<v8::Object> navigator = global->Get(context, navigatorName).ToLocalChecked()->ToObject();
+ V8WindowPartial::installDurableStorage(isolate, world, global, interface);
haraken 2016/05/27 22:25:17 You should pass in ScriptState. ScriptState knows
iclelland 2016/05/30 12:15:35 Yes, I'll do that -- Somehow, I was thinking that
iclelland 2016/05/30 15:07:46 Done.
+ V8NavigatorPartial::installDurableStorage(isolate, world, navigator, interface);
+ } else if (executionContext->isSharedWorkerGlobalScope()) {
+ V8SharedWorkerGlobalScopePartial::installDurableStorage(isolate, world, global, interface);
+ } else if (executionContext->isDedicatedWorkerGlobalScope()) {
+ V8DedicatedWorkerGlobalScopePartial::installDurableStorage(isolate, world, global, interface);
+ } else if (executionContext->isServiceWorkerGlobalScope()) {
+ V8ServiceWorkerGlobalScope::installDurableStorage(isolate, world, global, interface);
+ }
+ originTrialContext->setFeatureBindingsInstalled("DurableStorage");
+ }
+}
+
+void registerInitializeOriginTrialsForModules()
+{
+ s_originalInitializeOriginTrialsFunction = setInitializeOriginTrialsFunction(&initializeOriginTrialsForModules);
+}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698