Bug 1011738 - Theme support for b2g/gaia, Part 1 : settings hook-up r=vingtetun

This commit is contained in:
Fabrice Desré 2014-08-28 17:20:26 -07:00
parent 4c6b48d9b8
commit 850bc9b545
2 changed files with 46 additions and 1 deletions

View File

@ -395,7 +395,7 @@ pref("browser.dom.window.dump.enabled", false);
// Default Content Security Policy to apply to privileged and certified apps
pref("security.apps.privileged.CSP.default", "default-src *; script-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline'");
// If you change this CSP, make sure to update the fast path in nsCSPService.cpp
pref("security.apps.certified.CSP.default", "default-src *; script-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline'");
pref("security.apps.certified.CSP.default", "default-src *; script-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline' app://theme.gaiamobile.org");
// Temporarily force-enable GL compositing. This is default-disabled
// deep within the bowels of the widgetry system. Remove me when GL
@ -928,6 +928,11 @@ pref("gfx.gralloc.fence-with-readpixels", true);
// The url of the page used to display network error details.
pref("b2g.neterror.url", "app://system.gaiamobile.org/net_error.html");
// The origin used for the shared themes uri space.
pref("b2g.theme.origin", "app://theme.gaiamobile.org");
pref("dom.mozApps.themable", true);
pref("dom.mozApps.selected_theme", "default_theme.gaiamobile.org");
// Enable Web Speech synthesis API
pref("media.webspeech.synth.enabled", true);

View File

@ -394,6 +394,46 @@ setUpdateTrackingId();
});
})();
// ================ Theme selection ============
// theme.selected holds the manifest url of the currently used theme.
SettingsListener.observe("theme.selected",
"app://default_theme.gaiamobile.org/manifest.webapp",
function(value) {
if (!value) {
return;
}
let newTheme;
try {
let enabled = Services.prefs.getBoolPref("dom.mozApps.themable");
if (!enabled) {
return;
}
// Make sure this is a url, and only keep the host part to set the pref.
let uri = Services.io.newURI(value, null, null);
// We only support overriding in the app:// protocol handler.
if (uri.scheme !== "app") {
return;
}
newTheme = uri.host;
} catch(e) {
return;
}
let currentTheme;
try {
currentTheme = Services.prefs.getCharPref('dom.mozApps.selected_theme');
} catch(e) {};
if (currentTheme != newTheme) {
debug("New theme selected " + value);
Services.prefs.setCharPref('dom.mozApps.selected_theme', newTheme);
Services.prefs.savePrefFile(null);
Services.obs.notifyObservers(null, 'app-theme-changed', newTheme);
}
});
// =================== Various simple mapping ======================
let settingsToObserve = {
'app.update.channel': {