summaryrefslogtreecommitdiffstats
path: root/application/palemoon/base/content/browser.js
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-15 09:46:17 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-15 09:46:17 +0200
commitf2b4134845cb61831847e6746de2f15051d65a08 (patch)
tree06516a6ea2a72b44edec1a5b74ae3e4e4369be48 /application/palemoon/base/content/browser.js
parent0c6c32a0e6243040360d9dce05af377e95a71a5f (diff)
downloadUXP-f2b4134845cb61831847e6746de2f15051d65a08.tar
UXP-f2b4134845cb61831847e6746de2f15051d65a08.tar.gz
UXP-f2b4134845cb61831847e6746de2f15051d65a08.tar.lz
UXP-f2b4134845cb61831847e6746de2f15051d65a08.tar.xz
UXP-f2b4134845cb61831847e6746de2f15051d65a08.zip
Bug 989984 - getShortcutOrURIAndPostData should have a synchronous callback behavior
Issue #112
Diffstat (limited to 'application/palemoon/base/content/browser.js')
-rw-r--r--application/palemoon/base/content/browser.js140
1 files changed, 75 insertions, 65 deletions
diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js
index 73661a8c9..154badae5 100644
--- a/application/palemoon/base/content/browser.js
+++ b/application/palemoon/base/content/browser.js
@@ -1899,55 +1899,47 @@ function loadURI(uri, referrer, postData, allowThirdPartyFixup) {
} catch (e) {}
}
-function getShortcutOrURIAndPostData(aURL) {
- return Task.spawn(function() {
- let mayInheritPrincipal = false;
- let postData = null;
- let shortcutURL = null;
- let keyword = aURL;
- let param = "";
-
- let offset = aURL.indexOf(" ");
- if (offset > 0) {
- keyword = aURL.substr(0, offset);
- param = aURL.substr(offset + 1);
- }
-
- let engine = Services.search.getEngineByAlias(keyword);
- if (engine) {
- let submission = engine.getSubmission(param);
- postData = submission.postData;
- throw new Task.Result({ postData: submission.postData,
- url: submission.uri.spec,
- mayInheritPrincipal: mayInheritPrincipal });
- }
-
- [shortcutURL, postData] =
- PlacesUtils.getURLAndPostDataForKeyword(keyword);
-
- if (!shortcutURL)
- throw new Task.Result({ postData: postData, url: aURL,
- mayInheritPrincipal: mayInheritPrincipal });
-
- let escapedPostData = "";
- if (postData)
- escapedPostData = unescape(postData);
-
- if (/%s/i.test(shortcutURL) || /%s/i.test(escapedPostData)) {
- let charset = "";
- const re = /^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/;
- let matches = shortcutURL.match(re);
- if (matches)
- [, shortcutURL, charset] = matches;
- else {
- // Try to get the saved character-set.
- try {
- // makeURI throws if URI is invalid.
- // Will return an empty string if character-set is not found.
- charset = yield PlacesUtils.getCharsetForURI(makeURI(shortcutURL));
- } catch (e) {}
- }
+function getShortcutOrURIAndPostData(aURL, aCallback) {
+ let mayInheritPrincipal = false;
+ let postData = null;
+ let shortcutURL = null;
+ let keyword = aURL;
+ let param = "";
+
+ let offset = aURL.indexOf(" ");
+ if (offset > 0) {
+ keyword = aURL.substr(0, offset);
+ param = aURL.substr(offset + 1);
+ }
+
+ let engine = Services.search.getEngineByAlias(keyword);
+ if (engine) {
+ let submission = engine.getSubmission(param);
+ postData = submission.postData;
+ aCallback({ postData: submission.postData, url: submission.uri.spec,
+ mayInheritPrincipal: mayInheritPrincipal });
+ return;
+ }
+
+ [shortcutURL, postData] =
+ PlacesUtils.getURLAndPostDataForKeyword(keyword);
+
+ if (!shortcutURL) {
+ aCallback({ postData: postData, url: aURL,
+ mayInheritPrincipal: mayInheritPrincipal });
+ return;
+ }
+
+ let escapedPostData = "";
+ if (postData)
+ escapedPostData = unescape(postData);
+ if (/%s/i.test(shortcutURL) || /%s/i.test(escapedPostData)) {
+ let charset = "";
+ const re = /^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/;
+ let matches = shortcutURL.match(re);
+
+ let continueOperation = function () {
// encodeURIComponent produces UTF-8, and cannot be used for other charsets.
// escape() works in those cases, but it doesn't uri-encode +, @, and /.
// Therefore we need to manually replace these ASCII characters by their
@@ -1965,23 +1957,45 @@ function getShortcutOrURIAndPostData(aURL) {
if (/%s/i.test(escapedPostData)) // POST keyword
postData = getPostDataStream(escapedPostData, param, encodedParam,
"application/x-www-form-urlencoded");
+
+ // This URL came from a bookmark, so it's safe to let it inherit the current
+ // document's principal.
+ mayInheritPrincipal = true;
+
+ aCallback({ postData: postData, url: shortcutURL,
+ mayInheritPrincipal: mayInheritPrincipal });
}
- else if (param) {
- // This keyword doesn't take a parameter, but one was provided. Just return
- // the original URL.
- postData = null;
- throw new Task.Result({ postData: postData, url: aURL,
- mayInheritPrincipal: mayInheritPrincipal });
+ if (matches) {
+ [, shortcutURL, charset] = matches;
+ continueOperation();
+ } else {
+ // Try to get the saved character-set.
+ // makeURI throws if URI is invalid.
+ // Will return an empty string if character-set is not found.
+ try {
+ PlacesUtils.getCharsetForURI(makeURI(shortcutURL))
+ .then(c => { charset = c; continueOperation(); });
+ } catch (ex) {
+ continueOperation();
+ }
}
+ }
+ else if (param) {
+ // This keyword doesn't take a parameter, but one was provided. Just return
+ // the original URL.
+ postData = null;
+ aCallback({ postData: postData, url: aURL,
+ mayInheritPrincipal: mayInheritPrincipal });
+ } else {
// This URL came from a bookmark, so it's safe to let it inherit the current
// document's principal.
mayInheritPrincipal = true;
- throw new Task.Result({ postData: postData, url: shortcutURL,
- mayInheritPrincipal: mayInheritPrincipal });
- });
+ aCallback({ postData: postData, url: shortcutURL,
+ mayInheritPrincipal: mayInheritPrincipal });
+ }
}
function getPostDataStream(aStringData, aKeyword, aEncKeyword, aType) {
@@ -2726,8 +2740,7 @@ var newTabButtonObserver = {
onDrop: function (aEvent)
{
let url = browserDragAndDrop.drop(aEvent, { });
- Task.spawn(function() {
- let data = yield getShortcutOrURIAndPostData(url);
+ getShortcutOrURIAndPostData(url, data => {
if (data.url) {
// allow third-party services to fixup this URL
openNewTabWith(data.url, null, data.postData, aEvent, true);
@@ -2747,8 +2760,7 @@ var newWindowButtonObserver = {
onDrop: function (aEvent)
{
let url = browserDragAndDrop.drop(aEvent, { });
- Task.spawn(function() {
- let data = yield getShortcutOrURIAndPostData(url);
+ getShortcutOrURIAndPostData(url, data => {
if (data.url) {
// allow third-party services to fixup this URL
openNewWindowWith(data.url, null, data.postData, true);
@@ -5049,8 +5061,7 @@ function middleMousePaste(event) {
lastLocationChange = gBrowser.selectedBrowser.lastLocationChange;
}
- Task.spawn(function() {
- let data = yield getShortcutOrURIAndPostData(clipboard);
+ getShortcutOrURIAndPostData(clipboard, data => {
try {
makeURI(data.url);
} catch (ex) {
@@ -5081,8 +5092,7 @@ function handleDroppedLink(event, url, name)
{
let lastLocationChange = gBrowser.selectedBrowser.lastLocationChange;
- Task.spawn(function() {
- let data = yield getShortcutOrURIAndPostData(url);
+ getShortcutOrURIAndPostData(url, data => {
if (data.url &&
lastLocationChange == gBrowser.selectedBrowser.lastLocationChange)
loadURI(data.url, null, data.postData, false);