From cb853b7f774e783b1513f75a9880c7e982e5ab4e Mon Sep 17 00:00:00 2001 From: Butkovits Atila Date: Mon, 28 Nov 2022 23:14:52 +0200 Subject: [PATCH] Backed out 33 changesets (bug 1778510) for causing build bustages at nsIGlobalObject.h. CLOSED TREE Backed out changeset f2a53c9e497c Backed out changeset 59350ca6f3f2 (bug 1778510) Backed out changeset abbba7e72b57 (bug 1778510) Backed out changeset 6cf7473afae8 (bug 1778510) Backed out changeset 74fb5fed93ea (bug 1778510) Backed out changeset 5b5dc70cdd0a (bug 1778510) Backed out changeset ff93191cafd2 (bug 1778510) Backed out changeset 39cc006b610c (bug 1778510) Backed out changeset dfaef3ad17a9 (bug 1778510) Backed out changeset 8fbabeb8244b (bug 1778510) Backed out changeset 45051b62e3f1 (bug 1778510) Backed out changeset 86c0923fd81f (bug 1778510) Backed out changeset a49c0f69d519 (bug 1778510) Backed out changeset cfad733d4aaf (bug 1778510) Backed out changeset df6d0fe89d5b (bug 1778510) Backed out changeset 704db76eab17 (bug 1778510) Backed out changeset 0651c128e369 (bug 1778510) Backed out changeset 1e650de647c0 (bug 1778510) Backed out changeset fa15a3572741 (bug 1778510) Backed out changeset 4ceffd409eae (bug 1778510) Backed out changeset 47db43142c62 (bug 1778510) Backed out changeset ebb21153aaac (bug 1778510) Backed out changeset a87eaaec3f9c (bug 1778510) Backed out changeset 43ad5ee21f79 (bug 1778510) Backed out changeset 5f20af8e1263 (bug 1778510) Backed out changeset b78576875db0 (bug 1778510) Backed out changeset d801fdeac90b (bug 1778510) Backed out changeset 5af032c628c0 (bug 1778510) Backed out changeset 86aa59de11b4 (bug 1778510) Backed out changeset 58642357a19c (bug 1778510) Backed out changeset c575e824e291 (bug 1778510) Backed out changeset 32a358de4843 (bug 1778510) Backed out changeset 40e0708c01e7 (bug 1778510) --- .../test/browser/browser.ini | 10 +- .../browser/browser_animationapi_iframes.js | 263 ---------- .../test/browser/browser_navigator.js | 2 +- ...eader.sjs => browser_navigator_header.sjs} | 0 .../test/browser/browser_navigator_iframes.js | 470 +++++++++++++----- .../browser_reduceTimePrecision_iframes.js | 270 ---------- .../browser/file_animationapi_iframee.html | 85 ---- .../browser/file_animationapi_iframer.html | 41 -- .../test/browser/file_navigator_iframee.html | 4 +- .../test/browser/file_navigator_iframer.html | 5 +- ...file_reduceTimePrecision_iframe_worker.sjs | 34 -- .../file_reduceTimePrecision_iframee.html | 52 -- .../file_reduceTimePrecision_iframer.html | 41 -- .../resistfingerprinting/test/browser/head.js | 388 --------------- .../test/mochitest/mochitest.ini | 1 + .../mochitest/test_reduce_time_precision.html | 208 ++++++++ dom/animation/Animation.cpp | 16 +- dom/animation/Animation.h | 4 - dom/animation/AnimationEffect.cpp | 7 +- dom/animation/AnimationEffect.h | 3 - dom/animation/AnimationTimeline.h | 12 +- dom/animation/AnimationUtils.h | 4 +- dom/animation/CSSAnimation.cpp | 4 +- dom/animation/CSSTransition.cpp | 4 +- dom/animation/DocumentTimeline.cpp | 3 +- dom/animation/ScrollTimeline.cpp | 3 +- dom/base/nsGlobalWindowInner.cpp | 4 +- dom/base/nsGlobalWindowOuter.cpp | 40 +- dom/base/nsIGlobalObject.cpp | 26 +- dom/base/nsIGlobalObject.h | 19 +- dom/bindings/SimpleGlobalObject.h | 7 - dom/events/Event.cpp | 8 +- dom/file/BaseBlobImpl.cpp | 6 +- dom/file/BaseBlobImpl.h | 3 +- dom/file/Blob.cpp | 9 +- dom/file/File.cpp | 6 +- dom/file/MemoryBlobImpl.cpp | 7 +- dom/file/MemoryBlobImpl.h | 2 +- dom/file/MultipartBlobImpl.cpp | 21 +- dom/file/MultipartBlobImpl.h | 9 +- dom/media/webaudio/AudioContext.cpp | 9 +- .../webaudio/AudioWorkletGlobalScope.cpp | 3 - dom/media/webrtc/jsapi/RTCStatsReport.cpp | 13 +- dom/media/webrtc/jsapi/RTCStatsReport.h | 3 +- dom/network/ConnectionWorker.cpp | 3 +- dom/performance/Performance.cpp | 43 +- dom/performance/Performance.h | 9 +- dom/performance/PerformanceEventTiming.h | 12 +- dom/performance/PerformanceMainThread.cpp | 9 +- dom/performance/PerformanceMainThread.h | 2 +- .../PerformanceNavigationTiming.cpp | 2 +- dom/performance/PerformancePaintTiming.cpp | 3 +- dom/performance/PerformanceTiming.cpp | 19 +- dom/performance/PerformanceTiming.h | 41 +- dom/performance/PerformanceWorker.cpp | 4 +- dom/script/ShadowRealmGlobalScope.h | 7 - dom/workers/WorkerNavigator.cpp | 23 +- dom/workers/WorkerPrivate.cpp | 25 +- dom/workers/WorkerPrivate.h | 6 +- dom/workers/WorkerScope.cpp | 31 +- dom/workers/WorkerScope.h | 15 +- dom/worklet/WorkletGlobalScope.cpp | 8 - dom/worklet/WorkletGlobalScope.h | 3 - dom/worklet/WorkletImpl.cpp | 4 - dom/worklet/WorkletImpl.h | 7 - js/public/Date.h | 8 +- js/public/RealmOptions.h | 9 - js/src/jsdate.cpp | 5 +- js/xpconnect/src/BackstagePass.h | 7 - js/xpconnect/src/SandboxPrivate.h | 7 - js/xpconnect/src/nsXPConnect.cpp | 20 +- js/xpconnect/src/xpcprivate.h | 3 +- layout/style/PaintWorkletGlobalScope.cpp | 3 - .../resistfingerprinting/nsRFPService.cpp | 132 ++--- .../resistfingerprinting/nsRFPService.h | 29 +- 75 files changed, 875 insertions(+), 1753 deletions(-) delete mode 100644 browser/components/resistfingerprinting/test/browser/browser_animationapi_iframes.js rename browser/components/resistfingerprinting/test/browser/{file_navigator_header.sjs => browser_navigator_header.sjs} (100%) delete mode 100644 browser/components/resistfingerprinting/test/browser/browser_reduceTimePrecision_iframes.js delete mode 100644 browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html delete mode 100644 browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html delete mode 100644 browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframe_worker.sjs delete mode 100644 browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframee.html delete mode 100644 browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html create mode 100644 browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html diff --git a/browser/components/resistfingerprinting/test/browser/browser.ini b/browser/components/resistfingerprinting/test/browser/browser.ini index e2c9bfb23562..97be5b4a393a 100644 --- a/browser/components/resistfingerprinting/test/browser/browser.ini +++ b/browser/components/resistfingerprinting/test/browser/browser.ini @@ -1,6 +1,7 @@ [DEFAULT] tags = resistfingerprinting support-files = + browser_navigator_header.sjs coop_header.sjs file_dummy.html file_keyBoardEvent.sjs @@ -9,18 +10,11 @@ support-files = file_workerNetInfo.js file_workerPerformance.js head.js - file_navigator_header.sjs file_navigator_iframer.html file_navigator_iframee.html file_navigator_iframe_worker.sjs - file_reduceTimePrecision_iframer.html - file_reduceTimePrecision_iframee.html - file_reduceTimePrecision_iframe_worker.sjs - file_animationapi_iframer.html - file_animationapi_iframee.html [browser_block_mozAddonManager.js] -[browser_animationapi_iframes.js] [browser_cross_origin_isolated_animation_api.js] [browser_cross_origin_isolated_performance_api.js] [browser_cross_origin_isolated_reduce_time_precision.js] @@ -42,8 +36,6 @@ skip-if = https_first_disabled = true [browser_performanceAPI.js] [browser_performanceAPIWorkers.js] -[browser_reduceTimePrecision_iframes.js] -https_first_disabled = true [browser_roundedWindow_dialogWindow.js] [browser_roundedWindow_newWindow.js] [browser_roundedWindow_open_max_inner.js] diff --git a/browser/components/resistfingerprinting/test/browser/browser_animationapi_iframes.js b/browser/components/resistfingerprinting/test/browser/browser_animationapi_iframes.js deleted file mode 100644 index 188cfb8973bf..000000000000 --- a/browser/components/resistfingerprinting/test/browser/browser_animationapi_iframes.js +++ /dev/null @@ -1,263 +0,0 @@ -/** - * This test only tests values in the iframe, it does not test them on the framer - * - * Covers the following cases: - * - RFP is disabled entirely - * - RFP is enabled entirely - - * - (A) RFP is exempted on the framer and framee - * - (B) RFP is exempted on the framer and framee - - * - (C) RFP is exempted on the framer but not the framee - * - (D) RFP is exempted on the framer but not the framee - - * - (E) RFP is not exempted on the framer nor the framee - * - (F) RFP is not exempted on the framer nor the framee - * - * - (G) RFP is not exempted on the framer but is on the framee - * - (H) RFP is not exempted on the framer but is on the framee - */ - -"use strict"; - -requestLongerTimeout(3); - -ChromeUtils.defineModuleGetter( - this, - "AppConstants", - "resource://gre/modules/AppConstants.jsm" -); - -// ============================================================================================= -// ============================================================================================= - -async function testTimePrecision(results, expectedResults, extraData) { - let testDesc = extraData.testDesc; - let precision = undefined; - - if (!expectedResults.shouldRFPApply) { - precision = extraData.Unconditional_Precision; - } else { - precision = extraData.RFP_Precision; - } - - for (let result of results) { - if ("error" in result) { - ok(false, result.error); - continue; - } - - let isRounded = isTimeValueRounded(result.value, precision); - - ok( - isRounded, - "Test: " + - testDesc + - " - '" + - "'" + - result.name + - "' should be rounded to nearest " + - precision + - " ms; saw " + - result.value - ); - } -} - -const RFP_TIME_ATOM_MS = 16.667; -const framer_domain = "example.com"; -const iframe_domain = "example.org"; -const cross_origin_domain = "example.net"; -const uri = `https://${framer_domain}/browser/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html`; - -// The first three variables are defined here; and then set for test banks below. -let extraData = {}; -let extraPrefs = {}; -let precision = 100; -let expectedResults = {}; // In this test, we don't have explicit expected values, but rather we expect them to be rounded - -// ======================================================================================================================== -// Create a function that defines all the tests -function addAllTests(extraData_, extraPrefs_) { - add_task( - partial( - defaultsTest, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - add_task( - partial( - simpleRFPTest, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource - add_task( - partial( - testA, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testB, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource - add_task( - partial( - testC, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testD, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource - add_task( - partial( - testE, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testF, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource - add_task( - partial( - testG, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testH, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); -} - -// ======================================================================================================================== -// First we run through all the tests with RTP's precision set to 100 ms and 133 ms. -// Animation does _not_ obey RTP's timestamp, instead it falls back to the unconditional -// rounding which is 20 microseconds. -extraData = { - RFP_Precision: 100, - Unconditional_Precision: 0.02, -}; - -extraPrefs = [ - [ - "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", - extraData.RFP_Precision * 1000, - ], - ["dom.animations-api.timelines.enabled", true], -]; - -addAllTests(extraData, extraPrefs); - -extraData = { - RFP_Precision: 133, - Unconditional_Precision: 0.02, -}; - -extraPrefs = [ - [ - "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", - extraData.RFP_Precision * 1000, - ], - ["dom.animations-api.timelines.enabled", true], -]; - -addAllTests(extraData, extraPrefs); - -// ======================================================================================================================== -// Then we run through all the tests with the precision set to its normal value. -// This will mean that in some cases we expect RFP to apply and in some we don't. -extraData = { - RFP_Precision: RFP_TIME_ATOM_MS, - Unconditional_Precision: 0.02, -}; -extraPrefs = [["dom.animations-api.timelines.enabled", true]]; -addAllTests(extraData, extraPrefs); diff --git a/browser/components/resistfingerprinting/test/browser/browser_navigator.js b/browser/components/resistfingerprinting/test/browser/browser_navigator.js index 78e15f1476b2..b99a4002beac 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_navigator.js +++ b/browser/components/resistfingerprinting/test/browser/browser_navigator.js @@ -153,7 +153,7 @@ const SPOOFED_UA_GECKO_TRAIL = { async function testUserAgentHeader() { const BASE = "http://mochi.test:8888/browser/browser/components/resistfingerprinting/test/browser/"; - const TEST_TARGET_URL = `${BASE}file_navigator_header.sjs?`; + const TEST_TARGET_URL = `${BASE}browser_navigator_header.sjs?`; let tab = await BrowserTestUtils.openNewForegroundTab( gBrowser, TEST_TARGET_URL diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator_header.sjs b/browser/components/resistfingerprinting/test/browser/browser_navigator_header.sjs similarity index 100% rename from browser/components/resistfingerprinting/test/browser/file_navigator_header.sjs rename to browser/components/resistfingerprinting/test/browser/browser_navigator_header.sjs diff --git a/browser/components/resistfingerprinting/test/browser/browser_navigator_iframes.js b/browser/components/resistfingerprinting/test/browser/browser_navigator_iframes.js index 088d059bf328..72dbf8effc7e 100644 --- a/browser/components/resistfingerprinting/test/browser/browser_navigator_iframes.js +++ b/browser/components/resistfingerprinting/test/browser/browser_navigator_iframes.js @@ -170,8 +170,8 @@ const DEFAULT_HARDWARE_CONCURRENCY = navigator.hardwareConcurrency; // ============================================================================================= // ============================================================================================= -async function testNavigator(result, expectedResults, extraData) { - let testDesc = extraData.testDesc; +async function testNavigator(result, expectedResults) { + let testDesc = expectedResults.testDesc; is( result.appVersion, @@ -345,138 +345,372 @@ const iframe_domain = "example.org"; const cross_origin_domain = "example.net"; const uri = `https://${framer_domain}/browser/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html`; -requestLongerTimeout(2); +add_task(async function defaultsTest() { + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); -let expectedResults = {}; + let expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); + expectedResults.testDesc = "default"; -expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); -add_task( - partial( - defaultsTest, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); + testNavigator(result, expectedResults); + } + ); +}); -expectedResults = JSON.parse(JSON.stringify(allSpoofed)); -add_task( - partial( - simpleRFPTest, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function simpleRFPTest() { + await SpecialPowers.pushPrefEnv({ + set: [["privacy.resistFingerprinting", true]], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allSpoofed)); + expectedResults.testDesc = "simple RFP enabled"; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); -add_task( - partial( - testA, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testA() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.com, example.org, example.net", + ], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); + expectedResults.testDesc = "test (A)"; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); -add_task( - partial( - testB, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testB() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.com, example.org", + ], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allNotSpoofed)); + expectedResults.testDesc = "test (B)"; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allSpoofed)); -expectedResults.framer_crossOrigin_userAgentHTTPHeader = defaultUserAgent; -expectedResults.framee_crossOrigin_userAgentHTTPHeader = spoofedUserAgentHeader; -add_task( - partial( - testC, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testC() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.com, example.net", + ], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allSpoofed)); + expectedResults.testDesc = "test (C)"; + expectedResults.framer_crossOrigin_userAgentHTTPHeader = defaultUserAgent; + expectedResults.framee_crossOrigin_userAgentHTTPHeader = spoofedUserAgentHeader; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allSpoofed)); -expectedResults.framer_crossOrigin_userAgentHTTPHeader = defaultUserAgent; -expectedResults.framee_crossOrigin_userAgentHTTPHeader = spoofedUserAgentHeader; -add_task( - partial( - testD, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testD() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", "example.com"], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allSpoofed)); + expectedResults.testDesc = "test (D)"; + expectedResults.framer_crossOrigin_userAgentHTTPHeader = defaultUserAgent; + expectedResults.framee_crossOrigin_userAgentHTTPHeader = spoofedUserAgentHeader; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allSpoofed)); -add_task( - partial( - testE, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testE() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", "example.net"], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allSpoofed)); + expectedResults.testDesc = "test (E)"; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allSpoofed)); -add_task( - partial( - testF, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testF() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", ""], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allSpoofed)); + expectedResults.testDesc = "test (F)"; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allSpoofed)); -add_task( - partial( - testG, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testG() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + [ + "privacy.resistFingerprinting.exemptedDomains", + "example.org, example.net", + ], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allSpoofed)); + expectedResults.testDesc = "test (G)"; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); // (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource -expectedResults = JSON.parse(JSON.stringify(allSpoofed)); -add_task( - partial( - testH, - uri, - iframe_domain, - cross_origin_domain, - testNavigator, - expectedResults - ) -); +add_task(async function testH() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.resistFingerprinting", true], + ["privacy.resistFingerprinting.testGranularityMask", 4], + ["privacy.resistFingerprinting.exemptedDomains", "example.org"], + ], + }); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + url: uri, + }, + async function(browser) { + let result = await SpecialPowers.spawn( + browser, + [iframe_domain, cross_origin_domain], + async function(iframe_domain_, cross_origin_domain_) { + return content.wrappedJSObject.runTheTest( + iframe_domain_, + cross_origin_domain_ + ); + } + ); + + let expectedResults = JSON.parse(JSON.stringify(allSpoofed)); + expectedResults.testDesc = "test (H)"; + + testNavigator(result, expectedResults); + } + ); + + await SpecialPowers.popPrefEnv(); +}); diff --git a/browser/components/resistfingerprinting/test/browser/browser_reduceTimePrecision_iframes.js b/browser/components/resistfingerprinting/test/browser/browser_reduceTimePrecision_iframes.js deleted file mode 100644 index bb0a967224c0..000000000000 --- a/browser/components/resistfingerprinting/test/browser/browser_reduceTimePrecision_iframes.js +++ /dev/null @@ -1,270 +0,0 @@ -/** - * This test only tests values in the iframe, it does not test them on the framer - * - * Covers the following cases: - * - RFP is disabled entirely - * - RFP is enabled entirely - - * - (A) RFP is exempted on the framer and framee - * - (B) RFP is exempted on the framer and framee - - * - (C) RFP is exempted on the framer but not the framee - * - (D) RFP is exempted on the framer but not the framee - - * - (E) RFP is not exempted on the framer nor the framee - * - (F) RFP is not exempted on the framer nor the framee - * - * - (G) RFP is not exempted on the framer but is on the framee - * - (H) RFP is not exempted on the framer but is on the framee - */ - -"use strict"; - -requestLongerTimeout(3); - -ChromeUtils.defineModuleGetter( - this, - "AppConstants", - "resource://gre/modules/AppConstants.jsm" -); - -// ============================================================================================= -// ============================================================================================= - -async function testTimePrecision(results, expectedResults, extraData) { - let testDesc = extraData.testDesc; - let precision = undefined; - - if (!expectedResults.shouldRFPApply) { - precision = extraData.RTP_Precision; - } else { - precision = extraData.RFP_Precision; - } - - for (let result of results) { - let isRounded = isTimeValueRounded(result.value, precision); - - ok( - isRounded, - "Test: " + - testDesc + - " - '" + - "'" + - result.name + - "' should be rounded to nearest " + - precision + - " ms; saw " + - result.value - ); - } -} - -const RFP_TIME_ATOM_MS = 16.667; -const framer_domain = "example.com"; -const iframe_domain = "example.org"; -const cross_origin_domain = "example.net"; -const uri = `https://${framer_domain}/browser/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html`; - -// The first three variables are defined here; and then set for test banks below. -let extraData = {}; -let extraPrefs = {}; -let precision = 100; -let expectedResults = {}; // In this test, we don't have explicit expected values, but rather we expect them to be rounded - -// ======================================================================================================================== -// Create a function that defines all the tests -function addAllTests(extraData_, extraPrefs_) { - add_task( - partial( - defaultsTest, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - add_task( - partial( - simpleRFPTest, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource - add_task( - partial( - testA, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testB, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource - add_task( - partial( - testC, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testD, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource - add_task( - partial( - testE, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testF, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource - add_task( - partial( - testG, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); - - // (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource - add_task( - partial( - testH, - uri, - iframe_domain, - cross_origin_domain, - testTimePrecision, - expectedResults, - extraData_, - extraPrefs_ - ) - ); -} - -// ======================================================================================================================== -// First we run through all the tests with RTP's precision set to 100 ms and 133 ms. -// Because 100ms and 133ms are >= RFP's precision of 100ms, _all_ tests results should -// be rounded. -precision = 100; -extraData = { - RFP_Precision: precision, - RTP_Precision: precision, -}; -extraPrefs = [ - [ - "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", - precision * 1000, - ], -]; -addAllTests(extraData, extraPrefs); - -precision = 133; -extraData = { - RFP_Precision: precision, - RTP_Precision: precision, -}; -extraPrefs = [ - [ - "privacy.resistFingerprinting.reduceTimerPrecision.microseconds", - precision * 1000, - ], -]; -addAllTests(extraData, extraPrefs); - -// ======================================================================================================================== -// Then we run through all the tests with the precision set to its normal value. -// This will mean that in some cases we expect RFP to apply and in some we don't. - -precision = RFP_TIME_ATOM_MS; -extraData = { - RFP_Precision: precision, - RTP_Precision: 1, -}; -extraPrefs = []; -addAllTests(extraData, extraPrefs); - -// ======================================================================================================================== -// Finally we run through all the tests with the precision set to an unusual value -// This will mean that in some cases we expect RFP to apply and in some we don't. - -precision = RFP_TIME_ATOM_MS; -extraData = { - RFP_Precision: RFP_TIME_ATOM_MS, - RTP_Precision: 7, -}; -extraPrefs = [ - ["privacy.resistFingerprinting.reduceTimerPrecision.microseconds", 7 * 1000], -]; -addAllTests(extraData, extraPrefs); diff --git a/browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html b/browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html deleted file mode 100644 index da86656bd44d..000000000000 --- a/browser/components/resistfingerprinting/test/browser/file_animationapi_iframee.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - -
test
- - diff --git a/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html b/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html deleted file mode 100644 index ece07357e13b..000000000000 --- a/browser/components/resistfingerprinting/test/browser/file_animationapi_iframer.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html b/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html index 8e312d1d7b53..566b02ae1c7a 100644 --- a/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html +++ b/browser/components/resistfingerprinting/test/browser/file_navigator_iframee.html @@ -40,13 +40,13 @@ window.addEventListener("message", async function listener(event) { result.worker_product = worker_result.product; result.worker_hardwareConcurrency = worker_result.hardwareConcurrency; - var one = fetch("file_navigator_header.sjs?") + var one = fetch("browser_navigator_header.sjs?") .then((response) => { return response.text(); }) .then((content) => { result.userAgentHTTPHeader = content; }); - var two = fetch(`https://${cross_origin_domain}/browser/browser/components/resistfingerprinting/test/browser/file_navigator_header.sjs?`) + var two = fetch(`https://${cross_origin_domain}/browser/browser/components/resistfingerprinting/test/browser/browser_navigator_header.sjs?`) .then((response) => { return response.text(); }) .then((content) => { result.framee_crossOrigin_userAgentHTTPHeader = content; diff --git a/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html b/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html index e01027b07eee..c0cce12313fd 100644 --- a/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html +++ b/browser/components/resistfingerprinting/test/browser/file_navigator_iframer.html @@ -1,6 +1,9 @@ + diff --git a/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html b/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html deleted file mode 100644 index 454cc8d3b2bb..000000000000 --- a/browser/components/resistfingerprinting/test/browser/file_reduceTimePrecision_iframer.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - diff --git a/browser/components/resistfingerprinting/test/browser/head.js b/browser/components/resistfingerprinting/test/browser/head.js index ffc8134d9e6e..8ad916a6fdf7 100644 --- a/browser/components/resistfingerprinting/test/browser/head.js +++ b/browser/components/resistfingerprinting/test/browser/head.js @@ -585,391 +585,3 @@ class OpenTest extends RoundedWindowTest { ); } } - -// ============================================================ -const partial = (func, ...args) => (...rest) => func(...args, ...rest); - -async function runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData -) { - await BrowserTestUtils.withNewTab( - { - gBrowser, - url: uri, - }, - async function(browser) { - let result = await SpecialPowers.spawn( - browser, - [iframe_domain, cross_origin_domain, extraData], - async function(iframe_domain_, cross_origin_domain_, extraData_) { - return content.wrappedJSObject.runTheTest( - iframe_domain_, - cross_origin_domain_, - extraData_ - ); - } - ); - - testFunction(result, expectedResults, extraData); - } - ); -} - -async function defaultsTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "default"; - expectedResults.shouldRFPApply = false; - if (extraPrefs != undefined) { - await SpecialPowers.pushPrefEnv({ - set: extraPrefs, - }); - } - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - if (extraPrefs != undefined) { - await SpecialPowers.popPrefEnv(); - } -} - -async function simpleRFPTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "simple RFP enabled"; - expectedResults.shouldRFPApply = true; - await SpecialPowers.pushPrefEnv({ - set: [["privacy.resistFingerprinting", true]].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (A) RFP is exempted on the framer and framee and each contacts an exempted cross-origin resource -async function testA( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (A)"; - expectedResults.shouldRFPApply = false; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - [ - "privacy.resistFingerprinting.exemptedDomains", - "example.com, example.org, example.net", - ], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (B) RFP is exempted on the framer and framee and each contacts a non-exempted cross-origin resource -async function testB( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (B)"; - expectedResults.shouldRFPApply = false; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - [ - "privacy.resistFingerprinting.exemptedDomains", - "example.com, example.org", - ], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (C) RFP is exempted on the framer but not the framee and each contacts an exempted cross-origin resource -async function testC( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (C)"; - expectedResults.shouldRFPApply = true; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - [ - "privacy.resistFingerprinting.exemptedDomains", - "example.com, example.net", - ], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (D) RFP is exempted on the framer but not the framee and each contacts a non-exempted cross-origin resource -async function testD( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (D)"; - expectedResults.shouldRFPApply = true; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - ["privacy.resistFingerprinting.exemptedDomains", "example.com"], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (E) RFP is not exempted on the framer nor the framee and each contacts an exempted cross-origin resource -async function testE( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (E)"; - expectedResults.shouldRFPApply = true; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - ["privacy.resistFingerprinting.exemptedDomains", "example.net"], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (F) RFP is not exempted on the framer nor the framee and each contacts a non-exempted cross-origin resource -async function testF( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (F)"; - expectedResults.shouldRFPApply = true; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - ["privacy.resistFingerprinting.exemptedDomains", ""], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (G) RFP is not exempted on the framer but is on the framee and each contacts an exempted cross-origin resource -async function testG( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (G)"; - expectedResults.shouldRFPApply = true; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - [ - "privacy.resistFingerprinting.exemptedDomains", - "example.org, example.net", - ], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} - -// (H) RFP is not exempted on the framer but is on the framee and each contacts a non-exempted cross-origin resource -async function testH( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData, - extraPrefs -) { - if (extraData == undefined) { - extraData = {}; - } - extraData.testDesc = "test (H)"; - expectedResults.shouldRFPApply = true; - await SpecialPowers.pushPrefEnv({ - set: [ - ["privacy.resistFingerprinting", true], - ["privacy.resistFingerprinting.testGranularityMask", 4], - ["privacy.resistFingerprinting.exemptedDomains", "example.org"], - ].concat(extraPrefs || []), - }); - - await runActualTest( - uri, - iframe_domain, - cross_origin_domain, - testFunction, - expectedResults, - extraData - ); - - await SpecialPowers.popPrefEnv(); -} diff --git a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini index cfd6d6701784..b9dfad783034 100644 --- a/browser/components/resistfingerprinting/test/mochitest/mochitest.ini +++ b/browser/components/resistfingerprinting/test/mochitest/mochitest.ini @@ -13,6 +13,7 @@ support-files = [test_geolocation.html] scheme = https fail-if = xorigin +[test_reduce_time_precision.html] [test_hide_gamepad_info.html] scheme = https support-files = test_hide_gamepad_info_iframe.html diff --git a/browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html b/browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html new file mode 100644 index 000000000000..fec7cfc48c65 --- /dev/null +++ b/browser/components/resistfingerprinting/test/mochitest/test_reduce_time_precision.html @@ -0,0 +1,208 @@ + + + + + + Test for Tor Bug 1517 and Mozilla Bug 1424341 + + + + +Tor Bug 1517 +Mozilla Bug 1424341 + + + + + + + diff --git a/dom/animation/Animation.cpp b/dom/animation/Animation.cpp index cfa463989ce0..dfb553320f40 100644 --- a/dom/animation/Animation.cpp +++ b/dom/animation/Animation.cpp @@ -83,9 +83,7 @@ class MOZ_RAII AutoMutationBatchForAnimation { // --------------------------------------------------------------------------- Animation::Animation(nsIGlobalObject* aGlobal) - : DOMEventTargetHelper(aGlobal), - mAnimationIndex(sNextAnimationIndex++), - mRTPCallerType(aGlobal->RTPCallerType()) {} + : DOMEventTargetHelper(aGlobal), mAnimationIndex(sNextAnimationIndex++) {} Animation::~Animation() = default; @@ -142,14 +140,14 @@ already_AddRefed Animation::Constructor( const GlobalObject& aGlobal, AnimationEffect* aEffect, const Optional& aTimeline, ErrorResult& aRv) { nsCOMPtr global = do_QueryInterface(aGlobal.GetAsSupports()); + RefPtr animation = new Animation(global); AnimationTimeline* timeline; - Document* document = - AnimationUtils::GetCurrentRealmDocument(aGlobal.Context()); - if (aTimeline.WasPassed()) { timeline = aTimeline.Value(); } else { + Document* document = + AnimationUtils::GetCurrentRealmDocument(aGlobal.Context()); if (!document) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; @@ -157,7 +155,6 @@ already_AddRefed Animation::Constructor( timeline = document->Timeline(); } - RefPtr animation = new Animation(global); animation->SetTimelineNoUpdate(timeline); animation->SetEffectNoUpdate(aEffect); @@ -875,7 +872,7 @@ void Animation::CommitStyles(ErrorResult& aRv) { // --------------------------------------------------------------------------- Nullable Animation::GetStartTimeAsDouble() const { - return AnimationUtils::TimeDurationToDouble(mStartTime, mRTPCallerType); + return AnimationUtils::TimeDurationToDouble(mStartTime); } void Animation::SetStartTimeAsDouble(const Nullable& aStartTime) { @@ -883,8 +880,7 @@ void Animation::SetStartTimeAsDouble(const Nullable& aStartTime) { } Nullable Animation::GetCurrentTimeAsDouble() const { - return AnimationUtils::TimeDurationToDouble(GetCurrentTimeAsDuration(), - mRTPCallerType); + return AnimationUtils::TimeDurationToDouble(GetCurrentTimeAsDuration()); } void Animation::SetCurrentTimeAsDouble(const Nullable& aCurrentTime, diff --git a/dom/animation/Animation.h b/dom/animation/Animation.h index 8a5146d62ba0..464a273a6b85 100644 --- a/dom/animation/Animation.h +++ b/dom/animation/Animation.h @@ -11,7 +11,6 @@ #include "nsCycleCollectionParticipant.h" #include "mozilla/AnimationPerformanceWarning.h" #include "mozilla/Attributes.h" -#include "mozilla/BasePrincipal.h" #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/EffectCompositor.h" // For EffectCompositor::CascadeLevel #include "mozilla/LinkedList.h" @@ -676,9 +675,6 @@ class Animation : public DOMEventTargetHelper, bool mResetCurrentTimeOnResume = false; - // Whether the Animation is System, ResistFingerprinting, or neither - RTPCallerType mRTPCallerType; - private: // The id for this animaiton on the compositor. uint64_t mIdOnCompositor = 0; diff --git a/dom/animation/AnimationEffect.cpp b/dom/animation/AnimationEffect.cpp index be0ef9fc799c..15035ab3bbf1 100644 --- a/dom/animation/AnimationEffect.cpp +++ b/dom/animation/AnimationEffect.cpp @@ -35,9 +35,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AnimationEffect) NS_INTERFACE_MAP_END AnimationEffect::AnimationEffect(Document* aDocument, TimingParams&& aTiming) - : mDocument(aDocument), mTiming(std::move(aTiming)) { - mRTPCallerType = mDocument->GetScopeObject()->RTPCallerType(); -} + : mDocument(aDocument), mTiming(std::move(aTiming)) {} AnimationEffect::~AnimationEffect() = default; @@ -318,8 +316,7 @@ void AnimationEffect::GetComputedTimingAsDict( aRetVal.mFill = computedTiming.mFill; aRetVal.mActiveDuration = computedTiming.mActiveDuration.ToMilliseconds(); aRetVal.mEndTime = computedTiming.mEndTime.ToMilliseconds(); - aRetVal.mLocalTime = - AnimationUtils::TimeDurationToDouble(currentTime, mRTPCallerType); + aRetVal.mLocalTime = AnimationUtils::TimeDurationToDouble(currentTime); aRetVal.mProgress = computedTiming.mProgress; if (!aRetVal.mProgress.IsNull()) { diff --git a/dom/animation/AnimationEffect.h b/dom/animation/AnimationEffect.h index 7dbd51c2bf38..0f597d1b9859 100644 --- a/dom/animation/AnimationEffect.h +++ b/dom/animation/AnimationEffect.h @@ -106,9 +106,6 @@ class AnimationEffect : public nsISupports, public nsWrapperCache { RefPtr mAnimation; TimingParams mTiming; Maybe mNormalizedTiming; - - // Whether the Animation is System, ResistFingerprinting, or neither - enum RTPCallerType mRTPCallerType; }; } // namespace dom diff --git a/dom/animation/AnimationTimeline.h b/dom/animation/AnimationTimeline.h index a8d3ced34d06..ba437350dbc2 100644 --- a/dom/animation/AnimationTimeline.h +++ b/dom/animation/AnimationTimeline.h @@ -25,9 +25,7 @@ class ScrollTimeline; class AnimationTimeline : public nsISupports, public nsWrapperCache { public: - explicit AnimationTimeline(nsIGlobalObject* aWindow, - RTPCallerType aRTPCallerType) - : mWindow(aWindow), mRTPCallerType(aRTPCallerType) { + explicit AnimationTimeline(nsIGlobalObject* aWindow) : mWindow(aWindow) { MOZ_ASSERT(mWindow); } @@ -50,8 +48,7 @@ class AnimationTimeline : public nsISupports, public nsWrapperCache { // Wrapper functions for AnimationTimeline DOM methods when called from // script. Nullable GetCurrentTimeAsDouble() const { - return AnimationUtils::TimeDurationToDouble(GetCurrentTimeAsDuration(), - mRTPCallerType); + return AnimationUtils::TimeDurationToDouble(GetCurrentTimeAsDuration()); } TimeStamp GetCurrentTimeAsTimeStamp() const { @@ -108,8 +105,6 @@ class AnimationTimeline : public nsISupports, public nsWrapperCache { virtual bool IsMonotonicallyIncreasing() const = 0; - RTPCallerType RTPCallerType() const { return mRTPCallerType; } - virtual bool IsScrollTimeline() const { return false; } virtual const ScrollTimeline* AsScrollTimeline() const { return nullptr; } @@ -134,9 +129,6 @@ class AnimationTimeline : public nsISupports, public nsWrapperCache { typedef nsTHashSet> AnimationSet; AnimationSet mAnimations; LinkedList mAnimationOrder; - - // Whether the Timeline is System, ResistFingerprinting, or neither - enum RTPCallerType mRTPCallerType; }; } // namespace mozilla::dom diff --git a/dom/animation/AnimationUtils.h b/dom/animation/AnimationUtils.h index cd867da1d4c8..1743b305d31a 100644 --- a/dom/animation/AnimationUtils.h +++ b/dom/animation/AnimationUtils.h @@ -31,7 +31,7 @@ class AnimationUtils { using Document = dom::Document; static dom::Nullable TimeDurationToDouble( - const dom::Nullable& aTime, RTPCallerType aRTPCallerType) { + const dom::Nullable& aTime) { dom::Nullable result; if (!aTime.IsNull()) { @@ -40,7 +40,7 @@ class AnimationUtils { // only clamping for RFP mode. RFP mode gives a much lower time precision, // so we accept the security leak here for now result.SetValue(nsRFPService::ReduceTimePrecisionAsMSecsRFPOnly( - aTime.Value().ToMilliseconds(), 0, aRTPCallerType)); + aTime.Value().ToMilliseconds(), 0)); } return result; diff --git a/dom/animation/CSSAnimation.cpp b/dom/animation/CSSAnimation.cpp index ed48d248064c..b750a1405c73 100644 --- a/dom/animation/CSSAnimation.cpp +++ b/dom/animation/CSSAnimation.cpp @@ -227,8 +227,8 @@ void CSSAnimation::QueueEvents(const StickyTimeDuration& aActiveTime) { // That is to say, whenever elapsedTime goes negative (because an // animation restarts, something rewinds the animation, or otherwise) // a new random value for the mix-in must be generated. - elapsedTime = nsRFPService::ReduceTimePrecisionAsSecsRFPOnly( - elapsedTime, 0, mRTPCallerType); + elapsedTime = + nsRFPService::ReduceTimePrecisionAsSecsRFPOnly(elapsedTime, 0); } events.AppendElement( AnimationEventInfo(mAnimationName, mOwningElement.Target(), aMessage, diff --git a/dom/animation/CSSTransition.cpp b/dom/animation/CSSTransition.cpp index 38f9c9386abb..3123553a1d2a 100644 --- a/dom/animation/CSSTransition.cpp +++ b/dom/animation/CSSTransition.cpp @@ -116,8 +116,8 @@ void CSSTransition::QueueEvents(const StickyTimeDuration& aActiveTime) { // That is to say, whenever elapsedTime goes negative (because an // animation restarts, something rewinds the animation, or otherwise) // a new random value for the mix-in must be generated. - elapsedTime = nsRFPService::ReduceTimePrecisionAsSecsRFPOnly( - elapsedTime, 0, mRTPCallerType); + elapsedTime = + nsRFPService::ReduceTimePrecisionAsSecsRFPOnly(elapsedTime, 0); } events.AppendElement(AnimationEventInfo( TransitionProperty(), mOwningElement.Target(), aMessage, elapsedTime, diff --git a/dom/animation/DocumentTimeline.cpp b/dom/animation/DocumentTimeline.cpp index 6f8af780a30e..5dc1df223c84 100644 --- a/dom/animation/DocumentTimeline.cpp +++ b/dom/animation/DocumentTimeline.cpp @@ -42,8 +42,7 @@ NS_IMPL_RELEASE_INHERITED(DocumentTimeline, AnimationTimeline) DocumentTimeline::DocumentTimeline(Document* aDocument, const TimeDuration& aOriginTime) - : AnimationTimeline(aDocument->GetParentObject(), - aDocument->GetScopeObject()->RTPCallerType()), + : AnimationTimeline(aDocument->GetParentObject()), mDocument(aDocument), mIsObservingRefreshDriver(false), mOriginTime(aOriginTime) { diff --git a/dom/animation/ScrollTimeline.cpp b/dom/animation/ScrollTimeline.cpp index c2b88c23079a..ae44dc8cef55 100644 --- a/dom/animation/ScrollTimeline.cpp +++ b/dom/animation/ScrollTimeline.cpp @@ -43,8 +43,7 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(ScrollTimeline, ScrollTimeline::ScrollTimeline(Document* aDocument, const Scroller& aScroller, StyleScrollAxis aAxis) - : AnimationTimeline(aDocument->GetParentObject(), - aDocument->GetScopeObject()->RTPCallerType()), + : AnimationTimeline(aDocument->GetParentObject()), mDocument(aDocument), mSource(aScroller), mAxis(aAxis) { diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 9ebbf429c407..c8a8296292ad 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -1629,9 +1629,7 @@ bool nsGlobalWindowInner::ShouldResistFingerprinting() const { if (mDoc) { return mDoc->ShouldResistFingerprinting(); } - return nsContentUtils::ShouldResistFingerprinting( - "If we do not have a document then we do not have any context" - "to make an informed RFP choice, so we fall back to the global pref"); + return nsIScriptGlobalObject::ShouldResistFingerprinting(); } OriginTrials nsGlobalWindowInner::Trials() const { diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 1752ecc54974..6cfca28a0c1c 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -1670,9 +1670,7 @@ bool nsGlobalWindowOuter::ShouldResistFingerprinting() const { if (mDoc) { return mDoc->ShouldResistFingerprinting(); } - return nsContentUtils::ShouldResistFingerprinting( - "If we do not have a document then we do not have any context" - "to make an informed RFP choice, so we fall back to the global pref"); + return nsIScriptGlobalObject::ShouldResistFingerprinting(); } uint32_t nsGlobalWindowOuter::GetPrincipalHashValue() const { @@ -2015,25 +2013,22 @@ static JS::RealmCreationOptions& SelectZone( * to manage the lifetime of it. */ static nsresult CreateNativeGlobalForInner( - JSContext* aCx, nsGlobalWindowInner* aNewInner, Document* aDocument, - JS::MutableHandle aGlobal, bool aIsSecureContext, - bool aDefineSharedArrayBufferConstructor) { + JSContext* aCx, nsGlobalWindowInner* aNewInner, nsIURI* aURI, + nsIPrincipal* aPrincipal, JS::MutableHandle aGlobal, + bool aIsSecureContext, bool aDefineSharedArrayBufferConstructor) { MOZ_ASSERT(aCx); MOZ_ASSERT(aNewInner); - - nsCOMPtr uri = aDocument->GetDocumentURI(); - nsCOMPtr principal = aDocument->NodePrincipal(); - MOZ_ASSERT(principal); + MOZ_ASSERT(aPrincipal); // DOMWindow with nsEP is not supported, we have to make sure // no one creates one accidentally. - nsCOMPtr nsEP = do_QueryInterface(principal); + nsCOMPtr nsEP = do_QueryInterface(aPrincipal); MOZ_RELEASE_ASSERT(!nsEP, "DOMWindow with nsEP is not supported"); JS::RealmOptions options; JS::RealmCreationOptions& creationOptions = options.creationOptions(); - SelectZone(aCx, principal, aNewInner, creationOptions); + SelectZone(aCx, aPrincipal, aNewInner, creationOptions); creationOptions.setSecureContext(aIsSecureContext); @@ -2046,16 +2041,15 @@ static nsresult CreateNativeGlobalForInner( creationOptions.setDefineSharedArrayBufferConstructor( aDefineSharedArrayBufferConstructor); - xpc::InitGlobalObjectOptions(options, principal->IsSystemPrincipal(), - aDocument->ShouldResistFingerprinting()); + xpc::InitGlobalObjectOptions(options, aPrincipal); // Determine if we need the Components object. - bool needComponents = principal->IsSystemPrincipal(); + bool needComponents = aPrincipal->IsSystemPrincipal(); uint32_t flags = needComponents ? 0 : xpc::OMIT_COMPONENTS_OBJECT; flags |= xpc::DONT_FIRE_ONNEWGLOBALHOOK; if (!Window_Binding::Wrap(aCx, aNewInner, aNewInner, options, - nsJSPrincipals::get(principal), false, aGlobal) || + nsJSPrincipals::get(aPrincipal), false, aGlobal) || !xpc::InitGlobalObject(aCx, aGlobal, flags)) { return NS_ERROR_FAILURE; } @@ -2064,7 +2058,7 @@ static nsresult CreateNativeGlobalForInner( // Set the location information for the new global, so that tools like // about:memory may use that information - xpc::SetLocationForGlobal(aGlobal, uri); + xpc::SetLocationForGlobal(aGlobal, aURI); if (!InitializeLegacyNetscapeObject(aCx, aGlobal)) { return NS_ERROR_FAILURE; @@ -2258,7 +2252,8 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument, // Every script context we are initialized with must create a // new global. rv = CreateNativeGlobalForInner( - cx, newInnerWindow, aDocument, &newInnerGlobal, + cx, newInnerWindow, aDocument->GetDocumentURI(), + aDocument->NodePrincipal(), &newInnerGlobal, ComputeIsSecureContext(aDocument), newInnerWindow->IsSharedMemoryAllowedInternal( aDocument->NodePrincipal())); @@ -5470,9 +5465,9 @@ void nsGlobalWindowOuter::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, CheckForDPIChange(); } -void nsGlobalWindowOuter::SizeToContentOuter( - CallerType aCallerType, const SizeToContentConstraints& aConstraints, - ErrorResult& aError) { +void nsGlobalWindowOuter::SizeToContentOuter(CallerType aCallerType, + const SizeToContentConstraints& aConstraints, + ErrorResult& aError) { if (!mDocShell) { return; } @@ -5494,8 +5489,7 @@ void nsGlobalWindowOuter::SizeToContentOuter( return aError.Throw(NS_ERROR_FAILURE); } - auto contentSize = cv->GetContentSize( - aConstraints.mMaxWidth, aConstraints.mMaxHeight, aConstraints.mPrefWidth); + auto contentSize = cv->GetContentSize(aConstraints.mMaxWidth, aConstraints.mMaxHeight, aConstraints.mPrefWidth); if (!contentSize) { return aError.Throw(NS_ERROR_FAILURE); } diff --git a/dom/base/nsIGlobalObject.cpp b/dom/base/nsIGlobalObject.cpp index b40bbe6679c7..5aa3a9e5d970 100644 --- a/dom/base/nsIGlobalObject.cpp +++ b/dom/base/nsIGlobalObject.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsIGlobalObject.h" -#include "mozilla/BasePrincipal.h" #include "mozilla/CycleCollectedJSContext.h" #include "mozilla/Result.h" #include "mozilla/StorageAccess.h" @@ -69,7 +68,7 @@ nsIGlobalObject::~nsIGlobalObject() { MOZ_DIAGNOSTIC_ASSERT(mEventTargetObjects.isEmpty()); } -nsIPrincipal* nsIGlobalObject::PrincipalOrNull() const { +nsIPrincipal* nsIGlobalObject::PrincipalOrNull() { if (!NS_IsMainThread()) { return nullptr; } @@ -397,26 +396,3 @@ mozilla::Result nsIGlobalObject::HasEqualStorageKey( return mozilla::ipc::StorageKeysEqual(storageKey, aStorageKey); } - -bool nsIGlobalObject::IsSystemPrincipal() const { - MOZ_ASSERT(NS_IsMainThread(), - "Cannot ask nsIGlobalObject IsSystemPrincipal off-main-thread"); - - return PrincipalOrNull()->IsSystemPrincipal(); -} - -RTPCallerType nsIGlobalObject::RTPCallerType() const { - if (IsSystemPrincipal()) { - return RTPCallerType::SystemPrincipal; - } - - if (ShouldResistFingerprinting()) { - return RTPCallerType::ResistFingerprinting; - } - - if (CrossOriginIsolated()) { - return RTPCallerType::CrossOriginIsolated; - } - - return RTPCallerType::Normal; -} diff --git a/dom/base/nsIGlobalObject.h b/dom/base/nsIGlobalObject.h index 1de8473899fd..e79bd6d31b7d 100644 --- a/dom/base/nsIGlobalObject.h +++ b/dom/base/nsIGlobalObject.h @@ -13,7 +13,6 @@ #include "mozilla/dom/DispatcherTrait.h" #include "mozilla/dom/ServiceWorkerDescriptor.h" #include "mozilla/OriginTrials.h" -#include "nsContentUtils.h" #include "nsHashKeys.h" #include "nsISupports.h" #include "nsStringFwd.h" @@ -59,16 +58,6 @@ namespace JS::loader { class ModuleLoaderBase; } // namespace JS::loader -// Reduce Timer Precision (RTP) Caller Type -// This lives here because anything dealing with RTPCallerType determines it -// through this object. -enum class RTPCallerType : uint8_t { - Normal = 0, - SystemPrincipal = (1 << 0), - ResistFingerprinting = (1 << 1), - CrossOriginIsolated = (1 << 2) -}; - /** * See . */ @@ -145,7 +134,7 @@ class nsIGlobalObject : public nsISupports, bool HasJSGlobal() const { return GetGlobalJSObjectPreserveColor(); } // This method is not meant to be overridden. - nsIPrincipal* PrincipalOrNull() const; + nsIPrincipal* PrincipalOrNull(); void RegisterHostObjectURI(const nsACString& aURI); @@ -253,9 +242,7 @@ class nsIGlobalObject : public nsISupports, * Check whether we should avoid leaking distinguishing information to JS/CSS. * https://w3c.github.io/fingerprinting-guidance/ */ - virtual bool ShouldResistFingerprinting() const = 0; - - RTPCallerType RTPCallerType() const; + virtual bool ShouldResistFingerprinting() const; /** * Threadsafe way to get nsIPrincipal::GetHashValue for the associated @@ -281,8 +268,6 @@ class nsIGlobalObject : public nsISupports, protected: virtual ~nsIGlobalObject(); - virtual bool IsSystemPrincipal() const; - void StartDying() { mIsDying = true; } void StartForbiddingScript() { mIsScriptForbidden = true; } diff --git a/dom/bindings/SimpleGlobalObject.h b/dom/bindings/SimpleGlobalObject.h index ef9ebd2d6875..45abd651ebf2 100644 --- a/dom/bindings/SimpleGlobalObject.h +++ b/dom/bindings/SimpleGlobalObject.h @@ -13,7 +13,6 @@ #ifndef mozilla_dom_SimpleGlobalObject_h__ #define mozilla_dom_SimpleGlobalObject_h__ -#include "nsContentUtils.h" #include "nsIGlobalObject.h" #include "nsWrapperCache.h" #include "js/TypeDecls.h" @@ -73,12 +72,6 @@ class SimpleGlobalObject : public nsIGlobalObject, public nsWrapperCache { MOZ_CRASH("SimpleGlobalObject doesn't use DOM bindings!"); } - bool ShouldResistFingerprinting() const override { - return nsContentUtils::ShouldResistFingerprinting( - "Presently we don't have enough context to make an informed decision" - "on JS Sandboxes. See 1782853"); - } - private: SimpleGlobalObject(JSObject* global, GlobalType type) : mType(type) { SetWrapper(global); diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index d0f2d6459d5d..5f00c4c98153 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -28,7 +28,6 @@ #include "mozilla/dom/DocumentInlines.h" #include "mozilla/dom/Event.h" #include "mozilla/dom/ShadowRoot.h" -#include "mozilla/dom/WorkerScope.h" #include "mozilla/StaticPrefs_dom.h" #include "mozilla/SVGUtils.h" #include "mozilla/SVGOuterSVGFrame.h" @@ -762,7 +761,9 @@ double Event::TimeStamp() { MOZ_ASSERT(mOwner->PrincipalOrNull()); return nsRFPService::ReduceTimePrecisionAsMSecs( - ret, perf->GetRandomTimelineSeed(), perf->RTPCallerType()); + ret, perf->GetRandomTimelineSeed(), + mOwner->PrincipalOrNull()->IsSystemPrincipal(), + mOwner->CrossOriginIsolated()); } WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); @@ -772,7 +773,8 @@ double Event::TimeStamp() { return nsRFPService::ReduceTimePrecisionAsMSecs( ret, workerPrivate->GetRandomTimelineSeed(), - workerPrivate->GlobalScope()->RTPCallerType()); + workerPrivate->UsesSystemPrincipal(), + workerPrivate->CrossOriginIsolated()); } void Event::Serialize(IPC::MessageWriter* aWriter, diff --git a/dom/file/BaseBlobImpl.cpp b/dom/file/BaseBlobImpl.cpp index 5871b9da047b..3841737cc469 100644 --- a/dom/file/BaseBlobImpl.cpp +++ b/dom/file/BaseBlobImpl.cpp @@ -64,10 +64,12 @@ void BaseBlobImpl::SetLastModificationDatePrecisely(int64_t aDate) { mLastModificationDate = aDate; } -void BaseBlobImpl::SetLastModificationDate(RTPCallerType aRTPCallerType, +void BaseBlobImpl::SetLastModificationDate(bool aCrossOriginIsolated, int64_t aDate) { return SetLastModificationDatePrecisely( - nsRFPService::ReduceTimePrecisionAsUSecs(aDate, 0, aRTPCallerType)); + nsRFPService::ReduceTimePrecisionAsUSecs(aDate, 0, + /* aIsSystemPrincipal */ false, + aCrossOriginIsolated)); // mLastModificationDate is an absolute timestamp so we supply a zero // context mix-in } diff --git a/dom/file/BaseBlobImpl.h b/dom/file/BaseBlobImpl.h index 7265fc21045d..82f58ae99d4b 100644 --- a/dom/file/BaseBlobImpl.h +++ b/dom/file/BaseBlobImpl.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_BaseBlobImpl_h #define mozilla_dom_BaseBlobImpl_h -#include "nsIGlobalObject.h" #include "mozilla/dom/BlobImpl.h" #include "mozilla/ErrorResult.h" @@ -127,7 +126,7 @@ class BaseBlobImpl : public BlobImpl { */ static uint64_t NextSerialNumber(); - void SetLastModificationDate(RTPCallerType aRTPCallerType, int64_t aDate); + void SetLastModificationDate(bool aCrossOriginIsolated, int64_t aDate); void SetLastModificationDatePrecisely(int64_t aDate); #ifdef DEBUG diff --git a/dom/file/Blob.cpp b/dom/file/Blob.cpp index 15078209b712..3990bde72bfd 100644 --- a/dom/file/Blob.cpp +++ b/dom/file/Blob.cpp @@ -148,8 +148,9 @@ already_AddRefed Blob::ToFile(const nsAString& aName, nsAutoString contentType; mImpl->GetType(contentType); - RefPtr impl = MultipartBlobImpl::Create( - std::move(blobImpls), aName, contentType, mGlobal->RTPCallerType(), aRv); + RefPtr impl = + MultipartBlobImpl::Create(std::move(blobImpls), aName, contentType, + mGlobal->CrossOriginIsolated(), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } @@ -225,9 +226,9 @@ already_AddRefed Blob::Constructor( MakeValidBlobType(type); impl->InitializeBlob(aData.Value(), type, aBag.mEndings == EndingType::Native, - global->RTPCallerType(), aRv); + global->CrossOriginIsolated(), aRv); } else { - impl->InitializeBlob(global->RTPCallerType(), aRv); + impl->InitializeBlob(global->CrossOriginIsolated(), aRv); } if (NS_WARN_IF(aRv.Failed())) { diff --git a/dom/file/File.cpp b/dom/file/File.cpp index 4b168964bec9..4da00ea5e45d 100644 --- a/dom/file/File.cpp +++ b/dom/file/File.cpp @@ -14,7 +14,6 @@ #include "mozilla/dom/FileSystemUtils.h" #include "mozilla/dom/Promise.h" #include "nsIFile.h" -#include "nsContentUtils.h" #include "nsXULAppAPI.h" namespace mozilla::dom { @@ -59,7 +58,8 @@ already_AddRefed File::CreateMemoryFileWithLastModifiedNow( MOZ_ASSERT(aGlobal); RefPtr blobImpl = MemoryBlobImpl::CreateWithLastModifiedNow( - aMemoryBuffer, aLength, aName, aContentType, aGlobal->RTPCallerType()); + aMemoryBuffer, aLength, aName, aContentType, + aGlobal->CrossOriginIsolated()); MOZ_ASSERT(blobImpl); RefPtr file = File::Create(aGlobal, blobImpl); @@ -143,7 +143,7 @@ already_AddRefed File::Constructor(const GlobalObject& aGlobal, nsAutoString type(aBag.mType); MakeValidBlobType(type); impl->InitializeBlob(aData, type, aBag.mEndings == EndingType::Native, - global->RTPCallerType(), aRv); + global->CrossOriginIsolated(), aRv); if (aRv.Failed()) { return nullptr; } diff --git a/dom/file/MemoryBlobImpl.cpp b/dom/file/MemoryBlobImpl.cpp index b6d5c442d149..1c48ec0393a7 100644 --- a/dom/file/MemoryBlobImpl.cpp +++ b/dom/file/MemoryBlobImpl.cpp @@ -28,9 +28,10 @@ already_AddRefed MemoryBlobImpl::CreateWithCustomLastModified( // static already_AddRefed MemoryBlobImpl::CreateWithLastModifiedNow( void* aMemoryBuffer, uint64_t aLength, const nsAString& aName, - const nsAString& aContentType, RTPCallerType aRTPCallerType) { - int64_t lastModificationDate = - nsRFPService::ReduceTimePrecisionAsUSecs(PR_Now(), 0, aRTPCallerType); + const nsAString& aContentType, bool aCrossOriginIsolated) { + int64_t lastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs( + PR_Now(), 0, + /* aIsSystemPrincipal */ false, aCrossOriginIsolated); return CreateWithCustomLastModified(aMemoryBuffer, aLength, aName, aContentType, lastModificationDate); } diff --git a/dom/file/MemoryBlobImpl.h b/dom/file/MemoryBlobImpl.h index 29d812feee2b..94c05569dd49 100644 --- a/dom/file/MemoryBlobImpl.h +++ b/dom/file/MemoryBlobImpl.h @@ -27,7 +27,7 @@ class MemoryBlobImpl final : public BaseBlobImpl { // File constructor. static already_AddRefed CreateWithLastModifiedNow( void* aMemoryBuffer, uint64_t aLength, const nsAString& aName, - const nsAString& aContentType, RTPCallerType aRTPCallerType); + const nsAString& aContentType, bool aCrossOriginIsolated); // File constructor with custom lastModified attribue value. You should // probably use CreateWithLastModifiedNow() instead of this one. diff --git a/dom/file/MultipartBlobImpl.cpp b/dom/file/MultipartBlobImpl.cpp index ef3eaefe6fd5..27f5f22a4c2b 100644 --- a/dom/file/MultipartBlobImpl.cpp +++ b/dom/file/MultipartBlobImpl.cpp @@ -10,7 +10,6 @@ #include "mozilla/dom/FileBinding.h" #include "mozilla/dom/UnionTypes.h" #include "nsComponentManagerUtils.h" -#include "nsIGlobalObject.h" #include "nsIMultiplexInputStream.h" #include "nsReadableUtils.h" #include "nsRFPService.h" @@ -26,11 +25,11 @@ using namespace mozilla::dom; /* static */ already_AddRefed MultipartBlobImpl::Create( nsTArray>&& aBlobImpls, const nsAString& aName, - const nsAString& aContentType, RTPCallerType aRTPCallerType, + const nsAString& aContentType, bool aCrossOriginIsolated, ErrorResult& aRv) { RefPtr blobImpl = new MultipartBlobImpl(std::move(aBlobImpls), aName, aContentType); - blobImpl->SetLengthAndModifiedDate(Some(aRTPCallerType), aRv); + blobImpl->SetLengthAndModifiedDate(Some(aCrossOriginIsolated), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } @@ -44,7 +43,7 @@ already_AddRefed MultipartBlobImpl::Create( ErrorResult& aRv) { RefPtr blobImpl = new MultipartBlobImpl(std::move(aBlobImpls), aContentType); - blobImpl->SetLengthAndModifiedDate(/* aRTPCallerType */ Nothing(), aRv); + blobImpl->SetLengthAndModifiedDate(/* aCrossOriginIsolated */ Nothing(), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } @@ -178,16 +177,16 @@ already_AddRefed MultipartBlobImpl::CreateSlice( return impl.forget(); } -void MultipartBlobImpl::InitializeBlob(RTPCallerType aRTPCallerType, +void MultipartBlobImpl::InitializeBlob(bool aCrossOriginIsolated, ErrorResult& aRv) { - SetLengthAndModifiedDate(Some(aRTPCallerType), aRv); + SetLengthAndModifiedDate(Some(aCrossOriginIsolated), aRv); NS_WARNING_ASSERTION(!aRv.Failed(), "SetLengthAndModifiedDate failed"); } void MultipartBlobImpl::InitializeBlob(const Sequence& aData, const nsAString& aContentType, bool aNativeEOL, - RTPCallerType aRTPCallerType, + bool aCrossOriginIsolated, ErrorResult& aRv) { mContentType = aContentType; BlobSet blobSet; @@ -234,12 +233,12 @@ void MultipartBlobImpl::InitializeBlob(const Sequence& aData, } mBlobImpls = blobSet.GetBlobImpls(); - SetLengthAndModifiedDate(Some(aRTPCallerType), aRv); + SetLengthAndModifiedDate(Some(aCrossOriginIsolated), aRv); NS_WARNING_ASSERTION(!aRv.Failed(), "SetLengthAndModifiedDate failed"); } void MultipartBlobImpl::SetLengthAndModifiedDate( - const Maybe& aRTPCallerType, ErrorResult& aRv) { + const Maybe& aCrossOriginIsolated, ErrorResult& aRv) { MOZ_ASSERT(mLength == MULTIPARTBLOBIMPL_UNKNOWN_LENGTH); MOZ_ASSERT_IF(mIsFile, IsLastModificationDateUnset()); @@ -278,13 +277,13 @@ void MultipartBlobImpl::SetLengthAndModifiedDate( if (lastModifiedSet) { SetLastModificationDatePrecisely(lastModified); } else { - MOZ_ASSERT(aRTPCallerType.isSome()); + MOZ_ASSERT(aCrossOriginIsolated.isSome()); // We cannot use PR_Now() because bug 493756 and, for this reason: // var x = new Date(); var f = new File(...); // x.getTime() < f.dateModified.getTime() // could fail. - SetLastModificationDate(aRTPCallerType.value(), JS_Now()); + SetLastModificationDate(aCrossOriginIsolated.value(), JS_Now()); } } } diff --git a/dom/file/MultipartBlobImpl.h b/dom/file/MultipartBlobImpl.h index cb62f2adb5b3..d22f971ee4ef 100644 --- a/dom/file/MultipartBlobImpl.h +++ b/dom/file/MultipartBlobImpl.h @@ -10,7 +10,6 @@ #include #include "Blob.h" -#include "nsContentUtils.h" #include "mozilla/Attributes.h" #include "mozilla/Maybe.h" #include "mozilla/dom/BaseBlobImpl.h" @@ -32,7 +31,7 @@ class MultipartBlobImpl final : public BaseBlobImpl { // Create as a file static already_AddRefed Create( nsTArray>&& aBlobImpls, const nsAString& aName, - const nsAString& aContentType, RTPCallerType aRTPCallerType, + const nsAString& aContentType, bool aCrossOriginIsolated, ErrorResult& aRv); // Create as a blob @@ -49,11 +48,11 @@ class MultipartBlobImpl final : public BaseBlobImpl { MultipartBlobImpl() : BaseBlobImpl(u""_ns, MULTIPARTBLOBIMPL_UNKNOWN_LENGTH) {} - void InitializeBlob(RTPCallerType aRTPCallerType, ErrorResult& aRv); + void InitializeBlob(bool aCrossOriginIsolated, ErrorResult& aRv); void InitializeBlob(const Sequence& aData, const nsAString& aContentType, bool aNativeEOL, - RTPCallerType aRTPCallerType, ErrorResult& aRv); + bool aCrossOriginIsolated, ErrorResult& aRv); already_AddRefed CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType, @@ -94,7 +93,7 @@ class MultipartBlobImpl final : public BaseBlobImpl { ~MultipartBlobImpl() override = default; - void SetLengthAndModifiedDate(const Maybe& aRTPCallerType, + void SetLengthAndModifiedDate(const Maybe& aCrossOriginIsolated, ErrorResult& aRv); nsTArray> mBlobImpls; diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index 2755690fb615..bb4bec84b491 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -739,15 +739,12 @@ double AudioContext::CurrentTime() { double rawTime = track->TrackTimeToSeconds(track->GetCurrentTime()); - RTPCallerType callerType = GetParentObject()->AsGlobal()->RTPCallerType(); - // CurrentTime increments in intervals of 128/sampleRate. If the Timer // Precision Reduction is smaller than this interval, the jittered time // can always be reversed to the raw step of the interval. In that case // we can simply return the un-reduced time; and avoid breaking tests. // We have to convert each variable into a common magnitude, we choose ms. - if ((128 / mSampleRate) * 1000.0 > - nsRFPService::TimerResolution(callerType) / 1000.0) { + if ((128 / mSampleRate) * 1000.0 > nsRFPService::TimerResolution() / 1000.0) { return rawTime; } @@ -756,7 +753,9 @@ double AudioContext::CurrentTime() { // will never reset (even if one rewinds a video.) Therefore we can use a // single Random Seed initialized at the same time as the object. return nsRFPService::ReduceTimePrecisionAsSecs( - rawTime, GetRandomTimelineSeed(), callerType); + rawTime, GetRandomTimelineSeed(), + /* aIsSystemPrincipal */ false, + GetParentObject()->AsGlobal()->CrossOriginIsolated()); } nsISerialEventTarget* AudioContext::GetMainThread() const { diff --git a/dom/media/webaudio/AudioWorkletGlobalScope.cpp b/dom/media/webaudio/AudioWorkletGlobalScope.cpp index 44e2e9e677b5..7d7429f0dd53 100644 --- a/dom/media/webaudio/AudioWorkletGlobalScope.cpp +++ b/dom/media/webaudio/AudioWorkletGlobalScope.cpp @@ -49,9 +49,6 @@ bool AudioWorkletGlobalScope::WrapGlobalObject( JS::RealmOptions options; - options.behaviors().setShouldResistFingerprinting( - ShouldResistFingerprinting()); - // The SharedArrayBuffer global constructor property should not be present in // a fresh global object when shared memory objects aren't allowed (because // COOP/COEP support isn't enabled, or because COOP/COEP don't act to isolate diff --git a/dom/media/webrtc/jsapi/RTCStatsReport.cpp b/dom/media/webrtc/jsapi/RTCStatsReport.cpp index 0d1e5fdc1616..5b51322127c0 100644 --- a/dom/media/webrtc/jsapi/RTCStatsReport.cpp +++ b/dom/media/webrtc/jsapi/RTCStatsReport.cpp @@ -15,7 +15,7 @@ namespace mozilla::dom { RTCStatsTimestampMaker::RTCStatsTimestampMaker() : mRandomTimelineSeed(0), mStartRealtime(WebrtcSystemTimeBase()), - mRTPCallerType(RTPCallerType::Normal), + mCrossOriginIsolated(false), mStartWallClockRaw( PerformanceService::GetOrCreate()->TimeOrigin(mStartRealtime)) {} @@ -27,9 +27,8 @@ RTCStatsTimestampMaker::RTCStatsTimestampMaker(nsPIDOMWindowInner* aWindow) mStartRealtime(aWindow && aWindow->GetPerformance() ? aWindow->GetPerformance()->CreationTimeStamp() : WebrtcSystemTimeBase()), - mRTPCallerType(aWindow && aWindow->GetPerformance() - ? aWindow->GetPerformance()->RTPCallerType() - : RTPCallerType::Normal), + mCrossOriginIsolated(aWindow ? aWindow->AsGlobal()->CrossOriginIsolated() + : false), mStartWallClockRaw( PerformanceService::GetOrCreate()->TimeOrigin(mStartRealtime)) {} @@ -47,7 +46,8 @@ DOMHighResTimeStamp RTCStatsTimestampMaker::ReduceRealtimePrecision( // mRandomTimelineSeed is not set in the unit-tests. if (mRandomTimelineSeed) { realtime = nsRFPService::ReduceTimePrecisionAsMSecs( - realtime, mRandomTimelineSeed, mRTPCallerType); + realtime, mRandomTimelineSeed, + /* aIsSystemPrincipal */ false, mCrossOriginIsolated); } // Ugh. Performance::TimeOrigin is not constant, which means we need to @@ -56,7 +56,8 @@ DOMHighResTimeStamp RTCStatsTimestampMaker::ReduceRealtimePrecision( // https://searchfox.org/mozilla-central/rev/ // 053826b10f838f77c27507e5efecc96e34718541/dom/performance/Performance.cpp#111-117 DOMHighResTimeStamp start = nsRFPService::ReduceTimePrecisionAsMSecs( - mStartWallClockRaw, 0, mRTPCallerType); + mStartWallClockRaw, 0, /* aIsSystemPrincipal = */ false, + mCrossOriginIsolated); return start + realtime; } diff --git a/dom/media/webrtc/jsapi/RTCStatsReport.h b/dom/media/webrtc/jsapi/RTCStatsReport.h index 5319f26e6b7c..98f868b29846 100644 --- a/dom/media/webrtc/jsapi/RTCStatsReport.h +++ b/dom/media/webrtc/jsapi/RTCStatsReport.h @@ -21,7 +21,6 @@ #include "nsCOMPtr.h" #include "nsIGlobalObject.h" #include "nsPIDOMWindow.h" // nsPIDOMWindowInner -#include "nsContentUtils.h" #include "nsWrapperCache.h" #include "prtime.h" // PR_Now @@ -64,7 +63,7 @@ class RTCStatsTimestampMaker { const uint64_t mRandomTimelineSeed; const TimeStamp mStartRealtime; - const RTPCallerType mRTPCallerType; + const bool mCrossOriginIsolated; const DOMHighResTimeStamp mStartWallClockRaw; }; diff --git a/dom/network/ConnectionWorker.cpp b/dom/network/ConnectionWorker.cpp index 79e81b33b283..c1b76a024456 100644 --- a/dom/network/ConnectionWorker.cpp +++ b/dom/network/ConnectionWorker.cpp @@ -10,7 +10,6 @@ #include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRef.h" #include "mozilla/dom/WorkerRunnable.h" -#include "mozilla/dom/WorkerScope.h" namespace mozilla::dom::network { @@ -142,7 +141,7 @@ class NotifyRunnable : public WorkerRunnable { already_AddRefed ConnectionWorker::Create( WorkerPrivate* aWorkerPrivate, ErrorResult& aRv) { bool shouldResistFingerprinting = - aWorkerPrivate->GlobalScope()->ShouldResistFingerprinting(); + aWorkerPrivate->ShouldResistFingerprinting(); RefPtr c = new ConnectionWorker(shouldResistFingerprinting); c->mProxy = ConnectionProxy::Create(aWorkerPrivate, c); if (!c->mProxy) { diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index e041b5093d0b..f7390af77ebf 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -57,8 +57,8 @@ already_AddRefed Performance::CreateForMainThread( MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aWindow->AsGlobal()); - RefPtr performance = - new PerformanceMainThread(aWindow, aDOMTiming, aChannel); + RefPtr performance = new PerformanceMainThread( + aWindow, aDOMTiming, aChannel, aPrincipal->IsSystemPrincipal()); return performance.forget(); } @@ -93,23 +93,21 @@ already_AddRefed Performance::Get(JSContext* aCx, return performance.forget(); } -Performance::Performance(nsIGlobalObject* aGlobal) +Performance::Performance(nsIGlobalObject* aGlobal, bool aSystemPrincipal) : DOMEventTargetHelper(aGlobal), mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), mPendingNotificationObserversTask(false), mPendingResourceTimingBufferFullEvent(false), - mRTPCallerType( - RTPCallerType::Normal /* to be updated in CreateForFoo */) { + mSystemPrincipal(aSystemPrincipal) { MOZ_ASSERT(!NS_IsMainThread()); } -Performance::Performance(nsPIDOMWindowInner* aWindow) +Performance::Performance(nsPIDOMWindowInner* aWindow, bool aSystemPrincipal) : DOMEventTargetHelper(aWindow), mResourceTimingBufferSize(kDefaultResourceTimingBufferSize), mPendingNotificationObserversTask(false), mPendingResourceTimingBufferFullEvent(false), - mRTPCallerType( - RTPCallerType::Normal /* to be updated in CreateForFoo */) { + mSystemPrincipal(aSystemPrincipal) { MOZ_ASSERT(NS_IsMainThread()); } @@ -118,27 +116,28 @@ Performance::~Performance() = default; DOMHighResTimeStamp Performance::TimeStampToDOMHighResForRendering( TimeStamp aTimeStamp) const { DOMHighResTimeStamp stamp = GetDOMTiming()->TimeStampToDOMHighRes(aTimeStamp); - // 0 is an inappropriate mixin for this this area; however CSS Animations - // needs to have it's Time Reduction Logic refactored, so it's currently - // only clamping for RFP mode. RFP mode gives a much lower time precision, - // so we accept the security leak here for now. - return nsRFPService::ReduceTimePrecisionAsMSecsRFPOnly(stamp, 0, - mRTPCallerType); + if (!IsSystemPrincipal()) { + // 0 is an inappropriate mixin for this this area; however CSS Animations + // needs to have it's Time Reduction Logic refactored, so it's currently + // only clamping for RFP mode. RFP mode gives a much lower time precision, + // so we accept the security leak here for now. + return nsRFPService::ReduceTimePrecisionAsMSecsRFPOnly(stamp, 0); + } + return stamp; } DOMHighResTimeStamp Performance::Now() { DOMHighResTimeStamp rawTime = NowUnclamped(); - // XXX: Removing this caused functions in pkcs11f.h to fail. - // Bug 1628021 investigates the root cause - it involves initializing - // the RNG service (part of GetRandomTimelineSeed()) off-main-thread - // but the underlying cause hasn't been identified yet. - if (mRTPCallerType == RTPCallerType::SystemPrincipal) { + // XXX: Remove this would cause functions in pkcs11f.h to fail. + // Bug 1628021 will find out the root cause. + if (mSystemPrincipal) { return rawTime; } return nsRFPService::ReduceTimePrecisionAsMSecs( - rawTime, GetRandomTimelineSeed(), mRTPCallerType); + rawTime, GetRandomTimelineSeed(), mSystemPrincipal, + CrossOriginIsolated()); } DOMHighResTimeStamp Performance::NowUnclamped() const { @@ -155,8 +154,8 @@ DOMHighResTimeStamp Performance::TimeOrigin() { DOMHighResTimeStamp rawTimeOrigin = mPerformanceService->TimeOrigin(CreationTimeStamp()); // Time Origin is an absolute timestamp, so we supply a 0 context mix-in - return nsRFPService::ReduceTimePrecisionAsMSecs(rawTimeOrigin, 0, - mRTPCallerType); + return nsRFPService::ReduceTimePrecisionAsMSecs( + rawTimeOrigin, 0, mSystemPrincipal, CrossOriginIsolated()); } JSObject* Performance::WrapObject(JSContext* aCx, diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index c2088c681ff9..55ee9d162d14 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -10,7 +10,6 @@ #include "mozilla/Attributes.h" #include "mozilla/DOMEventTargetHelper.h" #include "nsCOMPtr.h" -#include "nsContentUtils.h" #include "nsDOMNavigationTiming.h" #include "nsTObserverArray.h" @@ -120,7 +119,7 @@ class Performance : public DOMEventTargetHelper { virtual TimeStamp CreationTimeStamp() const = 0; - RTPCallerType RTPCallerType() const { return mRTPCallerType; } + bool IsSystemPrincipal() const { return mSystemPrincipal; } DOMHighResTimeStamp TimeStampToDOMHighResForRendering(TimeStamp) const; @@ -158,8 +157,8 @@ class Performance : public DOMEventTargetHelper { virtual bool IsGlobalObjectWindow() const { return false; }; protected: - Performance(nsIGlobalObject* aGlobal); - Performance(nsPIDOMWindowInner* aWindow); + Performance(nsIGlobalObject* aGlobal, bool aSystemPrincipal); + Performance(nsPIDOMWindowInner* aWindow, bool aSystemPrincipal); virtual ~Performance(); @@ -205,7 +204,7 @@ class Performance : public DOMEventTargetHelper { RefPtr mPerformanceService; - enum RTPCallerType mRTPCallerType; + bool mSystemPrincipal; private: MOZ_ALWAYS_INLINE bool CanAddResourceTimingEntry(); diff --git a/dom/performance/PerformanceEventTiming.h b/dom/performance/PerformanceEventTiming.h index 68e129d4946e..8fe78b2e95d4 100644 --- a/dom/performance/PerformanceEventTiming.h +++ b/dom/performance/PerformanceEventTiming.h @@ -43,7 +43,8 @@ class PerformanceEventTiming final if (mCachedProcessingStart.isNothing()) { mCachedProcessingStart.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( mProcessingStart, mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType())); + mPerformance->IsSystemPrincipal(), + mPerformance->CrossOriginIsolated())); } return mCachedProcessingStart.value(); } @@ -52,7 +53,8 @@ class PerformanceEventTiming final if (mCachedProcessingEnd.isNothing()) { mCachedProcessingEnd.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( mProcessingEnd, mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType())); + mPerformance->IsSystemPrincipal(), + mPerformance->CrossOriginIsolated())); } return mCachedProcessingEnd.value(); } @@ -74,7 +76,8 @@ class PerformanceEventTiming final if (mCachedDuration.isNothing()) { mCachedDuration.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( mDuration, mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType())); + mPerformance->IsSystemPrincipal(), + mPerformance->CrossOriginIsolated())); } return mCachedDuration.value(); } @@ -87,7 +90,8 @@ class PerformanceEventTiming final if (mCachedStartTime.isNothing()) { mCachedStartTime.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( mStartTime, mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType())); + mPerformance->IsSystemPrincipal(), + mPerformance->CrossOriginIsolated())); } return mCachedStartTime.value(); } diff --git a/dom/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index bd01c1a5bb13..2bf9267431a4 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -90,13 +90,13 @@ NS_INTERFACE_MAP_END_INHERITING(Performance) PerformanceMainThread::PerformanceMainThread(nsPIDOMWindowInner* aWindow, nsDOMNavigationTiming* aDOMTiming, - nsITimedChannel* aChannel) - : Performance(aWindow), + nsITimedChannel* aChannel, + bool aPrincipal) + : Performance(aWindow, aPrincipal), mDOMTiming(aDOMTiming), mChannel(aChannel), mCrossOriginIsolated(aWindow->AsGlobal()->CrossOriginIsolated()) { MOZ_ASSERT(aWindow, "Parent window object should be provided"); - mRTPCallerType = aWindow->AsGlobal()->RTPCallerType(); if (StaticPrefs::dom_enable_event_timing()) { mEventCounts = new class EventCounts(GetParentObject()); } @@ -361,7 +361,8 @@ DOMHighResTimeStamp PerformanceMainThread::GetPerformanceTimingFromString( "of sync"); } return nsRFPService::ReduceTimePrecisionAsMSecs( - retValue, GetRandomTimelineSeed(), mRTPCallerType); + retValue, GetRandomTimelineSeed(), /* aIsSystemPrinciapl */ false, + CrossOriginIsolated()); } void PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry) { diff --git a/dom/performance/PerformanceMainThread.h b/dom/performance/PerformanceMainThread.h index 31f784b19174..f7070f954155 100644 --- a/dom/performance/PerformanceMainThread.h +++ b/dom/performance/PerformanceMainThread.h @@ -20,7 +20,7 @@ class PerformanceMainThread final : public Performance, public: PerformanceMainThread(nsPIDOMWindowInner* aWindow, nsDOMNavigationTiming* aDOMTiming, - nsITimedChannel* aChannel); + nsITimedChannel* aChannel, bool aPrincipal); NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PerformanceMainThread, diff --git a/dom/performance/PerformanceNavigationTiming.cpp b/dom/performance/PerformanceNavigationTiming.cpp index 5b0b1b70e273..0bd774309836 100644 --- a/dom/performance/PerformanceNavigationTiming.cpp +++ b/dom/performance/PerformanceNavigationTiming.cpp @@ -26,7 +26,7 @@ JSObject* PerformanceNavigationTiming::WrapObject( #define REDUCE_TIME_PRECISION \ return nsRFPService::ReduceTimePrecisionAsMSecs( \ rawValue, mPerformance->GetRandomTimelineSeed(), \ - mPerformance->RTPCallerType()) + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()) DOMHighResTimeStamp PerformanceNavigationTiming::UnloadEventStart() const { DOMHighResTimeStamp rawValue = 0; diff --git a/dom/performance/PerformancePaintTiming.cpp b/dom/performance/PerformancePaintTiming.cpp index 1899de5ab81b..eb13be95f994 100644 --- a/dom/performance/PerformancePaintTiming.cpp +++ b/dom/performance/PerformancePaintTiming.cpp @@ -41,7 +41,8 @@ DOMHighResTimeStamp PerformancePaintTiming::StartTime() const { mPerformance->GetDOMTiming()->TimeStampToDOMHighRes(mRawStartTime); mCachedStartTime.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType())); + mPerformance->IsSystemPrincipal(), + mPerformance->CrossOriginIsolated())); } return mCachedStartTime.value(); } diff --git a/dom/performance/PerformanceTiming.cpp b/dom/performance/PerformanceTiming.cpp index 71f4d90aa33e..594a073b4392 100644 --- a/dom/performance/PerformanceTiming.cpp +++ b/dom/performance/PerformanceTiming.cpp @@ -84,7 +84,8 @@ PerformanceTiming::PerformanceTiming(Performance* aPerformance, aChannel, aHttpChannel, nsRFPService::ReduceTimePrecisionAsMSecs( aZeroTime, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()))); + aPerformance->IsSystemPrincipal(), + aPerformance->CrossOriginIsolated()))); // Non-null aHttpChannel implies that this PerformanceTiming object is being // used for subresources, which is irrelevant to this probe. @@ -310,7 +311,7 @@ DOMHighResTimeStamp PerformanceTimingData::FetchStartHighRes( } return nsRFPService::ReduceTimePrecisionAsMSecs( mFetchStart, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::FetchStart() { @@ -381,7 +382,7 @@ DOMHighResTimeStamp PerformanceTimingData::AsyncOpenHighRes( TimeStampToDOMHighRes(aPerformance, mAsyncOpen); return nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMHighResTimeStamp PerformanceTimingData::WorkerStartHighRes( @@ -396,7 +397,7 @@ DOMHighResTimeStamp PerformanceTimingData::WorkerStartHighRes( TimeStampToDOMHighRes(aPerformance, mWorkerStart); return nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } /** @@ -505,7 +506,7 @@ DOMHighResTimeStamp PerformanceTimingData::DomainLookupEndHighRes( TimeStampToDOMHighRes(aPerformance, mDomainLookupEnd); return nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::DomainLookupEnd() { @@ -527,7 +528,7 @@ DOMHighResTimeStamp PerformanceTimingData::ConnectStartHighRes( TimeStampToDOMHighRes(aPerformance, mConnectStart); return nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::ConnectStart() { @@ -552,7 +553,7 @@ DOMHighResTimeStamp PerformanceTimingData::SecureConnectionStartHighRes( TimeStampToDOMHighRes(aPerformance, mSecureConnectionStart); return nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::SecureConnectionStart() { @@ -575,7 +576,7 @@ DOMHighResTimeStamp PerformanceTimingData::ConnectEndHighRes( TimeStampToDOMHighRes(aPerformance, mConnectEnd); return nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::ConnectEnd() { @@ -646,7 +647,7 @@ DOMHighResTimeStamp PerformanceTimingData::ResponseEndHighRes( TimeStampToDOMHighRes(aPerformance, mResponseEnd); return nsRFPService::ReduceTimePrecisionAsMSecs( rawValue, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } DOMTimeMilliSec PerformanceTiming::ResponseEnd() { diff --git a/dom/performance/PerformanceTiming.h b/dom/performance/PerformanceTiming.h index 80f86d1ad385..080b3ddf5f4d 100644 --- a/dom/performance/PerformanceTiming.h +++ b/dom/performance/PerformanceTiming.h @@ -84,7 +84,7 @@ class PerformanceTimingData final { return nsRFPService::ReduceTimePrecisionAsMSecs( rawTimestamp, aPerformance->GetRandomTimelineSeed(), - aPerformance->RTPCallerType()); + aPerformance->IsSystemPrincipal(), aPerformance->CrossOriginIsolated()); } /** @@ -262,7 +262,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetNavigationStart(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec UnloadEventStart() { @@ -271,7 +272,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetUnloadEventStart(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec UnloadEventEnd() { @@ -280,7 +282,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetUnloadEventEnd(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } // Low resolution (used by navigation timing) @@ -302,7 +305,7 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomLoading(), mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType()); + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomInteractive() const { @@ -311,7 +314,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomInteractive(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomContentLoadedEventStart() const { @@ -320,7 +324,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomContentLoadedEventStart(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomContentLoadedEventEnd() const { @@ -329,7 +334,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomContentLoadedEventEnd(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec DomComplete() const { @@ -338,7 +344,7 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetDomComplete(), mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType()); + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec LoadEventStart() const { @@ -347,7 +353,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetLoadEventStart(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec LoadEventEnd() const { @@ -356,7 +363,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetLoadEventEnd(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToNonBlankPaint() const { @@ -365,7 +373,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetTimeToNonBlankPaint(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToContentfulPaint() const { @@ -374,7 +383,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetTimeToContentfulComposite(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToDOMContentFlushed() const { @@ -383,7 +393,8 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetTimeToDOMContentFlushed(), - mPerformance->GetRandomTimelineSeed(), mPerformance->RTPCallerType()); + mPerformance->GetRandomTimelineSeed(), + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } DOMTimeMilliSec TimeToFirstInteractive() const { @@ -392,7 +403,7 @@ class PerformanceTiming final : public nsWrapperCache { } return nsRFPService::ReduceTimePrecisionAsMSecs( GetDOMTiming()->GetTimeToTTFI(), mPerformance->GetRandomTimelineSeed(), - mPerformance->RTPCallerType()); + mPerformance->IsSystemPrincipal(), mPerformance->CrossOriginIsolated()); } PerformanceTimingData* Data() const { return mTimingData.get(); } diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp index 2b17cf2345b7..4940a530ae4d 100644 --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -11,10 +11,10 @@ namespace mozilla::dom { PerformanceWorker::PerformanceWorker(WorkerPrivate* aWorkerPrivate) - : Performance(aWorkerPrivate->GlobalScope()), + : Performance(aWorkerPrivate->GlobalScope(), + aWorkerPrivate->UsesSystemPrincipal()), mWorkerPrivate(aWorkerPrivate) { mWorkerPrivate->AssertIsOnWorkerThread(); - mRTPCallerType = aWorkerPrivate->GlobalScope()->RTPCallerType(); } PerformanceWorker::~PerformanceWorker() { diff --git a/dom/script/ShadowRealmGlobalScope.h b/dom/script/ShadowRealmGlobalScope.h index 927c69db5fce..80729c72c451 100644 --- a/dom/script/ShadowRealmGlobalScope.h +++ b/dom/script/ShadowRealmGlobalScope.h @@ -12,7 +12,6 @@ #include "mozilla/Maybe.h" #include "mozilla/OriginTrials.h" #include "mozilla/dom/BindingDeclarations.h" -#include "nsContentUtils.h" #include "nsIGlobalObject.h" #include "nsWrapperCache.h" @@ -55,12 +54,6 @@ class ShadowRealmGlobalScope : public nsIGlobalObject, public nsWrapperCache { JS::loader::ModuleLoaderBase* GetModuleLoader(JSContext* aCx) override; - bool ShouldResistFingerprinting() const override { - return nsContentUtils::ShouldResistFingerprinting( - "Presently we don't have enough context to make an informed decision" - "on JS Sandboxes. See 1782853"); - } - private: virtual ~ShadowRealmGlobalScope() = default; diff --git a/dom/workers/WorkerNavigator.cpp b/dom/workers/WorkerNavigator.cpp index c69ab250fe55..32585e42edd7 100644 --- a/dom/workers/WorkerNavigator.cpp +++ b/dom/workers/WorkerNavigator.cpp @@ -157,21 +157,13 @@ void WorkerNavigator::GetPlatform(nsString& aPlatform, CallerType aCallerType, namespace { -/* - * This Worker Runnable needs to check RFP; but our standard way of doing so - * relies on accessing GlobalScope() - which can only be accessed on the worker - * thread. So we need to pass it in. - */ class GetUserAgentRunnable final : public WorkerMainThreadRunnable { nsString& mUA; - bool mShouldResistFingerprinting; public: - GetUserAgentRunnable(WorkerPrivate* aWorkerPrivate, nsString& aUA, - bool aShouldResistFingerprinting) + GetUserAgentRunnable(WorkerPrivate* aWorkerPrivate, nsString& aUA) : WorkerMainThreadRunnable(aWorkerPrivate, "UserAgent getter"_ns), - mUA(aUA), - mShouldResistFingerprinting(aShouldResistFingerprinting) { + mUA(aUA) { MOZ_ASSERT(aWorkerPrivate); aWorkerPrivate->AssertIsOnWorkerThread(); } @@ -181,9 +173,11 @@ class GetUserAgentRunnable final : public WorkerMainThreadRunnable { nsCOMPtr window = mWorkerPrivate->GetWindow(); + bool shouldResistFingerprinting = + mWorkerPrivate->ShouldResistFingerprinting(); nsresult rv = dom::Navigator::GetUserAgent(window, mWorkerPrivate->GetDocument(), - Some(mShouldResistFingerprinting), mUA); + Some(shouldResistFingerprinting), mUA); if (NS_FAILED(rv)) { NS_WARNING("Failed to retrieve user-agent from the worker thread."); } @@ -199,9 +193,8 @@ void WorkerNavigator::GetUserAgent(nsString& aUserAgent, CallerType aCallerType, WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); MOZ_ASSERT(workerPrivate); - RefPtr runnable = new GetUserAgentRunnable( - workerPrivate, aUserAgent, - workerPrivate->GlobalScope()->ShouldResistFingerprinting()); + RefPtr runnable = + new GetUserAgentRunnable(workerPrivate, aUserAgent); runnable->Dispatch(Canceling, aRv); } @@ -211,7 +204,7 @@ uint64_t WorkerNavigator::HardwareConcurrency() const { MOZ_ASSERT(rts); WorkerPrivate* aWorkerPrivate = GetCurrentThreadWorkerPrivate(); - bool rfp = aWorkerPrivate->GlobalScope()->ShouldResistFingerprinting(); + bool rfp = aWorkerPrivate->ShouldResistFingerprinting(); return rts->ClampedHardwareConcurrency(rfp); } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 30cbeb4c5628..c117de10c7f0 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -2364,10 +2364,8 @@ WorkerPrivate::WorkerPrivate( // Make timing imprecise in unprivileged code to blunt Spectre timing // attacks. bool clampAndJitterTime = !usesSystemPrincipal; - chromeRealmBehaviors.setClampAndJitterTime(clampAndJitterTime) - .setShouldResistFingerprinting(false); - contentRealmBehaviors.setClampAndJitterTime(clampAndJitterTime) - .setShouldResistFingerprinting(mLoadInfo.mShouldResistFingerprinting); + chromeRealmBehaviors.setClampAndJitterTime(clampAndJitterTime); + contentRealmBehaviors.setClampAndJitterTime(clampAndJitterTime); JS::RealmCreationOptions& chromeCreationOptions = chromeRealmOptions.creationOptions(); @@ -2744,10 +2742,10 @@ nsresult WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow, loadInfo.mOriginAttributes = aParent->GetOriginAttributes(); loadInfo.mServiceWorkersTestingInWindow = aParent->ServiceWorkersTestingInWindow(); + loadInfo.mShouldResistFingerprinting = + aParent->ShouldResistFingerprinting(); loadInfo.mIsThirdPartyContextToTopWindow = aParent->IsThirdPartyContextToTopWindow(); - loadInfo.mShouldResistFingerprinting = - aParent->GlobalScope()->ShouldResistFingerprinting(); loadInfo.mParentController = aParent->GlobalScope()->GetController(); loadInfo.mWatchedByDevTools = aParent->IsWatchedByDevTools(); } else { @@ -5438,18 +5436,15 @@ WorkerGlobalScope* WorkerPrivate::GetOrCreateGlobalScope(JSContext* aCx) { return data->mScope; } - bool rfp = mLoadInfo.mShouldResistFingerprinting; - if (IsSharedWorker()) { - data->mScope = new SharedWorkerGlobalScope(this, CreateClientSource(), - WorkerName(), rfp); + data->mScope = + new SharedWorkerGlobalScope(this, CreateClientSource(), WorkerName()); } else if (IsServiceWorker()) { data->mScope = new ServiceWorkerGlobalScope( - this, CreateClientSource(), GetServiceWorkerRegistrationDescriptor(), - rfp); + this, CreateClientSource(), GetServiceWorkerRegistrationDescriptor()); } else { data->mScope = new DedicatedWorkerGlobalScope(this, CreateClientSource(), - WorkerName(), rfp); + WorkerName()); } JS::Rooted global(aCx); @@ -5477,10 +5472,8 @@ WorkerDebuggerGlobalScope* WorkerPrivate::CreateDebuggerGlobalScope( auto clientSource = ClientManager::CreateSource( GetClientType(), HybridEventTarget(), NullPrincipalInfo()); - bool rfp = false; // The debugger for a worker can exempt RFP; it is not - // client-exposed data->mDebuggerScope = - new WorkerDebuggerGlobalScope(this, std::move(clientSource), rfp); + new WorkerDebuggerGlobalScope(this, std::move(clientSource)); JS::Rooted global(aCx); NS_ENSURE_TRUE(data->mDebuggerScope->WrapGlobalObject(aCx, &global), nullptr); diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 1ba0be2a3415..3d75f364beee 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -891,7 +891,11 @@ class WorkerPrivate final return mLoadInfo.mServiceWorkersTestingInWindow; } - // Determine if the worker was created under a third-party context. + bool ShouldResistFingerprinting() const { + return mLoadInfo.mShouldResistFingerprinting; + } + + // Determin if the worker was created under a third-party context. bool IsThirdPartyContextToTopWindow() const { return mLoadInfo.mIsThirdPartyContextToTopWindow; } diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index ce0fd33ef07c..88d31a2653a9 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -232,12 +232,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WorkerGlobalScopeBase) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) WorkerGlobalScopeBase::WorkerGlobalScopeBase( - WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - bool aShouldResistFingerprinting) + WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource) : mWorkerPrivate(aWorkerPrivate), mClientSource(std::move(aClientSource)), - mSerialEventTarget(aWorkerPrivate->HybridEventTarget()), - mShouldResistFingerprinting(aShouldResistFingerprinting) { + mSerialEventTarget(aWorkerPrivate->HybridEventTarget()) { MOZ_ASSERT(mWorkerPrivate); #ifdef DEBUG mWorkerPrivate->AssertIsOnWorkerThread(); @@ -273,11 +271,7 @@ bool WorkerGlobalScopeBase::IsSharedMemoryAllowed() const { bool WorkerGlobalScopeBase::ShouldResistFingerprinting() const { AssertIsOnWorkerThread(); - return mShouldResistFingerprinting; -} - -bool WorkerGlobalScopeBase::IsSystemPrincipal() const { - return mWorkerPrivate->UsesSystemPrincipal(); + return mWorkerPrivate->ShouldResistFingerprinting(); } uint32_t WorkerGlobalScopeBase::GetPrincipalHashValue() const { @@ -878,9 +872,8 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(DedicatedWorkerGlobalScope, DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope( WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const nsString& aName, bool aShouldResistFingerprinting) - : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource), - aShouldResistFingerprinting), + const nsString& aName) + : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource)), NamedWorkerGlobalScopeMixin(aName) {} bool DedicatedWorkerGlobalScope::WrapGlobalObject( @@ -1035,8 +1028,7 @@ void DedicatedWorkerGlobalScope::OnVsync(const VsyncEvent& aVsync) { // needs to have it's Time Reduction Logic refactored, so it's currently // only clamping for RFP mode. RFP mode gives a much lower time precision, // so we accept the security leak here for now. - timeStamp = nsRFPService::ReduceTimePrecisionAsMSecsRFPOnly( - timeStamp, 0, this->RTPCallerType()); + timeStamp = nsRFPService::ReduceTimePrecisionAsMSecsRFPOnly(timeStamp, 0); } for (auto& callback : callbacks) { @@ -1054,9 +1046,8 @@ void DedicatedWorkerGlobalScope::OnVsync(const VsyncEvent& aVsync) { SharedWorkerGlobalScope::SharedWorkerGlobalScope( WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const nsString& aName, bool aShouldResistFingerprinting) - : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource), - aShouldResistFingerprinting), + const nsString& aName) + : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource)), NamedWorkerGlobalScopeMixin(aName) {} bool SharedWorkerGlobalScope::WrapGlobalObject( @@ -1089,10 +1080,8 @@ NS_IMPL_RELEASE_INHERITED(ServiceWorkerGlobalScope, WorkerGlobalScope) ServiceWorkerGlobalScope::ServiceWorkerGlobalScope( WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor, - bool aShouldResistFingerprinting) - : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource), - aShouldResistFingerprinting), + const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor) + : WorkerGlobalScope(std::move(aWorkerPrivate), std::move(aClientSource)), mScope(NS_ConvertUTF8toUTF16(aRegistrationDescriptor.Scope())) // Eagerly create the registration because we will need to receive diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h index b6d77964770a..f63c5bbbdaa6 100644 --- a/dom/workers/WorkerScope.h +++ b/dom/workers/WorkerScope.h @@ -98,8 +98,7 @@ class WorkerGlobalScopeBase : public DOMEventTargetHelper, DOMEventTargetHelper) WorkerGlobalScopeBase(WorkerPrivate* aWorkerPrivate, - UniquePtr aClientSource, - bool mShouldResistFingerprinting); + UniquePtr aClientSource); virtual bool WrapGlobalObject(JSContext* aCx, JS::MutableHandle aReflector) = 0; @@ -173,8 +172,6 @@ class WorkerGlobalScopeBase : public DOMEventTargetHelper, protected: ~WorkerGlobalScopeBase(); - bool IsSystemPrincipal() const final; - CheckedUnsafePtr mWorkerPrivate; void AssertIsOnWorkerThread() const { @@ -185,7 +182,6 @@ class WorkerGlobalScopeBase : public DOMEventTargetHelper, RefPtr mConsole; const UniquePtr mClientSource; nsCOMPtr mSerialEventTarget; - bool mShouldResistFingerprinting; #ifdef DEBUG PRThread* mWorkerThreadUsedOnlyForAssert; #endif @@ -378,8 +374,7 @@ class DedicatedWorkerGlobalScope final DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const nsString& aName, - bool aShouldResistFingerprinting); + const nsString& aName); bool WrapGlobalObject(JSContext* aCx, JS::MutableHandle aReflector) override; @@ -423,8 +418,7 @@ class SharedWorkerGlobalScope final public: SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const nsString& aName, - bool aShouldResistFingerprinting); + const nsString& aName); bool WrapGlobalObject(JSContext* aCx, JS::MutableHandle aReflector) override; @@ -445,8 +439,7 @@ class ServiceWorkerGlobalScope final : public WorkerGlobalScope { ServiceWorkerGlobalScope( WorkerPrivate* aWorkerPrivate, UniquePtr aClientSource, - const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor, - bool aShouldResistFingerprinting); + const ServiceWorkerRegistrationDescriptor& aRegistrationDescriptor); bool WrapGlobalObject(JSContext* aCx, JS::MutableHandle aReflector) override; diff --git a/dom/worklet/WorkletGlobalScope.cpp b/dom/worklet/WorkletGlobalScope.cpp index 484e5d70735e..501fb2b1dd1e 100644 --- a/dom/worklet/WorkletGlobalScope.cpp +++ b/dom/worklet/WorkletGlobalScope.cpp @@ -72,14 +72,6 @@ bool WorkletGlobalScope::IsSharedMemoryAllowed() const { return mImpl->IsSharedMemoryAllowed(); } -bool WorkletGlobalScope::ShouldResistFingerprinting() const { - return mImpl->ShouldResistFingerprinting(); -} - -bool WorkletGlobalScope::IsSystemPrincipal() const { - return mImpl->IsSystemPrincipal(); -} - void WorkletGlobalScope::Dump(const Optional& aString) const { WorkletThread::AssertIsOnWorkletThread(); diff --git a/dom/worklet/WorkletGlobalScope.h b/dom/worklet/WorkletGlobalScope.h index 3d34e2c81370..0ff627159640 100644 --- a/dom/worklet/WorkletGlobalScope.h +++ b/dom/worklet/WorkletGlobalScope.h @@ -68,13 +68,10 @@ class WorkletGlobalScope : public nsIGlobalObject, public nsWrapperCache { OriginTrials Trials() const override; Maybe GetAgentClusterId() const override; bool IsSharedMemoryAllowed() const override; - bool ShouldResistFingerprinting() const override; protected: ~WorkletGlobalScope(); - bool IsSystemPrincipal() const override; - const RefPtr mImpl; private: diff --git a/dom/worklet/WorkletImpl.cpp b/dom/worklet/WorkletImpl.cpp index 8f100f1979af..cccc1d04aee7 100644 --- a/dom/worklet/WorkletImpl.cpp +++ b/dom/worklet/WorkletImpl.cpp @@ -39,7 +39,6 @@ WorkletLoadInfo::WorkletLoadInfo(nsPIDOMWindowInner* aWindow) WorkletImpl::WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal) : mPrincipal(NullPrincipal::CreateWithInheritedAttributes(aPrincipal)), - mIsSystemPrincipal(mPrincipal->IsSystemPrincipal()), mWorkletLoadInfo(aWindow), mTerminated(false), mFinishedOnExecutionThread(false), @@ -53,9 +52,6 @@ WorkletImpl::WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal) mSharedMemoryAllowed = nsGlobalWindowInner::Cast(aWindow)->IsSharedMemoryAllowed(); - - mShouldResistFingerprinting = - aWindow->AsGlobal()->ShouldResistFingerprinting(); } WorkletImpl::~WorkletImpl() { diff --git a/dom/worklet/WorkletImpl.h b/dom/worklet/WorkletImpl.h index e495584a807b..39bc9c46f4c3 100644 --- a/dom/worklet/WorkletImpl.h +++ b/dom/worklet/WorkletImpl.h @@ -82,10 +82,6 @@ class WorkletImpl { const Maybe& GetAgentClusterId() const { return mAgentClusterId; } bool IsSharedMemoryAllowed() const { return mSharedMemoryAllowed; } - bool IsSystemPrincipal() const { return mIsSystemPrincipal; } - bool ShouldResistFingerprinting() const { - return mShouldResistFingerprinting; - } virtual void OnAddModuleStarted() const { MOZ_ASSERT(NS_IsMainThread()); @@ -107,8 +103,6 @@ class WorkletImpl { ipc::PrincipalInfo mPrincipalInfo; // Accessed on only worklet parent thread. nsCOMPtr mPrincipal; - // For off-main-thread checks - bool mIsSystemPrincipal; const WorkletLoadInfo mWorkletLoadInfo; @@ -123,7 +117,6 @@ class WorkletImpl { Maybe mAgentClusterId; bool mSharedMemoryAllowed; - bool mShouldResistFingerprinting; const OriginTrials mTrials; }; diff --git a/js/public/Date.h b/js/public/Date.h index cd641a54d9f9..bb69d58dc96e 100644 --- a/js/public/Date.h +++ b/js/public/Date.h @@ -186,12 +186,10 @@ JS_PUBLIC_API double DayFromYear(double year); // |JS::DayFromYear(time)|. JS_PUBLIC_API double DayWithinYear(double time, double year); -// The callback will be a wrapper function that accepts a double (the time -// to clamp and jitter) as well as a bool indicating if we should be resisting -// fingerprinting. Inside the JS Engine, other parameters that may be +// The callback will be a wrapper function that accepts a single double (the +// time to clamp and jitter.) Inside the JS Engine, other parameters that may be // needed are all constant, so they are handled inside the wrapper function -using ReduceMicrosecondTimePrecisionCallback = double (*)(double, bool, - JSContext*); +using ReduceMicrosecondTimePrecisionCallback = double (*)(double, JSContext*); // Set a callback into the toolkit/components/resistfingerprinting function that // will centralize time resolution and jitter into one place. diff --git a/js/public/RealmOptions.h b/js/public/RealmOptions.h index 437aaec4b182..58c2405a142a 100644 --- a/js/public/RealmOptions.h +++ b/js/public/RealmOptions.h @@ -313,14 +313,6 @@ class JS_PUBLIC_API RealmBehaviors { return *this; } - bool shouldResistFingerprinting() const { - return shouldResistFingerprinting_; - } - RealmBehaviors& setShouldResistFingerprinting(bool flag) { - shouldResistFingerprinting_ = flag; - return *this; - } - class Override { public: Override() : mode_(Default) {} @@ -356,7 +348,6 @@ class JS_PUBLIC_API RealmBehaviors { private: bool discardSource_ = false; bool clampAndJitterTime_ = true; - bool shouldResistFingerprinting_ = false; bool isNonLive_ = false; }; diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index 2183cbbb819b..a873f358b8fc 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -1536,11 +1536,8 @@ static ClippedTime NowAsMillis(JSContext* cx) { double now = PRMJ_Now(); bool clampAndJitter = cx->realm()->behaviors().clampAndJitterTime(); - bool shouldResistFingerprinting = - cx->realm()->behaviors().shouldResistFingerprinting(); if (clampAndJitter && sReduceMicrosecondTimePrecisionCallback) { - now = sReduceMicrosecondTimePrecisionCallback( - now, shouldResistFingerprinting, cx); + now = sReduceMicrosecondTimePrecisionCallback(now, cx); } else if (clampAndJitter && sResolutionUsec) { double clamped = floor(now / sResolutionUsec) * sResolutionUsec; diff --git a/js/xpconnect/src/BackstagePass.h b/js/xpconnect/src/BackstagePass.h index 018e15b23ac2..586a842260da 100644 --- a/js/xpconnect/src/BackstagePass.h +++ b/js/xpconnect/src/BackstagePass.h @@ -8,7 +8,6 @@ #define BackstagePass_h__ #include "js/loader/ModuleLoaderBase.h" -#include "mozilla/BasePrincipal.h" #include "mozilla/StorageAccess.h" #include "nsISupports.h" #include "nsWeakReference.h" @@ -68,12 +67,6 @@ class BackstagePass final : public nsIGlobalObject, mModuleLoader = aModuleLoader; } - bool ShouldResistFingerprinting() const override { - // BackstagePass is always the System Principal - MOZ_RELEASE_ASSERT(mPrincipal->IsSystemPrincipal()); - return false; - } - private: virtual ~BackstagePass() = default; diff --git a/js/xpconnect/src/SandboxPrivate.h b/js/xpconnect/src/SandboxPrivate.h index 3ae04ae8dbf3..40a54532238d 100644 --- a/js/xpconnect/src/SandboxPrivate.h +++ b/js/xpconnect/src/SandboxPrivate.h @@ -11,7 +11,6 @@ #include "mozilla/StaticPrefs_dom.h" #include "mozilla/StorageAccess.h" #include "mozilla/net/CookieJarSettings.h" -#include "nsContentUtils.h" #include "nsIGlobalObject.h" #include "nsIScriptObjectPrincipal.h" #include "nsIPrincipal.h" @@ -97,12 +96,6 @@ class SandboxPrivate : public nsIGlobalObject, return 0; } - bool ShouldResistFingerprinting() const override { - return nsContentUtils::ShouldResistFingerprinting( - "Presently we don't have enough context to make an informed decision" - "on JS Sandboxes. See 1782853"); - } - private: explicit SandboxPrivate(nsIPrincipal* principal) : mPrincipal(principal) {} diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index e91311f7c0fe..cec04013b53e 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -477,22 +477,23 @@ JSObject* CreateGlobalObject(JSContext* cx, const JSClass* clasp, } void InitGlobalObjectOptions(JS::RealmOptions& aOptions, - bool aIsSystemPrincipal, - bool aShouldResistFingerprinting) { + nsIPrincipal* aPrincipal) { bool shouldDiscardSystemSource = ShouldDiscardSystemSource(); - if (aIsSystemPrincipal) { + bool isSystem = aPrincipal->IsSystemPrincipal(); + + if (isSystem) { // Make toSource functions [ChromeOnly] aOptions.creationOptions().setToSourceEnabled(true); // Make sure [SecureContext] APIs are visible: aOptions.creationOptions().setSecureContext(true); aOptions.behaviors().setClampAndJitterTime(false); } - aOptions.behaviors().setShouldResistFingerprinting( - aShouldResistFingerprinting); if (shouldDiscardSystemSource) { - aOptions.behaviors().setDiscardSource(aIsSystemPrincipal); + bool discardSource = isSystem; + + aOptions.behaviors().setDiscardSource(discardSource); } } @@ -536,13 +537,8 @@ nsresult InitClassesWithNewWrappedGlobal(JSContext* aJSContext, // We pass null for the 'extra' pointer during global object creation, so // we need to have a principal. MOZ_ASSERT(aPrincipal); - // All uses (at time of writing) were System Principal, meaning - // aShouldResistFingerprinting can be hardcoded to false. - // If this changes, ShouldRFP needs to be updated accordingly. - MOZ_RELEASE_ASSERT(aPrincipal->IsSystemPrincipal()); - InitGlobalObjectOptions(aOptions, /* aSystemPrincipal */ true, - /* aShouldResistFingerprinting */ false); + InitGlobalObjectOptions(aOptions, aPrincipal); // Call into XPCWrappedNative to make a new global object, scope, and global // prototype. diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index cf0079336946..42990756babe 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -2424,8 +2424,7 @@ JSObject* CreateGlobalObject(JSContext* cx, const JSClass* clasp, // you can't get a *mutable* JS::RealmOptions& from an existing global // object.) void InitGlobalObjectOptions(JS::RealmOptions& aOptions, - bool aIsSystemPrincipal, - bool aShouldResistFingerprinting); + nsIPrincipal* aPrincipal); // Finish initializing an already-created, not-yet-exposed-to-script global // object. This will attach a Components object (if necessary) and call diff --git a/layout/style/PaintWorkletGlobalScope.cpp b/layout/style/PaintWorkletGlobalScope.cpp index 525a5d1d2a5f..22e251bd7da0 100644 --- a/layout/style/PaintWorkletGlobalScope.cpp +++ b/layout/style/PaintWorkletGlobalScope.cpp @@ -24,9 +24,6 @@ bool PaintWorkletGlobalScope::WrapGlobalObject( JSContext* aCx, JS::MutableHandle aReflector) { JS::RealmOptions options; - options.behaviors().setShouldResistFingerprinting( - ShouldResistFingerprinting()); - // The SharedArrayBuffer global constructor property should not be present in // a fresh global object when shared memory objects aren't allowed (because // COOP/COEP support isn't enabled, or because COOP/COEP don't act to isolate diff --git a/toolkit/components/resistfingerprinting/nsRFPService.cpp b/toolkit/components/resistfingerprinting/nsRFPService.cpp index 9be0b7024ead..72edfa2f347a 100644 --- a/toolkit/components/resistfingerprinting/nsRFPService.cpp +++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp @@ -171,10 +171,10 @@ minutes, I'm impressed, and we might revisit this. */ /* static */ -double nsRFPService::TimerResolution(RTPCallerType aRTPCallerType) { +double nsRFPService::TimerResolution() { double prefValue = StaticPrefs:: privacy_resistFingerprinting_reduceTimerPrecision_microseconds(); - if (aRTPCallerType == RTPCallerType::ResistFingerprinting) { + if (StaticPrefs::privacy_resistFingerprinting()) { return std::max(RFP_TIME_ATOM_MS * 1000.0, prefValue); } return prefValue; @@ -447,69 +447,66 @@ double nsRFPService::ReduceTimePrecisionImpl(double aTime, TimeScale aTimeScale, /* static */ double nsRFPService::ReduceTimePrecisionAsUSecs(double aTime, int64_t aContextMixin, - RTPCallerType aRTPCallerType) { - const auto type = GetTimerPrecisionType(aRTPCallerType); - return nsRFPService::ReduceTimePrecisionImpl(aTime, MicroSeconds, - TimerResolution(aRTPCallerType), - aContextMixin, type); + bool aIsSystemPrincipal, + bool aCrossOriginIsolated) { + const auto type = + GetTimerPrecisionType(aIsSystemPrincipal, aCrossOriginIsolated); + return nsRFPService::ReduceTimePrecisionImpl( + aTime, MicroSeconds, TimerResolution(), aContextMixin, type); } /* static */ double nsRFPService::ReduceTimePrecisionAsMSecs(double aTime, int64_t aContextMixin, - RTPCallerType aRTPCallerType) { - const auto type = GetTimerPrecisionType(aRTPCallerType); - return nsRFPService::ReduceTimePrecisionImpl(aTime, MilliSeconds, - TimerResolution(aRTPCallerType), - aContextMixin, type); + bool aIsSystemPrincipal, + bool aCrossOriginIsolated) { + const auto type = + GetTimerPrecisionType(aIsSystemPrincipal, aCrossOriginIsolated); + return nsRFPService::ReduceTimePrecisionImpl( + aTime, MilliSeconds, TimerResolution(), aContextMixin, type); } /* static */ -double nsRFPService::ReduceTimePrecisionAsMSecsRFPOnly( - double aTime, int64_t aContextMixin, RTPCallerType aRTPCallerType) { - return nsRFPService::ReduceTimePrecisionImpl( - aTime, MilliSeconds, TimerResolution(aRTPCallerType), aContextMixin, - GetTimerPrecisionTypeRFPOnly(aRTPCallerType)); +double nsRFPService::ReduceTimePrecisionAsMSecsRFPOnly(double aTime, + int64_t aContextMixin) { + return nsRFPService::ReduceTimePrecisionImpl(aTime, MilliSeconds, + TimerResolution(), aContextMixin, + GetTimerPrecisionTypeRFPOnly()); } /* static */ double nsRFPService::ReduceTimePrecisionAsSecs(double aTime, int64_t aContextMixin, - RTPCallerType aRTPCallerType) { - const auto type = GetTimerPrecisionType(aRTPCallerType); + bool aIsSystemPrincipal, + bool aCrossOriginIsolated) { + const auto type = + GetTimerPrecisionType(aIsSystemPrincipal, aCrossOriginIsolated); return nsRFPService::ReduceTimePrecisionImpl( - aTime, Seconds, TimerResolution(aRTPCallerType), aContextMixin, type); + aTime, Seconds, TimerResolution(), aContextMixin, type); } /* static */ -double nsRFPService::ReduceTimePrecisionAsSecsRFPOnly( - double aTime, int64_t aContextMixin, RTPCallerType aRTPCallerType) { - return nsRFPService::ReduceTimePrecisionImpl( - aTime, Seconds, TimerResolution(aRTPCallerType), aContextMixin, - GetTimerPrecisionTypeRFPOnly(aRTPCallerType)); +double nsRFPService::ReduceTimePrecisionAsSecsRFPOnly(double aTime, + int64_t aContextMixin) { + return nsRFPService::ReduceTimePrecisionImpl(aTime, Seconds, + TimerResolution(), aContextMixin, + GetTimerPrecisionTypeRFPOnly()); } /* static */ -double nsRFPService::ReduceTimePrecisionAsUSecsWrapper( - double aTime, bool aShouldResistFingerprinting, JSContext* aCx) { +double nsRFPService::ReduceTimePrecisionAsUSecsWrapper(double aTime, + JSContext* aCx) { MOZ_ASSERT(aCx); nsCOMPtr global = xpc::CurrentNativeGlobal(aCx); MOZ_ASSERT(global); - - RTPCallerType callerType; - if (aShouldResistFingerprinting) { - callerType = RTPCallerType::ResistFingerprinting; - } else if (global->CrossOriginIsolated()) { - callerType = RTPCallerType::CrossOriginIsolated; - } else { - callerType = RTPCallerType::Normal; - } + const auto type = GetTimerPrecisionType(/* aIsSystemPrincipal */ false, + global->CrossOriginIsolated()); return nsRFPService::ReduceTimePrecisionImpl( - aTime, MicroSeconds, TimerResolution(callerType), + aTime, MicroSeconds, TimerResolution(), 0, /* For absolute timestamps (all the JS engine does), supply zero context mixin */ - GetTimerPrecisionType(callerType)); + type); } /* static */ @@ -519,8 +516,7 @@ uint32_t nsRFPService::CalculateTargetVideoResolution(uint32_t aVideoQuality) { /* static */ uint32_t nsRFPService::GetSpoofedTotalFrames(double aTime) { - double precision = - TimerResolution(RTPCallerType::ResistFingerprinting) / 1000 / 1000; + double precision = TimerResolution() / 1000 / 1000; double time = floor(aTime / precision) * precision; return NSToIntFloor(time * kVideoFramesPerSec); @@ -538,8 +534,7 @@ uint32_t nsRFPService::GetSpoofedDroppedFrames(double aTime, uint32_t aWidth, return 0; } - double precision = - TimerResolution(RTPCallerType::ResistFingerprinting) / 1000 / 1000; + double precision = TimerResolution() / 1000 / 1000; double time = floor(aTime / precision) * precision; // Bound the dropped ratio from 0 to 100. uint32_t boundedDroppedRatio = std::min(kVideoDroppedRatio, 100U); @@ -560,8 +555,7 @@ uint32_t nsRFPService::GetSpoofedPresentedFrames(double aTime, uint32_t aWidth, return GetSpoofedTotalFrames(aTime); } - double precision = - TimerResolution(RTPCallerType::ResistFingerprinting) / 1000 / 1000; + double precision = TimerResolution() / 1000 / 1000; double time = floor(aTime / precision) * precision; // Bound the dropped ratio from 0 to 100. uint32_t boundedDroppedRatio = std::min(kVideoDroppedRatio, 100U); @@ -663,17 +657,37 @@ nsresult nsRFPService::Init() { return rv; } +// This function updates only timing-related fingerprinting items +void nsRFPService::UpdateTimers() { + MOZ_ASSERT(NS_IsMainThread()); + + if (StaticPrefs::privacy_resistFingerprinting() || + StaticPrefs::privacy_reduceTimerPrecision()) { + JS::SetTimeResolutionUsec( + TimerResolution(), + StaticPrefs:: + privacy_resistFingerprinting_reduceTimerPrecision_jitter()); + JS::SetReduceMicrosecondTimePrecisionCallback( + nsRFPService::ReduceTimePrecisionAsUSecsWrapper); + } else if (StaticPrefs::privacy_reduceTimerPrecision_unconditional()) { + JS::SetTimeResolutionUsec(RFP_TIMER_UNCONDITIONAL_VALUE, false); + JS::SetReduceMicrosecondTimePrecisionCallback( + nsRFPService::ReduceTimePrecisionAsUSecsWrapper); + } else if (sInitialized) { + JS::SetTimeResolutionUsec(0, false); + } +} + // This function updates every fingerprinting item necessary except // timing-related void nsRFPService::UpdateRFPPref() { MOZ_ASSERT(NS_IsMainThread()); + UpdateTimers(); + bool privacyResistFingerprinting = StaticPrefs::privacy_resistFingerprinting(); - JS::SetReduceMicrosecondTimePrecisionCallback( - nsRFPService::ReduceTimePrecisionAsUSecsWrapper); - // set fdlibm pref JS::SetUseFdlibmForSinCosTan( StaticPrefs::javascript_options_use_fdlibm_for_sin_cos_tan() || @@ -951,17 +965,16 @@ bool nsRFPService::GetSpoofedKeyCode(const dom::Document* aDoc, /* static */ TimerPrecisionType nsRFPService::GetTimerPrecisionType( - RTPCallerType aRTPCallerType) { - if (aRTPCallerType == RTPCallerType::SystemPrincipal) { + bool aIsSystemPrincipal, bool aCrossOriginIsolated) { + if (aIsSystemPrincipal) { return DangerouslyNone; } - if (aRTPCallerType == RTPCallerType::ResistFingerprinting) { + if (StaticPrefs::privacy_resistFingerprinting()) { return RFP; } - if (StaticPrefs::privacy_reduceTimerPrecision() && - aRTPCallerType == RTPCallerType::CrossOriginIsolated) { + if (StaticPrefs::privacy_reduceTimerPrecision() && aCrossOriginIsolated) { return UnconditionalAKAHighRes; } @@ -977,14 +990,12 @@ TimerPrecisionType nsRFPService::GetTimerPrecisionType( } /* static */ -TimerPrecisionType nsRFPService::GetTimerPrecisionTypeRFPOnly( - RTPCallerType aRTPCallerType) { - if (aRTPCallerType == RTPCallerType::ResistFingerprinting) { +TimerPrecisionType nsRFPService::GetTimerPrecisionTypeRFPOnly() { + if (StaticPrefs::privacy_resistFingerprinting()) { return RFP; } - if (StaticPrefs::privacy_reduceTimerPrecision_unconditional() && - aRTPCallerType != RTPCallerType::SystemPrincipal) { + if (StaticPrefs::privacy_reduceTimerPrecision_unconditional()) { return UnconditionalAKAHighRes; } @@ -1021,7 +1032,12 @@ void nsRFPService::PrefChanged(const char* aPref, void* aSelf) { void nsRFPService::PrefChanged(const char* aPref) { nsDependentCString pref(aPref); - if (pref.EqualsLiteral(RESIST_FINGERPRINTING_PREF)) { + if (pref.EqualsLiteral(RFP_TIMER_PREF) || + pref.EqualsLiteral(RFP_TIMER_UNCONDITIONAL_PREF) || + pref.EqualsLiteral(RFP_TIMER_VALUE_PREF) || + pref.EqualsLiteral(RFP_JITTER_VALUE_PREF)) { + UpdateTimers(); + } else if (pref.EqualsLiteral(RESIST_FINGERPRINTING_PREF)) { UpdateRFPPref(); #if defined(XP_WIN) diff --git a/toolkit/components/resistfingerprinting/nsRFPService.h b/toolkit/components/resistfingerprinting/nsRFPService.h index 5081c385736b..7b9b6de5bc17 100644 --- a/toolkit/components/resistfingerprinting/nsRFPService.h +++ b/toolkit/components/resistfingerprinting/nsRFPService.h @@ -10,9 +10,7 @@ #include "ErrorList.h" #include "PLDHashTable.h" #include "mozilla/BasicEvents.h" -#include "nsContentUtils.h" #include "nsHashtablesFwd.h" -#include "nsIGlobalObject.h" #include "nsIObserver.h" #include "nsISupports.h" #include "nsStringFwd.h" @@ -136,27 +134,27 @@ class nsRFPService final : public nsIObserver { NS_DECL_NSIOBSERVER static nsRFPService* GetOrCreate(); - static double TimerResolution(RTPCallerType aRTPCallerType); + static double TimerResolution(); enum TimeScale { Seconds = 1, MilliSeconds = 1000, MicroSeconds = 1000000 }; // The following Reduce methods can be called off main thread. static double ReduceTimePrecisionAsUSecs(double aTime, int64_t aContextMixin, - RTPCallerType aRTPCallerType); + bool aIsSystemPrincipal, + bool aCrossOriginIsolated); static double ReduceTimePrecisionAsMSecs(double aTime, int64_t aContextMixin, - RTPCallerType aRTPCallerType); + bool aIsSystemPrincipal, + bool aCrossOriginIsolated); static double ReduceTimePrecisionAsMSecsRFPOnly(double aTime, - int64_t aContextMixin, - RTPCallerType aRTPCallerType); + int64_t aContextMixin); static double ReduceTimePrecisionAsSecs(double aTime, int64_t aContextMixin, - RTPCallerType aRTPCallerType); + bool aIsSystemPrincipal, + bool aCrossOriginIsolated); static double ReduceTimePrecisionAsSecsRFPOnly(double aTime, - int64_t aContextMixin, - RTPCallerType aRTPCallerType); + int64_t aContextMixin); // Used by the JS Engine, as it doesn't know about the TimerPrecisionType enum - static double ReduceTimePrecisionAsUSecsWrapper( - double aTime, bool aShouldResistFingerprinting, JSContext* aCx); + static double ReduceTimePrecisionAsUSecsWrapper(double aTime, JSContext* aCx); // Public only for testing purposes static double ReduceTimePrecisionImpl(double aTime, TimeScale aTimeScale, @@ -234,6 +232,7 @@ class nsRFPService final : public nsIObserver { ~nsRFPService() = default; + void UpdateTimers(); void UpdateRFPPref(); void StartShutdown(); @@ -254,10 +253,10 @@ class nsRFPService final : public nsIObserver { static nsTHashMap* sSpoofingKeyboardCodes; - static TimerPrecisionType GetTimerPrecisionType(RTPCallerType aRTPCallerType); + static TimerPrecisionType GetTimerPrecisionType(bool aIsSystemPrincipal, + bool aCrossOriginIsolated); - static TimerPrecisionType GetTimerPrecisionTypeRFPOnly( - RTPCallerType aRTPCallerType); + static TimerPrecisionType GetTimerPrecisionTypeRFPOnly(); static void TypeToText(TimerPrecisionType aType, nsACString& aText);