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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/encryptedmedia/MediaKeySystemAccess.cpp
diff --git a/Source/modules/encryptedmedia/MediaKeySystemAccess.cpp b/Source/modules/encryptedmedia/MediaKeySystemAccess.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..842ff8f97c6fcf0e8fb65300aa0d585e7a9ec04d
--- /dev/null
+++ b/Source/modules/encryptedmedia/MediaKeySystemAccess.cpp
@@ -0,0 +1,113 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/encryptedmedia/MediaKeySystemAccess.h"
+
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/core/v8/ScriptState.h"
+#include "core/dom/DOMException.h"
+#include "core/dom/Document.h"
+#include "core/dom/ExceptionCode.h"
+#include "modules/encryptedmedia/MediaKeys.h"
+#include "modules/encryptedmedia/MediaKeysController.h"
+#include "platform/Logging.h"
+#include "platform/Timer.h"
+#include "public/platform/WebContentDecryptionModule.h"
+
+namespace blink {
+
+// This class allows a MediaKeys object to be created asynchronously.
+class MediaKeysInitializer : public ScriptPromiseResolver {
+ WTF_MAKE_NONCOPYABLE(MediaKeysInitializer);
+
+public:
+ static ScriptPromise create(ScriptState*, const String& keySystem);
+ virtual ~MediaKeysInitializer();
+
+private:
+ MediaKeysInitializer(ScriptState*, const String& keySystem);
+ void timerFired(Timer<MediaKeysInitializer>*);
+
+ const String m_keySystem;
+ Timer<MediaKeysInitializer> m_timer;
+};
+
+ScriptPromise MediaKeysInitializer::create(ScriptState* scriptState, const String& keySystem)
+{
+ RefPtr<MediaKeysInitializer> initializer = adoptRef(new MediaKeysInitializer(scriptState, keySystem));
+ initializer->suspendIfNeeded();
+ initializer->keepAliveWhilePending();
+ return initializer->promise();
+}
+
+MediaKeysInitializer::MediaKeysInitializer(ScriptState* scriptState, const String& keySystem)
+ : ScriptPromiseResolver(scriptState)
+ , m_keySystem(keySystem)
+ , m_timer(this, &MediaKeysInitializer::timerFired)
+{
+ WTF_LOG(Media, "MediaKeysInitializer::MediaKeysInitializer");
+ // Start the timer so that MediaKeys can be created asynchronously.
+ m_timer.startOneShot(0, FROM_HERE);
+}
+
+MediaKeysInitializer::~MediaKeysInitializer()
+{
+ WTF_LOG(Media, "MediaKeysInitializer::~MediaKeysInitializer");
+}
+
+void MediaKeysInitializer::timerFired(Timer<MediaKeysInitializer>*)
+{
+ WTF_LOG(Media, "MediaKeysInitializer::timerFired");
+
+ // NOTE: Continued from step 2. of MediaKeySystemAccess::createMediaKeys().
+ // 2.1 Let cdm be the CDM corresponding to this object.
+ // 2.2 Load and initialize the cdm if necessary.
+ 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.
+ MediaKeysController* controller = MediaKeysController::from(document->page());
+ OwnPtr<WebContentDecryptionModule> cdm = controller->createContentDecryptionModule(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?
+
+ // 2.3 If cdm fails to load or initialize, reject promise with a new
+ // DOMException whose name is the appropriate error name.
+ if (!cdm) {
+ 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.
+ reject(DOMException::create(UnknownError, message));
+ return;
+ }
+
+ // 2.4 Let media keys be a new MediaKeys object.
+ MediaKeys* mediaKeys = new MediaKeys(executionContext(), m_keySystem, cdm.release());
+
+ // 2.5 Resolve promise with media keys.
+ resolve(mediaKeys);
+
+ // Note: As soon as the promise is resolved (or rejected), the
+ // ScriptPromiseResolver object (|this|) is freed. So access to
+ // any members will crash once the promise is fulfilled.
+}
+
+MediaKeySystemAccess::MediaKeySystemAccess(const String& keySystem)
+ : 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.
+{
+}
+
+MediaKeySystemAccess::~MediaKeySystemAccess()
+{
+}
+
+ScriptPromise MediaKeySystemAccess::createMediaKeys(ScriptState* scriptState)
+{
+ // From https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#widl-MediaKeySystemAccess-createMediaKeys-Promise-MediaKeys
+ // When this method is invoked, the user agent must run the following steps:
+ // 1. Let promise be a new promise.
+ // 2. Asynchronously create and initialize the MediaKeys object.
+ // 3. Return promise.
+ return MediaKeysInitializer::create(scriptState, m_keySystem);
+}
+
+void MediaKeySystemAccess::trace(Visitor*)
+{
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698