Commit d697e6aa authored by Andrew Swan's avatar Andrew Swan
Browse files

Bug 1567258 - Convert fxmonitor to a built-in component r=nhnt11,flod

Differential Revision: https://phabricator.services.mozilla.com/D40666

--HG--
rename : browser/extensions/fxmonitor/privileged/api.js => browser/components/fxmonitor/FirefoxMonitor.jsm
rename : browser/extensions/fxmonitor/privileged/FirefoxMonitor.css => browser/components/fxmonitor/content/FirefoxMonitor.css
rename : browser/extensions/fxmonitor/assets/monitor32.svg => browser/components/fxmonitor/content/monitor32.svg
rename : browser/extensions/fxmonitor/moz.build => browser/components/fxmonitor/moz.build
rename : browser/extensions/fxmonitor/test/browser/browser.ini => browser/components/fxmonitor/test/browser/browser.ini
rename : browser/extensions/fxmonitor/test/browser/browser_fxmonitor_doorhanger.js => browser/components/fxmonitor/test/browser/browser_fxmonitor_doorhanger.js
rename : browser/extensions/fxmonitor/locales/en-US/fxmonitor.properties => browser/locales/en-US/chrome/browser/fxmonitor.properties
extra : moz-landing-system : lando
parent 31eced36
...@@ -514,6 +514,7 @@ XPCOMUtils.defineLazyModuleGetters(this, { ...@@ -514,6 +514,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
Corroborate: "resource://gre/modules/Corroborate.jsm", Corroborate: "resource://gre/modules/Corroborate.jsm",
Discovery: "resource:///modules/Discovery.jsm", Discovery: "resource:///modules/Discovery.jsm",
ExtensionsUI: "resource:///modules/ExtensionsUI.jsm", ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
FirefoxMonitor: "resource:///modules/FirefoxMonitor.jsm",
FxAccounts: "resource://gre/modules/FxAccounts.jsm", FxAccounts: "resource://gre/modules/FxAccounts.jsm",
HomePage: "resource:///modules/HomePage.jsm", HomePage: "resource:///modules/HomePage.jsm",
HybridContentTelemetry: "resource://gre/modules/HybridContentTelemetry.jsm", HybridContentTelemetry: "resource://gre/modules/HybridContentTelemetry.jsm",
...@@ -1998,6 +1999,8 @@ BrowserGlue.prototype = { ...@@ -1998,6 +1999,8 @@ BrowserGlue.prototype = {
if (pService.createdAlternateProfile) { if (pService.createdAlternateProfile) {
this._showNewInstallModal(); this._showNewInstallModal();
} }
FirefoxMonitor.init();
}, },
/** /**
......
...@@ -2,55 +2,25 @@ ...@@ -2,55 +2,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* globals ExtensionAPI, XPCOMUtils */ "use strict";
ChromeUtils.defineModuleGetter( const EXPORTED_SYMBOLS = ["FirefoxMonitor"];
this,
"EveryWindow",
"resource:///modules/EveryWindow.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"PluralForm",
"resource://gre/modules/PluralForm.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"Preferences",
"resource://gre/modules/Preferences.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"RemoteSettings",
"resource://services-settings/remote-settings.js"
);
ChromeUtils.defineModuleGetter(
this,
"Services",
"resource://gre/modules/Services.jsm"
);
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
this.fxmonitor = class extends ExtensionAPI { const { XPCOMUtils } = ChromeUtils.import(
getAPI(context) { "resource://gre/modules/XPCOMUtils.jsm"
return { );
fxmonitor: {
async start() {
await FirefoxMonitor.init(context.extension);
},
},
};
}
onShutdown(shutdownReason) { XPCOMUtils.defineLazyModuleGetters(this, {
if (Services.startup.shuttingDown) { EveryWindow: "resource:///modules/EveryWindow.jsm",
return; PluralForm: "resource://gre/modules/PluralForm.jsm",
} Preferences: "resource://gre/modules/Preferences.jsm",
RemoteSettings: "resource://services-settings/remote-settings.js",
Services: "resource://gre/modules/Services.jsm",
});
FirefoxMonitor.stopObserving(); const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
} const STYLESHEET = "chrome://browser/content/fxmonitor/FirefoxMonitor.css";
}; const ICON = "chrome://browser/content/fxmonitor/monitor32.svg";
this.FirefoxMonitor = { this.FirefoxMonitor = {
// Map of breached site host -> breach metadata. // Map of breached site host -> breach metadata.
...@@ -101,10 +71,6 @@ this.FirefoxMonitor = { ...@@ -101,10 +71,6 @@ this.FirefoxMonitor = {
Preferences.set(this.kEnabledPref, false); Preferences.set(this.kEnabledPref, false);
}, },
getURL(aPath) {
return this.extension.getURL(aPath);
},
getString(aKey) { getString(aKey) {
return this.strings.GetStringFromName(aKey); return this.strings.GetStringFromName(aKey);
}, },
...@@ -138,9 +104,7 @@ this.FirefoxMonitor = { ...@@ -138,9 +104,7 @@ this.FirefoxMonitor = {
Preferences.reset(this.kWarnedHostsPref); Preferences.reset(this.kWarnedHostsPref);
}, },
init(aExtension) { init() {
this.extension = aExtension;
XPCOMUtils.defineLazyPreferenceGetter( XPCOMUtils.defineLazyPreferenceGetter(
this, this,
"enabled", "enabled",
...@@ -200,6 +164,9 @@ this.FirefoxMonitor = { ...@@ -200,6 +164,9 @@ this.FirefoxMonitor = {
}, },
}); });
let telemetryEnabled = !Preferences.get(this.kTelemetryDisabledPref);
Services.telemetry.setEventRecordingEnabled("fxmonitor", telemetryEnabled);
XPCOMUtils.defineLazyPreferenceGetter( XPCOMUtils.defineLazyPreferenceGetter(
this, this,
"FirefoxMonitorURL", "FirefoxMonitorURL",
...@@ -214,6 +181,12 @@ this.FirefoxMonitor = { ...@@ -214,6 +181,12 @@ this.FirefoxMonitor = {
false false
); );
XPCOMUtils.defineLazyGetter(this, "strings", () => {
return Services.strings.createBundle(
"chrome://browser/locale/fxmonitor.properties"
);
});
XPCOMUtils.defineLazyPreferenceGetter( XPCOMUtils.defineLazyPreferenceGetter(
this, this,
"telemetryDisabled", "telemetryDisabled",
...@@ -221,37 +194,9 @@ this.FirefoxMonitor = { ...@@ -221,37 +194,9 @@ this.FirefoxMonitor = {
false false
); );
await this.loadStrings();
await this.loadBreaches(); await this.loadBreaches();
}, },
loadStrings() {
let l10nManifest;
if (this.extension.rootURI instanceof Ci.nsIJARURI) {
l10nManifest = this.extension.rootURI.JARFile.QueryInterface(
Ci.nsIFileURL
).file;
} else if (this.extension.rootURI instanceof Ci.nsIFileURL) {
l10nManifest = this.extension.rootURI.file;
}
if (l10nManifest) {
XPCOMUtils.defineLazyGetter(this, "strings", () => {
Components.manager.addBootstrappedManifestLocation(l10nManifest);
return Services.strings.createBundle(
"chrome://fxmonitor/locale/fxmonitor.properties"
);
});
} else {
// Something is very strange if we reach this line, so we throw
// in order to prevent init from completing and burst the stack.
throw new Error(
"Cannot find fxmonitor chrome.manifest for registering translated strings"
);
}
},
kRemoteSettingsKey: "fxmonitor-breaches", kRemoteSettingsKey: "fxmonitor-breaches",
async loadBreaches() { async loadBreaches() {
let populateSites = data => { let populateSites = data => {
...@@ -358,7 +303,7 @@ this.FirefoxMonitor = { ...@@ -358,7 +303,7 @@ this.FirefoxMonitor = {
let DOMWindowUtils = win.windowUtils; let DOMWindowUtils = win.windowUtils;
DOMWindowUtils.removeSheetUsingURIString( DOMWindowUtils.removeSheetUsingURIString(
this.getURL("privileged/FirefoxMonitor.css"), STYLESHEET,
DOMWindowUtils.AUTHOR_SHEET DOMWindowUtils.AUTHOR_SHEET
); );
...@@ -389,7 +334,7 @@ this.FirefoxMonitor = { ...@@ -389,7 +334,7 @@ this.FirefoxMonitor = {
// Inject our stylesheet. // Inject our stylesheet.
let DOMWindowUtils = win.windowUtils; let DOMWindowUtils = win.windowUtils;
DOMWindowUtils.loadSheetUsingURIString( DOMWindowUtils.loadSheetUsingURIString(
this.getURL("privileged/FirefoxMonitor.css"), STYLESHEET,
DOMWindowUtils.AUTHOR_SHEET DOMWindowUtils.AUTHOR_SHEET
); );
...@@ -406,7 +351,7 @@ this.FirefoxMonitor = { ...@@ -406,7 +351,7 @@ this.FirefoxMonitor = {
let img = doc.createElementNS(XUL_NS, "image"); let img = doc.createElementNS(XUL_NS, "image");
img.setAttribute("role", "button"); img.setAttribute("role", "button");
img.classList.add(`${this.kNotificationID}-icon`); img.classList.add(`${this.kNotificationID}-icon`);
img.style.listStyleImage = `url(${this.getURL("assets/monitor32.svg")})`; img.style.listStyleImage = `url(${ICON})`;
anchorBox.appendChild(img); anchorBox.appendChild(img);
notificationBox.appendChild(anchorBox); notificationBox.appendChild(anchorBox);
img.setAttribute( img.setAttribute(
...@@ -551,7 +496,7 @@ this.FirefoxMonitor = { ...@@ -551,7 +496,7 @@ this.FirefoxMonitor = {
persistent: true, persistent: true,
hideClose: true, hideClose: true,
eventCallback: populatePanel, eventCallback: populatePanel,
popupIconURL: this.getURL("assets/monitor32.svg"), popupIconURL: ICON,
} }
); );
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
[features/fxmonitor@mozilla.org] @AB_CD@.jar: browser.jar:
% locale fxmonitor @AB_CD@ %locale/@AB_CD@/ content/browser/fxmonitor/FirefoxMonitor.css (content/FirefoxMonitor.css)
locale/@AB_CD@/fxmonitor.properties (%fxmonitor.properties) content/browser/fxmonitor/monitor32.svg (content/monitor32.svg)
...@@ -4,4 +4,14 @@ ...@@ -4,4 +4,14 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
with Files('**'):
BUG_COMPONENT = ('Firefox', 'Firefox Monitor')
EXTRA_JS_MODULES += [
'FirefoxMonitor.jsm',
]
JAR_MANIFESTS += ['jar.mn'] JAR_MANIFESTS += ['jar.mn']
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
...@@ -50,64 +50,6 @@ async function clearWarnedHosts() { ...@@ -50,64 +50,6 @@ async function clearWarnedHosts() {
}); });
} }
add_task(async function test_warnedHosts_migration() {
info("Test that we correctly migrate the warnedHosts pref to content prefs.");
// Pre-set the warnedHosts pref to include example.com.
await SpecialPowers.pushPrefEnv({
set: [["extensions.fxmonitor.warnedHosts", '["example.com"]']],
});
// Pre-populate the Remote Settings collection with a breach.
let collection = await RemoteSettings(kRemoteSettingsKey).openCollection();
let BreachDate = new Date();
let AddedDate = new Date();
await collection.create({
Domain: "example.com",
Name: "Example Site",
BreachDate: `${BreachDate.getFullYear()}-${BreachDate.getMonth() +
1}-${BreachDate.getDate()}`,
AddedDate: `${AddedDate.getFullYear()}-${AddedDate.getMonth() +
1}-${AddedDate.getDate()}`,
PwnCount: 1000000,
});
await collection.db.saveLastModified(1234567);
// Finally, reload the extension.
let addon = await AddonManager.getAddonByID("fxmonitor@mozilla.org");
await addon.reload();
await TestUtils.waitForCondition(() => {
return !Services.prefs.prefHasUserValue("extensions.fxmonitor.warnedHosts");
}, "Waiting for the warnedHosts pref to be cleared");
ok(true, "The warnedHosts pref was cleared");
// Open a tab and ensure the alert isn't shown.
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"http://example.com"
);
await fxmonitorNotificationGone();
// Clean up.
BrowserTestUtils.removeTab(tab);
await collection.clear();
await collection.db.saveLastModified(1234567);
// Trigger a sync to clear.
await RemoteSettings(kRemoteSettingsKey).emit("sync", {
data: {
current: [],
},
});
await clearWarnedHosts();
await SpecialPowers.pushPrefEnv({
clear: [
["extensions.fxmonitor.enabled"],
["extensions.fxmonitor.firstAlertShown"],
],
});
});
add_task(async function test_main_flow() { add_task(async function test_main_flow() {
info("Test that we show the first alert correctly for a recent breach."); info("Test that we show the first alert correctly for a recent breach.");
......
...@@ -36,6 +36,7 @@ DIRS += [ ...@@ -36,6 +36,7 @@ DIRS += [
'downloads', 'downloads',
'enterprisepolicies', 'enterprisepolicies',
'extensions', 'extensions',
'fxmonitor',
'library', 'library',
'migration', 'migration',
'newtab', 'newtab',
......
<!-- 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/. -->
<svg width="28" height="28" xmlns="http://www.w3.org/2000/svg">
<path fill="context-fill" fill-opacity="context-fill-opacity" d="M27.386 22.024L17.48 2.212a4 4 0 0 0-7.156 0L.418 22.032a4 4 0 0 0 3.578 5.78h19.81a4 4 0 0 0 3.58-5.788zM11.902 7.812a2 2 0 1 1 4 0v8a2 2 0 1 1-4 0v-8zm2 16.5a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5z"/>
</svg>
/* 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/. */
/* eslint-env webextensions */
"use strict";
browser.fxmonitor.start();
{
"manifest_version": 2,
"name": "Firefox Monitor",
"version": "3.0",
"applications": {
"gecko": {
"id": "fxmonitor@mozilla.org",
"strict_min_version": "65.0"
}
},
"background": {
"scripts": ["background.js"]
},
"experiment_apis": {
"fxmonitor": {
"schema": "./privileged/schema.json",
"parent": {
"scopes": ["addon_parent"],
"script": "./privileged/api.js",
"paths": [["fxmonitor"]]
}
}
}
}
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
DEFINES['MOZ_APP_MAXVERSION'] = CONFIG['MOZ_APP_MAXVERSION']
DIRS += ['locales']
FINAL_TARGET_FILES.features['fxmonitor@mozilla.org'] += [
'background.js',
'manifest.json'
]
FINAL_TARGET_FILES.features['fxmonitor@mozilla.org']['assets'] += [
'assets/alert.svg',
'assets/monitor32.svg'
]
FINAL_TARGET_FILES.features['fxmonitor@mozilla.org']['privileged'] += [
'privileged/api.js',
'privileged/FirefoxMonitor.css',
'privileged/schema.json'
]
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
with Files('**'):
BUG_COMPONENT = ('Firefox', 'Firefox Monitor')
[
{
"namespace": "fxmonitor",
"functions": [
{
"name": "start",
"type": "function",
"async": true,
"parameters": []
}
]
}
]
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/browser-test"
]
};
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
DIRS += [ DIRS += [
'formautofill', 'formautofill',
'fxmonitor',
'pdfjs', 'pdfjs',
'screenshots', 'screenshots',
'webcompat', 'webcompat',
......
...@@ -61,7 +61,6 @@ libs-%: ...@@ -61,7 +61,6 @@ libs-%:
ifneq (,$(wildcard ../extensions/formautofill/locales)) ifneq (,$(wildcard ../extensions/formautofill/locales))
@$(MAKE) -C ../extensions/formautofill/locales AB_CD=$* XPI_NAME=locale-$* @$(MAKE) -C ../extensions/formautofill/locales AB_CD=$* XPI_NAME=locale-$*
endif endif
@$(MAKE) -C ../extensions/fxmonitor/locales AB_CD=$* XPI_NAME=locale-$*
@$(MAKE) -C ../extensions/report-site-issue/locales AB_CD=$* XPI_NAME=locale-$* @$(MAKE) -C ../extensions/report-site-issue/locales AB_CD=$* XPI_NAME=locale-$*
@$(MAKE) -C ../../devtools/client/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)' @$(MAKE) -C ../../devtools/client/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
@$(MAKE) -C ../../devtools/startup/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)' @$(MAKE) -C ../../devtools/startup/locales AB_CD=$* XPI_NAME=locale-$* XPI_ROOT_APPID='$(XPI_ROOT_APPID)'
...@@ -79,7 +78,6 @@ chrome-%: ...@@ -79,7 +78,6 @@ chrome-%:
ifneq (,$(wildcard ../extensions/formautofill/locales)) ifneq (,$(wildcard ../extensions/formautofill/locales))
@$(MAKE) -C ../extensions/formautofill/locales chrome AB_CD=$* @$(MAKE) -C ../extensions/formautofill/locales chrome AB_CD=$*
endif endif
@$(MAKE) -C ../extensions/fxmonitor/locales chrome AB_CD=$*
@$(MAKE) -C ../../devtools/client/locales chrome AB_CD=$* @$(MAKE) -C ../../devtools/client/locales chrome AB_CD=$*
@$(MAKE) -C ../../devtools/startup/locales chrome AB_CD=$* @$(MAKE) -C ../../devtools/startup/locales chrome AB_CD=$*
@$(MAKE) chrome AB_CD=$* @$(MAKE) chrome AB_CD=$*
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
locale/pdfviewer/chrome.properties (%pdfviewer/chrome.properties) locale/pdfviewer/chrome.properties (%pdfviewer/chrome.properties)
locale/browser/newInstall.dtd (%chrome/browser/newInstall.dtd) locale/browser/newInstall.dtd (%chrome/browser/newInstall.dtd)
locale/browser/brandings.dtd (%chrome/browser/brandings.dtd) locale/browser/brandings.dtd (%chrome/browser/brandings.dtd)
locale/browser/fxmonitor.properties (%chrome/browser/fxmonitor.properties)
#ifdef XPI_NAME #ifdef XPI_NAME
# Bug 1240628, restructure how l10n repacks work with feature addons # Bug 1240628, restructure how l10n repacks work with feature addons
......
...@@ -6,7 +6,6 @@ l10n: ...@@ -6,7 +6,6 @@ l10n:
include: include:
- browser/branding/official/locales/en-US - browser/branding/official/locales/en-US
- browser/extensions/formautofill/locales/en-US - browser/extensions/formautofill/locales/en-US
- browser/extensions/fxmonitor/locales/en-US
- browser/extensions/report-site-issue/locales/en-US - browser/extensions/report-site-issue/locales/en-US
- browser/locales/en-US - browser/locales/en-US
- devtools/client/locales/en-US - devtools/client/locales/en-US
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment