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