author | Berker Peksag <berker.peksag@gmail.com> |
Tue, 26 Feb 2013 09:48:35 +0200 | |
changeset 123015 | cf2e08f56575e44ec29b5134c174389022237bbe |
parent 123014 | d181c19294876e9b8a6580f67a16e9e952068fe5 |
child 123016 | 5228ec314dc99a425d9007f90c889b263bc58f0f |
push id | 24372 |
push user | emorley@mozilla.com |
push date | Wed, 27 Feb 2013 13:22:59 +0000 |
treeherder | mozilla-central@0a91da5f5eab [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | yoric |
bugs | 801618 |
milestone | 22.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/toolkit/webapps/WebappsInstaller.jsm +++ b/toolkit/webapps/WebappsInstaller.jsm @@ -7,16 +7,17 @@ this.EXPORTED_SYMBOLS = ["WebappsInstall const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; const Cr = Components.results; Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/FileUtils.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); +Cu.import("resource://gre/modules/osfile.jsm"); this.WebappsInstaller = { /** * Creates a native installation of the web app in the OS * * @param aData the manifest data provided by the web app * * @returns bool true on success, false if an error was thrown @@ -313,17 +314,17 @@ WinNativeApp.prototype = { uninstaller.copyTo(this.uninstallDir, this.uninstallerFile.leafName); }, /** * Creates the configuration files into their destination folders. */ _createConfigFiles: function() { // ${InstallDir}/webapp.json - writeToFile(this.configJson, JSON.stringify(this.webappJson), function() {}); + writeToFile(this.configJson, JSON.stringify(this.webappJson)); let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"] .getService(Ci.nsIINIParserFactory); // ${InstallDir}/webapp.ini let writer = factory.createINIParser(this.webappINI).QueryInterface(Ci.nsIINIParserWriter); writer.setString("Webapp", "Name", this.appName); writer.setString("Webapp", "Profile", this.installDir.leafName); @@ -344,17 +345,17 @@ WinNativeApp.prototype = { // ${UninstallDir}/uninstall.log let uninstallContent = "File: \\webapp.ini\r\n" + "File: \\webapp.json\r\n" + "File: \\webapprt.old\r\n" + "File: \\chrome\\icons\\default\\default.ico"; let uninstallLog = this.uninstallDir.clone(); uninstallLog.append("uninstall.log"); - writeToFile(uninstallLog, uninstallContent, function() {}); + writeToFile(uninstallLog, uninstallContent); }, /** * Writes the keys to the system registry that are necessary for the app operation * and uninstall process. */ _writeSystemKeys: function() { let parentKey; @@ -551,17 +552,17 @@ MacNativeApp.prototype = { webapprt.append("webapprt-stub"); webapprt.copyTo(this.macOSDir, "webapprt"); }, _createConfigFiles: function() { // ${ProfileDir}/webapp.json let configJson = this.appProfileDir.clone(); configJson.append("webapp.json"); - writeToFile(configJson, JSON.stringify(this.webappJson), function() {}); + writeToFile(configJson, JSON.stringify(this.webappJson)); // ${InstallDir}/Contents/MacOS/webapp.ini let applicationINI = this.macOSDir.clone().QueryInterface(Ci.nsILocalFile); applicationINI.append("webapp.ini"); let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"] .getService(Ci.nsIINIParserFactory); @@ -595,17 +596,17 @@ MacNativeApp.prototype = { <string>0</string>\n\ <key>FirefoxBinary</key>\n\ #expand <string>__MOZ_MACBUNDLE_ID__</string>\n\ </dict>\n\ </plist>'; let infoPListFile = this.contentsDir.clone(); infoPListFile.append("Info.plist"); - writeToFile(infoPListFile, infoPListContent, function() {}); + writeToFile(infoPListFile, infoPListContent); }, _moveToApplicationsFolder: function() { let appDir = Services.dirsvc.get("LocApp", Ci.nsILocalFile); let destination = getAvailableFile(appDir, this.appNameAsFilename, ".app"); if (!destination) { @@ -794,17 +795,17 @@ LinuxNativeApp.prototype = { } } return categories; }, _createConfigFiles: function() { // ${InstallDir}/webapp.json - writeToFile(this.configJson, JSON.stringify(this.webappJson), function() {}); + writeToFile(this.configJson, JSON.stringify(this.webappJson)); let factory = Cc["@mozilla.org/xpcom/ini-processor-factory;1"] .getService(Ci.nsIINIParserFactory); let webappsBundle = Services.strings.createBundle("chrome://global/locale/webapps.properties"); // ${InstallDir}/webapp.ini let writer = factory.createINIParser(this.webappINI).QueryInterface(Ci.nsIINIParserWriter); @@ -875,25 +876,21 @@ LinuxNativeApp.prototype = { /* Helper Functions */ /** * Async write a data string into a file * * @param aFile the nsIFile to write to * @param aData a string with the data to be written - * @param aCallback a callback to be called after the process is finished */ -function writeToFile(aFile, aData, aCallback) { - let ostream = FileUtils.openSafeFileOutputStream(aFile); - let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] - .createInstance(Ci.nsIScriptableUnicodeConverter); - converter.charset = "UTF-8"; - let istream = converter.convertToInputStream(aData); - NetUtil.asyncCopy(istream, ostream, function(x) aCallback(x)); +function writeToFile(aFile, aData) { + let path = aFile.path; + let data = new TextEncoder().encode(aData); + return OS.File.writeAtomic(path, data, { tmpPath: path + ".tmp" }); } /** * Removes unprintable characters from a string. */ function sanitize(aStr) { let unprintableRE = new RegExp("[\\x00-\\x1F\\x7F]" ,"gi"); return aStr.replace(unprintableRE, "");