diff --git a/chromium_src/third_party/blink/renderer/core/dom/element_additions.cc b/chromium_src/third_party/blink/renderer/core/dom/element_additions.cc new file mode 100644 index 000000000000..a1bc0ee9b752 --- /dev/null +++ b/chromium_src/third_party/blink/renderer/core/dom/element_additions.cc @@ -0,0 +1,39 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "third_party/blink/renderer/core/dom/node.cc" +#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" +#include "third_party/blink/renderer/platform/wtf/text/string_view.cc" +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + +namespace blink { + +AtomicString PossiblyModifyAttrParam(const Element& elm, + const QualifiedName& name, const AtomicString& new_value) { + // Check to see if the following conditions are true, to work around + // the google tag manager (and related) block-the-screen stuff. + // 1) The class being modified + // 2) The element being modified is the element + // 3) The new class value includes "async-hide" + // https://github.com/brave/brave-browser/issues/4402 + const StringView async_hide_class_token("async-hide"); + const bool should_strip_async_hide_class = ( + name == kClassAttr && + elm.tagName().LowerASCII() == "html" && + new_value.Find(async_hide_class_token) != kNotFound); + + if (!should_strip_async_hide_class) { + return new_value; + } + + String prev_attr_value = new_value.GetString(); + AtomicString modified_value(prev_attr_value.Replace( + async_hide_class_token, StringView(""))); + + return modified_value; +} + +} // namespace blink + diff --git a/patches/third_party-blink-renderer-core-dom-element.cc.patch b/patches/third_party-blink-renderer-core-dom-element.cc.patch new file mode 100644 index 000000000000..61bbcc7e264c --- /dev/null +++ b/patches/third_party-blink-renderer-core-dom-element.cc.patch @@ -0,0 +1,45 @@ +diff --git a/third_party/blink/renderer/core/dom/element.cc b/third_party/blink/renderer/core/dom/element.cc +index 8a7abaeb53db0fdbe3f1ba9d52c7a2770ad9438b..1ad787c8cc0110ce99089c9bd8eddcab0cebfce5 100644 +--- a/third_party/blink/renderer/core/dom/element.cc ++++ b/third_party/blink/renderer/core/dom/element.cc +@@ -162,6 +162,10 @@ + #include "third_party/blink/renderer/platform/wtf/text/string_builder.h" + #include "third_party/blink/renderer/platform/wtf/text/text_position.h" + ++#if defined(BRAVE_CHROMIUM_BUILD) ++#include "third_party/blink/renderer/core/dom/element_additions.cc" ++#endif ++ + namespace blink { + + using namespace html_names; +@@ -1699,8 +1703,11 @@ ALWAYS_INLINE void Element::SetAttributeInternal( + return; + } + ++ // Brave addition ++ AtomicString modified_value = PossiblyModifyAttrParam(*this, name, new_value); ++ + if (index == kNotFound) { +- AppendAttributeInternal(name, new_value, ++ AppendAttributeInternal(name, modified_value, + in_synchronization_of_lazy_attribute); + return; + } +@@ -1712,12 +1719,12 @@ ALWAYS_INLINE void Element::SetAttributeInternal( + + if (!in_synchronization_of_lazy_attribute) + WillModifyAttribute(existing_attribute_name, existing_attribute_value, +- new_value); +- if (new_value != existing_attribute_value) +- EnsureUniqueElementData().Attributes().at(index).SetValue(new_value); ++ modified_value); ++ if (modified_value != existing_attribute_value) ++ EnsureUniqueElementData().Attributes().at(index).SetValue(modified_value); + if (!in_synchronization_of_lazy_attribute) + DidModifyAttribute(existing_attribute_name, existing_attribute_value, +- new_value); ++ modified_value); + } + + static inline AtomicString MakeIdForStyleResolution(const AtomicString& value,