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