Bug 1306561 - Make the Restore Default button take into account that the devedition theme is the default in devedition builds. r?jaws
MozReview-Commit-ID: 3gIOZuaXOO1
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -33,16 +33,17 @@ XPCOMUtils.defineLazyModuleGetter(this,
const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const kSpecialWidgetPfx = "customizableui-special-";
const kPrefCustomizationState = "browser.uiCustomization.state";
const kPrefCustomizationAutoAdd = "browser.uiCustomization.autoAdd";
const kPrefCustomizationDebug = "browser.uiCustomization.debug";
const kPrefDrawInTitlebar = "browser.tabs.drawInTitlebar";
+const kPrefSelectedThemeID = "lightweightThemes.selectedThemeID";
const kPrefWebIDEInNavbar = "devtools.webide.widget.inNavbarByDefault";
const kExpectedWindowURL = "chrome://browser/content/browser.xul";
/**
* The keys are the handlers that are fired when the event type (the value)
* is fired on the subview. A widget that provides a subview has the option
* of providing onViewShowing and onViewHiding event handlers.
@@ -1925,25 +1926,17 @@ var CustomizableUIInternal = {
// Note that this does not populate gPlacements, which is done lazily so that
// the legacy state can be migrated, which is only available once a browser
// window is openned.
// The panel area is an exception here, since it has no legacy state and is
// built lazily - and therefore wouldn't otherwise result in restoring its
// state immediately when a browser window opens, which is important for
// other consumers of this API.
loadSavedState() {
- let state = null;
- try {
- state = Services.prefs.getCharPref(kPrefCustomizationState);
- } catch (e) {
- log.debug("No saved state found");
- // This will fail if nothing has been customized, so silently fall back to
- // the defaults.
- }
-
+ let state = Services.prefs.getCharPref(kPrefCustomizationState);
if (!state) {
return;
}
try {
gSavedState = JSON.parse(state);
if (typeof gSavedState != "object" || gSavedState === null) {
throw "Invalid saved state";
}
@@ -2519,28 +2512,28 @@ var CustomizableUIInternal = {
if (gSeenWidgets.size) {
gDirty = true;
}
gResetting = false;
},
_resetUIState() {
- try {
- gUIStateBeforeReset.drawInTitlebar = Services.prefs.getBoolPref(kPrefDrawInTitlebar);
- gUIStateBeforeReset.uiCustomizationState = Services.prefs.getCharPref(kPrefCustomizationState);
- gUIStateBeforeReset.currentTheme = LightweightThemeManager.currentTheme;
- } catch (e) { }
-
this._resetExtraToolbars();
- Services.prefs.clearUserPref(kPrefCustomizationState);
+ gUIStateBeforeReset.selectedThemeID = Services.prefs.getCharPref(kPrefSelectedThemeID);
+ let selectedThemeID = Services.prefs.getDefaultBranch("").getCharPref(kPrefSelectedThemeID);
+ LightweightThemeManager.currentTheme =
+ selectedThemeID ? LightweightThemeManager.getUsedTheme(selectedThemeID) : null;
+
+ gUIStateBeforeReset.drawInTitlebar = Services.prefs.getBoolPref(kPrefDrawInTitlebar);
Services.prefs.clearUserPref(kPrefDrawInTitlebar);
- LightweightThemeManager.currentTheme = null;
- log.debug("State reset");
+
+ gUIStateBeforeReset.uiCustomizationState = Services.prefs.getCharPref(kPrefCustomizationState);
+ Services.prefs.clearUserPref(kPrefCustomizationState);
// Reset placements to make restoring default placements possible.
gPlacements = new Map();
gDirtyAreaCache = new Set();
gSeenWidgets = new Set();
// Clear the saved state to ensure that defaults will be used.
gSavedState = null;
// Restore the state for each area to its defaults
@@ -2598,25 +2591,26 @@ var CustomizableUIInternal = {
if (gUIStateBeforeReset.uiCustomizationState == null ||
gUIStateBeforeReset.drawInTitlebar == null) {
return;
}
gUndoResetting = true;
let uiCustomizationState = gUIStateBeforeReset.uiCustomizationState;
let drawInTitlebar = gUIStateBeforeReset.drawInTitlebar;
- let currentTheme = gUIStateBeforeReset.currentTheme;
+ let selectedThemeID = gUIStateBeforeReset.selectedThemeID;
// Need to clear the previous state before setting the prefs
// because pref observers may check if there is a previous UI state.
this._clearPreviousUIState();
Services.prefs.setCharPref(kPrefCustomizationState, uiCustomizationState);
Services.prefs.setBoolPref(kPrefDrawInTitlebar, drawInTitlebar);
- LightweightThemeManager.currentTheme = currentTheme;
+ LightweightThemeManager.currentTheme =
+ selectedThemeID ? LightweightThemeManager.getUsedTheme(selectedThemeID) : null;
this.loadSavedState();
// If the user just customizes toolbar/titlebar visibility, gSavedState will be null
// and we don't need to do anything else here:
if (gSavedState) {
for (let areaId of Object.keys(gSavedState.placements)) {
let placements = gSavedState.placements[areaId];
gPlacements.set(areaId, placements);
}
@@ -2785,18 +2779,19 @@ var CustomizableUIInternal = {
}
}
if (Services.prefs.prefHasUserValue(kPrefDrawInTitlebar)) {
log.debug(kPrefDrawInTitlebar + " pref is non-default");
return false;
}
- if (LightweightThemeManager.currentTheme) {
- log.debug(LightweightThemeManager.currentTheme + " theme is non-default");
+ if (Services.prefs.getDefaultBranch("").getCharPref(kPrefSelectedThemeID) !=
+ Services.prefs.getCharPref(kPrefSelectedThemeID)) {
+ log.debug(kPrefSelectedThemeID + " pref is non-default");
return false;
}
return true;
},
setToolbarVisibility(aToolbarId, aIsVisible) {
// We only persist the attribute the first time.