diff --git a/OxFF/components/OxFF.js b/OxFF/components/OxFF.js index 926cd4f..70b0d00 100644 --- a/OxFF/components/OxFF.js +++ b/OxFF/components/OxFF.js @@ -13,8 +13,9 @@ const Ci = Components.interfaces; Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://firefogg/uploader.jsm"); +Components.utils.import("resource://firefogg/encoder.jsm"); +Components.utils.import("resource://firefogg/utils.jsm"); -Components.utils.import("resource://ox/utils.jsm"); Components.utils.import("resource://ox/oxff.jsm"); var OxFFFactory = @@ -44,30 +45,13 @@ function OxFF() { this.access(); if (!oxff.get('username')) { - oxff.set('username', ox.makeRandomString(8)); - oxff.set('password', ox.makeRandomString(8)); + oxff.set('username', utils.makeRandomString(8)); + oxff.set('password', utils.makeRandomString(8)); } this.authkey = oxff.get('username'); this.password = oxff.get('password'); - try { - //FF3.6 fallback - 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; - } - }); - } - + this._ffmpeg2theora = ffenc.bin('ffmpeg2theora'); } OxFF.prototype = { @@ -195,7 +179,7 @@ OxFF.prototype = { var base = this.base; //later base can not be a public property var url = base + action; - ox.request({ + utils.request({ url: url, data: data, load: function(e) { @@ -206,7 +190,7 @@ OxFF.prototype = { }, error: function(e) { _this.startDaemon(); - ox.setTimeout(function() { _this.api(action, data, callback); }, 1000); + utils.setTimeout(function() { _this.api(action, data, callback); }, 1000); } }); return true; @@ -249,7 +233,7 @@ OxFF.prototype = { progress = progress.callback; if (options.action == 'frames') { - var timer = ox.setInterval(function() { + var timer = utils.setInterval(function() { _this.api('extract', {oshash: options.oshash, media: 'frames'}, function(result) { var data = JSON.parse(result); if (data.status == 'extracting') { @@ -266,7 +250,7 @@ OxFF.prototype = { f.initWithPath(data.frames[i]); formData.frame.push(f); } - ox.request({ + utils.request({ url: url, data: formData, load: function(e) { @@ -294,7 +278,7 @@ OxFF.prototype = { formData.file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile) formData.file.initWithPath(path); if (formData.file.exists()) { //FIXME: should check if more than one file with oshash is known - ox.request({ + utils.request({ url: url, data: formData, load: function(e) { @@ -310,7 +294,7 @@ OxFF.prototype = { } return false; } else if (options.action == 'video') { - var timer = ox.setInterval(function() { + var timer = utils.setInterval(function() { _this.api('extract', {oshash: options.oshash, media: options.profile}, function(result) { var data = JSON.parse(result); if (data.status == 'extracting') { @@ -427,25 +411,10 @@ OxFF.prototype = { var args = [oxff.getDBFile().path, _this._ffmpeg2theora]; _this._daemon.runw(false, args, args.length); } - - try { - //FF3.6 fallback - 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); - } - }); - } - + var file = __LOCATION__.parent.parent.QueryInterface(Ci.nsILocalFile); + file.appendRelativePath('bin'); + file.appendRelativePath(daemon); + runDaemon(file); }, } diff --git a/OxFF/modules/oxff.jsm b/OxFF/modules/oxff.jsm index e1d19e7..fa89466 100644 --- a/OxFF/modules/oxff.jsm +++ b/OxFF/modules/oxff.jsm @@ -6,7 +6,7 @@ let EXPORTED_SYMBOLS = [ "oxff" ]; const Cc = Components.classes; const Ci = Components.interfaces; -Components.utils.import("resource://ox/utils.jsm"); +Components.utils.import("resource://firefogg/encoder.jsm"); let oxff = { getDBFile: function() { @@ -59,7 +59,7 @@ let oxff = { var path = q.row.path; q.finalize(); - ox.subprocess(command, options, callback); + ffenc.subprocess(command, options, callback); }, }; diff --git a/OxFF/modules/utils.jsm b/OxFF/modules/utils.jsm deleted file mode 100644 index ba79c34..0000000 --- a/OxFF/modules/utils.jsm +++ /dev/null @@ -1,168 +0,0 @@ -// -*- coding: utf-8 -*- -// vi:si:et:sw=4:sts=4:ts=4:ft=js - -let EXPORTED_SYMBOLS = [ "ox" ]; - -const Cc = Components.classes; -const Ci = Components.interfaces; - -let ox = { - setTimeout: function(callback, timeout) { - var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_ONE_SHOT); - }, - setInterval: function(callback, timeout) { - var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_REPEATING_SLACK); - return timer; - }, - glob: function (path) { - /* - return array of all files(in all subdirectories) for given directory - */ - var directory = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); - directory.initWithPath(path); - var entries = directory.directoryEntries; - var array = []; - while(entries.hasMoreElements()) { - var entry = entries.getNext(); - entry.QueryInterface(Components.interfaces.nsIFile); - if(entry.isDirectory()) { - var sub = this.glob(entry.path); - for(i in sub) { - array.push(sub[i]); - } - } else { - array.push(entry.path); - } - } - return array; - }, - makeRandomString: function(len) { - var s = ""; - var table = [ - 'a','b','c','d','e','f','g','h','i','j', - 'k','l','m','n','o','p','q','r','s','t', - 'u','v','w','x','y','z','0','1','2','3', - '4','5','6','7','8','9' - ]; - for(var i=0;i0) { - for(i in data[key]) - appendData(key, data[key][i]); - } else if (data[key]) { - appendData(key, data[key]); - } - } - } - var formData = "--" + boundary + "--\r\n"; - formData = converter.convertToInputStream(formData); - multiStream.appendStream(formData); - - req.open("POST", url); - req.setRequestHeader("Content-type", "multipart/form-data; boundary=" + boundary); - req.setRequestHeader("Content-length", multiStream.available()); - req.send(multiStream); - return req; - }, - subprocess: function(command, options, callback) { - if(!this.ipcService) { - this.ipcService = Cc["@mozilla.org/process/ipc-service;1"] - .getService().QueryInterface(Ci.nsIIPCService); - } - var cmd = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); - cmd.initWithPath(command); - - if(command.indexOf(".exe")==-1 && - command.substr(0, 15) != "/usr/local/bin/" && - command.substr(0, 9) != "/usr/bin/") { - cmd.permissions = 0755; - } - - if (typeof(callback) == 'function') { - var thread = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager) - .newThread(0); - var backgroundTask = { - run: function() { - var result = that.ipcService.run(cmd, options, options.length); - callback(result); - } - } - thread.dispatch(backgroundTask, thread.DISPATCH_NORMAL); - } else { //no callback, call subprocess blocking, will only return once done - /* - dump('\ncmd: '); - dump(cmd.path) - dump('\n'); - dump(options) - */ - return this.ipcService.run(cmd, options, options.length); - } - }, - -};