| 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, |
| 83 media::MediaKeys::MessageType message_type, |
| 74 const std::vector<uint8>& message, | 84 const std::vector<uint8>& message, |
| 75 const GURL& destination_url); | 85 const GURL& legacy_destination_url); |
| 76 void OnSessionReady(int render_frame_id, int cdm_id, uint32 session_id); | 86 void OnSessionClosed(int render_frame_id, |
| 77 void OnSessionClosed(int render_frame_id, int cdm_id, uint32 session_id); | 87 int cdm_id, |
| 78 void OnSessionError(int render_frame_id, | 88 const std::string& session_id); |
| 79 int cdm_id, | 89 void OnLegacySessionError(int render_frame_id, |
| 80 uint32 session_id, | 90 int cdm_id, |
| 81 media::MediaKeys::KeyError error_code, | 91 const std::string& session_id, |
| 82 uint32 system_code); | 92 media::MediaKeys::Exception exception_code, |
| 93 uint32_t system_code, |
| 94 const std::string& error_message); |
| 95 void OnSessionKeysChange(int render_frame_id, |
| 96 int cdm_id, |
| 97 const std::string& session_id, |
| 98 bool has_additional_usable_key, |
| 99 media::CdmKeysInfo keys_info); |
| 100 void OnSessionExpirationUpdate(int render_frame_id, |
| 101 int cdm_id, |
| 102 const std::string& session_id, |
| 103 const base::Time& new_expiry_time); |
| 83 | 104 |
| 84 // Message handlers. | 105 // Message handlers. |
| 85 void OnInitializeCdm(int render_frame_id, | 106 void OnInitializeCdm(int render_frame_id, |
| 86 int cdm_id, | 107 int cdm_id, |
| 87 const std::string& key_system, | 108 const std::string& key_system, |
| 88 const GURL& frame_url); | 109 const GURL& frame_url); |
| 89 void OnCreateSession(int render_frame_id, | 110 void OnSetServerCertificate(int render_frame_id, |
| 90 int cdm_id, | 111 int cdm_id, |
| 91 uint32 session_id, | 112 uint32_t promise_id, |
| 92 CdmHostMsg_CreateSession_ContentType content_type, | 113 const std::vector<uint8_t>& certificate); |
| 93 const std::vector<uint8>& init_data); | 114 void OnCreateSessionAndGenerateRequest( |
| 115 int render_frame_id, |
| 116 int cdm_id, |
| 117 uint32_t promise_id, |
| 118 CdmHostMsg_CreateSession_InitDataType init_data_type, |
| 119 const std::vector<uint8>& init_data); |
| 94 void OnUpdateSession(int render_frame_id, | 120 void OnUpdateSession(int render_frame_id, |
| 95 int cdm_id, | 121 int cdm_id, |
| 96 uint32 session_id, | 122 uint32_t promise_id, |
| 123 const std::string& session_id, |
| 97 const std::vector<uint8>& response); | 124 const std::vector<uint8>& response); |
| 98 void OnReleaseSession(int render_frame_id, | 125 void OnCloseSession(int render_frame_id, |
| 99 int cdm_id, uint32 session_id); | 126 int cdm_id, |
| 127 uint32_t promise_id, |
| 128 const std::string& session_id); |
| 100 void OnDestroyCdm(int render_frame_id, int cdm_id); | 129 void OnDestroyCdm(int render_frame_id, int cdm_id); |
| 101 | 130 |
| 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 | 131 // Adds a new CDM identified by |cdm_id| for the given |key_system| and |
| 105 // |security_origin|. | 132 // |security_origin|. |
| 106 void AddCdm(int render_frame_id, | 133 void AddCdm(int render_frame_id, |
| 107 int cdm_id, | 134 int cdm_id, |
| 108 const std::string& key_system, | 135 const std::string& key_system, |
| 109 const GURL& security_origin); | 136 const GURL& security_origin); |
| 110 | 137 |
| 111 // Removes all CDMs associated with |render_frame_id|. | 138 // Removes all CDMs associated with |render_frame_id|. |
| 112 void RemoveAllCdmForFrame(int render_frame_id); | 139 void RemoveAllCdmForFrame(int render_frame_id); |
| 113 | 140 |
| 114 // Removes the CDM with the specified id. | 141 // Removes the CDM with the specified id. |
| 115 void RemoveCdm(uint64 id); | 142 void RemoveCdm(uint64 id); |
| 116 | 143 |
| 117 // Requests permission for the given protected-media session (infobar). | 144 // Requests permission for the given protected-media session (infobar). |
| 118 void RequestSessionPermission(int render_frame_id, | 145 void RequestSessionPermission( |
| 119 const GURL& security_origin, | 146 int render_frame_id, |
| 120 int cdm_id, | 147 const GURL& security_origin, |
| 121 uint32 session_id, | 148 int cdm_id, |
| 122 const std::string& content_type, | 149 const std::string& init_data_type, |
| 123 const std::vector<uint8>& init_data); | 150 const std::vector<uint8>& init_data, |
| 151 scoped_ptr<media::NewSessionCdmPromise> promise); |
| 124 | 152 |
| 125 // If |permitted| is false, it does nothing but send | 153 // If |permitted| is false, it does nothing but send |
| 126 // |CdmMsg_SessionError| IPC message. | 154 // |CdmMsg_LegacySessionError| IPC message. |
| 127 // The primary use case is infobar permission callback, i.e., when infobar | 155 // 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 | 156 // can decide user's intention either from interacting with the actual info |
| 129 // bar or from the saved preference. | 157 // bar or from the saved preference. |
| 130 void CreateSessionIfPermitted(int render_frame_id, | 158 void GenerateRequestIfPermitted( |
| 131 int cdm_id, | 159 int render_frame_id, |
| 132 uint32 session_id, | 160 int cdm_id, |
| 133 const std::string& content_type, | 161 const std::string& init_data_type, |
| 134 const std::vector<uint8>& init_data, | 162 const std::vector<uint8>& init_data, |
| 135 bool permitted); | 163 scoped_ptr<media::NewSessionCdmPromise> promise, |
| 164 bool permitted); |
| 136 | 165 |
| 137 const int render_process_id_; | 166 const int render_process_id_; |
| 138 | 167 |
| 139 // TaskRunner to dispatch all CDM messages to. If it's NULL, all messages are | 168 // TaskRunner to dispatch all CDM messages to. If it's NULL, all messages are |
| 140 // dispatched to the browser UI thread. | 169 // dispatched to the browser UI thread. |
| 141 scoped_refptr<base::TaskRunner> task_runner_; | 170 scoped_refptr<base::TaskRunner> task_runner_; |
| 142 | 171 |
| 143 // The key in the following maps is a combination of |render_frame_id| and | 172 // The key in the following maps is a combination of |render_frame_id| and |
| 144 // |cdm_id|. | 173 // |cdm_id|. |
| 145 | 174 |
| 146 // Map of managed BrowserCdms. | 175 // Map of managed BrowserCdms. |
| 147 typedef base::ScopedPtrHashMap<uint64, media::BrowserCdm> CdmMap; | 176 typedef base::ScopedPtrHashMap<uint64, media::BrowserCdm> CdmMap; |
| 148 CdmMap cdm_map_; | 177 CdmMap cdm_map_; |
| 149 | 178 |
| 150 // Map of CDM's security origin. | 179 // Map of CDM's security origin. |
| 151 std::map<uint64, GURL> cdm_security_origin_map_; | 180 std::map<uint64, GURL> cdm_security_origin_map_; |
| 152 | 181 |
| 153 // Map of callbacks to cancel the permission request. | 182 // Map of callbacks to cancel the permission request. |
| 154 std::map<uint64, base::Closure> cdm_cancel_permission_map_; | 183 std::map<uint64, base::Closure> cdm_cancel_permission_map_; |
| 155 | 184 |
| 156 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager); | 185 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager); |
| 157 }; | 186 }; |
| 158 | 187 |
| 159 } // namespace content | 188 } // namespace content |
| 160 | 189 |
| 161 #endif // CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ | 190 #endif // CONTENT_BROWSER_MEDIA_CDM_BROWSER_CDM_MANAGER_H_ |
| OLD | NEW |