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