зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1026263 - set orientation default pref on firstrun; r=wesj
This commit is contained in:
Родитель
1f56ef05c9
Коммит
0efd01fc58
|
@ -22,8 +22,6 @@ function pref(name, value) {
|
|||
}
|
||||
|
||||
let WebappRT = {
|
||||
DEFAULT_PREFS_FILENAME: "default-prefs.js",
|
||||
|
||||
prefs: [
|
||||
// Disable all add-on locations other than the profile (which can't be disabled this way)
|
||||
pref("extensions.enabledScopes", 1),
|
||||
|
@ -49,7 +47,7 @@ let WebappRT = {
|
|||
|
||||
// on first run, update any prefs
|
||||
if (aStatus == "new") {
|
||||
this.getDefaultPrefs().forEach(this.addPref);
|
||||
this.prefs.forEach(this.addPref);
|
||||
|
||||
// update the blocklist url to use a different app id
|
||||
let blocklist = Services.prefs.getCharPref("extensions.blocklist.url");
|
||||
|
@ -74,7 +72,19 @@ let WebappRT = {
|
|||
}
|
||||
});
|
||||
|
||||
this.findManifestUrlFor(aUrl, aCallback);
|
||||
this.findManifestUrlFor(aUrl, (function(aLaunchUrl) {
|
||||
if (aStatus == "new") {
|
||||
if (BrowserApp.manifest && BrowserApp.manifest.orientation) {
|
||||
let orientation = BrowserApp.manifest.orientation;
|
||||
if (Array.isArray(orientation)) {
|
||||
orientation = orientation.join(",");
|
||||
}
|
||||
this.addPref(pref("app.orientation.default", orientation));
|
||||
}
|
||||
}
|
||||
|
||||
aCallback(aLaunchUrl);
|
||||
}).bind(this));
|
||||
},
|
||||
|
||||
getManifestFor: function (aUrl, aCallback) {
|
||||
|
@ -117,31 +127,6 @@ let WebappRT = {
|
|||
});
|
||||
},
|
||||
|
||||
getDefaultPrefs: function() {
|
||||
// read default prefs from the disk
|
||||
try {
|
||||
let defaultPrefs = [];
|
||||
try {
|
||||
defaultPrefs = this.readDefaultPrefs(FileUtils.getFile("ProfD", [this.DEFAULT_PREFS_FILENAME]));
|
||||
} catch(ex) {
|
||||
// this can throw if the defaultprefs.js file doesn't exist
|
||||
}
|
||||
for (let i = 0; i < defaultPrefs.length; i++) {
|
||||
this.prefs.push(defaultPrefs[i]);
|
||||
}
|
||||
} catch(ex) {
|
||||
console.log("Error reading defaultPrefs file: " + ex);
|
||||
}
|
||||
return this.prefs;
|
||||
},
|
||||
|
||||
readDefaultPrefs: function webapps_readDefaultPrefs(aFile) {
|
||||
let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
|
||||
fstream.init(aFile, -1, 0, 0);
|
||||
let prefsString = NetUtil.readInputStreamToString(fstream, fstream.available(), {});
|
||||
return JSON.parse(prefsString);
|
||||
},
|
||||
|
||||
addPref: function(aPref) {
|
||||
switch (typeof aPref.value) {
|
||||
case "string":
|
||||
|
|
|
@ -192,11 +192,6 @@ this.WebappManager = {
|
|||
apkPackageName: aApkPackageName,
|
||||
origin: aOrigin,
|
||||
});
|
||||
|
||||
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
|
||||
file.initWithPath(aProfilePath);
|
||||
let localeManifest = new ManifestHelper(aNewManifest, aOrigin, aManifestUrl);
|
||||
this.writeDefaultPrefs(file, localeManifest);
|
||||
},
|
||||
|
||||
launch: function({ apkPackageName }) {
|
||||
|
@ -651,33 +646,4 @@ this.WebappManager = {
|
|||
}
|
||||
});
|
||||
},
|
||||
|
||||
writeDefaultPrefs: function(aProfile, aManifest) {
|
||||
// build any app specific default prefs
|
||||
let prefs = [];
|
||||
if (aManifest.orientation) {
|
||||
let orientation = aManifest.orientation;
|
||||
if (Array.isArray(orientation)) {
|
||||
orientation = orientation.join(",");
|
||||
}
|
||||
prefs.push({ name: "app.orientation.default", value: orientation });
|
||||
}
|
||||
|
||||
// write them into the app profile
|
||||
let defaultPrefsFile = aProfile.clone();
|
||||
defaultPrefsFile.append(this.DEFAULT_PREFS_FILENAME);
|
||||
this._writeData(defaultPrefsFile, prefs);
|
||||
},
|
||||
|
||||
_writeData: function(aFile, aPrefs) {
|
||||
if (aPrefs.length > 0) {
|
||||
let array = new TextEncoder().encode(JSON.stringify(aPrefs));
|
||||
OS.File.writeAtomic(aFile.path, array, { tmpPath: aFile.path + ".tmp" }).then(null, function onError(reason) {
|
||||
debug("Error writing default prefs: " + reason);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
DEFAULT_PREFS_FILENAME: "default-prefs.js",
|
||||
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче