| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "modules/encryptedmedia/NavigatorRequestMediaKeySystemAccess.h" | 5 #include "modules/encryptedmedia/NavigatorRequestMediaKeySystemAccess.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 7 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 11 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/V8ThrowException.h" | 12 #include "bindings/core/v8/V8ThrowException.h" |
| 11 #include "core/dom/DOMException.h" | 13 #include "core/dom/DOMException.h" |
| 12 #include "core/dom/Document.h" | 14 #include "core/dom/Document.h" |
| 13 #include "core/dom/ExceptionCode.h" | 15 #include "core/dom/ExceptionCode.h" |
| 14 #include "core/frame/Deprecation.h" | 16 #include "core/frame/Deprecation.h" |
| 17 #include "core/frame/Settings.h" |
| 15 #include "core/inspector/ConsoleMessage.h" | 18 #include "core/inspector/ConsoleMessage.h" |
| 16 #include "modules/encryptedmedia/EncryptedMediaUtils.h" | 19 #include "modules/encryptedmedia/EncryptedMediaUtils.h" |
| 17 #include "modules/encryptedmedia/MediaKeySession.h" | 20 #include "modules/encryptedmedia/MediaKeySession.h" |
| 18 #include "modules/encryptedmedia/MediaKeySystemAccess.h" | 21 #include "modules/encryptedmedia/MediaKeySystemAccess.h" |
| 19 #include "modules/encryptedmedia/MediaKeysController.h" | 22 #include "modules/encryptedmedia/MediaKeysController.h" |
| 20 #include "platform/EncryptedMediaRequest.h" | 23 #include "platform/EncryptedMediaRequest.h" |
| 21 #include "platform/Histogram.h" | 24 #include "platform/Histogram.h" |
| 22 #include "platform/network/ParsedContentType.h" | 25 #include "platform/network/ParsedContentType.h" |
| 23 #include "public/platform/WebEncryptedMediaClient.h" | 26 #include "public/platform/WebEncryptedMediaClient.h" |
| 24 #include "public/platform/WebEncryptedMediaRequest.h" | 27 #include "public/platform/WebEncryptedMediaRequest.h" |
| 25 #include "public/platform/WebMediaKeySystemConfiguration.h" | 28 #include "public/platform/WebMediaKeySystemConfiguration.h" |
| 26 #include "public/platform/WebMediaKeySystemMediaCapability.h" | 29 #include "public/platform/WebMediaKeySystemMediaCapability.h" |
| 27 #include "public/platform/WebVector.h" | 30 #include "public/platform/WebVector.h" |
| 28 #include "wtf/PtrUtil.h" | 31 #include "wtf/PtrUtil.h" |
| 29 #include "wtf/Vector.h" | 32 #include "wtf/Vector.h" |
| 30 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
| 31 #include <algorithm> | |
| 32 | 34 |
| 33 namespace blink { | 35 namespace blink { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 static WebVector<WebEncryptedMediaInitDataType> convertInitDataTypes( | 39 static WebVector<WebEncryptedMediaInitDataType> convertInitDataTypes( |
| 38 const Vector<String>& initDataTypes) { | 40 const Vector<String>& initDataTypes) { |
| 39 WebVector<WebEncryptedMediaInitDataType> result(initDataTypes.size()); | 41 WebVector<WebEncryptedMediaInitDataType> result(initDataTypes.size()); |
| 40 for (size_t i = 0; i < initDataTypes.size(); ++i) | 42 for (size_t i = 0; i < initDataTypes.size(); ++i) |
| 41 result[i] = EncryptedMediaUtils::convertToInitDataType(initDataTypes[i]); | 43 result[i] = EncryptedMediaUtils::convertToInitDataType(initDataTypes[i]); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 299 |
| 298 } // namespace | 300 } // namespace |
| 299 | 301 |
| 300 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( | 302 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( |
| 301 ScriptState* scriptState, | 303 ScriptState* scriptState, |
| 302 Navigator& navigator, | 304 Navigator& navigator, |
| 303 const String& keySystem, | 305 const String& keySystem, |
| 304 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) { | 306 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) { |
| 305 DVLOG(3) << __func__; | 307 DVLOG(3) << __func__; |
| 306 | 308 |
| 309 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 310 Document* document = toDocument(executionContext); |
| 311 |
| 312 // If encrypted media is disabled, return a rejected promise. |
| 313 if (!document->settings() || |
| 314 !document->settings()->getEncryptedMediaEnabled()) { |
| 315 return ScriptPromise::rejectWithDOMException( |
| 316 scriptState, DOMException::create(NotSupportedError, |
| 317 "Encrypted media is disabled.")); |
| 318 } |
| 319 |
| 307 // From https://w3c.github.io/encrypted-media/#requestMediaKeySystemAccess | 320 // From https://w3c.github.io/encrypted-media/#requestMediaKeySystemAccess |
| 308 // When this method is invoked, the user agent must run the following steps: | 321 // When this method is invoked, the user agent must run the following steps: |
| 309 // 1. If keySystem is the empty string, return a promise rejected with a | 322 // 1. If keySystem is the empty string, return a promise rejected with a |
| 310 // newly created TypeError. | 323 // newly created TypeError. |
| 311 if (keySystem.isEmpty()) { | 324 if (keySystem.isEmpty()) { |
| 312 return ScriptPromise::reject( | 325 return ScriptPromise::reject( |
| 313 scriptState, | 326 scriptState, |
| 314 V8ThrowException::createTypeError(scriptState->isolate(), | 327 V8ThrowException::createTypeError(scriptState->isolate(), |
| 315 "The keySystem parameter is empty.")); | 328 "The keySystem parameter is empty.")); |
| 316 } | 329 } |
| 317 | 330 |
| 318 // 2. If supportedConfigurations is empty, return a promise rejected with | 331 // 2. If supportedConfigurations is empty, return a promise rejected with |
| 319 // a newly created TypeError. | 332 // a newly created TypeError. |
| 320 if (!supportedConfigurations.size()) { | 333 if (!supportedConfigurations.size()) { |
| 321 return ScriptPromise::reject( | 334 return ScriptPromise::reject( |
| 322 scriptState, V8ThrowException::createTypeError( | 335 scriptState, V8ThrowException::createTypeError( |
| 323 scriptState->isolate(), | 336 scriptState->isolate(), |
| 324 "The supportedConfigurations parameter is empty.")); | 337 "The supportedConfigurations parameter is empty.")); |
| 325 } | 338 } |
| 326 | 339 |
| 327 // Note: This method should only be exposed to secure contexts as indicated | 340 // Note: This method should only be exposed to secure contexts as indicated |
| 328 // by the [SecureContext] IDL attribute. Since that will break some existing | 341 // by the [SecureContext] IDL attribute. Since that will break some existing |
| 329 // sites, we simply keep track of sites that aren't secure and output a | 342 // sites, we simply keep track of sites that aren't secure and output a |
| 330 // deprecation message. | 343 // deprecation message. |
| 331 ExecutionContext* executionContext = scriptState->getExecutionContext(); | |
| 332 if (executionContext->isSecureContext()) { | 344 if (executionContext->isSecureContext()) { |
| 333 UseCounter::count(executionContext, UseCounter::EncryptedMediaSecureOrigin); | 345 UseCounter::count(executionContext, UseCounter::EncryptedMediaSecureOrigin); |
| 334 } else { | 346 } else { |
| 335 Deprecation::countDeprecation(executionContext, | 347 Deprecation::countDeprecation(executionContext, |
| 336 UseCounter::EncryptedMediaInsecureOrigin); | 348 UseCounter::EncryptedMediaInsecureOrigin); |
| 337 // TODO(ddorwin): Implement the following: | 349 // TODO(ddorwin): Implement the following: |
| 338 // Reject promise with a new DOMException whose name is NotSupportedError. | 350 // Reject promise with a new DOMException whose name is NotSupportedError. |
| 339 } | 351 } |
| 340 | 352 |
| 341 // 3. Let document be the calling context's Document. | 353 // 3. Let document be the calling context's Document. |
| 342 Document* document = toDocument(executionContext); | 354 // (Done at the begining of this function.) |
| 343 if (!document->page()) { | 355 if (!document->page()) { |
| 344 return ScriptPromise::rejectWithDOMException( | 356 return ScriptPromise::rejectWithDOMException( |
| 345 scriptState, | 357 scriptState, |
| 346 DOMException::create( | 358 DOMException::create( |
| 347 InvalidStateError, | 359 InvalidStateError, |
| 348 "The context provided is not associated with a page.")); | 360 "The context provided is not associated with a page.")); |
| 349 } | 361 } |
| 350 | 362 |
| 351 // 4. Let origin be the origin of document. | 363 // 4. Let origin be the origin of document. |
| 352 // (Passed with the execution context.) | 364 // (Passed with the execution context.) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 363 WebEncryptedMediaClient* mediaClient = | 375 WebEncryptedMediaClient* mediaClient = |
| 364 controller->encryptedMediaClient(executionContext); | 376 controller->encryptedMediaClient(executionContext); |
| 365 mediaClient->requestMediaKeySystemAccess( | 377 mediaClient->requestMediaKeySystemAccess( |
| 366 WebEncryptedMediaRequest(initializer)); | 378 WebEncryptedMediaRequest(initializer)); |
| 367 | 379 |
| 368 // 7. Return promise. | 380 // 7. Return promise. |
| 369 return promise; | 381 return promise; |
| 370 } | 382 } |
| 371 | 383 |
| 372 } // namespace blink | 384 } // namespace blink |
| OLD | NEW |