summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorjrummell <jrummell@chromium.org>2014-12-17 17:08:50 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-18 01:09:31 +0000
commit109c3a60b30e295539e699a81b213a642d5d2907 (patch)
tree4a60a80d42576c48318ca7a40d0a803ebbf28a10 /media
parentdad76e2e45684ba3816479e07dc9e52618ec482e (diff)
downloadchromium_src-109c3a60b30e295539e699a81b213a642d5d2907.zip
chromium_src-109c3a60b30e295539e699a81b213a642d5d2907.tar.gz
chromium_src-109c3a60b30e295539e699a81b213a642d5d2907.tar.bz2
Changes to support WebEncryptedMediaClient.
RenderFrameImpl now has a WebEncryptedMediaClientImpl object lazily initialized. This object can be used to create the CDM (after doing the necessary checks which are currently missing). WebContentDecryptionModuleImpl::Create() now supports a WebContentDecryptionModuleResult parameter to report success or errors back to blink. BUG=224786, 425186 TEST=existing EME tests pass Review URL: https://codereview.chromium.org/733743002 Cr-Commit-Position: refs/heads/master@{#308906}
Diffstat (limited to 'media')
-rw-r--r--media/blink/BUILD.gn4
-rw-r--r--media/blink/media_blink.gyp4
-rw-r--r--media/blink/webcontentdecryptionmodule_impl.cc56
-rw-r--r--media/blink/webcontentdecryptionmodule_impl.h5
-rw-r--r--media/blink/webcontentdecryptionmoduleaccess_impl.cc57
-rw-r--r--media/blink/webcontentdecryptionmoduleaccess_impl.h49
-rw-r--r--media/blink/webcontentdecryptionmodulesession_impl.cc2
-rw-r--r--media/blink/webencryptedmediaclient_impl.cc91
-rw-r--r--media/blink/webencryptedmediaclient_impl.h32
9 files changed, 298 insertions, 2 deletions
diff --git a/media/blink/BUILD.gn b/media/blink/BUILD.gn
index 5d3a60c..f9f5f98 100644
--- a/media/blink/BUILD.gn
+++ b/media/blink/BUILD.gn
@@ -47,8 +47,12 @@ component("blink") {
"webaudiosourceprovider_impl.h",
"webcontentdecryptionmodule_impl.cc",
"webcontentdecryptionmodule_impl.h",
+ "webcontentdecryptionmoduleaccess_impl.cc",
+ "webcontentdecryptionmoduleaccess_impl.h",
"webcontentdecryptionmodulesession_impl.cc",
"webcontentdecryptionmodulesession_impl.h",
+ "webencryptedmediaclient_impl.cc",
+ "webencryptedmediaclient_impl.h",
"webinbandtexttrack_impl.cc",
"webinbandtexttrack_impl.h",
"webmediaplayer_delegate.h",
diff --git a/media/blink/media_blink.gyp b/media/blink/media_blink.gyp
index 5307971..35d0480 100644
--- a/media/blink/media_blink.gyp
+++ b/media/blink/media_blink.gyp
@@ -51,8 +51,12 @@
'webaudiosourceprovider_impl.h',
'webcontentdecryptionmodule_impl.cc',
'webcontentdecryptionmodule_impl.h',
+ 'webcontentdecryptionmoduleaccess_impl.cc',
+ 'webcontentdecryptionmoduleaccess_impl.h',
'webcontentdecryptionmodulesession_impl.cc',
'webcontentdecryptionmodulesession_impl.h',
+ "webencryptedmediaclient_impl.cc",
+ "webencryptedmediaclient_impl.h",
'webinbandtexttrack_impl.cc',
'webinbandtexttrack_impl.h',
'webmediaplayer_delegate.h',
diff --git a/media/blink/webcontentdecryptionmodule_impl.cc b/media/blink/webcontentdecryptionmodule_impl.cc
index e2fa8aa..9d54f68 100644
--- a/media/blink/webcontentdecryptionmodule_impl.cc
+++ b/media/blink/webcontentdecryptionmodule_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "media/blink/webcontentdecryptionmodule_impl.h"
+#include "webcontentdecryptionmodule_impl.h"
#include "base/basictypes.h"
#include "base/bind.h"
@@ -22,6 +22,7 @@
namespace media {
+// TODO(jrummell): Remove once WebContentDecryptionModuleResult always passed.
WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create(
CdmFactory* cdm_factory,
const blink::WebSecurityOrigin& security_origin,
@@ -57,6 +58,59 @@ WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create(
return new WebContentDecryptionModuleImpl(adapter);
}
+void WebContentDecryptionModuleImpl::Create(
+ media::CdmFactory* cdm_factory,
+ const blink::WebSecurityOrigin& security_origin,
+ const base::string16& key_system,
+ blink::WebContentDecryptionModuleResult result) {
+ DCHECK(!security_origin.isNull());
+ DCHECK(!key_system.empty());
+
+ // TODO(ddorwin): Guard against this in supported types check and remove this.
+ // Chromium only supports ASCII key systems.
+ if (!base::IsStringASCII(key_system)) {
+ NOTREACHED();
+ result.completeWithError(
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
+ "Invalid keysystem.");
+ return;
+ }
+
+ std::string key_system_ascii = base::UTF16ToASCII(key_system);
+ if (!media::IsConcreteSupportedKeySystem(key_system_ascii)) {
+ std::string message =
+ "Keysystem '" + key_system_ascii + "' is not supported.";
+ result.completeWithError(
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
+ blink::WebString::fromUTF8(message));
+ return;
+ }
+
+ // If unique security origin, don't try to create the CDM.
+ if (security_origin.isUnique() || security_origin.toString() == "null") {
+ result.completeWithError(
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
+ "CDM use not allowed for unique security origin.");
+ return;
+ }
+
+ GURL security_origin_as_gurl(security_origin.toString());
+ scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter());
+
+ // TODO(jrummell): Pass WebContentDecryptionModuleResult (or similar) to
+ // Initialize() so that more specific errors can be reported.
+ if (!adapter->Initialize(cdm_factory, key_system_ascii,
+ security_origin_as_gurl)) {
+ result.completeWithError(
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
+ "Failed to initialize CDM.");
+ return;
+ }
+
+ result.completeWithContentDecryptionModule(
+ new WebContentDecryptionModuleImpl(adapter));
+}
+
WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
scoped_refptr<CdmSessionAdapter> adapter)
: adapter_(adapter) {
diff --git a/media/blink/webcontentdecryptionmodule_impl.h b/media/blink/webcontentdecryptionmodule_impl.h
index bf1915e..a7730d1 100644
--- a/media/blink/webcontentdecryptionmodule_impl.h
+++ b/media/blink/webcontentdecryptionmodule_impl.h
@@ -29,10 +29,15 @@ class WebContentDecryptionModuleSessionImpl;
class MEDIA_EXPORT WebContentDecryptionModuleImpl
: public blink::WebContentDecryptionModule {
public:
+ // TODO(jrummell): Remove once WebContentDecryptionModuleResult always passed.
static WebContentDecryptionModuleImpl* Create(
CdmFactory* cdm_factory,
const blink::WebSecurityOrigin& security_origin,
const base::string16& key_system);
+ static void Create(CdmFactory* cdm_factory,
+ const blink::WebSecurityOrigin& security_origin,
+ const base::string16& key_system,
+ blink::WebContentDecryptionModuleResult result);
virtual ~WebContentDecryptionModuleImpl();
diff --git a/media/blink/webcontentdecryptionmoduleaccess_impl.cc b/media/blink/webcontentdecryptionmoduleaccess_impl.cc
new file mode 100644
index 0000000..9971829
--- /dev/null
+++ b/media/blink/webcontentdecryptionmoduleaccess_impl.cc
@@ -0,0 +1,57 @@
+// Copyright 2013 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 "webcontentdecryptionmoduleaccess_impl.h"
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
+#include "webcontentdecryptionmodule_impl.h"
+
+namespace media {
+
+// The caller owns the created cdm (passed back using |result|).
+static void CreateCdm(CdmFactory* cdm_factory,
+ blink::WebSecurityOrigin security_origin,
+ blink::WebString key_system,
+ blink::WebContentDecryptionModuleResult result) {
+ WebContentDecryptionModuleImpl::Create(cdm_factory, security_origin,
+ key_system, result);
+}
+
+WebContentDecryptionModuleAccessImpl*
+WebContentDecryptionModuleAccessImpl::Create(
+ const blink::WebString& key_system,
+ const blink::WebSecurityOrigin& security_origin,
+ CdmFactory* cdm_factory) {
+ return new WebContentDecryptionModuleAccessImpl(key_system, security_origin,
+ cdm_factory);
+}
+
+WebContentDecryptionModuleAccessImpl::WebContentDecryptionModuleAccessImpl(
+ const blink::WebString& key_system,
+ const blink::WebSecurityOrigin& security_origin,
+ CdmFactory* cdm_factory)
+ : key_system_(key_system),
+ security_origin_(security_origin),
+ cdm_factory_(cdm_factory) {
+}
+
+WebContentDecryptionModuleAccessImpl::~WebContentDecryptionModuleAccessImpl() {
+}
+
+void WebContentDecryptionModuleAccessImpl::createContentDecryptionModule(
+ blink::WebContentDecryptionModuleResult result) {
+ // This method needs to run asynchronously, as it may need to load the CDM.
+ // As this object's lifetime is controlled by MediaKeySystemAccess on the
+ // blink side, copy all values needed by CreateCdm() in case the blink object
+ // gets garbage-collected.
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE, base::Bind(&CreateCdm, cdm_factory_, security_origin_,
+ key_system_, result));
+}
+
+} // namespace media
diff --git a/media/blink/webcontentdecryptionmoduleaccess_impl.h b/media/blink/webcontentdecryptionmoduleaccess_impl.h
new file mode 100644
index 0000000..2d288ca
--- /dev/null
+++ b/media/blink/webcontentdecryptionmoduleaccess_impl.h
@@ -0,0 +1,49 @@
+// Copyright 2013 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.
+
+#ifndef MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULEACCESS_IMPL_H_
+#define MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULEACCESS_IMPL_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "media/base/cdm_factory.h"
+#include "third_party/WebKit/public/platform/WebContentDecryptionModuleAccess.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
+
+namespace blink {
+class WebLocalFrame;
+}
+
+namespace media {
+
+class WebContentDecryptionModuleAccessImpl
+ : public blink::WebContentDecryptionModuleAccess {
+ public:
+ static WebContentDecryptionModuleAccessImpl* Create(
+ const blink::WebString& key_system,
+ const blink::WebSecurityOrigin& security_origin,
+ CdmFactory* cdm_factory);
+ virtual ~WebContentDecryptionModuleAccessImpl();
+
+ // blink::WebContentDecryptionModuleAccess interface.
+ virtual void createContentDecryptionModule(
+ blink::WebContentDecryptionModuleResult result) override;
+
+ private:
+ WebContentDecryptionModuleAccessImpl(
+ const blink::WebString& key_system,
+ const blink::WebSecurityOrigin& security_origin,
+ CdmFactory* cdm_factory);
+
+ DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleAccessImpl);
+
+ blink::WebString key_system_;
+ blink::WebSecurityOrigin security_origin_;
+ CdmFactory* cdm_factory_;
+};
+
+} // namespace media
+
+#endif // MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULEACCESS_IMPL_H_
diff --git a/media/blink/webcontentdecryptionmodulesession_impl.cc b/media/blink/webcontentdecryptionmodulesession_impl.cc
index 58f163eb..74c117d 100644
--- a/media/blink/webcontentdecryptionmodulesession_impl.cc
+++ b/media/blink/webcontentdecryptionmodulesession_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "media/blink/webcontentdecryptionmodulesession_impl.h"
+#include "webcontentdecryptionmodulesession_impl.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/webencryptedmediaclient_impl.cc
new file mode 100644
index 0000000..09cb0e5
--- /dev/null
+++ b/media/blink/webencryptedmediaclient_impl.cc
@@ -0,0 +1,91 @@
+// 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 "webencryptedmediaclient_impl.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h"
+#include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+#include "third_party/WebKit/public/platform/WebVector.h"
+#include "webcontentdecryptionmoduleaccess_impl.h"
+
+namespace media {
+
+static bool IsKeySystemSupportedWithInitDataType(
+ const blink::WebString& keySystem,
+ const blink::WebString& initDataType) {
+ DCHECK(!keySystem.isEmpty());
+ return true;
+}
+
+WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl(
+ scoped_ptr<CdmFactory> cdm_factory)
+ : cdm_factory_(cdm_factory.Pass()) {
+}
+
+WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() {
+}
+
+void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess(
+ blink::WebEncryptedMediaRequest request) {
+ // TODO(jrummell): This should be asynchronous.
+
+ // Continued from requestMediaKeySystemAccess(), step 5, from
+ // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#requestmediakeysystemaccess
+ //
+ // 5.1 If keySystem is not supported or not allowed in the origin of the
+ // calling context's Document, return a promise rejected with a new
+ // DOMException whose name is NotSupportedError.
+ // (Handled by Chromium.)
+
+ // 5.2 If supportedConfigurations was not provided, resolve the promise
+ // with a new MediaKeySystemAccess object, execute the following steps:
+ size_t number_configs = request.supportedConfigurations().size();
+ if (!number_configs) {
+ // 5.2.1 Let access be a new MediaKeySystemAccess object, and initialize
+ // it as follows:
+ // 5.2.1.1 Set the keySystem attribute to keySystem.
+ // 5.2.2 Resolve promise with access and abort these steps.
+ request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
+ request.keySystem(), request.securityOrigin(), cdm_factory_.get()));
+ return;
+ }
+
+ // 5.3 For each element of supportedConfigurations:
+ // 5.3.1 Let combination be the element.
+ // 5.3.2 For each dictionary member in combination:
+ for (size_t i = 0; i < number_configs; ++i) {
+ const auto& combination = request.supportedConfigurations()[i];
+ // 5.3.2.1 If the member's value cannot be satisfied together in
+ // combination with the previous members, continue to the next
+ // iteration of the loop.
+ // 5.3.3 If keySystem is supported and allowed in the origin of the
+ // calling context's Document in the configuration specified by
+ // the combination of the values in combination, execute the
+ // following steps:
+ // FIXME: This test needs to be enhanced to use more values from
+ // combination.
+ for (size_t j = 0; j < combination.initDataTypes.size(); ++j) {
+ const auto& initDataType = combination.initDataTypes[j];
+ if (IsKeySystemSupportedWithInitDataType(request.keySystem(),
+ initDataType)) {
+ // 5.3.3.1 Let access be a new MediaKeySystemAccess object, and
+ // initialize it as follows:
+ // 5.3.3.1.1 Set the keySystem attribute to keySystem.
+ // 5.3.3.2 Resolve promise with access and abort these steps.
+ request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create(
+ request.keySystem(), request.securityOrigin(), cdm_factory_.get()));
+ return;
+ }
+ }
+ }
+
+ // 5.4 Reject promise with a new DOMException whose name is
+ // NotSupportedError.
+ request.requestNotSupported(
+ "There were no supported combinations in supportedConfigurations.");
+}
+
+} // namespace media
diff --git a/media/blink/webencryptedmediaclient_impl.h b/media/blink/webencryptedmediaclient_impl.h
new file mode 100644
index 0000000..2b4e9d5
--- /dev/null
+++ b/media/blink/webencryptedmediaclient_impl.h
@@ -0,0 +1,32 @@
+// 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.
+
+#ifndef MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_
+#define MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "media/base/cdm_factory.h"
+#include "media/base/media_export.h"
+#include "third_party/WebKit/public/platform/WebEncryptedMediaClient.h"
+#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
+
+namespace media {
+
+class MEDIA_EXPORT WebEncryptedMediaClientImpl
+ : public blink::WebEncryptedMediaClient {
+ public:
+ WebEncryptedMediaClientImpl(scoped_ptr<CdmFactory> cdm_factory);
+ virtual ~WebEncryptedMediaClientImpl();
+
+ // WebEncryptedMediaClient implementation.
+ virtual void requestMediaKeySystemAccess(
+ blink::WebEncryptedMediaRequest request);
+
+ private:
+ scoped_ptr<CdmFactory> cdm_factory_;
+};
+
+} // namespace media
+
+#endif // MEDIA_BLINK_WEBENCRYPTEDMEDIACLIENT_IMPL_H_