Skip to content

Commit

Permalink
modify HTMLHtmlElement to reject async-hide when set by JS fixes brav…
Browse files Browse the repository at this point in the history
  • Loading branch information
pes10k committed May 11, 2019
1 parent a11eae1 commit 670a51d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/third_party/blink/renderer/core/html/html_html_element.cc b/third_party/blink/renderer/core/html/html_html_element.cc
index 7cc4857d439f055e3e3ed24d0f8ebd29a9a93fb9..082be842010cf84110d5b310490110f5b212a237 100644
--- a/third_party/blink/renderer/core/html/html_html_element.cc
+++ b/third_party/blink/renderer/core/html/html_html_element.cc
@@ -64,6 +64,36 @@ void HTMLHtmlElement::InsertedByParser() {
}
}

+void HTMLHtmlElement::AttributeChanged(const AttributeModificationParams& params) {
+ // Check to see if the following conditions are true, to work around
+ // the google tag manager (and related) block-the-screen stuff.
+ // 1) The element being modified is the <html> element
+ // 2) The change is not made by the parser
+ // 3) The class being added includes "async-hide"
+ // https://github.com/brave/brave-browser/issues/4402
+ #if defined(BRAVE_CHROMIUM_BUILD)
+ const StringView async_hide_class_token = StringView("async-hide");
+ const bool should_strip_async_hide_class = (
+ params.name == kClassAttr &&
+ params.reason == AttributeModificationReason::kDirectly &&
+ params.new_value.Find(async_hide_class_token) != kNotFound);
+
+ if (!should_strip_async_hide_class) {
+ HTMLElement::AttributeChanged(params);
+ return;
+ }
+
+ String prev_attr_value = params.new_value.GetString();
+ AtomicString new_value = AtomicString(prev_attr_value.Replace(
+ async_hide_class_token, StringView("")));
+
+ HTMLElement::AttributeChanged(AttributeModificationParams(
+ params.name, params.old_value, new_value, params.reason));
+#else
+ HTMLElement::AttributeChanged(params);
+#endif
+}
+
void HTMLHtmlElement::MaybeSetupApplicationCache() {
if (!GetDocument().GetFrame())
return;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/third_party/blink/renderer/core/html/html_html_element.h b/third_party/blink/renderer/core/html/html_html_element.h
index 1ba669ce9ea95c8623d10c3f9e52237d61bd1e7a..bb7bbf5ad04e63a15e35b657e71a17554c972cf5 100644
--- a/third_party/blink/renderer/core/html/html_html_element.h
+++ b/third_party/blink/renderer/core/html/html_html_element.h
@@ -41,6 +41,8 @@ class CORE_EXPORT HTMLHtmlElement final : public HTMLElement {

bool HasNonInBodyInsertionMode() const override { return true; }

+ void AttributeChanged(const AttributeModificationParams&) override;
+
private:
void MaybeSetupApplicationCache();

0 comments on commit 670a51d

Please sign in to comment.