Bug 608791 - onBeforeLinkTraversal should compare host strings instead of top level domains. r=gavin, a=blocking

This commit is contained in:
Margaret Leibovic 2010-11-29 13:22:25 -08:00
Родитель 8c245f81dc
Коммит e576bd7893
4 изменённых файлов: 39 добавлений и 12 удалений

Просмотреть файл

@ -3995,18 +3995,29 @@ var XULBrowserWindow = {
if (originalTarget != "" || !isAppTab)
return originalTarget;
let docURI = linkNode.ownerDocument.documentURIObject;
try {
let docURIDomain = Services.eTLD.getBaseDomain(docURI, 0);
let linkURIDomain = Services.eTLD.getBaseDomain(linkURI, 0);
// External links from within app tabs should always open in new tabs
// instead of replacing the app tab's page (Bug 575561)
if (docURIDomain != linkURIDomain)
return "_blank";
let linkHost;
let docHost;
try {
linkHost = linkURI.host;
docHost = linkNode.ownerDocument.documentURIObject.host;
} catch(e) {
// If getBaseDomain fails, we return originalTarget below.
}
// 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) {

Просмотреть файл

@ -11,6 +11,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=575561
<a href="http://test1.example.com/browser/browser/base/content/test/dummy_page.html">same domain (different subdomain)</a>
<a href="http://example.org/browser/browser/base/content/test/dummy_page.html">different domain</a>
<a href="http://example.org/browser/browser/base/content/test/dummy_page.html" target="foo">different domain (with target)</a>
<a href="http://www.example.com/browser/browser/base/content/test/dummy_page.html">same domain (www prefix)</a>
<a href="data:text/html,<!DOCTYPE html><html><body>Another Page</body></html>">data: URI</a>
<a href="about:mozilla">about: URI</a>
<iframe src="app_subframe_bug575561.html"></iframe>
</body>
</html>

Просмотреть файл

@ -4,9 +4,9 @@ function test() {
// Pinned: Link to the same domain should not open a new tab
// Tests link to http://example.com/browser/browser/base/content/test/dummy_page.html
testLink(0, true, false, function() {
// Pinned: Link to the same domain should not open a new tab
// Pinned: Link to a different subdomain should open a new tab
// Tests link to http://test1.example.com/browser/browser/base/content/test/dummy_page.html
testLink(1, true, false, function() {
testLink(1, true, true, function() {
// Pinned: Link to a different domain should open a new tab
// Tests link to http://example.org/browser/browser/base/content/test/dummy_page.html
testLink(2, true, true, function() {
@ -18,7 +18,19 @@ function test() {
testLink(3, true, true, function() {
// Pinned: Link in a subframe should not open a new tab
// Tests link to http://example.org/browser/browser/base/content/test/dummy_page.html in subframe
testLink(0, true, false, finish, true);
testLink(0, true, false, function() {
// Pinned: Link to the same domain (with www prefix) should not open a new tab
// Tests link to http://www.example.com/browser/browser/base/content/test/dummy_page.html
testLink(4, true, false, function() {
// Pinned: Link to a data: URI should not open a new tab
// Tests link to data:text/html,<!DOCTYPE html><html><body>Another Page</body></html>
testLink(5, true, false, function() {
// Pinned: Link to an about: URI should not open a new tab
// Tests link to about:mozilla
testLink(6, true, false, finish);
});
});
}, true);
});
});
});

Просмотреть файл

@ -100,6 +100,7 @@ http://sub1.test2.example.org:8000 privileged
http://sub2.test1.example.org:8000 privileged
http://sub2.test2.example.org:8000 privileged
http://example.com:80 privileged
http://www.example.com:80 privileged
http://test1.example.com:80 privileged
http://test2.example.com:80 privileged
http://sub1.test1.example.com:80 privileged