summaryrefslogtreecommitdiffstats
path: root/application
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
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')
-rw-r--r--application/palemoon/base/content/browser.js140
-rw-r--r--application/palemoon/base/content/urlbarBindings.xml147
2 files changed, 152 insertions, 135 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);
diff --git a/application/palemoon/base/content/urlbarBindings.xml b/application/palemoon/base/content/urlbarBindings.xml
index e0bb40d64..44b398304 100644
--- a/application/palemoon/base/content/urlbarBindings.xml
+++ b/application/palemoon/base/content/urlbarBindings.xml
@@ -264,29 +264,35 @@
var action = this._parseActionUrl(url);
let lastLocationChange = gBrowser.selectedBrowser.lastLocationChange;
- Task.spawn(function() {
- let matchLastLocationChange = true;
- if (action) {
- url = action.param;
- if (this.hasAttribute("actiontype")) {
- if (action.type == "switchtab") {
- this.handleRevert();
- let prevTab = gBrowser.selectedTab;
- if (switchToTabHavingURI(url) &&
- isTabEmpty(prevTab))
- gBrowser.removeTab(prevTab);
- }
- return;
+
+ let matchLastLocationChange = true;
+ if (action) {
+ url = action.param;
+ if (this.hasAttribute("actiontype")) {
+ if (action.type == "switchtab") {
+ this.handleRevert();
+ let prevTab = gBrowser.selectedTab;
+ if (switchToTabHavingURI(url) &&
+ isTabEmpty(prevTab))
+ gBrowser.removeTab(prevTab);
}
+ return;
}
- else {
- [url, postData, mayInheritPrincipal] = yield this._canonizeURL(aTriggeringEvent);
- matchLastLocationChange = (lastLocationChange ==
- gBrowser.selectedBrowser.lastLocationChange);
- if (!url)
- return;
- }
+ continueOperation.call(this);
+ }
+ else {
+ this._canonizeURL(aTriggeringEvent, response => {
+ [url, postData, mayInheritPrincipal] = response;
+ if (url) {
+ matchLastLocationChange = (lastLocationChange ==
+ gBrowser.selectedBrowser.lastLocationChange);
+ continueOperation.call(this);
+ }
+ });
+ }
+ function continueOperation()
+ {
this.value = url;
gBrowser.userTypedValue = url;
try {
@@ -355,73 +361,74 @@
loadCurrent();
}
}
- }.bind(this));
+ }
]]></body>
</method>
<method name="_canonizeURL">
<parameter name="aTriggeringEvent"/>
+ <parameter name="aCallback"/>
<body><![CDATA[
- return Task.spawn(function() {
- var url = this.value;
- if (!url)
- throw new Task.Result(["", null, false]);
-
- // Only add the suffix when the URL bar value isn't already "URL-like",
- // and only if we get a keyboard event, to match user expectations.
- if (/^\s*[^.:\/\s]+(?:\/.*|\s*)$/i.test(url) &&
- (aTriggeringEvent instanceof KeyEvent)) {
+ var url = this.value;
+ if (!url) {
+ aCallback(["", null, false]);
+ return;
+ }
+
+ // Only add the suffix when the URL bar value isn't already "URL-like",
+ // and only if we get a keyboard event, to match user expectations.
+ if (/^\s*[^.:\/\s]+(?:\/.*|\s*)$/i.test(url) &&
+ (aTriggeringEvent instanceof KeyEvent)) {
#ifdef XP_MACOSX
- let accel = aTriggeringEvent.metaKey;
+ let accel = aTriggeringEvent.metaKey;
#else
- let accel = aTriggeringEvent.ctrlKey;
+ let accel = aTriggeringEvent.ctrlKey;
#endif
- let shift = aTriggeringEvent.shiftKey;
-
- let suffix = "";
-
- switch (true) {
- case (accel && shift):
- suffix = ".org/";
- break;
- case (shift):
- suffix = ".net/";
- break;
- case (accel):
- try {
- suffix = gPrefService.getCharPref("browser.fixup.alternate.suffix");
- if (suffix.charAt(suffix.length - 1) != "/")
- suffix += "/";
- } catch(e) {
- suffix = ".com/";
- }
- break;
- }
+ let shift = aTriggeringEvent.shiftKey;
- if (suffix) {
- // trim leading/trailing spaces (bug 233205)
- url = url.trim();
+ let suffix = "";
+
+ switch (true) {
+ case (accel && shift):
+ suffix = ".org/";
+ break;
+ case (shift):
+ suffix = ".net/";
+ break;
+ case (accel):
+ try {
+ suffix = gPrefService.getCharPref("browser.fixup.alternate.suffix");
+ if (suffix.charAt(suffix.length - 1) != "/")
+ suffix += "/";
+ } catch(e) {
+ suffix = ".com/";
+ }
+ break;
+ }
- // Tack www. and suffix on. If user has appended directories, insert
- // suffix before them (bug 279035). Be careful not to get two slashes.
+ if (suffix) {
+ // trim leading/trailing spaces (bug 233205)
+ url = url.trim();
- let firstSlash = url.indexOf("/");
+ // Tack www. and suffix on. If user has appended directories, insert
+ // suffix before them (bug 279035). Be careful not to get two slashes.
- if (firstSlash >= 0) {
- url = url.substring(0, firstSlash) + suffix +
- url.substring(firstSlash + 1);
- } else {
- url = url + suffix;
- }
+ let firstSlash = url.indexOf("/");
- url = "http://www." + url;
+ if (firstSlash >= 0) {
+ url = url.substring(0, firstSlash) + suffix +
+ url.substring(firstSlash + 1);
+ } else {
+ url = url + suffix;
}
- }
- let data = yield getShortcutOrURIAndPostData(url);
+ url = "http://www." + url;
+ }
+ }
- throw new Task.Result([data.url, data.postData, data.mayInheritPrincipal]);
- }.bind(this));
+ getShortcutOrURIAndPostData(url, data => {
+ aCallback([data.url, data.postData, data.mayInheritPrincipal]);
+ });
]]></body>
</method>