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..299b517fea9336fb53ec52c0967cd93149aee462 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" |
+#include "core/origin_trials/OriginTrials.h" |
namespace blink { |
@@ -25,40 +26,63 @@ 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); |
} |
} |
} |
+bool installConditionalFeaturesIfNeededCore( |
+ const WrapperTypeInfo* wrapperTypeInfo, |
+ const ScriptState* scriptState) { |
+ if (wrapperTypeInfo == &V8Window::wrapperTypeInfo) { |
+ LOG(INFO) << "Just install, don't look for existing instance for type: " |
iclelland
2017/01/20 14:31:19
Is this a debug message to be removed?
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
|
+ << wrapperTypeInfo->interfaceName; |
+ installConditionalFeatures(wrapperTypeInfo, scriptState, |
iclelland
2017/01/20 14:31:19
V8Window is a global object, which is the one case
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
|
+ v8::Local<v8::Object>(), |
+ v8::Local<v8::Function>()); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+void getAffectedTypesForConditionalFeatureCore( |
iclelland
2017/01/20 14:31:19
Rather than modifying its input, could this return
chasej
2017/01/25 19:58:20
This method is gone in the new, simplified approac
|
+ const String& feature, |
+ HashSet<const WrapperTypeInfo*>* affectedTypes) { |
+ if (feature == "LongTaskObserver") { |
+ affectedTypes->add(&V8Window::wrapperTypeInfo); |
+ return; |
+ } |
+} |
+ |
namespace { |
InstallConditionalFeaturesFunction s_installConditionalFeaturesFunction = |
&installConditionalFeaturesCore; |
+ |
+InstallConditionalFeaturesIfNeededFunction |
+ s_installConditionalFeaturesIfNeededFunction = |
+ &installConditionalFeaturesIfNeededCore; |
+ |
+GetAffectedTypesForConditionalFeatureFunction |
+ s_getAffectedTypesForConditionalFeatureFunction = |
+ &getAffectedTypesForConditionalFeatureCore; |
} |
InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( |
@@ -69,6 +93,28 @@ InstallConditionalFeaturesFunction setInstallConditionalFeaturesFunction( |
return originalFunction; |
} |
+InstallConditionalFeaturesIfNeededFunction |
+setInstallConditionalFeaturesIfNeededFunction( |
+ InstallConditionalFeaturesIfNeededFunction |
+ newInstallConditionalFeaturesIfNeededFunction) { |
+ InstallConditionalFeaturesIfNeededFunction originalFunction = |
+ s_installConditionalFeaturesIfNeededFunction; |
+ s_installConditionalFeaturesIfNeededFunction = |
+ newInstallConditionalFeaturesIfNeededFunction; |
+ return originalFunction; |
+} |
+ |
+GetAffectedTypesForConditionalFeatureFunction |
+setGetAffectedTypesForConditionalFeatureFunction( |
+ GetAffectedTypesForConditionalFeatureFunction |
+ newGetAffectedTypesForConditionalFeatureFunction) { |
+ GetAffectedTypesForConditionalFeatureFunction originalFunction = |
+ s_getAffectedTypesForConditionalFeatureFunction; |
+ s_getAffectedTypesForConditionalFeatureFunction = |
+ newGetAffectedTypesForConditionalFeatureFunction; |
+ return originalFunction; |
+} |
+ |
void installConditionalFeatures(const WrapperTypeInfo* type, |
const ScriptState* scriptState, |
v8::Local<v8::Object> prototypeObject, |
@@ -87,6 +133,29 @@ void installPendingConditionalFeaturesOnWindow(const ScriptState* scriptState) { |
v8::Local<v8::Function>()); |
} |
+bool installPendingConditionalFeature(const ScriptState* scriptState, |
+ const String& feature) { |
+ DCHECK(scriptState); |
+ DCHECK(scriptState->context() == scriptState->isolate()->GetCurrentContext()); |
+ DCHECK(scriptState->perContextData()); |
+ DCHECK(scriptState->world().isMainWorld()); |
+ |
+ // TODO(chasej): Make the installation of features more granular, rather |
+ // than attempting to install all features per type |
+ HashSet<const WrapperTypeInfo*> affectedTypes; |
+ LOG(INFO) << "Install pending feature: " << feature; |
iclelland
2017/01/20 14:31:19
Debug, right?
chasej
2017/01/25 19:58:20
Removed (along with this method being rewritten).
|
+ (*s_getAffectedTypesForConditionalFeatureFunction)(feature, &affectedTypes); |
+ |
+ bool allInstalled = true; |
+ for (auto type : affectedTypes) { |
+ LOG(INFO) << "Install on affected type: " << type->interfaceName; |
+ if (!((*s_installConditionalFeaturesIfNeededFunction)(type, scriptState))) |
+ allInstalled = false; |
+ } |
+ |
+ return allInstalled; |
+} |
+ |
bool isFeatureEnabledInFrame(const FeaturePolicy::Feature& feature, |
const LocalFrame* frame) { |
// If there is no frame, or if feature policy is disabled, use defaults. |