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
This commit is contained in:
Andrew Swan 2019-08-23 14:27:55 +00:00
Родитель 31eced3689
Коммит d697e6aa9a
20 изменённых файлов: 47 добавлений и 239 удалений

Просмотреть файл

@ -514,6 +514,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
Corroborate: "resource://gre/modules/Corroborate.jsm",
Discovery: "resource:///modules/Discovery.jsm",
ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
FirefoxMonitor: "resource:///modules/FirefoxMonitor.jsm",
FxAccounts: "resource://gre/modules/FxAccounts.jsm",
HomePage: "resource:///modules/HomePage.jsm",
HybridContentTelemetry: "resource://gre/modules/HybridContentTelemetry.jsm",
@ -1998,6 +1999,8 @@ BrowserGlue.prototype = {
if (pService.createdAlternateProfile) {
this._showNewInstallModal();
}
FirefoxMonitor.init();
},
/**

Просмотреть файл

@ -2,55 +2,25 @@
* 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/. */
/* globals ExtensionAPI, XPCOMUtils */
"use strict";
ChromeUtils.defineModuleGetter(
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 EXPORTED_SYMBOLS = ["FirefoxMonitor"];
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
EveryWindow: "resource:///modules/EveryWindow.jsm",
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",
});
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
this.fxmonitor = class extends ExtensionAPI {
getAPI(context) {
return {
fxmonitor: {
async start() {
await FirefoxMonitor.init(context.extension);
},
},
};
}
onShutdown(shutdownReason) {
if (Services.startup.shuttingDown) {
return;
}
FirefoxMonitor.stopObserving();
}
};
const STYLESHEET = "chrome://browser/content/fxmonitor/FirefoxMonitor.css";
const ICON = "chrome://browser/content/fxmonitor/monitor32.svg";
this.FirefoxMonitor = {
// Map of breached site host -> breach metadata.
@ -101,10 +71,6 @@ this.FirefoxMonitor = {
Preferences.set(this.kEnabledPref, false);
},
getURL(aPath) {
return this.extension.getURL(aPath);
},
getString(aKey) {
return this.strings.GetStringFromName(aKey);
},
@ -138,9 +104,7 @@ this.FirefoxMonitor = {
Preferences.reset(this.kWarnedHostsPref);
},
init(aExtension) {
this.extension = aExtension;
init() {
XPCOMUtils.defineLazyPreferenceGetter(
this,
"enabled",
@ -200,6 +164,9 @@ this.FirefoxMonitor = {
},
});
let telemetryEnabled = !Preferences.get(this.kTelemetryDisabledPref);
Services.telemetry.setEventRecordingEnabled("fxmonitor", telemetryEnabled);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"FirefoxMonitorURL",
@ -214,6 +181,12 @@ this.FirefoxMonitor = {
false
);
XPCOMUtils.defineLazyGetter(this, "strings", () => {
return Services.strings.createBundle(
"chrome://browser/locale/fxmonitor.properties"
);
});
XPCOMUtils.defineLazyPreferenceGetter(
this,
"telemetryDisabled",
@ -221,37 +194,9 @@ this.FirefoxMonitor = {
false
);
await this.loadStrings();
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",
async loadBreaches() {
let populateSites = data => {
@ -358,7 +303,7 @@ this.FirefoxMonitor = {
let DOMWindowUtils = win.windowUtils;
DOMWindowUtils.removeSheetUsingURIString(
this.getURL("privileged/FirefoxMonitor.css"),
STYLESHEET,
DOMWindowUtils.AUTHOR_SHEET
);
@ -389,7 +334,7 @@ this.FirefoxMonitor = {
// Inject our stylesheet.
let DOMWindowUtils = win.windowUtils;
DOMWindowUtils.loadSheetUsingURIString(
this.getURL("privileged/FirefoxMonitor.css"),
STYLESHEET,
DOMWindowUtils.AUTHOR_SHEET
);
@ -406,7 +351,7 @@ this.FirefoxMonitor = {
let img = doc.createElementNS(XUL_NS, "image");
img.setAttribute("role", "button");
img.classList.add(`${this.kNotificationID}-icon`);
img.style.listStyleImage = `url(${this.getURL("assets/monitor32.svg")})`;
img.style.listStyleImage = `url(${ICON})`;
anchorBox.appendChild(img);
notificationBox.appendChild(anchorBox);
img.setAttribute(
@ -551,7 +496,7 @@ this.FirefoxMonitor = {
persistent: true,
hideClose: true,
eventCallback: populatePanel,
popupIconURL: this.getURL("assets/monitor32.svg"),
popupIconURL: ICON,
}
);

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.6 KiB

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Просмотреть файл

@ -3,6 +3,6 @@
# 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/.
[features/fxmonitor@mozilla.org] @AB_CD@.jar:
% locale fxmonitor @AB_CD@ %locale/@AB_CD@/
locale/@AB_CD@/fxmonitor.properties (%fxmonitor.properties)
browser.jar:
content/browser/fxmonitor/FirefoxMonitor.css (content/FirefoxMonitor.css)
content/browser/fxmonitor/monitor32.svg (content/monitor32.svg)

Просмотреть файл

@ -4,4 +4,14 @@
# 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/.
with Files('**'):
BUG_COMPONENT = ('Firefox', 'Firefox Monitor')
EXTRA_JS_MODULES += [
'FirefoxMonitor.jsm',
]
JAR_MANIFESTS += ['jar.mn']
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']

Просмотреть файл

@ -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() {
info("Test that we show the first alert correctly for a recent breach.");

Просмотреть файл

@ -36,6 +36,7 @@ DIRS += [
'downloads',
'enterprisepolicies',
'extensions',
'fxmonitor',
'library',
'migration',
'newtab',

Просмотреть файл

@ -1,6 +0,0 @@
<!-- 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>

До

Ширина:  |  Высота:  |  Размер: 550 B

Просмотреть файл

@ -1,9 +0,0 @@
/* 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();

Просмотреть файл

@ -1,24 +0,0 @@
{
"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"]]
}
}
}
}

Просмотреть файл

@ -1,31 +0,0 @@
# -*- 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')

Просмотреть файл

@ -1,13 +0,0 @@
[
{
"namespace": "fxmonitor",
"functions": [
{
"name": "start",
"type": "function",
"async": true,
"parameters": []
}
]
}
]

Просмотреть файл

@ -1,7 +0,0 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/browser-test"
]
};

Просмотреть файл

@ -6,7 +6,6 @@
DIRS += [
'formautofill',
'fxmonitor',
'pdfjs',
'screenshots',
'webcompat',

Просмотреть файл

@ -61,7 +61,6 @@ libs-%:
ifneq (,$(wildcard ../extensions/formautofill/locales))
@$(MAKE) -C ../extensions/formautofill/locales AB_CD=$* XPI_NAME=locale-$*
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 ../../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)'
@ -79,7 +78,6 @@ chrome-%:
ifneq (,$(wildcard ../extensions/formautofill/locales))
@$(MAKE) -C ../extensions/formautofill/locales chrome AB_CD=$*
endif
@$(MAKE) -C ../extensions/fxmonitor/locales chrome AB_CD=$*
@$(MAKE) -C ../../devtools/client/locales chrome AB_CD=$*
@$(MAKE) -C ../../devtools/startup/locales chrome AB_CD=$*
@$(MAKE) chrome AB_CD=$*

Просмотреть файл

@ -58,6 +58,7 @@
locale/pdfviewer/chrome.properties (%pdfviewer/chrome.properties)
locale/browser/newInstall.dtd (%chrome/browser/newInstall.dtd)
locale/browser/brandings.dtd (%chrome/browser/brandings.dtd)
locale/browser/fxmonitor.properties (%chrome/browser/fxmonitor.properties)
#ifdef XPI_NAME
# Bug 1240628, restructure how l10n repacks work with feature addons

Просмотреть файл

@ -6,7 +6,6 @@ l10n:
include:
- browser/branding/official/locales/en-US
- browser/extensions/formautofill/locales/en-US
- browser/extensions/fxmonitor/locales/en-US
- browser/extensions/report-site-issue/locales/en-US
- browser/locales/en-US
- devtools/client/locales/en-US