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

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

Issue 2260113002: Lazily install origin trial features on V8 objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase after parent CL landed Created 4 years, 3 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/ConditionalFeaturesForModules.cpp
diff --git a/third_party/WebKit/Source/bindings/modules/v8/ConditionalFeaturesForModules.cpp b/third_party/WebKit/Source/bindings/modules/v8/ConditionalFeaturesForModules.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9eed3b9572f6930f0a5e3eb892ca1198d5e301c9
--- /dev/null
+++ b/third_party/WebKit/Source/bindings/modules/v8/ConditionalFeaturesForModules.cpp
@@ -0,0 +1,97 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "bindings/modules/v8/ConditionalFeaturesForModules.h"
+
+#include "bindings/core/v8/ScriptState.h"
+#include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h"
+#include "bindings/core/v8/V8Navigator.h"
+#include "bindings/core/v8/V8SharedWorkerGlobalScope.h"
+#include "bindings/core/v8/V8Window.h"
+#include "bindings/core/v8/V8WorkerNavigator.h"
+#include "bindings/modules/v8/V8DedicatedWorkerGlobalScopePartial.h"
+#include "bindings/modules/v8/V8InstallEvent.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/V8WorkerNavigatorPartial.h"
+#include "core/dom/ExecutionContext.h"
+#include "core/origin_trials/OriginTrialContext.h"
+
+namespace blink {
+
+namespace {
+InstallConditionalFeaturesFunction s_originalInstallConditionalFeaturesFunction = nullptr;
+}
+
+void installConditionalFeaturesForModules(const WrapperTypeInfo* wrapperTypeInfo, const ScriptState* scriptState, v8::Local<v8::Object> prototypeObject, v8::Local<v8::Function> interfaceObject)
+{
+ // 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_originalInstallConditionalFeaturesFunction)(wrapperTypeInfo, scriptState, prototypeObject, interfaceObject);
+
+ ExecutionContext* executionContext = scriptState->getExecutionContext();
+ if (!executionContext)
+ return;
+ OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext, OriginTrialContext::DontCreateIfNotExists);
+ v8::Isolate* isolate = scriptState->isolate();
+ const DOMWrapperWorld& world = scriptState->world();
+ v8::Local<v8::Object> global = scriptState->context()->Global();
+ if (wrapperTypeInfo == &V8Navigator::wrapperTypeInfo) {
+ if (RuntimeEnabledFeatures::durableStorageEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("DurableStorage"))) {
+ V8NavigatorPartial::installDurableStorage(isolate, world, v8::Local<v8::Object>(), prototypeObject, interfaceObject); // Need to specify interface object explicitly to avoid looping back here
+ }
+ if (RuntimeEnabledFeatures::webBluetoothEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("WebBluetooth"))) {
+ V8NavigatorPartial::installWebBluetooth(isolate, world, v8::Local<v8::Object>(), prototypeObject, interfaceObject);
+ }
+ if (RuntimeEnabledFeatures::webShareEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("WebShare"))) {
+ V8NavigatorPartial::installWebShare(isolate, world, v8::Local<v8::Object>(), prototypeObject, interfaceObject);
+ }
+ if (RuntimeEnabledFeatures::webUSBEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("WebUSB"))) {
+ V8NavigatorPartial::installWebUSB(isolate, world, v8::Local<v8::Object>(), prototypeObject, interfaceObject);
+ }
+ } else if (wrapperTypeInfo == &V8WorkerNavigator::wrapperTypeInfo) {
+ if (RuntimeEnabledFeatures::durableStorageEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("DurableStorage"))) {
+ V8WorkerNavigatorPartial::installDurableStorage(isolate, world, v8::Local<v8::Object>(), prototypeObject, interfaceObject);
+ }
+ } else if (wrapperTypeInfo == &V8Window::wrapperTypeInfo) {
+ if (RuntimeEnabledFeatures::durableStorageEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("DurableStorage"))) {
+ V8WindowPartial::installDurableStorage(isolate, world, global, prototypeObject, interfaceObject);
+ }
+ if (RuntimeEnabledFeatures::webBluetoothEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("WebBluetooth"))) {
+ V8WindowPartial::installWebBluetooth(isolate, world, global, prototypeObject, interfaceObject);
+ }
+ if (RuntimeEnabledFeatures::webUSBEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("WebUSB"))) {
+ V8WindowPartial::installWebUSB(isolate, world, global, prototypeObject, interfaceObject);
+ }
+ } else if (wrapperTypeInfo == &V8SharedWorkerGlobalScope::wrapperTypeInfo) {
+ if (RuntimeEnabledFeatures::durableStorageEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("DurableStorage"))) {
+ V8SharedWorkerGlobalScopePartial::installDurableStorage(isolate, world, global, prototypeObject, interfaceObject);
+ }
+ } else if (wrapperTypeInfo == &V8DedicatedWorkerGlobalScope::wrapperTypeInfo) {
+ if (RuntimeEnabledFeatures::durableStorageEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("DurableStorage"))) {
+ V8DedicatedWorkerGlobalScopePartial::installDurableStorage(isolate, world, global, prototypeObject, interfaceObject);
+ }
+ } else if (wrapperTypeInfo == &V8ServiceWorkerGlobalScope::wrapperTypeInfo) {
+ if (RuntimeEnabledFeatures::durableStorageEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("DurableStorage"))) {
+ V8ServiceWorkerGlobalScope::installDurableStorage(isolate, world, global, prototypeObject, interfaceObject);
+ }
+ if (RuntimeEnabledFeatures::foreignFetchEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("ForeignFetch"))) {
+ V8ServiceWorkerGlobalScope::installForeignFetch(isolate, world, global, prototypeObject, interfaceObject);
+ }
+ } else if (wrapperTypeInfo == &V8InstallEvent::wrapperTypeInfo) {
+ if (RuntimeEnabledFeatures::foreignFetchEnabled() || (originTrialContext && originTrialContext->isFeatureEnabled("ForeignFetch"))) {
+ V8InstallEvent::installForeignFetch(isolate, world, v8::Local<v8::Object>(), prototypeObject, interfaceObject);
+ }
+ }
+}
+
+void registerInstallConditionalFeaturesForModules()
+{
+ s_originalInstallConditionalFeaturesFunction = setInstallConditionalFeaturesFunction(&installConditionalFeaturesForModules);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698