| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" | 5 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
| 6 | 6 |
| 7 #include <map> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 8 #include "base/bind.h" |
| 12 #include "base/logging.h" | 9 #include "base/logging.h" |
| 13 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 15 #include "content/renderer/media/cdm_session_adapter.h" | 12 #include "content/renderer/media/cdm_session_adapter.h" |
| 16 #include "content/renderer/media/crypto/key_systems.h" | 13 #include "content/renderer/media/crypto/key_systems.h" |
| 17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" | 14 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" |
| 18 #include "media/base/cdm_promise.h" | 15 #include "media/base/cdm_promise.h" |
| 19 #include "media/base/media_keys.h" | 16 #include "media/base/media_keys.h" |
| 20 #include "media/blink/cdm_result_promise.h" | 17 #include "media/blink/cdm_result_promise.h" |
| 21 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 22 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 19 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 23 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 24 | 21 |
| 25 #if defined(ENABLE_PEPPER_CDMS) | |
| 26 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" | |
| 27 #endif | |
| 28 | |
| 29 namespace content { | 22 namespace content { |
| 30 | 23 |
| 31 WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create( | 24 WebContentDecryptionModuleImpl* WebContentDecryptionModuleImpl::Create( |
| 32 #if defined(ENABLE_PEPPER_CDMS) | 25 scoped_ptr<media::CdmFactory> cdm_factory, |
| 33 blink::WebLocalFrame* frame, | |
| 34 #elif defined(ENABLE_BROWSER_CDMS) | |
| 35 RendererCdmManager* manager, | |
| 36 #endif | |
| 37 const blink::WebSecurityOrigin& security_origin, | 26 const blink::WebSecurityOrigin& security_origin, |
| 38 const base::string16& key_system) { | 27 const base::string16& key_system) { |
| 39 #if defined(ENABLE_PEPPER_CDMS) | 28 DCHECK(cdm_factory); |
| 40 DCHECK(frame); | |
| 41 #elif defined(ENABLE_BROWSER_CDMS) | |
| 42 DCHECK(manager); | |
| 43 #endif | |
| 44 DCHECK(!security_origin.isNull()); | 29 DCHECK(!security_origin.isNull()); |
| 45 DCHECK(!key_system.empty()); | 30 DCHECK(!key_system.empty()); |
| 46 | 31 |
| 47 // TODO(ddorwin): Guard against this in supported types check and remove this. | 32 // TODO(ddorwin): Guard against this in supported types check and remove this. |
| 48 // Chromium only supports ASCII key systems. | 33 // Chromium only supports ASCII key systems. |
| 49 if (!base::IsStringASCII(key_system)) { | 34 if (!base::IsStringASCII(key_system)) { |
| 50 NOTREACHED(); | 35 NOTREACHED(); |
| 51 return NULL; | 36 return NULL; |
| 52 } | 37 } |
| 53 | 38 |
| 54 std::string key_system_ascii = base::UTF16ToASCII(key_system); | 39 std::string key_system_ascii = base::UTF16ToASCII(key_system); |
| 55 if (!IsConcreteSupportedKeySystem(key_system_ascii)) | 40 if (!IsConcreteSupportedKeySystem(key_system_ascii)) |
| 56 return NULL; | 41 return NULL; |
| 57 | 42 |
| 58 // If unique security origin, don't try to create the CDM. | 43 // If unique security origin, don't try to create the CDM. |
| 59 if (security_origin.isUnique() || security_origin.toString() == "null") { | 44 if (security_origin.isUnique() || security_origin.toString() == "null") { |
| 60 DLOG(ERROR) << "CDM use not allowed for unique security origin."; | 45 DLOG(ERROR) << "CDM use not allowed for unique security origin."; |
| 61 return NULL; | 46 return NULL; |
| 62 } | 47 } |
| 63 | 48 |
| 64 scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter()); | 49 scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter()); |
| 65 GURL security_origin_as_gurl(security_origin.toString()); | 50 GURL security_origin_as_gurl(security_origin.toString()); |
| 66 | 51 |
| 67 if (!adapter->Initialize( | 52 if (!adapter->Initialize( |
| 68 #if defined(ENABLE_PEPPER_CDMS) | 53 cdm_factory.Pass(), key_system_ascii, security_origin_as_gurl)) { |
| 69 base::Bind(&PepperCdmWrapperImpl::Create, frame), | |
| 70 #elif defined(ENABLE_BROWSER_CDMS) | |
| 71 manager, | |
| 72 #endif | |
| 73 key_system_ascii, | |
| 74 security_origin_as_gurl)) { | |
| 75 return NULL; | 54 return NULL; |
| 76 } | 55 } |
| 77 | 56 |
| 78 return new WebContentDecryptionModuleImpl(adapter); | 57 return new WebContentDecryptionModuleImpl(adapter); |
| 79 } | 58 } |
| 80 | 59 |
| 81 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( | 60 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( |
| 82 scoped_refptr<CdmSessionAdapter> adapter) | 61 scoped_refptr<CdmSessionAdapter> adapter) |
| 83 : adapter_(adapter) { | 62 : adapter_(adapter) { |
| 84 } | 63 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 return adapter_->GetDecryptor(); | 95 return adapter_->GetDecryptor(); |
| 117 } | 96 } |
| 118 | 97 |
| 119 #if defined(ENABLE_BROWSER_CDMS) | 98 #if defined(ENABLE_BROWSER_CDMS) |
| 120 int WebContentDecryptionModuleImpl::GetCdmId() const { | 99 int WebContentDecryptionModuleImpl::GetCdmId() const { |
| 121 return adapter_->GetCdmId(); | 100 return adapter_->GetCdmId(); |
| 122 } | 101 } |
| 123 #endif // defined(ENABLE_BROWSER_CDMS) | 102 #endif // defined(ENABLE_BROWSER_CDMS) |
| 124 | 103 |
| 125 } // namespace content | 104 } // namespace content |
| OLD | NEW |