Index: third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp b/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp |
index 6b28b52df4953a008dc110c22f6ab41c6b32a6e6..96e57ce40ede1552cc1d84f7e5c159d2922114c2 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/ConditionalFeatures.cpp |
@@ -12,6 +12,7 @@ |
#include "core/dom/ExecutionContext.h" |
#include "core/frame/LocalFrame.h" |
#include "core/origin_trials/OriginTrialContext.h" |
iclelland
2017/01/26 20:14:11
I think we can remove this one now
chasej
2017/01/27 17:22:36
Done.
|
+#include "core/origin_trials/OriginTrials.h" |
namespace blink { |
@@ -25,40 +26,73 @@ void installConditionalFeaturesCore(const WrapperTypeInfo* wrapperTypeInfo, |
ExecutionContext* executionContext = scriptState->getExecutionContext(); |
if (!executionContext) |
return; |
- OriginTrialContext* originTrialContext = OriginTrialContext::from( |
- executionContext, OriginTrialContext::DontCreateIfNotExists); |
v8::Isolate* isolate = scriptState->isolate(); |
const DOMWrapperWorld& world = scriptState->world(); |
if (wrapperTypeInfo == &V8HTMLLinkElement::wrapperTypeInfo) { |
- if (RuntimeEnabledFeatures::linkServiceWorkerEnabled() || |
- (originTrialContext && |
- originTrialContext->isTrialEnabled("ForeignFetch"))) { |
+ if (OriginTrials::linkServiceWorkerEnabled(executionContext)) { |
V8HTMLLinkElement::installLinkServiceWorker( |
isolate, world, v8::Local<v8::Object>(), prototypeObject, |
interfaceObject); |
} |
} else if (wrapperTypeInfo == &V8Window::wrapperTypeInfo) { |
v8::Local<v8::Object> instanceObject = scriptState->context()->Global(); |
- if (RuntimeEnabledFeatures::longTaskObserverEnabled() || |
- (originTrialContext && |
- originTrialContext->isTrialEnabled("LongTaskObserver"))) { |
+ if (OriginTrials::longTaskObserverEnabled(executionContext)) { |
V8Window::installLongTaskObserver(isolate, world, instanceObject, |
prototypeObject, interfaceObject); |
} |
} else if (wrapperTypeInfo == &V8Document::wrapperTypeInfo) { |
- if (RuntimeEnabledFeatures::setRootScrollerEnabled() || |
- (originTrialContext && |
- originTrialContext->isTrialEnabled("RootScroller"))) { |
+ if (OriginTrials::setRootScrollerEnabled(executionContext)) { |
V8Document::installRootScroller(isolate, world, v8::Local<v8::Object>(), |
prototypeObject, interfaceObject); |
} |
} |
} |
+void installPendingConditionalFeatureCore(const String& feature, |
+ const ScriptState* scriptState) { |
+ // TODO(iclelland): Generate all of this logic at compile-time, based on the |
+ // configuration of origin trial enabled attributes and interfaces in IDL |
+ // files. (crbug.com/615060) |
+ v8::Local<v8::Object> prototypeObject; |
+ v8::Local<v8::Function> interfaceObject; |
+ v8::Isolate* isolate = scriptState->isolate(); |
+ const DOMWrapperWorld& world = scriptState->world(); |
+ if (feature == "ForeignFetch") { |
+ if (getExistingConstructorAndPrototypeForType( |
+ &V8HTMLLinkElement::wrapperTypeInfo, scriptState, &prototypeObject, |
+ &interfaceObject)) { |
+ V8HTMLLinkElement::installLinkServiceWorker( |
+ isolate, world, v8::Local<v8::Object>(), prototypeObject, |
+ interfaceObject); |
+ } |
+ return; |
+ } |
+ if (feature == "LongTaskObserver") { |
+ v8::Local<v8::Object> instanceObject = scriptState->context()->Global(); |
+ V8Window::installLongTaskObserver(isolate, world, instanceObject, |
+ v8::Local<v8::Object>(), |
+ v8::Local<v8::Function>()); |
+ return; |
+ } |
+ if (feature == "RootScroller") { |
+ if (getExistingConstructorAndPrototypeForType(&V8Document::wrapperTypeInfo, |
+ scriptState, &prototypeObject, |
+ &interfaceObject)) { |
+ V8Document::installRootScroller(isolate, world, v8::Local<v8::Object>(), |
+ prototypeObject, interfaceObject); |
+ } |
+ return; |
+ } |
+} |
+ |
namespace { |
InstallConditionalFeaturesFunction s_installConditionalFeaturesFunction = |
&installConditionalFeaturesCore; |
+ |
+InstallPendingConditionalFeatureFunction |
+ s_installPendingConditionalFeatureFunction = |
+ &installPendingConditionalFeatureCore; |
} |
InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( |
@@ -69,6 +103,17 @@ InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( |
return originalFunction; |
} |
+InstallPendingConditionalFeatureFunction |
+setInstallPendingConditionalFeatureFunction( |
+ InstallPendingConditionalFeatureFunction |
+ newInstallPendingConditionalFeatureFunction) { |
+ InstallPendingConditionalFeatureFunction originalFunction = |
+ s_installPendingConditionalFeatureFunction; |
+ s_installPendingConditionalFeatureFunction = |
+ newInstallPendingConditionalFeatureFunction; |
+ return originalFunction; |
+} |
+ |
void installConditionalFeatures(const WrapperTypeInfo* type, |
const ScriptState* scriptState, |
v8::Local<v8::Object> prototypeObject, |
@@ -87,6 +132,31 @@ void installPendingConditionalFeaturesOnWindow(const ScriptState* scriptState) { |
v8::Local<v8::Function>()); |
} |
+void installPendingConditionalFeature(const String& feature, |
+ const ScriptState* scriptState) { |
+ DCHECK(scriptState); |
+ DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); |
+ DCHECK(scriptState->perContextData()); |
+ DCHECK(scriptState->world().isMainWorld()); |
+ |
+ (*s_installPendingConditionalFeatureFunction)(feature, scriptState); |
+} |
+ |
+bool getExistingConstructorAndPrototypeForType( |
+ const WrapperTypeInfo* wrapperTypeInfo, |
+ const ScriptState* scriptState, |
+ v8::Local<v8::Object>* prototypeObject, |
+ v8::Local<v8::Function>* interfaceObject) { |
+ V8PerContextData* contextData = scriptState->perContextData(); |
+ *interfaceObject = contextData->constructorForTypeFromCache(wrapperTypeInfo); |
+ if (interfaceObject->IsEmpty()) { |
+ *prototypeObject = v8::Local<v8::Object>(); |
+ return false; |
+ } |
+ *prototypeObject = contextData->prototypeForType(wrapperTypeInfo); |
+ return true; |
+} |
+ |
bool isFeatureEnabledInFrame(const FeaturePolicy::Feature& feature, |
const LocalFrame* frame) { |
// If there is no frame, or if feature policy is disabled, use defaults. |