Skip to content

Commit

Permalink
Bug 961867: Pass app tab status to child processes and allow onBefore…
Browse files Browse the repository at this point in the history
…LinkTraversal to work there. r=smaug, r=felipe
  • Loading branch information
rmottola committed Nov 19, 2019
1 parent ce911c7 commit 095f446
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 47 deletions.
33 changes: 1 addition & 32 deletions browser/base/content/browser.js
Expand Up @@ -3639,41 +3639,10 @@ var XULBrowserWindow = {

// Called before links are navigated to to allow us to retarget them if needed.
onBeforeLinkTraversal: function(originalTarget, linkURI, linkNode, isAppTab) {
let target = this._onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab);
let target = BrowserUtils.onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab);
return target;
},

_onBeforeLinkTraversal: function(originalTarget, linkURI, linkNode, isAppTab) {
// Don't modify non-default targets or targets that aren't in top-level app
// tab docshells (isAppTab will be false for app tab subframes).
if (originalTarget != "" || !isAppTab)
return originalTarget;

// External links from within app tabs should always open in new tabs
// instead of replacing the app tab's page (Bug 575561)
let linkHost;
let docHost;
try {
linkHost = linkURI.host;
docHost = linkNode.ownerDocument.documentURIObject.host;
} catch(e) {
// nsIURI.host can throw for non-nsStandardURL nsIURIs.
// If we fail to get either host, just return originalTarget.
return originalTarget;
}

if (docHost == linkHost)
return originalTarget;

// Special case: ignore "www" prefix if it is part of host string
let [longHost, shortHost] =
linkHost.length > docHost.length ? [linkHost, docHost] : [docHost, linkHost];
if (longHost == "www." + shortHost)
return originalTarget;

return "_blank";
},

onLinkIconAvailable: function (aIconURL) {
if (gProxyFavIcon && gBrowser.userTypedValue === null) {
PageProxySetIcon(aIconURL); // update the favicon in the URL bar
Expand Down
16 changes: 16 additions & 0 deletions browser/base/content/content.js
Expand Up @@ -309,6 +309,22 @@ let ClickEventHandler = {
};
ClickEventHandler.init();

addMessageListener("Browser:AppTab", function(message) {
docShell.isAppTab = message.data.isAppTab;
});

let WebBrowserChrome = {
onBeforeLinkTraversal: function(originalTarget, linkURI, linkNode, isAppTab) {
return BrowserUtils.onBeforeLinkTraversal(originalTarget, linkURI, linkNode, isAppTab);
},
};

if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
let tabchild = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsITabChild);
tabchild.webBrowserChrome = WebBrowserChrome;
}

// Lazily load the finder code
addMessageListener("Finder:Initialize", function () {
let {RemoteFinderListener} = Cu.import("resource://gre/modules/RemoteFinder.jsm", {});
Expand Down
4 changes: 2 additions & 2 deletions browser/base/content/tabbrowser.xml
Expand Up @@ -223,7 +223,7 @@
this.tabContainer._positionPinnedTabs();
this.tabContainer.adjustTabstrip();
this.getBrowserForTab(aTab).docShell.isAppTab = true;
this.getBrowserForTab(aTab).messageManager.sendAsyncMessage("Browser:AppTab", { isAppTab: true })
if (aTab.selected)
this._setCloseKeyState(false);
Expand All @@ -248,7 +248,7 @@
this.tabContainer._positionPinnedTabs();
this.tabContainer.adjustTabstrip();
this.getBrowserForTab(aTab).docShell.isAppTab = false;
this.getBrowserForTab(aTab).messageManager.sendAsyncMessage("Browser:AppTab", { isAppTab: true })
if (aTab.selected)
this._setCloseKeyState(true);
Expand Down
13 changes: 0 additions & 13 deletions browser/base/content/test/general/browser.ini
Expand Up @@ -191,17 +191,13 @@ skip-if = e10s # Bug 940195 - XULBrowserWindow.isBusy is false as a remote tab s
run-if = toolkit == "cocoa"
[browser_bug567306.js]
[browser_bug575561.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_bug575830.js]
skip-if = e10s # Bug 691614 - no e10s zoom support yet
[browser_bug577121.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_bug578534.js]
skip-if = e10s # Bug ?????? - test directly manipulates content
[browser_bug579872.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_bug580638.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_bug580956.js]
skip-if = e10s # Bug 516755 - SessionStore disabled for e10s
[browser_bug581242.js]
Expand All @@ -210,19 +206,16 @@ skip-if = e10s # Bug 930863 - pageshow issues ("TypeError: charset is undefined"
skip-if = e10s # Bug 930863 - pageshow issues ("TypeError: charset is undefined" in pageshow listener, as document is null)
[browser_bug581947.js]
[browser_bug585558.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_bug585785.js]
[browser_bug585830.js]
[browser_bug590206.js]
[browser_bug592338.js]
skip-if = e10s # Bug 653065 - Make the lightweight theme web installer ready for e10s
[browser_bug594131.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_bug595507.js]
skip-if = e10s # Bug 691601 - no form submit observers
[browser_bug596687.js]
[browser_bug597218.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_bug609700.js]
skip-if = e10s # Bug 516755 - SessionStore disabled for e10s (calls duplicateTabIn, which uses SessionStore)
[browser_bug623155.js]
Expand Down Expand Up @@ -327,7 +320,6 @@ skip-if = e10s # Bug ?????? - uncaught exception - Error: cannot ipc non-cpow ob
[browser_offlineQuotaNotification.js]
skip-if = e10s # Bug ?????? - test directly manipulates content (gBrowser.selectedBrowser.contentWindow.applicationCache.oncached = function() {...})
[browser_overflowScroll.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_pageInfo.js]
skip-if = e10s # Bug 866413 - PageInfo doesn't work in e10s
[browser_page_style_menu.js]
Expand All @@ -336,7 +328,6 @@ skip-if = e10s # Bug ?????? - test directly manipulates content
[browser_parsable_css.js]

[browser_pinnedTabs.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_plainTextLinks.js]
skip-if = e10s # Bug ?????? - test directly manipulates content (creates and fetches elements directly from content document)
[browser_popupUI.js]
Expand All @@ -347,7 +338,6 @@ skip-if = e10s # Bug ?????? - timeout after logging "Error: Channel closing: too
[browser_private_no_prompt.js]
[browser_relatedTabs.js]
[browser_removeTabsToTheEnd.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_removeUnsafeProtocolsFromURLBarPaste.js]
[browser_sanitize-download-history.js]
skip-if = true # bug 432425
Expand Down Expand Up @@ -412,13 +402,10 @@ skip-if = e10s # Bug ?????? - FHR tests failing (either with "no data for today"
skip-if = e10s # Bug ?????? - test directly manipulates content
[browser_visibleLabel.js]
[browser_visibleTabs.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_visibleTabs_bookmarkAllPages.js]
skip-if = true # Bug 1005420 - fails intermittently. also with e10s enabled: bizarre problem with hidden tab having _mouseenter called, via _setPositionalAttributes, and tab not being found resulting in 'candidate is undefined'
[browser_visibleTabs_bookmarkAllTabs.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_visibleTabs_contextMenu.js]
skip-if = e10s # Bug 921905 - pinTab/unpinTab fail in e10s
[browser_visibleTabs_tabPreview.js]
skip-if = (os == "win" && !debug) || e10s # Bug 1007418 / Bug 698371 - thumbnail captures need e10s love (tabPreviews_capture fails with Argument 1 of CanvasRenderingContext2D.drawWindow does not implement interface Window.)
[browser_windowopen_reflows.js]
Expand Down
31 changes: 31 additions & 0 deletions toolkit/modules/BrowserUtils.jsm
Expand Up @@ -185,6 +185,37 @@ this.BrowserUtils = {
return "_blank";
},

onBeforeLinkTraversal: function(originalTarget, linkURI, linkNode, isAppTab) {
// Don't modify non-default targets or targets that aren't in top-level app
// tab docshells (isAppTab will be false for app tab subframes).
if (originalTarget != "" || !isAppTab)
return originalTarget;

// External links from within app tabs should always open in new tabs
// instead of replacing the app tab's page (Bug 575561)
let linkHost;
let docHost;
try {
linkHost = linkURI.host;
docHost = linkNode.ownerDocument.documentURIObject.host;
} catch(e) {
// nsIURI.host can throw for non-nsStandardURL nsIURIs.
// If we fail to get either host, just return originalTarget.
return originalTarget;
}

if (docHost == linkHost)
return originalTarget;

// Special case: ignore "www" prefix if it is part of host string
let [longHost, shortHost] =
linkHost.length > docHost.length ? [linkHost, docHost] : [docHost, linkHost];
if (longHost == "www." + shortHost)
return originalTarget;

return "_blank";
},

/**
* Map the plugin's name to a filtered version more suitable for UI.
*
Expand Down

0 comments on commit 095f446

Please sign in to comment.