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

Unified Diff: third_party/WebKit/Source/core/origin_trials/OriginTrialContext.cpp

Issue 2005433002: [Origin Trials] Install origin trial bindings on V8 context conditionally (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@track-ef-install
Patch Set: Clean up Created 4 years, 7 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/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..54a59045a20d984f03642eba73eb598ae2737d09 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);
haraken 2016/05/27 00:01:42 Do you have a plan to enable the origin-trials att
iclelland 2016/05/27 03:19:43 Not at the moment; there's definitely no plan righ
haraken 2016/05/27 22:25:17 Not supporting isolated worlds at the moment makes
+ if (!state)
+ return;
+ if (!frame->script().windowProxy(state->world())->isContextInitialized())
+ return;
+ v8::HandleScope handleScope(state->isolate());
+ initializeOriginTrials(state->context(), state->world());
+ } 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->context(), state->world());
+ }
}
void OriginTrialContext::setFeatureBindingsInstalled(const String& featureName)

Powered by Google App Engine
This is Rietveld 408576698