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/webcontentdecryptionmodule_impl.h" | 5 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "content/renderer/media/crypto/content_decryption_module_factory.h" | 16 #include "content/renderer/media/crypto/content_decryption_module_factory.h" |
| 17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" | 17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" |
| 18 #include "media/base/media_keys.h" | 18 #include "media/base/media_keys.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 // Forwards the reference ID-based callbacks of the MediaKeys interface to the | 23 // Forwards the reference ID-based callbacks of the MediaKeys interface to the |
|
ddorwin
2013/12/05 00:44:52
update
jrummell
2013/12/06 23:42:35
Done.
| |
| 24 // appropriate session object. | 24 // appropriate session object. |
| 25 class ReferenceIdAdapter { | 25 class ReferenceIdAdapter { |
|
ddorwin
2013/12/05 00:44:52
Rename. TODO?
jrummell
2013/12/06 23:42:35
Implemented.
| |
| 26 public: | 26 public: |
| 27 ReferenceIdAdapter(); | 27 ReferenceIdAdapter(); |
| 28 ~ReferenceIdAdapter(); | 28 ~ReferenceIdAdapter(); |
| 29 | 29 |
| 30 // On success, creates a MediaKeys, returns it in |media_keys|, returns true. | 30 // On success, creates a MediaKeys, returns it in |media_keys|, returns true. |
| 31 bool Initialize(const std::string& key_system, | 31 bool Initialize(const std::string& key_system, |
| 32 scoped_ptr<media::MediaKeys>* media_keys); | 32 scoped_ptr<media::MediaKeys>* media_keys); |
| 33 | 33 |
| 34 // Adds a session to the internal map. Does not take ownership of the session. | 34 // Adds a session to the internal map. Does not take ownership of the session. |
| 35 void AddSession(uint32 reference_id, | 35 void AddSession(uint32 session_id, |
| 36 WebContentDecryptionModuleSessionImpl* session); | 36 WebContentDecryptionModuleSessionImpl* session); |
| 37 | 37 |
| 38 // Removes a session from the internal map. | 38 // Removes a session from the internal map. |
| 39 void RemoveSession(uint32 reference_id); | 39 void RemoveSession(uint32 session_id); |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap; | 42 typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap; |
| 43 | 43 |
| 44 // Callbacks for firing session events. | 44 // Callbacks for firing session events. |
| 45 void OnSessionCreated(uint32 reference_id, const std::string& session_id); | 45 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); |
| 46 void OnSessionMessage(uint32 reference_id, | 46 void OnSessionMessage(uint32 session_id, |
| 47 const std::vector<uint8>& message, | 47 const std::vector<uint8>& message, |
| 48 const std::string& destination_url); | 48 const std::string& destination_url); |
| 49 void OnSessionReady(uint32 reference_id); | 49 void OnSessionReady(uint32 session_id); |
| 50 void OnSessionClosed(uint32 reference_id); | 50 void OnSessionClosed(uint32 session_id); |
| 51 void OnSessionError(uint32 reference_id, | 51 void OnSessionError(uint32 session_id, |
| 52 media::MediaKeys::KeyError error_code, | 52 media::MediaKeys::KeyError error_code, |
| 53 int system_code); | 53 int system_code); |
| 54 | 54 |
| 55 // Helper function of the callbacks. | 55 // Helper function of the callbacks. |
| 56 WebContentDecryptionModuleSessionImpl* GetSession(uint32 reference_id); | 56 WebContentDecryptionModuleSessionImpl* GetSession(uint32 session_id); |
| 57 | 57 |
| 58 base::WeakPtrFactory<ReferenceIdAdapter> weak_ptr_factory_; | 58 base::WeakPtrFactory<ReferenceIdAdapter> weak_ptr_factory_; |
| 59 | 59 |
| 60 SessionMap sessions_; | 60 SessionMap sessions_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ReferenceIdAdapter); | 62 DISALLOW_COPY_AND_ASSIGN(ReferenceIdAdapter); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 ReferenceIdAdapter::ReferenceIdAdapter() | 65 ReferenceIdAdapter::ReferenceIdAdapter() |
| 66 : weak_ptr_factory_(this) { | 66 : weak_ptr_factory_(this) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 97 base::Bind(&ReferenceIdAdapter::OnSessionClosed, weak_this), | 97 base::Bind(&ReferenceIdAdapter::OnSessionClosed, weak_this), |
| 98 base::Bind(&ReferenceIdAdapter::OnSessionError, weak_this)); | 98 base::Bind(&ReferenceIdAdapter::OnSessionError, weak_this)); |
| 99 if (!created_media_keys) | 99 if (!created_media_keys) |
| 100 return false; | 100 return false; |
| 101 | 101 |
| 102 *media_keys = created_media_keys.Pass(); | 102 *media_keys = created_media_keys.Pass(); |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ReferenceIdAdapter::AddSession( | 106 void ReferenceIdAdapter::AddSession( |
| 107 uint32 reference_id, | 107 uint32 session_id, |
| 108 WebContentDecryptionModuleSessionImpl* session) { | 108 WebContentDecryptionModuleSessionImpl* session) { |
| 109 DCHECK(sessions_.find(reference_id) == sessions_.end()); | 109 DCHECK(sessions_.find(session_id) == sessions_.end()); |
| 110 sessions_[reference_id] = session; | 110 sessions_[session_id] = session; |
| 111 } | 111 } |
| 112 | 112 |
| 113 void ReferenceIdAdapter::RemoveSession(uint32 reference_id) { | 113 void ReferenceIdAdapter::RemoveSession(uint32 session_id) { |
| 114 DCHECK(sessions_.find(reference_id) != sessions_.end()); | 114 DCHECK(sessions_.find(session_id) != sessions_.end()); |
| 115 sessions_.erase(reference_id); | 115 sessions_.erase(session_id); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void ReferenceIdAdapter::OnSessionCreated(uint32 reference_id, | 118 void ReferenceIdAdapter::OnSessionCreated(uint32 session_id, |
| 119 const std::string& session_id) { | 119 const std::string& web_session_id) { |
| 120 GetSession(reference_id)->OnSessionCreated(session_id); | 120 GetSession(session_id)->OnSessionCreated(web_session_id); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void ReferenceIdAdapter::OnSessionMessage(uint32 reference_id, | 123 void ReferenceIdAdapter::OnSessionMessage(uint32 session_id, |
| 124 const std::vector<uint8>& message, | 124 const std::vector<uint8>& message, |
| 125 const std::string& destination_url) { | 125 const std::string& destination_url) { |
| 126 GetSession(reference_id)->OnSessionMessage(message, destination_url); | 126 GetSession(session_id)->OnSessionMessage(message, destination_url); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void ReferenceIdAdapter::OnSessionReady(uint32 reference_id) { | 129 void ReferenceIdAdapter::OnSessionReady(uint32 session_id) { |
| 130 GetSession(reference_id)->OnSessionReady(); | 130 GetSession(session_id)->OnSessionReady(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void ReferenceIdAdapter::OnSessionClosed(uint32 reference_id) { | 133 void ReferenceIdAdapter::OnSessionClosed(uint32 session_id) { |
| 134 GetSession(reference_id)->OnSessionClosed(); | 134 GetSession(session_id)->OnSessionClosed(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void ReferenceIdAdapter::OnSessionError(uint32 reference_id, | 137 void ReferenceIdAdapter::OnSessionError(uint32 session_id, |
| 138 media::MediaKeys::KeyError error_code, | 138 media::MediaKeys::KeyError error_code, |
| 139 int system_code) { | 139 int system_code) { |
| 140 GetSession(reference_id)->OnSessionError(error_code, system_code); | 140 GetSession(session_id)->OnSessionError(error_code, system_code); |
| 141 } | 141 } |
| 142 | 142 |
| 143 WebContentDecryptionModuleSessionImpl* ReferenceIdAdapter::GetSession( | 143 WebContentDecryptionModuleSessionImpl* ReferenceIdAdapter::GetSession( |
| 144 uint32 reference_id) { | 144 uint32 session_id) { |
| 145 DCHECK(sessions_.find(reference_id) != sessions_.end()); | 145 DCHECK(sessions_.find(session_id) != sessions_.end()); |
| 146 return sessions_[reference_id]; | 146 return sessions_[session_id]; |
| 147 } | 147 } |
| 148 | 148 |
| 149 //------------------------------------------------------------------------------ | 149 //------------------------------------------------------------------------------ |
| 150 | 150 |
| 151 WebContentDecryptionModuleImpl* | 151 WebContentDecryptionModuleImpl* |
| 152 WebContentDecryptionModuleImpl::Create(const string16& key_system) { | 152 WebContentDecryptionModuleImpl::Create(const string16& key_system) { |
| 153 // TODO(ddorwin): Guard against this in supported types check and remove this. | 153 // TODO(ddorwin): Guard against this in supported types check and remove this. |
| 154 // Chromium only supports ASCII key systems. | 154 // Chromium only supports ASCII key systems. |
| 155 if (!IsStringASCII(key_system)) { | 155 if (!IsStringASCII(key_system)) { |
| 156 NOTREACHED(); | 156 NOTREACHED(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 182 WebContentDecryptionModuleImpl::createSession( | 182 WebContentDecryptionModuleImpl::createSession( |
| 183 blink::WebContentDecryptionModuleSession::Client* client) { | 183 blink::WebContentDecryptionModuleSession::Client* client) { |
| 184 DCHECK(media_keys_); | 184 DCHECK(media_keys_); |
| 185 WebContentDecryptionModuleSessionImpl* session = | 185 WebContentDecryptionModuleSessionImpl* session = |
| 186 new WebContentDecryptionModuleSessionImpl( | 186 new WebContentDecryptionModuleSessionImpl( |
| 187 media_keys_.get(), | 187 media_keys_.get(), |
| 188 client, | 188 client, |
| 189 base::Bind(&WebContentDecryptionModuleImpl::OnSessionClosed, | 189 base::Bind(&WebContentDecryptionModuleImpl::OnSessionClosed, |
| 190 base::Unretained(this))); | 190 base::Unretained(this))); |
| 191 | 191 |
| 192 adapter_->AddSession(session->reference_id(), session); | 192 adapter_->AddSession(session->session_id(), session); |
| 193 return session; | 193 return session; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void WebContentDecryptionModuleImpl::OnSessionClosed(uint32 reference_id) { | 196 void WebContentDecryptionModuleImpl::OnSessionClosed(uint32 session_id) { |
| 197 adapter_->RemoveSession(reference_id); | 197 adapter_->RemoveSession(session_id); |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace content | 200 } // namespace content |
| OLD | NEW |