From 84b270da2da241980f586c9d226aa2f11c02e24f Mon Sep 17 00:00:00 2001 From: Xiaocheng Hu Date: Thu, 28 Apr 2022 19:21:32 +0000 Subject: [PATCH] Rename IsRenderBlocking to IsExplicitlyRenderBlocking This change reflects the renaming of "render-blocking" to "explicitly render-blocking" in https://github.com/whatwg/html/pull/7857 It's also a preparation for implementing logic related to "implicitly render-blocking" in crrev.com/c/3608747 Bug: 1271296 Change-Id: I6724e7e4858e2b2c92398b8ff68c984f793a4753 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3607827 Reviewed-by: Joey Arhar Commit-Queue: Joey Arhar Auto-Submit: Xiaocheng Hu Cr-Commit-Position: refs/heads/main@{#997335} NOKEYCHECK=True GitOrigin-RevId: c1bcf0dcb6b206e42c82c515d89466133bddc045 --- blink/renderer/core/css/pending_sheet_type.cc | 2 +- blink/renderer/core/css/style_element.cc | 2 +- blink/renderer/core/css/style_rule_import.cc | 2 +- blink/renderer/core/html/blocking_attribute.cc | 3 ++- blink/renderer/core/html/blocking_attribute.h | 5 +++-- blink/renderer/core/html/html_script_element.cc | 2 +- blink/renderer/core/html/html_script_element.h | 4 ++-- .../renderer/core/html/parser/html_preload_scanner.cc | 11 ++++++----- blink/renderer/core/loader/preload_helper.cc | 6 ++++-- blink/renderer/core/script/mock_script_element_base.h | 2 +- blink/renderer/core/script/script_element_base.h | 3 ++- blink/renderer/core/script/script_loader.cc | 2 +- blink/renderer/core/svg/svg_script_element.h | 2 +- 13 files changed, 26 insertions(+), 20 deletions(-) diff --git a/blink/renderer/core/css/pending_sheet_type.cc b/blink/renderer/core/css/pending_sheet_type.cc index ece9cf9d9a2..d5c99c291b6 100644 --- a/blink/renderer/core/css/pending_sheet_type.cc +++ b/blink/renderer/core/css/pending_sheet_type.cc @@ -30,7 +30,7 @@ ComputePendingSheetTypeAndRenderBlockingBehavior(Element& sheet_owner, } bool has_render_blocking_attr = RuntimeEnabledFeatures::BlockingAttributeEnabled() && - BlockingAttribute::IsRenderBlocking( + BlockingAttribute::IsExplicitlyRenderBlocking( sheet_owner.FastGetAttribute(html_names::kBlockingAttr)); return has_render_blocking_attr ? std::make_pair(PendingSheetType::kDynamicRenderBlocking, diff --git a/blink/renderer/core/css/style_element.cc b/blink/renderer/core/css/style_element.cc index a367ffda7e4..3eb48c86822 100644 --- a/blink/renderer/core/css/style_element.cc +++ b/blink/renderer/core/css/style_element.cc @@ -234,7 +234,7 @@ void StyleElement::BlockingAttributeChanged(Element& element) { // rendering. if (pending_sheet_type_ != PendingSheetType::kDynamicRenderBlocking) return; - if (blocking() && blocking()->IsRenderBlocking()) + if (blocking() && blocking()->IsExplicitlyRenderBlocking()) return; element.GetDocument().GetStyleEngine().RemovePendingBlockingSheet( element, pending_sheet_type_); diff --git a/blink/renderer/core/css/style_rule_import.cc b/blink/renderer/core/css/style_rule_import.cc index 1ea0dbbefa8..cca81540af2 100644 --- a/blink/renderer/core/css/style_rule_import.cc +++ b/blink/renderer/core/css/style_rule_import.cc @@ -156,7 +156,7 @@ void StyleRuleImport::RequestStyleSheet() { DCHECK(!style_sheet_client_->GetResource()); params.SetRenderBlockingBehavior(root_sheet->GetRenderBlockingBehavior()); - // TODO(yoav): Set defer status based on the IsRenderBlocking flag. + // TODO(yoav): Set defer status based on the IsExplicitlyRenderBlocking flag. // https://bugs.chromium.org/p/chromium/issues/detail?id=1001078 CSSStyleSheetResource::Fetch(params, fetcher, style_sheet_client_); if (loading_) { diff --git a/blink/renderer/core/html/blocking_attribute.cc b/blink/renderer/core/html/blocking_attribute.cc index dc945d9fb7a..09e13a45054 100644 --- a/blink/renderer/core/html/blocking_attribute.cc +++ b/blink/renderer/core/html/blocking_attribute.cc @@ -28,7 +28,8 @@ HashSet& BlockingAttribute::SupportedTokens() { } // static -bool BlockingAttribute::IsRenderBlocking(const String& attribute_value) { +bool BlockingAttribute::IsExplicitlyRenderBlocking( + const String& attribute_value) { if (!RuntimeEnabledFeatures::BlockingAttributeEnabled()) return false; if (attribute_value.IsEmpty()) diff --git a/blink/renderer/core/html/blocking_attribute.h b/blink/renderer/core/html/blocking_attribute.h index d30d68d02cc..c357c8efadf 100644 --- a/blink/renderer/core/html/blocking_attribute.h +++ b/blink/renderer/core/html/blocking_attribute.h @@ -20,8 +20,9 @@ class BlockingAttribute final : public DOMTokenList { explicit BlockingAttribute(Element* element) : DOMTokenList(*element, html_names::kBlockingAttr) {} - static bool IsRenderBlocking(const String& attribute_value); - bool IsRenderBlocking() const { return contains(kRenderToken); } + // https://html.spec.whatwg.org/C/#explicitly-render-blocking + static bool IsExplicitlyRenderBlocking(const String& attribute_value); + bool IsExplicitlyRenderBlocking() const { return contains(kRenderToken); } void CountTokenUsage(); diff --git a/blink/renderer/core/html/html_script_element.cc b/blink/renderer/core/html/html_script_element.cc index 8706b221337..679fa6d46f0 100644 --- a/blink/renderer/core/html/html_script_element.cc +++ b/blink/renderer/core/html/html_script_element.cc @@ -108,7 +108,7 @@ void HTMLScriptElement::ParseAttribute( params.new_value); blocking_attribute_->CountTokenUsage(); if (GetDocument().GetRenderBlockingResourceManager() && - !blocking_attribute_->IsRenderBlocking()) { + !blocking_attribute_->IsExplicitlyRenderBlocking()) { GetDocument().GetRenderBlockingResourceManager()->RemovePendingScript( *this); } diff --git a/blink/renderer/core/html/html_script_element.h b/blink/renderer/core/html/html_script_element.h index 1203c8b8c1d..ff13a42962e 100644 --- a/blink/renderer/core/html/html_script_element.h +++ b/blink/renderer/core/html/html_script_element.h @@ -114,8 +114,8 @@ class CORE_EXPORT HTMLScriptElement final : public HTMLElement, bool ElementHasDuplicateAttributes() const override { return HasDuplicateAttribute(); } - bool IsRenderBlocking() const override { - return blocking_attribute_->IsRenderBlocking(); + bool IsExplicitlyRenderBlocking() const override { + return blocking_attribute_->IsExplicitlyRenderBlocking(); } bool AllowInlineScriptForCSP(const AtomicString& nonce, const WTF::OrdinalNumber&, diff --git a/blink/renderer/core/html/parser/html_preload_scanner.cc b/blink/renderer/core/html/parser/html_preload_scanner.cc index 7a0b2ead3f9..34a9f7208c4 100644 --- a/blink/renderer/core/html/parser/html_preload_scanner.cc +++ b/blink/renderer/core/html/parser/html_preload_scanner.cc @@ -305,14 +305,15 @@ class TokenPreloadScanner::StartTagScanner { RenderBlockingBehavior render_blocking_behavior = RenderBlockingBehavior::kUnset; if (request_type == PreloadRequest::kRequestTypeLinkRelPreload) { - render_blocking_behavior = - BlockingAttribute::IsRenderBlocking(blocking_attribute_value_) - ? RenderBlockingBehavior::kBlocking - : RenderBlockingBehavior::kNonBlocking; + render_blocking_behavior = BlockingAttribute::IsExplicitlyRenderBlocking( + blocking_attribute_value_) + ? RenderBlockingBehavior::kBlocking + : RenderBlockingBehavior::kNonBlocking; } else if (is_script && (is_module || defer_ == FetchParameters::kLazyLoad)) { render_blocking_behavior = - BlockingAttribute::IsRenderBlocking(blocking_attribute_value_) + BlockingAttribute::IsExplicitlyRenderBlocking( + blocking_attribute_value_) ? RenderBlockingBehavior::kBlocking : (is_async_ ? RenderBlockingBehavior::kPotentiallyBlocking : RenderBlockingBehavior::kNonBlocking); diff --git a/blink/renderer/core/loader/preload_helper.cc b/blink/renderer/core/loader/preload_helper.cc index d66cdd1eb6c..3b5645bc8ea 100644 --- a/blink/renderer/core/loader/preload_helper.cc +++ b/blink/renderer/core/loader/preload_helper.cc @@ -384,7 +384,8 @@ Resource* PreloadHelper::PreloadIfNeeded( } link_fetch_params.SetLinkPreload(true); - bool render_blocking = BlockingAttribute::IsRenderBlocking(params.blocking); + bool render_blocking = + BlockingAttribute::IsExplicitlyRenderBlocking(params.blocking); link_fetch_params.SetRenderBlockingBehavior( render_blocking ? RenderBlockingBehavior::kBlocking : RenderBlockingBehavior::kNonBlocking); @@ -521,7 +522,8 @@ void PreloadHelper::ModulePreloadIfNeeded( // is cryptographic nonce, integrity metadata is integrity metadata, parser // metadata is "not-parser-inserted", credentials mode is credentials mode, // and referrer policy is referrer policy." [spec text] - bool render_blocking = BlockingAttribute::IsRenderBlocking(params.blocking); + bool render_blocking = + BlockingAttribute::IsExplicitlyRenderBlocking(params.blocking); ModuleScriptFetchRequest request( params.href, ModuleType::kJavaScript, context_type, destination, ScriptFetchOptions( diff --git a/blink/renderer/core/script/mock_script_element_base.h b/blink/renderer/core/script/mock_script_element_base.h index 5186d1dc125..dd993ef3813 100644 --- a/blink/renderer/core/script/mock_script_element_base.h +++ b/blink/renderer/core/script/mock_script_element_base.h @@ -42,7 +42,7 @@ class MockScriptElementBase : public GarbageCollected, MOCK_CONST_METHOD0(GetNonceForElement, const AtomicString&()); MOCK_CONST_METHOD0(ElementHasDuplicateAttributes, bool()); MOCK_CONST_METHOD0(InitiatorName, AtomicString()); - MOCK_CONST_METHOD0(IsRenderBlocking, bool()); + MOCK_CONST_METHOD0(IsExplicitlyRenderBlocking, bool()); MOCK_METHOD3(AllowInlineScriptForCSP, bool(const AtomicString&, const WTF::OrdinalNumber&, diff --git a/blink/renderer/core/script/script_element_base.h b/blink/renderer/core/script/script_element_base.h index 72d968ce61c..eb3f4fe2bda 100644 --- a/blink/renderer/core/script/script_element_base.h +++ b/blink/renderer/core/script/script_element_base.h @@ -67,7 +67,8 @@ class CORE_EXPORT ScriptElementBase : public GarbageCollectedMixin { virtual bool HasChildren() const = 0; virtual const AtomicString& GetNonceForElement() const = 0; virtual bool ElementHasDuplicateAttributes() const = 0; - virtual bool IsRenderBlocking() const = 0; + // https://html.spec.whatwg.org/C/#explicitly-render-blocking + virtual bool IsExplicitlyRenderBlocking() const = 0; // Whether the inline script is allowed by the CSP. Must be called // synchronously to ensure the correct Javascript world is used for CSP diff --git a/blink/renderer/core/script/script_loader.cc b/blink/renderer/core/script/script_loader.cc index b33b1e211d2..9da13593704 100644 --- a/blink/renderer/core/script/script_loader.cc +++ b/blink/renderer/core/script/script_loader.cc @@ -534,7 +534,7 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, bool has_render_blocking_attr = RuntimeEnabledFeatures::BlockingAttributeEnabled() && - element_->IsRenderBlocking(); + element_->IsExplicitlyRenderBlocking(); RenderBlockingBehavior render_blocking_behavior = !has_render_blocking_attr && (non_blocking_ || dynamic_async_ || element_->DeferAttributeValue()) diff --git a/blink/renderer/core/svg/svg_script_element.h b/blink/renderer/core/svg/svg_script_element.h index 584d5dd7c5c..1f7fa7a6d7c 100644 --- a/blink/renderer/core/svg/svg_script_element.h +++ b/blink/renderer/core/svg/svg_script_element.h @@ -93,7 +93,7 @@ class SVGScriptElement final : public SVGElement, bool ElementHasDuplicateAttributes() const override { return HasDuplicateAttribute(); } - bool IsRenderBlocking() const override { return false; } + bool IsExplicitlyRenderBlocking() const override { return false; } bool AllowInlineScriptForCSP(const AtomicString& nonce, const WTF::OrdinalNumber&, const String& script_content) override;