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..298487b13adc8740dee4f2e4329d01f98d76906f 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(v8::Local<v8::Context> context, const DOMWrapperWorld& world) |
haraken
2016/05/27 00:01:42
This method should take ScriptState. ScriptState c
iclelland
2016/05/27 03:19:43
That's a great idea -- thank you for that!
|
+{ |
+ // 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) |
+ DCHECK(!context.IsEmpty()); |
+ (*s_originalInitializeOriginTrialsFunction)(context, world); |
+ |
+ ExecutionContext* executionContext = toExecutionContext(context); |
+ OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext, OriginTrialContext::DontCreateIfNotExists); |
+ if (!originTrialContext) |
+ return; |
+ |
+ context->Enter(); |
haraken
2016/05/27 00:01:42
ScriptState::Scope scope(scriptState);
iclelland
2016/05/27 03:19:43
Done.
|
+ 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 (!originTrialContext->featureBindingsInstalled("DurableStorage") && (RuntimeEnabledFeatures::durableStorageEnabled() || originTrialContext->isFeatureEnabled("DurableStorage", nullptr))) { |
haraken
2016/05/27 00:01:42
Let's drop RuntimeEnableFeatures::durableStorageEn
iclelland
2016/05/27 03:19:43
DurableStorage isn't a runtime-enabled attribute a
|
+ 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"); |
haraken
2016/05/27 00:01:42
Before this CL, how was DurableStorage installed?
iclelland
2016/05/27 03:19:43
In early development, it was [RuntimeEnabled=Durab
|
+ } |
+ context->Exit(); |
+} |
+ |
+void registerInitializeOriginTrialsForModules() |
+{ |
+ s_originalInitializeOriginTrialsFunction = setInitializeOriginTrialsFunction(&initializeOriginTrialsForModules); |
+} |
} // namespace blink |