From bce6091bd1f4fd64e711fe647de649f62d052883 Mon Sep 17 00:00:00 2001 From: sanketh Date: Sun, 10 May 2020 16:50:41 +0000 Subject: [PATCH] (ESR68) Bug 1511941 - Don't expose PerformanceNavigationTiming in RFP mode In RFP mode, we do not support PerformanceNavigationTiming, so don't expose it. In particular, window.PerformanceNavigationTiming should return undefined. Added a new method PerformanceNavigationTiming::Enabled which when used with the WebIDL Func attribute allows us to toggle whether window.PerformanceNavigationTiming is exposed. Created dom/tests/mochitest/general/test_toggling_performance_navigation_timing.html to test whether the toggling works. Updated browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js to create a new window each time privacy.resistFingerprinting is flipped so this behavior does not leak into other tests. --- .../test/browser/browser_performanceAPI.js | 62 +++++++------------ dom/performance/PerformanceMainThread.cpp | 3 +- .../PerformanceNavigationTiming.cpp | 6 ++ dom/performance/PerformanceNavigationTiming.h | 6 ++ dom/tests/mochitest/general/mochitest.ini | 1 + ...oggling_performance_navigation_timing.html | 47 ++++++++++++++ dom/webidl/PerformanceNavigationTiming.webidl | 2 + 7 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 dom/tests/mochitest/general/test_toggling_performance_navigation_timing.html diff --git a/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js b/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js index b4c6b4f9d4613..eb51a98e7364a 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js +++ b/browser/components/resistfingerprinting/test/browser/browser_performanceAPI.js @@ -78,7 +78,6 @@ let isRounded = (x, expectedPrecision) => { }; let setupTest = async function( - tab, resistFingerprinting, reduceTimerPrecision, expectedPrecision, @@ -95,6 +94,13 @@ let setupTest = async function( ], ], }); + + let win = await BrowserTestUtils.openNewBrowserWindow(); + let tab = await BrowserTestUtils.openNewForegroundTab( + win.gBrowser, + TEST_PATH + "file_dummy.html" + ); + // No matter what we set the precision to, if we're in ResistFingerprinting mode // we use the larger of the precision pref and the constant 100ms if (resistFingerprinting) { @@ -110,15 +116,11 @@ let setupTest = async function( }, runTests ); + await BrowserTestUtils.closeWindow(win); }; // ================================================================================================ // ================================================================================================ add_task(async function runRPTests() { - let tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - TEST_PATH + "file_dummy.html" - ); - let runTests = async function(data) { let timerlist = data.list; let expectedPrecision = data.precision; @@ -165,21 +167,14 @@ add_task(async function runRPTests() { ); }; - await setupTest(tab, true, true, 100, runTests); - await setupTest(tab, true, false, 13, runTests); - await setupTest(tab, true, false, 0.13, runTests); - - BrowserTestUtils.removeTab(tab); + await setupTest(true, true, 100, runTests); + await setupTest(true, false, 13, runTests); + await setupTest(true, false, 0.13, runTests); }); // ================================================================================================ // ================================================================================================ add_task(async function runRTPTests() { - let tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - TEST_PATH + "file_dummy.html" - ); - let runTests = async function(data) { let timerlist = data.list; let expectedPrecision = data.precision; @@ -215,6 +210,7 @@ add_task(async function runRTPTests() { content.performance.getEntries().length, 4, "For reduceTimerPrecision, there should be 4 entries for performance.getEntries()" + // PerformanceNavigationTiming, PerformanceMark, PerformanceMark, PerformanceMeasure ); for (var i = 0; i < 4; i++) { let startTime = content.performance.getEntries()[i].startTime; @@ -253,11 +249,9 @@ add_task(async function runRTPTests() { content.performance.clearResourceTimings(); }; - await setupTest(tab, false, true, 100, runTests); - await setupTest(tab, false, true, 13, runTests); - await setupTest(tab, false, true, 0.13, runTests); - - BrowserTestUtils.removeTab(tab); + await setupTest(false, true, 100, runTests); + await setupTest(false, true, 13, runTests); + await setupTest(false, true, 0.13, runTests); }); // ================================================================================================ @@ -284,27 +278,13 @@ let runWorkerTest = async function(data) { }; add_task(async function runRPTestsForWorker() { - let tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - TEST_PATH + "file_dummy.html" - ); - - await setupTest(tab, true, true, 100, runWorkerTest, "runRPTests"); - await setupTest(tab, true, false, 13, runWorkerTest, "runRPTests"); - await setupTest(tab, true, true, 0.13, runWorkerTest, "runRPTests"); - - BrowserTestUtils.removeTab(tab); + await setupTest(true, true, 100, runWorkerTest, "runRPTests"); + await setupTest(true, false, 13, runWorkerTest, "runRPTests"); + await setupTest(true, true, 0.13, runWorkerTest, "runRPTests"); }); add_task(async function runRTPTestsForWorker() { - let tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - TEST_PATH + "file_dummy.html" - ); - - await setupTest(tab, false, true, 100, runWorkerTest, "runRTPTests"); - await setupTest(tab, false, true, 13, runWorkerTest, "runRTPTests"); - await setupTest(tab, false, true, 0.13, runWorkerTest, "runRTPTests"); - - BrowserTestUtils.removeTab(tab); + await setupTest(false, true, 100, runWorkerTest, "runRTPTests"); + await setupTest(false, true, 13, runWorkerTest, "runRTPTests"); + await setupTest(false, true, 0.13, runWorkerTest, "runRTPTests"); }); diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index 7c39b93506467..bfcbea4e1148e 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -305,7 +305,8 @@ DOMHighResTimeStamp PerformanceMainThread::CreationTime() const { void PerformanceMainThread::CreateNavigationTimingEntry() { MOZ_ASSERT(!mDocEntry, "mDocEntry should be null."); - if (!StaticPrefs::dom_enable_performance_navigation_timing()) { + if (!StaticPrefs::dom_enable_performance_navigation_timing() || + StaticPrefs::privacy_resistFingerprinting()) { return; } diff --git a/dom/performance/PerformanceNavigationTiming.cpp b/dom/performance/PerformanceNavigationTiming.cpp index dbc6aa78c4d54..fb18b91aabe61 100644 --- a/dom/performance/PerformanceNavigationTiming.cpp +++ b/dom/performance/PerformanceNavigationTiming.cpp @@ -6,6 +6,7 @@ #include "mozilla/dom/PerformanceNavigationTiming.h" #include "mozilla/dom/PerformanceNavigationTimingBinding.h" +#include "mozilla/StaticPrefs.h" using namespace mozilla::dom; @@ -138,3 +139,8 @@ void PerformanceNavigationTiming::UpdatePropertiesFromHttpChannel( nsIHttpChannel* aHttpChannel, nsITimedChannel* aChannel) { mTimingData->SetPropertiesFromHttpChannel(aHttpChannel, aChannel); } + +bool PerformanceNavigationTiming::Enabled(JSContext* aCx, JSObject* aGlobal) { + return (StaticPrefs::dom_enable_performance_navigation_timing() && + !StaticPrefs::privacy_resistFingerprinting()); +} diff --git a/dom/performance/PerformanceNavigationTiming.h b/dom/performance/PerformanceNavigationTiming.h index 8ef79999a1bc2..7bf76ee3d6708 100644 --- a/dom/performance/PerformanceNavigationTiming.h +++ b/dom/performance/PerformanceNavigationTiming.h @@ -65,6 +65,12 @@ class PerformanceNavigationTiming final : public PerformanceResourceTiming { void UpdatePropertiesFromHttpChannel(nsIHttpChannel* aHttpChannel, nsITimedChannel* aChannel); + /* + * For use with the WebIDL Func attribute to determine whether + * window.PerformanceNavigationTiming is exposed. + */ + static bool Enabled(JSContext* aCx, JSObject* aGlobal); + private: ~PerformanceNavigationTiming() {} }; diff --git a/dom/tests/mochitest/general/mochitest.ini b/dom/tests/mochitest/general/mochitest.ini index cb233881397d5..36f955500c09a 100644 --- a/dom/tests/mochitest/general/mochitest.ini +++ b/dom/tests/mochitest/general/mochitest.ini @@ -141,6 +141,7 @@ skip-if = toolkit == 'android' # bug 1230232 - Mouse doesn't select in the same [test_storagePermissionsReject.html] [test_storagePermissionsRejectForeign.html] [test_stylesheetPI.html] +[test_toggling_performance_navigation_timing.html] [test_vibrator.html] [test_WebKitCSSMatrix.html] [test_windowedhistoryframes.html] diff --git a/dom/tests/mochitest/general/test_toggling_performance_navigation_timing.html b/dom/tests/mochitest/general/test_toggling_performance_navigation_timing.html new file mode 100644 index 0000000000000..88f7154286cd8 --- /dev/null +++ b/dom/tests/mochitest/general/test_toggling_performance_navigation_timing.html @@ -0,0 +1,47 @@ + + + + + Test for Bug 1511941 - Don't expose PerformanceNavigationTiming when it is disabled + + + + +
+ + + diff --git a/dom/webidl/PerformanceNavigationTiming.webidl b/dom/webidl/PerformanceNavigationTiming.webidl index b26e1c18f6885..cf029972304f6 100644 --- a/dom/webidl/PerformanceNavigationTiming.webidl +++ b/dom/webidl/PerformanceNavigationTiming.webidl @@ -17,6 +17,8 @@ enum NavigationType { "prerender" }; +[Exposed=Window, + Func="mozilla::dom::PerformanceNavigationTiming::Enabled"] interface PerformanceNavigationTiming : PerformanceResourceTiming { readonly attribute DOMHighResTimeStamp unloadEventStart; readonly attribute DOMHighResTimeStamp unloadEventEnd; -- GitLab