| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ | 6 #define CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/containers/scoped_ptr_hash_map.h" | 14 #include "base/containers/scoped_ptr_hash_map.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/common/media/cdm_messages_enums.h" | 17 #include "content/common/media/cdm_messages_enums.h" |
| 18 #include "content/public/browser/browser_message_filter.h" | 18 #include "content/public/browser/browser_message_filter.h" |
| 19 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
| 20 // TODO(xhwang): Drop this when KeyError is moved to a common header. | 20 #include "media/base/cdm_promise.h" |
| 21 #include "media/base/media_keys.h" | 21 #include "media/base/media_keys.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 class BrowserCdm; | 25 class BrowserCdm; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 // This class manages all CDM objects. It receives control operations from the | 30 // This class manages all CDM objects. It receives control operations from the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 bool OnMessageReceived(const IPC::Message& message) override; | 50 bool OnMessageReceived(const IPC::Message& message) override; |
| 51 | 51 |
| 52 media::BrowserCdm* GetCdm(int render_frame_id, int cdm_id); | 52 media::BrowserCdm* GetCdm(int render_frame_id, int cdm_id); |
| 53 | 53 |
| 54 // Notifies that the render frame has been deleted so that all CDMs belongs | 54 // Notifies that the render frame has been deleted so that all CDMs belongs |
| 55 // to this render frame needs to be destroyed as well. This is needed because | 55 // to this render frame needs to be destroyed as well. This is needed because |
| 56 // in some cases (e.g. fast termination of the renderer), the message to | 56 // in some cases (e.g. fast termination of the renderer), the message to |
| 57 // destroy the CDM will not be received. | 57 // destroy the CDM will not be received. |
| 58 void RenderFrameDeleted(int render_frame_id); | 58 void RenderFrameDeleted(int render_frame_id); |
| 59 | 59 |
| 60 // Promise handlers. |
| 61 template <typename... T> |
| 62 void ResolvePromise(int render_frame_id, |
| 63 int cdm_id, |
| 64 uint32_t promise_id, |
| 65 const T&... result); |
| 66 void RejectPromise(int render_frame_id, |
| 67 int cdm_id, |
| 68 uint32_t promise_id, |
| 69 media::MediaKeys::Exception exception, |
| 70 uint32_t system_code, |
| 71 const std::string& error_message); |
| 72 |
| 60 protected: | 73 protected: |
| 61 friend class base::RefCountedThreadSafe<BrowserCdmManager>; | 74 friend class base::RefCountedThreadSafe<BrowserCdmManager>; |
| 62 friend class base::DeleteHelper<BrowserCdmManager>; | 75 friend class base::DeleteHelper<BrowserCdmManager>; |
| 63 ~BrowserCdmManager() override; | 76 ~BrowserCdmManager() override; |
| 64 | 77 |
| 65 private: | 78 private: |
| 66 // CDM callbacks. | 79 // CDM callbacks. |
| 67 void OnSessionCreated(int render_frame_id, | |
| 68 int cdm_id, | |
| 69 uint32 session_id, | |
| 70 const std::string& web_session_id); | |
| 71 void OnSessionMessage(int render_frame_id, | 80 void OnSessionMessage(int render_frame_id, |
| 72 int cdm_id, | 81 int cdm_id, |
| 73 uint32 session_id, | 82 const std::string& session_id, |
| 74 const std::vector<uint8>& message, | 83 const std::vector<uint8>& message, |
| 75 const GURL& destination_url); | 84 const GURL& destination_url); |
| 76 void OnSessionReady(int render_frame_id, int cdm_id, uint32 session_id); | 85 void OnSessionClosed(int render_frame_id, |
| 77 void OnSessionClosed(int render_frame_id, int cdm_id, uint32 session_id); | 86 int cdm_id, |
| 87 const std::string& session_id); |
| 78 void OnSessionError(int render_frame_id, | 88 void OnSessionError(int render_frame_id, |
| 79 int cdm_id, | 89 int cdm_id, |
| 80 uint32 session_id, | 90 const std::string& session_id, |
| 81 media::MediaKeys::KeyError error_code, | 91 media::MediaKeys::Exception exception_code, |
| 82 uint32 system_code); | 92 uint32_t system_code, |
| 93 const std::string& error_message); |
| 94 void OnSessionKeysChange(int render_frame_id, |
| 95 int cdm_id, |
| 96 const std::string& session_id, |
| 97 bool has_additional_usable_key, |
| 98 media::CdmKeysInfo keys_info); |
| 99 void OnSessionExpirationUpdate(int render_frame_id, |
| 100 int cdm_id, |
| 101 const std::string& session_id, |
| 102 const base::Time& new_expiry_time); |
| 83 | 103 |
| 84 // Message handlers. | 104 // Message handlers. |
| 85 void OnInitializeCdm(int render_frame_id, | 105 void OnInitializeCdm(int render_frame_id, |
| 86 int cdm_id, | 106 int cdm_id, |
| 87 const std::string& key_system, | 107 const std::string& key_system, |
| 88 const GURL& frame_url); | 108 const GURL& frame_url); |
| 89 void OnCreateSession(int render_frame_id, | 109 void OnSetServerCertificate(int render_frame_id, |
| 90 int cdm_id, | 110 int cdm_id, |
| 91 uint32 session_id, | 111 uint32_t promise_id, |
| 92 CdmHostMsg_CreateSession_ContentType content_type, | 112 const std::vector<uint8_t>& certificate); |
| 93 const std::vector<uint8>& init_data); | 113 void OnCreateSessionAndGenerateRequest( |
| 114 int render_frame_id, |
| 115 int cdm_id, |
| 116 uint32_t promise_id, |
| 117 CdmHostMsg_CreateSession_InitDataType init_data_type, |
| 118 const std::vector<uint8>& init_data); |
| 94 void OnUpdateSession(int render_frame_id, | 119 void OnUpdateSession(int render_frame_id, |
| 95 int cdm_id, | 120 int cdm_id, |
| 96 uint32 session_id, | 121 uint32_t promise_id, |
| 122 const std::string& session_id, |
| 97 const std::vector<uint8>& response); | 123 const std::vector<uint8>& response); |
| 98 void OnReleaseSession(int render_frame_id, | 124 void OnCloseSession(int render_frame_id, |
| 99 int cdm_id, uint32 session_id); | 125 int cdm_id, |
| 126 uint32_t promise_id, |
| 127 const std::string& session_id); |
| 100 void OnDestroyCdm(int render_frame_id, int cdm_id); | 128 void OnDestroyCdm(int render_frame_id, int cdm_id); |
| 101 | 129 |
| 102 void SendSessionError(int render_frame_id, int cdm_id, uint32 session_id); | |
| 103 | |
| 104 // Adds a new CDM identified by |cdm_id| for the given |key_system| and | 130 // Adds a new CDM identified by |cdm_id| for the given |key_system| and |
| 105 // |security_origin|. | 131 // |security_origin|. |
| 106 void AddCdm(int render_frame_id, | 132 void AddCdm(int render_frame_id, |
| 107 int cdm_id, | 133 int cdm_id, |
| 108 const std::string& key_system, | 134 const std::string& key_system, |
| 109 const GURL& security_origin); | 135 const GURL& security_origin); |
| 110 | 136 |
| 111 // Removes all CDMs associated with |render_frame_id|. | 137 // Removes all CDMs associated with |render_frame_id|. |
| 112 void RemoveAllCdmForFrame(int render_frame_id); | 138 void RemoveAllCdmForFrame(int render_frame_id); |
| 113 | 139 |
| 114 // Removes the CDM with the specified id. | 140 // Removes the CDM with the specified id. |
| 115 void RemoveCdm(uint64 id); | 141 void RemoveCdm(uint64 id); |
| 116 | 142 |
| 117 // Requests permission for the given protected-media session (infobar). | 143 // Requests permission for the given protected-media session (infobar). |
| 118 void RequestSessionPermission(int render_frame_id, | 144 void RequestSessionPermission( |
| 119 const GURL& security_origin, | 145 int render_frame_id, |
| 120 int cdm_id, | 146 const GURL& security_origin, |
| 121 uint32 session_id, | 147 int cdm_id, |
| 122 const std::string& content_type, | 148 const std::string& init_data_type, |
| 123 const std::vector<uint8>& init_data); | 149 const std::vector<uint8>& init_data, |
| 150 scoped_ptr<media::NewSessionCdmPromise> promise); |
| 124 | 151 |
| 125 // If |permitted| is false, it does nothing but send | 152 // If |permitted| is false, it does nothing but send |
| 126 // |CdmMsg_SessionError| IPC message. | 153 // |CdmMsg_SessionError| IPC message. |
| 127 // The primary use case is infobar permission callback, i.e., when infobar | 154 // The primary use case is infobar permission callback, i.e., when infobar |
| 128 // can decide user's intention either from interacting with the actual info | 155 // can decide user's intention either from interacting with the actual info |
| 129 // bar or from the saved preference. | 156 // bar or from the saved preference. |
| 130 void CreateSessionIfPermitted(int render_frame_id, | 157 void CreateSessionIfPermitted(int render_frame_id, |
| 131 int cdm_id, | 158 int cdm_id, |
| 132 uint32 session_id, | 159 const std::string& init_data_type, |
| 133 const std::string& content_type, | |
| 134 const std::vector<uint8>& init_data, | 160 const std::vector<uint8>& init_data, |
| 161 scoped_ptr<media::NewSessionCdmPromise> promise, |
| 135 bool permitted); | 162 bool permitted); |
| 136 | 163 |
| 137 const int render_process_id_; | 164 const int render_process_id_; |
| 138 | 165 |
| 139 // TaskRunner to dispatch all CDM messages to. If it's NULL, all messages are | 166 // TaskRunner to dispatch all CDM messages to. If it's NULL, all messages are |
| 140 // dispatched to the browser UI thread. | 167 // dispatched to the browser UI thread. |
| 141 scoped_refptr<base::TaskRunner> task_runner_; | 168 scoped_refptr<base::TaskRunner> task_runner_; |
| 142 | 169 |
| 143 // The key in the following maps is a combination of |render_frame_id| and | 170 // The key in the following maps is a combination of |render_frame_id| and |
| 144 // |cdm_id|. | 171 // |cdm_id|. |
| 145 | 172 |
| 146 // Map of managed BrowserCdms. | 173 // Map of managed BrowserCdms. |
| 147 typedef base::ScopedPtrHashMap<uint64, media::BrowserCdm> CdmMap; | 174 typedef base::ScopedPtrHashMap<uint64, media::BrowserCdm> CdmMap; |
| 148 CdmMap cdm_map_; | 175 CdmMap cdm_map_; |
| 149 | 176 |
| 150 // Map of CDM's security origin. | 177 // Map of CDM's security origin. |
| 151 std::map<uint64, GURL> cdm_security_origin_map_; | 178 std::map<uint64, GURL> cdm_security_origin_map_; |
| 152 | 179 |
| 153 // Map of callbacks to cancel the permission request. | 180 // Map of callbacks to cancel the permission request. |
| 154 std::map<uint64, base::Closure> cdm_cancel_permission_map_; | 181 std::map<uint64, base::Closure> cdm_cancel_permission_map_; |
| 155 | 182 |
| 156 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager); | 183 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager); |
| 157 }; | 184 }; |
| 158 | 185 |
| 159 } // namespace content | 186 } // namespace content |
| 160 | 187 |
| 161 #endif // CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ | 188 #endif // CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ |
| OLD | NEW |