Bug 1448971 - Replace "when Firefox starts" section in about:preferences#general with checkbox r=flod,jaws

MozReview-Commit-ID: JHL20S5gZq2

--HG--
extra : rebase_source : 7b6462b85cf44f69ac978115656b724a59a935a6
This commit is contained in:
k88hudson 2018-04-04 12:28:22 -04:00
Родитель 295ace1eb2
Коммит f37daeac63
7 изменённых файлов: 139 добавлений и 79 удалений

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

@ -25,11 +25,12 @@ async function check_homepage({expectedURL, expectedPageVal = 1, locked = false}
await ContentTask.spawn(tab.linkedBrowser, {expectedURL, expectedPageVal, locked},
// eslint-disable-next-line no-shadow
async function({expectedURL, expectedPageVal, locked}) {
let startupPageRadioGroup = content.document.getElementById("browserStartupPage");
is(startupPageRadioGroup.disabled, locked,
"Disabled status of start page radio group should match expected");
is(startupPageRadioGroup.value, expectedPageVal,
"Value of start page radio group should match expected");
let browserRestoreSessionCheckbox = content.document.getElementById("browserRestoreSession");
is(browserRestoreSessionCheckbox.disabled, locked,
"Disabled status of session restore status should match expected");
let shouldBeChecked = expectedPageVal === 3;
is(browserRestoreSessionCheckbox.checked, shouldBeChecked,
"Session restore status checkbox should be: " + (shouldBeChecked ? "checked" : "unchecked"));
content.document.getElementById("category-home").click();
@ -39,6 +40,9 @@ async function check_homepage({expectedURL, expectedPageVal = 1, locked = false}
// is(homepageTextbox.value, expectedURL,
// "Homepage URL should match expected");
// Wait for rendering to be finished
await ContentTaskUtils.waitForCondition(() => content.document.getElementById("useCurrentBtn").disabled === locked);
is(homepageTextbox.disabled, locked,
"Homepage URL text box disabled status should match expected");
is(content.document.getElementById("homeMode").disabled, locked,

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

@ -4,6 +4,7 @@
/* import-globals-from extensionControlled.js */
/* import-globals-from preferences.js */
/* import-globals-from main.js */
// HOME PAGE
@ -67,38 +68,67 @@ let gHomePane = {
/**
* _renderCustomSettings: Hides or shows the UI for setting a custom
* homepage URL
* @param {bool} shouldShow Should the custom UI be shown?
* @param {obj} options
* @param {bool} options.shouldShow Should the custom UI be shown?
* @param {bool} options.isControlled Is an extension controlling the home page?
*/
_renderCustomSettings(shouldShow) {
_renderCustomSettings(options = {}) {
let {shouldShow, isControlled} = options;
const customSettingsContainerEl = document.getElementById("customSettings");
const customUrlEl = document.getElementById("homePageUrl");
const isHomepageCustom = !this._isHomePageDefaultValue() && !this._isHomePageBlank();
if (typeof shouldShow === "undefined") shouldShow = isHomepageCustom;
const homePref = Preferences.get("browser.startup.homepage");
const isHomePageCustom = isControlled || (!this._isHomePageDefaultValue() && !this.isHomePageBlank());
if (typeof shouldShow === "undefined") {
shouldShow = isHomePageCustom;
}
customSettingsContainerEl.hidden = !shouldShow;
if (isHomepageCustom) {
customUrlEl.value = Preferences.get("browser.startup.homepage").value;
// We can't use isHomePageDefaultValue and isHomePageBlank here because we want to disregard the blank
// possibility triggered by the browser.startup.page being 0.
let newValue;
if (homePref.value !== homePref.defaultValue && homePref.value !== "about:blank") {
newValue = homePref.value;
} else {
customUrlEl.value = "";
newValue = "";
}
if (customUrlEl.value !== newValue) {
customUrlEl.value = newValue;
}
},
/**
* _isHomePageDefaultValue
* @param {bool} isControlled Is an extension controlling the home page?
* @returns {bool} Is the homepage set to the default pref value?
*/
_isHomePageDefaultValue() {
const startupPref = Preferences.get("browser.startup.page");
const homePref = Preferences.get("browser.startup.homepage");
return homePref.value === homePref.defaultValue;
return startupPref.value !== gMainPane.STARTUP_PREF_BLANK && homePref.value === homePref.defaultValue;
},
/**
* _isHomePageBlank
* isHomePageBlank
* @returns {bool} Is the homepage set to about:blank?
*/
_isHomePageBlank() {
isHomePageBlank() {
const startupPref = Preferences.get("browser.startup.page");
const homePref = Preferences.get("browser.startup.homepage");
return homePref.value === "about:blank" || homePref.value === "";
return homePref.value === "about:blank" || homePref.value === "" || startupPref.value === gMainPane.STARTUP_PREF_BLANK;
},
/**
* isHomePageControlled
* @resolves {bool} Is the homepage being controlled by an extension?
* @returns {Promise}
*/
isHomePageControlled() {
const homePref = Preferences.get("browser.startup.homepage");
if (homePref.locked) {
return Promise.resolve(false);
}
return handleControllingExtension(
PREF_SETTING_TYPE, HOMEPAGE_OVERRIDE_KEY, "extensionControlled.homepage_override2");
},
/**
@ -129,17 +159,23 @@ let gHomePane = {
return tabs;
},
_renderHomepageMode() {
_renderHomepageMode(isControlled) {
const isDefault = this._isHomePageDefaultValue();
const isBlank = this._isHomePageBlank();
const isBlank = this.isHomePageBlank();
const el = document.getElementById("homeMode");
let newValue;
if (isDefault) {
el.value = this.HOME_MODE_FIREFOX_HOME;
if (isControlled) {
newValue = this.HOME_MODE_CUSTOM;
} else if (isDefault) {
newValue = this.HOME_MODE_FIREFOX_HOME;
} else if (isBlank) {
el.value = this.HOME_MODE_BLANK;
newValue = this.HOME_MODE_BLANK;
} else {
el.value = this.HOME_MODE_CUSTOM;
newValue = this.HOME_MODE_CUSTOM;
}
if (el.value !== newValue) {
el.value = newValue;
}
},
@ -172,15 +208,14 @@ let gHomePane = {
hideControllingExtension(HOMEPAGE_OVERRIDE_KEY);
this._setInputDisabledStates(false);
} else {
// Asynchronously update the extension controlled UI.
const isHomePageControlled = await handleControllingExtension(
PREF_SETTING_TYPE, HOMEPAGE_OVERRIDE_KEY, "extensionControlled.homepage_override2");
this._setInputDisabledStates(isHomePageControlled);
const isControlled = await this.isHomePageControlled();
this._setInputDisabledStates(isControlled);
this._renderCustomSettings({isControlled});
this._renderHomepageMode(isControlled);
}
},
syncFromHomePref() {
// Set the "Use Current Page(s)" button's text and enabled state.
this._updateUseCurrentButton();
this._renderCustomSettings();
this._renderHomepageMode();
@ -198,24 +233,29 @@ let gHomePane = {
onMenuChange(event) {
const {value} = event.target;
const startupPref = Preferences.get("browser.startup.page");
const homePref = Preferences.get("browser.startup.homepage");
switch (value) {
case this.HOME_MODE_FIREFOX_HOME:
if (startupPref.value === gMainPane.STARTUP_PREF_BLANK) {
startupPref.value = gMainPane.STARTUP_PREF_HOMEPAGE;
}
if (homePref.value !== homePref.defaultValue) {
homePref.value = homePref.defaultValue;
} else {
this._renderCustomSettings(false);
this._renderCustomSettings({shouldShow: false});
}
break;
case this.HOME_MODE_BLANK:
if (homePref.value !== "about:blank") {
homePref.value = "about:blank";
} else {
this._renderCustomSettings(false);
this._renderCustomSettings({shouldShow: false});
}
break;
case this.HOME_MODE_CUSTOM:
this._renderCustomSettings(true);
this._renderCustomSettings({shouldShow: true});
break;
}
},
@ -237,8 +277,9 @@ let gHomePane = {
// In this case, the button's disabled state is set by preferences.xml.
let prefName = "pref.browser.homepage.disable_button.current_page";
if (Preferences.get(prefName).locked)
if (Preferences.get(prefName).locked) {
return;
}
useCurrent.disabled = tabCount < 1;
},

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

@ -257,6 +257,10 @@ var gMainPane = {
// A hash of integer counts, indexed by string description.
_visibleTypeDescriptionCount: {},
// browser.startup.page values
STARTUP_PREF_BLANK: 0,
STARTUP_PREF_HOMEPAGE: 1,
STARTUP_PREF_RESTORE_SESSION: 3,
// Convenience & Performance Shortcuts
@ -344,8 +348,6 @@ var gMainPane = {
});
this.updatePerformanceSettingsBox({ duringChangeEvent: false });
this.updateBrowserStartupLastSession();
let connectionSettingsLink = document.getElementById("connectionSettingsLearnMore");
let connectionSettingsUrl = Services.urlFormatter.formatURLPref("app.support.baseURL") +
"prefs-connection-settings";
@ -371,8 +373,18 @@ var gMainPane = {
if (!TransientPrefs.prefShouldBeVisible("browser.tabs.warnOnOpen"))
document.getElementById("warnOpenMany").hidden = true;
// Startup pref
setEventListener("browserRestoreSession", "command",
gMainPane.onBrowserRestoreSessionChange);
gMainPane.updateBrowserStartupUI = gMainPane.updateBrowserStartupUI.bind(gMainPane);
Preferences.get("browser.privatebrowsing.autostart").on("change",
gMainPane.updateBrowserStartupLastSession.bind(gMainPane));
gMainPane.updateBrowserStartupUI);
Preferences.get("browser.startup.page").on("change",
gMainPane.updateBrowserStartupUI);
Preferences.get("browser.startup.homepage").on("change",
gMainPane.updateBrowserStartupUI);
gMainPane.updateBrowserStartupUI();
if (AppConstants.HAVE_SHELL_SERVICE) {
setEventListener("setDefaultButton", "command",
gMainPane.setDefaultBrowser);
@ -711,7 +723,7 @@ var gMainPane = {
* browser.startup.page
* - what page(s) to show when the user starts the application, as an integer:
*
* 0: a blank page
* 0: a blank page (DEPRECATED - this can be set via browser.startup.homepage)
* 1: the home page (as set by the browser.startup.homepage pref)
* 2: the last page the user visited (DEPRECATED)
* 3: windows and tabs from the last session (a.k.a. session restore)
@ -736,20 +748,39 @@ var gMainPane = {
* Hide/show the "Show my windows and tabs from last time" option based
* on the value of the browser.privatebrowsing.autostart pref.
*/
updateBrowserStartupLastSession() {
let pbAutoStartPref = Preferences.get("browser.privatebrowsing.autostart");
let startupPref = Preferences.get("browser.startup.page");
let group = document.getElementById("browserStartupPage");
let option = document.getElementById("browserStartupLastSession");
if (pbAutoStartPref.value) {
option.setAttribute("disabled", "true");
if (option.selected) {
group.selectedItem = document.getElementById("browserStartupHomePage");
}
updateBrowserStartupUI() {
const pbAutoStartPref = Preferences.get("browser.privatebrowsing.autostart");
const startupPref = Preferences.get("browser.startup.page");
let newValue;
let checkbox = document.getElementById("browserRestoreSession");
if (pbAutoStartPref.value || startupPref.locked) {
checkbox.setAttribute("disabled", "true");
newValue = false;
} else {
option.removeAttribute("disabled");
startupPref.updateElements(); // select the correct radio in the startup group
checkbox.removeAttribute("disabled");
newValue = startupPref.value === this.STARTUP_PREF_RESTORE_SESSION;
}
if (checkbox.checked !== newValue) {
checkbox.checked = newValue;
}
},
onBrowserRestoreSessionChange(event) {
const value = event.target.checked;
const startupPref = Preferences.get("browser.startup.page");
let newValue;
if (value) {
// We need to restore the blank homepage setting in our other pref
if (startupPref.value === this.STARTUP_PREF_BLANK) {
Preferences.get("browser.startup.homepage").value = "about:blank";
}
newValue = this.STARTUP_PREF_RESTORE_SESSION;
} else {
newValue = this.STARTUP_PREF_HOMEPAGE;
}
startupPref.value = newValue;
},
// TABS

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

@ -43,6 +43,11 @@
</vbox>
#endif
<vbox id="startupPageBox">
<checkbox id="browserRestoreSession"
data-l10n-id="startup-restore-previous-session"/>
</vbox>
#ifdef HAVE_SHELL_SERVICE
<vbox id="defaultBrowserBox">
<checkbox id="alwaysCheckDefault" preference="browser.shell.checkDefaultBrowser"
@ -64,23 +69,6 @@
</vbox>
#endif
<vbox id="startupPageBox">
<label data-l10n-id="startup-page"
control="browserStartupPage"/>
<radiogroup id="browserStartupPage"
preference="browser.startup.page">
<radio data-l10n-id="startup-user-homepage"
value="1"
id="browserStartupHomePage"/>
<radio data-l10n-id="startup-blank-page"
value="0"
id="browserStartupBlank"/>
<radio data-l10n-id="startup-prev-session"
value="3"
id="browserStartupLastSession"/>
</radiogroup>
</vbox>
</groupbox>
<!-- Tab preferences -->

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

@ -14,7 +14,14 @@ add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("paneHome", {leaveOpen: true});
// Set custom URL so bookmark button will be shown on the page (otherwise it is hidden)
await SpecialPowers.pushPrefEnv({"set": [["browser.startup.homepage", "about:robots"]]});
await SpecialPowers.pushPrefEnv({"set": [
["browser.startup.homepage", "about:robots"],
["browser.startup.page", 1]
]});
// Wait for Activity Stream to add its panels
await BrowserTestUtils.waitForCondition(() => ContentTask.spawn(gBrowser.selectedTab.linkedBrowser, {},
async () => content.document.getElementById("homeContentsGroup")));
await evaluateSearchResults("Set Home Page", "homepageGroup");
BrowserTestUtils.removeTab(gBrowser.selectedTab);

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

@ -112,16 +112,10 @@ set-as-my-default-browser =
.label = Make Default…
.accesskey = D
startup-page = When { -brand-short-name } starts
startup-restore-previous-session =
.label = Restore previous session
.accesskey = s
startup-user-homepage =
.label = Show your home page
startup-blank-page =
.label = Show a blank page
startup-prev-session =
.label = Show your windows and tabs from last time
disable-extension =
.label = Disable Extension

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

@ -180,10 +180,6 @@ button > hbox > label {
font-weight: 600;
}
#startupPageBox {
padding-top: 32px;
}
.extension-controlled-icon {
height: 20px;
margin: 2px 0 6px;
@ -250,8 +246,7 @@ button > hbox > label {
margin-inline-start: 6px !important;
}
#updateRadioGroup > radio,
#browserStartupPage > radio {
#updateRadioGroup > radio {
height: 30px;
margin: 2px 0;
}