From 0c6c32a0e6243040360d9dce05af377e95a71a5f Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 09:31:07 +0200 Subject: Bug 846635 - Use asynchronous getCharsetForURI in getShortcutOrURI Issue #121 --- application/palemoon/base/content/browser.js | 239 ++++++++++---------- application/palemoon/base/content/openLocation.js | 78 ++++--- application/palemoon/base/content/tabbrowser.xml | 4 +- .../palemoon/base/content/urlbarBindings.xml | 242 +++++++++++---------- 4 files changed, 304 insertions(+), 259 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index b2d260101..73661a8c9 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -9,6 +9,9 @@ var Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource:///modules/RecentWindow.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "Task", + "resource://gre/modules/Task.jsm"); + XPCOMUtils.defineLazyModuleGetter(this, "CharsetMenu", "resource:///modules/CharsetMenu.jsm"); @@ -1896,88 +1899,89 @@ function loadURI(uri, referrer, postData, allowThirdPartyFixup) { } catch (e) {} } -function getShortcutOrURI(aURL, aPostDataRef, aMayInheritPrincipal) { - // Initialize outparam to false - if (aMayInheritPrincipal) - aMayInheritPrincipal.value = false; - - var shortcutURL = null; - var keyword = aURL; - var param = ""; - - var offset = aURL.indexOf(" "); - if (offset > 0) { - keyword = aURL.substr(0, offset); - param = aURL.substr(offset + 1); - } - - if (!aPostDataRef) - aPostDataRef = {}; - - var engine = Services.search.getEngineByAlias(keyword); - if (engine) { - var submission = engine.getSubmission(param); - aPostDataRef.value = submission.postData; - return submission.uri.spec; - } - - [shortcutURL, aPostDataRef.value] = - PlacesUtils.getURLAndPostDataForKeyword(keyword); +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) {} + } - if (!shortcutURL) - return aURL; + // 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 + // encodeURIComponent result, to match the behavior of nsEscape() with + // url_XPAlphas + let encodedParam = ""; + if (charset && charset != "UTF-8") + encodedParam = escape(convertFromUnicode(charset, param)). + replace(/[+@\/]+/g, encodeURIComponent); + else // Default charset is UTF-8 + encodedParam = encodeURIComponent(param); - var postData = ""; - if (aPostDataRef.value) - postData = unescape(aPostDataRef.value); + shortcutURL = shortcutURL.replace(/%s/g, encodedParam).replace(/%S/g, param); - if (/%s/i.test(shortcutURL) || /%s/i.test(postData)) { - var charset = ""; - const re = /^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/; - var 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 = PlacesUtils.history.getCharsetForURI(makeURI(shortcutURL)); - } catch (e) {} + if (/%s/i.test(escapedPostData)) // POST keyword + postData = getPostDataStream(escapedPostData, param, encodedParam, + "application/x-www-form-urlencoded"); } + else if (param) { + // This keyword doesn't take a parameter, but one was provided. Just return + // the original URL. + postData = null; - // 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 - // encodeURIComponent result, to match the behavior of nsEscape() with - // url_XPAlphas - var encodedParam = ""; - if (charset && charset != "UTF-8") - encodedParam = escape(convertFromUnicode(charset, param)). - replace(/[+@\/]+/g, encodeURIComponent); - else // Default charset is UTF-8 - encodedParam = encodeURIComponent(param); - - shortcutURL = shortcutURL.replace(/%s/g, encodedParam).replace(/%S/g, param); - - if (/%s/i.test(postData)) // POST keyword - aPostDataRef.value = getPostDataStream(postData, param, encodedParam, - "application/x-www-form-urlencoded"); - } - else if (param) { - // This keyword doesn't take a parameter, but one was provided. Just return - // the original URL. - aPostDataRef.value = null; - - return aURL; - } + throw new Task.Result({ postData: postData, url: aURL, + mayInheritPrincipal: mayInheritPrincipal }); + } - // This URL came from a bookmark, so it's safe to let it inherit the current - // document's principal. - if (aMayInheritPrincipal) - aMayInheritPrincipal.value = true; + // This URL came from a bookmark, so it's safe to let it inherit the current + // document's principal. + mayInheritPrincipal = true; - return shortcutURL; + throw new Task.Result({ postData: postData, url: shortcutURL, + mayInheritPrincipal: mayInheritPrincipal }); + }); } function getPostDataStream(aStringData, aKeyword, aEncKeyword, aType) { @@ -2722,12 +2726,13 @@ var newTabButtonObserver = { onDrop: function (aEvent) { let url = browserDragAndDrop.drop(aEvent, { }); - var postData = {}; - url = getShortcutOrURI(url, postData); - if (url) { - // allow third-party services to fixup this URL - openNewTabWith(url, null, postData.value, aEvent, true); - } + Task.spawn(function() { + let data = yield getShortcutOrURIAndPostData(url); + if (data.url) { + // allow third-party services to fixup this URL + openNewTabWith(data.url, null, data.postData, aEvent, true); + } + }); } } @@ -2742,12 +2747,13 @@ var newWindowButtonObserver = { onDrop: function (aEvent) { let url = browserDragAndDrop.drop(aEvent, { }); - var postData = {}; - url = getShortcutOrURI(url, postData); - if (url) { - // allow third-party services to fixup this URL - openNewWindowWith(url, null, postData.value, true); - } + Task.spawn(function() { + let data = yield getShortcutOrURIAndPostData(url); + if (data.url) { + // allow third-party services to fixup this URL + openNewWindowWith(data.url, null, data.postData, true); + } + }); } } @@ -5035,36 +5041,52 @@ function middleMousePaste(event) { // bar's behavior (stripsurroundingwhitespace) clipboard = clipboard.replace(/\s*\n\s*/g, ""); - let mayInheritPrincipal = { value: false }; - let url = getShortcutOrURI(clipboard, mayInheritPrincipal); - try { - makeURI(url); - } catch (ex) { - // Not a valid URI. - return; + // if it's not the current tab, we don't need to do anything because the + // browser doesn't exist. + let where = whereToOpenLink(event, true, false); + let lastLocationChange; + if (where == "current") { + lastLocationChange = gBrowser.selectedBrowser.lastLocationChange; } - try { - addToUrlbarHistory(url); - } catch (ex) { - // Things may go wrong when adding url to session history, - // but don't let that interfere with the loading of the url. - Cu.reportError(ex); - } + Task.spawn(function() { + let data = yield getShortcutOrURIAndPostData(clipboard); + try { + makeURI(data.url); + } catch (ex) { + // Not a valid URI. + return; + } + + try { + addToUrlbarHistory(data.url); + } catch (ex) { + // Things may go wrong when adding url to session history, + // but don't let that interfere with the loading of the url. + Cu.reportError(ex); + } - openUILink(url, event, - { ignoreButton: true, - disallowInheritPrincipal: !mayInheritPrincipal.value }); + if (where != "current" || + lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) { + openUILink(data.url, event, + { ignoreButton: true, + disallowInheritPrincipal: !data.mayInheritPrincipal }); + } + }); event.stopPropagation(); } function handleDroppedLink(event, url, name) { - let postData = { }; - let uri = getShortcutOrURI(url, postData); - if (uri) - loadURI(uri, null, postData.value, false); + let lastLocationChange = gBrowser.selectedBrowser.lastLocationChange; + + Task.spawn(function() { + let data = yield getShortcutOrURIAndPostData(url); + if (data.url && + lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) + loadURI(data.url, null, data.postData, false); + }); // Keep the event from being handled by the dragDrop listeners // built-in to goanna if they happen to be above us. @@ -5179,7 +5201,6 @@ function charsetLoadListener() { } } - var gPageStyleMenu = { _getAllStyleSheets: function (frameset) { diff --git a/application/palemoon/base/content/openLocation.js b/application/palemoon/base/content/openLocation.js index 5b731c7e8..b00dbc571 100644 --- a/application/palemoon/base/content/openLocation.js +++ b/application/palemoon/base/content/openLocation.js @@ -16,6 +16,7 @@ try { } Components.utils.import("resource:///modules/openLocationLastURL.jsm", openLocationModule); +Components.utils.import("resource://gre/modules/Task.jsm"); let gOpenLocationLastURL = new openLocationModule.OpenLocationLastURL(window.opener); function onLoad() @@ -61,45 +62,52 @@ function doEnabling() function open() { - var url; - var postData = {}; - var mayInheritPrincipal = {value: false}; - if (browser) - url = browser.getShortcutOrURI(dialog.input.value, postData, mayInheritPrincipal); - else - url = dialog.input.value; + Task.spawn(function() { + let url; + let postData = null; + let mayInheritPrincipal = false; + + if (browser) { + let data = yield browser.getShortcutOrURIAndPostData(dialog.input.value); + url = data.url; + postData = data.postData; + mayInheritPrincipal = data.mayInheritPrincipal; + } else { + url = dialog.input.value; + } - try { - // Whichever target we use for the load, we allow third-party services to - // fixup the URI - switch (dialog.openWhereList.value) { - case "0": - var webNav = Components.interfaces.nsIWebNavigation; - var flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP | - webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS; - if (!mayInheritPrincipal.value) - flags |= webNav.LOAD_FLAGS_DISALLOW_INHERIT_OWNER; - browser.gBrowser.loadURIWithFlags(url, flags, null, null, postData.value); - break; - case "1": - window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no", - url, postData.value, null, null, true); - break; - case "3": - browser.delayedOpenTab(url, null, null, postData.value, true); - break; + try { + // Whichever target we use for the load, we allow third-party services to + // fixup the URI + switch (dialog.openWhereList.value) { + case "0": + var webNav = Components.interfaces.nsIWebNavigation; + var flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; + if (!mayInheritPrincipal) + flags |= webNav.LOAD_FLAGS_DISALLOW_INHERIT_OWNER; + browser.gBrowser.loadURIWithFlags(url, flags, null, null, postData); + break; + case "1": + window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no", + url, postData, null, null, true); + break; + case "3": + browser.delayedOpenTab(url, null, null, postData, true); + break; + } + } + catch(exception) { } - } - catch(exception) { - } - if (pref) { - gOpenLocationLastURL.value = dialog.input.value; - pref.setIntPref("general.open_location.last_window_choice", dialog.openWhereList.value); - } + if (pref) { + gOpenLocationLastURL.value = dialog.input.value; + pref.setIntPref("general.open_location.last_window_choice", dialog.openWhereList.value); + } + + // Delay closing slightly to avoid timing bug on Linux. + window.close(); + }); - // Delay closing slightly to avoid timing bug on Linux. - window.close(); return false; } diff --git a/application/palemoon/base/content/tabbrowser.xml b/application/palemoon/base/content/tabbrowser.xml index 4b10855a7..4f713d76f 100644 --- a/application/palemoon/base/content/tabbrowser.xml +++ b/application/palemoon/base/content/tabbrowser.xml @@ -738,8 +738,10 @@ aFlags]); } - if (topLevel) + if (topLevel) { this.mBrowser.lastURI = aLocation; + this.mBrowser.lastLocationChange = Date.now(); + } }, onStatusChange: function (aWebProgress, aRequest, aStatus, aMessage) { diff --git a/application/palemoon/base/content/urlbarBindings.xml b/application/palemoon/base/content/urlbarBindings.xml index c99819f0d..e0bb40d64 100644 --- a/application/palemoon/base/content/urlbarBindings.xml +++ b/application/palemoon/base/content/urlbarBindings.xml @@ -263,151 +263,165 @@ var postData = null; var action = this._parseActionUrl(url); - 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); + 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; } - return; } - } - else { - [url, postData, mayInheritPrincipal] = this._canonizeURL(aTriggeringEvent); - if (!url) - return; - } + else { + [url, postData, mayInheritPrincipal] = yield this._canonizeURL(aTriggeringEvent); + matchLastLocationChange = (lastLocationChange == + gBrowser.selectedBrowser.lastLocationChange); + if (!url) + return; + } - this.value = url; - gBrowser.userTypedValue = url; - try { - addToUrlbarHistory(url); - } catch (ex) { - // Things may go wrong when adding url to session history, - // but don't let that interfere with the loading of the url. - Cu.reportError(ex); - } + this.value = url; + gBrowser.userTypedValue = url; + try { + addToUrlbarHistory(url); + } catch (ex) { + // Things may go wrong when adding url to session history, + // but don't let that interfere with the loading of the url. + Cu.reportError(ex); + } - function loadCurrent() { - let webnav = Ci.nsIWebNavigation; - let flags = webnav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP | - webnav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS; - // Pass LOAD_FLAGS_DISALLOW_INHERIT_OWNER to prevent any loads from - // inheriting the currently loaded document's principal, unless this - // URL is marked as safe to inherit (e.g. came from a bookmark - // keyword). - if (!mayInheritPrincipal) - flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER; - gBrowser.loadURIWithFlags(url, flags, null, null, postData); - } + function loadCurrent() { + let flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; + // Pass LOAD_FLAGS_DISALLOW_INHERIT_OWNER to prevent any loads from + // inheriting the currently loaded document's principal, unless this + // URL is marked as safe to inherit (e.g. came from a bookmark + // keyword). + if (!mayInheritPrincipal) + flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER; + // If the value wasn't typed, we know that we decoded the value as + // UTF-8 (see losslessDecodeURI) + if (!this.valueIsTyped) + flags |= Ci.nsIWebNavigation.LOAD_FLAGS_URI_IS_UTF8; + gBrowser.loadURIWithFlags(url, flags, null, null, postData); + } - // Focus the content area before triggering loads, since if the load - // occurs in a new tab, we want focus to be restored to the content - // area when the current tab is re-selected. - gBrowser.selectedBrowser.focus(); + // Focus the content area before triggering loads, since if the load + // occurs in a new tab, we want focus to be restored to the content + // area when the current tab is re-selected. + gBrowser.selectedBrowser.focus(); - let isMouseEvent = aTriggeringEvent instanceof MouseEvent; - let altEnter = !isMouseEvent && aTriggeringEvent && aTriggeringEvent.altKey; + let isMouseEvent = aTriggeringEvent instanceof MouseEvent; + let altEnter = !isMouseEvent && aTriggeringEvent && aTriggeringEvent.altKey; - if (altEnter) { - // XXX This was added a long time ago, and I'm not sure why it is - // necessary. Alt+Enter's default action might cause a system beep, - // or something like that? - aTriggeringEvent.preventDefault(); - aTriggeringEvent.stopPropagation(); - } + if (altEnter) { + // XXX This was added a long time ago, and I'm not sure why it is + // necessary. Alt+Enter's default action might cause a system beep, + // or something like that? + aTriggeringEvent.preventDefault(); + aTriggeringEvent.stopPropagation(); + } - // If the current tab is empty, ignore Alt+Enter (just reuse this tab) - altEnter = altEnter && !isTabEmpty(gBrowser.selectedTab); + // If the current tab is empty, ignore Alt+Enter (just reuse this tab) + altEnter = altEnter && !isTabEmpty(gBrowser.selectedTab); - if (isMouseEvent || altEnter) { - // Use the standard UI link behaviors for clicks or Alt+Enter - let where = "tab"; - if (isMouseEvent) - where = whereToOpenLink(aTriggeringEvent, false, false); + if (isMouseEvent || altEnter) { + // Use the standard UI link behaviors for clicks or Alt+Enter + let where = "tab"; + if (isMouseEvent) + where = whereToOpenLink(aTriggeringEvent, false, false); - if (where == "current") { - loadCurrent(); + if (where == "current") { + if (matchLastLocationChange) { + loadCurrent(); + } + } else { + this.handleRevert(); + let params = { allowThirdPartyFixup: true, + postData: postData, + initiatingDoc: document }; + if (!this.valueIsTyped) + params.isUTF8 = true; + openUILinkIn(url, where, params); + } } else { - this.handleRevert(); - let params = { allowThirdPartyFixup: true, - postData: postData, - initiatingDoc: document }; - openUILinkIn(url, where, params); + if (matchLastLocationChange) { + loadCurrent(); + } } - } else { - loadCurrent(); - } + }.bind(this)); ]]> = 0) { + url = url.substring(0, firstSlash) + suffix + + url.substring(firstSlash + 1); + } else { + url = url + suffix; + } - if (firstSlash >= 0) { - url = url.substring(0, firstSlash) + suffix + - url.substring(firstSlash + 1); - } else { - url = url + suffix; + url = "http://www." + url; } - - url = "http://www." + url; } - } - var postData = {}; - var mayInheritPrincipal = { value: false }; - url = getShortcutOrURI(url, postData, mayInheritPrincipal); + let data = yield getShortcutOrURIAndPostData(url); - return [url, postData.value, mayInheritPrincipal.value]; + throw new Task.Result([data.url, data.postData, data.mayInheritPrincipal]); + }.bind(this)); ]]> -- cgit v1.2.3 From f2b4134845cb61831847e6746de2f15051d65a08 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 09:46:17 +0200 Subject: Bug 989984 - getShortcutOrURIAndPostData should have a synchronous callback behavior Issue #112 --- application/palemoon/base/content/browser.js | 140 +++++++++++--------- .../palemoon/base/content/urlbarBindings.xml | 147 +++++++++++---------- 2 files changed, 152 insertions(+), 135 deletions(-) (limited to 'application/palemoon/base/content') 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)); + } ]]> + = 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]); + }); ]]> -- cgit v1.2.3 From 451cbfc0393ee0f3b8d18f856e6c8ad88d57b172 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 09:48:39 +0200 Subject: Bug 1100291 - Make getShortcutOrURIAndPostData() async by calling the passed callback off a zero timeout Issue #112 --- application/palemoon/base/content/browser.js | 6 ++++++ application/palemoon/base/content/urlbarBindings.xml | 12 ++---------- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index 154badae5..be7993961 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -1906,6 +1906,12 @@ function getShortcutOrURIAndPostData(aURL, aCallback) { let keyword = aURL; let param = ""; + // XXX Bug 1100294 will remove this little hack by using an async version of + // PlacesUtils.getURLAndPostDataForKeyword(). For now we simulate an async + // execution with at least a setTimeout(fn, 0). + let originalCallback = aCallback; + aCallback = data => setTimeout(() => originalCallback(data)); + let offset = aURL.indexOf(" "); if (offset > 0) { keyword = aURL.substr(0, offset); diff --git a/application/palemoon/base/content/urlbarBindings.xml b/application/palemoon/base/content/urlbarBindings.xml index 44b398304..ec9feb22d 100644 --- a/application/palemoon/base/content/urlbarBindings.xml +++ b/application/palemoon/base/content/urlbarBindings.xml @@ -324,18 +324,10 @@ gBrowser.selectedBrowser.focus(); let isMouseEvent = aTriggeringEvent instanceof MouseEvent; - let altEnter = !isMouseEvent && aTriggeringEvent && aTriggeringEvent.altKey; - - if (altEnter) { - // XXX This was added a long time ago, and I'm not sure why it is - // necessary. Alt+Enter's default action might cause a system beep, - // or something like that? - aTriggeringEvent.preventDefault(); - aTriggeringEvent.stopPropagation(); - } // If the current tab is empty, ignore Alt+Enter (just reuse this tab) - altEnter = altEnter && !isTabEmpty(gBrowser.selectedTab); + let altEnter = !isMouseEvent && aTriggeringEvent && + aTriggeringEvent.altKey && !isTabEmpty(gBrowser.selectedTab); if (isMouseEvent || altEnter) { // Use the standard UI link behaviors for clicks or Alt+Enter -- cgit v1.2.3 From 54cd77a551a0576f7593d24dfc9d82abcf99154f Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 11:14:20 +0200 Subject: Bug 1100294 - Turn getShortcutOrURIAndPostData() into a task that uses the new keywords API Issue #121 --- application/palemoon/base/content/browser.js | 169 ++++++++++++--------- .../palemoon/base/content/urlbarBindings.xml | 2 +- 2 files changed, 99 insertions(+), 72 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index be7993961..7a85b18e9 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -1899,53 +1899,81 @@ function loadURI(uri, referrer, postData, allowThirdPartyFixup) { } catch (e) {} } -function getShortcutOrURIAndPostData(aURL, aCallback) { - let mayInheritPrincipal = false; - let postData = null; - let shortcutURL = null; - let keyword = aURL; - let param = ""; - - // XXX Bug 1100294 will remove this little hack by using an async version of - // PlacesUtils.getURLAndPostDataForKeyword(). For now we simulate an async - // execution with at least a setTimeout(fn, 0). - let originalCallback = aCallback; - aCallback = data => setTimeout(() => originalCallback(data)); - - let offset = aURL.indexOf(" "); - if (offset > 0) { - keyword = aURL.substr(0, offset); - param = aURL.substr(offset + 1); +/** + * Given a urlbar value, discerns between URIs, keywords and aliases. + * + * @param url + * The urlbar value. + * @param callback (optional, deprecated) + * The callback function invoked when done. This parameter is + * deprecated, please use the Promise that is returned. + * + * @return Promise<{ postData, url, mayInheritPrincipal }> + */ +function getShortcutOrURIAndPostData(url, callback = null) { + if (callback) { + Deprecated.warning("Please use the Promise returned by " + + "getShortcutOrURIAndPostData() instead of passing a " + + "callback", + "https://bugzilla.mozilla.org/show_bug.cgi?id=1100294"); } - 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; - } + return Task.spawn(function* () { + let mayInheritPrincipal = false; + let postData = null; + let shortcutURL = null; + let keyword = url; + let param = ""; - [shortcutURL, postData] = - PlacesUtils.getURLAndPostDataForKeyword(keyword); + let offset = url.indexOf(" "); + if (offset > 0) { + keyword = url.substr(0, offset); + param = url.substr(offset + 1); + } - if (!shortcutURL) { - aCallback({ postData: postData, url: aURL, - mayInheritPrincipal: mayInheritPrincipal }); - return; - } + let engine = Services.search.getEngineByAlias(keyword); + if (engine) { + let submission = engine.getSubmission(param, null, "keyword"); + postData = submission.postData; + return { postData: submission.postData, url: submission.uri.spec, + mayInheritPrincipal }; + } + + let entry = yield PlacesUtils.keywords.fetch(keyword); + if (entry) { + shortcutURL = entry.url.href; + postData = entry.postData; + } + + if (!shortcutURL) { + return { postData, url, mayInheritPrincipal }; + } + + let escapedPostData = ""; + if (postData) + escapedPostData = unescape(postData); - 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 (/%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 { + let uri; + try { + // makeURI() throws if URI is invalid. + uri = makeURI(shortcutURL); + } catch (ex) {} + + if (uri) { + // Try to get the saved character-set. + // Will return an empty string if character-set is not found. + charset = yield PlacesUtils.getCharsetForURI(uri); + } + } - 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 @@ -1968,40 +1996,29 @@ function getShortcutOrURIAndPostData(aURL, aCallback) { // document's principal. mayInheritPrincipal = true; - aCallback({ postData: postData, url: shortcutURL, - mayInheritPrincipal: mayInheritPrincipal }); + return { postData, url: shortcutURL, 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(); - } + if (param) { + // This keyword doesn't take a parameter, but one was provided. Just return + // the original URL. + postData = null; + + return { postData, url, mayInheritPrincipal }; } - } - 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; - aCallback({ postData: postData, url: shortcutURL, - mayInheritPrincipal: mayInheritPrincipal }); - } + return { postData, url: shortcutURL, mayInheritPrincipal }; + }).then(data => { + if (callback) { + callback(data); + } + + return data; + }); } function getPostDataStream(aStringData, aKeyword, aEncKeyword, aType) { @@ -2746,7 +2763,7 @@ var newTabButtonObserver = { onDrop: function (aEvent) { let url = browserDragAndDrop.drop(aEvent, { }); - getShortcutOrURIAndPostData(url, data => { + getShortcutOrURIAndPostData(url).then(data => { if (data.url) { // allow third-party services to fixup this URL openNewTabWith(data.url, null, data.postData, aEvent, true); @@ -2766,7 +2783,7 @@ var newWindowButtonObserver = { onDrop: function (aEvent) { let url = browserDragAndDrop.drop(aEvent, { }); - getShortcutOrURIAndPostData(url, data => { + getShortcutOrURIAndPostData(url).then(data => { if (data.url) { // allow third-party services to fixup this URL openNewWindowWith(data.url, null, data.postData, true); @@ -5067,7 +5084,7 @@ function middleMousePaste(event) { lastLocationChange = gBrowser.selectedBrowser.lastLocationChange; } - getShortcutOrURIAndPostData(clipboard, data => { + getShortcutOrURIAndPostData(clipboard).then(data => { try { makeURI(data.url); } catch (ex) { @@ -5094,11 +5111,21 @@ function middleMousePaste(event) { event.stopPropagation(); } -function handleDroppedLink(event, url, name) +// handleDroppedLink has the following 2 overloads: +// handleDroppedLink(event, url, name) +// handleDroppedLink(event, links) +function handleDroppedLink(event, urlOrLinks, name) { + let links; + if (Array.isArray(urlOrLinks)) { + links = urlOrLinks; + } else { + links = [{ url: urlOrLinks, name, type: "" }]; + } + let lastLocationChange = gBrowser.selectedBrowser.lastLocationChange; - getShortcutOrURIAndPostData(url, data => { + getShortcutOrURIAndPostData(url).then(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 ec9feb22d..e859fe804 100644 --- a/application/palemoon/base/content/urlbarBindings.xml +++ b/application/palemoon/base/content/urlbarBindings.xml @@ -418,7 +418,7 @@ } } - getShortcutOrURIAndPostData(url, data => { + getShortcutOrURIAndPostData(url).then(data => { aCallback([data.url, data.postData, data.mayInheritPrincipal]); }); ]]> -- cgit v1.2.3 From 3c93fde763c87eaaa655a517cc93faa895415185 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 11:29:52 +0200 Subject: Bug 92737 - Part 2: Open multiple tabs when multiple items are dropped on non-remote content area browser.js: // handleDroppedLink has the following 2 overloads: // handleDroppedLink(event, url, name) // handleDroppedLink(event, links) function handleDroppedLink(event, urlOrLinks, name) { let links; if (Array.isArray(urlOrLinks)) { links = urlOrLinks; } else { links = [{ url: urlOrLinks, name, type: "" }]; } ...it is in the previous commit. --- application/palemoon/base/content/browser.js | 31 +++++++++--- application/palemoon/base/content/tabbrowser.xml | 61 +++++++++++++++++++++--- 2 files changed, 80 insertions(+), 12 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index 7a85b18e9..1d1fd73ae 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -2677,8 +2677,8 @@ var browserDragAndDrop = { } }, - drop: function (aEvent, aName, aDisallowInherit) { - return Services.droppedLinkHandler.dropLink(aEvent, aName, aDisallowInherit); + dropLinks: function (aEvent, aDisallowInherit) { + return Services.droppedLinkHandler.dropLinks(aEvent, aDisallowInherit); } }; @@ -5125,10 +5125,29 @@ function handleDroppedLink(event, urlOrLinks, name) let lastLocationChange = gBrowser.selectedBrowser.lastLocationChange; - getShortcutOrURIAndPostData(url).then(data => { - if (data.url && - lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) - loadURI(data.url, null, data.postData, false); + let userContextId = gBrowser.selectedBrowser.getAttribute("usercontextid"); + + let inBackground = Services.prefs.getBoolPref("browser.tabs.loadInBackground"); + if (event.shiftKey) + inBackground = !inBackground; + + Task.spawn(function*() { + let urls = []; + let postDatas = []; + for (let link of links) { + let data = yield getShortcutOrURIAndPostData(link.url); + urls.push(data.url); + postDatas.push(data.postData); + } + if (lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) { + gBrowser.loadTabs(urls, { + inBackground, + replace: true, + allowThirdPartyFixup: false, + postDatas, + userContextId, + }); + } }); // Keep the event from being handled by the dragDrop listeners diff --git a/application/palemoon/base/content/tabbrowser.xml b/application/palemoon/base/content/tabbrowser.xml index 4f713d76f..0d9c29395 100644 --- a/application/palemoon/base/content/tabbrowser.xml +++ b/application/palemoon/base/content/tabbrowser.xml @@ -1314,6 +1314,24 @@ 1; var owner = multiple || aLoadInBackground ? null : this.selectedTab; var firstTabAdded = null; + var targetTabIndex = -1; if (aReplace) { + let browser; + if (aTargetTab) { + browser = this.getBrowserForTab(aTargetTab); + targetTabIndex = aTargetTab._tPos; + } else { + browser = this.mCurrentBrowser; + targetTabIndex = this.tabContainer.selectedIndex; + } + let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE; + if (aAllowThirdPartyFixup) { + flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP | + Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS; + } try { - this.loadURI(aURIs[0], null, null); + browser.loadURIWithFlags(aURIs[0], { + flags, postData: aPostDatas[0] + }); } catch (e) { // Ignore failure in case a URI is wrong, so we can continue // opening the next ones. } + } else { + firstTabAdded = this.addTab(aURIs[0], { + ownerTab: owner, + skipAnimation: multiple, + allowThirdPartyFixup: aAllowThirdPartyFixup, + postData: aPostDatas[0], + userContextId: aUserContextId + }); + if (aNewIndex !== -1) { + this.moveTabTo(firstTabAdded, aNewIndex); + targetTabIndex = firstTabAdded._tPos; + } } - else - firstTabAdded = this.addTab(aURIs[0], {ownerTab: owner, skipAnimation: multiple}); - var tabNum = this.tabContainer.selectedIndex; + let tabNum = targetTabIndex; for (let i = 1; i < aURIs.length; ++i) { - let tab = this.addTab(aURIs[i], {skipAnimation: true}); - if (aReplace) + let tab = this.addTab(aURIs[i], { + skipAnimation: true, + allowThirdPartyFixup: aAllowThirdPartyFixup, + postData: aPostDatas[i], + userContextId: aUserContextId + }); + if (targetTabIndex !== -1) this.moveTabTo(tab, ++tabNum); } -- cgit v1.2.3 From 60d29fb2861768032b831b77541e06de03b6ded2 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 11:43:52 +0200 Subject: Bug 92737 - Part 4: Open multiple tabs when multiple items are dropped on tab + Follow up: Bug 92737 - Part 3: Open multiple tabs when multiple items are dropped on remote content area - browser.js: "usercontextid" (default: 0) --- application/palemoon/base/content/browser.js | 3 +- application/palemoon/base/content/tabbrowser.xml | 43 +++++++++++------------- 2 files changed, 21 insertions(+), 25 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index 1d1fd73ae..e05eca986 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -5125,7 +5125,8 @@ function handleDroppedLink(event, urlOrLinks, name) let lastLocationChange = gBrowser.selectedBrowser.lastLocationChange; - let userContextId = gBrowser.selectedBrowser.getAttribute("usercontextid"); + let userContextId = gBrowser.selectedBrowser + .getAttribute("usercontextid") || 0; let inBackground = Services.prefs.getBoolPref("browser.tabs.loadInBackground"); if (event.shiftKey) diff --git a/application/palemoon/base/content/tabbrowser.xml b/application/palemoon/base/content/tabbrowser.xml index 0d9c29395..69d824fd5 100644 --- a/application/palemoon/base/content/tabbrowser.xml +++ b/application/palemoon/base/content/tabbrowser.xml @@ -4503,40 +4503,35 @@ this.tabbrowser.updateCurrentBrowser(true); } else { // Pass true to disallow dropping javascript: or data: urls - let url; + let links; try { - url = browserDragAndDrop.drop(event, { }, true); + links = browserDragAndDrop.dropLinks(event, true); } catch (ex) {} // // valid urls don't contain spaces ' '; if we have a space it isn't a valid url. // if (!url || url.includes(" ")) //PMed - if (!url) //FF + if (!links || links.length === 0) //FF return; - let bgLoad = Services.prefs.getBoolPref("browser.tabs.loadInBackground"); + let inBackground = Services.prefs.getBoolPref("browser.tabs.loadInBackground"); if (event.shiftKey) - bgLoad = !bgLoad; + inBackground = !inBackground; - let tab = this._getDragTargetTab(event); - if (!tab || dropEffect == "copy") { - // We're adding a new tab. - let newIndex = this._getDropIndex(event); - let newTab = this.tabbrowser.loadOneTab(url, {inBackground: bgLoad, allowThirdPartyFixup: true}); - this.tabbrowser.moveTabTo(newTab, newIndex); - } else { - // Load in an existing tab. - try { - let webNav = Ci.nsIWebNavigation; - let flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP | - webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS; - this.tabbrowser.getBrowserForTab(tab).loadURIWithFlags(url, flags); - if (!bgLoad) - this.selectedItem = tab; - } catch(ex) { - // Just ignore invalid urls - } - } + let targetTab = this._getDragTargetTab(event); + let userContextId = this.selectedItem + .getAttribute("usercontextid") || 0; + let replace = !(!tab || dropEffect == "copy"); + let newIndex = this._getDropIndex(event); + let urls = links.map(link => link.url); + this.tabbrowser.loadTabs(urls, { + inBackground, + replace, + allowThirdPartyFixup: true, + targetTab, + newIndex, + userContextId, + }); } if (draggedTab) { -- cgit v1.2.3 From d432689a50bc57be3b38e0b8ec8e1171bc26b2b2 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 11:46:16 +0200 Subject: Bug 92737 - Part 5: Set multiple homepage when multiple items are dropped on Home button Issue #121 --- application/palemoon/base/content/browser.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index e05eca986..efd26c2b9 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -2686,8 +2686,10 @@ var homeButtonObserver = { onDrop: function (aEvent) { // disallow setting home pages that inherit the principal - let url = browserDragAndDrop.drop(aEvent, {}, true); - setTimeout(openHomeDialog, 0, url); + let links = browserDragAndDrop.dropLinks(aEvent, true); + if (links.length) { + setTimeout(openHomeDialog, 0, links.map(link => link.url).join("|")); + } }, onDragOver: function (aEvent) @@ -2703,18 +2705,24 @@ var homeButtonObserver = { function openHomeDialog(aURL) { var promptTitle = gNavigatorBundle.getString("droponhometitle"); - var promptMsg = gNavigatorBundle.getString("droponhomemsg"); + var promptMsg; + if (aURL.includes("|")) { + promptMsg = gNavigatorBundle.getString("droponhomemsgMultiple"); + } else { + promptMsg = gNavigatorBundle.getString("droponhomemsg"); + } + var pressedVal = Services.prompt.confirmEx(window, promptTitle, promptMsg, Services.prompt.STD_YES_NO_BUTTONS, null, null, null, null, {value:0}); if (pressedVal == 0) { try { - var str = Components.classes["@mozilla.org/supports-string;1"] - .createInstance(Components.interfaces.nsISupportsString); - str.data = aURL; + var homepageStr = Components.classes["@mozilla.org/supports-string;1"] + .createInstance(Components.interfaces.nsISupportsString); + homepageStr.data = aURL; gPrefService.setComplexValue("browser.startup.homepage", - Components.interfaces.nsISupportsString, str); + Components.interfaces.nsISupportsString, homepageStr); } catch (ex) { dump("Failed to set the home page.\n"+ex+"\n"); } -- cgit v1.2.3 From d15edc6fd6d5f96a46793871d60487ba1dac10b2 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 11:47:06 +0200 Subject: Bug 92737 - Part 6: Open multiple tabs when multiple items are dropped on New Tab button Issue #121 --- application/palemoon/base/content/browser.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index efd26c2b9..9c8e16942 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -2770,11 +2770,14 @@ var newTabButtonObserver = { onDrop: function (aEvent) { - let url = browserDragAndDrop.drop(aEvent, { }); - getShortcutOrURIAndPostData(url).then(data => { - if (data.url) { - // allow third-party services to fixup this URL - openNewTabWith(data.url, null, data.postData, aEvent, true); + let links = browserDragAndDrop.dropLinks(aEvent); + Task.spawn(function*() { + for (let link of links) { + let data = yield getShortcutOrURIAndPostData(link.url); + if (data.url) { + // allow third-party services to fixup this URL + openNewTabWith(data.url, null, data.postData, aEvent, true); + } } }); } -- cgit v1.2.3 From c16c115ea719abdcddbe5106e126935c9f391be8 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 11:48:06 +0200 Subject: Bug 92737 - Part 7: Open multiple windows when multiple items are dropped on New Window button Issue #121 --- application/palemoon/base/content/browser.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index 9c8e16942..3f294d82b 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -2793,11 +2793,14 @@ var newWindowButtonObserver = { }, onDrop: function (aEvent) { - let url = browserDragAndDrop.drop(aEvent, { }); - getShortcutOrURIAndPostData(url).then(data => { - if (data.url) { - // allow third-party services to fixup this URL - openNewWindowWith(data.url, null, data.postData, true); + let links = browserDragAndDrop.dropLinks(aEvent); + Task.spawn(function*() { + for (let link of links) { + let data = yield getShortcutOrURIAndPostData(link.url); + if (data.url) { + // allow third-party services to fixup this URL + openNewWindowWith(data.url, null, data.postData, true); + } } }); } -- cgit v1.2.3 From cebd1e72e28b58881fbcccfb48a43ce47a6b01a4 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 11:53:33 +0200 Subject: Bug 92737 - Part 10: Use browserDragAndDrop.dropLinks in urlbarBindings.xml Issue #121 --- application/palemoon/base/content/urlbarBindings.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/urlbarBindings.xml b/application/palemoon/base/content/urlbarBindings.xml index e859fe804..bdb7a6a12 100644 --- a/application/palemoon/base/content/urlbarBindings.xml +++ b/application/palemoon/base/content/urlbarBindings.xml @@ -455,11 +455,12 @@ 0 && links[0].url) { + let url = links[0].url; aEvent.preventDefault(); this.value = url; SetPageProxyState("invalid"); -- cgit v1.2.3 From cfa5951ea85357e119f397524710320a8aa85e83 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 12:07:57 +0200 Subject: Maybe fix openLocation.js (to Promise) Issue #121 --- application/palemoon/base/content/openLocation.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/openLocation.js b/application/palemoon/base/content/openLocation.js index b00dbc571..80d542954 100644 --- a/application/palemoon/base/content/openLocation.js +++ b/application/palemoon/base/content/openLocation.js @@ -62,13 +62,12 @@ function doEnabling() function open() { - Task.spawn(function() { + getShortcutOrURIAndPostData(dialog.input.value).then(data => { let url; let postData = null; let mayInheritPrincipal = false; if (browser) { - let data = yield browser.getShortcutOrURIAndPostData(dialog.input.value); url = data.url; postData = data.postData; mayInheritPrincipal = data.mayInheritPrincipal; -- cgit v1.2.3 From 1b4963fd734bbfb857593afaa103879d6c0e55eb Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 12:51:04 +0200 Subject: Fix flags for "loadURIWithFlags" in openLocation.js Issue #121 --- application/palemoon/base/content/openLocation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/openLocation.js b/application/palemoon/base/content/openLocation.js index 80d542954..6987abdf8 100644 --- a/application/palemoon/base/content/openLocation.js +++ b/application/palemoon/base/content/openLocation.js @@ -81,7 +81,8 @@ function open() switch (dialog.openWhereList.value) { case "0": var webNav = Components.interfaces.nsIWebNavigation; - var flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP; + var flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP | + webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS; if (!mayInheritPrincipal) flags |= webNav.LOAD_FLAGS_DISALLOW_INHERIT_OWNER; browser.gBrowser.loadURIWithFlags(url, flags, null, null, postData); -- cgit v1.2.3 From e3dda3ebd5658bcea920be3becc89a84194930f6 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Tue, 17 Apr 2018 08:19:14 +0200 Subject: [PALEMOON] Fix conflict in openLocation.js https://github.com/MoonchildProductions/UXP/commit/931950a880b3550490422b1855c509be10586858#diff-2f4cb31954d5857012f1452698b9bfce --- application/palemoon/base/content/openLocation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/openLocation.js b/application/palemoon/base/content/openLocation.js index 6987abdf8..f6e6a2434 100644 --- a/application/palemoon/base/content/openLocation.js +++ b/application/palemoon/base/content/openLocation.js @@ -7,7 +7,7 @@ var browser; var dialog = {}; var pref = null; -let openLocationModule = {}; +var openLocationModule = {}; try { pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); @@ -17,7 +17,7 @@ try { Components.utils.import("resource:///modules/openLocationLastURL.jsm", openLocationModule); Components.utils.import("resource://gre/modules/Task.jsm"); -let gOpenLocationLastURL = new openLocationModule.OpenLocationLastURL(window.opener); +var gOpenLocationLastURL = new openLocationModule.OpenLocationLastURL(window.opener); function onLoad() { -- cgit v1.2.3 From 90c68b34abf51ae0b1a2848094fc3115b30ee498 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Tue, 17 Apr 2018 08:25:01 +0200 Subject: [PALEMOON] Remove unused Task.jsm in openLocation.js --- application/palemoon/base/content/openLocation.js | 1 - 1 file changed, 1 deletion(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/openLocation.js b/application/palemoon/base/content/openLocation.js index f6e6a2434..1a10334c7 100644 --- a/application/palemoon/base/content/openLocation.js +++ b/application/palemoon/base/content/openLocation.js @@ -16,7 +16,6 @@ try { } Components.utils.import("resource:///modules/openLocationLastURL.jsm", openLocationModule); -Components.utils.import("resource://gre/modules/Task.jsm"); var gOpenLocationLastURL = new openLocationModule.OpenLocationLastURL(window.opener); function onLoad() -- cgit v1.2.3 From c28caba8bd08da3f37df9251c1b54b640e439ec4 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 28 Apr 2018 10:06:44 +0200 Subject: [PALEMOON] Style clean up in browser.js --- application/palemoon/base/content/browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index bfdc1e30b..5af5ed5af 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -1989,7 +1989,7 @@ function getShortcutOrURIAndPostData(url, callback = null) { if (/%s/i.test(escapedPostData)) // POST keyword postData = getPostDataStream(escapedPostData, param, encodedParam, - "application/x-www-form-urlencoded"); + "application/x-www-form-urlencoded"); // This URL came from a bookmark, so it's safe to let it inherit the current // document's principal. -- cgit v1.2.3 From 383cb2c41e8a36439851e5c8f7fec9109196b995 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 28 Apr 2018 10:28:44 +0200 Subject: [PALEMOON] Fix typo in tabbrowser.xml --- application/palemoon/base/content/tabbrowser.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/tabbrowser.xml b/application/palemoon/base/content/tabbrowser.xml index 530b42527..14bd99619 100644 --- a/application/palemoon/base/content/tabbrowser.xml +++ b/application/palemoon/base/content/tabbrowser.xml @@ -4525,7 +4525,7 @@ let targetTab = this._getDragTargetTab(event); let userContextId = this.selectedItem .getAttribute("usercontextid") || 0; - let replace = !(!tab || dropEffect == "copy"); + let replace = !(!targetTab || dropEffect == "copy"); let newIndex = this._getDropIndex(event); let urls = links.map(link => link.url); this.tabbrowser.loadTabs(urls, { -- cgit v1.2.3 From c99c89cb40123d9b37f0e75a9fde6141295acca9 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 28 Apr 2018 11:12:58 +0200 Subject: [PALEMOON] Fix a function "middleMousePaste" ("Save") in browser.js --- application/palemoon/base/content/browser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js index 5af5ed5af..6dbd9677e 100644 --- a/application/palemoon/base/content/browser.js +++ b/application/palemoon/base/content/browser.js @@ -5117,7 +5117,8 @@ function middleMousePaste(event) { lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) { openUILink(data.url, event, { ignoreButton: true, - disallowInheritPrincipal: !data.mayInheritPrincipal }); + disallowInheritPrincipal: !data.mayInheritPrincipal, + initiatingDoc: event ? event.target.ownerDocument : null }); } }); -- cgit v1.2.3 From 6bdb9d25d62fc0cfb265ebfebdfdc3362cf4f49a Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 28 Apr 2018 12:29:07 +0200 Subject: [PALEMOON] [DevTools] Storage inspector throws an error when url changes Issue #102 --- application/palemoon/base/content/newtab/grid.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/newtab/grid.js b/application/palemoon/base/content/newtab/grid.js index 46e0b804b..a614d0396 100644 --- a/application/palemoon/base/content/newtab/grid.js +++ b/application/palemoon/base/content/newtab/grid.js @@ -59,8 +59,13 @@ var gGrid = { * Refreshes the grid and re-creates all sites. */ refresh: function Grid_refresh() { + let cells = this.cells; + if (!cells) { + return; + } + // Remove all sites. - this.cells.forEach(function (cell) { + cells.forEach(function (cell) { let node = cell.node; let child = node.firstElementChild; -- cgit v1.2.3 From fd10ee105af74c5559c0021c2ada0997e943ac87 Mon Sep 17 00:00:00 2001 From: JustOff Date: Sat, 28 Apr 2018 14:41:28 +0300 Subject: Use `urlbarChangeTracker` instead of `userTypedClear` to track address bar changes --- application/palemoon/base/content/tabbrowser.xml | 41 ++++++++---------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'application/palemoon/base/content') diff --git a/application/palemoon/base/content/tabbrowser.xml b/application/palemoon/base/content/tabbrowser.xml index a7cc6deea..48a853993 100644 --- a/application/palemoon/base/content/tabbrowser.xml +++ b/application/palemoon/base/content/tabbrowser.xml @@ -570,6 +570,12 @@ const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; const nsIChannel = Components.interfaces.nsIChannel; + let location, originalLocation; + try { + aRequest.QueryInterface(nsIChannel) + location = aRequest.URI; + originalLocation = aRequest.originalURI; + } catch (ex) {} if (aStateFlags & nsIWebProgressListener.STATE_START) { this.mRequestCount++; @@ -588,16 +594,8 @@ if (aStateFlags & nsIWebProgressListener.STATE_START && aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) { - // It's okay to clear what the user typed when we start - // loading a document. If the user types, this counter gets - // set to zero, if the document load ends without an - // onLocationChange, this counter gets decremented - // (so we keep it while switching tabs after failed loads) - // We need to add 2 because loadURIWithFlags may have - // cancelled a pending load which would have cleared - // its anchor scroll detection temporary increment. if (aWebProgress.isTopLevel) - this.mBrowser.userTypedClear += 2; + this.mBrowser.urlbarChangeTracker.startedLoad(); if (this._shouldShowProgress(aRequest)) { if (!(aStateFlags & nsIWebProgressListener.STATE_RESTORING)) { @@ -625,8 +623,8 @@ this.mTab.removeAttribute("progress"); if (aWebProgress.isTopLevel) { - if (!Components.isSuccessCode(aStatus) && - !isTabEmpty(this.mTab)) { + let isSuccessful = Components.isSuccessCode(aStatus); + if (!isSuccessful && !isTabEmpty(this.mTab)) { // Restore the current document's location in case the // request was stopped (possibly from a content script) // before the location changed. @@ -635,14 +633,8 @@ if (this.mTab.selected && gURLBar) URLBarSetURI(); - } else { - // The document is done loading, we no longer want the - // value cleared. - - if (this.mBrowser.userTypedClear > 1) - this.mBrowser.userTypedClear -= 2; - else if (this.mBrowser.userTypedClear > 0) - this.mBrowser.userTypedClear--; + } else if (isSuccessful) { + this.mBrowser.urlbarChangeTracker.finishedLoad(); } if (!this.mBrowser.mIconURL) @@ -652,8 +644,6 @@ if (this.mBlank) this.mBlank = false; - var location = aRequest.QueryInterface(nsIChannel).URI; - // For keyword URIs clear the user typed value since they will be changed into real URIs if (location.scheme == "keyword") this.mBrowser.userTypedValue = null; @@ -696,13 +686,12 @@ let topLevel = aWebProgress.isTopLevel; if (topLevel) { - // If userTypedClear > 0, the document loaded correctly and we should be - // clearing the user typed value. We also need to clear the typed value + // We need to clear the typed value // if the document failed to load, to make sure the urlbar reflects the // failed URI (particularly for SSL errors). However, don't clear the value // if the error page's URI is about:blank, because that causes complete // loss of urlbar contents for invalid URI errors (see bug 867957). - if (this.mBrowser.userTypedClear > 0 || + if (this.mBrowser.didStartLoadSinceLastUserTyping() || ((aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE) && aLocation.spec != "about:blank")) this.mBrowser.userTypedValue = null; @@ -2976,10 +2965,6 @@ ]]> - - -- cgit v1.2.3