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" |
| 11 #include "media/base/cdm_config.h" |
11 #include "media/base/key_systems.h" | 12 #include "media/base/key_systems.h" |
12 #include "media/base/media_permission.h" | 13 #include "media/base/media_permission.h" |
13 #include "media/blink/webmediaplayer_util.h" | 14 #include "media/blink/webmediaplayer_util.h" |
14 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
15 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" | 16 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" |
16 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 17 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
18 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return EmeConfigRule::PERSISTENCE_REQUIRED; | 125 return EmeConfigRule::PERSISTENCE_REQUIRED; |
125 } | 126 } |
126 | 127 |
127 } // namespace | 128 } // namespace |
128 | 129 |
129 struct KeySystemConfigSelector::SelectionRequest { | 130 struct KeySystemConfigSelector::SelectionRequest { |
130 std::string key_system; | 131 std::string key_system; |
131 blink::WebVector<blink::WebMediaKeySystemConfiguration> | 132 blink::WebVector<blink::WebMediaKeySystemConfiguration> |
132 candidate_configurations; | 133 candidate_configurations; |
133 blink::WebSecurityOrigin security_origin; | 134 blink::WebSecurityOrigin security_origin; |
134 base::Callback<void(const blink::WebMediaKeySystemConfiguration&, bool)> | 135 base::Callback<void(const blink::WebMediaKeySystemConfiguration&, |
135 succeeded_cb; | 136 const CdmConfig&)> succeeded_cb; |
136 base::Callback<void(const blink::WebString&)> not_supported_cb; | 137 base::Callback<void(const blink::WebString&)> not_supported_cb; |
137 bool was_permission_requested = false; | 138 bool was_permission_requested = false; |
138 bool is_permission_granted = false; | 139 bool is_permission_granted = false; |
139 bool are_secure_codecs_supported = false; | 140 bool are_secure_codecs_supported = false; |
140 }; | 141 }; |
141 | 142 |
142 // Accumulates configuration rules to determine if a feature (additional | 143 // Accumulates configuration rules to determine if a feature (additional |
143 // configuration rule) can be added to an accumulated configuration. | 144 // configuration rule) can be added to an accumulated configuration. |
144 class KeySystemConfigSelector::ConfigState { | 145 class KeySystemConfigSelector::ConfigState { |
145 public: | 146 public: |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 // 17. Return accumulated configuration. | 667 // 17. Return accumulated configuration. |
667 return CONFIGURATION_SUPPORTED; | 668 return CONFIGURATION_SUPPORTED; |
668 } | 669 } |
669 | 670 |
670 void KeySystemConfigSelector::SelectConfig( | 671 void KeySystemConfigSelector::SelectConfig( |
671 const blink::WebString& key_system, | 672 const blink::WebString& key_system, |
672 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& | 673 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& |
673 candidate_configurations, | 674 candidate_configurations, |
674 const blink::WebSecurityOrigin& security_origin, | 675 const blink::WebSecurityOrigin& security_origin, |
675 bool are_secure_codecs_supported, | 676 bool are_secure_codecs_supported, |
676 base::Callback<void(const blink::WebMediaKeySystemConfiguration&, bool)> | 677 base::Callback<void(const blink::WebMediaKeySystemConfiguration&, |
677 succeeded_cb, | 678 const CdmConfig&)> succeeded_cb, |
678 base::Callback<void(const blink::WebString&)> not_supported_cb) { | 679 base::Callback<void(const blink::WebString&)> not_supported_cb) { |
679 // Continued from requestMediaKeySystemAccess(), step 7, from | 680 // Continued from requestMediaKeySystemAccess(), step 7, from |
680 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess | 681 // https://w3c.github.io/encrypted-media/#requestmediakeysystemaccess |
681 // | 682 // |
682 // 7.1. If keySystem is not one of the Key Systems supported by the user | 683 // 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 | 684 // agent, reject promise with with a new DOMException whose name is |
684 // NotSupportedError. String comparison is case-sensitive. | 685 // NotSupportedError. String comparison is case-sensitive. |
685 if (!base::IsStringASCII(key_system)) { | 686 if (!base::IsStringASCII(key_system)) { |
686 not_supported_cb.Run("Only ASCII keySystems are supported"); | 687 not_supported_cb.Run("Only ASCII keySystems are supported"); |
687 return; | 688 return; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 // configuration, and origin. | 721 // configuration, and origin. |
721 // 7.3.3. If supported configuration is not null, [initialize and return a | 722 // 7.3.3. If supported configuration is not null, [initialize and return a |
722 // new MediaKeySystemAccess object.] | 723 // new MediaKeySystemAccess object.] |
723 ConfigState config_state(request->was_permission_requested, | 724 ConfigState config_state(request->was_permission_requested, |
724 request->is_permission_granted); | 725 request->is_permission_granted); |
725 DCHECK(config_state.IsRuleSupported( | 726 DCHECK(config_state.IsRuleSupported( |
726 EmeConfigRule::SECURE_CODECS_NOT_ALLOWED)); | 727 EmeConfigRule::SECURE_CODECS_NOT_ALLOWED)); |
727 if (!request->are_secure_codecs_supported) | 728 if (!request->are_secure_codecs_supported) |
728 config_state.AddRule(EmeConfigRule::SECURE_CODECS_NOT_ALLOWED); | 729 config_state.AddRule(EmeConfigRule::SECURE_CODECS_NOT_ALLOWED); |
729 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 730 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
| 731 CdmConfig cdm_config; |
730 ConfigurationSupport support = GetSupportedConfiguration( | 732 ConfigurationSupport support = GetSupportedConfiguration( |
731 request->key_system, request->candidate_configurations[i], | 733 request->key_system, request->candidate_configurations[i], |
732 &config_state, &accumulated_configuration); | 734 &config_state, &accumulated_configuration); |
733 switch (support) { | 735 switch (support) { |
734 case CONFIGURATION_NOT_SUPPORTED: | 736 case CONFIGURATION_NOT_SUPPORTED: |
735 continue; | 737 continue; |
736 case CONFIGURATION_REQUIRES_PERMISSION: | 738 case CONFIGURATION_REQUIRES_PERMISSION: |
737 if (request->was_permission_requested) { | 739 if (request->was_permission_requested) { |
738 DVLOG(2) << "Rejecting requested configuration because " | 740 DVLOG(2) << "Rejecting requested configuration because " |
739 << "permission was denied."; | 741 << "permission was denied."; |
740 continue; | 742 continue; |
741 } | 743 } |
742 media_permission_->RequestPermission( | 744 media_permission_->RequestPermission( |
743 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, | 745 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, |
744 GURL(request->security_origin.toString()), | 746 GURL(request->security_origin.toString()), |
745 base::Bind(&KeySystemConfigSelector::OnPermissionResult, | 747 base::Bind(&KeySystemConfigSelector::OnPermissionResult, |
746 weak_factory_.GetWeakPtr(), base::Passed(&request))); | 748 weak_factory_.GetWeakPtr(), base::Passed(&request))); |
747 return; | 749 return; |
748 case CONFIGURATION_SUPPORTED: | 750 case CONFIGURATION_SUPPORTED: |
749 request->succeeded_cb.Run(accumulated_configuration, | 751 cdm_config.allow_distinctive_identifier = |
750 config_state.AreSecureCodecsRequired()); | 752 (accumulated_configuration.distinctiveIdentifier == |
| 753 blink::WebMediaKeySystemConfiguration::Requirement::Required); |
| 754 cdm_config.allow_persistent_state = |
| 755 (accumulated_configuration.persistentState == |
| 756 blink::WebMediaKeySystemConfiguration::Requirement::Required); |
| 757 cdm_config.use_secure_codecs = config_state.AreSecureCodecsRequired(); |
| 758 request->succeeded_cb.Run(accumulated_configuration, cdm_config); |
751 return; | 759 return; |
752 } | 760 } |
753 } | 761 } |
754 | 762 |
755 // 7.4. Reject promise with a new DOMException whose name is | 763 // 7.4. Reject promise with a new DOMException whose name is |
756 // NotSupportedError. | 764 // NotSupportedError. |
757 request->not_supported_cb.Run( | 765 request->not_supported_cb.Run( |
758 "None of the requested configurations were supported."); | 766 "None of the requested configurations were supported."); |
759 } | 767 } |
760 | 768 |
761 void KeySystemConfigSelector::OnPermissionResult( | 769 void KeySystemConfigSelector::OnPermissionResult( |
762 scoped_ptr<SelectionRequest> request, | 770 scoped_ptr<SelectionRequest> request, |
763 bool is_permission_granted) { | 771 bool is_permission_granted) { |
764 request->was_permission_requested = true; | 772 request->was_permission_requested = true; |
765 request->is_permission_granted = is_permission_granted; | 773 request->is_permission_granted = is_permission_granted; |
766 SelectConfigInternal(request.Pass()); | 774 SelectConfigInternal(request.Pass()); |
767 } | 775 } |
768 | 776 |
769 } // namespace media | 777 } // namespace media |
OLD | NEW |