Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / webcontentdecryptionmodule_impl.cc
index a9b201f..fa64ee7 100644 (file)
 #include "base/strings/string_util.h"
 #include "base/strings/utf_string_conversions.h"
 #include "content/renderer/media/cdm_session_adapter.h"
+#include "content/renderer/media/crypto/key_systems.h"
 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
 #include "media/base/media_keys.h"
+#include "third_party/WebKit/public/platform/WebString.h"
 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
+#include "url/gurl.h"
 
 #if defined(ENABLE_PEPPER_CDMS)
 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
@@ -28,27 +31,39 @@ class WebFrame;
 namespace content {
 
 WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create(
-    blink::WebFrame* frame,
+    blink::WebLocalFrame* frame,
     const blink::WebSecurityOrigin& security_origin,
     const base::string16& key_system) {
-  // TODO(jrummell): Use |security_origin| rather than using the document URL.
   DCHECK(frame);
   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 (!IsStringASCII(key_system)) {
+  if (!base::IsStringASCII(key_system)) {
     NOTREACHED();
     return NULL;
   }
 
+  std::string key_system_ascii = base::UTF16ToASCII(key_system);
+  if (!IsConcreteSupportedKeySystem(key_system_ascii))
+    return NULL;
+
+  // If unique security origin, don't try to create the CDM.
+  if (security_origin.isUnique() || security_origin.toString() == "null") {
+    DLOG(ERROR) << "CDM use not allowed for unique security origin.";
+    return NULL;
+  }
+
   scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter());
+  GURL security_origin_as_gurl(security_origin.toString());
+
   if (!adapter->Initialize(
 #if defined(ENABLE_PEPPER_CDMS)
           base::Bind(&PepperCdmWrapperImpl::Create, frame),
 #endif
-          base::UTF16ToASCII(key_system))) {
+          key_system_ascii,
+          security_origin_as_gurl)) {
     return NULL;
   }
 
@@ -57,8 +72,7 @@ WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create(
 
 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
     scoped_refptr<CdmSessionAdapter> adapter)
-    : adapter_(adapter) {
-}
+    : adapter_(adapter) {}
 
 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() {
 }
@@ -74,4 +88,10 @@ media::Decryptor* WebContentDecryptionModuleImpl::GetDecryptor() {
   return adapter_->GetDecryptor();
 }
 
+#if defined(OS_ANDROID)
+int WebContentDecryptionModuleImpl::GetCdmId() const {
+  return adapter_->GetCdmId();
+}
+#endif  // defined(OS_ANDROID)
+
 }  // namespace content