mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-29 13:10:03 +00:00
FoxToPhone: Remove charset workaround, identify ourselves correctly, add workaround for long urls with goo.gl
This commit is contained in:
@@ -315,11 +315,7 @@ ChromeExOAuth.sendRequest = function(method, url, headers, body, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The server is expecting an exact content-type header (line 96 of RequestInfo.java)
|
xhr.send(body);
|
||||||
// but Firefox adds the charset, so let's workaround the problem
|
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=416178#c31
|
|
||||||
// xhr.send(body);
|
|
||||||
xhr.sendAsBinary(body);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ var sendtophoneCore = {
|
|||||||
'consumer_key' : 'anonymous',
|
'consumer_key' : 'anonymous',
|
||||||
'consumer_secret' : 'anonymous',
|
'consumer_secret' : 'anonymous',
|
||||||
'scope' : baseUrl,
|
'scope' : baseUrl,
|
||||||
'app_name' : 'Chrome To Phone',
|
'app_name' : 'Fox To Phone',
|
||||||
'callback_page': this.returnOAuthUrl
|
'callback_page': this.returnOAuthUrl
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -113,16 +113,20 @@ var sendtophoneCore = {
|
|||||||
.logStringMessage( text );
|
.logStringMessage( text );
|
||||||
},
|
},
|
||||||
|
|
||||||
processXHR: function(url, method, data, callback)
|
processXHR: function(url, method, headers, data, callback)
|
||||||
{
|
{
|
||||||
var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
.createInstance(Ci.nsIXMLHttpRequest);
|
.createInstance(Ci.nsIXMLHttpRequest);
|
||||||
|
|
||||||
req.open(method, url, true);
|
req.open(method, url, true);
|
||||||
req.setRequestHeader('X-Same-Domain', 'true'); // XSRF protector
|
|
||||||
|
|
||||||
if (method=='POST')
|
if (headers) {
|
||||||
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
for (var header in headers) {
|
||||||
|
if (headers.hasOwnProperty(header)) {
|
||||||
|
req.setRequestHeader(header, headers[header]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
req.onreadystatechange = function()
|
req.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
@@ -139,18 +143,13 @@ var sendtophoneCore = {
|
|||||||
var redirectUrl = redirectMatch[2].replace(/&/g, '&');
|
var redirectUrl = redirectMatch[2].replace(/&/g, '&');
|
||||||
|
|
||||||
// Do the redirect and use the original callback
|
// Do the redirect and use the original callback
|
||||||
sendtophoneCore.processXHR( redirectUrl, 'GET', null, callback);
|
sendtophoneCore.processXHR( redirectUrl, 'GET', null, null, callback);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
callback.call( sendtophoneCore, req );
|
callback.call( sendtophoneCore, req );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (req.status==400&&this.retryCount<4){
|
|
||||||
this.retryCount++;
|
|
||||||
this.processXHR(this.sendUrl, 'POST', this.pendingMessage, this.processSentData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sendtophoneCore.alert(sendtophoneCore.getString("ErrorOnSend") + ' (status ' + req.status + ')\r\n' + body);
|
sendtophoneCore.alert(sendtophoneCore.getString("ErrorOnSend") + ' (status ' + req.status + ')\r\n' + body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,6 +210,24 @@ var sendtophoneCore = {
|
|||||||
url = proxyUrl + encodeURIComponent( url);
|
url = proxyUrl + encodeURIComponent( url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Seems that the server fails with URLs larger than 990 bytes, so let's shorten it in those cases
|
||||||
|
// http://code.google.com/p/chrometophone/issues/detail?id=315
|
||||||
|
if (url.length>900) {
|
||||||
|
var self = this;
|
||||||
|
this.processXHR("https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyDfmYwz1EevIW18Ifda3YeS9dVPhKsDUQo", "POST", {'Content-Type':'application/json'},
|
||||||
|
JSON.stringify( {"longUrl": url} ), function(req) {
|
||||||
|
var body = req.responseText,
|
||||||
|
response = (body && body[0]=='{' && JSON.parse( body ) );
|
||||||
|
// If OK then perform now the action
|
||||||
|
if (response && response.kind == "urlshortener#url")
|
||||||
|
self.send(title, response.id, selection);
|
||||||
|
else
|
||||||
|
this.alert( body );
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var data = 'title=' + encodeURIComponent(title) +
|
var data = 'title=' + encodeURIComponent(title) +
|
||||||
'&url=' + encodeURIComponent(url) + '&sel=' + encodeURIComponent(selection);
|
'&url=' + encodeURIComponent(url) + '&sel=' + encodeURIComponent(selection);
|
||||||
|
|
||||||
@@ -520,7 +537,7 @@ var Minus = {
|
|||||||
|
|
||||||
SendFile : function(nsFile, callback) {
|
SendFile : function(nsFile, callback) {
|
||||||
// Create a gallery
|
// Create a gallery
|
||||||
sendtophoneCore.processXHR( Minus.prefix + 'CreateGallery', 'GET', null, function(req) {
|
sendtophoneCore.processXHR( Minus.prefix + 'CreateGallery', 'GET', null, null, function(req) {
|
||||||
var body = req.responseText;
|
var body = req.responseText;
|
||||||
|
|
||||||
if (body.substring(0, 1) != '{')
|
if (body.substring(0, 1) != '{')
|
||||||
|
|||||||
Reference in New Issue
Block a user