Skip to content

Commit

Permalink
Re-enable ReportingObserver and make noop (uplift to 1.69.x) (#24779)
Browse files Browse the repository at this point in the history
Uplift of #24726 (squashed) to beta
  • Loading branch information
brave-builds authored Jul 22, 2024
1 parent c0a1a1e commit 377b733
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();"));
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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_

This file was deleted.

This file was deleted.

22 changes: 16 additions & 6 deletions test/data/reporting_observer.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 377b733

Please sign in to comment.