Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: media/base/android/media_drm_bridge.h

Issue 1427183002: Move MediaDrmBridge provision communication to native side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ 6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "media/base/browser_cdm.h" 16 #include "media/base/browser_cdm.h"
17 #include "media/base/cdm_promise_adapter.h" 17 #include "media/base/cdm_promise_adapter.h"
18 #include "media/base/media_export.h" 18 #include "media/base/media_export.h"
19 #include "media/cdm/player_tracker_impl.h" 19 #include "media/cdm/player_tracker_impl.h"
20 #include "url/gurl.h" 20 #include "url/gurl.h"
21 21
22 class GURL; 22 class GURL;
23 23
24 namespace media { 24 namespace media {
25 25
26 class MediaDrmBridge; 26 class MediaDrmBridge;
27 class ProvisionFetcher;
27 28
28 using ScopedMediaDrmBridgePtr = scoped_ptr<MediaDrmBridge, BrowserCdmDeleter>; 29 using ScopedMediaDrmBridgePtr = scoped_ptr<MediaDrmBridge, BrowserCdmDeleter>;
29 30
30 // This class provides DRM services for android EME implementation. 31 // This class provides DRM services for android EME implementation.
31 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { 32 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm {
32 public: 33 public:
33 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 34 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400
34 enum SecurityLevel { 35 enum SecurityLevel {
35 SECURITY_LEVEL_NONE = 0, 36 SECURITY_LEVEL_NONE = 0,
36 SECURITY_LEVEL_1 = 1, 37 SECURITY_LEVEL_1 = 1,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 71
71 // Returns the list of the platform-supported key system names that 72 // Returns the list of the platform-supported key system names that
72 // are not handled by Chrome explicitly. 73 // are not handled by Chrome explicitly.
73 static std::vector<std::string> GetPlatformKeySystemNames(); 74 static std::vector<std::string> GetPlatformKeySystemNames();
74 75
75 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL 76 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL
76 // pointer otherwise. 77 // pointer otherwise.
77 // TODO(xhwang): Is it okay not to update session expiration info? 78 // TODO(xhwang): Is it okay not to update session expiration info?
78 static ScopedMediaDrmBridgePtr Create( 79 static ScopedMediaDrmBridgePtr Create(
79 const std::string& key_system, 80 const std::string& key_system,
81 scoped_ptr<ProvisionFetcher> provision_fetcher,
80 const SessionMessageCB& session_message_cb, 82 const SessionMessageCB& session_message_cb,
81 const SessionClosedCB& session_closed_cb, 83 const SessionClosedCB& session_closed_cb,
82 const LegacySessionErrorCB& legacy_session_error_cb, 84 const LegacySessionErrorCB& legacy_session_error_cb,
83 const SessionKeysChangeCB& session_keys_change_cb, 85 const SessionKeysChangeCB& session_keys_change_cb,
84 const SessionExpirationUpdateCB& session_expiration_update_cb); 86 const SessionExpirationUpdateCB& session_expiration_update_cb);
85 87
86 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL 88 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL
87 // otherwise. No session callbacks are provided. This is used when we need to 89 // otherwise. No session callbacks are provided. This is used when we need to
88 // use MediaDrmBridge without creating any sessions. 90 // use MediaDrmBridge without creating any sessions.
89 static ScopedMediaDrmBridgePtr CreateWithoutSessionSupport( 91 static ScopedMediaDrmBridgePtr CreateWithoutSessionSupport(
90 const std::string& key_system); 92 const std::string& key_system,
93 scoped_ptr<ProvisionFetcher> provision_fetcher);
91 94
92 // Returns a WeakPtr to be used on the |task_runner_|. 95 // Returns a WeakPtr to be used on the |task_runner_|.
93 base::WeakPtr<MediaDrmBridge> WeakPtr(); 96 base::WeakPtr<MediaDrmBridge> WeakPtr();
94 97
95 // MediaKeys (via BrowserCdm) implementation. 98 // MediaKeys (via BrowserCdm) implementation.
96 void SetServerCertificate( 99 void SetServerCertificate(
97 const std::vector<uint8_t>& certificate, 100 const std::vector<uint8_t>& certificate,
98 scoped_ptr<media::SimpleCdmPromise> promise) override; 101 scoped_ptr<media::SimpleCdmPromise> promise) override;
99 void CreateSessionAndGenerateRequest( 102 void CreateSessionAndGenerateRequest(
100 SessionType session_type, 103 SessionType session_type,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Sets callback which will be called when MediaCrypto is ready. If 150 // Sets callback which will be called when MediaCrypto is ready. If
148 // |media_crypto_ready_cb| is null, previously set callback will be cleared. 151 // |media_crypto_ready_cb| is null, previously set callback will be cleared.
149 void SetMediaCryptoReadyCB(const MediaCryptoReadyCB& media_crypto_ready_cb); 152 void SetMediaCryptoReadyCB(const MediaCryptoReadyCB& media_crypto_ready_cb);
150 153
151 // All the OnXxx functions below are called from Java. The implementation must 154 // All the OnXxx functions below are called from Java. The implementation must
152 // only do minimal work and then post tasks to avoid reentrancy issues. 155 // only do minimal work and then post tasks to avoid reentrancy issues.
153 156
154 // Called by Java after a MediaCrypto object is created. 157 // Called by Java after a MediaCrypto object is created.
155 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm); 158 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm);
156 159
160 // Called by Java when we need to send a provisioning request,
161 void OnStartProvisioning(JNIEnv* env,
162 jobject j_media_drm,
163 jstring j_default_url,
164 jbyteArray j_request_data);
165
157 // Callbacks to resolve the promise for |promise_id|. 166 // Callbacks to resolve the promise for |promise_id|.
158 void OnPromiseResolved(JNIEnv* env, jobject j_media_drm, jint j_promise_id); 167 void OnPromiseResolved(JNIEnv* env, jobject j_media_drm, jint j_promise_id);
159 void OnPromiseResolvedWithSession(JNIEnv* env, 168 void OnPromiseResolvedWithSession(JNIEnv* env,
160 jobject j_media_drm, 169 jobject j_media_drm,
161 jint j_promise_id, 170 jint j_promise_id,
162 jbyteArray j_session_id); 171 jbyteArray j_session_id);
163 172
164 // Callback to reject the promise for |promise_id| with |error_message|. 173 // Callback to reject the promise for |promise_id| with |error_message|.
165 // Note: No |system_error| is available from MediaDrm. 174 // Note: No |system_error| is available from MediaDrm.
166 // TODO(xhwang): Implement Exception code. 175 // TODO(xhwang): Implement Exception code.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 void OnLegacySessionError(JNIEnv* env, 215 void OnLegacySessionError(JNIEnv* env,
207 jobject j_media_drm, 216 jobject j_media_drm,
208 jbyteArray j_session_id, 217 jbyteArray j_session_id,
209 jstring j_error_message); 218 jstring j_error_message);
210 219
211 // Called by the java object when credential reset is completed. 220 // Called by the java object when credential reset is completed.
212 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success); 221 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success);
213 222
214 private: 223 private:
215 MediaDrmBridge(const std::vector<uint8>& scheme_uuid, 224 MediaDrmBridge(const std::vector<uint8>& scheme_uuid,
225 scoped_ptr<ProvisionFetcher> provision_fetcher,
216 const SessionMessageCB& session_message_cb, 226 const SessionMessageCB& session_message_cb,
217 const SessionClosedCB& session_closed_cb, 227 const SessionClosedCB& session_closed_cb,
218 const LegacySessionErrorCB& legacy_session_error_cb, 228 const LegacySessionErrorCB& legacy_session_error_cb,
219 const SessionKeysChangeCB& session_keys_change_cb, 229 const SessionKeysChangeCB& session_keys_change_cb,
220 const SessionExpirationUpdateCB& session_expiration_update_cb); 230 const SessionExpirationUpdateCB& session_expiration_update_cb);
221 231
222 static bool IsSecureDecoderRequired(SecurityLevel security_level); 232 static bool IsSecureDecoderRequired(SecurityLevel security_level);
223 233
224 // Get the security level of the media. 234 // Get the security level of the media.
225 SecurityLevel GetSecurityLevel(); 235 SecurityLevel GetSecurityLevel();
226 236
227 // A helper method that calls a |player_tracker_| method on correct thread. 237 // A helper method that calls a |player_tracker_| method on correct thread.
228 void NotifyNewKeyOnCorrectThread(); 238 void NotifyNewKeyOnCorrectThread();
229 239
230 // A helper method that calculates the |media_crypto_ready_cb_| arguments and 240 // A helper method that calculates the |media_crypto_ready_cb_| arguments and
231 // run this callback. 241 // run this callback.
232 void NotifyMediaCryptoReady(const MediaCryptoReadyCB& cb); 242 void NotifyMediaCryptoReady(const MediaCryptoReadyCB& cb);
233 243
244 // Sends HTTP provisioning request to a provisioning server.
245 void SendProvisioningRequest(const std::string& default_url,
246 const std::string& request_data);
247
248 // Process the data received by provisioning server.
249 void ProcessProvisioningResult(const std::string& response, bool success);
250
234 // UUID of the key system. 251 // UUID of the key system.
235 std::vector<uint8> scheme_uuid_; 252 std::vector<uint8> scheme_uuid_;
236 253
237 // Java MediaDrm instance. 254 // Java MediaDrm instance.
238 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; 255 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_;
239 256
257 // The object that requests and receives provisioning data.
258 scoped_ptr<ProvisionFetcher> provision_fetcher_;
259
240 // Callbacks for firing session events. 260 // Callbacks for firing session events.
241 SessionMessageCB session_message_cb_; 261 SessionMessageCB session_message_cb_;
242 SessionClosedCB session_closed_cb_; 262 SessionClosedCB session_closed_cb_;
243 LegacySessionErrorCB legacy_session_error_cb_; 263 LegacySessionErrorCB legacy_session_error_cb_;
244 SessionKeysChangeCB session_keys_change_cb_; 264 SessionKeysChangeCB session_keys_change_cb_;
245 SessionExpirationUpdateCB session_expiration_update_cb_; 265 SessionExpirationUpdateCB session_expiration_update_cb_;
246 266
247 MediaCryptoReadyCB media_crypto_ready_cb_; 267 MediaCryptoReadyCB media_crypto_ready_cb_;
248 268
249 ResetCredentialsCB reset_credentials_cb_; 269 ResetCredentialsCB reset_credentials_cb_;
(...skipping 17 matching lines...) Expand all
267 287
268 // Default WeakPtrFactory. 288 // Default WeakPtrFactory.
269 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; 289 base::WeakPtrFactory<MediaDrmBridge> weak_factory_;
270 290
271 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); 291 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge);
272 }; 292 };
273 293
274 } // namespace media 294 } // namespace media
275 295
276 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ 296 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698