Chromium Code Reviews| 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/crypto/render_cdm_factory.h" | 5 #include "content/renderer/media/crypto/render_cdm_factory.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/location.h" | 8 #include "base/location.h" | 
| 9 #include "base/logging.h" | 9 #include "base/logging.h" | 
| 10 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" | 
| 12 #include "media/base/cdm_promise.h" | |
| 11 #include "media/base/key_systems.h" | 13 #include "media/base/key_systems.h" | 
| 14 #include "media/base/media_keys.h" | |
| 12 #include "media/cdm/aes_decryptor.h" | 15 #include "media/cdm/aes_decryptor.h" | 
| 13 #include "url/gurl.h" | 16 #include "url/gurl.h" | 
| 14 #if defined(ENABLE_PEPPER_CDMS) | 17 #if defined(ENABLE_PEPPER_CDMS) | 
| 15 #include "content/renderer/media/crypto/ppapi_decryptor.h" | 18 #include "content/renderer/media/crypto/ppapi_decryptor.h" | 
| 16 #elif defined(ENABLE_BROWSER_CDMS) | 19 #elif defined(ENABLE_BROWSER_CDMS) | 
| 17 #include "content/renderer/media/crypto/proxy_media_keys.h" | 20 #include "content/renderer/media/crypto/proxy_media_keys.h" | 
| 18 #endif // defined(ENABLE_PEPPER_CDMS) | 21 #endif // defined(ENABLE_PEPPER_CDMS) | 
| 19 | 22 | 
| 20 namespace content { | 23 namespace content { | 
| 21 | 24 | 
| 25 class CdmInitializedPromise : public media::SimpleCdmPromise { | |
| 26 public: | |
| 27 CdmInitializedPromise(const RenderCdmFactory::CdmCreatedCB& cdm_created_cb, | |
| 28 scoped_ptr<media::MediaKeys> cdm) | |
| 29 : cdm_created_cb_(cdm_created_cb), cdm_(cdm.Pass()) { | |
| 30 } | |
| 31 | |
| 32 ~CdmInitializedPromise() override { | |
| 33 } | |
| 34 | |
| 35 void resolve() override { | |
| 36 MarkPromiseSettled(); | |
| 37 cdm_created_cb_.Run(cdm_.Pass()); | |
| 38 } | |
| 39 | |
| 40 void reject(media::MediaKeys::Exception exception_code, | |
| 41 uint32 system_code, | |
| 42 const std::string& error_message) override { | |
| 43 MarkPromiseSettled(); | |
| 44 cdm_created_cb_.Run(nullptr); | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 RenderCdmFactory::CdmCreatedCB cdm_created_cb_; | |
| 49 scoped_ptr<media::MediaKeys> cdm_; | |
| 50 }; | |
| 51 | |
| 22 RenderCdmFactory::RenderCdmFactory( | 52 RenderCdmFactory::RenderCdmFactory( | 
| 23 #if defined(ENABLE_PEPPER_CDMS) | 53 #if defined(ENABLE_PEPPER_CDMS) | 
| 24 const CreatePepperCdmCB& create_pepper_cdm_cb, | 54 const CreatePepperCdmCB& create_pepper_cdm_cb, | 
| 25 #elif defined(ENABLE_BROWSER_CDMS) | 55 #elif defined(ENABLE_BROWSER_CDMS) | 
| 26 RendererCdmManager* manager, | 56 RendererCdmManager* manager, | 
| 27 #endif // defined(ENABLE_PEPPER_CDMS) | 57 #endif // defined(ENABLE_PEPPER_CDMS) | 
| 28 RenderFrame* render_frame) | 58 RenderFrame* render_frame) | 
| 29 : RenderFrameObserver(render_frame) | 59 : RenderFrameObserver(render_frame) | 
| 30 #if defined(ENABLE_PEPPER_CDMS) | 60 #if defined(ENABLE_PEPPER_CDMS) | 
| 31 , create_pepper_cdm_cb_(create_pepper_cdm_cb) | 61 , create_pepper_cdm_cb_(create_pepper_cdm_cb) | 
| (...skipping 19 matching lines...) Expand all Loading... | |
| 51 const media::SessionExpirationUpdateCB& session_expiration_update_cb, | 81 const media::SessionExpirationUpdateCB& session_expiration_update_cb, | 
| 52 const CdmCreatedCB& cdm_created_cb) { | 82 const CdmCreatedCB& cdm_created_cb) { | 
| 53 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); | 
| 54 | 84 | 
| 55 if (!security_origin.is_valid()) { | 85 if (!security_origin.is_valid()) { | 
| 56 base::MessageLoopProxy::current()->PostTask( | 86 base::MessageLoopProxy::current()->PostTask( | 
| 57 FROM_HERE, base::Bind(cdm_created_cb, nullptr)); | 87 FROM_HERE, base::Bind(cdm_created_cb, nullptr)); | 
| 58 return; | 88 return; | 
| 59 } | 89 } | 
| 60 | 90 | 
| 61 scoped_ptr<media::MediaKeys> cdm; | |
| 62 | |
| 63 if (media::CanUseAesDecryptor(key_system)) { | 91 if (media::CanUseAesDecryptor(key_system)) { | 
| 64 // TODO(sandersd): Currently the prefixed API always allows distinctive | 92 // TODO(sandersd): Currently the prefixed API always allows distinctive | 
| 65 // identifiers and persistent state. Once that changes we can sanity check | 93 // identifiers and persistent state. Once that changes we can sanity check | 
| 66 // here that neither is allowed for AesDecryptor, since it does not support | 94 // here that neither is allowed for AesDecryptor, since it does not support | 
| 67 // them and should never be configured that way. http://crbug.com/455271 | 95 // them and should never be configured that way. http://crbug.com/455271 | 
| 68 cdm.reset(new media::AesDecryptor(security_origin, session_message_cb, | 96 scoped_ptr<media::MediaKeys> cdm( | 
| 69 session_closed_cb, | 97 new media::AesDecryptor(security_origin, session_message_cb, | 
| 70 session_keys_change_cb)); | 98 session_closed_cb, session_keys_change_cb)); | 
| 71 } else { | 99 base::MessageLoopProxy::current()->PostTask( | 
| 72 #if defined(ENABLE_PEPPER_CDMS) | 100 FROM_HERE, base::Bind(cdm_created_cb, base::Passed(&cdm))); | 
| 73 cdm = PpapiDecryptor::Create( | 101 return; | 
| 74 key_system, allow_distinctive_identifier, allow_persistent_state, | |
| 75 security_origin, create_pepper_cdm_cb_, session_message_cb, | |
| 76 session_closed_cb, legacy_session_error_cb, session_keys_change_cb, | |
| 77 session_expiration_update_cb); | |
| 78 #elif defined(ENABLE_BROWSER_CDMS) | |
| 79 DCHECK(allow_distinctive_identifier); | |
| 80 DCHECK(allow_persistent_state); | |
| 81 cdm = ProxyMediaKeys::Create( | |
| 82 key_system, security_origin, manager_, session_message_cb, | |
| 83 session_closed_cb, legacy_session_error_cb, session_keys_change_cb, | |
| 84 session_expiration_update_cb); | |
| 85 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 86 } | 102 } | 
| 87 | 103 | 
| 104 #if defined(ENABLE_PEPPER_CDMS) | |
| 105 scoped_ptr<PpapiDecryptor> cdm; | |
| 106 cdm = PpapiDecryptor::Create( | |
| 107 key_system, security_origin, create_pepper_cdm_cb_, session_message_cb, | |
| 108 session_closed_cb, legacy_session_error_cb, session_keys_change_cb, | |
| 109 session_expiration_update_cb); | |
| 110 if (!cdm) { | |
| 111 base::MessageLoopProxy::current()->PostTask( | |
| 112 FROM_HERE, base::Bind(cdm_created_cb, nullptr)); | |
| 113 return; | |
| 114 } | |
| 115 // PpapiDecryptor ownership passed to the promise, but keep a copy in order | |
| 116 // to call InitializeCdm(). | |
| 117 PpapiDecryptor* ppapi_decryptor = cdm.get(); | |
| 118 scoped_ptr<CdmInitializedPromise> promise( | |
| 119 new CdmInitializedPromise(cdm_created_cb, cdm.Pass())); | |
| 120 ppapi_decryptor->InitializeCdm(key_system, allow_distinctive_identifier, | |
| 
 
ddorwin
2015/04/27 23:52:18
If this is only called by us here, why not hide it
 
jrummell
2015/04/28 18:02:45
Changed to do all the work in ::Create(). Not retu
 
 | |
| 121 allow_persistent_state, promise.Pass()); | |
| 122 #elif defined(ENABLE_BROWSER_CDMS) | |
| 123 DCHECK(allow_distinctive_identifier); | |
| 124 DCHECK(allow_persistent_state); | |
| 125 scoped_ptr<ProxyMediaKeys> cdm; | |
| 126 cdm = ProxyMediaKeys::Create(manager_, session_message_cb, session_closed_cb, | |
| 127 legacy_session_error_cb, session_keys_change_cb, | |
| 128 session_expiration_update_cb); | |
| 129 if (!cdm) { | |
| 
 
ddorwin
2015/04/27 23:52:18
Duplicating this logic seems wrong.
 
 | |
| 130 base::MessageLoopProxy::current()->PostTask( | |
| 131 FROM_HERE, base::Bind(cdm_created_cb, nullptr)); | |
| 132 return; | |
| 133 } | |
| 134 // ProxyMediaKeys ownership passed to the promise, but keep a copy in order | |
| 135 // to call InitializeCdm(). | |
| 136 ProxyMediaKeys* proxy_media_keys = cdm.get(); | |
| 137 scoped_ptr<CdmInitializedPromise> promise( | |
| 138 new CdmInitializedPromise(cdm_created_cb, cdm.Pass())); | |
| 139 proxy_media_keys->InitializeCdm(key_system, security_origin, promise.Pass()); | |
| 140 #else | |
| 88 base::MessageLoopProxy::current()->PostTask( | 141 base::MessageLoopProxy::current()->PostTask( | 
| 89 FROM_HERE, base::Bind(cdm_created_cb, base::Passed(&cdm))); | 142 FROM_HERE, base::Bind(cdm_created_cb, nullptr)); | 
| 143 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 90 } | 144 } | 
| 91 | 145 | 
| 92 } // namespace content | 146 } // namespace content | 
| OLD | NEW |