| Index: third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| diff --git a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| index f19a442252bc43be50a4f9c8fb0a8a40ca42f889..d0b7917fc6784a284b28decc629d053d0ee6b723 100644
|
| --- a/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| +++ b/third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp
|
| @@ -4,7 +4,14 @@
|
|
|
| #include "core/origin_trials/OriginTrialContext.h"
|
|
|
| +#include "bindings/core/v8/ScriptController.h"
|
| +#include "bindings/core/v8/V8Binding.h"
|
| +#include "bindings/core/v8/WindowProxy.h"
|
| +#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
|
| +#include "core/dom/Document.h"
|
| #include "core/dom/ExecutionContext.h"
|
| +#include "core/frame/LocalFrame.h"
|
| +#include "core/workers/WorkerGlobalScope.h"
|
| #include "platform/Histogram.h"
|
| #include "platform/RuntimeEnabledFeatures.h"
|
| #include "platform/weborigin/SecurityOrigin.h"
|
| @@ -14,6 +21,8 @@
|
| #include "public/platform/WebTrialTokenValidator.h"
|
| #include "wtf/text/StringBuilder.h"
|
|
|
| +#include <v8.h>
|
| +
|
| namespace blink {
|
|
|
| namespace {
|
| @@ -234,11 +243,42 @@ void OriginTrialContext::addToken(const String& token)
|
| {
|
| if (!token.isEmpty())
|
| m_tokens.append(token);
|
| + initializePendingTrials();
|
| }
|
|
|
| void OriginTrialContext::addTokens(const Vector<String>& tokens)
|
| {
|
| m_tokens.appendVector(tokens);
|
| + initializePendingTrials();
|
| +}
|
| +
|
| +void OriginTrialContext::initializePendingTrials()
|
| +{
|
| + // TODO(iclelland): Factor this logic out to methods on the various
|
| + // execution contexts
|
| + if (m_host->isDocument()) {
|
| + LocalFrame* frame = toDocument(m_host.get())->frame();
|
| + if (!frame)
|
| + return;
|
| + ScriptState* state = ScriptState::forMainWorld(frame);
|
| + if (!state)
|
| + return;
|
| + if (!frame->script().windowProxy(state->world())->isContextInitialized())
|
| + return;
|
| + v8::HandleScope handleScope(state->isolate());
|
| + initializeOriginTrials(state);
|
| + } else if (m_host->isWorkerGlobalScope()) {
|
| + WorkerOrWorkletScriptController* scriptController = toWorkerGlobalScope(m_host.get())->scriptController();
|
| + if (!scriptController)
|
| + return;
|
| + ScriptState* state = scriptController->getScriptState();
|
| + if (!state)
|
| + return;
|
| + if (!scriptController->isContextInitialized())
|
| + return;
|
| + v8::HandleScope handleScope(state->isolate());
|
| + initializeOriginTrials(state);
|
| + }
|
| }
|
|
|
| void OriginTrialContext::setFeatureBindingsInstalled(const String& featureName)
|
|
|