Bug 1395460 p1 - Remove usages of about:accounts. r=tcsc

MozReview-Commit-ID: APdGc9avJDw

--HG--
extra : rebase_source : 9da1cea9fb6494c057bc6587a7bcbdb4ac127448
This commit is contained in:
Edouard Oger 2017-10-24 14:05:52 -04:00
Родитель 2a4555d99b
Коммит 58876ecbe9
13 изменённых файлов: 115 добавлений и 128 удалений

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

@ -254,27 +254,14 @@ var gSync = {
PanelUI.hide();
},
openAccountsPage(action, urlParams = {}) {
let params = new URLSearchParams();
if (action) {
params.set("action", action);
}
for (let name in urlParams) {
if (urlParams[name] !== undefined) {
params.set(name, urlParams[name]);
}
}
let url = "about:accounts?" + params;
async openSignInAgainPage(entryPoint) {
const url = await fxAccounts.promiseAccountsForceSigninURI(entryPoint);
switchToTabHavingURI(url, true, {
replaceQueryString: true,
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
},
openSignInAgainPage(entryPoint) {
this.openAccountsPage("reauth", { entrypoint: entryPoint });
},
async openDevicesManagementPage(entryPoint) {
let url = await fxAccounts.promiseAccountsManageDevicesURI(entryPoint);
switchToTabHavingURI(url, true, {

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

@ -59,7 +59,7 @@ add_task(async function setup() {
// The test expects the about:preferences#sync page to open in the current tab
async function openPrefsFromMenuPanel(expectedPanelId, entryPoint) {
info("Check Sync button functionality");
Services.prefs.setCharPref("identity.fxaccounts.remote.signup.uri", "http://example.com/");
Services.prefs.setCharPref("identity.fxaccounts.remote.signup.uri", "https://example.com/");
CustomizableUI.addWidgetToArea("sync-button", CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
await waitForOverflowButtonShown();

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

@ -559,23 +559,23 @@ var gMainPane = {
}
},
onGetStarted(aEvent) {
if (AppConstants.MOZ_DEV_EDITION) {
const Cc = Components.classes, Ci = Components.interfaces;
let win = Services.wm.getMostRecentWindow("navigator:browser");
fxAccounts.getSignedInUser().then(data => {
if (win) {
if (data) {
// We have a user, open Sync preferences in the same tab
win.openUILinkIn("about:preferences#sync", "current");
return;
}
let accountsTab = win.gBrowser.addTab("about:accounts?action=signin&entrypoint=dev-edition-setup");
win.gBrowser.selectedTab = accountsTab;
}
});
async onGetStarted(aEvent) {
if (!AppConstants.MOZ_DEV_EDITION) {
return;
}
const win = Services.wm.getMostRecentWindow("navigator:browser");
if (!win) {
return;
}
const user = await fxAccounts.getSignedInUser();
if (user) {
// We have a user, open Sync preferences in the same tab
win.openUILinkIn("about:preferences#sync", "current");
return;
}
let url = await fxAccounts.promiseAccountsSignInURI("dev-edition-setup");
let accountsTab = win.gBrowser.addTab(url);
win.gBrowser.selectedTab = accountsTab;
},
// HOME PAGE

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

@ -153,6 +153,10 @@ var gSyncPane = {
document.getElementById("verifiedManage").setAttribute("href", accountsManageURI);
});
fxAccounts.promiseAccountsSignUpURI(this._getEntryPoint()).then(signUpURI => {
document.getElementById("noFxaSignUp").setAttribute("href", signUpURI);
});
this.updateWeavePrefs();
// Notify observers that the UI is now ready
@ -355,17 +359,6 @@ var gSyncPane = {
return params.get("entrypoint") || "preferences";
},
_openAboutAccounts(action) {
let entryPoint = this._getEntryPoint();
let params = new URLSearchParams();
if (action) {
params.set("action", action);
}
params.set("entrypoint", entryPoint);
this.replaceTabWithUrl("about:accounts?" + params);
},
openContentInBrowser(url, options) {
let win = Services.wm.getMostRecentWindow("navigator:browser");
if (!win) {
@ -386,16 +379,14 @@ var gSyncPane = {
browser.loadURI(url);
},
signUp() {
this._openAboutAccounts("signup");
async signIn() {
const url = await fxAccounts.promiseAccountsSignInURI(this._getEntryPoint());
this.replaceTabWithUrl(url);
},
signIn() {
this._openAboutAccounts("signin");
},
reSignIn() {
this._openAboutAccounts("reauth");
async reSignIn() {
const url = await fxAccounts.promiseAccountsForceSigninURI(this._getEntryPoint());
this.replaceTabWithUrl(url);
},

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

@ -69,9 +69,7 @@
<hbox align="center" flex="1">
<html:a id="noFxaSignUp"
class="openLink"
accesskey="&signedOut.accountBox.create2.accesskey;"
onclick="gSyncPane.signUp();"
onkeypress="gSyncPane.signUp();">&signedOut.accountBox.create2;</html:a>
accesskey="&signedOut.accountBox.create2.accesskey;">&signedOut.accountBox.create2;</html:a>
</hbox>
</vbox>
</hbox>

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

@ -573,18 +573,18 @@ if (typeof Mozilla == "undefined") {
* for the URL opened by the browser.
* @since 31, 47 for `extraURLCampaignParams`
* @example
* // Will open about:accounts?action=signup&entrypoint=uitour
* // Will open https://accounts.firefox.com/signup?entrypoint=uitour
* Mozilla.UITour.showFirefoxAccounts();
* @example
* // Will open:
* // about:accounts?action=signup&entrypoint=uitour&utm_foo=bar&utm_bar=baz
* // https://accounts.firefox.com/signup?entrypoint=uitour&utm_foo=bar&utm_bar=baz
* Mozilla.UITour.showFirefoxAccounts({
* 'utm_foo': 'bar',
* 'utm_bar': 'baz'
* });
* @example
* // Will open:
* // about:accounts?action=signup&entrypoint=uitour&email=foo%40bar.com
* // https://accounts.firefox.com/?action=email&email=foo%40bar.com&entrypoint=uitour
* Mozilla.UITour.showFirefoxAccounts(null, "foo@bar.com");
*/
Mozilla.UITour.showFirefoxAccounts = function(extraURLCampaignParams, email) {

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

@ -34,6 +34,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "ReaderParent",
"resource:///modules/ReaderParent.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PageActions",
"resource:///modules/PageActions.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
"resource://gre/modules/FxAccounts.jsm");
// See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
const PREF_LOG_LEVEL = "browser.uitour.loglevel";
@ -548,25 +550,20 @@ this.UITour = {
}
case "showFirefoxAccounts": {
let p;
if (data.email) {
// With email parameter added, we need to use 'email' action to help FxA determine
// whether the email is registered or not and direct the user down the correct flow
p = new URLSearchParams("action=email&entrypoint=uitour");
p.append("email", data.email);
} else {
// 'signup' is the default action that makes sense currently, so we don't
// accept arbitrary actions just to be safe...
p = new URLSearchParams("action=signup&entrypoint=uitour");
}
// Call our helper to validate extraURLCampaignParams and populate URLSearchParams
if (!this._populateCampaignParams(p, data.extraURLCampaignParams)) {
log.warn("showFirefoxAccounts: invalid campaign args specified");
return false;
}
Promise.resolve().then(() => {
return data.email ? fxAccounts.promiseAccountsEmailURI(data.email, "uitour") :
fxAccounts.promiseAccountsSignUpURI("uitour");
}).then(uri => {
const url = new URL(uri);
// Call our helper to validate extraURLCampaignParams and populate URLSearchParams
if (!this._populateCampaignParams(url, data.extraURLCampaignParams)) {
log.warn("showFirefoxAccounts: invalid campaign args specified");
return false;
}
// We want to replace the current tab.
browser.loadURI("about:accounts?" + p.toString());
// We want to replace the current tab.
browser.loadURI(url.href);
});
break;
}
@ -761,9 +758,9 @@ this.UITour = {
// Given a string that is a JSONified represenation of an object with
// additional utm_* URL params that should be appended, validate and append
// them to the passed URLSearchParams object. Returns true if the params
// them to the passed URL object. Returns true if the params
// were validated and appended, and false if the request should be ignored.
_populateCampaignParams(urlSearchParams, extraURLCampaignParams) {
_populateCampaignParams(url, extraURLCampaignParams) {
// We are extra paranoid about what params we allow to be appended.
if (typeof extraURLCampaignParams == "undefined") {
// no params, so it's all good.
@ -799,7 +796,7 @@ this.UITour = {
log.warn("_populateCampaignParams: invalid campaign param specified");
return false;
}
urlSearchParams.append(name, value);
url.searchParams.append(name, value);
}
}
return true;

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

@ -5,11 +5,20 @@ var gContentAPI;
var gContentWindow;
registerCleanupFunction(function() {
Services.prefs.clearUserPref("identity.fxaccounts.remote.signup.uri");
Services.prefs.clearUserPref("identity.fxaccounts.remote.email.uri");
Services.prefs.clearUserPref("services.sync.username");
});
add_task(setup_UITourTest);
add_task(async function setup() {
Services.prefs.setCharPref("identity.fxaccounts.remote.signup.uri",
"https://example.com/signup");
Services.prefs.setCharPref("identity.fxaccounts.remote.email.uri",
"https://example.com/?action=email");
})
add_UITour_task(async function test_checkSyncSetup_disabled() {
let result = await getConfigurationPromise("sync");
is(result.setup, false, "Sync shouldn't be setup by default");
@ -51,25 +60,25 @@ add_UITour_task(async function test_checkSyncCounts() {
// The showFirefoxAccounts API is sync related, so we test that here too...
add_UITour_task(async function test_firefoxAccountsNoParams() {
info("Load about:accounts containing an iframe to https://accounts.firefox.com");
info("Load https://accounts.firefox.com");
await gContentAPI.showFirefoxAccounts();
await BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
"about:accounts?action=signup&entrypoint=uitour");
"https://example.com/signup?entrypoint=uitour");
});
add_UITour_task(async function test_firefoxAccountsValidParams() {
info("Load about:accounts containing an iframe to https://accounts.firefox.com");
info("Load https://accounts.firefox.com");
await gContentAPI.showFirefoxAccounts({ utm_foo: "foo", utm_bar: "bar" });
await BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
"about:accounts?action=signup&entrypoint=uitour&utm_foo=foo&utm_bar=bar");
"https://example.com/signup?entrypoint=uitour&utm_foo=foo&utm_bar=bar");
});
add_UITour_task(async function test_firefoxAccountsWithEmail() {
info("Load about:accounts containing an iframe to https://accounts.firefox.com");
info("Load https://accounts.firefox.com");
await gContentAPI.showFirefoxAccounts(null, "foo@bar.com");
await BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
"about:accounts?action=email&entrypoint=uitour&email=foo%40bar.com");
"https://example.com/?action=email&email=foo%40bar.com&entrypoint=uitour");
});
add_UITour_task(async function test_firefoxAccountsNonAlphaValue() {
@ -79,38 +88,38 @@ add_UITour_task(async function test_firefoxAccountsNonAlphaValue() {
let value = "foo& /=?:\\\xa9";
// encodeURIComponent encodes spaces to %20 but we want "+"
let expected = encodeURIComponent(value).replace(/%20/g, "+");
info("Load about:accounts containing an iframe to https://accounts.firefox.com");
info("Load https://accounts.firefox.com");
await gContentAPI.showFirefoxAccounts({ utm_foo: value });
await BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser, false,
"about:accounts?action=signup&entrypoint=uitour&utm_foo=" + expected);
"https://example.com/signup?entrypoint=uitour&utm_foo=" + expected);
});
// A helper to check the request was ignored due to invalid params.
async function checkAboutAccountsNotLoaded() {
async function checkFxANotLoaded() {
try {
await waitForConditionPromise(() => {
return gBrowser.selectedBrowser.currentURI.spec.startsWith("about:accounts");
}, "Check if about:accounts opened");
ok(false, "No about:accounts tab should have opened");
return gBrowser.selectedBrowser.currentURI.spec.startsWith("https://example.com");
}, "Check if FxA opened");
ok(false, "No FxA tab should have opened");
} catch (ex) {
ok(true, "No about:accounts tab opened");
ok(true, "No FxA tab opened");
}
}
add_UITour_task(async function test_firefoxAccountsNonObject() {
// non-string should be rejected.
await gContentAPI.showFirefoxAccounts(99);
await checkAboutAccountsNotLoaded();
await checkFxANotLoaded();
});
add_UITour_task(async function test_firefoxAccountsNonUtmPrefix() {
// Any non "utm_" name should should be rejected.
await gContentAPI.showFirefoxAccounts({ utm_foo: "foo", bar: "bar" });
await checkAboutAccountsNotLoaded();
await checkFxANotLoaded();
});
add_UITour_task(async function test_firefoxAccountsNonAlphaName() {
// Any "utm_" name which includes non-alpha chars should be rejected.
await gContentAPI.showFirefoxAccounts({ utm_foo: "foo", "utm_bar=": "bar" });
await checkAboutAccountsNotLoaded();
await checkFxANotLoaded();
});

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

@ -13,6 +13,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "ShellService",
"resource:///modules/ShellService.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ProfileAge",
"resource://gre/modules/ProfileAge.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
"resource://gre/modules/FxAccounts.jsm");
// Url to fetch snippets, in the urlFormatter service format.
const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl";
@ -124,9 +126,10 @@ this.SnippetsFeed = class SnippetsFeed {
this.store.dispatch(ac.BroadcastToContent({type: at.SNIPPETS_RESET}));
}
showFirefoxAccounts(browser) {
async showFirefoxAccounts(browser) {
const url = await fxAccounts.promiseAccountsSignUpURI("snippets");
// We want to replace the current tab.
browser.loadURI("about:accounts?action=signup&entrypoint=snippets");
browser.loadURI(url);
}
onAction(action) {

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

@ -77,15 +77,11 @@ onboarding.tour-sync.logged-in.title=Youre signed in to Sync!
onboarding.tour-sync.logged-in.description=Sync works when youre signed in to %1$S on more than one device. Have a mobile device? Install the %1$S app and sign in to get your bookmarks, history, and passwords on the go.
# LOCALIZATION NOTE(onboarding.tour-sync.form.title): This string is displayed
# as a title and followed by onboarding.tour-sync.form.description.
# Your translation should be consistent with the form displayed in
# about:accounts when signing up to Firefox Account.
onboarding.tour-sync.form.title=Create a Firefox Account
# LOCALIZATION NOTE(onboarding.tour-sync.form.description): The description
# continues after onboarding.tour-sync.form.title to create a complete sentence.
# If it's not possible for your locale, you can translate this string as
# "Continue to Firefox Sync" instead.
# Your translation should be consistent with the form displayed in
# about:accounts when signing up to Firefox Account.
onboarding.tour-sync.form.description=to continue to Firefox Sync
onboarding.tour-sync.button=Next
onboarding.tour-sync.email-input.placeholder=Email

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

@ -13,9 +13,9 @@ add_task(async function runTests() {
let browser = tab.linkedBrowser;
browser.loadURI("about:accounts");
browser.loadURI("about:healthreport");
let href = await BrowserTestUtils.browserLoaded(browser);
is(href, "about:accounts", "Check about:accounts loaded");
is(href, "about:healthreport", "Check about:healthreport loaded");
// Using a dummy onunload listener to disable the bfcache as that can prevent
// the test browser load detection mechanism from working.
@ -26,7 +26,7 @@ add_task(async function runTests() {
browser.goBack();
href = await BrowserTestUtils.browserLoaded(browser);
is(href, "about:accounts", "Check we've gone back to about:accounts");
is(href, "about:healthreport", "Check we've gone back to about:healthreport");
browser.goForward();
href = await BrowserTestUtils.browserLoaded(browser);

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

@ -1297,16 +1297,29 @@ FxAccountsInternal.prototype = {
return allowHttp !== true;
},
promiseAccountsSignUpURI() {
return FxAccountsConfig.promiseAccountsSignUpURI();
async promiseAccountsSignUpURI(entrypoint) {
const url = new URL((await FxAccountsConfig.promiseAccountsSignUpURI()));
if (entrypoint) {
url.searchParams.append("entrypoint", entrypoint);
}
return url.href;
},
promiseAccountsSignInURI() {
return FxAccountsConfig.promiseAccountsSignInURI();
async promiseAccountsSignInURI(entrypoint) {
const url = new URL((await FxAccountsConfig.promiseAccountsSignInURI()));
if (entrypoint) {
url.searchParams.append("entrypoint", entrypoint);
}
return url.href;
},
promiseAccountsEmailURI() {
return FxAccountsConfig.promiseAccountsEmailURI();
async promiseAccountsEmailURI(email, entrypoint) {
const url = new URL((await FxAccountsConfig.promiseAccountsEmailURI()));
url.searchParams.append("email", email);
if (entrypoint) {
url.searchParams.append("entrypoint", entrypoint);
}
return url.href;
},
/**
@ -1342,9 +1355,9 @@ FxAccountsInternal.prototype = {
// Returns a promise that resolves with the URL to use to force a re-signin
// of the current account.
async promiseAccountsForceSigninURI() {
async promiseAccountsForceSigninURI(entrypoint) {
await FxAccountsConfig.ensureConfigured();
return this._formatPrefURL("identity.fxaccounts.remote.force_auth.uri");
return this._formatPrefURL("identity.fxaccounts.remote.force_auth.uri", entrypoint);
},
// Returns a promise that resolves with the URL to use to change

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

@ -33,10 +33,9 @@ const CONFIG_PREFS = [
this.FxAccountsConfig = {
// Returns a promise that resolves with the URI of the remote UI flows.
async promiseAccountsSignUpURI() {
async _getPrefURL(prefName) {
await this.ensureConfigured();
let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.remote.signup.uri");
let url = Services.urlFormatter.formatURLPref(prefName);
if (fxAccounts.requiresHttps() && !/^https:/.test(url)) { // Comment to un-break emacs js-mode highlighting
throw new Error("Firefox Accounts server must use HTTPS");
}
@ -44,23 +43,17 @@ this.FxAccountsConfig = {
},
// Returns a promise that resolves with the URI of the remote UI flows.
async promiseAccountsSignInURI() {
await this.ensureConfigured();
let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.remote.signin.uri");
if (fxAccounts.requiresHttps() && !/^https:/.test(url)) { // Comment to un-break emacs js-mode highlighting
throw new Error("Firefox Accounts server must use HTTPS");
}
return url;
promiseAccountsSignUpURI() {
return this._getPrefURL("identity.fxaccounts.remote.signup.uri");
},
// Returns a promise that resolves with the URI of the remote UI flows.
async promiseAccountsEmailURI() {
await this.ensureConfigured();
let url = Services.urlFormatter.formatURLPref("identity.fxaccounts.remote.email.uri");
if (fxAccounts.requiresHttps() && !/^https:/.test(url)) { // Comment to un-break emacs js-mode highlighting
throw new Error("Firefox Accounts server must use HTTPS");
}
return url;
promiseAccountsSignInURI() {
return this._getPrefURL("identity.fxaccounts.remote.signin.uri");
},
promiseAccountsEmailURI() {
return this._getPrefURL("identity.fxaccounts.remote.email.uri");
},
resetConfigURLs() {