| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ | |
| 6 #define CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <memory> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/callback.h" | |
| 16 #include "base/macros.h" | |
| 17 #include "base/memory/weak_ptr.h" | |
| 18 #include "content/common/content_export.h" | |
| 19 #include "content/common/media/cdm_messages.h" | |
| 20 #include "content/common/media/cdm_messages_enums.h" | |
| 21 #include "content/public/browser/browser_message_filter.h" | |
| 22 #include "ipc/ipc_message.h" | |
| 23 #include "media/base/cdm_promise.h" | |
| 24 #include "media/base/eme_constants.h" | |
| 25 #include "media/base/media_keys.h" | |
| 26 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | |
| 27 #include "url/gurl.h" | |
| 28 | |
| 29 struct CdmHostMsg_CreateSessionAndGenerateRequest_Params; | |
| 30 | |
| 31 namespace media { | |
| 32 class CdmFactory; | |
| 33 } | |
| 34 | |
| 35 namespace content { | |
| 36 | |
| 37 // This class manages all CDM objects. It receives control operations from the | |
| 38 // the render process, and forwards them to corresponding CDM object. Callbacks | |
| 39 // from CDM objects are converted to IPCs and then sent to the render process. | |
| 40 class CONTENT_EXPORT BrowserCdmManager : public BrowserMessageFilter { | |
| 41 public: | |
| 42 // Returns the BrowserCdmManager associated with the |render_process_id|. | |
| 43 // Returns NULL if no BrowserCdmManager is associated. | |
| 44 static BrowserCdmManager* FromProcess(int render_process_id); | |
| 45 | |
| 46 // Constructs the BrowserCdmManager for |render_process_id| which runs on | |
| 47 // |task_runner|. | |
| 48 // If |task_runner| is not NULL, all CDM messages are posted to it. Otherwise, | |
| 49 // all messages are posted to the browser UI thread. | |
| 50 BrowserCdmManager(int render_process_id, | |
| 51 const scoped_refptr<base::TaskRunner>& task_runner); | |
| 52 | |
| 53 // BrowserMessageFilter implementations. | |
| 54 void OnDestruct() const override; | |
| 55 base::TaskRunner* OverrideTaskRunnerForMessage( | |
| 56 const IPC::Message& message) override; | |
| 57 bool OnMessageReceived(const IPC::Message& message) override; | |
| 58 | |
| 59 // Returns the CDM associated with |render_frame_id| and |cdm_id|. Returns | |
| 60 // null if no such CDM exists. | |
| 61 scoped_refptr<media::MediaKeys> GetCdm(int render_frame_id, int cdm_id) const; | |
| 62 | |
| 63 // Notifies that the render frame has been deleted so that all CDMs belongs | |
| 64 // to this render frame needs to be destroyed as well. This is needed because | |
| 65 // in some cases (e.g. fast termination of the renderer), the message to | |
| 66 // destroy the CDM will not be received. | |
| 67 void RenderFrameDeleted(int render_frame_id); | |
| 68 | |
| 69 // Promise handlers. | |
| 70 void ResolvePromise(int render_frame_id, int cdm_id, uint32_t promise_id); | |
| 71 void ResolvePromiseWithSession(int render_frame_id, | |
| 72 int cdm_id, | |
| 73 uint32_t promise_id, | |
| 74 const std::string& session_id); | |
| 75 void RejectPromise(int render_frame_id, | |
| 76 int cdm_id, | |
| 77 uint32_t promise_id, | |
| 78 media::MediaKeys::Exception exception, | |
| 79 uint32_t system_code, | |
| 80 const std::string& error_message); | |
| 81 | |
| 82 protected: | |
| 83 friend class base::RefCountedThreadSafe<BrowserCdmManager>; | |
| 84 friend class base::DeleteHelper<BrowserCdmManager>; | |
| 85 ~BrowserCdmManager() override; | |
| 86 | |
| 87 private: | |
| 88 // Returns the CdmFactory that can be used to create CDMs. Returns null if | |
| 89 // CDM is not supported. | |
| 90 media::CdmFactory* GetCdmFactory(); | |
| 91 | |
| 92 // CDM callbacks. | |
| 93 void OnSessionMessage(int render_frame_id, | |
| 94 int cdm_id, | |
| 95 const std::string& session_id, | |
| 96 media::MediaKeys::MessageType message_type, | |
| 97 const std::vector<uint8_t>& message); | |
| 98 void OnSessionClosed(int render_frame_id, | |
| 99 int cdm_id, | |
| 100 const std::string& session_id); | |
| 101 void OnSessionKeysChange(int render_frame_id, | |
| 102 int cdm_id, | |
| 103 const std::string& session_id, | |
| 104 bool has_additional_usable_key, | |
| 105 media::CdmKeysInfo keys_info); | |
| 106 void OnSessionExpirationUpdate(int render_frame_id, | |
| 107 int cdm_id, | |
| 108 const std::string& session_id, | |
| 109 const base::Time& new_expiry_time); | |
| 110 | |
| 111 // Message handlers. | |
| 112 void OnInitializeCdm(int render_frame_id, | |
| 113 int cdm_id, | |
| 114 uint32_t promise_id, | |
| 115 const CdmHostMsg_InitializeCdm_Params& params); | |
| 116 void OnSetServerCertificate(int render_frame_id, | |
| 117 int cdm_id, | |
| 118 uint32_t promise_id, | |
| 119 const std::vector<uint8_t>& certificate); | |
| 120 void OnCreateSessionAndGenerateRequest( | |
| 121 const CdmHostMsg_CreateSessionAndGenerateRequest_Params& params); | |
| 122 void OnLoadSession( | |
| 123 int render_frame_id, | |
| 124 int cdm_id, | |
| 125 uint32_t promise_id, | |
| 126 media::MediaKeys::SessionType session_type, | |
| 127 const std::string& session_id); | |
| 128 void OnUpdateSession(int render_frame_id, | |
| 129 int cdm_id, | |
| 130 uint32_t promise_id, | |
| 131 const std::string& session_id, | |
| 132 const std::vector<uint8_t>& response); | |
| 133 void OnCloseSession(int render_frame_id, | |
| 134 int cdm_id, | |
| 135 uint32_t promise_id, | |
| 136 const std::string& session_id); | |
| 137 void OnRemoveSession(int render_frame_id, | |
| 138 int cdm_id, | |
| 139 uint32_t promise_id, | |
| 140 const std::string& session_id); | |
| 141 void OnDestroyCdm(int render_frame_id, int cdm_id); | |
| 142 | |
| 143 // Callback for CDM creation. | |
| 144 void OnCdmCreated(int render_frame_id, | |
| 145 int cdm_id, | |
| 146 const GURL& security_origin, | |
| 147 std::unique_ptr<media::SimpleCdmPromise> promise, | |
| 148 const scoped_refptr<media::MediaKeys>& cdm, | |
| 149 const std::string& error_message); | |
| 150 | |
| 151 // Removes all CDMs associated with |render_frame_id|. | |
| 152 void RemoveAllCdmForFrame(int render_frame_id); | |
| 153 | |
| 154 // Removes the CDM with the specified id. | |
| 155 void RemoveCdm(uint64_t id); | |
| 156 | |
| 157 using PermissionStatusCB = base::Callback<void(bool)>; | |
| 158 | |
| 159 // Checks protected media identifier permission for the given | |
| 160 // |render_frame_id| and |cdm_id|. | |
| 161 void CheckPermissionStatus(int render_frame_id, | |
| 162 int cdm_id, | |
| 163 const PermissionStatusCB& permission_status_cb); | |
| 164 | |
| 165 // Checks permission status on Browser UI thread. Runs |permission_status_cb| | |
| 166 // on the |task_runner_| with the permission status. | |
| 167 void CheckPermissionStatusOnUIThread( | |
| 168 int render_frame_id, | |
| 169 const GURL& security_origin, | |
| 170 const PermissionStatusCB& permission_status_cb); | |
| 171 | |
| 172 // Calls CreateSessionAndGenerateRequest() on the CDM if | |
| 173 // |permission_was_allowed| is true. Otherwise rejects the |promise|. | |
| 174 void CreateSessionAndGenerateRequestIfPermitted( | |
| 175 int render_frame_id, | |
| 176 int cdm_id, | |
| 177 media::MediaKeys::SessionType session_type, | |
| 178 media::EmeInitDataType init_data_type, | |
| 179 const std::vector<uint8_t>& init_data, | |
| 180 std::unique_ptr<media::NewSessionCdmPromise> promise, | |
| 181 bool permission_was_allowed); | |
| 182 | |
| 183 // Calls LoadSession() on the CDM if |permission_was_allowed| is true. | |
| 184 // Otherwise rejects |promise|. | |
| 185 void LoadSessionIfPermitted( | |
| 186 int render_frame_id, | |
| 187 int cdm_id, | |
| 188 media::MediaKeys::SessionType session_type, | |
| 189 const std::string& session_id, | |
| 190 std::unique_ptr<media::NewSessionCdmPromise> promise, | |
| 191 bool permission_was_allowed); | |
| 192 | |
| 193 const int render_process_id_; | |
| 194 | |
| 195 // TaskRunner to dispatch all CDM messages to. If it's NULL, all messages are | |
| 196 // dispatched to the browser UI thread. | |
| 197 scoped_refptr<base::TaskRunner> task_runner_; | |
| 198 | |
| 199 std::unique_ptr<media::CdmFactory> cdm_factory_; | |
| 200 | |
| 201 // The key in the following maps is a combination of |render_frame_id| and | |
| 202 // |cdm_id|. | |
| 203 | |
| 204 // Map of managed CDMs. | |
| 205 typedef std::map<uint64_t, scoped_refptr<media::MediaKeys>> CdmMap; | |
| 206 CdmMap cdm_map_; | |
| 207 | |
| 208 // Map of CDM's security origin. | |
| 209 std::map<uint64_t, GURL> cdm_security_origin_map_; | |
| 210 | |
| 211 base::WeakPtrFactory<BrowserCdmManager> weak_ptr_factory_; | |
| 212 | |
| 213 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager); | |
| 214 }; | |
| 215 | |
| 216 } // namespace content | |
| 217 | |
| 218 #endif // CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ | |
| OLD | NEW |