Re-enable ReportingObserver and make noop (#24726)

This commit is contained in:
Shivan Kaul Sahib
2024-07-19 09:19:40 -07:00
committed by GitHub
parent a59f1d1c06
commit 017fec05ee
7 changed files with 54 additions and 62 deletions
@@ -32,11 +32,11 @@ class ReportingObserverTest : public InProcessBrowserTest {
}
};
IN_PROC_BROWSER_TEST_F(ReportingObserverTest, IsDisabled) {
IN_PROC_BROWSER_TEST_F(ReportingObserverTest, IsNoop) {
GURL url = embedded_test_server()->GetURL(kReportingObserver);
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(true, EvalJs(contents, "isReportingObserverDisabled();"));
EXPECT_EQ(true, EvalJs(contents, "isReportingObserverNoop();"));
}
@@ -1,30 +0,0 @@
/* Copyright (c) 2020 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/. */
#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_CONTEXT_FEATURES_CONTEXT_FEATURE_SETTINGS_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_CONTEXT_FEATURES_CONTEXT_FEATURE_SETTINGS_H_
// ContextEnabled=ReportingObservers feature methods need to be added since we
// patched ReportingObservers as ContextEnabled into
// third_party/blink/renderer/core/frame/reporting_observer.idl
#define BRAVE_CONTEXT_FEATURE_SETTINGS_H_ \
public: \
void enableReportingObservers(bool enable) { \
enable_reporting_observers_ = enable; \
} \
bool isReportingObserversEnabled() const { \
return enable_reporting_observers_; \
} \
\
private: \
bool enable_reporting_observers_ = false; \
\
public:
// #define BRAVE_CONTEXT_FEATURE_SETTINGS_H_
#include "src/third_party/blink/renderer/core/context_features/context_feature_settings.h" // IWYU pragma: export
#undef BRAVE_CONTEXT_FEATURE_SETTINGS_H_
#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_CONTEXT_FEATURES_CONTEXT_FEATURE_SETTINGS_H_
@@ -0,0 +1,19 @@
/* Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. */
#include "third_party/blink/renderer/core/frame/reporting_observer.h"
#define QueueReport QueueReport_Unused
#include "src/third_party/blink/renderer/core/frame/reporting_observer.cc"
#undef QueueReport
namespace blink {
// Don't add reports. We previously used to disable ReportingObserver in
// Brave, but for webcompat reasons, we now just no-op it. This makes
// takeRecords() always return an empty list.
void ReportingObserver::QueueReport(Report* report) {}
} // namespace blink
@@ -0,0 +1,17 @@
/* Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORTING_OBSERVER_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORTING_OBSERVER_H_
#define QueueReport \
QueueReport_Unused(Report* report); \
void QueueReport
#include "src/third_party/blink/renderer/core/frame/reporting_observer.h" // IWYU pragma: export
#undef QueueReport
#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_REPORTING_OBSERVER_H_
@@ -1,12 +0,0 @@
diff --git a/third_party/blink/renderer/core/context_features/context_feature_settings.h b/third_party/blink/renderer/core/context_features/context_feature_settings.h
index 096d49ecd53d7e17811ad7d70ea6a9b2af9acd6f..eed64a36e45779db4a16e75f40b02b76b480673a 100644
--- a/third_party/blink/renderer/core/context_features/context_feature_settings.h
+++ b/third_party/blink/renderer/core/context_features/context_feature_settings.h
@@ -64,6 +64,7 @@ class CORE_EXPORT ContextFeatureSettings final
}
void Trace(Visitor*) const override;
+ BRAVE_CONTEXT_FEATURE_SETTINGS_H_
private:
bool enable_mojo_js_ = false;
@@ -1,12 +0,0 @@
diff --git a/third_party/blink/renderer/core/frame/reporting_observer.idl b/third_party/blink/renderer/core/frame/reporting_observer.idl
index 90d04d7f35828629d71124cdd0024baebd7d4fb3..094d82aa0d3ba6b70c112907c94edc49f1003506 100644
--- a/third_party/blink/renderer/core/frame/reporting_observer.idl
+++ b/third_party/blink/renderer/core/frame/reporting_observer.idl
@@ -7,6 +7,7 @@
callback ReportingObserverCallback = void (sequence<Report> reports, ReportingObserver observer);
[
+ ContextEnabled=ReportingObservers,
ActiveScriptWrappable,
Exposed=(Window,Worker)
] interface ReportingObserver {
+16 -6
View File
@@ -1,11 +1,21 @@
<script>
function isReportingObserverDisabled() {
function isReportingObserverNoop() {
try {
new ReportingObserver(function(reports, observer) {
return false;
}, {});
} catch (err) {
return true;
const observer = new ReportingObserver(() => {},
{ types: ['deprecation'], buffered: true }
);
observer.observe();
const xhr = new XMLHttpRequest();
// false makes it synchronous, which is deprecated.
xhr.open('GET', '/', false);
xhr.send(null);
const reports = observer.takeRecords();
console.log("Reports:", reports);
// Even though we made a synchronous request, we should not have any reports.
return reports.length === 0;
} catch (error) {
console.error("Error occurred:", error);
return false;
}
}
</script>