Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "key_system_config_selector.h" | 5 #include "key_system_config_selector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 struct KeySystemConfigSelector::SelectionRequest { | 129 struct KeySystemConfigSelector::SelectionRequest { |
| 130 std::string key_system; | 130 std::string key_system; |
| 131 blink::WebVector<blink::WebMediaKeySystemConfiguration> | 131 blink::WebVector<blink::WebMediaKeySystemConfiguration> |
| 132 candidate_configurations; | 132 candidate_configurations; |
| 133 blink::WebSecurityOrigin security_origin; | 133 blink::WebSecurityOrigin security_origin; |
| 134 base::Callback<void(const blink::WebMediaKeySystemConfiguration&)> | 134 base::Callback<void(const blink::WebMediaKeySystemConfiguration&)> |
| 135 succeeded_cb; | 135 succeeded_cb; |
| 136 base::Callback<void(const blink::WebString&)> not_supported_cb; | 136 base::Callback<void(const blink::WebString&)> not_supported_cb; |
| 137 bool was_permission_requested = false; | 137 bool was_permission_requested = false; |
| 138 bool is_permission_granted = false; | 138 bool is_permission_granted = false; |
| 139 #if defined(OS_ANDROID) | |
| 140 bool allow_secure_surfaces = false; | |
| 141 #endif // defined(OS_ANDROID) | |
| 139 }; | 142 }; |
| 140 | 143 |
| 141 // Accumulates configuration rules to determine if a feature (additional | 144 // Accumulates configuration rules to determine if a feature (additional |
| 142 // configuration rule) can be added to an accumulated configuration. | 145 // configuration rule) can be added to an accumulated configuration. |
| 143 class KeySystemConfigSelector::ConfigState { | 146 class KeySystemConfigSelector::ConfigState { |
| 144 public: | 147 public: |
| 145 ConfigState(bool was_permission_requested, bool is_permission_granted) | 148 ConfigState(bool was_permission_requested, bool is_permission_granted) |
| 146 : was_permission_requested_(was_permission_requested), | 149 : was_permission_requested_(was_permission_requested), |
| 147 is_permission_granted_(is_permission_granted) {} | 150 is_permission_granted_(is_permission_granted) {} |
| 148 | 151 |
| 149 bool IsPermissionGranted() const { return is_permission_granted_; } | 152 bool IsPermissionGranted() const { return is_permission_granted_; } |
| 150 | 153 |
| 151 // Permission is possible if it has not been denied. | 154 // Permission is possible if it has not been denied. |
| 152 bool IsPermissionPossible() const { | 155 bool IsPermissionPossible() const { |
| 153 return is_permission_granted_ || !was_permission_requested_; | 156 return is_permission_granted_ || !was_permission_requested_; |
| 154 } | 157 } |
| 155 | 158 |
| 156 bool IsIdentifierRequired() const { return is_identifier_required_; } | 159 bool IsIdentifierRequired() const { return is_identifier_required_; } |
| 157 | 160 |
| 158 bool IsIdentifierRecommended() const { return is_identifier_recommended_; } | 161 bool IsIdentifierRecommended() const { return is_identifier_recommended_; } |
| 159 | 162 |
| 163 bool AreSecureCodecsRequired() const { return are_secure_codecs_required_; } | |
| 164 | |
| 160 // Checks whether a rule is compatible with all previously added rules. | 165 // Checks whether a rule is compatible with all previously added rules. |
| 161 bool IsRuleSupported(EmeConfigRule rule) const { | 166 bool IsRuleSupported(EmeConfigRule rule) const { |
| 162 switch (rule) { | 167 switch (rule) { |
| 163 case EmeConfigRule::NOT_SUPPORTED: | 168 case EmeConfigRule::NOT_SUPPORTED: |
| 164 return false; | 169 return false; |
| 165 case EmeConfigRule::IDENTIFIER_NOT_ALLOWED: | 170 case EmeConfigRule::IDENTIFIER_NOT_ALLOWED: |
| 166 return !is_identifier_required_; | 171 return !is_identifier_required_; |
| 167 case EmeConfigRule::IDENTIFIER_REQUIRED: | 172 case EmeConfigRule::IDENTIFIER_REQUIRED: |
| 168 // TODO(sandersd): Confirm if we should be refusing these rules when | 173 // TODO(sandersd): Confirm if we should be refusing these rules when |
| 169 // permission has been denied (as the spec currently says). | 174 // permission has been denied (as the spec currently says). |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 // 5. Return media type capabilities. | 390 // 5. Return media type capabilities. |
| 386 return true; | 391 return true; |
| 387 } | 392 } |
| 388 | 393 |
| 389 KeySystemConfigSelector::ConfigurationSupport | 394 KeySystemConfigSelector::ConfigurationSupport |
| 390 KeySystemConfigSelector::GetSupportedConfiguration( | 395 KeySystemConfigSelector::GetSupportedConfiguration( |
| 391 const std::string& key_system, | 396 const std::string& key_system, |
| 392 const blink::WebMediaKeySystemConfiguration& candidate, | 397 const blink::WebMediaKeySystemConfiguration& candidate, |
| 393 ConfigState* config_state, | 398 ConfigState* config_state, |
| 394 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { | 399 blink::WebMediaKeySystemConfiguration* accumulated_configuration) { |
| 395 // TODO(sandersd): Set state of SECURE_CODECS from renderer pref. | |
| 396 // From https://w3c.github.io/encrypted-media/#get-supported-configuration | 400 // From https://w3c.github.io/encrypted-media/#get-supported-configuration |
| 397 // 1. Let accumulated configuration be empty. (Done by caller.) | 401 // 1. Let accumulated configuration be empty. (Done by caller.) |
| 398 // 2. If the initDataTypes member is present in candidate configuration, run | 402 // 2. If the initDataTypes member is present in candidate configuration, run |
| 399 // the following steps: | 403 // the following steps: |
| 400 if (candidate.hasInitDataTypes) { | 404 if (candidate.hasInitDataTypes) { |
| 401 // 2.1. Let supported types be empty. | 405 // 2.1. Let supported types be empty. |
| 402 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; | 406 std::vector<blink::WebEncryptedMediaInitDataType> supported_types; |
| 403 | 407 |
| 404 // 2.2. For each value in candidate configuration's initDataTypes member: | 408 // 2.2. For each value in candidate configuration's initDataTypes member: |
| 405 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { | 409 for (size_t i = 0; i < candidate.initDataTypes.size(); i++) { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 // value of the candidate configuration's label member to accumulated | 667 // value of the candidate configuration's label member to accumulated |
| 664 // configuration. | 668 // configuration. |
| 665 accumulated_configuration->label = candidate.label; | 669 accumulated_configuration->label = candidate.label; |
| 666 | 670 |
| 667 // 17. Return accumulated configuration. | 671 // 17. Return accumulated configuration. |
| 668 return CONFIGURATION_SUPPORTED; | 672 return CONFIGURATION_SUPPORTED; |
| 669 } | 673 } |
| 670 | 674 |
| 671 void KeySystemConfigSelector::SelectConfig( | 675 void KeySystemConfigSelector::SelectConfig( |
| 672 const blink::WebString& key_system, | 676 const blink::WebString& key_system, |
| 677 #if defined(OS_ANDROID) | |
| 678 const bool allow_secure_surfaces, | |
| 679 #endif // defined(OS_ANDROID) | |
| 673 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& | 680 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& |
| 674 candidate_configurations, | 681 candidate_configurations, |
| 675 const blink::WebSecurityOrigin& security_origin, | 682 const blink::WebSecurityOrigin& security_origin, |
| 676 base::Callback<void(const blink::WebMediaKeySystemConfiguration&)> | 683 base::Callback<void(const blink::WebMediaKeySystemConfiguration&)> |
| 677 succeeded_cb, | 684 succeeded_cb, |
| 678 base::Callback<void(const blink::WebString&)> not_supported_cb) { | 685 base::Callback<void(const blink::WebString&)> not_supported_cb) { |
| 679 // Continued from requestMediaKeySystemAccess(), step 7, from | 686 // Continued from requestMediaKeySystemAccess(), step 7, from |
| 680 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | 687 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
| 681 // | 688 // |
| 682 // 7.1. If keySystem is not one of the Key Systems supported by the user | 689 // 7.1. If keySystem is not one of the Key Systems supported by the user |
| 683 // agent, reject promise with with a new DOMException whose name is | 690 // agent, reject promise with with a new DOMException whose name is |
| 684 // NotSupportedError. String comparison is case-sensitive. | 691 // NotSupportedError. String comparison is case-sensitive. |
| 685 if (!base::IsStringASCII(key_system)) { | 692 if (!base::IsStringASCII(key_system)) { |
| 686 not_supported_cb.Run("Only ASCII keySystems are supported"); | 693 not_supported_cb.Run("Only ASCII keySystems are supported"); |
| 687 return; | 694 return; |
| 688 } | 695 } |
| 689 | 696 |
| 690 std::string key_system_ascii = base::UTF16ToASCII(key_system); | 697 std::string key_system_ascii = base::UTF16ToASCII(key_system); |
| 691 if (!key_systems_->IsSupportedKeySystem(key_system_ascii)) { | 698 if (!key_systems_->IsSupportedKeySystem(key_system_ascii)) { |
| 692 not_supported_cb.Run("Unsupported keySystem"); | 699 not_supported_cb.Run("Unsupported keySystem"); |
| 693 return; | 700 return; |
| 694 } | 701 } |
| 695 | 702 |
| 696 // 7.2-7.4. Implemented by OnSelectConfig(). | 703 // 7.2-7.4. Implemented by OnSelectConfig(). |
| 697 // TODO(sandersd): This should be async, ideally not on the main thread. | 704 // TODO(sandersd): This should be async, ideally not on the main thread. |
| 698 scoped_ptr<SelectionRequest> request(new SelectionRequest()); | 705 scoped_ptr<SelectionRequest> request(new SelectionRequest()); |
| 699 request->key_system = key_system_ascii; | 706 request->key_system = key_system_ascii; |
| 707 #if defined(OS_ANDROID) | |
| 708 request->allow_secure_surfaces = allow_secure_surfaces; | |
| 709 #endif // defined(OS_ANDROID) | |
| 700 request->candidate_configurations = candidate_configurations; | 710 request->candidate_configurations = candidate_configurations; |
| 701 request->security_origin = security_origin; | 711 request->security_origin = security_origin; |
| 702 request->succeeded_cb = succeeded_cb; | 712 request->succeeded_cb = succeeded_cb; |
| 703 request->not_supported_cb = not_supported_cb; | 713 request->not_supported_cb = not_supported_cb; |
| 704 SelectConfigInternal(request.Pass()); | 714 SelectConfigInternal(request.Pass()); |
| 705 } | 715 } |
| 706 | 716 |
| 707 void KeySystemConfigSelector::SelectConfigInternal( | 717 void KeySystemConfigSelector::SelectConfigInternal( |
| 708 scoped_ptr<SelectionRequest> request) { | 718 scoped_ptr<SelectionRequest> request) { |
| 709 // Continued from requestMediaKeySystemAccess(), step 7.1, from | 719 // Continued from requestMediaKeySystemAccess(), step 7.1, from |
| 710 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | 720 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
| 711 // | 721 // |
| 712 // 7.2. Let implementation be the implementation of keySystem. | 722 // 7.2. Let implementation be the implementation of keySystem. |
| 713 // (|key_systems_| fills this role.) | 723 // (|key_systems_| fills this role.) |
| 714 // 7.3. For each value in supportedConfigurations: | 724 // 7.3. For each value in supportedConfigurations: |
| 715 for (size_t i = 0; i < request->candidate_configurations.size(); i++) { | 725 for (size_t i = 0; i < request->candidate_configurations.size(); i++) { |
| 716 // 7.3.1. Let candidate configuration be the value. | 726 // 7.3.1. Let candidate configuration be the value. |
| 717 // 7.3.2. Let supported configuration be the result of executing the Get | 727 // 7.3.2. Let supported configuration be the result of executing the Get |
| 718 // Supported Configuration algorithm on implementation, candidate | 728 // Supported Configuration algorithm on implementation, candidate |
| 719 // configuration, and origin. | 729 // configuration, and origin. |
| 720 // 7.3.3. If supported configuration is not null, [initialize and return a | 730 // 7.3.3. If supported configuration is not null, [initialize and return a |
| 721 // new MediaKeySystemAccess object.] | 731 // new MediaKeySystemAccess object.] |
| 722 ConfigState config_state(request->was_permission_requested, | 732 ConfigState config_state(request->was_permission_requested, |
| 723 request->is_permission_granted); | 733 request->is_permission_granted); |
| 734 #if defined(OS_ANDROID) | |
| 735 // On Android, hardware-secure codecs are not allowed when the renderer | |
| 736 // preference is not enabled. | |
|
ddorwin
2015/05/06 02:17:11
This comment is specific to code outside the funct
sandersd (OOO until July 31)
2015/05/08 00:37:42
Done.
| |
| 737 DCHECK(config_state.IsRuleSupported( | |
| 738 EmeConfigRule::SECURE_CODECS_NOT_ALLOWED); | |
| 739 if (!request->allow_secure_surfaces) | |
| 740 config_state.AddRule(EmeConfigRule::SECURE_CODECS_NOT_ALLOWED); | |
| 741 #endif // defined(OS_ANDROID) | |
| 724 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 742 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
| 725 ConfigurationSupport support = GetSupportedConfiguration( | 743 ConfigurationSupport support = GetSupportedConfiguration( |
| 726 request->key_system, request->candidate_configurations[i], | 744 request->key_system, request->candidate_configurations[i], |
| 727 &config_state, &accumulated_configuration); | 745 &config_state, &accumulated_configuration); |
| 728 switch (support) { | 746 switch (support) { |
| 729 case CONFIGURATION_NOT_SUPPORTED: | 747 case CONFIGURATION_NOT_SUPPORTED: |
| 730 continue; | 748 continue; |
| 731 case CONFIGURATION_REQUIRES_PERMISSION: | 749 case CONFIGURATION_REQUIRES_PERMISSION: |
| 732 if (request->was_permission_requested) { | 750 if (request->was_permission_requested) { |
| 733 DVLOG(2) << "Rejecting requested configuration because " | 751 DVLOG(2) << "Rejecting requested configuration because " |
| 734 << "permission was denied."; | 752 << "permission was denied."; |
| 735 continue; | 753 continue; |
| 736 } | 754 } |
| 737 media_permission_->RequestPermission( | 755 media_permission_->RequestPermission( |
| 738 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, | 756 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, |
| 739 GURL(request->security_origin.toString()), | 757 GURL(request->security_origin.toString()), |
| 740 base::Bind(&KeySystemConfigSelector::OnPermissionResult, | 758 base::Bind(&KeySystemConfigSelector::OnPermissionResult, |
| 741 weak_factory_.GetWeakPtr(), base::Passed(&request))); | 759 weak_factory_.GetWeakPtr(), base::Passed(&request))); |
| 742 return; | 760 return; |
| 743 case CONFIGURATION_SUPPORTED: | 761 case CONFIGURATION_SUPPORTED: |
| 762 #if defined(OS_ANDROID) | |
| 763 request->succeeded_cb.Run(accumulated_configuration, | |
| 764 config_state.AreSecureCodecsRequired()); | |
| 765 #else | |
| 744 request->succeeded_cb.Run(accumulated_configuration); | 766 request->succeeded_cb.Run(accumulated_configuration); |
| 767 #endif // defined(OS_ANDROID) | |
| 745 return; | 768 return; |
| 746 } | 769 } |
| 747 } | 770 } |
| 748 | 771 |
| 749 // 7.4. Reject promise with a new DOMException whose name is | 772 // 7.4. Reject promise with a new DOMException whose name is |
| 750 // NotSupportedError. | 773 // NotSupportedError. |
| 751 request->not_supported_cb.Run( | 774 request->not_supported_cb.Run( |
| 752 "None of the requested configurations were supported."); | 775 "None of the requested configurations were supported."); |
| 753 } | 776 } |
| 754 | 777 |
| 755 void KeySystemConfigSelector::OnPermissionResult( | 778 void KeySystemConfigSelector::OnPermissionResult( |
| 756 scoped_ptr<SelectionRequest> request, | 779 scoped_ptr<SelectionRequest> request, |
| 757 bool is_permission_granted) { | 780 bool is_permission_granted) { |
| 758 request->was_permission_requested = true; | 781 request->was_permission_requested = true; |
| 759 request->is_permission_granted = is_permission_granted; | 782 request->is_permission_granted = is_permission_granted; |
| 760 SelectConfigInternal(request.Pass()); | 783 SelectConfigInternal(request.Pass()); |
| 761 } | 784 } |
| 762 | 785 |
| 763 } // namespace media | 786 } // namespace media |
| OLD | NEW |