Index: media/blink/key_system_config_selector.cc |
diff --git a/media/blink/webencryptedmediaclient_impl.cc b/media/blink/key_system_config_selector.cc |
similarity index 72% |
copy from media/blink/webencryptedmediaclient_impl.cc |
copy to media/blink/key_system_config_selector.cc |
index faa7657f4cd81cf393940635b707e6c44bb659af..badeefc66d2a8a1a0f26cdac74f7fd6e7a83e956 100644 |
--- a/media/blink/webencryptedmediaclient_impl.cc |
+++ b/media/blink/key_system_config_selector.cc |
@@ -2,61 +2,73 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "webencryptedmediaclient_impl.h" |
+#include "key_system_config_selector.h" |
#include "base/bind.h" |
#include "base/logging.h" |
-#include "base/metrics/histogram.h" |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "media/base/key_systems.h" |
#include "media/base/media_permission.h" |
-#include "media/blink/webcontentdecryptionmodule_impl.h" |
-#include "media/blink/webcontentdecryptionmoduleaccess_impl.h" |
#include "media/blink/webmediaplayer_util.h" |
#include "net/base/mime_util.h" |
-#include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.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/WebVector.h" |
+#include "url/gurl.h" |
namespace media { |
-// These names are used by UMA. |
-const char kKeySystemSupportUMAPrefix[] = |
- "Media.EME.RequestMediaKeySystemAccess."; |
+namespace { |
-enum ConfigurationSupport { |
- CONFIGURATION_NOT_SUPPORTED, |
- CONFIGURATION_REQUIRES_PERMISSION, |
- CONFIGURATION_SUPPORTED, |
+static EmeFeatureRequirement ConvertRequirement( |
+ blink::WebMediaKeySystemConfiguration::Requirement requirement) { |
+ switch (requirement) { |
+ case blink::WebMediaKeySystemConfiguration::Requirement::Required: |
+ return EME_FEATURE_REQUIRED; |
+ case blink::WebMediaKeySystemConfiguration::Requirement::Optional: |
+ return EME_FEATURE_OPTIONAL; |
+ case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
+ return EME_FEATURE_NOT_ALLOWED; |
+ } |
+ |
+ NOTREACHED(); |
+ return EME_FEATURE_NOT_ALLOWED; |
+} |
+ |
+} // namespace |
+ |
+struct KeySystemConfigSelector::SelectionRequest { |
+ std::string key_system; |
+ blink::WebVector<blink::WebMediaKeySystemConfiguration> |
+ candidate_configurations; |
+ blink::WebSecurityOrigin security_origin; |
+ base::Callback<void(const blink::WebMediaKeySystemConfiguration&)> |
+ succeeded_cb; |
+ base::Callback<void(const blink::WebString&)> not_supported_cb; |
+ bool was_permission_requested = false; |
+ bool is_permission_granted = false; |
}; |
// Accumulates configuration rules to determine if a feature (additional |
// configuration rule) can be added to an accumulated configuration. |
-class ConfigState { |
+class KeySystemConfigSelector::ConfigState { |
public: |
ConfigState(bool was_permission_requested, bool is_permission_granted) |
: was_permission_requested_(was_permission_requested), |
- is_permission_granted_(is_permission_granted) { |
- } |
+ is_permission_granted_(is_permission_granted) {} |
- bool IsPermissionGranted() const { |
- return is_permission_granted_; |
- } |
+ bool IsPermissionGranted() const { return is_permission_granted_; } |
// Permission is possible if it has not been denied. |
bool IsPermissionPossible() const { |
return is_permission_granted_ || !was_permission_requested_; |
} |
- bool IsIdentifierRequired() const { |
- return is_identifier_required_; |
- } |
+ bool IsIdentifierRequired() const { return is_identifier_required_; } |
- bool IsIdentifierRecommended() const { |
- return is_identifier_recommended_; |
- } |
+ bool IsIdentifierRecommended() const { return is_identifier_recommended_; } |
// Checks whether a rule is compatible with all previously added rules. |
bool IsRuleSupported(EmeConfigRule rule) const { |
@@ -135,10 +147,24 @@ class ConfigState { |
// Whether a rule has been added that requires or blocks persistent state. |
bool is_persistence_required_ = false; |
bool is_persistence_not_allowed_ = false; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ConfigState); |
}; |
-static bool IsSupportedContentType( |
- const KeySystems& key_systems, |
+KeySystemConfigSelector::KeySystemConfigSelector( |
+ const KeySystems* key_systems, |
+ MediaPermission* media_permission) |
+ : key_systems_(key_systems), |
+ media_permission_(media_permission), |
+ weak_factory_(this) { |
+ DCHECK(key_systems_); |
+ DCHECK(media_permission_); |
+} |
+ |
+KeySystemConfigSelector::~KeySystemConfigSelector() { |
+} |
+ |
+bool KeySystemConfigSelector::IsSupportedContentType( |
const std::string& key_system, |
EmeMediaType media_type, |
const std::string& container_mime_type, |
@@ -152,8 +178,8 @@ static bool IsSupportedContentType( |
// is stripped. |
std::vector<std::string> codec_vector; |
net::ParseCodecString(codecs, &codec_vector, true); |
- if (!key_systems.IsSupportedCodecCombination( |
- key_system, media_type, container_lower, codec_vector)) { |
+ if (!key_systems_->IsSupportedCodecCombination( |
+ key_system, media_type, container_lower, codec_vector)) { |
return false; |
} |
@@ -176,13 +202,12 @@ static bool IsSupportedContentType( |
net::IsSupported); |
} |
-static bool GetSupportedCapabilities( |
- const KeySystems& key_systems, |
+bool KeySystemConfigSelector::GetSupportedCapabilities( |
const std::string& key_system, |
EmeMediaType media_type, |
const blink::WebVector<blink::WebMediaKeySystemMediaCapability>& |
requested_media_capabilities, |
- ConfigState* config_state, |
+ KeySystemConfigSelector::ConfigState* config_state, |
std::vector<blink::WebMediaKeySystemMediaCapability>* |
supported_media_capabilities) { |
// From |
@@ -208,7 +233,7 @@ static bool GetSupportedCapabilities( |
// 3.4-3.11. (Implemented by IsSupportedContentType().) |
if (!base::IsStringASCII(capability.mimeType) || |
!base::IsStringASCII(capability.codecs) || |
- !IsSupportedContentType(key_systems, key_system, media_type, |
+ !IsSupportedContentType(key_system, media_type, |
base::UTF16ToASCII(capability.mimeType), |
base::UTF16ToASCII(capability.codecs))) { |
continue; |
@@ -220,7 +245,7 @@ static bool GetSupportedCapabilities( |
// comparison is case-sensitive. |
if (!base::IsStringASCII(capability.robustness)) |
continue; |
- EmeConfigRule robustness_rule = key_systems.GetRobustnessConfigRule( |
+ EmeConfigRule robustness_rule = key_systems_->GetRobustnessConfigRule( |
key_system, media_type, base::UTF16ToASCII(capability.robustness)); |
if (!config_state->IsRuleSupported(robustness_rule)) |
continue; |
@@ -248,30 +273,12 @@ static bool GetSupportedCapabilities( |
return true; |
} |
-static EmeFeatureRequirement ConvertRequirement( |
- blink::WebMediaKeySystemConfiguration::Requirement requirement) { |
- switch (requirement) { |
- case blink::WebMediaKeySystemConfiguration::Requirement::Required: |
- return EME_FEATURE_REQUIRED; |
- case blink::WebMediaKeySystemConfiguration::Requirement::Optional: |
- return EME_FEATURE_OPTIONAL; |
- case blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed: |
- return EME_FEATURE_NOT_ALLOWED; |
- } |
- |
- NOTREACHED(); |
- return EME_FEATURE_NOT_ALLOWED; |
-} |
- |
-static ConfigurationSupport GetSupportedConfiguration( |
- const KeySystems& key_systems, |
+KeySystemConfigSelector::ConfigurationSupport |
+KeySystemConfigSelector::GetSupportedConfiguration( |
const std::string& key_system, |
const blink::WebMediaKeySystemConfiguration& candidate, |
- bool was_permission_requested, |
- bool is_permission_granted, |
+ ConfigState* config_state, |
blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
- ConfigState config_state(was_permission_requested, is_permission_granted); |
- |
// From https://w3c.github.io/encrypted-media/#get-supported-configuration |
// 1. Let accumulated configuration be empty. (Done by caller.) |
// 2. If the initDataTypes member is present in candidate configuration, run |
@@ -289,9 +296,7 @@ static ConfigurationSupport GetSupportedConfiguration( |
// initDataType, add initDataType to supported types. String |
// comparison is case-sensitive. The empty string is never |
// supported. |
- if (init_data_type == blink::WebEncryptedMediaInitDataType::Unknown) |
- continue; |
- if (key_systems.IsSupportedInitDataType( |
+ if (key_systems_->IsSupportedInitDataType( |
key_system, ConvertToEmeInitDataType(init_data_type))) { |
supported_types.push_back(init_data_type); |
} |
@@ -319,14 +324,14 @@ static ConfigurationSupport GetSupportedConfiguration( |
// null. |
// We also reject OPTIONAL when distinctive identifiers are ALWAYS_ENABLED and |
// permission has already been denied. This would happen anyway at step 11. |
- EmeConfigRule di_rule = key_systems.GetDistinctiveIdentifierConfigRule( |
+ EmeConfigRule di_rule = key_systems_->GetDistinctiveIdentifierConfigRule( |
key_system, ConvertRequirement(candidate.distinctiveIdentifier)); |
- if (!config_state.IsRuleSupported(di_rule)) { |
+ if (!config_state->IsRuleSupported(di_rule)) { |
DVLOG(2) << "Rejecting requested configuration because " |
<< "the distinctiveIdentifier requirement was not supported."; |
return CONFIGURATION_NOT_SUPPORTED; |
} |
- config_state.AddRule(di_rule); |
+ config_state->AddRule(di_rule); |
// 4. Add the value of the candidate configuration's distinctiveIdentifier |
// member to accumulated configuration. |
@@ -340,14 +345,14 @@ static ConfigurationSupport GetSupportedConfiguration( |
// - "optional": Continue. |
// - "not-allowed": If the implementation requires persisting state in |
// combination with accumulated configuration, return null. |
- EmeConfigRule ps_rule = key_systems.GetPersistentStateConfigRule( |
+ EmeConfigRule ps_rule = key_systems_->GetPersistentStateConfigRule( |
key_system, ConvertRequirement(candidate.persistentState)); |
- if (!config_state.IsRuleSupported(ps_rule)) { |
+ if (!config_state->IsRuleSupported(ps_rule)) { |
DVLOG(2) << "Rejecting requested configuration because " |
<< "the persistentState requirement was not supported."; |
return CONFIGURATION_NOT_SUPPORTED; |
} |
- config_state.AddRule(ps_rule); |
+ config_state->AddRule(ps_rule); |
// 6. Add the value of the candidate configuration's persistentState |
// member to accumulated configuration. |
@@ -391,20 +396,20 @@ static ConfigurationSupport GetSupportedConfiguration( |
break; |
case blink::WebEncryptedMediaSessionType::PersistentLicense: |
session_type_rule = |
- key_systems.GetPersistentLicenseSessionConfigRule(key_system); |
+ key_systems_->GetPersistentLicenseSessionConfigRule(key_system); |
break; |
case blink::WebEncryptedMediaSessionType::PersistentReleaseMessage: |
session_type_rule = |
- key_systems.GetPersistentReleaseMessageSessionConfigRule( |
+ key_systems_->GetPersistentReleaseMessageSessionConfigRule( |
key_system); |
break; |
} |
- if (!config_state.IsRuleSupported(session_type_rule)) { |
+ if (!config_state->IsRuleSupported(session_type_rule)) { |
DVLOG(2) << "Rejecting requested configuration because " |
<< "a required session type was not supported."; |
return CONFIGURATION_NOT_SUPPORTED; |
} |
- config_state.AddRule(session_type_rule); |
+ config_state->AddRule(session_type_rule); |
} |
// 9. Add session types to accumulated configuration. |
@@ -418,9 +423,9 @@ static ConfigurationSupport GetSupportedConfiguration( |
// configuration. |
// 10.2. If video capabilities is null, return null. |
std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities; |
- if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::VIDEO, |
- candidate.videoCapabilities, |
- &config_state, &video_capabilities)) { |
+ if (!GetSupportedCapabilities(key_system, EmeMediaType::VIDEO, |
+ candidate.videoCapabilities, config_state, |
+ &video_capabilities)) { |
return CONFIGURATION_NOT_SUPPORTED; |
} |
@@ -436,9 +441,9 @@ static ConfigurationSupport GetSupportedConfiguration( |
// configuration. |
// 11.2. If audio capabilities is null, return null. |
std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities; |
- if (!GetSupportedCapabilities(key_systems, key_system, EmeMediaType::AUDIO, |
- candidate.audioCapabilities, |
- &config_state, &audio_capabilities)) { |
+ if (!GetSupportedCapabilities(key_system, EmeMediaType::AUDIO, |
+ candidate.audioCapabilities, config_state, |
+ &audio_capabilities)) { |
return CONFIGURATION_NOT_SUPPORTED; |
} |
@@ -457,28 +462,28 @@ static ConfigurationSupport GetSupportedConfiguration( |
if (accumulated_configuration->distinctiveIdentifier == |
blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
EmeConfigRule not_allowed_rule = |
- key_systems.GetDistinctiveIdentifierConfigRule( |
+ key_systems_->GetDistinctiveIdentifierConfigRule( |
key_system, EME_FEATURE_NOT_ALLOWED); |
EmeConfigRule required_rule = |
- key_systems.GetDistinctiveIdentifierConfigRule( |
- key_system, EME_FEATURE_REQUIRED); |
- bool not_allowed_supported = config_state.IsRuleSupported(not_allowed_rule); |
- bool required_supported = config_state.IsRuleSupported(required_rule); |
+ key_systems_->GetDistinctiveIdentifierConfigRule(key_system, |
+ EME_FEATURE_REQUIRED); |
+ bool not_allowed_supported = |
+ config_state->IsRuleSupported(not_allowed_rule); |
+ bool required_supported = config_state->IsRuleSupported(required_rule); |
// If a distinctive identifier is recommend and that is a possible outcome, |
// prefer that. |
- if (required_supported && |
- config_state.IsIdentifierRecommended() && |
- config_state.IsPermissionPossible()) { |
+ if (required_supported && config_state->IsIdentifierRecommended() && |
+ config_state->IsPermissionPossible()) { |
not_allowed_supported = false; |
} |
if (not_allowed_supported) { |
accumulated_configuration->distinctiveIdentifier = |
blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
- config_state.AddRule(not_allowed_rule); |
+ config_state->AddRule(not_allowed_rule); |
} else if (required_supported) { |
accumulated_configuration->distinctiveIdentifier = |
blink::WebMediaKeySystemConfiguration::Requirement::Required; |
- config_state.AddRule(required_rule); |
+ config_state->AddRule(required_rule); |
} else { |
// We should not have passed step 3. |
NOTREACHED(); |
@@ -496,29 +501,26 @@ static ConfigurationSupport GetSupportedConfiguration( |
// to "not-allowed". |
if (accumulated_configuration->persistentState == |
blink::WebMediaKeySystemConfiguration::Requirement::Optional) { |
- EmeConfigRule not_allowed_rule = |
- key_systems.GetPersistentStateConfigRule( |
- key_system, EME_FEATURE_NOT_ALLOWED); |
- EmeConfigRule required_rule = |
- key_systems.GetPersistentStateConfigRule( |
- key_system, EME_FEATURE_REQUIRED); |
+ EmeConfigRule not_allowed_rule = key_systems_->GetPersistentStateConfigRule( |
+ key_system, EME_FEATURE_NOT_ALLOWED); |
+ EmeConfigRule required_rule = key_systems_->GetPersistentStateConfigRule( |
+ key_system, EME_FEATURE_REQUIRED); |
// |distinctiveIdentifier| should not be affected after it is decided. |
DCHECK(not_allowed_rule == EmeConfigRule::NOT_SUPPORTED || |
not_allowed_rule == EmeConfigRule::PERSISTENCE_NOT_ALLOWED); |
DCHECK(required_rule == EmeConfigRule::NOT_SUPPORTED || |
required_rule == EmeConfigRule::PERSISTENCE_REQUIRED); |
bool not_allowed_supported = |
- config_state.IsRuleSupported(not_allowed_rule); |
- bool required_supported = |
- config_state.IsRuleSupported(required_rule); |
+ config_state->IsRuleSupported(not_allowed_rule); |
+ bool required_supported = config_state->IsRuleSupported(required_rule); |
if (not_allowed_supported) { |
accumulated_configuration->persistentState = |
blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed; |
- config_state.AddRule(not_allowed_rule); |
+ config_state->AddRule(not_allowed_rule); |
} else if (required_supported) { |
accumulated_configuration->persistentState = |
blink::WebMediaKeySystemConfiguration::Requirement::Required; |
- config_state.AddRule(required_rule); |
+ config_state->AddRule(required_rule); |
} else { |
// We should not have passed step 5. |
NOTREACHED(); |
@@ -535,7 +537,7 @@ static ConfigurationSupport GetSupportedConfiguration( |
blink::WebMediaKeySystemConfiguration::Requirement::Required) { |
// The caller is responsible for resolving what to do if permission is |
// required but has been denied (it should treat it as NOT_SUPPORTED). |
- if (!config_state.IsPermissionGranted()) |
+ if (!config_state->IsPermissionGranted()) |
return CONFIGURATION_REQUIRES_PERMISSION; |
} |
@@ -548,183 +550,96 @@ static ConfigurationSupport GetSupportedConfiguration( |
return CONFIGURATION_SUPPORTED; |
} |
-// Report usage of key system to UMA. There are 2 different counts logged: |
-// 1. The key system is requested. |
-// 2. The requested key system and options are supported. |
-// Each stat is only reported once per renderer frame per key system. |
-// Note that WebEncryptedMediaClientImpl is only created once by each |
-// renderer frame. |
-class WebEncryptedMediaClientImpl::Reporter { |
- public: |
- enum KeySystemSupportStatus { |
- KEY_SYSTEM_REQUESTED = 0, |
- KEY_SYSTEM_SUPPORTED = 1, |
- KEY_SYSTEM_SUPPORT_STATUS_COUNT |
- }; |
- |
- explicit Reporter(const std::string& key_system_for_uma) |
- : uma_name_(kKeySystemSupportUMAPrefix + key_system_for_uma), |
- is_request_reported_(false), |
- is_support_reported_(false) {} |
- ~Reporter() {} |
- |
- void ReportRequested() { |
- if (is_request_reported_) |
- return; |
- Report(KEY_SYSTEM_REQUESTED); |
- is_request_reported_ = true; |
- } |
- |
- void ReportSupported() { |
- DCHECK(is_request_reported_); |
- if (is_support_reported_) |
- return; |
- Report(KEY_SYSTEM_SUPPORTED); |
- is_support_reported_ = true; |
- } |
- |
- private: |
- void Report(KeySystemSupportStatus status) { |
- // Not using UMA_HISTOGRAM_ENUMERATION directly because UMA_* macros |
- // require the names to be constant throughout the process' lifetime. |
- base::LinearHistogram::FactoryGet( |
- uma_name_, 1, KEY_SYSTEM_SUPPORT_STATUS_COUNT, |
- KEY_SYSTEM_SUPPORT_STATUS_COUNT + 1, |
- base::Histogram::kUmaTargetedHistogramFlag)->Add(status); |
- } |
- |
- const std::string uma_name_; |
- bool is_request_reported_; |
- bool is_support_reported_; |
-}; |
- |
-WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( |
- CdmFactory* cdm_factory, |
- MediaPermission* media_permission) |
- : key_systems_(KeySystems::GetInstance()), |
- cdm_factory_(cdm_factory), |
- media_permission_(media_permission), |
- weak_factory_(this) { |
- DCHECK(media_permission); |
-} |
- |
-WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { |
-} |
- |
-void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
- blink::WebEncryptedMediaRequest request) { |
- // TODO(jrummell): This should be asynchronous, ideally not on the main |
- // thread. |
- |
+void KeySystemConfigSelector::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) { |
// Continued from requestMediaKeySystemAccess(), step 7, from |
// https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
// |
// 7.1. If keySystem is not one of the Key Systems supported by the user |
// agent, reject promise with with a new DOMException whose name is |
// NotSupportedError. String comparison is case-sensitive. |
- if (!base::IsStringASCII(request.keySystem())) { |
- request.requestNotSupported("Only ASCII keySystems are supported"); |
+ if (!base::IsStringASCII(key_system)) { |
+ not_supported_cb.Run("Only ASCII keySystems are supported"); |
return; |
} |
- // Report this request to the UMA. |
- std::string key_system = base::UTF16ToASCII(request.keySystem()); |
- GetReporter(key_system)->ReportRequested(); |
- |
- if (!key_systems_.IsSupportedKeySystem(key_system)) { |
- request.requestNotSupported("Unsupported keySystem"); |
+ std::string key_system_ascii = base::UTF16ToASCII(key_system); |
+ if (!key_systems_->IsSupportedKeySystem(key_system_ascii)) { |
+ not_supported_cb.Run("Unsupported keySystem"); |
return; |
} |
- // 7.2-7.4. Implemented by SelectSupportedConfiguration(). |
- SelectSupportedConfiguration(request, false, false); |
+ // 7.2-7.4. Implemented by OnSelectConfig(). |
+ // TODO(sandersd): This should be async, ideally not on the main thread. |
+ scoped_ptr<SelectionRequest> request(new SelectionRequest()); |
+ request->key_system = key_system_ascii; |
+ request->candidate_configurations = candidate_configurations; |
+ request->security_origin = security_origin; |
+ request->succeeded_cb = succeeded_cb; |
+ request->not_supported_cb = not_supported_cb; |
+ SelectConfigInternal(request.Pass()); |
} |
-void WebEncryptedMediaClientImpl::SelectSupportedConfiguration( |
- blink::WebEncryptedMediaRequest request, |
- bool was_permission_requested, |
- bool is_permission_granted) { |
+void KeySystemConfigSelector::SelectConfigInternal( |
+ scoped_ptr<SelectionRequest> request) { |
// Continued from requestMediaKeySystemAccess(), step 7.1, from |
// https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
// |
// 7.2. Let implementation be the implementation of keySystem. |
- std::string key_system = base::UTF16ToASCII(request.keySystem()); |
- |
+ // (|key_systems_| fills this role.) |
// 7.3. For each value in supportedConfigurations: |
- const blink::WebVector<blink::WebMediaKeySystemConfiguration>& |
- configurations = request.supportedConfigurations(); |
- for (size_t i = 0; i < configurations.size(); i++) { |
+ for (size_t i = 0; i < request->candidate_configurations.size(); i++) { |
// 7.3.1. Let candidate configuration be the value. |
- const blink::WebMediaKeySystemConfiguration& candidate_configuration = |
- configurations[i]; |
// 7.3.2. Let supported configuration be the result of executing the Get |
// Supported Configuration algorithm on implementation, candidate |
// configuration, and origin. |
// 7.3.3. If supported configuration is not null, [initialize and return a |
// new MediaKeySystemAccess object.] |
+ ConfigState config_state(request->was_permission_requested, |
+ request->is_permission_granted); |
blink::WebMediaKeySystemConfiguration accumulated_configuration; |
- ConfigurationSupport supported = GetSupportedConfiguration( |
- key_systems_, key_system, candidate_configuration, |
- was_permission_requested, is_permission_granted, |
- &accumulated_configuration); |
- switch (supported) { |
+ ConfigurationSupport support = GetSupportedConfiguration( |
+ request->key_system, request->candidate_configurations[i], |
+ &config_state, &accumulated_configuration); |
+ switch (support) { |
case CONFIGURATION_NOT_SUPPORTED: |
continue; |
case CONFIGURATION_REQUIRES_PERMISSION: |
- if (was_permission_requested) { |
+ if (request->was_permission_requested) { |
DVLOG(2) << "Rejecting requested configuration because " |
<< "permission was denied."; |
continue; |
} |
media_permission_->RequestPermission( |
MediaPermission::PROTECTED_MEDIA_IDENTIFIER, |
- GURL(request.securityOrigin().toString()), |
- // Try again with |was_permission_requested| true and |
- // |is_permission_granted| the value of the permission. |
- base::Bind( |
- &WebEncryptedMediaClientImpl::SelectSupportedConfiguration, |
- weak_factory_.GetWeakPtr(), request, true)); |
+ GURL(request->security_origin.toString()), |
+ base::Bind(&KeySystemConfigSelector::OnPermissionResult, |
+ weak_factory_.GetWeakPtr(), base::Passed(&request))); |
return; |
case CONFIGURATION_SUPPORTED: |
- // Report that this request succeeded to the UMA. |
- GetReporter(key_system)->ReportSupported(); |
- request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
- request.keySystem(), accumulated_configuration, |
- request.securityOrigin(), weak_factory_.GetWeakPtr())); |
+ request->succeeded_cb.Run(accumulated_configuration); |
return; |
} |
} |
// 7.4. Reject promise with a new DOMException whose name is |
// NotSupportedError. |
- request.requestNotSupported( |
+ request->not_supported_cb.Run( |
"None of the requested configurations were supported."); |
} |
-void WebEncryptedMediaClientImpl::CreateCdm( |
- const blink::WebString& key_system, |
- bool allow_distinctive_identifier, |
- bool allow_persistent_state, |
- const blink::WebSecurityOrigin& security_origin, |
- blink::WebContentDecryptionModuleResult result) { |
- WebContentDecryptionModuleImpl::Create( |
- cdm_factory_, key_system, allow_distinctive_identifier, |
- allow_persistent_state, security_origin, result); |
-} |
- |
-// Lazily create Reporters. |
-WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( |
- const std::string& key_system) { |
- std::string uma_name = GetKeySystemNameForUMA(key_system); |
- Reporter* reporter = reporters_.get(uma_name); |
- if (reporter != nullptr) |
- return reporter; |
- |
- // Reporter not found, so create one. |
- auto result = |
- reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
- DCHECK(result.second); |
- return result.first->second; |
+void KeySystemConfigSelector::OnPermissionResult( |
+ scoped_ptr<SelectionRequest> request, |
+ bool is_permission_granted) { |
+ request->was_permission_requested = true; |
+ request->is_permission_granted = is_permission_granted; |
+ SelectConfigInternal(request.Pass()); |
} |
} // namespace media |