Skip to content

Commit

Permalink
Rename IsRenderBlocking to IsExplicitlyRenderBlocking
Browse files Browse the repository at this point in the history
This change reflects the renaming of "render-blocking" to
"explicitly render-blocking" in whatwg/html#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 <[email protected]>
Commit-Queue: Joey Arhar <[email protected]>
Auto-Submit: Xiaocheng Hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#997335}
NOKEYCHECK=True
GitOrigin-RevId: c1bcf0dcb6b206e42c82c515d89466133bddc045
  • Loading branch information
xiaochengh authored and copybara-github committed Apr 28, 2022
1 parent 0a3315c commit 84b270d
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion blink/renderer/core/css/pending_sheet_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/css/style_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/css/style_rule_import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down
3 changes: 2 additions & 1 deletion blink/renderer/core/html/blocking_attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ HashSet<AtomicString>& 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())
Expand Down
5 changes: 3 additions & 2 deletions blink/renderer/core/html/blocking_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/html/html_script_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions blink/renderer/core/html/html_script_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&,
Expand Down
11 changes: 6 additions & 5 deletions blink/renderer/core/html/parser/html_preload_scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions blink/renderer/core/loader/preload_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/script/mock_script_element_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MockScriptElementBase : public GarbageCollected<MockScriptElementBase>,
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&,
Expand Down
3 changes: 2 additions & 1 deletion blink/renderer/core/script/script_element_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/script/script_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/svg/svg_script_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 84b270d

Please sign in to comment.