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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/origin_trials/OriginTrialContext.h" 5 #include "core/origin_trials/OriginTrialContext.h"
6 6
7 #include "bindings/core/v8/ScriptController.h"
8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/WindowProxy.h"
10 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
11 #include "core/dom/Document.h"
7 #include "core/dom/ExecutionContext.h" 12 #include "core/dom/ExecutionContext.h"
13 #include "core/frame/LocalFrame.h"
14 #include "core/workers/WorkerGlobalScope.h"
8 #include "platform/Histogram.h" 15 #include "platform/Histogram.h"
9 #include "platform/RuntimeEnabledFeatures.h" 16 #include "platform/RuntimeEnabledFeatures.h"
10 #include "platform/weborigin/SecurityOrigin.h" 17 #include "platform/weborigin/SecurityOrigin.h"
11 #include "public/platform/Platform.h" 18 #include "public/platform/Platform.h"
12 #include "public/platform/WebOriginTrialTokenStatus.h" 19 #include "public/platform/WebOriginTrialTokenStatus.h"
13 #include "public/platform/WebSecurityOrigin.h" 20 #include "public/platform/WebSecurityOrigin.h"
14 #include "public/platform/WebTrialTokenValidator.h" 21 #include "public/platform/WebTrialTokenValidator.h"
15 #include "wtf/text/StringBuilder.h" 22 #include "wtf/text/StringBuilder.h"
16 23
24 #include <v8.h>
25
17 namespace blink { 26 namespace blink {
18 27
19 namespace { 28 namespace {
20 29
21 // The enum entries below are written to histograms and thus cannot be deleted 30 // The enum entries below are written to histograms and thus cannot be deleted
22 // or reordered. 31 // or reordered.
23 // New entries must be added immediately before the end. 32 // New entries must be added immediately before the end.
24 enum MessageGeneratedResult { 33 enum MessageGeneratedResult {
25 MessageGeneratedResultNotRequested = 0, 34 MessageGeneratedResultNotRequested = 0,
26 MessageGeneratedResultYes = 1, 35 MessageGeneratedResultYes = 1,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 if (!context || context->m_tokens.isEmpty()) 236 if (!context || context->m_tokens.isEmpty())
228 return nullptr; 237 return nullptr;
229 return std::unique_ptr<Vector<String>>(new Vector<String>(context->m_tokens) ); 238 return std::unique_ptr<Vector<String>>(new Vector<String>(context->m_tokens) );
230 } 239 }
231 240
232 241
233 void OriginTrialContext::addToken(const String& token) 242 void OriginTrialContext::addToken(const String& token)
234 { 243 {
235 if (!token.isEmpty()) 244 if (!token.isEmpty())
236 m_tokens.append(token); 245 m_tokens.append(token);
246 initializePendingTrials();
237 } 247 }
238 248
239 void OriginTrialContext::addTokens(const Vector<String>& tokens) 249 void OriginTrialContext::addTokens(const Vector<String>& tokens)
240 { 250 {
241 m_tokens.appendVector(tokens); 251 m_tokens.appendVector(tokens);
252 initializePendingTrials();
253 }
254
255 void OriginTrialContext::initializePendingTrials()
256 {
257 // TODO(iclelland): Factor this logic out to methods on the various
258 // execution contexts
259 if (m_host->isDocument()) {
260 LocalFrame* frame = toDocument(m_host.get())->frame();
261 if (!frame)
262 return;
263 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
264 if (!state)
265 return;
266 if (!frame->script().windowProxy(state->world())->isContextInitialized() )
267 return;
268 v8::HandleScope handleScope(state->isolate());
269 initializeOriginTrials(state->context(), state->world());
270 } else if (m_host->isWorkerGlobalScope()) {
271 WorkerOrWorkletScriptController* scriptController = toWorkerGlobalScope( m_host.get())->scriptController();
272 if (!scriptController)
273 return;
274 ScriptState* state = scriptController->getScriptState();
275 if (!state)
276 return;
277 if (!scriptController->isContextInitialized())
278 return;
279 v8::HandleScope handleScope(state->isolate());
280 initializeOriginTrials(state->context(), state->world());
281 }
242 } 282 }
243 283
244 void OriginTrialContext::setFeatureBindingsInstalled(const String& featureName) 284 void OriginTrialContext::setFeatureBindingsInstalled(const String& featureName)
245 { 285 {
246 m_bindingsInstalled.add(featureName); 286 m_bindingsInstalled.add(featureName);
247 } 287 }
248 288
249 bool OriginTrialContext::featureBindingsInstalled(const String& featureName) 289 bool OriginTrialContext::featureBindingsInstalled(const String& featureName)
250 { 290 {
251 return m_bindingsInstalled.contains(featureName); 291 return m_bindingsInstalled.contains(featureName);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 384
345 return failedValidationResult; 385 return failedValidationResult;
346 } 386 }
347 387
348 DEFINE_TRACE(OriginTrialContext) 388 DEFINE_TRACE(OriginTrialContext)
349 { 389 {
350 visitor->trace(m_host); 390 visitor->trace(m_host);
351 } 391 }
352 392
353 } // namespace blink 393 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698