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

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/V8BindingForModules.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: Switch to using ScriptState instead of explicit context/world Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 18 matching lines...) Expand all
29 #include "bindings/core/v8/SerializedScriptValueFactory.h" 29 #include "bindings/core/v8/SerializedScriptValueFactory.h"
30 #include "bindings/core/v8/V8ArrayBuffer.h" 30 #include "bindings/core/v8/V8ArrayBuffer.h"
31 #include "bindings/core/v8/V8ArrayBufferView.h" 31 #include "bindings/core/v8/V8ArrayBufferView.h"
32 #include "bindings/core/v8/V8Binding.h" 32 #include "bindings/core/v8/V8Binding.h"
33 #include "bindings/core/v8/V8Blob.h" 33 #include "bindings/core/v8/V8Blob.h"
34 #include "bindings/core/v8/V8DOMStringList.h" 34 #include "bindings/core/v8/V8DOMStringList.h"
35 #include "bindings/core/v8/V8File.h" 35 #include "bindings/core/v8/V8File.h"
36 #include "bindings/core/v8/V8Uint8Array.h" 36 #include "bindings/core/v8/V8Uint8Array.h"
37 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 37 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
38 #include "bindings/modules/v8/ToV8ForModules.h" 38 #include "bindings/modules/v8/ToV8ForModules.h"
39 #include "bindings/modules/v8/V8DedicatedWorkerGlobalScopePartial.h"
39 #include "bindings/modules/v8/V8IDBCursor.h" 40 #include "bindings/modules/v8/V8IDBCursor.h"
40 #include "bindings/modules/v8/V8IDBCursorWithValue.h" 41 #include "bindings/modules/v8/V8IDBCursorWithValue.h"
41 #include "bindings/modules/v8/V8IDBDatabase.h" 42 #include "bindings/modules/v8/V8IDBDatabase.h"
42 #include "bindings/modules/v8/V8IDBIndex.h" 43 #include "bindings/modules/v8/V8IDBIndex.h"
43 #include "bindings/modules/v8/V8IDBKeyRange.h" 44 #include "bindings/modules/v8/V8IDBKeyRange.h"
44 #include "bindings/modules/v8/V8IDBObjectStore.h" 45 #include "bindings/modules/v8/V8IDBObjectStore.h"
46 #include "bindings/modules/v8/V8NavigatorPartial.h"
47 #include "bindings/modules/v8/V8ServiceWorkerGlobalScope.h"
48 #include "bindings/modules/v8/V8SharedWorkerGlobalScopePartial.h"
49 #include "bindings/modules/v8/V8WindowPartial.h"
45 #include "bindings/modules/v8/V8WorkletGlobalScope.h" 50 #include "bindings/modules/v8/V8WorkletGlobalScope.h"
46 #include "core/dom/DOMArrayBuffer.h" 51 #include "core/dom/DOMArrayBuffer.h"
47 #include "core/dom/DOMArrayBufferView.h" 52 #include "core/dom/DOMArrayBufferView.h"
48 #include "core/dom/ExecutionContext.h" 53 #include "core/dom/ExecutionContext.h"
54 #include "core/origin_trials/OriginTrialContext.h"
49 #include "modules/indexeddb/IDBKey.h" 55 #include "modules/indexeddb/IDBKey.h"
50 #include "modules/indexeddb/IDBKeyPath.h" 56 #include "modules/indexeddb/IDBKeyPath.h"
51 #include "modules/indexeddb/IDBKeyRange.h" 57 #include "modules/indexeddb/IDBKeyRange.h"
52 #include "modules/indexeddb/IDBTracing.h" 58 #include "modules/indexeddb/IDBTracing.h"
53 #include "modules/indexeddb/IDBValue.h" 59 #include "modules/indexeddb/IDBValue.h"
54 #include "modules/worklet/WorkletGlobalScope.h" 60 #include "modules/worklet/WorkletGlobalScope.h"
55 #include "platform/RuntimeEnabledFeatures.h" 61 #include "platform/RuntimeEnabledFeatures.h"
56 #include "platform/SharedBuffer.h" 62 #include "platform/SharedBuffer.h"
57 #include "wtf/MathExtras.h" 63 #include "wtf/MathExtras.h"
58 #include "wtf/Vector.h" 64 #include "wtf/Vector.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (context.IsEmpty()) 531 if (context.IsEmpty())
526 return nullptr; 532 return nullptr;
527 v8::Local<v8::Object> global = context->Global(); 533 v8::Local<v8::Object> global = context->Global();
528 v8::Local<v8::Object> workletWrapper = V8WorkletGlobalScope::findInstanceInP rototypeChain(global, context->GetIsolate()); 534 v8::Local<v8::Object> workletWrapper = V8WorkletGlobalScope::findInstanceInP rototypeChain(global, context->GetIsolate());
529 if (!workletWrapper.IsEmpty()) 535 if (!workletWrapper.IsEmpty())
530 return V8WorkletGlobalScope::toImpl(workletWrapper); 536 return V8WorkletGlobalScope::toImpl(workletWrapper);
531 // FIXME: Is this line of code reachable? 537 // FIXME: Is this line of code reachable?
532 return nullptr; 538 return nullptr;
533 } 539 }
534 540
541 namespace {
542 initializeOriginTrialsFunction s_originalInitializeOriginTrialsFunction = nullpt r;
543 }
544
545 void initializeOriginTrialsForModules(ScriptState* scriptState)
546 {
547 // TODO(iclelland): Generate all of this logic at compile-time, based on the
548 // configuration of origin trial enabled attibutes and interfaces in IDL
549 // files. (crbug.com/615060)
550 (*s_originalInitializeOriginTrialsFunction)(scriptState);
551
552 v8::Local<v8::Context> context = scriptState->context();
553 ExecutionContext* executionContext = toExecutionContext(context);
554 OriginTrialContext* originTrialContext = OriginTrialContext::from(executionC ontext, OriginTrialContext::DontCreateIfNotExists);
555 if (!originTrialContext)
556 return;
557
558 ScriptState::Scope scope(scriptState);
559 v8::Local<v8::Object> global = context->Global();
560 v8::Isolate* isolate = scriptState->isolate();
561 const DOMWrapperWorld& world = scriptState->world();
562 // TODO(iclelland): This is a placeholder for the real interface object,
563 // which we don't try to obtain at this time. (An assertion in the bindings
564 // generation code prevents it from actually being used.) It should be
565 // replaced with the actual interface if possible, in order to allow origin
566 // trials on static attributes. (crbug.com/614352)
haraken 2016/05/27 22:25:17 At which point is the placeholder (i.e., |interfac
iclelland 2016/05/30 12:15:35 This is probably unnecessarily confusing, and I ca
iclelland 2016/05/30 15:07:47 Done.
567 v8::Local<v8::Function> interface = v8::Function::New(context, nullptr).ToLo calChecked();
568
569 if (!originTrialContext->featureBindingsInstalled("DurableStorage") && (Runt imeEnabledFeatures::durableStorageEnabled() || originTrialContext->isFeatureEnab led("DurableStorage", nullptr))) {
570 if (executionContext->isDocument()) {
571 v8::Local<v8::String> navigatorName = v8::String::NewFromUtf8(isolat e, "navigator", v8::NewStringType::kNormal).ToLocalChecked();
572 v8::Local<v8::Object> navigator = global->Get(context, navigatorName ).ToLocalChecked()->ToObject();
573 V8WindowPartial::installDurableStorage(isolate, world, global, inter face);
haraken 2016/05/27 22:25:17 You should pass in ScriptState. ScriptState knows
iclelland 2016/05/30 12:15:35 Yes, I'll do that -- Somehow, I was thinking that
iclelland 2016/05/30 15:07:46 Done.
574 V8NavigatorPartial::installDurableStorage(isolate, world, navigator, interface);
575 } else if (executionContext->isSharedWorkerGlobalScope()) {
576 V8SharedWorkerGlobalScopePartial::installDurableStorage(isolate, wor ld, global, interface);
577 } else if (executionContext->isDedicatedWorkerGlobalScope()) {
578 V8DedicatedWorkerGlobalScopePartial::installDurableStorage(isolate, world, global, interface);
579 } else if (executionContext->isServiceWorkerGlobalScope()) {
580 V8ServiceWorkerGlobalScope::installDurableStorage(isolate, world, gl obal, interface);
581 }
582 originTrialContext->setFeatureBindingsInstalled("DurableStorage");
583 }
584 }
585
586 void registerInitializeOriginTrialsForModules()
587 {
588 s_originalInitializeOriginTrialsFunction = setInitializeOriginTrialsFunction (&initializeOriginTrialsForModules);
589 }
535 } // namespace blink 590 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698