| 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 RefPtr<MediaQuerySet> media_queries = MediaQuerySet::Create(attribute_value); | 130 RefPtr<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, MediaValuesCached* media_values) | 139 StartTagScanner(const StringImpl* tag_impl, |
| 140 MediaValuesCached* media_values, |
| 141 TokenPreloadScanner::ScannerType scanner_type) |
| 140 : tag_impl_(tag_impl), | 142 : tag_impl_(tag_impl), |
| 141 link_is_style_sheet_(false), | 143 link_is_style_sheet_(false), |
| 142 link_is_preconnect_(false), | 144 link_is_preconnect_(false), |
| 143 link_is_preload_(false), | 145 link_is_preload_(false), |
| 144 link_is_import_(false), | 146 link_is_import_(false), |
| 145 matched_(true), | 147 matched_(true), |
| 146 input_is_image_(false), | 148 input_is_image_(false), |
| 147 source_size_(0), | 149 source_size_(0), |
| 148 source_size_set_(false), | 150 source_size_set_(false), |
| 149 defer_(FetchParameters::kNoDefer), | 151 defer_(FetchParameters::kNoDefer), |
| 150 cross_origin_(kCrossOriginAttributeNotSet), | 152 cross_origin_(kCrossOriginAttributeNotSet), |
| 151 media_values_(media_values), | 153 media_values_(media_values), |
| 152 referrer_policy_set_(false), | 154 referrer_policy_set_(false), |
| 153 referrer_policy_(kReferrerPolicyDefault) { | 155 referrer_policy_(kReferrerPolicyDefault), |
| 156 scanner_type_(scanner_type) { |
| 154 if (Match(tag_impl_, imgTag) || Match(tag_impl_, sourceTag)) { | 157 if (Match(tag_impl_, imgTag) || Match(tag_impl_, sourceTag)) { |
| 155 source_size_ = SizesAttributeParser(media_values_, String()).length(); | 158 source_size_ = SizesAttributeParser(media_values_, String()).length(); |
| 156 return; | 159 return; |
| 157 } | 160 } |
| 158 if (!Match(tag_impl_, inputTag) && !Match(tag_impl_, linkTag) && | 161 if (!Match(tag_impl_, inputTag) && !Match(tag_impl_, linkTag) && |
| 159 !Match(tag_impl_, scriptTag) && !Match(tag_impl_, videoTag)) | 162 !Match(tag_impl_, scriptTag) && !Match(tag_impl_, videoTag)) |
| 160 tag_impl_ = 0; | 163 tag_impl_ = 0; |
| 161 } | 164 } |
| 162 | 165 |
| 163 enum URLReplacement { kAllowURLReplacement, kDisallowURLReplacement }; | 166 enum URLReplacement { kAllowURLReplacement, kDisallowURLReplacement }; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 type.value(), referrer_policy, PreloadRequest::kDocumentIsReferrer, | 253 type.value(), referrer_policy, PreloadRequest::kDocumentIsReferrer, |
| 251 resource_width, client_hints_preferences, request_type); | 254 resource_width, client_hints_preferences, request_type); |
| 252 if (!request) | 255 if (!request) |
| 253 return nullptr; | 256 return nullptr; |
| 254 | 257 |
| 255 request->SetCrossOrigin(cross_origin_); | 258 request->SetCrossOrigin(cross_origin_); |
| 256 request->SetNonce(nonce_); | 259 request->SetNonce(nonce_); |
| 257 request->SetCharset(Charset()); | 260 request->SetCharset(Charset()); |
| 258 request->SetDefer(defer_); | 261 request->SetDefer(defer_); |
| 259 request->SetIntegrityMetadata(integrity_metadata_); | 262 request->SetIntegrityMetadata(integrity_metadata_); |
| 263 if (scanner_type_ == ScannerType::kInsertion) |
| 264 request->SetFromInsertionScanner(true); |
| 260 | 265 |
| 261 return request; | 266 return request; |
| 262 } | 267 } |
| 263 | 268 |
| 264 private: | 269 private: |
| 265 template <typename NameType> | 270 template <typename NameType> |
| 266 void ProcessScriptAttribute(const NameType& attribute_name, | 271 void ProcessScriptAttribute(const NameType& attribute_name, |
| 267 const String& attribute_value) { | 272 const String& attribute_value) { |
| 268 // FIXME - Don't set crossorigin multiple times. | 273 // FIXME - Don't set crossorigin multiple times. |
| 269 if (Match(attribute_name, srcAttr)) | 274 if (Match(attribute_name, srcAttr)) |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 String language_attribute_value_; | 562 String language_attribute_value_; |
| 558 float source_size_; | 563 float source_size_; |
| 559 bool source_size_set_; | 564 bool source_size_set_; |
| 560 FetchParameters::DeferOption defer_; | 565 FetchParameters::DeferOption defer_; |
| 561 CrossOriginAttributeValue cross_origin_; | 566 CrossOriginAttributeValue cross_origin_; |
| 562 String nonce_; | 567 String nonce_; |
| 563 Member<MediaValuesCached> media_values_; | 568 Member<MediaValuesCached> media_values_; |
| 564 bool referrer_policy_set_; | 569 bool referrer_policy_set_; |
| 565 ReferrerPolicy referrer_policy_; | 570 ReferrerPolicy referrer_policy_; |
| 566 IntegrityMetadataSet integrity_metadata_; | 571 IntegrityMetadataSet integrity_metadata_; |
| 572 TokenPreloadScanner::ScannerType scanner_type_; |
| 567 }; | 573 }; |
| 568 | 574 |
| 569 TokenPreloadScanner::TokenPreloadScanner( | 575 TokenPreloadScanner::TokenPreloadScanner( |
| 570 const KURL& document_url, | 576 const KURL& document_url, |
| 571 std::unique_ptr<CachedDocumentParameters> document_parameters, | 577 std::unique_ptr<CachedDocumentParameters> document_parameters, |
| 572 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data) | 578 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data, |
| 579 const ScannerType scanner_type) |
| 573 : document_url_(document_url), | 580 : document_url_(document_url), |
| 574 in_style_(false), | 581 in_style_(false), |
| 575 in_picture_(false), | 582 in_picture_(false), |
| 576 in_script_(false), | 583 in_script_(false), |
| 577 template_count_(0), | 584 template_count_(0), |
| 578 document_parameters_(std::move(document_parameters)), | 585 document_parameters_(std::move(document_parameters)), |
| 579 media_values_(MediaValuesCached::Create(media_values_cached_data)), | 586 media_values_(MediaValuesCached::Create(media_values_cached_data)), |
| 587 scanner_type_(scanner_type), |
| 580 did_rewind_(false) { | 588 did_rewind_(false) { |
| 581 DCHECK(document_parameters_.get()); | 589 DCHECK(document_parameters_.get()); |
| 582 DCHECK(media_values_.Get()); | 590 DCHECK(media_values_.Get()); |
| 583 DCHECK(document_url.IsValid()); | 591 DCHECK(document_url.IsValid()); |
| 584 css_scanner_.SetReferrerPolicy(document_parameters_->referrer_policy); | 592 css_scanner_.SetReferrerPolicy(document_parameters_->referrer_policy); |
| 585 } | 593 } |
| 586 | 594 |
| 587 TokenPreloadScanner::~TokenPreloadScanner() {} | 595 TokenPreloadScanner::~TokenPreloadScanner() {} |
| 588 | 596 |
| 589 TokenPreloadScannerCheckpoint TokenPreloadScanner::CreateCheckpoint() { | 597 TokenPreloadScannerCheckpoint TokenPreloadScanner::CreateCheckpoint() { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 HandleMetaNameAttribute(token, document_parameters_.get(), | 845 HandleMetaNameAttribute(token, document_parameters_.get(), |
| 838 media_values_.Get(), &css_scanner_, viewport); | 846 media_values_.Get(), &css_scanner_, viewport); |
| 839 } | 847 } |
| 840 | 848 |
| 841 if (Match(tag_impl, pictureTag)) { | 849 if (Match(tag_impl, pictureTag)) { |
| 842 in_picture_ = true; | 850 in_picture_ = true; |
| 843 picture_data_ = PictureData(); | 851 picture_data_ = PictureData(); |
| 844 return; | 852 return; |
| 845 } | 853 } |
| 846 | 854 |
| 847 StartTagScanner scanner(tag_impl, media_values_); | 855 StartTagScanner scanner(tag_impl, media_values_, scanner_type_); |
| 848 scanner.ProcessAttributes(token.Attributes()); | 856 scanner.ProcessAttributes(token.Attributes()); |
| 849 // TODO(yoav): ViewportWidth is currently racy and might be zero in some | 857 // TODO(yoav): ViewportWidth is currently racy and might be zero in some |
| 850 // cases, at least in tests. That problem will go away once | 858 // cases, at least in tests. That problem will go away once |
| 851 // ParseHTMLOnMainThread lands and MediaValuesCached is eliminated. | 859 // ParseHTMLOnMainThread lands and MediaValuesCached is eliminated. |
| 852 if (in_picture_ && media_values_->ViewportWidth()) | 860 if (in_picture_ && media_values_->ViewportWidth()) |
| 853 scanner.HandlePictureSourceURL(picture_data_); | 861 scanner.HandlePictureSourceURL(picture_data_); |
| 854 std::unique_ptr<PreloadRequest> request = scanner.CreatePreloadRequest( | 862 std::unique_ptr<PreloadRequest> request = scanner.CreatePreloadRequest( |
| 855 predicted_base_element_url_, source, client_hints_preferences_, | 863 predicted_base_element_url_, source, client_hints_preferences_, |
| 856 picture_data_, document_parameters_->referrer_policy); | 864 picture_data_, document_parameters_->referrer_policy); |
| 857 if (request) | 865 if (request) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 871 href_attribute->Value8BitIfNecessary())); | 879 href_attribute->Value8BitIfNecessary())); |
| 872 predicted_base_element_url_ = | 880 predicted_base_element_url_ = |
| 873 url.IsValid() && !url.ProtocolIsData() ? url.Copy() : KURL(); | 881 url.IsValid() && !url.ProtocolIsData() ? url.Copy() : KURL(); |
| 874 } | 882 } |
| 875 } | 883 } |
| 876 | 884 |
| 877 HTMLPreloadScanner::HTMLPreloadScanner( | 885 HTMLPreloadScanner::HTMLPreloadScanner( |
| 878 const HTMLParserOptions& options, | 886 const HTMLParserOptions& options, |
| 879 const KURL& document_url, | 887 const KURL& document_url, |
| 880 std::unique_ptr<CachedDocumentParameters> document_parameters, | 888 std::unique_ptr<CachedDocumentParameters> document_parameters, |
| 881 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data) | 889 const MediaValuesCached::MediaValuesCachedData& media_values_cached_data, |
| 890 const TokenPreloadScanner::ScannerType scanner_type) |
| 882 : scanner_(document_url, | 891 : scanner_(document_url, |
| 883 std::move(document_parameters), | 892 std::move(document_parameters), |
| 884 media_values_cached_data), | 893 media_values_cached_data, |
| 894 scanner_type), |
| 885 tokenizer_(HTMLTokenizer::Create(options)) {} | 895 tokenizer_(HTMLTokenizer::Create(options)) {} |
| 886 | 896 |
| 887 HTMLPreloadScanner::~HTMLPreloadScanner() {} | 897 HTMLPreloadScanner::~HTMLPreloadScanner() {} |
| 888 | 898 |
| 889 void HTMLPreloadScanner::AppendToEnd(const SegmentedString& source) { | 899 void HTMLPreloadScanner::AppendToEnd(const SegmentedString& source) { |
| 890 source_.Append(source); | 900 source_.Append(source); |
| 891 } | 901 } |
| 892 | 902 |
| 893 PreloadRequestStream HTMLPreloadScanner::Scan( | 903 PreloadRequestStream HTMLPreloadScanner::Scan( |
| 894 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... |
| 935 default_viewport_min_width = document->ViewportDefaultMinWidth(); | 945 default_viewport_min_width = document->ViewportDefaultMinWidth(); |
| 936 viewport_meta_zero_values_quirk = | 946 viewport_meta_zero_values_quirk = |
| 937 document->GetSettings() && | 947 document->GetSettings() && |
| 938 document->GetSettings()->GetViewportMetaZeroValuesQuirk(); | 948 document->GetSettings()->GetViewportMetaZeroValuesQuirk(); |
| 939 viewport_meta_enabled = document->GetSettings() && | 949 viewport_meta_enabled = document->GetSettings() && |
| 940 document->GetSettings()->GetViewportMetaEnabled(); | 950 document->GetSettings()->GetViewportMetaEnabled(); |
| 941 referrer_policy = document->GetReferrerPolicy(); | 951 referrer_policy = document->GetReferrerPolicy(); |
| 942 } | 952 } |
| 943 | 953 |
| 944 } // namespace blink | 954 } // namespace blink |
| OLD | NEW |