From 7abbd82c077ec00a8a10ffd9f5450771de8bf08f Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 17 Aug 2010 00:47:20 +0200 Subject: [PATCH] backport to firefox 3.6 --- OxFF/components/OxFF.js | 76 ++++++++++++++++++++++++++++++----------- build.sh | 4 ++- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/OxFF/components/OxFF.js b/OxFF/components/OxFF.js index 634e823..57f14e6 100644 --- a/OxFF/components/OxFF.js +++ b/OxFF/components/OxFF.js @@ -9,7 +9,6 @@ const Cc = Components.classes; const Ci = Components.interfaces; -Components.utils.import("resource://gre/modules/AddonManager.jsm"); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://ox/utils.jsm"); @@ -49,14 +48,22 @@ function OxFF() { this.username = oxff.get('username'); this.password = oxff.get('password'); - AddonManager.getAddonByID('firefogg@firefogg.org', function(addon) { - if (addon.hasResource('bin')) { - var resource = addon.getResourceURI('bin'); - var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile); - file.append('ffmpeg2theora'); - _this._ffmpeg2theora = file.path; - } - }); + try { + var em = Cc["@mozilla.org/extensions/manager;1"] + .getService(Ci.nsIExtensionManager); + var f = em.getInstallLocation('firefogg@firefogg.org').getItemFile('firefogg@firefogg.org', 'ffmpeg2theora'); + _this._ffmpeg2theora = f.path; + } catch(e) { + Components.utils.import("resource://gre/modules/AddonManager.jsm"); + AddonManager.getAddonByID('firefogg@firefogg.org', function(addon) { + if (addon.hasResource('bin')) { + var resource = addon.getResourceURI('bin'); + var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile); + file.append('ffmpeg2theora'); + _this._ffmpeg2theora = file.path; + } + }); + } } @@ -205,15 +212,36 @@ OxFF.prototype = { var base = this.base; //later base can not be a public property var url = base + action; + //req.open("POST", url, true, this.username, this.password); + req.open("POST", url, true); + + try { var formData = Cc["@mozilla.org/files/formdata;1"].createInstance(Ci.nsIDOMFormData); if (data) { for(key in data) { formData.append(key, data[key]); } } + } catch(e) { + var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter); + converter.charset = "UTF-8"; + var boundary = "--------XX" + Math.random(); + var formData=''; + if (data) { + for(key in data) { + if (data[key]) { + formData +="--" + boundary + "\r\n" + + "Content-Disposition: form-data; name=\""+key+"\"\r\n\r\n" + + data[key] + "\r\n"; + } + } + } + formData += "--" + boundary + "--\r\n"; + req.setRequestHeader("Content-type", "multipart/form-data; boundary=" + boundary); + req.setRequestHeader("Content-length", formData.length); + var formData = converter.convertToInputStream(formData); + } - //req.open("POST", url, true, this.username, this.password); - req.open("POST", url, true); req.send(formData); return true; }, @@ -351,14 +379,24 @@ OxFF.prototype = { var args = [oxff.getDBFile().path, _this._ffmpeg2theora]; _this._daemon.runw(false, args, args.length); } - AddonManager.getAddonByID(this.extensionID, function(addon) { - if (addon.hasResource('bin')) { - var resource = addon.getResourceURI('bin'); - var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile); - file.append(daemon); - runDaemon(file); - } - }); + + try { + var em = Cc["@mozilla.org/extensions/manager;1"] + .getService(Ci.nsIExtensionManager); + var file = em.getInstallLocation(this.extensionID).getItemFile(this.extensionID, daemon); + runDaemon(file); + } catch(e) { + Components.utils.import("resource://gre/modules/AddonManager.jsm"); + AddonManager.getAddonByID(this.extensionID, function(addon) { + if (addon.hasResource('bin')) { + var resource = addon.getResourceURI('bin'); + var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile); + file.append(daemon); + runDaemon(file); + } + }); + } + }, } diff --git a/build.sh b/build.sh index 51b2a5d..1adc56c 100755 --- a/build.sh +++ b/build.sh @@ -14,8 +14,10 @@ sed -i "s/version: \".*\"/version: \"$version\"/g" OxFF/components/OxFF.js sed -i "s/em:version>.*<\/em:version/em:version>$version<\/em:version/g" OxFF/install.rdf rm -f dist/OxFF-$version.xpi -zip -9 -r dist/OxFF-$version.xpi * \ +cd OxFF +zip -9 -r ../dist/OxFF-$version.xpi * \ -x \*.~1~ -x \*.orig +cd .. #cleanup sed -i "s/version: \".*\"/version: \"bzr\"/g" OxFF/components/OxFF.js