diff --git a/third_party/firefox_sendtophone/chrome.manifest b/third_party/firefox_sendtophone/chrome.manifest
index 923d869..f9df281 100644
--- a/third_party/firefox_sendtophone/chrome.manifest
+++ b/third_party/firefox_sendtophone/chrome.manifest
@@ -24,3 +24,5 @@ overlay chrome://navigator/content/navigator.xul chrome://sendtophone/content/ff
style chrome://global/content/customizeToolbar.xul chrome://sendtophone/skin/overlay.css
+# Support for Mac
+override chrome://sendtophone/skin/uploads.css chrome://sendtophone/skin/uploads-mac.css os=Darwin
diff --git a/third_party/firefox_sendtophone/chrome/content/ff-overlay.js b/third_party/firefox_sendtophone/chrome/content/ff-overlay.js
index 935f328..504e510 100644
--- a/third_party/firefox_sendtophone/chrome/content/ff-overlay.js
+++ b/third_party/firefox_sendtophone/chrome/content/ff-overlay.js
@@ -181,7 +181,7 @@ sendtophone.pickFile = function(folder)
else
{
fp.init(window, this.getString("SendFileToPhone"), Ci.nsIFilePicker.modeOpenMultiple);
- fp.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterImages);
+ fp.appendFilters( Ci.nsIFilePicker.filterAll );
}
var rv = fp.show();
diff --git a/third_party/firefox_sendtophone/chrome/content/options.js b/third_party/firefox_sendtophone/chrome/content/options.js
new file mode 100644
index 0000000..2fb34c2
--- /dev/null
+++ b/third_party/firefox_sendtophone/chrome/content/options.js
@@ -0,0 +1,55 @@
+"use strict";
+
+let foxToPhonePreferences =
+{
+ load: function()
+ {
+ let fileServerUrl = document.getElementById("extensions.sendtophone.fileServerUrl").value;
+
+ let fileserverMenuList = document.getElementById("extensionsSendToPhoneFileServer") ;
+
+ switch (fileServerUrl)
+ {
+ case '':
+ fileserverMenuList.value = fileServerUrl;
+ break;
+
+ case 'http://min.us':
+ fileserverMenuList.value = fileServerUrl;
+ break;
+
+ default:
+ fileserverMenuList.value = 'Custom';
+ break;
+ }
+
+ fileserverMenuList.addEventListener("command", function () {
+ let fileServer = fileserverMenuList.value;
+ switch (fileServer)
+ {
+ case '':
+ document.getElementById("extensions.sendtophone.fileServerUrl").value = '';
+ break;
+
+ case 'Custom':
+ break;
+
+ default:
+ document.getElementById("extensions.sendtophone.fileServerUrl").value = fileServer;
+ break;
+ }
+
+ document.getElementById("hboxFileServerUrl").hidden = ( fileServer != 'Custom');
+
+ window.sizeToContent();
+ }, false);
+
+ document.getElementById("hboxFileServerUrl").hidden = ( fileserverMenuList.value != 'Custom');
+
+ window.sizeToContent();
+
+ }
+} ;
+
+
+this.addEventListener("load", function () {foxToPhonePreferences.load(); }, false);
diff --git a/third_party/firefox_sendtophone/chrome/content/options.xul b/third_party/firefox_sendtophone/chrome/content/options.xul
index c77cffd..efe6266 100644
--- a/third_party/firefox_sendtophone/chrome/content/options.xul
+++ b/third_party/firefox_sendtophone/chrome/content/options.xul
@@ -12,6 +12,7 @@
+
@@ -29,6 +30,35 @@
label="tel:" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Disclaimer: We (FoxToPhone developers) are not affiliated
+ with any of the third party hosting services listed here.
+ You should read their Terms Of Service before using them.
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/third_party/firefox_sendtophone/chrome/content/overlay.js b/third_party/firefox_sendtophone/chrome/content/overlay.js
index d50cf50..cb210d7 100644
--- a/third_party/firefox_sendtophone/chrome/content/overlay.js
+++ b/third_party/firefox_sendtophone/chrome/content/overlay.js
@@ -14,7 +14,6 @@
limitations under the License.
*/
-
// Core functions
Components.utils.import("resource://sendtophone/sendtophone.js");
// Protocol handlers
diff --git a/third_party/firefox_sendtophone/chrome/content/upload.xml b/third_party/firefox_sendtophone/chrome/content/upload.xml
index dd73128..f5d2b4f 100644
--- a/third_party/firefox_sendtophone/chrome/content/upload.xml
+++ b/third_party/firefox_sendtophone/chrome/content/upload.xml
@@ -36,8 +36,7 @@
if (!startEl.length)
startEl = [this];
- const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
- return startEl[0].getElementsByTagNameNS(XULNS, "button");
+ return startEl[0].getElementsByTagNameNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "button");
]]>
@@ -62,7 +61,7 @@
+ oncommand="FoxToPhoneUploadWindow.performCancelCommand(this);"/>
diff --git a/third_party/firefox_sendtophone/chrome/content/uploads.js b/third_party/firefox_sendtophone/chrome/content/uploads.js
index 86d91e4..e9a36e6 100644
--- a/third_party/firefox_sendtophone/chrome/content/uploads.js
+++ b/third_party/firefox_sendtophone/chrome/content/uploads.js
@@ -1,57 +1,19 @@
-var Cc = Components.classes;
-var Ci = Components.interfaces;
+"use strict";
+
+let Cc = Components.classes;
+let Ci = Components.interfaces;
let Cu = Components.utils;
+
Cu.import("resource://gre/modules/DownloadUtils.jsm");
Cu.import("resource://gre/modules/PluralForm.jsm");
-
Cu.import("resource://sendtophone/uploadsManager.js");
-let gUploadManager = sendtophoneUploadsManager;
-let gUploadsView = null;
-
-function addFile(upload)
-{
- let dl = document.createElement("richlistitem");
-
- dl.setAttribute("file", upload.file.path);
- dl.setAttribute("target", upload.file.leafName);
- dl.setAttribute("image", "moz-icon://" + upload.file.path + "?size=32");
-
- dl.setAttribute("state", upload.state);
- dl.setAttribute("startTime", upload.startTime);
- dl.setAttribute("currBytes", upload.currBytes);
- dl.setAttribute("maxBytes", upload.maxBytes);
- dl.setAttribute("lastSeconds", Infinity);
-
- // Initialize other attributes
- dl.setAttribute("type", "upload");
- dl.setAttribute("id", "upl" + upload.id);
- dl.setAttribute("uploadId", upload.id);
-
- gUploadsView.appendChild( dl );
-}
-
-var checkTimerEvent =
-{
- notify: function(timer)
- {
- if (sendtophoneUploadsManager.isWindowNeeded())
- {
- if (gUploadsView.children.length==0)
- window.close();
- }
- }
-}
-
-function cancelUpload(item)
-{
- gUploadManager.cancelUpload( parseInt(item.getAttribute("uploadId"), 10) );
-}
-
let gUploadListener = {
+ UploadsView: null,
+
fileAdded: function(data)
{
- addFile(data);
+ this.addFile(data);
},
progressUpdate: function(data)
{
@@ -63,106 +25,107 @@ let gUploadListener = {
item.setAttribute("progress", percentComplete);
// Status text
- updateStatus(item);
+ FoxToPhoneUploadWindow.updateStatus(item);
},
fileFinished: function(data)
{
let item = document.getElementById("upl" + data.id);
- gUploadsView.removeChild(item);
+ this.UploadsView.removeChild(item);
// If no more pending uploads, close the tab.
// Use a 0 ms timeout to avoid flicker while compress -> upload a folder
let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
- checkTimer.initWithCallback(checkTimerEvent, 0, Ci.nsITimer.TYPE_ONE_SHOT);
+ checkTimer.initWithCallback( this.checkTimerEvent, 0, Ci.nsITimer.TYPE_ONE_SHOT );
+ },
+ checkTimerEvent :
+ {
+ notify: function(timer)
+ {
+ if (!sendtophoneUploadsManager.isWindowNeeded())
+ {
+ if (gUploadListener.UploadsView.children.length==0)
+ window.close();
+ }
+ }
+ },
+
+ addFile: function(upload)
+ {
+ let dl = document.createElement("richlistitem");
+
+ dl.setAttribute("file", upload.file.path);
+ dl.setAttribute("target", upload.file.leafName);
+ dl.setAttribute("image", "moz-icon://" + upload.file.path + "?size=32");
+
+ dl.setAttribute("state", upload.state);
+ dl.setAttribute("startTime", upload.startTime);
+ dl.setAttribute("currBytes", upload.currBytes);
+ dl.setAttribute("maxBytes", upload.maxBytes);
+ dl.setAttribute("lastSeconds", Infinity);
+
+ // Initialize other attributes
+ dl.setAttribute("type", "upload");
+ dl.setAttribute("id", "upl" + upload.id);
+ dl.setAttribute("uploadId", upload.id);
+
+ this.UploadsView.appendChild( dl );
}
+
+};
+
+let FoxToPhoneUploadWindow = {
+ UploadManager: null,
+
+ Startup: function()
+ {
+ this.UploadManager = sendtophoneUploadsManager;
+
+ gUploadListener.UploadsView = document.getElementById("UploadsBox");
+
+ this.UploadManager.addListener(gUploadListener);
+
+ for (let id in this.UploadManager.uploads)
+ gUploadListener.addFile( this.UploadManager.uploads[id] );
+ },
+
+ Shutdown: function()
+ {
+ this.UploadManager.removeListener(gUploadListener);
+ },
+
+ performCancelCommand: function(aItem)
+ {
+ let elm = aItem;
+
+ while (elm.nodeName != "richlistitem" ||
+ elm.getAttribute("type") != "upload")
+ elm = elm.parentNode;
+
+ if (elm.inProgress)
+ this.UploadManager.cancelUpload( parseInt(elm.getAttribute("uploadId"), 10) );
+ },
+
+ updateStatus: function(aItem)
+ {
+ let currBytes = Number(aItem.getAttribute("currBytes"));
+ let maxBytes = Number(aItem.getAttribute("maxBytes"));
+
+ let elapsedTime = (Date.now() - Number(aItem.getAttribute("startTime"))) / 1000;
+ // If we don't have an active upload, assume 0 bytes/sec
+ let speed = (currBytes>0) ? currBytes/elapsedTime : 0;
+ let lastSec = Number(aItem.getAttribute("lastSeconds"));
+
+ let status, newLast;
+ [status, newLast] =
+ DownloadUtils.getDownloadStatus(currBytes, maxBytes, speed, lastSec);
+
+ // Update lastSeconds to be the new value
+ aItem.setAttribute("lastSeconds", newLast);
+
+ aItem.setAttribute("status", status);
+ }
+
};
-function Startup()
-{
- gUploadsView = document.getElementById("UploadsBox");
-
- gUploadManager.addListener(gUploadListener);
-
- for (let id in gUploadManager.uploads)
- addFile( gUploadManager.uploads[id] );
-
-}
-
-function Shutdown()
-{
- gUploadManager.removeListener(gUploadListener);
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-//// Command Updating and Command Handlers
-
-var gUploadViewController = {
- isCommandEnabled: function(aCommand, aItem)
- {
- let dl = aItem;
-
- switch (aCommand) {
- case "cmd_cancel":
- return dl.inProgress;
- }
- return false;
- },
-
- doCommand: function(aCommand, aItem)
- {
- if (this.isCommandEnabled(aCommand, aItem))
- this.commands[aCommand](aItem);
- },
-
- commands: {
- cmd_cancel: function(aSelectedItem) {
- cancelUpload(aSelectedItem);
- }
- }
-};
-
-/**
- * Helper function to do commands.
- *
- * @param aCmd
- * The command to be performed.
- * @param aItem
- * The richlistitem that represents the download that will have the
- * command performed on it. If this is null, the command is performed on
- * all downloads. If the item passed in is not a richlistitem that
- * represents a download, it will walk up the parent nodes until it finds
- * a DOM node that is.
- */
-function performCommand(aCmd, aItem)
-{
- let elm = aItem;
-
- while (elm.nodeName != "richlistitem" ||
- elm.getAttribute("type") != "upload")
- elm = elm.parentNode;
-
- gUploadViewController.doCommand(aCmd, elm);
-}
-
-function updateStatus(aItem)
-{
- let currBytes = Number(aItem.getAttribute("currBytes"));
- let maxBytes = Number(aItem.getAttribute("maxBytes"));
-
- let elapsedTime = (Date.now() - Number(aItem.getAttribute("startTime"))) / 1000;
- // If we don't have an active upload, assume 0 bytes/sec
- let speed = (currBytes>0) ? currBytes/elapsedTime : 0;
- let lastSec = Number(aItem.getAttribute("lastSeconds"));
-
- let status, newLast;
- [status, newLast] =
- DownloadUtils.getDownloadStatus(currBytes, maxBytes, speed, lastSec);
-
- // Update lastSeconds to be the new value
- aItem.setAttribute("lastSeconds", newLast);
-
- aItem.setAttribute("status", status);
-}
diff --git a/third_party/firefox_sendtophone/chrome/content/uploads.xul b/third_party/firefox_sendtophone/chrome/content/uploads.xul
index 367bc68..ac81e9a 100644
--- a/third_party/firefox_sendtophone/chrome/content/uploads.xul
+++ b/third_party/firefox_sendtophone/chrome/content/uploads.xul
@@ -1,18 +1,16 @@
-
-
+
+
-
-
-
-
+
+
\ No newline at end of file
diff --git a/third_party/firefox_sendtophone/chrome/skin/uploads-mac.css b/third_party/firefox_sendtophone/chrome/skin/uploads-mac.css
new file mode 100644
index 0000000..ab94d8b
--- /dev/null
+++ b/third_party/firefox_sendtophone/chrome/skin/uploads-mac.css
@@ -0,0 +1,63 @@
+#UploadsBox {
+ -moz-appearance: none;
+ margin: 0;
+ padding: 0;
+ border-width: 0;
+}
+
+/* Upload View Items */
+richlistitem[type="upload"] {
+ padding: 5px;
+ min-height: 44px !important;
+ border: 1px solid transparent;
+}
+
+richlistitem[type="upload"]:not([selected="true"]):nth-child(odd) {
+ background-color: -moz-oddtreerow;
+}
+
+richlistitem[type="upload"] .status {
+ font-size: smaller;
+ color: #555;
+}
+
+richlistitem[selected="true"][type="upload"] {
+ outline: none;
+}
+
+richlistbox:focus > richlistitem[selected="true"][type="upload"] .status {
+ color: highlighttext;
+}
+
+richlistitem[type="upload"] button {
+ -moz-appearance: none;
+ min-height: 16px;
+ min-width: 16px;
+ max-height: 16px;
+ max-width: 16px;
+ padding: 0;
+ margin: 0 1px 0 1px;
+}
+
+/**
+ * Images for buttons in the interface
+ */
+richlistitem[type="upload"] button {
+ list-style-image: url(chrome://mozapps/skin/downloads/buttons.png);
+}
+.cancel {
+ -moz-image-region: rect(0px, 16px, 16px, 0px);
+}
+.cancel:hover {
+ -moz-image-region: rect(0px, 32px, 16px, 16px);
+}
+.cancel:hover:active {
+ -moz-image-region: rect(0px, 48px, 16px, 32px);
+}
+
+/* prevent flickering when changing states */
+.uploadTypeIcon {
+ min-height: 32px;
+ min-width: 32px;
+ -moz-padding-end: 2px;
+}
diff --git a/third_party/firefox_sendtophone/chrome/skin/uploads.css b/third_party/firefox_sendtophone/chrome/skin/uploads.css
index ab94d8b..a3c493e 100644
--- a/third_party/firefox_sendtophone/chrome/skin/uploads.css
+++ b/third_party/firefox_sendtophone/chrome/skin/uploads.css
@@ -1,63 +1,63 @@
-#UploadsBox {
- -moz-appearance: none;
- margin: 0;
- padding: 0;
- border-width: 0;
+
+#sendtophoneUploadsWindow {
+ background-color: ThreeDFace;
+}
+
+/* Upload View */
+@media not all and (-moz-windows-classic) {
+ #UploadsBox {
+ -moz-appearance: none;
+ margin: 0;
+ border-bottom: 2px solid;
+ -moz-border-bottom-colors: ThreeDHighlight ThreeDLightShadow;
+ }
}
/* Upload View Items */
richlistitem[type="upload"] {
- padding: 5px;
- min-height: 44px !important;
- border: 1px solid transparent;
+ padding: 4px 8px 4px 4px;
+ min-height: 46px;
+ border-bottom: 1px solid ThreeDLightShadow;
}
-richlistitem[type="upload"]:not([selected="true"]):nth-child(odd) {
- background-color: -moz-oddtreerow;
+richlistitem[type="upload"][selected="true"] {
+ background-image: url(chrome://mozapps/skin/extensions/itemEnabledFader.png);
}
-richlistitem[type="upload"] .status {
- font-size: smaller;
- color: #555;
+richlistitem[type="upload"] .name {
+ font-size: larger;
}
-richlistitem[selected="true"][type="upload"] {
- outline: none;
-}
-
-richlistbox:focus > richlistitem[selected="true"][type="upload"] .status {
- color: highlighttext;
-}
-
-richlistitem[type="upload"] button {
+.mini-button {
-moz-appearance: none;
- min-height: 16px;
- min-width: 16px;
- max-height: 16px;
- max-width: 16px;
+ list-style-image: url(chrome://mozapps/skin/downloads/downloadButtons.png);
+ background-color: transparent;
+ border: none;
padding: 0;
- margin: 0 1px 0 1px;
+ margin: 0;
+ min-width: 0;
+ min-height: 0;
}
-/**
- * Images for buttons in the interface
- */
-richlistitem[type="upload"] button {
- list-style-image: url(chrome://mozapps/skin/downloads/buttons.png);
+.mini-button > .button-box {
+ padding: 0 !important;
}
+
.cancel {
- -moz-image-region: rect(0px, 16px, 16px, 0px);
-}
-.cancel:hover {
-moz-image-region: rect(0px, 32px, 16px, 16px);
}
-.cancel:hover:active {
- -moz-image-region: rect(0px, 48px, 16px, 32px);
+.cancel:hover {
+ -moz-image-region: rect(16px, 32px, 32px, 16px);
+}
+.cancel:active {
+ -moz-image-region: rect(32px, 32px, 48px, 16px);
+}
+.cancel[disabled="true"] {
+ -moz-image-region: rect(48px, 32px, 64px, 16px);
}
/* prevent flickering when changing states */
.uploadTypeIcon {
min-height: 32px;
min-width: 32px;
- -moz-padding-end: 2px;
}
diff --git a/third_party/firefox_sendtophone/modules/protocolHandlers.js b/third_party/firefox_sendtophone/modules/protocolHandlers.js
index 4c42df2..017a3c8 100644
--- a/third_party/firefox_sendtophone/modules/protocolHandlers.js
+++ b/third_party/firefox_sendtophone/modules/protocolHandlers.js
@@ -1,3 +1,5 @@
+"use strict";
+
/* This js module doesn't export anything, it's meant to handle the protocol registration/unregistration */
var EXPORTED_SYMBOLS = [];
diff --git a/third_party/firefox_sendtophone/modules/sendtophone.js b/third_party/firefox_sendtophone/modules/sendtophone.js
index 70b3beb..613aab4 100644
--- a/third_party/firefox_sendtophone/modules/sendtophone.js
+++ b/third_party/firefox_sendtophone/modules/sendtophone.js
@@ -13,6 +13,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
+"use strict";
// https://developer.mozilla.org/en/JavaScript_code_modules/Using_JavaScript_code_modules
var EXPORTED_SYMBOLS = ["sendtophoneCore"];
@@ -332,9 +333,9 @@ var sendtophoneCore = {
sendtophoneUploadsManager.finishedUpload( progressId );
// Send the zip and delete it afterwards
- sendtophoneCore.sendFile(nsZip, function() { nsZip.remove(false) });
+ sendtophoneCore.sendFile(nsZip, function() { nsZip.remove(false); });
}
- )
+ );
return;
}
@@ -344,6 +345,32 @@ var sendtophoneCore = {
return;
}
+ if ( uri == "http://min.us" )
+ {
+ Minus.SendFile(nsFile, callback);
+ return;
+ }
+
+ this.sendFileXHR( nsFile, callback, uri, 'upload', function(target, uploadName)
+ {
+ var body = target.responseXML,
+ uploads;
+
+ // FoxToPhone custom script
+ if (body && (uploads = body.documentElement.getElementsByTagName("upload")) && uploads[0])
+ {
+ var url = uploads[0].firstChild.data;
+ sendtophoneCore.send(uploadName, url, "");
+ return;
+ }
+
+ // error.
+ sendtophoneCore.alert(uri + "\r\n" + event.target.responseText);
+ });
+ },
+
+ sendFileXHR: function( nsFile, callback, uri, formElementName, onSuccess )
+ {
let size = Math.round(nsFile.fileSize / 1024);
let maxSize = this.prefs.getIntPref( "fileUploadMaxKb" );
if (maxSize>0 && size>maxSize)
@@ -356,9 +383,9 @@ var sendtophoneCore = {
// Try to determine the MIME type of the file
var mimeType = "text/plain";
try {
- var mimeService = Cc["@mozilla.org/mime;1"]
- .getService(Ci.nsIMIMEService);
- mimeType = mimeService.getTypeFromFile(nsFile); // nsFile is an nsIFile instance
+ var mimeService = Cc["@mozilla.org/mime;1"]
+ .getService(Ci.nsIMIMEService);
+ mimeType = mimeService.getTypeFromFile(nsFile); // nsFile is an nsIFile instance
}
catch(e) { /* eat it; just use text/plain */ }
@@ -371,20 +398,20 @@ var sendtophoneCore = {
bufInStream.init(inStream, 4096);
//Setup the boundary start stream
- var boundary = "--SendToPhone-------------" + Math.random();
+ var boundary = "--SendToPhone-------------" + Math.random().toString(16).substr(2);
var startBoundryStream = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
- startBoundryStream.setData("\r\n--"+boundary+"\r\n",-1);
+ startBoundryStream.setData("--"+boundary+"\r\n",-1);
// Setup the boundary end stream
var endBoundryStream = Cc["@mozilla.org/io/string-input-stream;1"]
.createInstance(Ci.nsIStringInputStream);
- endBoundryStream.setData("\r\n--"+boundary+"--",-1);
+ endBoundryStream.setData("\r\n\r\n--"+boundary+"--\r\n",-1);
// Setup the mime-stream - the 'part' of a multi-part mime type
var mimeStream = Cc["@mozilla.org/network/mime-input-stream;1"].createInstance(Ci.nsIMIMEInputStream);
mimeStream.addContentLength = false;
- mimeStream.addHeader("Content-disposition","form-data; charset: utf-8; name=\"upload\"; filename=\"" + this.toUTF8(uploadName) + "\"");
+ mimeStream.addHeader("Content-disposition",'form-data; charset: utf-8; name="' + formElementName + '"; filename="' + this.toUTF8(uploadName) + '"');
mimeStream.addHeader("Content-type", mimeType);
mimeStream.setData(bufInStream);
@@ -404,25 +431,16 @@ var sendtophoneCore = {
req.open('POST', uri, true);
req.setRequestHeader("Content-length",multiStream.available());
- req.setRequestHeader("Content-type","multipart/form-data; charset: utf-8; boundary="+boundary);
+ req.setRequestHeader("Content-type","multipart/form-data; boundary="+boundary);
req.addEventListener("load", function(event)
{
// If there's a callback (to delete temporary files) we call it now
if (callback)
callback();
- var body = event.target.responseXML;
- var uploads;
- if (body && (uploads = body.documentElement.getElementsByTagName("upload")))
- {
- var data = uploads[0].firstChild.data;
-// sendtophoneCore.toConsole(data);
- sendtophoneCore.send(uploadName, data, "");
- return;
- }
- // error.
- sendtophoneCore.alert(uri + "\r\n" + event.target.responseText);
+ onSuccess(event.target, uploadName);
}, false);
+
// Handle errors or aborted uploads
req.addEventListener("error", function(evt)
{
@@ -432,6 +450,7 @@ var sendtophoneCore = {
if (callback)
callback();
}, false);
+
req.addEventListener("abort", function(evt)
{
// Silent.
@@ -451,8 +470,45 @@ var sendtophoneCore = {
*/
req.send(multiStream);
}
+};
+
+// http://min.us/
+var Minus = {
+ prefix: 'http://min.us/api/',
+
+ SendFile : function(nsFile, callback) {
+ // Create a gallery
+ sendtophoneCore.processXHR( Minus.prefix + 'CreateGallery', 'GET', null, function(req) {
+ var body = req.responseText;
+
+ if (body.substring(0, 1) != '{')
+ {
+ sendtophoneCore.alert(sendtophoneCore.getString("ErrorOnSend") + ' (status ' + req.status + ')\r\n' + body);
+ return;
+ }
+
+ var gallery = JSON.parse( body );
+ // Send the file
+ sendtophoneCore.sendFileXHR(nsFile, callback, Minus.prefix +
+ 'UploadItem?editor_id=' + gallery.editor_id + '&key=OK&filename=' + encodeURIComponent(nsFile.leafName), 'file',
+ function(target, uploadName)
+ {
+ var body = target.responseText;
+ if (body.substring(0, 1) != '{')
+ {
+ sendtophoneCore.alert(sendtophoneCore.getString("ErrorOnSend") + ' (status ' + req.status + ')\r\n' + body);
+ return;
+ }
+ var file = JSON.parse( body );
+// var url = "http://k.min.us/j" + file.id;
+ var url = "http://min.us/m" + gallery.reader_id;
+ sendtophoneCore.send(uploadName, url, "");
+ });
+ });
+
+ }
};
/* Zipping functions */
@@ -478,7 +534,7 @@ function zipFolder(folder, callback)
// Create a new file
nsFile.append( folder.leafName + ".zip");
- nsFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
+ nsFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 438); // 438 (decimal) = 0666 (octal)
var zipWriter = Components.Constructor("@mozilla.org/zipwriter;1", "nsIZipWriter");
var zipW = new zipWriter();
@@ -497,7 +553,7 @@ function zipFolder(folder, callback)
// Notify that we're done. Now it must be sent and deleted afterwards
callback(nsFile);
}
- }
+ };
zipW.processQueue(observer, null);
}
diff --git a/third_party/firefox_sendtophone/modules/uploadsManager.js b/third_party/firefox_sendtophone/modules/uploadsManager.js
index b501294..c04d155 100644
--- a/third_party/firefox_sendtophone/modules/uploadsManager.js
+++ b/third_party/firefox_sendtophone/modules/uploadsManager.js
@@ -1,3 +1,5 @@
+"use strict";
+
var EXPORTED_SYMBOLS = ["sendtophoneUploadsManager"];
const Cc = Components.classes;
@@ -8,13 +10,13 @@ var sendtophoneUploadsManager = {
_counter : 0,
_listeners: [],
-
+
// Add a listener that will be called when there's any change on the uploads
addListener: function( obj )
{
this._listeners.push( obj );
},
-
+
// Remove an existing listener object
removeListener: function( obj )
{
@@ -27,7 +29,7 @@ var sendtophoneUploadsManager = {
}
}
},
-
+
/**
* Adds a new upload
* nsFile: The file that it's being send
@@ -40,7 +42,7 @@ var sendtophoneUploadsManager = {
req.upload.addEventListener("progress", function(evt)
{
- if (evt.lengthComputable) {
+ if (evt.lengthComputable) {
sendtophoneUploadsManager.updateProgress(id, evt.loaded, evt.total);
}
}, false);
@@ -65,33 +67,33 @@ var sendtophoneUploadsManager = {
}, false);
},
-
+
/**
* Adds a zip (it's not an upload, but this way we can show that something is going on)
* nsFolder: a nsFile object pointing to the folder being compressed
- * When the compression has finished, the external code has to call .finishedUpload(id)
+ * When the compression has finished, the external code has to call .finishedUpload(id)
* with the id returned in this method.
*/
addZip: function(nsFolder)
{
return this._addToUploads( {file:nsFolder, state:1} );
},
-
+
_addToUploads: function( obj )
{
initShowTest();
- // Creates a counter to automatically assign new ids to each upload
+ // Creates a counter to automatically assign new ids to each upload
let id = this._counter++;
obj.id = id;
this.uploads[id] = obj;
for(let i=0, listener; listener = this._listeners[i]; i++)
listener.fileAdded( obj );
-
+
return id;
},
-
+
showWindow: function()
{
// Open the tab
@@ -102,7 +104,7 @@ var sendtophoneUploadsManager = {
{
let upload = this.uploads[id];
- // The progress events are fired when the data is sent,
+ // The progress events are fired when the data is sent,
// but that leads to wrong speed because we don't know how long
// it has really taken to process the packet
// As long as the upload progress the speed converges to a more correct value
@@ -114,15 +116,15 @@ var sendtophoneUploadsManager = {
{
upload.adjusted = true;
// let elapsed = Date.now() - upload.firstPacket; // time to send a packet to the server and get back
- let elapsed = Date.now() - upload.startTime; //
+ let elapsed = Date.now() - upload.startTime; //
upload.startTime = upload.startTime - elapsed;
}
upload.currBytes = loaded;
upload.maxBytes = total;
- this._listeners.forEach( function( listener ) {
- listener.progressUpdate( upload );
+ this._listeners.forEach( function( listener ) {
+ listener.progressUpdate( upload );
});
},
@@ -137,31 +139,22 @@ var sendtophoneUploadsManager = {
count++;
if (count == 0)
cancelShowTimer();
-
+
// Notify the listeners
- this._listeners.forEach( function( listener ) {
+ this._listeners.forEach( function( listener ) {
listener.fileFinished( upload );
});
},
-
+
cancelUpload: function(id)
{
let upload = this.uploads[id];
- upload.req.abort();
-
+ upload.req.abort();
+
},
- // For use while debugging
- toConsole: function(text)
- {
- var aConsoleService = Cc["@mozilla.org/consoleservice;1"]
- .getService(Ci.nsIConsoleService);
-
- aConsoleService.logStringMessage( text );
- },
-
// Check if we might need to show the window.
- // Either some folder is being compressed,
+ // Either some folder is being compressed,
// or there's some file that might take longer than 2 seconds.
// If there's some file that we still don't know the speed
// then consider it also as needed.
@@ -170,20 +163,19 @@ var sendtophoneUploadsManager = {
for (let id in this.uploads)
{
let upload = this.uploads[id] ;
-
+
// zipping folder: if takes so long to compress it, it will also take some time to upload it
if (upload.state==1)
return true;
-
+
// If it still hasn't uploaded anything then something might be wrong
if (upload.currBytes==0)
return true;
-
- let elapsedTime = (Date.now() - upload.startTime) / 1000;
+
+ let elapsedTime = (Date.now() - upload.startTime) / 1000;
let speed = upload.currBytes/elapsedTime;
let remainingSecs = (upload.maxBytes - upload.currBytes) / speed;
-// this.toConsole(elapsedTime + " " + speed + " " + remainingSecs);
-
+
if (remainingSecs > 2)
return true;
@@ -202,9 +194,9 @@ let showTimer = null;
// we need a nsITimerCallback compatible...
// ... interface for the callbacks.
-var showTimerEvent =
+var showTimerEvent =
{
- notify: function(timer)
+ notify: function(timer)
{
if (sendtophoneUploadsManager.isWindowNeeded())
{
@@ -213,13 +205,13 @@ var showTimerEvent =
}
}
}
-
+
function initShowTest()
{
if (showTimer)
return;
-
- // Now it is time to create the timer...
+
+ // Now it is time to create the timer...
showTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
showTimer.initWithCallback(showTimerEvent, 400, Ci.nsITimer.TYPE_REPEATING_SLACK);
}