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

Unified Diff: third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.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/testing/v8/WebCoreTestSupport.cpp
diff --git a/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp b/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
index 76b1d711395d707ce69f8c40036574efeffaaaec..074579bd22eb7b9585008a1fac9d6455046dacc1 100644
--- a/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
+++ b/third_party/WebKit/Source/core/testing/v8/WebCoreTestSupport.cpp
@@ -25,10 +25,14 @@
#include "core/testing/v8/WebCoreTestSupport.h"
+#include "bindings/core/v8/DOMWrapperWorld.h"
+#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8Internals.h"
+#include "bindings/core/v8/V8WorkerInternals.h"
#include "core/dom/Document.h"
#include "core/dom/ExecutionContext.h"
#include "core/frame/LocalFrame.h"
+#include "core/origin_trials/OriginTrialContext.h"
#include "core/testing/InternalSettings.h"
#include "core/testing/Internals.h"
#include "core/testing/WorkerInternals.h"
@@ -37,6 +41,10 @@ using namespace blink;
namespace WebCoreTestSupport {
+namespace {
+blink::initializeOriginTrialsFunction s_originalInitializeOriginTrialsFunction = nullptr;
+}
+
v8::Local<v8::Value> createInternalsObject(v8::Local<v8::Context> context)
{
ScriptState* scriptState = ScriptState::from(context);
@@ -51,13 +59,63 @@ v8::Local<v8::Value> createInternalsObject(v8::Local<v8::Context> context)
void injectInternalsObject(v8::Local<v8::Context> context)
{
+ if (!s_originalInitializeOriginTrialsFunction) {
+ s_originalInitializeOriginTrialsFunction = setInitializeOriginTrialsFunction(initializeOriginTrialsForTests);
+ }
+
ScriptState* scriptState = ScriptState::from(context);
ScriptState::Scope scope(scriptState);
v8::Local<v8::Object> global = scriptState->context()->Global();
v8::Local<v8::Value> internals = createInternalsObject(context);
if (internals.IsEmpty())
return;
+
v8CallOrCrash(global->Set(scriptState->context(), v8AtomicString(scriptState->isolate(), Internals::internalsId), internals));
+
+ // If Origin Trials have been registered before the internals object was ready,
+ // then inject them into the context now
+ ExecutionContext* executionContext = toExecutionContext(context);
+ if (executionContext) {
+ OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext);
+ if (originTrialContext)
+ originTrialContext->initializePendingTrials();
+ }
+}
+
+void initializeOriginTrialsForTests(v8::Local<v8::Context> context, const blink::DOMWrapperWorld& world)
haraken 2016/05/27 00:01:42 Hmm, this adds a couple of complexity. Alternatel
iclelland 2016/05/27 03:19:43 That's what we do -- see LayoutTests/http/origin_t
haraken 2016/05/27 22:25:17 I'm not sure if it's too late. In common cases, a
iclelland 2016/05/30 15:39:28 That's true, but it's not window that is a problem
+{
+ DCHECK(!context.IsEmpty());
+ (*s_originalInitializeOriginTrialsFunction)(context, world);
+ ExecutionContext* executionContext = toExecutionContext(context);
+ if (!executionContext->isDocument() && !executionContext->isWorkerGlobalScope())
+ return;
+ OriginTrialContext* originTrialContext = OriginTrialContext::from(executionContext, OriginTrialContext::DontCreateIfNotExists);
+ if (!originTrialContext)
+ return;
+
+ context->Enter();
+ v8::Isolate* isolate = context->GetIsolate();
+ v8::Local<v8::Object> global = context->Global();
+ // TODO(iclelland): This is a placeholder for the real interface object,
+ // which we don't try to obtain at this time. (An assertion in the bindings
+ // generation code prevents it from actually being used.) It should be
+ // replaced with the actual interface if possible, in order to allow origin
+ // trials on static attributes. (crbug.com/614352)
+ v8::Local<v8::Function> interface = v8::Function::New(context, nullptr).ToLocalChecked();
+
+ v8::Local<v8::String> internalsName = v8::String::NewFromUtf8(isolate, "internals", v8::NewStringType::kNormal).ToLocalChecked();
+ v8::Local<v8::Value> v8Internals = global->Get(context, internalsName).ToLocalChecked();
+ if (v8Internals->IsObject()) {
+ v8::Local<v8::Object> internals = v8Internals->ToObject();
+ if (!originTrialContext->featureBindingsInstalled("Frobulate") && originTrialContext->isFeatureEnabled("Frobulate", nullptr)) {
+ if (executionContext->isDocument())
+ V8Internals::installOriginTrialsSampleAPI(isolate, world, internals, interface);
+ else if (executionContext->isWorkerGlobalScope())
+ V8WorkerInternals::installOriginTrialsSampleAPI(isolate, world, internals, interface);
+ originTrialContext->setFeatureBindingsInstalled("Frobulate");
+ }
+ }
+ context->Exit();
}
void resetInternalsObject(v8::Local<v8::Context> context)

Powered by Google App Engine
This is Rietveld 408576698