Commit ac2d3244 authored by sandersd's avatar sandersd Committed by Commit bot

Extract requestMediaKeySystemAccess() algorithm.

This separates the Chromium side of requestMediaKeySystemAccess() into the Blink interface implementation (WebEncryptedMediaClientImpl), which also handles the UMAs, and the core algorithm (KeySystemConfigSelector). This should make it easy to test the core algorithm.

BUG=468912

Review URL: https://codereview.chromium.org/1052273004

Cr-Commit-Position: refs/heads/master@{#323983}
parent 36318aa4
...@@ -187,7 +187,7 @@ static bool IsPotentiallySupportedKeySystem(const std::string& key_system) { ...@@ -187,7 +187,7 @@ static bool IsPotentiallySupportedKeySystem(const std::string& key_system) {
class KeySystemsImpl : public KeySystems { class KeySystemsImpl : public KeySystems {
public: public:
static KeySystemsImpl& GetInstance(); static KeySystemsImpl* GetInstance();
void UpdateIfNeeded(); void UpdateIfNeeded();
...@@ -310,9 +310,9 @@ class KeySystemsImpl : public KeySystems { ...@@ -310,9 +310,9 @@ class KeySystemsImpl : public KeySystems {
static base::LazyInstance<KeySystemsImpl> g_key_systems = static base::LazyInstance<KeySystemsImpl> g_key_systems =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
KeySystemsImpl& KeySystemsImpl::GetInstance() { KeySystemsImpl* KeySystemsImpl::GetInstance() {
KeySystemsImpl& key_systems = g_key_systems.Get(); KeySystemsImpl* key_systems = g_key_systems.Pointer();
key_systems.UpdateIfNeeded(); key_systems->UpdateIfNeeded();
return key_systems; return key_systems;
} }
...@@ -906,7 +906,7 @@ EmeConfigRule KeySystemsImpl::GetDistinctiveIdentifierConfigRule( ...@@ -906,7 +906,7 @@ EmeConfigRule KeySystemsImpl::GetDistinctiveIdentifierConfigRule(
return EmeConfigRule::IDENTIFIER_REQUIRED; return EmeConfigRule::IDENTIFIER_REQUIRED;
} }
KeySystems& KeySystems::GetInstance() { KeySystems* KeySystems::GetInstance() {
return KeySystemsImpl::GetInstance(); return KeySystemsImpl::GetInstance();
} }
...@@ -932,11 +932,12 @@ std::string GetPrefixedKeySystemName(const std::string& key_system) { ...@@ -932,11 +932,12 @@ std::string GetPrefixedKeySystemName(const std::string& key_system) {
} }
bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) { bool PrefixedIsSupportedConcreteKeySystem(const std::string& key_system) {
return KeySystemsImpl::GetInstance().IsConcreteSupportedKeySystem(key_system); return KeySystemsImpl::GetInstance()->IsConcreteSupportedKeySystem(
key_system);
} }
bool IsSupportedKeySystem(const std::string& key_system) { bool IsSupportedKeySystem(const std::string& key_system) {
if (!KeySystemsImpl::GetInstance().IsSupportedKeySystem(key_system)) if (!KeySystemsImpl::GetInstance()->IsSupportedKeySystem(key_system))
return false; return false;
// TODO(ddorwin): Move this to where we add key systems when prefixed EME is // TODO(ddorwin): Move this to where we add key systems when prefixed EME is
...@@ -953,8 +954,8 @@ bool IsSupportedKeySystem(const std::string& key_system) { ...@@ -953,8 +954,8 @@ bool IsSupportedKeySystem(const std::string& key_system) {
bool IsSupportedKeySystemWithInitDataType(const std::string& key_system, bool IsSupportedKeySystemWithInitDataType(const std::string& key_system,
EmeInitDataType init_data_type) { EmeInitDataType init_data_type) {
return KeySystemsImpl::GetInstance().IsSupportedInitDataType(key_system, return KeySystemsImpl::GetInstance()->IsSupportedInitDataType(key_system,
init_data_type); init_data_type);
} }
bool PrefixedIsSupportedKeySystemWithMediaMimeType( bool PrefixedIsSupportedKeySystemWithMediaMimeType(
...@@ -962,21 +963,21 @@ bool PrefixedIsSupportedKeySystemWithMediaMimeType( ...@@ -962,21 +963,21 @@ bool PrefixedIsSupportedKeySystemWithMediaMimeType(
const std::vector<std::string>& codecs, const std::vector<std::string>& codecs,
const std::string& key_system) { const std::string& key_system) {
return KeySystemsImpl::GetInstance() return KeySystemsImpl::GetInstance()
.PrefixedIsSupportedKeySystemWithMediaMimeType(mime_type, codecs, ->PrefixedIsSupportedKeySystemWithMediaMimeType(mime_type, codecs,
key_system); key_system);
} }
std::string GetKeySystemNameForUMA(const std::string& key_system) { std::string GetKeySystemNameForUMA(const std::string& key_system) {
return KeySystemsImpl::GetInstance().GetKeySystemNameForUMA(key_system); return KeySystemsImpl::GetInstance()->GetKeySystemNameForUMA(key_system);
} }
bool CanUseAesDecryptor(const std::string& concrete_key_system) { bool CanUseAesDecryptor(const std::string& concrete_key_system) {
return KeySystemsImpl::GetInstance().UseAesDecryptor(concrete_key_system); return KeySystemsImpl::GetInstance()->UseAesDecryptor(concrete_key_system);
} }
#if defined(ENABLE_PEPPER_CDMS) #if defined(ENABLE_PEPPER_CDMS)
std::string GetPepperType(const std::string& concrete_key_system) { std::string GetPepperType(const std::string& concrete_key_system) {
return KeySystemsImpl::GetInstance().GetPepperType(concrete_key_system); return KeySystemsImpl::GetInstance()->GetPepperType(concrete_key_system);
} }
#endif #endif
...@@ -987,14 +988,14 @@ std::string GetPepperType(const std::string& concrete_key_system) { ...@@ -987,14 +988,14 @@ std::string GetPepperType(const std::string& concrete_key_system) {
// "MEDIA_EXPORT" here again so that they are visible to tests. // "MEDIA_EXPORT" here again so that they are visible to tests.
MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) { MEDIA_EXPORT void AddContainerMask(const std::string& container, uint32 mask) {
KeySystemsImpl::GetInstance().AddContainerMask(container, mask); KeySystemsImpl::GetInstance()->AddContainerMask(container, mask);
} }
MEDIA_EXPORT void AddCodecMask( MEDIA_EXPORT void AddCodecMask(
EmeMediaType media_type, EmeMediaType media_type,
const std::string& codec, const std::string& codec,
uint32 mask) { uint32 mask) {
KeySystemsImpl::GetInstance().AddCodecMask(media_type, codec, mask); KeySystemsImpl::GetInstance()->AddCodecMask(media_type, codec, mask);
} }
} // namespace media } // namespace media
...@@ -24,7 +24,7 @@ namespace media { ...@@ -24,7 +24,7 @@ namespace media {
// |key_system| to every method. http://crbug.com/457438 // |key_system| to every method. http://crbug.com/457438
class MEDIA_EXPORT KeySystems { class MEDIA_EXPORT KeySystems {
public: public:
static KeySystems& GetInstance(); static KeySystems* GetInstance();
// Returns whether |key_system| is a supported key system. // Returns whether |key_system| is a supported key system.
virtual bool IsSupportedKeySystem(const std::string& key_system) const = 0; virtual bool IsSupportedKeySystem(const std::string& key_system) const = 0;
......
...@@ -77,7 +77,7 @@ static bool IsSupportedKeySystemWithMediaMimeType( ...@@ -77,7 +77,7 @@ static bool IsSupportedKeySystemWithMediaMimeType(
const std::string& mime_type, const std::string& mime_type,
const std::vector<std::string>& codecs, const std::vector<std::string>& codecs,
const std::string& key_system) { const std::string& key_system) {
return KeySystems::GetInstance().IsSupportedCodecCombination( return KeySystems::GetInstance()->IsSupportedCodecCombination(
key_system, EmeMediaType::VIDEO, mime_type, codecs); key_system, EmeMediaType::VIDEO, mime_type, codecs);
} }
...@@ -85,7 +85,7 @@ static bool IsSupportedKeySystemWithAudioMimeType( ...@@ -85,7 +85,7 @@ static bool IsSupportedKeySystemWithAudioMimeType(
const std::string& mime_type, const std::string& mime_type,
const std::vector<std::string>& codecs, const std::vector<std::string>& codecs,
const std::string& key_system) { const std::string& key_system) {
return KeySystems::GetInstance().IsSupportedCodecCombination( return KeySystems::GetInstance()->IsSupportedCodecCombination(
key_system, EmeMediaType::AUDIO, mime_type, codecs); key_system, EmeMediaType::AUDIO, mime_type, codecs);
} }
......
...@@ -42,6 +42,8 @@ component("blink") { ...@@ -42,6 +42,8 @@ component("blink") {
"cdm_session_adapter.h", "cdm_session_adapter.h",
"encrypted_media_player_support.cc", "encrypted_media_player_support.cc",
"encrypted_media_player_support.h", "encrypted_media_player_support.h",
"key_system_config_selector.cc",
"key_system_config_selector.h",
"new_session_cdm_result_promise.cc", "new_session_cdm_result_promise.cc",
"new_session_cdm_result_promise.h", "new_session_cdm_result_promise.h",
"texttrack_impl.cc", "texttrack_impl.cc",
......
This diff is collapsed.
// Copyright 2015 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 MEDIA_BLINK_KEY_SYSTEM_CONFIG_SELECTOR_H_
#define MEDIA_BLINK_KEY_SYSTEM_CONFIG_SELECTOR_H_
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "media/base/eme_constants.h"
#include "third_party/WebKit/public/platform/WebVector.h"
namespace blink {
struct WebMediaKeySystemConfiguration;
struct WebMediaKeySystemMediaCapability;
class WebSecurityOrigin;
class WebString;
} // namespace blink
namespace media {
class KeySystems;
class MediaPermission;
class KeySystemConfigSelector {
public:
KeySystemConfigSelector(const KeySystems* key_systems,
MediaPermission* media_permission);
~KeySystemConfigSelector();
void SelectConfig(
const blink::WebString& key_system,
const blink::WebVector<blink::WebMediaKeySystemConfiguration>&
candidate_configurations,
const blink::WebSecurityOrigin& security_origin,
base::Callback<void(const blink::WebMediaKeySystemConfiguration&)>
succeeded_cb,
base::Callback<void(const blink::WebString&)> not_supported_cb);
private:
struct SelectionRequest;
class ConfigState;
enum ConfigurationSupport {
CONFIGURATION_NOT_SUPPORTED,
CONFIGURATION_REQUIRES_PERMISSION,
CONFIGURATION_SUPPORTED,
};
void SelectConfigInternal(scoped_ptr<SelectionRequest> request);
void OnPermissionResult(scoped_ptr<SelectionRequest> request,
bool is_permission_granted);
ConfigurationSupport GetSupportedConfiguration(
const std::string& key_system,
const blink::WebMediaKeySystemConfiguration& candidate,
ConfigState* config_state,
blink::WebMediaKeySystemConfiguration* accumulated_configuration);
bool GetSupportedCapabilities(
const std::string& key_system,
EmeMediaType media_type,
const blink::WebVector<blink::WebMediaKeySystemMediaCapability>&
requested_media_capabilities,
ConfigState* config_state,
std::vector<blink::WebMediaKeySystemMediaCapability>*
supported_media_capabilities);
bool IsSupportedContentType(const std::string& key_system,
EmeMediaType media_type,
const std::string& container_mime_type,
const std::string& codecs);
const KeySystems* key_systems_;
MediaPermission* media_permission_;
base::WeakPtrFactory<KeySystemConfigSelector> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(KeySystemConfigSelector);
};
} // namespace media
#endif // MEDIA_BLINK_KEY_SYSTEM_CONFIG_SELECTOR_H_
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
'cdm_session_adapter.h', 'cdm_session_adapter.h',
'encrypted_media_player_support.cc', 'encrypted_media_player_support.cc',
'encrypted_media_player_support.h', 'encrypted_media_player_support.h',
'key_system_config_selector.cc',
'key_system_config_selector.h',
'new_session_cdm_result_promise.cc', 'new_session_cdm_result_promise.cc',
'new_session_cdm_result_promise.h', 'new_session_cdm_result_promise.h',
'texttrack_impl.cc', 'texttrack_impl.cc',
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "media/blink/webcontentdecryptionmoduleaccess_impl.h" #include "media/blink/webcontentdecryptionmoduleaccess_impl.h"
#include "base/basictypes.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
......
...@@ -5,18 +5,12 @@ ...@@ -5,18 +5,12 @@
#ifndef MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULEACCESS_IMPL_H_ #ifndef MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULEACCESS_IMPL_H_
#define MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULEACCESS_IMPL_H_ #define MEDIA_BLINK_WEBCONTENTDECRYPTIONMODULEACCESS_IMPL_H_
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "media/base/cdm_factory.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModuleAccess.h" #include "third_party/WebKit/public/platform/WebContentDecryptionModuleAccess.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
#include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h"
#include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
namespace blink {
class WebLocalFrame;
}
namespace media { namespace media {
...@@ -44,14 +38,14 @@ class WebContentDecryptionModuleAccessImpl ...@@ -44,14 +38,14 @@ class WebContentDecryptionModuleAccessImpl
const blink::WebSecurityOrigin& security_origin, const blink::WebSecurityOrigin& security_origin,
const base::WeakPtr<WebEncryptedMediaClientImpl>& client); const base::WeakPtr<WebEncryptedMediaClientImpl>& client);
DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleAccessImpl);
blink::WebString key_system_; blink::WebString key_system_;
blink::WebMediaKeySystemConfiguration configuration_; blink::WebMediaKeySystemConfiguration configuration_;
blink::WebSecurityOrigin security_origin_; blink::WebSecurityOrigin security_origin_;
// Keep a WeakPtr as client is owned by render_frame_impl. // Keep a WeakPtr as client is owned by render_frame_impl.
base::WeakPtr<WebEncryptedMediaClientImpl> client_; base::WeakPtr<WebEncryptedMediaClientImpl> client_;
DISALLOW_COPY_AND_ASSIGN(WebContentDecryptionModuleAccessImpl);
}; };
} // namespace media } // namespace media
......
This diff is collapsed.
...@@ -10,14 +10,21 @@ ...@@ -10,14 +10,21 @@
#include "base/containers/scoped_ptr_hash_map.h" #include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "media/base/cdm_factory.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" #include "media/blink/key_system_config_selector.h"
#include "third_party/WebKit/public/platform/WebEncryptedMediaClient.h" #include "third_party/WebKit/public/platform/WebEncryptedMediaClient.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
namespace blink {
class WebContentDecryptionModuleResult;
struct WebMediaKeySystemConfiguration;
class WebSecurityOrigin;
} // namespace blink
namespace media { namespace media {
class CdmFactory;
class KeySystems; class KeySystems;
class MediaPermission; class MediaPermission;
...@@ -41,30 +48,31 @@ class MEDIA_EXPORT WebEncryptedMediaClientImpl ...@@ -41,30 +48,31 @@ class MEDIA_EXPORT WebEncryptedMediaClientImpl
blink::WebContentDecryptionModuleResult result); blink::WebContentDecryptionModuleResult result);
private: private:
// Pick a supported configuration if possible, and complete the request. This
// method may asynchronously invoke itself after prompting for permissions.
void SelectSupportedConfiguration(blink::WebEncryptedMediaRequest request,
bool was_permission_requested,
bool is_permission_granted);
// Report usage of key system to UMA. There are 2 different counts logged: // Report usage of key system to UMA. There are 2 different counts logged:
// 1. The key system is requested. // 1. The key system is requested.
// 2. The requested key system and options are supported. // 2. The requested key system and options are supported.
// Each stat is only reported once per renderer frame per key system. // Each stat is only reported once per renderer frame per key system.
class Reporter; class Reporter;
// Complete a requestMediaKeySystemAccess() request with a supported
// accumulated configuration.
void OnRequestSucceeded(
blink::WebEncryptedMediaRequest request,
const blink::WebMediaKeySystemConfiguration& accumulated_configuration);
// Complete a requestMediaKeySystemAccess() request with an error message.
void OnRequestNotSupported(blink::WebEncryptedMediaRequest request,
const blink::WebString& error_message);
// Gets the Reporter for |key_system|. If it doesn't already exist, // Gets the Reporter for |key_system|. If it doesn't already exist,
// create one. // create one.
Reporter* GetReporter(const std::string& key_system); Reporter* GetReporter(const blink::WebString& key_system);
// Key system <-> Reporter map. // Reporter singletons.
typedef base::ScopedPtrHashMap<std::string, Reporter> Reporters; base::ScopedPtrHashMap<std::string, Reporter> reporters_;
Reporters reporters_;
const KeySystems& key_systems_;
CdmFactory* cdm_factory_; CdmFactory* cdm_factory_;
MediaPermission* media_permission_; KeySystemConfigSelector key_system_config_selector_;
base::WeakPtrFactory<WebEncryptedMediaClientImpl> weak_factory_; base::WeakPtrFactory<WebEncryptedMediaClientImpl> weak_factory_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment