| 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_ANDROID_BROWSER_CDM_MANAGER_H_ | |
| 6 #define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_CDM_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "content/common/content_export.h" | |
| 16 #include "content/common/media/cdm_messages_enums.h" | |
| 17 #include "ipc/ipc_message.h" | |
| 18 // TODO(xhwang): Drop this when KeyError is moved to a common header. | |
| 19 #include "media/base/media_keys.h" | |
| 20 #include "url/gurl.h" | |
| 21 | |
| 22 namespace media { | |
| 23 class BrowserCdm; | |
| 24 } | |
| 25 | |
| 26 namespace content { | |
| 27 | |
| 28 class RenderFrameHost; | |
| 29 class WebContents; | |
| 30 | |
| 31 // This class manages all CDM objects. It receives control operations from the | |
| 32 // the render process, and forwards them to corresponding CDM object. Callbacks | |
| 33 // from CDM objects are converted to IPCs and then sent to the render process. | |
| 34 class CONTENT_EXPORT BrowserCdmManager { | |
| 35 public: | |
| 36 // Creates a new BrowserCdmManager for |rfh|. | |
| 37 static BrowserCdmManager* Create(RenderFrameHost* rfh); | |
| 38 | |
| 39 ~BrowserCdmManager(); | |
| 40 | |
| 41 media::BrowserCdm* GetCdm(int cdm_id); | |
| 42 | |
| 43 // CDM callbacks. | |
| 44 void OnSessionCreated(int cdm_id, | |
| 45 uint32 session_id, | |
| 46 const std::string& web_session_id); | |
| 47 void OnSessionMessage(int cdm_id, | |
| 48 uint32 session_id, | |
| 49 const std::vector<uint8>& message, | |
| 50 const GURL& destination_url); | |
| 51 void OnSessionReady(int cdm_id, uint32 session_id); | |
| 52 void OnSessionClosed(int cdm_id, uint32 session_id); | |
| 53 void OnSessionError(int cdm_id, | |
| 54 uint32 session_id, | |
| 55 media::MediaKeys::KeyError error_code, | |
| 56 uint32 system_code); | |
| 57 | |
| 58 // Message handlers. | |
| 59 void OnInitializeCdm(int cdm_id, | |
| 60 const std::string& key_system, | |
| 61 const GURL& frame_url); | |
| 62 void OnCreateSession(int cdm_id, | |
| 63 uint32 session_id, | |
| 64 CdmHostMsg_CreateSession_ContentType content_type, | |
| 65 const std::vector<uint8>& init_data); | |
| 66 void OnUpdateSession(int cdm_id, | |
| 67 uint32 session_id, | |
| 68 const std::vector<uint8>& response); | |
| 69 void OnReleaseSession(int cdm_id, uint32 session_id); | |
| 70 void OnSetCdm(int player_id, int cdm_id); | |
| 71 void OnDestroyCdm(int cdm_id); | |
| 72 | |
| 73 private: | |
| 74 // Clients must use Create() or subclass constructor. | |
| 75 explicit BrowserCdmManager(RenderFrameHost* render_frame_host); | |
| 76 | |
| 77 // Cancels all pending session creations associated with |cdm_id|. | |
| 78 void CancelAllPendingSessionCreations(int cdm_id); | |
| 79 | |
| 80 // Adds a new CDM identified by |cdm_id| for the given |key_system| and | |
| 81 // |security_origin|. | |
| 82 void AddCdm(int cdm_id, | |
| 83 const std::string& key_system, | |
| 84 const GURL& security_origin); | |
| 85 | |
| 86 // Removes the CDM with the specified id. | |
| 87 void RemoveCdm(int cdm_id); | |
| 88 | |
| 89 int RoutingID(); | |
| 90 | |
| 91 // Helper function to send messages to RenderFrameObserver. | |
| 92 bool Send(IPC::Message* msg); | |
| 93 | |
| 94 // If |permitted| is false, it does nothing but send | |
| 95 // |CdmMsg_SessionError| IPC message. | |
| 96 // The primary use case is infobar permission callback, i.e., when infobar | |
| 97 // can decide user's intention either from interacting with the actual info | |
| 98 // bar or from the saved preference. | |
| 99 void CreateSessionIfPermitted(int cdm_id, | |
| 100 uint32 session_id, | |
| 101 const std::string& content_type, | |
| 102 const std::vector<uint8>& init_data, | |
| 103 bool permitted); | |
| 104 | |
| 105 RenderFrameHost* const render_frame_host_; | |
| 106 | |
| 107 WebContents* const web_contents_; | |
| 108 | |
| 109 // A map from CDM IDs to managed CDMs. | |
| 110 // TODO(xhwang): Use ScopedPtrHashMap for CdmMap. | |
| 111 typedef std::map<int, media::BrowserCdm*> CdmMap; | |
| 112 CdmMap cdm_map_; | |
| 113 | |
| 114 // Map from CDM ID to CDM's security origin. | |
| 115 std::map<int, GURL> cdm_security_origin_map_; | |
| 116 | |
| 117 // NOTE: Weak pointers must be invalidated before all other member variables. | |
| 118 base::WeakPtrFactory<BrowserCdmManager> weak_ptr_factory_; | |
| 119 | |
| 120 DISALLOW_COPY_AND_ASSIGN(BrowserCdmManager); | |
| 121 }; | |
| 122 | |
| 123 } // namespace content | |
| 124 | |
| 125 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_CDM_MANAGER_H_ | |
| OLD | NEW |