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