зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1614743, convert about:protections to the new JSWindowActor-based remote page manager and remove now unused functions from the old RPM, r=johannh
Differential Revision: https://phabricator.services.mozilla.com/D71022
This commit is contained in:
Родитель
14879e2fe7
Коммит
e87cb94596
|
@ -0,0 +1,29 @@
|
|||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
var EXPORTED_SYMBOLS = ["AboutProtectionsChild"];
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const { RemotePageChild } = ChromeUtils.import(
|
||||
"resource://gre/actors/RemotePageChild.jsm"
|
||||
);
|
||||
|
||||
class AboutProtectionsChild extends RemotePageChild {
|
||||
actorCreated() {
|
||||
super.actorCreated();
|
||||
|
||||
this.exportFunctions(["RPMRecordTelemetryEvent"]);
|
||||
}
|
||||
|
||||
RPMRecordTelemetryEvent(category, event, object, value, extra) {
|
||||
return Services.telemetry.recordEvent(
|
||||
category,
|
||||
event,
|
||||
object,
|
||||
value,
|
||||
extra
|
||||
);
|
||||
}
|
||||
}
|
|
@ -6,13 +6,10 @@
|
|||
|
||||
Cu.importGlobalProperties(["fetch"]);
|
||||
|
||||
var EXPORTED_SYMBOLS = ["AboutProtectionsHandler"];
|
||||
var EXPORTED_SYMBOLS = ["AboutProtectionsParent"];
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
);
|
||||
const { RemotePages } = ChromeUtils.import(
|
||||
"resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm"
|
||||
);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
|
@ -59,44 +56,19 @@ const UNKNOWN_ERROR = "Unknown error";
|
|||
// Valid response info for successful Monitor data
|
||||
const MONITOR_RESPONSE_PROPS = ["monitoredEmails", "numBreaches", "passwords"];
|
||||
|
||||
var AboutProtectionsHandler = {
|
||||
_inited: false,
|
||||
monitorResponse: null,
|
||||
_topics: [
|
||||
"ClearMonitorCache",
|
||||
// Opening about:* pages
|
||||
"OpenAboutLogins",
|
||||
"OpenContentBlockingPreferences",
|
||||
"OpenSyncPreferences",
|
||||
// Fetching data
|
||||
"FetchContentBlockingEvents",
|
||||
"FetchMonitorData",
|
||||
"FetchUserLoginsData",
|
||||
"GetShowProxyCard",
|
||||
],
|
||||
let gTestOverride = null;
|
||||
|
||||
init() {
|
||||
this.receiveMessage = this.receiveMessage.bind(this);
|
||||
this.pageListener = new RemotePages("about:protections");
|
||||
for (let topic of this._topics) {
|
||||
this.pageListener.addMessageListener(topic, this.receiveMessage);
|
||||
}
|
||||
Services.telemetry.setEventRecordingEnabled(
|
||||
"security.ui.protections",
|
||||
true
|
||||
);
|
||||
this._inited = true;
|
||||
},
|
||||
class AboutProtectionsParent extends JSWindowActorParent {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
uninit() {
|
||||
if (!this._inited) {
|
||||
return;
|
||||
}
|
||||
for (let topic of this._topics) {
|
||||
this.pageListener.removeMessageListener(topic, this.receiveMessage);
|
||||
}
|
||||
this.pageListener.destroy();
|
||||
},
|
||||
this.monitorResponse = null;
|
||||
}
|
||||
|
||||
// Some tests wish to override certain functions with ones that mostly do nothing.
|
||||
static setTestOverride(callback) {
|
||||
gTestOverride = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches and validates data from the Monitor endpoint. If successful, then return
|
||||
|
@ -162,7 +134,7 @@ var AboutProtectionsHandler = {
|
|||
throw this.monitorResponse;
|
||||
}
|
||||
return this.monitorResponse;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves login data for the user.
|
||||
|
@ -174,6 +146,10 @@ var AboutProtectionsHandler = {
|
|||
* The login data.
|
||||
*/
|
||||
async getLoginData() {
|
||||
if (gTestOverride && "getLoginData" in gTestOverride) {
|
||||
return gTestOverride.getLoginData();
|
||||
}
|
||||
|
||||
let hasFxa = false;
|
||||
|
||||
try {
|
||||
|
@ -202,7 +178,7 @@ var AboutProtectionsHandler = {
|
|||
: 0,
|
||||
mobileDeviceConnected,
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves monitor data for the user.
|
||||
|
@ -216,6 +192,10 @@ var AboutProtectionsHandler = {
|
|||
* Monitor data.
|
||||
*/
|
||||
async getMonitorData() {
|
||||
if (gTestOverride && "getMonitorData" in gTestOverride) {
|
||||
return gTestOverride.getMonitorData();
|
||||
}
|
||||
|
||||
let monitorData = {};
|
||||
let potentiallyBreachedLogins = null;
|
||||
let userEmail = null;
|
||||
|
@ -277,7 +257,7 @@ var AboutProtectionsHandler = {
|
|||
: 0,
|
||||
error: !!monitorData.errorMessage,
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
async getMonitorScopedOAuthToken() {
|
||||
let token = null;
|
||||
|
@ -292,7 +272,7 @@ var AboutProtectionsHandler = {
|
|||
}
|
||||
|
||||
return token;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* The proxy card will only show if the user is in the US, has the browser language in "en-US",
|
||||
|
@ -313,27 +293,10 @@ var AboutProtectionsHandler = {
|
|||
!alreadyInstalled &&
|
||||
languages.data.toLowerCase().includes("en-us")
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends a response from message target.
|
||||
*
|
||||
* @param {Object} target
|
||||
* The message target.
|
||||
* @param {String} message
|
||||
* The topic of the message to send.
|
||||
* @param {Object} payload
|
||||
* The payload of the message to send.
|
||||
*/
|
||||
sendMessage(target, message, payload) {
|
||||
// Make sure the target's browser is available before sending.
|
||||
if (target.browser) {
|
||||
target.sendAsyncMessage(message, payload);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
async receiveMessage(aMessage) {
|
||||
let win = aMessage.target.browser.ownerGlobal;
|
||||
let win = this.browsingContext.top.embedderElement.ownerGlobal;
|
||||
switch (aMessage.name) {
|
||||
case "OpenAboutLogins":
|
||||
LoginHelper.openPasswordManager(win, {
|
||||
|
@ -368,12 +331,7 @@ var AboutProtectionsHandler = {
|
|||
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(win)) {
|
||||
dataToSend.isPrivate = true;
|
||||
this.sendMessage(
|
||||
aMessage.target,
|
||||
"SendContentBlockingRecords",
|
||||
dataToSend
|
||||
);
|
||||
return;
|
||||
return dataToSend;
|
||||
}
|
||||
let sumEvents = await TrackingDBService.sumAllEvents();
|
||||
let earliestDate = await TrackingDBService.getEarliestRecordedDate();
|
||||
|
@ -400,42 +358,23 @@ var AboutProtectionsHandler = {
|
|||
dataToSend.earliestDate = earliestDate;
|
||||
dataToSend.sumEvents = sumEvents;
|
||||
|
||||
this.sendMessage(
|
||||
aMessage.target,
|
||||
"SendContentBlockingRecords",
|
||||
dataToSend
|
||||
);
|
||||
break;
|
||||
return dataToSend;
|
||||
|
||||
case "FetchMonitorData":
|
||||
this.sendMessage(
|
||||
aMessage.target,
|
||||
"SendMonitorData",
|
||||
await this.getMonitorData()
|
||||
);
|
||||
break;
|
||||
return this.getMonitorData();
|
||||
|
||||
case "FetchUserLoginsData":
|
||||
let {
|
||||
hasFxa,
|
||||
numLogins,
|
||||
numSyncedDevices,
|
||||
mobileDeviceConnected,
|
||||
} = await this.getLoginData();
|
||||
this.sendMessage(aMessage.target, "SendUserLoginsData", {
|
||||
hasFxa,
|
||||
numLogins,
|
||||
numSyncedDevices,
|
||||
});
|
||||
this.sendMessage(aMessage.target, "SendUserMobileDeviceData", {
|
||||
mobileDeviceConnected,
|
||||
});
|
||||
break;
|
||||
return this.getLoginData();
|
||||
|
||||
case "ClearMonitorCache":
|
||||
this.monitorResponse = null;
|
||||
break;
|
||||
|
||||
case "GetShowProxyCard":
|
||||
if (await this.shouldShowProxyCard()) {
|
||||
this.sendMessage(aMessage.target, "SendShowProxyCard");
|
||||
}
|
||||
let card = await this.shouldShowProxyCard();
|
||||
return card;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@ with Files("WebRTCChild.jsm"):
|
|||
|
||||
FINAL_TARGET_FILES.actors += [
|
||||
'AboutNewTabChild.jsm',
|
||||
'AboutProtectionsChild.jsm',
|
||||
'AboutProtectionsParent.jsm',
|
||||
'AboutReaderChild.jsm',
|
||||
'BlockedSiteChild.jsm',
|
||||
'BlockedSiteParent.jsm',
|
||||
|
|
|
@ -105,6 +105,21 @@ let ACTORS = {
|
|||
remoteTypes: ["privilegedabout"],
|
||||
},
|
||||
|
||||
AboutProtections: {
|
||||
parent: {
|
||||
moduleURI: "resource:///actors/AboutProtectionsParent.jsm",
|
||||
},
|
||||
child: {
|
||||
moduleURI: "resource:///actors/AboutProtectionsChild.jsm",
|
||||
|
||||
events: {
|
||||
DOMWindowCreated: { capture: true },
|
||||
},
|
||||
},
|
||||
|
||||
matches: ["about:protections"],
|
||||
},
|
||||
|
||||
AboutWelcome: {
|
||||
parent: {
|
||||
moduleURI: "resource:///actors/AboutWelcomeParent.jsm",
|
||||
|
@ -576,8 +591,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
AboutCertViewerHandler: "resource://gre/modules/AboutCertViewerHandler.jsm",
|
||||
AboutPrivateBrowsingHandler:
|
||||
"resource:///modules/aboutpages/AboutPrivateBrowsingHandler.jsm",
|
||||
AboutProtectionsHandler:
|
||||
"resource:///modules/aboutpages/AboutProtectionsHandler.jsm",
|
||||
AddonManager: "resource://gre/modules/AddonManager.jsm",
|
||||
AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.jsm",
|
||||
AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm",
|
||||
|
@ -1690,7 +1703,10 @@ BrowserGlue.prototype = {
|
|||
|
||||
AboutPrivateBrowsingHandler.init();
|
||||
|
||||
AboutProtectionsHandler.init();
|
||||
Services.telemetry.setEventRecordingEnabled(
|
||||
"security.ui.protections",
|
||||
true
|
||||
);
|
||||
|
||||
PageActions.init();
|
||||
|
||||
|
@ -1939,7 +1955,6 @@ BrowserGlue.prototype = {
|
|||
NewTabUtils.uninit();
|
||||
AboutCertViewerHandler.uninit();
|
||||
AboutPrivateBrowsingHandler.uninit();
|
||||
AboutProtectionsHandler.uninit();
|
||||
|
||||
Normandy.uninit();
|
||||
RFPHelper.uninit();
|
||||
|
|
|
@ -23,7 +23,6 @@ XPCOM_MANIFESTS += [
|
|||
|
||||
EXTRA_JS_MODULES.aboutpages = [
|
||||
'AboutPrivateBrowsingHandler.jsm',
|
||||
'AboutProtectionsHandler.jsm',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'browsercomps'
|
||||
|
|
|
@ -69,14 +69,6 @@ export default class LockwiseCard {
|
|||
lockwiseReportLink.addEventListener("click", () => {
|
||||
this.doc.sendTelemetryEvent("click", "lw_about_link");
|
||||
});
|
||||
|
||||
RPMAddMessageListener("SendUserLoginsData", ({ data }) => {
|
||||
// Once data for the user is retrieved, display the lockwise card.
|
||||
this.buildContent(data);
|
||||
|
||||
const lockwiseUI = document.querySelector(".card.lockwise-card.loading");
|
||||
lockwiseUI.classList.remove("loading");
|
||||
});
|
||||
}
|
||||
|
||||
buildContent(data) {
|
||||
|
@ -121,6 +113,9 @@ export default class LockwiseCard {
|
|||
title.setAttribute("data-l10n-id", "lockwise-title");
|
||||
headerContent.setAttribute("data-l10n-id", "lockwise-header-content");
|
||||
}
|
||||
|
||||
const lockwiseUI = document.querySelector(".card.lockwise-card.loading");
|
||||
lockwiseUI.classList.remove("loading");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,6 @@ export default class MonitorClass {
|
|||
init() {
|
||||
// Wait for monitor data and display the card.
|
||||
this.getMonitorData();
|
||||
RPMSendAsyncMessage("FetchMonitorData");
|
||||
|
||||
let monitorReportLink = this.doc.getElementById("full-report-link");
|
||||
monitorReportLink.addEventListener("click", () => {
|
||||
|
@ -46,11 +45,10 @@ export default class MonitorClass {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds a listener for receiving the monitor data. Once received then display this data
|
||||
* in the card.
|
||||
* Retrieves the monitor data and displays this data in the card.
|
||||
**/
|
||||
getMonitorData() {
|
||||
RPMAddMessageListener("SendMonitorData", ({ data: monitorData }) => {
|
||||
RPMSendQuery("FetchMonitorData", {}).then(monitorData => {
|
||||
// Once data for the user is retrieved, display the monitor card.
|
||||
this.buildContent(monitorData);
|
||||
|
||||
|
|
|
@ -16,10 +16,7 @@ window.addEventListener("beforeunload", () => {
|
|||
document.addEventListener("DOMContentLoaded", e => {
|
||||
let todayInMs = Date.now();
|
||||
let weekAgoInMs = todayInMs - 6 * 24 * 60 * 60 * 1000;
|
||||
RPMSendAsyncMessage("FetchContentBlockingEvents", {
|
||||
from: weekAgoInMs,
|
||||
to: todayInMs,
|
||||
});
|
||||
|
||||
let dataTypes = [
|
||||
"cryptominer",
|
||||
"fingerprinter",
|
||||
|
@ -357,17 +354,10 @@ document.addEventListener("DOMContentLoaded", e => {
|
|||
}
|
||||
};
|
||||
|
||||
RPMAddMessageListener("SendContentBlockingRecords", message => {
|
||||
createGraph(message.data);
|
||||
});
|
||||
RPMAddMessageListener("SendUserMobileDeviceData", message => {
|
||||
if (
|
||||
RPMGetBoolPref("browser.contentblocking.report.show_mobile_app") &&
|
||||
!message.data.mobileDeviceConnected
|
||||
) {
|
||||
document.getElementById("mobile-hanger").classList.remove("hidden");
|
||||
}
|
||||
});
|
||||
RPMSendQuery("FetchContentBlockingEvents", {
|
||||
from: weekAgoInMs,
|
||||
to: todayInMs,
|
||||
}).then(createGraph);
|
||||
|
||||
let exitIcon = document.querySelector("#mobile-hanger .exit-icon");
|
||||
// hide the mobile promotion and keep hidden with a pref.
|
||||
|
@ -397,15 +387,33 @@ document.addEventListener("DOMContentLoaded", e => {
|
|||
"browser.contentblocking.report.lockwise.enabled",
|
||||
true
|
||||
);
|
||||
|
||||
let lockwiseCard;
|
||||
if (lockwiseEnabled) {
|
||||
const lockwiseUI = document.querySelector(".lockwise-card");
|
||||
lockwiseUI.classList.remove("hidden");
|
||||
lockwiseUI.classList.add("loading");
|
||||
|
||||
const lockwiseCard = new LockwiseCard(document);
|
||||
lockwiseCard = new LockwiseCard(document);
|
||||
lockwiseCard.init();
|
||||
}
|
||||
|
||||
RPMSendQuery("FetchUserLoginsData", {}).then(data => {
|
||||
if (lockwiseCard) {
|
||||
// Once data for the user is retrieved, display the lockwise card.
|
||||
lockwiseCard.buildContent(data);
|
||||
}
|
||||
|
||||
if (
|
||||
RPMGetBoolPref("browser.contentblocking.report.show_mobile_app") &&
|
||||
!data.mobileDeviceConnected
|
||||
) {
|
||||
document
|
||||
.getElementById("mobile-hanger")
|
||||
.classList.toggle("hidden", false);
|
||||
}
|
||||
});
|
||||
|
||||
// For tests
|
||||
const lockwiseUI = document.querySelector(".lockwise-card");
|
||||
lockwiseUI.dataset.enabled = lockwiseEnabled;
|
||||
|
@ -441,8 +449,4 @@ document.addEventListener("DOMContentLoaded", e => {
|
|||
// For tests
|
||||
const proxyUI = document.querySelector(".proxy-card");
|
||||
proxyUI.dataset.enabled = proxyEnabled;
|
||||
|
||||
// Dispatch messages to retrieve data for the Lockwise & Monitor
|
||||
// cards.
|
||||
RPMSendAsyncMessage("FetchUserLoginsData");
|
||||
});
|
||||
|
|
|
@ -21,11 +21,9 @@ export default class ProxyCard {
|
|||
proxyExtensionLink.href = PROXY_EXTENSION_URL;
|
||||
|
||||
// Show the Proxy card
|
||||
RPMAddMessageListener("SendShowProxyCard", () => {
|
||||
RPMSendQuery("GetShowProxyCard", {}).then(shouldShow => {
|
||||
const proxyCard = this.doc.querySelector(".proxy-card");
|
||||
proxyCard.classList.remove("hidden");
|
||||
proxyCard.classList.toggle("hidden", !shouldShow);
|
||||
});
|
||||
|
||||
RPMSendAsyncMessage("GetShowProxyCard");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { AboutProtectionsHandler } = ChromeUtils.import(
|
||||
"resource:///modules/aboutpages/AboutProtectionsHandler.jsm"
|
||||
const { AboutProtectionsParent } = ChromeUtils.import(
|
||||
"resource:///actors/AboutProtectionsParent.jsm"
|
||||
);
|
||||
|
||||
const nsLoginInfo = new Components.Constructor(
|
||||
"@mozilla.org/login-manager/loginInfo;1",
|
||||
Ci.nsILoginInfo,
|
||||
|
@ -39,7 +38,6 @@ add_task(async function() {
|
|||
url: "about:protections",
|
||||
gBrowser,
|
||||
});
|
||||
const { getLoginData } = AboutProtectionsHandler;
|
||||
|
||||
info("Check that the correct content is displayed for non-logged in users.");
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
|
||||
|
@ -144,7 +142,7 @@ add_task(async function() {
|
|||
info(
|
||||
"Mock login data with synced devices and check that the correct number and content is displayed."
|
||||
);
|
||||
AboutProtectionsHandler.getLoginData = mockGetLoginDataWithSyncedDevices(5);
|
||||
AboutProtectionsParent.setTestOverride(mockGetLoginDataWithSyncedDevices(5));
|
||||
await reloadTab(tab);
|
||||
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
|
||||
|
@ -198,6 +196,6 @@ add_task(async function() {
|
|||
Services.logins.removeLogin(TEST_LOGIN1);
|
||||
Services.logins.removeLogin(TEST_LOGIN2);
|
||||
|
||||
AboutProtectionsHandler.getLoginData = getLoginData;
|
||||
AboutProtectionsParent.setTestOverride(null);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { AboutProtectionsHandler } = ChromeUtils.import(
|
||||
"resource:///modules/aboutpages/AboutProtectionsHandler.jsm"
|
||||
const { AboutProtectionsParent } = ChromeUtils.import(
|
||||
"resource:///actors/AboutProtectionsParent.jsm"
|
||||
);
|
||||
const nsLoginInfo = new Components.Constructor(
|
||||
"@mozilla.org/login-manager/loginInfo;1",
|
||||
|
@ -39,16 +39,25 @@ let fakeDataWithError = {
|
|||
error: true,
|
||||
};
|
||||
|
||||
// Modify AboutProtectionsHandler's getMonitorData method to fake returning data from the
|
||||
// Monitor endpoint.
|
||||
const mockGetMonitorData = data => async () => data;
|
||||
// Modify AboutProtectionsParent's getMonitorData and getLoginData methods
|
||||
// to fake being logged in with Fxa.
|
||||
const mockGetMonitorData = data => {
|
||||
return {
|
||||
getMonitorData: async () => data,
|
||||
};
|
||||
};
|
||||
|
||||
// Modify AboutProtectionsHandler's getLoginData method to fake being logged in with Fxa.
|
||||
const mockGetLoginData = async () => {
|
||||
const mockGetMonitorAndLoginData = data => {
|
||||
return {
|
||||
hasFxa: true,
|
||||
numLogins: Services.logins.countLogins("", "", ""),
|
||||
numSyncedDevices: 0,
|
||||
getMonitorData: async () => data,
|
||||
getLoginData: () => {
|
||||
return {
|
||||
hasFxa: true,
|
||||
numLogins: Services.logins.countLogins("", "", ""),
|
||||
numSyncedDevices: 0,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -57,8 +66,6 @@ add_task(async function() {
|
|||
url: "about:protections",
|
||||
gBrowser,
|
||||
});
|
||||
const { getLoginData } = AboutProtectionsHandler;
|
||||
const { getMonitorData } = AboutProtectionsHandler;
|
||||
|
||||
await reloadTab(tab);
|
||||
|
||||
|
@ -69,8 +76,8 @@ add_task(async function() {
|
|||
"Check that the correct content is displayed for users with monitor data."
|
||||
);
|
||||
Services.logins.addLogin(TEST_LOGIN1);
|
||||
AboutProtectionsHandler.getMonitorData = mockGetMonitorData(
|
||||
fakeDataWithNoError
|
||||
AboutProtectionsParent.setTestOverride(
|
||||
mockGetMonitorData(fakeDataWithNoError)
|
||||
);
|
||||
await reloadTab(tab);
|
||||
|
||||
|
@ -127,8 +134,8 @@ add_task(async function() {
|
|||
...fakeDataWithNoError,
|
||||
potentiallyBreachedLogins: 0,
|
||||
};
|
||||
AboutProtectionsHandler.getMonitorData = mockGetMonitorData(
|
||||
noBreachedLoginsData
|
||||
AboutProtectionsParent.setTestOverride(
|
||||
mockGetMonitorData(noBreachedLoginsData)
|
||||
);
|
||||
|
||||
await reloadTab(tab);
|
||||
|
@ -154,10 +161,9 @@ add_task(async function() {
|
|||
info(
|
||||
"Check that correct content is displayed when monitor data contains an error message."
|
||||
);
|
||||
AboutProtectionsHandler.getMonitorData = mockGetMonitorData(
|
||||
fakeDataWithError
|
||||
AboutProtectionsParent.setTestOverride(
|
||||
mockGetMonitorAndLoginData(fakeDataWithError)
|
||||
);
|
||||
AboutProtectionsHandler.getLoginData = mockGetLoginData;
|
||||
await reloadTab(tab);
|
||||
await checkNoLoginsContentIsDisplayed(tab);
|
||||
|
||||
|
@ -187,9 +193,8 @@ add_task(async function() {
|
|||
// remove logins
|
||||
Services.logins.removeLogin(TEST_LOGIN1);
|
||||
|
||||
// restore original getLoginData & getMonitorData methods to AboutProtectionsHandler
|
||||
AboutProtectionsHandler.getLoginData = getLoginData;
|
||||
AboutProtectionsHandler.getMonitorData = getMonitorData;
|
||||
// restore original test functions
|
||||
AboutProtectionsParent.setTestOverride(null);
|
||||
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
});
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
||||
const { Sqlite } = ChromeUtils.import("resource://gre/modules/Sqlite.jsm");
|
||||
const { AboutProtectionsHandler } = ChromeUtils.import(
|
||||
"resource:///modules/aboutpages/AboutProtectionsHandler.jsm"
|
||||
const { AboutProtectionsParent } = ChromeUtils.import(
|
||||
"resource:///actors/AboutProtectionsParent.jsm"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
|
@ -756,8 +756,7 @@ add_task(async function test_etp_custom_protections_off() {
|
|||
// Ensure that the ETP mobile promotion card is shown when the pref is on and
|
||||
// there are no mobile devices connected.
|
||||
add_task(async function test_etp_mobile_promotion_pref_on() {
|
||||
const { getLoginData } = AboutProtectionsHandler;
|
||||
AboutProtectionsHandler.onLoginData = mockGetLoginDataWithSyncedDevices(0);
|
||||
AboutProtectionsParent.setTestOverride(mockGetLoginDataWithSyncedDevices(0));
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.contentblocking.report.show_mobile_app", true]],
|
||||
});
|
||||
|
@ -783,9 +782,8 @@ add_task(async function test_etp_mobile_promotion_pref_on() {
|
|||
BrowserTestUtils.removeTab(tab);
|
||||
|
||||
// Add a mock mobile device. The promotion should now be hidden.
|
||||
AboutProtectionsHandler.onLoginData = mockGetLoginDataWithSyncedDevices(
|
||||
2,
|
||||
true
|
||||
AboutProtectionsParent.setTestOverride(
|
||||
mockGetLoginDataWithSyncedDevices(2, true)
|
||||
);
|
||||
tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:protections",
|
||||
|
@ -800,14 +798,13 @@ add_task(async function test_etp_mobile_promotion_pref_on() {
|
|||
});
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
AboutProtectionsHandler.getLoginData = getLoginData;
|
||||
AboutProtectionsParent.setTestOverride(null);
|
||||
});
|
||||
|
||||
// Test that ETP mobile promotion is not shown when the pref is off,
|
||||
// even if no mobile devices are synced.
|
||||
add_task(async function test_etp_mobile_promotion_pref_on() {
|
||||
const { getLoginData } = AboutProtectionsHandler;
|
||||
AboutProtectionsHandler.onLoginData = mockGetLoginDataWithSyncedDevices(0);
|
||||
AboutProtectionsParent.setTestOverride(mockGetLoginDataWithSyncedDevices(0));
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.contentblocking.report.show_mobile_app", false]],
|
||||
});
|
||||
|
@ -826,9 +823,8 @@ add_task(async function test_etp_mobile_promotion_pref_on() {
|
|||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
|
||||
AboutProtectionsHandler.onLoginData = mockGetLoginDataWithSyncedDevices(
|
||||
2,
|
||||
true
|
||||
AboutProtectionsParent.setTestOverride(
|
||||
mockGetLoginDataWithSyncedDevices(2, true)
|
||||
);
|
||||
tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
url: "about:protections",
|
||||
|
@ -843,5 +839,5 @@ add_task(async function test_etp_mobile_promotion_pref_on() {
|
|||
);
|
||||
});
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
AboutProtectionsHandler.getLoginData = getLoginData;
|
||||
AboutProtectionsParent.setTestOverride(null);
|
||||
});
|
||||
|
|
|
@ -16,11 +16,15 @@ async function reloadTab(tab) {
|
|||
const mockGetLoginDataWithSyncedDevices = (
|
||||
deviceCount,
|
||||
mobileDeviceConnected = false
|
||||
) => async () => {
|
||||
) => {
|
||||
return {
|
||||
hasFxa: true,
|
||||
numLogins: Services.logins.countLogins("", "", ""),
|
||||
numSyncedDevices: deviceCount,
|
||||
mobileDeviceConnected: deviceCount && mobileDeviceConnected,
|
||||
getLoginData: () => {
|
||||
return {
|
||||
hasFxa: true,
|
||||
numLogins: Services.logins.countLogins("", "", ""),
|
||||
numSyncedDevices: deviceCount,
|
||||
mobileDeviceConnected: deviceCount && mobileDeviceConnected,
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
@ -7,11 +7,6 @@
|
|||
var EXPORTED_SYMBOLS = ["MessagePort", "MessageListener"];
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"AsyncPrefs",
|
||||
"resource://gre/modules/AsyncPrefs.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"PrivateBrowsingUtils",
|
||||
|
@ -42,46 +37,6 @@ let RPMAccessManager = {
|
|||
getFormatURLPref: ["app.support.baseURL"],
|
||||
isWindowPrivate: ["yes"],
|
||||
},
|
||||
"about:protections": {
|
||||
setBoolPref: [
|
||||
"browser.contentblocking.report.hide_lockwise_app",
|
||||
"browser.contentblocking.report.show_mobile_app",
|
||||
],
|
||||
getBoolPref: [
|
||||
"browser.contentblocking.report.lockwise.enabled",
|
||||
"browser.contentblocking.report.monitor.enabled",
|
||||
"privacy.socialtracking.block_cookies.enabled",
|
||||
"browser.contentblocking.report.proxy.enabled",
|
||||
"privacy.trackingprotection.cryptomining.enabled",
|
||||
"privacy.trackingprotection.fingerprinting.enabled",
|
||||
"privacy.trackingprotection.enabled",
|
||||
"privacy.trackingprotection.socialtracking.enabled",
|
||||
"browser.contentblocking.report.hide_lockwise_app",
|
||||
"browser.contentblocking.report.show_mobile_app",
|
||||
],
|
||||
getStringPref: [
|
||||
"browser.contentblocking.category",
|
||||
"browser.contentblocking.report.monitor.url",
|
||||
"browser.contentblocking.report.monitor.sign_in_url",
|
||||
"browser.contentblocking.report.manage_devices.url",
|
||||
"browser.contentblocking.report.proxy_extension.url",
|
||||
"browser.contentblocking.report.lockwise.mobile-android.url",
|
||||
"browser.contentblocking.report.lockwise.mobile-ios.url",
|
||||
"browser.contentblocking.report.mobile-ios.url",
|
||||
"browser.contentblocking.report.mobile-android.url",
|
||||
],
|
||||
getIntPref: ["network.cookie.cookieBehavior"],
|
||||
getFormatURLPref: [
|
||||
"browser.contentblocking.report.monitor.how_it_works.url",
|
||||
"browser.contentblocking.report.lockwise.how_it_works.url",
|
||||
"browser.contentblocking.report.social.url",
|
||||
"browser.contentblocking.report.cookie.url",
|
||||
"browser.contentblocking.report.tracker.url",
|
||||
"browser.contentblocking.report.fingerprinter.url",
|
||||
"browser.contentblocking.report.cryptominer.url",
|
||||
],
|
||||
recordTelemetryEvent: ["yes"],
|
||||
},
|
||||
"about:newinstall": {
|
||||
getUpdateChannel: ["yes"],
|
||||
getFxAccountsEndpoint: ["yes"],
|
||||
|
@ -427,46 +382,6 @@ class MessagePort {
|
|||
);
|
||||
}
|
||||
|
||||
getIntPref(aPref, defaultValue) {
|
||||
let doc = this.window.document;
|
||||
if (!RPMAccessManager.checkAllowAccess(doc, "getIntPref", aPref)) {
|
||||
throw new Error("RPMAccessManager does not allow access to getIntPref");
|
||||
}
|
||||
// Only call with a default value if it's defined, to be able to throw
|
||||
// errors for non-existent prefs.
|
||||
if (defaultValue !== undefined) {
|
||||
return Services.prefs.getIntPref(aPref, defaultValue);
|
||||
}
|
||||
return Services.prefs.getIntPref(aPref);
|
||||
}
|
||||
|
||||
getStringPref(aPref) {
|
||||
let doc = this.window.document;
|
||||
if (!RPMAccessManager.checkAllowAccess(doc, "getStringPref", aPref)) {
|
||||
throw new Error(
|
||||
"RPMAccessManager does not allow access to getStringPref"
|
||||
);
|
||||
}
|
||||
return Services.prefs.getStringPref(aPref);
|
||||
}
|
||||
|
||||
getBoolPref(aPref, defaultValue) {
|
||||
let doc = this.window.document;
|
||||
if (!RPMAccessManager.checkAllowAccess(doc, "getBoolPref", aPref)) {
|
||||
throw new Error("RPMAccessManager does not allow access to getBoolPref");
|
||||
}
|
||||
// Only call with a default value if it's defined, to be able to throw
|
||||
// errors for non-existent prefs.
|
||||
if (defaultValue !== undefined) {
|
||||
return Services.prefs.getBoolPref(aPref, defaultValue);
|
||||
}
|
||||
return Services.prefs.getBoolPref(aPref);
|
||||
}
|
||||
|
||||
setBoolPref(aPref, aVal) {
|
||||
return this.wrapPromise(AsyncPrefs.set(aPref, aVal));
|
||||
}
|
||||
|
||||
getFormatURLPref(aFormatURL) {
|
||||
let doc = this.window.document;
|
||||
if (
|
||||
|
@ -511,22 +426,4 @@ class MessagePort {
|
|||
|
||||
return this.sendRequest("FxAccountsEndpoint", aEntrypoint);
|
||||
}
|
||||
|
||||
recordTelemetryEvent(category, event, object, value, extra) {
|
||||
let doc = this.window.document;
|
||||
if (
|
||||
!RPMAccessManager.checkAllowAccess(doc, "recordTelemetryEvent", "yes")
|
||||
) {
|
||||
throw new Error(
|
||||
"RPMAccessManager does not allow access to recordTelemetryEvent"
|
||||
);
|
||||
}
|
||||
return Services.telemetry.recordEvent(
|
||||
category,
|
||||
event,
|
||||
object,
|
||||
value,
|
||||
extra
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,18 +32,6 @@ class ChildMessagePort extends MessagePort {
|
|||
defineAs: "RPMRemoveMessageListener",
|
||||
allowCallbacks: true,
|
||||
});
|
||||
Cu.exportFunction(this.getIntPref.bind(this), window, {
|
||||
defineAs: "RPMGetIntPref",
|
||||
});
|
||||
Cu.exportFunction(this.getStringPref.bind(this), window, {
|
||||
defineAs: "RPMGetStringPref",
|
||||
});
|
||||
Cu.exportFunction(this.getBoolPref.bind(this), window, {
|
||||
defineAs: "RPMGetBoolPref",
|
||||
});
|
||||
Cu.exportFunction(this.setBoolPref.bind(this), window, {
|
||||
defineAs: "RPMSetBoolPref",
|
||||
});
|
||||
Cu.exportFunction(this.getFormatURLPref.bind(this), window, {
|
||||
defineAs: "RPMGetFormatURLPref",
|
||||
});
|
||||
|
@ -56,9 +44,6 @@ class ChildMessagePort extends MessagePort {
|
|||
Cu.exportFunction(this.getFxAccountsEndpoint.bind(this), window, {
|
||||
defineAs: "RPMGetFxAccountsEndpoint",
|
||||
});
|
||||
Cu.exportFunction(this.recordTelemetryEvent.bind(this), window, {
|
||||
defineAs: "RPMRecordTelemetryEvent",
|
||||
});
|
||||
|
||||
// The actor form only needs the functions set up above. The actor
|
||||
// will send and receive messages directly.
|
||||
|
|
|
@ -93,6 +93,61 @@ let RemotePageAccessManager = {
|
|||
RPMPrefIsLocked: ["security.tls.version.min"],
|
||||
RPMAddToHistogram: ["*"],
|
||||
},
|
||||
"about:protections": {
|
||||
RPMSendAsyncMessage: [
|
||||
"OpenContentBlockingPreferences",
|
||||
"OpenAboutLogins",
|
||||
"OpenSyncPreferences",
|
||||
"ClearMonitorCache",
|
||||
],
|
||||
RPMSendQuery: [
|
||||
"FetchUserLoginsData",
|
||||
"FetchMonitorData",
|
||||
"FetchContentBlockingEvents",
|
||||
"FetchMobileDeviceConnected",
|
||||
"GetShowProxyCard",
|
||||
],
|
||||
RPMAddMessageListener: ["*"],
|
||||
RPMRemoveMessageListener: ["*"],
|
||||
RPMSetBoolPref: [
|
||||
"browser.contentblocking.report.hide_lockwise_app",
|
||||
"browser.contentblocking.report.show_mobile_app",
|
||||
],
|
||||
RPMGetBoolPref: [
|
||||
"browser.contentblocking.report.lockwise.enabled",
|
||||
"browser.contentblocking.report.monitor.enabled",
|
||||
"privacy.socialtracking.block_cookies.enabled",
|
||||
"browser.contentblocking.report.proxy.enabled",
|
||||
"privacy.trackingprotection.cryptomining.enabled",
|
||||
"privacy.trackingprotection.fingerprinting.enabled",
|
||||
"privacy.trackingprotection.enabled",
|
||||
"privacy.trackingprotection.socialtracking.enabled",
|
||||
"browser.contentblocking.report.hide_lockwise_app",
|
||||
"browser.contentblocking.report.show_mobile_app",
|
||||
],
|
||||
RPMGetStringPref: [
|
||||
"browser.contentblocking.category",
|
||||
"browser.contentblocking.report.monitor.url",
|
||||
"browser.contentblocking.report.monitor.sign_in_url",
|
||||
"browser.contentblocking.report.manage_devices.url",
|
||||
"browser.contentblocking.report.proxy_extension.url",
|
||||
"browser.contentblocking.report.lockwise.mobile-android.url",
|
||||
"browser.contentblocking.report.lockwise.mobile-ios.url",
|
||||
"browser.contentblocking.report.mobile-ios.url",
|
||||
"browser.contentblocking.report.mobile-android.url",
|
||||
],
|
||||
RPMGetIntPref: ["network.cookie.cookieBehavior"],
|
||||
RPMGetFormatURLPref: [
|
||||
"browser.contentblocking.report.monitor.how_it_works.url",
|
||||
"browser.contentblocking.report.lockwise.how_it_works.url",
|
||||
"browser.contentblocking.report.social.url",
|
||||
"browser.contentblocking.report.cookie.url",
|
||||
"browser.contentblocking.report.tracker.url",
|
||||
"browser.contentblocking.report.fingerprinter.url",
|
||||
"browser.contentblocking.report.cryptominer.url",
|
||||
],
|
||||
RPMRecordTelemetryEvent: ["*"],
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче