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

Side by Side Diff: Source/modules/encryptedmedia/MediaKeySystemAccess.cpp

Issue 665213002: Implement navigator.requestMediaKeySystemAccess() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add sequence Created 6 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/encryptedmedia/MediaKeySystemAccess.h"
7
8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h"
10 #include "core/dom/DOMException.h"
11 #include "core/dom/Document.h"
12 #include "core/dom/ExceptionCode.h"
13 #include "modules/encryptedmedia/MediaKeys.h"
14 #include "modules/encryptedmedia/MediaKeysController.h"
15 #include "platform/Logging.h"
16 #include "platform/Timer.h"
17 #include "public/platform/WebContentDecryptionModule.h"
18
19 namespace blink {
20
21 // This class allows a MediaKeys object to be created asynchronously.
22 class MediaKeysInitializer : public ScriptPromiseResolver {
23 WTF_MAKE_NONCOPYABLE(MediaKeysInitializer);
24
25 public:
26 static ScriptPromise create(ScriptState*, const String& keySystem);
27 virtual ~MediaKeysInitializer();
28
29 private:
30 MediaKeysInitializer(ScriptState*, const String& keySystem);
31 void timerFired(Timer<MediaKeysInitializer>*);
32
33 const String m_keySystem;
34 Timer<MediaKeysInitializer> m_timer;
35 };
36
37 ScriptPromise MediaKeysInitializer::create(ScriptState* scriptState, const Strin g& keySystem)
38 {
39 RefPtr<MediaKeysInitializer> initializer = adoptRef(new MediaKeysInitializer (scriptState, keySystem));
40 initializer->suspendIfNeeded();
41 initializer->keepAliveWhilePending();
42 return initializer->promise();
43 }
44
45 MediaKeysInitializer::MediaKeysInitializer(ScriptState* scriptState, const Strin g& keySystem)
46 : ScriptPromiseResolver(scriptState)
47 , m_keySystem(keySystem)
48 , m_timer(this, &MediaKeysInitializer::timerFired)
49 {
50 WTF_LOG(Media, "MediaKeysInitializer::MediaKeysInitializer");
51 // Start the timer so that MediaKeys can be created asynchronously.
52 m_timer.startOneShot(0, FROM_HERE);
53 }
54
55 MediaKeysInitializer::~MediaKeysInitializer()
56 {
57 WTF_LOG(Media, "MediaKeysInitializer::~MediaKeysInitializer");
58 }
59
60 void MediaKeysInitializer::timerFired(Timer<MediaKeysInitializer>*)
61 {
62 WTF_LOG(Media, "MediaKeysInitializer::timerFired");
63
64 // NOTE: Continued from step 2. of MediaKeySystemAccess::createMediaKeys().
65 // 2.1 Let cdm be the CDM corresponding to this object.
66 // 2.2 Load and initialize the cdm if necessary.
67 Document* document = toDocument(executionContext());
ddorwin 2014/10/22 22:18:54 OOC, should we be saving the execution context in
jrummell 2014/10/23 01:20:02 The execution context is part of ScriptState.
68 MediaKeysController* controller = MediaKeysController::from(document->page() );
69 OwnPtr<WebContentDecryptionModule> cdm = controller->createContentDecryption Module(executionContext(), m_keySystem);
ddorwin 2014/10/22 22:18:54 Maybe we should modify the creation function to re
jrummell 2014/10/23 01:20:03 Added FIXME. Also should it be async?
70
71 // 2.3 If cdm fails to load or initialize, reject promise with a new
72 // DOMException whose name is the appropriate error name.
73 if (!cdm) {
74 String message("A content decryption module could not be loaded for the '" + m_keySystem + "' key system.");
ddorwin 2014/10/22 22:18:54 I think it's more accurate to say "A CDM instance
jrummell 2014/10/23 01:20:02 Done.
75 reject(DOMException::create(UnknownError, message));
76 return;
77 }
78
79 // 2.4 Let media keys be a new MediaKeys object.
80 MediaKeys* mediaKeys = new MediaKeys(executionContext(), m_keySystem, cdm.re lease());
81
82 // 2.5 Resolve promise with media keys.
83 resolve(mediaKeys);
84
85 // Note: As soon as the promise is resolved (or rejected), the
86 // ScriptPromiseResolver object (|this|) is freed. So access to
87 // any members will crash once the promise is fulfilled.
88 }
89
90 MediaKeySystemAccess::MediaKeySystemAccess(const String& keySystem)
91 : m_keySystem(keySystem)
ddorwin 2014/10/22 22:18:54 I think it would be better if the request method c
jrummell 2014/10/23 01:20:02 Done.
92 {
93 }
94
95 MediaKeySystemAccess::~MediaKeySystemAccess()
96 {
97 }
98
99 ScriptPromise MediaKeySystemAccess::createMediaKeys(ScriptState* scriptState)
100 {
101 // From https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/e ncrypted-media.html#widl-MediaKeySystemAccess-createMediaKeys-Promise-MediaKeys
102 // When this method is invoked, the user agent must run the following steps:
103 // 1. Let promise be a new promise.
104 // 2. Asynchronously create and initialize the MediaKeys object.
105 // 3. Return promise.
106 return MediaKeysInitializer::create(scriptState, m_keySystem);
107 }
108
109 void MediaKeySystemAccess::trace(Visitor*)
110 {
111 }
112
113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698