OLD | NEW |
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 Loading... |
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); |
| 264 if (!state) |
| 265 return; |
| 266 if (!frame->script().windowProxy(state->world())->isContextInitialized()
) |
| 267 return; |
| 268 v8::HandleScope handleScope(state->isolate()); |
| 269 installOriginTrials(state); |
| 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 installOriginTrials(state); |
| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 381 |
342 return failedValidationResult; | 382 return failedValidationResult; |
343 } | 383 } |
344 | 384 |
345 DEFINE_TRACE(OriginTrialContext) | 385 DEFINE_TRACE(OriginTrialContext) |
346 { | 386 { |
347 visitor->trace(m_host); | 387 visitor->trace(m_host); |
348 } | 388 } |
349 | 389 |
350 } // namespace blink | 390 } // namespace blink |
OLD | NEW |