-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify HTMLHtmlElement to reject async-hide when set by JS fixes brav…
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
chromium_src/third_party/blink/renderer/core/dom/element_additions.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <html> 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 | ||
|
45 changes: 45 additions & 0 deletions
45
patches/third_party-blink-renderer-core-dom-element.cc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, |