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

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: updates 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..6aa2522cb9482ce61d98a4caa44c49bfa38031c0
--- /dev/null
+++ b/Source/modules/encryptedmedia/MediaKeySystemAccess.cpp
@@ -0,0 +1,119 @@
+// 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.
yhirano 2014/10/24 09:22:32 Can you place this class in an unnamed namespace?
jrummell 2014/10/24 22:43:22 Only by removing the logging. Done.
+class MediaKeysInitializer : public ScriptPromiseResolver {
haraken 2014/10/24 01:06:42 Add final.
jrummell 2014/10/24 22:43:22 Done.
+ 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.
yhirano 2014/10/24 09:22:32 I'm sorry if this is the second time, but can you
jrummell 2014/10/24 22:43:22 createContentDecryptionModule() may require the CD
yhirano 2014/10/27 02:26:28 Sorry I still don't understand... 1) What do you m
jrummell 2014/10/27 21:23:28 The layout tests all use ClearKey CDM, which is bu
yhirano 2014/10/28 02:02:01 OK, then please write a comment describing that he
jrummell 2014/10/28 17:45:44 Done.
yhirano 2014/10/29 01:44:26 As wrote above, please write in NavigatorRequestMe
jrummell 2014/10/29 18:24:43 Done.
+ 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());
+ MediaKeysController* controller = MediaKeysController::from(document->page());
+ // FIXME: Should this return an error code so there can be a better error
+ // message than UnknownError? Should it be asynchronous (maybe use
+ // webContentDecryptionModuleResult)?
+ OwnPtr<WebContentDecryptionModule> cdm = controller->createContentDecryptionModule(executionContext(), m_keySystem);
+
+ // 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 CDM instance could not be created for the '" + m_keySystem + "' key system.");
+ 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)
+{
+ // FIXME: There should be a Chromium-side equivalent object that contains
+ // any information, including the key system, from the results of the
+ // request call. It would also give us a place to put the createCDM() call.
+}
+
+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