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

Side by Side Diff: third_party/WebKit/Source/modules/encryptedmedia/NavigatorRequestMediaKeySystemAccess.cpp

Issue 2681383003: media: Add a web preference to enable encrypted media (Closed)
Patch Set: Created 3 years, 10 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 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 324
323 } // namespace 325 } // namespace
324 326
325 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess( 327 ScriptPromise NavigatorRequestMediaKeySystemAccess::requestMediaKeySystemAccess(
326 ScriptState* scriptState, 328 ScriptState* scriptState,
327 Navigator& navigator, 329 Navigator& navigator,
328 const String& keySystem, 330 const String& keySystem,
329 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) { 331 const HeapVector<MediaKeySystemConfiguration>& supportedConfigurations) {
330 DVLOG(3) << __func__; 332 DVLOG(3) << __func__;
331 333
334 ExecutionContext* executionContext = scriptState->getExecutionContext();
335 Document* document = toDocument(executionContext);
336
337 // If encrypted media is disabled, return a rejected promise.
338 if (!document->settings() ||
339 !document->settings()->getEncryptedMediaEnabled()) {
340 return ScriptPromise::rejectWithDOMException(
341 scriptState, DOMException::create(NotSupportedError,
342 "Encrypted media is disabled."));
343 }
344
332 // From https://w3c.github.io/encrypted-media/#requestMediaKeySystemAccess 345 // From https://w3c.github.io/encrypted-media/#requestMediaKeySystemAccess
333 // When this method is invoked, the user agent must run the following steps: 346 // When this method is invoked, the user agent must run the following steps:
334 // 1. If keySystem is the empty string, return a promise rejected with a 347 // 1. If keySystem is the empty string, return a promise rejected with a
335 // newly created TypeError. 348 // newly created TypeError.
336 if (keySystem.isEmpty()) { 349 if (keySystem.isEmpty()) {
337 return ScriptPromise::reject( 350 return ScriptPromise::reject(
338 scriptState, 351 scriptState,
339 V8ThrowException::createTypeError(scriptState->isolate(), 352 V8ThrowException::createTypeError(scriptState->isolate(),
340 "The keySystem parameter is empty.")); 353 "The keySystem parameter is empty."));
341 } 354 }
342 355
343 // 2. If supportedConfigurations is empty, return a promise rejected with 356 // 2. If supportedConfigurations is empty, return a promise rejected with
344 // a newly created TypeError. 357 // a newly created TypeError.
345 if (!supportedConfigurations.size()) { 358 if (!supportedConfigurations.size()) {
346 return ScriptPromise::reject( 359 return ScriptPromise::reject(
347 scriptState, V8ThrowException::createTypeError( 360 scriptState, V8ThrowException::createTypeError(
348 scriptState->isolate(), 361 scriptState->isolate(),
349 "The supportedConfigurations parameter is empty.")); 362 "The supportedConfigurations parameter is empty."));
350 } 363 }
351 364
352 // Note: This method should only be exposed to secure contexts as indicated 365 // Note: This method should only be exposed to secure contexts as indicated
353 // by the [SecureContext] IDL attribute. Since that will break some existing 366 // by the [SecureContext] IDL attribute. Since that will break some existing
354 // sites, we simply keep track of sites that aren't secure and output a 367 // sites, we simply keep track of sites that aren't secure and output a
355 // deprecation message. 368 // deprecation message.
356 ExecutionContext* executionContext = scriptState->getExecutionContext();
357 if (executionContext->isSecureContext()) { 369 if (executionContext->isSecureContext()) {
358 UseCounter::count(executionContext, UseCounter::EncryptedMediaSecureOrigin); 370 UseCounter::count(executionContext, UseCounter::EncryptedMediaSecureOrigin);
359 } else { 371 } else {
360 Deprecation::countDeprecation(executionContext, 372 Deprecation::countDeprecation(executionContext,
361 UseCounter::EncryptedMediaInsecureOrigin); 373 UseCounter::EncryptedMediaInsecureOrigin);
362 // TODO(ddorwin): Implement the following: 374 // TODO(ddorwin): Implement the following:
363 // Reject promise with a new DOMException whose name is NotSupportedError. 375 // Reject promise with a new DOMException whose name is NotSupportedError.
364 } 376 }
365 377
366 // 3. Let document be the calling context's Document. 378 // 3. Let document be the calling context's Document.
367 Document* document = toDocument(executionContext); 379 // (Done at the begining of this function.)
368 if (!document->page()) { 380 if (!document->page()) {
369 return ScriptPromise::rejectWithDOMException( 381 return ScriptPromise::rejectWithDOMException(
370 scriptState, 382 scriptState,
371 DOMException::create( 383 DOMException::create(
372 InvalidStateError, 384 InvalidStateError,
373 "The context provided is not associated with a page.")); 385 "The context provided is not associated with a page."));
374 } 386 }
375 387
376 // 4. Let origin be the origin of document. 388 // 4. Let origin be the origin of document.
377 // (Passed with the execution context.) 389 // (Passed with the execution context.)
(...skipping 10 matching lines...) Expand all
388 WebEncryptedMediaClient* mediaClient = 400 WebEncryptedMediaClient* mediaClient =
389 controller->encryptedMediaClient(executionContext); 401 controller->encryptedMediaClient(executionContext);
390 mediaClient->requestMediaKeySystemAccess( 402 mediaClient->requestMediaKeySystemAccess(
391 WebEncryptedMediaRequest(initializer)); 403 WebEncryptedMediaRequest(initializer));
392 404
393 // 7. Return promise. 405 // 7. Return promise.
394 return promise; 406 return promise;
395 } 407 }
396 408
397 } // namespace blink 409 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/Settings.json5 ('k') | third_party/WebKit/Source/web/WebSettingsImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698