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..9c0c73e5375ac3449ae423fb23ad2a223e745e59 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,50 @@ ExecutionContext* toExecutionContextForModules(v8::Local<v8::Context> context) |
return nullptr; |
} |
+namespace { |
+initializeOriginTrialsFunction s_originalInitializeOriginTrialsFunction = nullptr; |
+} |
+ |
+void initializeOriginTrialsForModules(v8::Local<v8::Context> context, const DOMWrapperWorld& world) |
+{ |
+ DCHECK(!context.IsEmpty()); |
+ (*s_originalInitializeOriginTrialsFunction)(context, world); |
+ context->Enter(); |
+ |
+ ExecutionContext* executionContext = toExecutionContext(context); |
+ OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext, OriginTrialContext::DontCreateIfNotExists); |
+ if (!originTrialContext) |
+ return; |
+ |
+ v8::Local<v8::Object> global = context->Global(); |
+ v8::Isolate* isolate = context->GetIsolate(); |
+ // 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) |
+ v8::Local<v8::Function> interface = v8::Function::New(context, nullptr).ToLocalChecked(); |
+ |
+ if ((RuntimeEnabledFeatures::durableStorageEnabled() || originTrialContext->isFeatureEnabled("DurableStorage", nullptr)) && !originTrialContext->featureBindingsInstalled("DurableStorage")) { |
+ 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); |
+ 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"); |
+ } |
+ context->Exit(); |
+} |
+ |
+void registerInitializeOriginTrialsForModules() |
+{ |
+ s_originalInitializeOriginTrialsFunction = setInitializeOriginTrialsFunction(&initializeOriginTrialsForModules); |
+} |
} // namespace blink |