mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 575561 - External links from within app tabs should always open in new tabs instead of replacing the app tab's page. r=gavin+bz, a=blocking-beta7
This commit is contained in:
parent
275d1802e2
commit
6a27d3fb58
@ -3985,6 +3985,27 @@ var XULBrowserWindow = {
|
||||
encodeURIComponent);
|
||||
gURLBar.setOverLink(link);
|
||||
},
|
||||
|
||||
// Called before links are navigated to to allow us to retarget them if needed.
|
||||
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;
|
||||
|
||||
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";
|
||||
} catch(e) {
|
||||
// If getBaseDomain fails, we return originalTarget below.
|
||||
}
|
||||
return originalTarget;
|
||||
},
|
||||
|
||||
onLinkIconAvailable: function (aIconURL) {
|
||||
if (gProxyFavIcon && gBrowser.userTypedValue === null)
|
||||
|
@ -191,6 +191,8 @@
|
||||
this.tabContainer._positionPinnedTabs();
|
||||
this.tabContainer.adjustTabstrip();
|
||||
|
||||
this.getBrowserForTab(aTab).docShell.isAppTab = true;
|
||||
|
||||
let event = document.createEvent("Events");
|
||||
event.initEvent("TabPinned", true, false);
|
||||
aTab.dispatchEvent(event);
|
||||
@ -210,6 +212,8 @@
|
||||
this.tabContainer._positionPinnedTabs();
|
||||
this.tabContainer.adjustTabstrip();
|
||||
|
||||
this.getBrowserForTab(aTab).docShell.isAppTab = false;
|
||||
|
||||
let event = document.createEvent("Events");
|
||||
event.initEvent("TabUnpinned", true, false);
|
||||
aTab.dispatchEvent(event);
|
||||
|
@ -159,7 +159,7 @@
|
||||
#include "nsIController.h"
|
||||
#include "nsPICommandUpdater.h"
|
||||
#include "nsIDOMHTMLAnchorElement.h"
|
||||
#include "nsIWebBrowserChrome2.h"
|
||||
#include "nsIWebBrowserChrome3.h"
|
||||
#include "nsITabChild.h"
|
||||
#include "nsIStrictTransportSecurityService.h"
|
||||
|
||||
@ -711,6 +711,7 @@ nsDocShell::nsDocShell():
|
||||
mAllowKeywordFixup(PR_FALSE),
|
||||
mIsOffScreenBrowser(PR_FALSE),
|
||||
mIsActive(PR_TRUE),
|
||||
mIsAppTab(PR_FALSE),
|
||||
mFiredUnloadEvent(PR_FALSE),
|
||||
mEODForCurrentDocument(PR_FALSE),
|
||||
mURIResultedInDocument(PR_FALSE),
|
||||
@ -4802,6 +4803,20 @@ nsDocShell::GetIsActive(PRBool *aIsActive)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::SetIsAppTab(PRBool aIsAppTab)
|
||||
{
|
||||
mIsAppTab = aIsAppTab;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetIsAppTab(PRBool *aIsAppTab)
|
||||
{
|
||||
*aIsAppTab = mIsAppTab;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::SetVisibility(PRBool aVisibility)
|
||||
{
|
||||
@ -11311,8 +11326,22 @@ nsDocShell::OnLinkClick(nsIContent* aContent,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsAutoString target;
|
||||
|
||||
nsCOMPtr<nsIWebBrowserChrome3> browserChrome3 = do_GetInterface(mTreeOwner);
|
||||
if (browserChrome3) {
|
||||
nsCOMPtr<nsIDOMNode> linkNode = do_QueryInterface(aContent);
|
||||
nsAutoString oldTarget(aTargetSpec);
|
||||
rv = browserChrome3->OnBeforeLinkTraversal(oldTarget, aURI,
|
||||
linkNode, mIsAppTab, target);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
target = aTargetSpec;
|
||||
|
||||
nsCOMPtr<nsIRunnable> ev =
|
||||
new OnLinkClickEvent(this, aContent, aURI, aTargetSpec,
|
||||
new OnLinkClickEvent(this, aContent, aURI, target.get(),
|
||||
aPostDataStream, aHeadersDataStream);
|
||||
return NS_DispatchToCurrentThread(ev);
|
||||
}
|
||||
|
@ -790,6 +790,7 @@ protected:
|
||||
PRPackedBool mAllowKeywordFixup;
|
||||
PRPackedBool mIsOffScreenBrowser;
|
||||
PRPackedBool mIsActive;
|
||||
PRPackedBool mIsAppTab;
|
||||
|
||||
// This boolean is set to true right before we fire pagehide and generally
|
||||
// unset when we embed a new content viewer. While it's true no navigation
|
||||
|
@ -71,7 +71,7 @@ interface nsIPrincipal;
|
||||
interface nsIWebBrowserPrint;
|
||||
interface nsIVariant;
|
||||
|
||||
[scriptable, uuid(74470127-87eb-4f79-8293-1616fe9cb689)]
|
||||
[scriptable, uuid(98cdbcc4-2d81-4191-a63f-b6c52085edbc)]
|
||||
interface nsIDocShell : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -529,11 +529,17 @@ interface nsIDocShell : nsISupports
|
||||
*/
|
||||
attribute boolean isActive;
|
||||
|
||||
|
||||
/**
|
||||
* The ID of the docshell in the session history.
|
||||
*/
|
||||
readonly attribute unsigned long long historyID;
|
||||
|
||||
/**
|
||||
* Sets whether a docshell is an app tab. An app tab docshell may behave
|
||||
* differently than a non-app tab docshell in some cases, such as when
|
||||
* handling link clicks. Docshells are not app tabs unless told otherwise.
|
||||
*/
|
||||
attribute boolean isAppTab;
|
||||
};
|
||||
|
||||
[uuid(5f7a2184-31b6-4d67-9c75-0c17477766e2)]
|
||||
|
@ -78,6 +78,7 @@ XPIDLSRCS = \
|
||||
nsIEmbeddingSiteWindow2.idl \
|
||||
nsIContextMenuListener2.idl \
|
||||
nsIWebBrowserChrome2.idl \
|
||||
nsIWebBrowserChrome3.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
65
embedding/browser/webBrowser/nsIWebBrowserChrome3.idl
Normal file
65
embedding/browser/webBrowser/nsIWebBrowserChrome3.idl
Normal file
@ -0,0 +1,65 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Margaret Leibovic <margaret.leibovic@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIWebBrowserChrome2.idl"
|
||||
#include "nsIURI.idl"
|
||||
#include "nsIDOMNode.idl"
|
||||
|
||||
/**
|
||||
* nsIWebBrowserChrome3 is an extension to nsIWebBrowserChrome2.
|
||||
*/
|
||||
[scriptable, uuid(7f2aa813-b250-4e46-afeb-97b1e91bc9a5)]
|
||||
interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2
|
||||
{
|
||||
/**
|
||||
* Determines the appropriate target for a link.
|
||||
*
|
||||
* @param originalTarget
|
||||
* The original link target.
|
||||
* @param linkURI
|
||||
* Link destination URI.
|
||||
* @param aDOMNode
|
||||
* Link DOM node.
|
||||
* @param isAppTab
|
||||
* Whether or not the link is in an app tab.
|
||||
* @returns A new link target, if appropriate.
|
||||
* Otherwise returns originalTarget.
|
||||
*/
|
||||
AString onBeforeLinkTraversal(in AString originalTarget,
|
||||
in nsIURI linkURI,
|
||||
in nsIDOMNode linkNode,
|
||||
in PRBool isAppTab);
|
||||
};
|
@ -562,7 +562,8 @@ nsHelpStatusHandler.prototype = {
|
||||
|
||||
setJSStatus : function(status) {},
|
||||
setJSDefaultStatus : function(status) {},
|
||||
setOverLink : function(link, context) {}
|
||||
setOverLink : function(link, context) {},
|
||||
onBeforeLinkTraversal: function(originalTarget, linkURI, linkNode, isAppTab) {}
|
||||
}
|
||||
|
||||
function UpdateBackForwardButtons() {
|
||||
|
@ -130,3 +130,7 @@ XPCOMUtils.defineLazyServiceGetter(Services, "strings",
|
||||
XPCOMUtils.defineLazyServiceGetter(Services, "urlFormatter",
|
||||
"@mozilla.org/toolkit/URLFormatterService;1",
|
||||
"nsIURLFormatter");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(Services, "eTLD",
|
||||
"@mozilla.org/network/effective-tld-service;1",
|
||||
"nsIEffectiveTLDService");
|
||||
|
@ -76,7 +76,9 @@
|
||||
|
||||
setOverLink: function(aStatusText, aLink) {
|
||||
gStatusText = aStatusText;
|
||||
}
|
||||
},
|
||||
|
||||
onBeforeLinkTraversal: function() { }
|
||||
};
|
||||
|
||||
function ok(condition, message) {
|
||||
|
@ -38,6 +38,8 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIURI.idl"
|
||||
#include "nsIDOMNode.idl"
|
||||
|
||||
interface nsIRequest;
|
||||
interface nsIDOMElement;
|
||||
@ -65,5 +67,13 @@ interface nsIXULBrowserWindow : nsISupports
|
||||
* over.
|
||||
*/
|
||||
void setOverLink(in AString link, in nsIDOMElement element);
|
||||
|
||||
/**
|
||||
* Determines the appropriate target for a link.
|
||||
*/
|
||||
AString onBeforeLinkTraversal(in AString originalTarget,
|
||||
in nsIURI linkURI,
|
||||
in nsIDOMNode linkNode,
|
||||
in PRBool isAppTab);
|
||||
};
|
||||
|
||||
|
@ -124,6 +124,7 @@ NS_INTERFACE_MAP_BEGIN(nsContentTreeOwner)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome2)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome3)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWindowProvider)
|
||||
// NOTE: This is using aggregation because there are some properties and
|
||||
@ -430,6 +431,29 @@ nsContentTreeOwner::GetPersistence(PRBool* aPersistPosition,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsContentTreeOwner::nsIWebBrowserChrome3
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP nsContentTreeOwner::OnBeforeLinkTraversal(const nsAString &originalTarget,
|
||||
nsIURI *linkURI,
|
||||
nsIDOMNode *linkNode,
|
||||
PRBool isAppTab,
|
||||
nsAString &_retval)
|
||||
{
|
||||
NS_ENSURE_STATE(mXULWindow);
|
||||
|
||||
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow;
|
||||
mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow));
|
||||
|
||||
if (xulBrowserWindow)
|
||||
return xulBrowserWindow->OnBeforeLinkTraversal(originalTarget, linkURI,
|
||||
linkNode, isAppTab, _retval);
|
||||
|
||||
_retval = originalTarget;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsContentTreeOwner::nsIWebBrowserChrome2
|
||||
//*****************************************************************************
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIWebBrowserChrome2.h"
|
||||
#include "nsIWebBrowserChrome3.h"
|
||||
#include "nsIWindowProvider.h"
|
||||
|
||||
class nsXULWindow;
|
||||
@ -58,7 +58,7 @@ class nsSiteWindow2;
|
||||
class nsContentTreeOwner : public nsIDocShellTreeOwner,
|
||||
public nsIBaseWindow,
|
||||
public nsIInterfaceRequestor,
|
||||
public nsIWebBrowserChrome2,
|
||||
public nsIWebBrowserChrome3,
|
||||
public nsIWindowProvider
|
||||
{
|
||||
friend class nsXULWindow;
|
||||
@ -72,6 +72,7 @@ public:
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
NS_DECL_NSIWEBBROWSERCHROME
|
||||
NS_DECL_NSIWEBBROWSERCHROME2
|
||||
NS_DECL_NSIWEBBROWSERCHROME3
|
||||
NS_DECL_NSIWINDOWPROVIDER
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user