OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ | 3 * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ |
4 * Copyright (C) 2010 Google Inc. All Rights Reserved. | 4 * Copyright (C) 2010 Google Inc. All Rights Reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 const String& attribute_value) { | 129 const String& attribute_value) { |
130 MediaQuerySet* media_queries = MediaQuerySet::Create(attribute_value); | 130 MediaQuerySet* media_queries = MediaQuerySet::Create(attribute_value); |
131 MediaQueryEvaluator media_query_evaluator(media_values); | 131 MediaQueryEvaluator media_query_evaluator(media_values); |
132 return media_query_evaluator.Eval(media_queries); | 132 return media_query_evaluator.Eval(media_queries); |
133 } | 133 } |
134 | 134 |
135 class TokenPreloadScanner::StartTagScanner { | 135 class TokenPreloadScanner::StartTagScanner { |
136 STACK_ALLOCATED(); | 136 STACK_ALLOCATED(); |
137 | 137 |
138 public: | 138 public: |
139 StartTagScanner(const StringImpl* tag_impl, | 139 StartTagScanner(const StringImpl* tag_impl, MediaValuesCached* media_values) |
140 MediaValuesCached* media_values, | |
141 TokenPreloadScanner::ScannerType scanner_type) | |
142 : tag_impl_(tag_impl), | 140 : tag_impl_(tag_impl), |
143 link_is_style_sheet_(false), | 141 link_is_style_sheet_(false), |
144 link_is_preconnect_(false), | 142 link_is_preconnect_(false), |
145 link_is_preload_(false), | 143 link_is_preload_(false), |
146 link_is_import_(false), | 144 link_is_import_(false), |
147 matched_(true), | 145 matched_(true), |
148 input_is_image_(false), | 146 input_is_image_(false), |
149 nomodule_attribute_value_(false), | 147 nomodule_attribute_value_(false), |
150 source_size_(0), | 148 source_size_(0), |
151 source_size_set_(false), | 149 source_size_set_(false), |
152 defer_(FetchParameters::kNoDefer), | 150 defer_(FetchParameters::kNoDefer), |
153 cross_origin_(kCrossOriginAttributeNotSet), | 151 cross_origin_(kCrossOriginAttributeNotSet), |
154 media_values_(media_values), | 152 media_values_(media_values), |
155 referrer_policy_set_(false), | 153 referrer_policy_set_(false), |
156 referrer_policy_(kReferrerPolicyDefault), | 154 referrer_policy_(kReferrerPolicyDefault) { |
157 scanner_type_(scanner_type) { | |
158 if (Match(tag_impl_, imgTag) || Match(tag_impl_, sourceTag)) { | 155 if (Match(tag_impl_, imgTag) || Match(tag_impl_, sourceTag)) { |
159 source_size_ = SizesAttributeParser(media_values_, String()).length(); | 156 source_size_ = SizesAttributeParser(media_values_, String()).length(); |
160 return; | 157 return; |
161 } | 158 } |
162 if (!Match(tag_impl_, inputTag) && !Match(tag_impl_, linkTag) && | 159 if (!Match(tag_impl_, inputTag) && !Match(tag_impl_, linkTag) && |
163 !Match(tag_impl_, scriptTag) && !Match(tag_impl_, videoTag)) | 160 !Match(tag_impl_, scriptTag) && !Match(tag_impl_, videoTag)) |
164 tag_impl_ = 0; | 161 tag_impl_ = 0; |
165 } | 162 } |
166 | 163 |
167 enum URLReplacement { kAllowURLReplacement, kDisallowURLReplacement }; | 164 enum URLReplacement { kAllowURLReplacement, kDisallowURLReplacement }; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 type.value(), referrer_policy, PreloadRequest::kDocumentIsReferrer, | 251 type.value(), referrer_policy, PreloadRequest::kDocumentIsReferrer, |
255 resource_width, client_hints_preferences, request_type); | 252 resource_width, client_hints_preferences, request_type); |
256 if (!request) | 253 if (!request) |
257 return nullptr; | 254 return nullptr; |
258 | 255 |
259 request->SetCrossOrigin(cross_origin_); | 256 request->SetCrossOrigin(cross_origin_); |
260 request->SetNonce(nonce_); | 257 request->SetNonce(nonce_); |
261 request->SetCharset(Charset()); | 258 request->SetCharset(Charset()); |
262 request->SetDefer(defer_); | 259 request->SetDefer(defer_); |
263 request->SetIntegrityMetadata(integrity_metadata_); | 260 request->SetIntegrityMetadata(integrity_metadata_); |
264 if (scanner_type_ == ScannerType::kInsertion) | |
265 request->SetFromInsertionScanner(true); | |
266 | 261 |
267 return request; | 262 return request; |
268 } | 263 } |
269 | 264 |
270 private: | 265 private: |
271 template <typename NameType> | 266 template <typename NameType> |
272 void ProcessScriptAttribute(const NameType& attribute_name, | 267 void ProcessScriptAttribute(const NameType& attribute_name, |
273 const String& attribute_value) { | 268 const String& attribute_value) { |
274 // FIXME - Don't set crossorigin multiple times. | 269 // FIXME - Don't set crossorigin multiple times. |
275 if (Match(attribute_name, srcAttr)) | 270 if (Match(attribute_name, srcAttr)) |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 bool nomodule_attribute_value_; | 567 bool nomodule_attribute_value_; |
573 float source_size_; | 568 float source_size_; |
574 bool source_size_set_; | 569 bool source_size_set_; |
575 FetchParameters::DeferOption defer_; | 570 FetchParameters::DeferOption defer_; |
576 CrossOriginAttributeValue cross_origin_; | 571 CrossOriginAttributeValue cross_origin_; |
577 String nonce_; | 572 String nonce_; |
578 Member<MediaValuesCached> media_values_; | 573 Member<MediaValuesCached> media_values_; |
579 bool referrer_policy_set_; | 574 bool referrer_policy_set_; |
580 ReferrerPolicy referrer_policy_; | 575 ReferrerPolicy referrer_policy_; |
581 IntegrityMetadataSet integrity_metadata_; | 576 IntegrityMetadataSet integrity_metadata_; |
582 TokenPreloadScanner::ScannerType scanner_type_; | |
583 }; | 577 }; |
584 | 578 |
585 TokenPreloadScanner::TokenPreloadScanner( | 579 TokenPreloadScanner::TokenPreloadScanner( |
586 const KURL& document_url, | 580 const KURL& document_url, |
587 std::unique_ptr<CachedDocumentParameters> document_parameters, | 581 std::unique_ptr<CachedDocumentParameters> document_parameters, |
588 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data, | 582 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data) |
589 const ScannerType scanner_type) | |
590 : document_url_(document_url), | 583 : document_url_(document_url), |
591 in_style_(false), | 584 in_style_(false), |
592 in_picture_(false), | 585 in_picture_(false), |
593 in_script_(false), | 586 in_script_(false), |
594 template_count_(0), | 587 template_count_(0), |
595 document_parameters_(std::move(document_parameters)), | 588 document_parameters_(std::move(document_parameters)), |
596 media_values_(MediaValuesCached::Create(media_values_cached_data)), | 589 media_values_(MediaValuesCached::Create(media_values_cached_data)), |
597 scanner_type_(scanner_type), | |
598 did_rewind_(false) { | 590 did_rewind_(false) { |
599 DCHECK(document_parameters_.get()); | 591 DCHECK(document_parameters_.get()); |
600 DCHECK(media_values_.Get()); | 592 DCHECK(media_values_.Get()); |
601 DCHECK(document_url.IsValid()); | 593 DCHECK(document_url.IsValid()); |
602 css_scanner_.SetReferrerPolicy(document_parameters_->referrer_policy); | 594 css_scanner_.SetReferrerPolicy(document_parameters_->referrer_policy); |
603 } | 595 } |
604 | 596 |
605 TokenPreloadScanner::~TokenPreloadScanner() {} | 597 TokenPreloadScanner::~TokenPreloadScanner() {} |
606 | 598 |
607 TokenPreloadScannerCheckpoint TokenPreloadScanner::CreateCheckpoint() { | 599 TokenPreloadScannerCheckpoint TokenPreloadScanner::CreateCheckpoint() { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 HandleMetaNameAttribute(token, document_parameters_.get(), | 847 HandleMetaNameAttribute(token, document_parameters_.get(), |
856 media_values_.Get(), &css_scanner_, viewport); | 848 media_values_.Get(), &css_scanner_, viewport); |
857 } | 849 } |
858 | 850 |
859 if (Match(tag_impl, pictureTag)) { | 851 if (Match(tag_impl, pictureTag)) { |
860 in_picture_ = true; | 852 in_picture_ = true; |
861 picture_data_ = PictureData(); | 853 picture_data_ = PictureData(); |
862 return; | 854 return; |
863 } | 855 } |
864 | 856 |
865 StartTagScanner scanner(tag_impl, media_values_, scanner_type_); | 857 StartTagScanner scanner(tag_impl, media_values_); |
866 scanner.ProcessAttributes(token.Attributes()); | 858 scanner.ProcessAttributes(token.Attributes()); |
867 // TODO(yoav): ViewportWidth is currently racy and might be zero in some | 859 // TODO(yoav): ViewportWidth is currently racy and might be zero in some |
868 // cases, at least in tests. That problem will go away once | 860 // cases, at least in tests. That problem will go away once |
869 // ParseHTMLOnMainThread lands and MediaValuesCached is eliminated. | 861 // ParseHTMLOnMainThread lands and MediaValuesCached is eliminated. |
870 if (in_picture_ && media_values_->ViewportWidth()) | 862 if (in_picture_ && media_values_->ViewportWidth()) |
871 scanner.HandlePictureSourceURL(picture_data_); | 863 scanner.HandlePictureSourceURL(picture_data_); |
872 std::unique_ptr<PreloadRequest> request = scanner.CreatePreloadRequest( | 864 std::unique_ptr<PreloadRequest> request = scanner.CreatePreloadRequest( |
873 predicted_base_element_url_, source, client_hints_preferences_, | 865 predicted_base_element_url_, source, client_hints_preferences_, |
874 picture_data_, document_parameters_->referrer_policy); | 866 picture_data_, document_parameters_->referrer_policy); |
875 if (request) | 867 if (request) |
(...skipping 13 matching lines...) Expand all Loading... |
889 href_attribute->Value8BitIfNecessary())); | 881 href_attribute->Value8BitIfNecessary())); |
890 predicted_base_element_url_ = | 882 predicted_base_element_url_ = |
891 url.IsValid() && !url.ProtocolIsData() ? url.Copy() : KURL(); | 883 url.IsValid() && !url.ProtocolIsData() ? url.Copy() : KURL(); |
892 } | 884 } |
893 } | 885 } |
894 | 886 |
895 HTMLPreloadScanner::HTMLPreloadScanner( | 887 HTMLPreloadScanner::HTMLPreloadScanner( |
896 const HTMLParserOptions& options, | 888 const HTMLParserOptions& options, |
897 const KURL& document_url, | 889 const KURL& document_url, |
898 std::unique_ptr<CachedDocumentParameters> document_parameters, | 890 std::unique_ptr<CachedDocumentParameters> document_parameters, |
899 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data, | 891 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data) |
900 const TokenPreloadScanner::ScannerType scanner_type) | |
901 : scanner_(document_url, | 892 : scanner_(document_url, |
902 std::move(document_parameters), | 893 std::move(document_parameters), |
903 media_values_cached_data, | 894 media_values_cached_data), |
904 scanner_type), | |
905 tokenizer_(HTMLTokenizer::Create(options)) {} | 895 tokenizer_(HTMLTokenizer::Create(options)) {} |
906 | 896 |
907 HTMLPreloadScanner::~HTMLPreloadScanner() {} | 897 HTMLPreloadScanner::~HTMLPreloadScanner() {} |
908 | 898 |
909 void HTMLPreloadScanner::AppendToEnd(const SegmentedString& source) { | 899 void HTMLPreloadScanner::AppendToEnd(const SegmentedString& source) { |
910 source_.Append(source); | 900 source_.Append(source); |
911 } | 901 } |
912 | 902 |
913 PreloadRequestStream HTMLPreloadScanner::Scan( | 903 PreloadRequestStream HTMLPreloadScanner::Scan( |
914 const KURL& starting_base_element_url, | 904 const KURL& starting_base_element_url, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 default_viewport_min_width = document->ViewportDefaultMinWidth(); | 945 default_viewport_min_width = document->ViewportDefaultMinWidth(); |
956 viewport_meta_zero_values_quirk = | 946 viewport_meta_zero_values_quirk = |
957 document->GetSettings() && | 947 document->GetSettings() && |
958 document->GetSettings()->GetViewportMetaZeroValuesQuirk(); | 948 document->GetSettings()->GetViewportMetaZeroValuesQuirk(); |
959 viewport_meta_enabled = document->GetSettings() && | 949 viewport_meta_enabled = document->GetSettings() && |
960 document->GetSettings()->GetViewportMetaEnabled(); | 950 document->GetSettings()->GetViewportMetaEnabled(); |
961 referrer_policy = document->GetReferrerPolicy(); | 951 referrer_policy = document->GetReferrerPolicy(); |
962 } | 952 } |
963 | 953 |
964 } // namespace blink | 954 } // namespace blink |
OLD | NEW |