Bug 1053434 - Add listeners for devedition prefs in browser.js and stub CSS files;r=Gijs

This commit is contained in:
Brian Grinstead 2014-10-08 16:05:46 -05:00
Родитель 544cd47e8c
Коммит f0b02eb27c
13 изменённых файлов: 188 добавлений и 0 удалений

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

@ -1292,6 +1292,9 @@ pref("services.sync.prefs.sync.spellchecker.dictionary", true);
pref("services.sync.prefs.sync.xpinstall.whitelist.required", true);
#endif
// Developer edition preferences
pref("browser.devedition.theme.enabled", false);
// Disable the error console
pref("devtools.errorconsole.enabled", false);

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

@ -0,0 +1,85 @@
# 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/.
/**
* Listeners for the DevEdition theme. This adds an extra stylesheet
* to browser.xul if a pref is set and no other themes are applied.
*/
let DevEdition = {
_prefName: "browser.devedition.theme.enabled",
_themePrefName: "general.skins.selectedSkin",
_lwThemePrefName: "lightweightThemes.isThemeSelected",
_devtoolsThemePrefName: "devtools.theme",
styleSheetLocation: "chrome://browser/skin/devedition.css",
styleSheet: null,
init: function () {
this._updateDevtoolsThemeAttribute();
this._updateStyleSheet();
// Listen for changes to all prefs except for complete themes.
// No need for this since changing a complete theme requires a
// restart.
Services.prefs.addObserver(this._lwThemePrefName, this, false);
Services.prefs.addObserver(this._prefName, this, false);
Services.prefs.addObserver(this._devtoolsThemePrefName, this, false);
},
observe: function (subject, topic, data) {
if (topic == "nsPref:changed") {
if (data == this._devtoolsThemePrefName) {
this._updateDevtoolsThemeAttribute();
} else {
this._updateStyleSheet();
}
}
},
_updateDevtoolsThemeAttribute: function() {
// Set an attribute on root element to make it possible
// to change colors based on the selected devtools theme.
document.documentElement.setAttribute("devtoolstheme",
Services.prefs.getCharPref(this._devtoolsThemePrefName));
},
_updateStyleSheet: function() {
// Only try to apply the dev edition theme if it is preffered
// on and there are no other themes applied.
let lightweightThemeSelected = false;
try {
lightweightThemeSelected = Services.prefs.getBoolPref(this._lwThemePrefName);
} catch(e) {}
let defaultThemeSelected = false;
try {
defaultThemeSelected = Services.prefs.getCharPref(this._themePrefName) == "classic/1.0";
} catch(e) {}
let deveditionThemeEnabled = Services.prefs.getBoolPref(this._prefName) &&
!lightweightThemeSelected && defaultThemeSelected;
if (deveditionThemeEnabled && !this.styleSheet) {
let styleSheetAttr = `href="${this.styleSheetLocation}" type="text/css"`;
let styleSheet = this.styleSheet = document.createProcessingInstruction(
'xml-stylesheet', styleSheetAttr);
this.styleSheet.addEventListener("load", function onLoad() {
styleSheet.removeEventListener("load", onLoad);
ToolbarIconColor.inferFromText();
});
document.insertBefore(this.styleSheet, document.documentElement);
} else if (!deveditionThemeEnabled && this.styleSheet) {
this.styleSheet.remove();
this.styleSheet = null;
ToolbarIconColor.inferFromText();
}
},
uninit: function () {
Services.prefs.removeObserver(this._lwThemePrefName, this);
Services.prefs.removeObserver(this._prefName, this);
Services.prefs.removeObserver(this._devtoolsThemePrefName, this);
this.styleSheet = null;
}
};

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

@ -199,6 +199,7 @@ let gInitialPages = [
#include browser-addons.js
#include browser-customization.js
#include browser-devedition.js
#include browser-feeds.js
#include browser-fullScreen.js
#include browser-fullZoom.js
@ -834,6 +835,7 @@ var gBrowserInit = {
gPageStyleMenu.init();
LanguageDetectionListener.init();
BrowserOnClick.init();
DevEdition.init();
let mm = window.getGroupMessageManager("browsers");
mm.loadFrameScript("chrome://browser/content/content.js", true);
@ -1391,6 +1393,8 @@ var gBrowserInit = {
BrowserOnClick.uninit();
DevEdition.uninit();
var enumerator = Services.wm.getEnumerator(null);
enumerator.getNext();
if (!enumerator.hasMoreElements()) {

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

@ -309,6 +309,7 @@ skip-if = e10s # Bug ????? - thumbnail captures need e10s love (tabPreviews_capt
skip-if = e10s
[browser_datareporting_notification.js]
run-if = datareporting
[browser_devedition.js]
[browser_devices_get_user_media.js]
skip-if = buildapp == 'mulet' || (os == "linux" && debug) || e10s # linux: bug 976544; e10s: Bug 973001 - appears user media notifications only happen in the child and don't make their way to the parent?
[browser_devices_get_user_media_about_urls.js]

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

@ -0,0 +1,66 @@
/*
* Testing changes for Developer Edition theme.
* A special stylesheet should be added to the browser.xul document
* when browser.devedition.theme.enabled is set to true and no themes
* are applied.
*/
const PREF_DEVEDITION_THEME = "browser.devedition.theme.enabled";
const PREF_THEME = "general.skins.selectedSkin";
const PREF_LWTHEME = "lightweightThemes.isThemeSelected";
const PREF_DEVTOOLS_THEME = "devtools.theme";
registerCleanupFunction(() => {
// Set preferences back to their original values
Services.prefs.clearUserPref(PREF_DEVEDITION_THEME);
Services.prefs.clearUserPref(PREF_THEME);
Services.prefs.clearUserPref(PREF_LWTHEME);
Services.prefs.clearUserPref(PREF_DEVTOOLS_THEME);
});
function test() {
waitForExplicitFinish();
startTests();
}
function startTests() {
ok (!DevEdition.styleSheet, "There is no devedition style sheet by default.");
info ("Setting browser.devedition.theme.enabled to true.");
Services.prefs.setBoolPref(PREF_DEVEDITION_THEME, true);
ok (DevEdition.styleSheet, "There is a devedition stylesheet when no themes are applied and pref is set.");
info ("Adding a lightweight theme.");
Services.prefs.setBoolPref(PREF_LWTHEME, true);
ok (!DevEdition.styleSheet, "The devedition stylesheet has been removed when a lightweight theme is applied.");
info ("Removing a lightweight theme.");
Services.prefs.setBoolPref(PREF_LWTHEME, false);
ok (DevEdition.styleSheet, "The devedition stylesheet has been added when a lightweight theme is removed.");
// There are no listeners for the complete theme pref since applying the theme
// requires a restart.
info ("Setting general.skins.selectedSkin to a custom string.");
Services.prefs.setCharPref(PREF_THEME, "custom-theme");
ok (DevEdition.styleSheet, "The devedition stylesheet is still here when a complete theme is added.");
info ("Resetting general.skins.selectedSkin to default value.");
Services.prefs.clearUserPref(PREF_THEME);
ok (DevEdition.styleSheet, "The devedition stylesheet is still here when a complete theme is removed.");
info ("Setting browser.devedition.theme.enabled to false.");
Services.prefs.setBoolPref(PREF_DEVEDITION_THEME, false);
ok (!DevEdition.styleSheet, "The devedition stylesheet has been removed.");
info ("Checking :root attributes based on devtools theme.");
is (document.documentElement.getAttribute("devtoolstheme"), "light",
"The documentElement has an attribute based on devtools theme.");
Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "dark");
is (document.documentElement.getAttribute("devtoolstheme"), "dark",
"The documentElement has an attribute based on devtools theme.");
Services.prefs.setCharPref(PREF_DEVTOOLS_THEME, "light");
is (document.documentElement.getAttribute("devtoolstheme"), "light",
"The documentElement has an attribute based on devtools theme.");
finish();
}

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

@ -0,0 +1,5 @@
% 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/.
%include ../shared/devedition.inc.css

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

@ -22,6 +22,7 @@ browser.jar:
skin/classic/browser/aboutTabCrashed.css
skin/classic/browser/actionicon-tab.png
* skin/classic/browser/browser.css
* skin/classic/browser/devedition.css
* skin/classic/browser/browser-lightweightTheme.css
skin/classic/browser/click-to-play-warning-stripes.png
* skin/classic/browser/content-contextmenu.svg

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

@ -0,0 +1,5 @@
% 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/.
%include ../shared/devedition.inc.css

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

@ -22,6 +22,7 @@ browser.jar:
skin/classic/browser/actionicon-tab.png
skin/classic/browser/actionicon-tab@2x.png
* skin/classic/browser/browser.css (browser.css)
* skin/classic/browser/devedition.css
* skin/classic/browser/browser-lightweightTheme.css
skin/classic/browser/click-to-play-warning-stripes.png
* skin/classic/browser/content-contextmenu.svg

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

@ -0,0 +1,3 @@
% 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/.

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

@ -0,0 +1,7 @@
% 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/.
%define WINDOWS_AERO
%include devedition.css
%undef WINDOWS_AERO

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

@ -0,0 +1,5 @@
% 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/.
%include ../shared/devedition.inc.css

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

@ -24,6 +24,7 @@ browser.jar:
skin/classic/browser/aboutTabCrashed.css
skin/classic/browser/actionicon-tab.png
* skin/classic/browser/browser.css
* skin/classic/browser/devedition.css
* skin/classic/browser/browser-lightweightTheme.css
skin/classic/browser/click-to-play-warning-stripes.png
* skin/classic/browser/content-contextmenu.svg
@ -446,6 +447,7 @@ browser.jar:
skin/classic/aero/browser/aboutWelcomeBack.css (../shared/aboutWelcomeBack.css)
skin/classic/aero/browser/actionicon-tab.png
* skin/classic/aero/browser/browser.css (browser-aero.css)
* skin/classic/aero/browser/devedition.css (devedition-aero.css)
* skin/classic/aero/browser/browser-lightweightTheme.css
skin/classic/aero/browser/click-to-play-warning-stripes.png
* skin/classic/aero/browser/content-contextmenu.svg