Backed out 5 changesets (bug 1218456) for Crashtest failures on dom/l10n/tests/mochitest/dom_localization/test_overlay.html. CLOSED TREE

Backed out changeset 31afe89c2d42 (bug 1218456)
Backed out changeset 8bd57ebc4528 (bug 1218456)
Backed out changeset e5d37afff36a (bug 1218456)
Backed out changeset e3da86278ecf (bug 1218456)
Backed out changeset 343046089f8e (bug 1218456)

--HG--
extra : rebase_source : f092d903c8c80581d187493e036b1875d8668b3d
This commit is contained in:
Dorel Luca 2019-07-09 22:04:13 +03:00
Родитель 441c28479d
Коммит 9925ca654c
28 изменённых файлов: 329 добавлений и 154 удалений

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

@ -25,6 +25,9 @@ with Files('*LoadContext.*'):
with Files('nsAboutRedirector.*'):
BUG_COMPONENT = ('Core', 'General')
with Files('nsILinkHandler.*'):
BUG_COMPONENT = ('Core', 'DOM: Core & HTML')
with Files('nsIScrollObserver.*'):
BUG_COMPONENT = ('Core', 'Panning and Zooming')
@ -61,6 +64,7 @@ EXPORTS += [
'nsDocShellLoadState.h',
'nsDocShellLoadTypes.h',
'nsDocShellTreeOwner.h',
'nsILinkHandler.h',
'nsIScrollObserver.h',
'SerializedLoadContext.h',
]

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

@ -557,6 +557,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIWebPageDescriptor)
NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider)
NS_INTERFACE_MAP_ENTRY(nsILoadContext)
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
NS_INTERFACE_MAP_ENTRY(nsIDOMStorageManager)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsINetworkInterceptController,
mInterceptController)
@ -12639,7 +12640,8 @@ OnLinkClickEvent::OnLinkClickEvent(
mTriggeringPrincipal(aTriggeringPrincipal),
mCsp(aCsp) {}
nsresult nsDocShell::OnLinkClick(
NS_IMETHODIMP
nsDocShell::OnLinkClick(
nsIContent* aContent, nsIURI* aURI, const nsAString& aTargetSpec,
const nsAString& aFileName, nsIInputStream* aPostDataStream,
nsIInputStream* aHeadersDataStream, bool aIsUserTriggered, bool aIsTrusted,
@ -12697,7 +12699,8 @@ static bool IsElementAnchorOrArea(nsIContent* aContent) {
return aContent->IsAnyOfHTMLElements(nsGkAtoms::a, nsGkAtoms::area);
}
nsresult nsDocShell::OnLinkClickSync(
NS_IMETHODIMP
nsDocShell::OnLinkClickSync(
nsIContent* aContent, nsIURI* aURI, const nsAString& aTargetSpec,
const nsAString& aFileName, nsIInputStream* aPostDataStream,
nsIInputStream* aHeadersDataStream, bool aNoOpenerImplied,
@ -12881,8 +12884,9 @@ nsresult nsDocShell::OnLinkClickSync(
return rv;
}
nsresult nsDocShell::OnOverLink(nsIContent* aContent, nsIURI* aURI,
const nsAString& aTargetSpec) {
NS_IMETHODIMP
nsDocShell::OnOverLink(nsIContent* aContent, nsIURI* aURI,
const nsAString& aTargetSpec) {
if (aContent->IsEditable()) {
return NS_OK;
}
@ -12916,7 +12920,8 @@ nsresult nsDocShell::OnOverLink(nsIContent* aContent, nsIURI* aURI,
return rv;
}
nsresult nsDocShell::OnLeaveLink() {
NS_IMETHODIMP
nsDocShell::OnLeaveLink() {
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));
nsresult rv = NS_ERROR_FAILURE;

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

@ -29,6 +29,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIDOMStorageManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsILinkHandler.h"
#include "nsILoadContext.h"
#include "nsILoadURIDelegate.h"
#include "nsINetworkInterceptController.h"
@ -119,6 +120,7 @@ class nsDocShell final : public nsDocLoader,
public nsIWebPageDescriptor,
public nsIAuthPromptProvider,
public nsILoadContext,
public nsILinkHandler,
public nsIDOMStorageManager,
public nsINetworkInterceptController,
public nsIDeprecationWarner,
@ -209,80 +211,26 @@ class nsDocShell final : public nsDocLoader,
return nsDocLoader::Stop();
}
/**
* Process a click on a link.
*
* @param aContent the content object used for triggering the link.
* @param aURI a URI object that defines the destination for the link
* @param aTargetSpec indicates where the link is targeted (may be an empty
* string)
* @param aFileName non-null when the link should be downloaded as the given
* file
* @param aPostDataStream the POST data to send
* @param aHeadersDataStream ??? (only used for plugins)
* @param aIsTrusted false if the triggerer is an untrusted DOM event.
* @param aTriggeringPrincipal, if not passed explicitly we fall back to
* the document's principal.
* @param aCsp, the CSP to be used for the load, that is the CSP of the
* entity responsible for causing the load to occur. Most likely
* this is the CSP of the document that started the load. In case
* aCsp was not passed explicitly we fall back to using
* aContent's document's CSP if that document holds any.
*/
nsresult OnLinkClick(nsIContent* aContent, nsIURI* aURI,
const nsAString& aTargetSpec, const nsAString& aFileName,
nsIInputStream* aPostDataStream,
nsIInputStream* aHeadersDataStream,
bool aIsUserTriggered, bool aIsTrusted,
nsIPrincipal* aTriggeringPrincipal,
nsIContentSecurityPolicy* aCsp);
/**
* Process a click on a link.
*
* Works the same as OnLinkClick() except it happens immediately rather than
* through an event.
*
* @param aContent the content object used for triggering the link.
* @param aURI a URI obect that defines the destination for the link
* @param aTargetSpec indicates where the link is targeted (may be an empty
* string)
* @param aFileName non-null when the link should be downloaded as the given
* file
* @param aPostDataStream the POST data to send
* @param aHeadersDataStream ??? (only used for plugins)
* @param aNoOpenerImplied if the link implies "noopener"
* @param aDocShell (out-param) the DocShell that the request was opened on
* @param aRequest the request that was opened
* @param aTriggeringPrincipal, if not passed explicitly we fall back to
* the document's principal.
* @param aCsp, the CSP to be used for the load, that is the CSP of the
* entity responsible for causing the load to occur. Most likely
* this is the CSP of the document that started the load. In case
* aCsp was not passed explicitly we fall back to using
* aContent's document's CSP if that document holds any.
*/
nsresult OnLinkClickSync(
// nsILinkHandler
NS_IMETHOD OnLinkClick(nsIContent* aContent, nsIURI* aURI,
const nsAString& aTargetSpec,
const nsAString& aFileName,
nsIInputStream* aPostDataStream,
nsIInputStream* aHeadersDataStream,
bool aIsUserTriggered, bool aIsTrusted,
nsIPrincipal* aTriggeringPrincipal,
nsIContentSecurityPolicy* aCsp) override;
NS_IMETHOD OnLinkClickSync(
nsIContent* aContent, nsIURI* aURI, const nsAString& aTargetSpec,
const nsAString& aFileName, nsIInputStream* aPostDataStream = nullptr,
nsIInputStream* aHeadersDataStream = nullptr,
bool aNoOpenerImplied = false, nsIDocShell** aDocShell = nullptr,
nsIRequest** aRequest = nullptr, bool aIsUserTriggered = false,
const nsAString& aFileName, nsIInputStream* aPostDataStream = 0,
nsIInputStream* aHeadersDataStream = 0, bool aNoOpenerImplied = false,
nsIDocShell** aDocShell = 0, nsIRequest** aRequest = 0,
bool aIsUserTriggered = false,
nsIPrincipal* aTriggeringPrincipal = nullptr,
nsIContentSecurityPolicy* aCsp = nullptr);
/**
* Process a mouse-over a link.
*
* @param aContent the linked content.
* @param aURI an URI object that defines the destination for the link
* @param aTargetSpec indicates where the link is targeted (it may be an empty
* string)
*/
nsresult OnOverLink(nsIContent* aContent, nsIURI* aURI,
const nsAString& aTargetSpec);
/**
* Process the mouse leaving a link.
*/
nsresult OnLeaveLink();
nsIContentSecurityPolicy* aCsp = nullptr) override;
NS_IMETHOD OnOverLink(nsIContent* aContent, nsIURI* aURI,
const nsAString& aTargetSpec) override;
NS_IMETHOD OnLeaveLink() override;
// Don't use NS_DECL_NSILOADCONTEXT because some of nsILoadContext's methods
// are shared with nsIDocShell and can't be declared twice.

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

@ -0,0 +1,114 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsILinkHandler_h___
#define nsILinkHandler_h___
#include "nsISupports.h"
#include "mozilla/EventForwards.h"
class nsIContent;
class nsIContentSecurityPolicy;
class nsIDocShell;
class nsIInputStream;
class nsIRequest;
#define NS_ILINKHANDLER_IID \
{ \
0xceb9aade, 0x43da, 0x4f1a, { \
0xac, 0x8a, 0xc7, 0x09, 0xfb, 0x22, 0x46, 0x64 \
} \
}
/**
* Interface used for handling clicks on links
*/
class nsILinkHandler : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ILINKHANDLER_IID)
/**
* Process a click on a link.
*
* @param aContent the content for the frame that generated the trigger
* @param aURI a URI object that defines the destination for the link
* @param aTargetSpec indicates where the link is targeted (may be an empty
* string)
* @param aFileName non-null when the link should be downloaded as the given
* file
* @param aPostDataStream the POST data to send
* @param aHeadersDataStream ???
* @param aIsTrusted false if the triggerer is an untrusted DOM event.
* @param aTriggeringPrincipal, if not passed explicitly we fall back to
* the document's principal.
* @param aCsp, the CSP to be used for the load, that is the CSP of the
* entity responsible for causing the load to occur. Most likely
* this is the CSP of the document that started the load. In case
* aCsp was not passed explicitly we fall back to using
* aContent's document's CSP if that document holds any.
*/
NS_IMETHOD OnLinkClick(nsIContent* aContent, nsIURI* aURI,
const nsAString& aTargetSpec,
const nsAString& aFileName,
nsIInputStream* aPostDataStream,
nsIInputStream* aHeadersDataStream,
bool aIsUserTriggered, bool aIsTrusted,
nsIPrincipal* aTriggeringPrincipal,
nsIContentSecurityPolicy* aCsp) = 0;
/**
* Process a click on a link.
*
* Works the same as OnLinkClick() except it happens immediately rather than
* through an event.
*
* @param aContent the content for the frame that generated the trigger
* @param aURI a URI obect that defines the destination for the link
* @param aTargetSpec indicates where the link is targeted (may be an empty
* string)
* @param aFileName non-null when the link should be downloaded as the given
* file
* @param aPostDataStream the POST data to send
* @param aHeadersDataStream ???
* @param aNoOpenerImplied if the link implies "noopener"
* @param aDocShell (out-param) the DocShell that the request was opened on
* @param aRequest the request that was opened
* @param aTriggeringPrincipal, if not passed explicitly we fall back to
* the document's principal.
* @param aCsp, the CSP to be used for the load, that is the CSP of the
* entity responsible for causing the load to occur. Most likely
* this is the CSP of the document that started the load. In case
* aCsp was not passed explicitly we fall back to using
* aContent's document's CSP if that document holds any.
*/
NS_IMETHOD OnLinkClickSync(
nsIContent* aContent, nsIURI* aURI, const nsAString& aTargetSpec,
const nsAString& aFileName, nsIInputStream* aPostDataStream = 0,
nsIInputStream* aHeadersDataStream = 0, bool aNoOpenerImplied = false,
nsIDocShell** aDocShell = 0, nsIRequest** aRequest = 0,
bool aIsUserTriggered = false,
nsIPrincipal* aTriggeringPrincipal = nullptr,
nsIContentSecurityPolicy* aCsp = nullptr) = 0;
/**
* Process a mouse-over a link.
*
* @param aContent the linked content.
* @param aURI an URI object that defines the destination for the link
* @param aTargetSpec indicates where the link is targeted (it may be an empty
* string)
*/
NS_IMETHOD OnOverLink(nsIContent* aContent, nsIURI* aURLSpec,
const nsAString& aTargetSpec) = 0;
/**
* Process the mouse leaving a link.
*/
NS_IMETHOD OnLeaveLink() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsILinkHandler, NS_ILINKHANDLER_IID)
#endif /* nsILinkHandler_h___ */

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

@ -1245,7 +1245,6 @@ Document::Document(const char* aContentType)
mDidCallBeginLoad(false),
mAllowPaymentRequest(false),
mEncodingMenuDisabled(false),
mLinksEnabled(true),
mIsSVGGlyphsDocument(false),
mInDestructor(false),
mIsGoingAway(false),

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

@ -1367,9 +1367,6 @@ class Document : public nsINode,
*/
void DisableCookieAccess() { mDisableCookieAccess = true; }
void SetLinkHandlingEnabled(bool aValue) { mLinksEnabled = aValue; }
bool LinkHandlingEnabled() { return mLinksEnabled; }
/**
* Set compatibility mode for this document
*/
@ -2339,7 +2336,7 @@ class Document : public nsINode,
/**
* Get the container (docshell) for this document.
*/
nsISupports* GetContainer() const;
virtual nsISupports* GetContainer() const;
/**
* Get the container's load context for this document.
@ -4664,10 +4661,6 @@ class Document : public nsINode,
// True if the encoding menu should be disabled.
bool mEncodingMenuDisabled : 1;
// False if we've disabled link handling for elements inside this document,
// true otherwise.
bool mLinksEnabled : 1;
// True if this document is for an SVG-in-OpenType font.
bool mIsSVGGlyphsDocument : 1;

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

@ -30,6 +30,7 @@
#include "mozilla/dom/DocumentTimeline.h"
#include "nsFlexContainerFrame.h"
#include "nsFocusManager.h"
#include "nsILinkHandler.h"
#include "nsIScriptGlobalObject.h"
#include "nsIURL.h"
#include "nsContainerFrame.h"
@ -2171,14 +2172,12 @@ nsresult Element::DispatchClickEvent(nsPresContext* aPresContext,
//----------------------------------------------------------------------
nsresult Element::LeaveLink(nsPresContext* aPresContext) {
if (!aPresContext || !aPresContext->Document()->LinkHandlingEnabled()) {
nsILinkHandler* handler = aPresContext->GetLinkHandler();
if (!handler) {
return NS_OK;
}
nsIDocShell* shell = aPresContext->Document()->GetDocShell();
if (!shell) {
return NS_OK;
}
return nsDocShell::Cast(shell)->OnLeaveLink();
return handler->OnLeaveLink();
}
nsresult Element::SetEventHandler(nsAtom* aEventName, const nsAString& aValue,
@ -2976,6 +2975,7 @@ bool Element::CheckHandleEventForLinksPrecondition(EventChainVisitor& aVisitor,
(aVisitor.mEvent->mMessage != eMouseClick) &&
(aVisitor.mEvent->mMessage != eKeyPress) &&
(aVisitor.mEvent->mMessage != eLegacyDOMActivate)) ||
!aVisitor.mPresContext ||
aVisitor.mEvent->mFlags.mMultipleActionsPrevented) {
return false;
}
@ -3016,7 +3016,7 @@ void Element::GetEventTargetParentForLinks(EventChainPreVisitor& aVisitor) {
if (!focusEvent || !focusEvent->mIsRefocus) {
nsAutoString target;
GetLinkTarget(target);
nsContentUtils::TriggerLink(this, absURI, target,
nsContentUtils::TriggerLink(this, aVisitor.mPresContext, absURI, target,
/* click */ false, /* isTrusted */ true);
// Make sure any ancestor links don't also TriggerLink
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
@ -3064,29 +3064,27 @@ nsresult Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) {
switch (aVisitor.mEvent->mMessage) {
case eMouseDown: {
if (aVisitor.mEvent->AsMouseEvent()->mButton == MouseButton::eLeft &&
OwnerDoc()->LinkHandlingEnabled()) {
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
if (IsInComposedDoc()) {
if (nsIFocusManager* fm = nsFocusManager::GetFocusManager()) {
if (aVisitor.mEvent->AsMouseEvent()->mButton == MouseButton::eLeft) {
// don't make the link grab the focus if there is no link handler
nsILinkHandler* handler = aVisitor.mPresContext->GetLinkHandler();
Document* document = GetComposedDoc();
if (handler && document) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
RefPtr<Element> kungFuDeathGrip(this);
fm->SetFocus(kungFuDeathGrip, nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL);
}
}
if (aVisitor.mPresContext) {
EventStateManager::SetActiveManager(
aVisitor.mPresContext->EventStateManager(), this);
}
// OK, we're pretty sure we're going to load, so warm up a speculative
// connection to be sure we have one ready when we open the channel.
if (nsIDocShell* shell = OwnerDoc()->GetDocShell()) {
// OK, we're pretty sure we're going to load, so warm up a speculative
// connection to be sure we have one ready when we open the channel.
nsCOMPtr<nsISpeculativeConnect> sc =
do_QueryInterface(nsContentUtils::GetIOService());
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(shell);
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(handler);
sc->SpeculativeConnect(absURI, NodePrincipal(), ir);
}
}
@ -3101,16 +3099,19 @@ nsresult Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) {
}
// The default action is simply to dispatch DOMActivate
nsEventStatus status = nsEventStatus_eIgnore;
// DOMActive event should be trusted since the activation is actually
// occurred even if the cause is an untrusted click event.
InternalUIEvent actEvent(true, eLegacyDOMActivate, mouseEvent);
actEvent.mDetail = 1;
if (RefPtr<PresShell> presShell =
aVisitor.mPresContext->GetPresShell()) {
// single-click
nsEventStatus status = nsEventStatus_eIgnore;
// DOMActive event should be trusted since the activation is actually
// occurred even if the cause is an untrusted click event.
InternalUIEvent actEvent(true, eLegacyDOMActivate, mouseEvent);
actEvent.mDetail = 1;
rv = EventDispatcher::Dispatch(this, aVisitor.mPresContext, &actEvent,
nullptr, &status);
if (NS_SUCCEEDED(rv)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
rv = presShell->HandleDOMEventWithTarget(this, &actEvent, &status);
if (NS_SUCCEEDED(rv)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
}
}
break;
@ -3121,7 +3122,8 @@ nsresult Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) {
GetLinkTarget(target);
const InternalUIEvent* activeEvent = aVisitor.mEvent->AsUIEvent();
MOZ_ASSERT(activeEvent);
nsContentUtils::TriggerLink(this, absURI, target, /* click */ true,
nsContentUtils::TriggerLink(this, aVisitor.mPresContext, absURI, target,
/* click */ true,
activeEvent->IsTrustable());
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}

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

@ -20,6 +20,7 @@
#include "nsChangeHint.h"
#include "nsContentUtils.h"
#include "nsDOMAttributeMap.h"
#include "nsILinkHandler.h"
#include "nsINodeList.h"
#include "nsIScrollableFrame.h"
#include "nsNodeUtils.h"

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

@ -38,6 +38,7 @@
#include "mozilla/dom/DocumentInlines.h"
#include "nsIDocumentEncoder.h"
#include "nsFocusManager.h"
#include "nsILinkHandler.h"
#include "nsIScriptGlobalObject.h"
#include "nsIURL.h"
#include "nsNetUtil.h"

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

@ -5080,22 +5080,24 @@ bool nsContentUtils::CombineResourcePrincipals(
}
/* static */
void nsContentUtils::TriggerLink(nsIContent* aContent, nsIURI* aLinkURI,
void nsContentUtils::TriggerLink(nsIContent* aContent,
nsPresContext* aPresContext, nsIURI* aLinkURI,
const nsString& aTargetSpec, bool aClick,
bool aIsTrusted) {
NS_ASSERTION(aPresContext, "Need a nsPresContext");
MOZ_ASSERT(aLinkURI, "No link URI");
if (aContent->IsEditable() || !aContent->OwnerDoc()->LinkHandlingEnabled()) {
if (aContent->IsEditable()) {
return;
}
nsCOMPtr<nsIDocShell> docShell = aContent->OwnerDoc()->GetDocShell();
if (!docShell) {
nsILinkHandler* handler = aPresContext->GetLinkHandler();
if (!handler) {
return;
}
if (!aClick) {
nsDocShell::Cast(docShell)->OnOverLink(aContent, aLinkURI, aTargetSpec);
handler->OnOverLink(aContent, aLinkURI, aTargetSpec);
return;
}
@ -5130,7 +5132,7 @@ void nsContentUtils::TriggerLink(nsIContent* aContent, nsIURI* aLinkURI,
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aContent->NodePrincipal();
nsCOMPtr<nsIContentSecurityPolicy> csp = aContent->GetCsp();
nsDocShell::Cast(docShell)->OnLinkClick(
handler->OnLinkClick(
aContent, aLinkURI, fileName.IsVoid() ? aTargetSpec : EmptyString(),
fileName, nullptr, nullptr, EventStateManager::IsHandlingUserInput(),
aIsTrusted, triggeringPrincipal, csp);

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

@ -1896,6 +1896,7 @@ class nsContentUtils {
* security check using aContent's principal.
*
* @param aContent the node on which a link was triggered.
* @param aPresContext the pres context, must be non-null.
* @param aLinkURI the URI of the link, must be non-null.
* @param aTargetSpec the target (like target=, may be empty).
* @param aClick whether this was a click or not (if false, this method
@ -1903,9 +1904,9 @@ class nsContentUtils {
* @param aIsTrusted If false, JS Context will be pushed to stack
* when the link is triggered.
*/
static void TriggerLink(nsIContent* aContent, nsIURI* aLinkURI,
const nsString& aTargetSpec, bool aClick,
bool aIsTrusted);
static void TriggerLink(nsIContent* aContent, nsPresContext* aPresContext,
nsIURI* aLinkURI, const nsString& aTargetSpec,
bool aClick, bool aIsTrusted);
/**
* Get the link location.

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

@ -67,6 +67,7 @@
#include "mozilla/dom/DocumentInlines.h"
#include "nsIDOMEventListener.h"
#include "nsIFrameInlines.h"
#include "nsILinkHandler.h"
#include "mozilla/dom/NodeInfo.h"
#include "mozilla/dom/NodeInfoInlines.h"
#include "nsIScriptError.h"

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

@ -142,9 +142,13 @@ bool HTMLAnchorElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
}
// cannot focus links if there is no link handler
if (!OwnerDoc()->LinkHandlingEnabled()) {
*aIsFocusable = false;
return false;
Document* doc = GetComposedDoc();
if (doc) {
nsPresContext* presContext = doc->GetPresContext();
if (presContext && !presContext->GetLinkHandler()) {
*aIsFocusable = false;
return false;
}
}
// Links that are in an editable region should never be focusable, even if

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

@ -634,8 +634,9 @@ nsresult HTMLFormElement::SubmitSubmission(
// If there is no link handler, then we won't actually be able to submit.
Document* doc = GetComposedDoc();
nsCOMPtr<nsIDocShell> container = doc ? doc->GetDocShell() : nullptr;
if (!container || IsEditable()) {
nsCOMPtr<nsISupports> container = doc ? doc->GetContainer() : nullptr;
nsCOMPtr<nsILinkHandler> linkHandler(do_QueryInterface(container));
if (!linkHandler || IsEditable()) {
mIsSubmitting = false;
return NS_OK;
}
@ -700,7 +701,7 @@ nsresult HTMLFormElement::SubmitSubmission(
nsAutoString target;
aFormSubmission->GetTarget(target);
rv = nsDocShell::Cast(container)->OnLinkClickSync(
rv = linkHandler->OnLinkClickSync(
this, actionURI, target, VoidString(), postDataStream, nullptr, false,
getter_AddRefs(docShell), getter_AddRefs(mSubmittingRequest),
aFormSubmission->IsInitiatedFromUserInput());

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

@ -8,6 +8,7 @@
#include "nsCOMPtr.h"
#include "nsIForm.h"
#include "nsILinkHandler.h"
#include "mozilla/dom/Document.h"
#include "nsGkAtoms.h"
#include "nsIFormControl.h"

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

@ -523,9 +523,23 @@ bool nsGenericHTMLElement::CheckHandleEventForAnchorsPreconditions(
EventChainVisitor& aVisitor) {
MOZ_ASSERT(nsCOMPtr<Link>(do_QueryObject(this)),
"should be called only when |this| implements |Link|");
// When disconnected, only <a> should navigate away per
// https://html.spec.whatwg.org/#cannot-navigate
return IsInComposedDoc() || IsHTMLElement(nsGkAtoms::a);
if (!aVisitor.mPresContext) {
// We need a pres context to do link stuff. Some events (e.g. mutation
// events) don't have one.
// XXX: ideally, shouldn't we be able to do what we need without one?
return false;
}
// Need to check if we hit an imagemap area and if so see if we're handling
// the event on that map or on a link farther up the tree. If we're on a
// link farther up, do nothing.
nsCOMPtr<nsIContent> target =
aVisitor.mPresContext->EventStateManager()->GetEventTargetContent(
aVisitor.mEvent);
return !target || !target->IsHTMLElement(nsGkAtoms::area) ||
IsHTMLElement(nsGkAtoms::area);
}
void nsGenericHTMLElement::GetEventTargetParentForAnchors(

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

@ -28,6 +28,7 @@ using mozilla::DefaultXDisplay;
#include "nsIStringStream.h"
#include "nsNetUtil.h"
#include "mozilla/Preferences.h"
#include "nsILinkHandler.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWebBrowserChrome.h"
#include "nsLayoutUtils.h"
@ -388,8 +389,10 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(
}
// the container of the pres context will give us the link handler
nsCOMPtr<nsIDocShell> container = presContext->GetDocShell();
nsCOMPtr<nsISupports> container = presContext->GetContainerWeak();
NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);
nsCOMPtr<nsILinkHandler> lh = do_QueryInterface(container);
NS_ENSURE_TRUE(lh, NS_ERROR_FAILURE);
nsAutoString unitarget;
if ((0 == PL_strcmp(aTarget, "newwindow")) ||
@ -443,10 +446,10 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(
nsCOMPtr<nsIContentSecurityPolicy> csp = content->GetCsp();
rv = nsDocShell::Cast(container)->OnLinkClick(
content, uri, unitarget, VoidString(), aPostStream, headersDataStream,
/* isUserTriggered */ false, /* isTrusted */ true, triggeringPrincipal,
csp);
rv = lh->OnLinkClick(content, uri, unitarget, VoidString(), aPostStream,
headersDataStream,
/* isUserTriggered */ false,
/* isTrusted */ true, triggeringPrincipal, csp);
return rv;
}

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

@ -214,8 +214,13 @@ bool SVGAElement::IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse) {
return isFocusable;
}
if (!OwnerDoc()->LinkHandlingEnabled()) {
return false;
// cannot focus links if there is no link handler
Document* doc = GetComposedDoc();
if (doc) {
nsPresContext* presContext = doc->GetPresContext();
if (presContext && !presContext->GetLinkHandler()) {
return false;
}
}
// Links that are in an editable region should never be focusable, even if

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

@ -30,6 +30,7 @@
#include "nsHTMLDocument.h"
#include "mozilla/dom/DocumentInlines.h"
#include "nsISelectionController.h"
#include "nsILinkHandler.h"
#include "nsIInlineSpellChecker.h"
#include "nsIPrincipal.h"
@ -189,9 +190,10 @@ HTMLEditor::~HTMLEditor() {
mTypeInState = nullptr;
if (mDisabledLinkHandling) {
if (Document* doc = GetDocument()) {
doc->SetLinkHandlingEnabled(mOldLinkHandlingEnabled);
if (mLinkHandler && IsInitialized()) {
PresShell* presShell = GetPresShell();
if (presShell && presShell->GetPresContext()) {
presShell->GetPresContext()->SetLinkHandler(mLinkHandler);
}
}
@ -208,6 +210,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLEditor, TextEditor)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStyleSheets)
tmp->HideAnonymousEditingUIs();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLinkHandler)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLEditor, TextEditor)
@ -239,6 +243,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLEditor, TextEditor)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddRowBeforeButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRemoveRowButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddRowAfterButton)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLinkHandler)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(HTMLEditor, EditorBase)
@ -289,14 +295,15 @@ nsresult HTMLEditor::Init(Document& aDoc, Element* aRoot,
mCSSEditUtils = MakeUnique<CSSEditUtils>(this);
// disable links
Document* doc = GetDocument();
if (NS_WARN_IF(!doc)) {
PresShell* presShell = GetPresShell();
if (NS_WARN_IF(!presShell)) {
return NS_ERROR_FAILURE;
}
nsPresContext* context = presShell->GetPresContext();
NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
if (!IsPlaintextEditor() && !IsInteractionAllowed()) {
mDisabledLinkHandling = true;
mOldLinkHandlingEnabled = doc->LinkHandlingEnabled();
doc->SetLinkHandlingEnabled(false);
mLinkHandler = context->GetLinkHandler();
context->SetLinkHandler(nullptr);
}
// init the type-in state

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

@ -36,6 +36,7 @@ class nsDocumentFragment;
class nsHTMLDocument;
class nsITransferable;
class nsIClipboard;
class nsILinkHandler;
class nsTableWrapperFrame;
class nsRange;
@ -2625,8 +2626,7 @@ class HTMLEditor final : public TextEditor,
void AddMouseClickListener(Element* aElement);
void RemoveMouseClickListener(Element* aElement);
bool mDisabledLinkHandling = false;
bool mOldLinkHandlingEnabled = false;
nsCOMPtr<nsILinkHandler> mLinkHandler;
ParagraphSeparator mDefaultParagraphSeparator;

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

@ -1379,6 +1379,9 @@ void PresShell::Destroy() {
// to us. To avoid the pres context having a dangling reference, set its
// pres shell to nullptr
mPresContext->DetachPresShell();
// Clear the link handler (weak reference) as well
mPresContext->SetLinkHandler(nullptr);
}
mHaveShutDown = true;

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

@ -30,6 +30,7 @@
#include "nsGenericHTMLElement.h"
#include "nsStubMutationObserver.h"
#include "nsILinkHandler.h"
#include "nsISelectionListener.h"
#include "mozilla/dom/Selection.h"
#include "nsContentUtils.h"
@ -949,6 +950,13 @@ nsresult nsDocumentViewer::InitInternal(nsIWidget* aParentWidget,
nsCOMPtr<nsIInterfaceRequestor> requestor(mContainer);
if (requestor) {
if (mPresContext) {
nsCOMPtr<nsILinkHandler> linkHandler;
requestor->GetInterface(NS_GET_IID(nsILinkHandler),
getter_AddRefs(linkHandler));
mPresContext->SetLinkHandler(linkHandler);
}
// Set script-context-owner in the document
nsCOMPtr<nsPIDOMWindowOuter> window = do_GetInterface(requestor);
@ -1531,6 +1539,11 @@ static void AttachContainerRecurse(nsIDocShell* aShell) {
if (doc) {
doc->SetContainer(static_cast<nsDocShell*>(aShell));
}
RefPtr<nsPresContext> pc = viewer->GetPresContext();
if (pc) {
nsCOMPtr<nsILinkHandler> handler = do_QueryInterface(aShell);
pc->SetLinkHandler(handler);
}
if (PresShell* presShell = viewer->GetPresShell()) {
presShell->SetForwardingContainer(WeakPtr<nsDocShell>());
}
@ -1683,9 +1696,14 @@ static void DetachContainerRecurse(nsIDocShell* aShell) {
nsCOMPtr<nsIContentViewer> viewer;
aShell->GetContentViewer(getter_AddRefs(viewer));
if (viewer) {
if (Document* doc = viewer->GetDocument()) {
Document* doc = viewer->GetDocument();
if (doc) {
doc->SetContainer(nullptr);
}
RefPtr<nsPresContext> pc = viewer->GetPresContext();
if (pc) {
pc->Detach();
}
if (PresShell* presShell = viewer->GetPresShell()) {
auto weakShell = static_cast<nsDocShell*>(aShell);
presShell->SetForwardingContainer(weakShell);
@ -1826,6 +1844,9 @@ nsDocumentViewer::Destroy() {
if (mDocument) {
mDocument->SetContainer(nullptr);
}
if (mPresContext) {
mPresContext->Detach();
}
if (mPresShell) {
mPresShell->SetForwardingContainer(mContainer);
}
@ -2237,6 +2258,14 @@ nsDocumentViewer::Show(void) {
containerView);
if (NS_FAILED(rv)) return rv;
if (mPresContext && base_win) {
nsCOMPtr<nsILinkHandler> linkHandler(do_GetInterface(base_win));
if (linkHandler) {
mPresContext->SetLinkHandler(linkHandler);
}
}
if (mPresContext) {
Hide();
@ -4180,6 +4209,7 @@ void nsDocumentViewer::DestroyPresShell() {
}
void nsDocumentViewer::DestroyPresContext() {
mPresContext->Detach();
mPresContext = nullptr;
}

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

@ -145,6 +145,7 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
mDocument(aDocument),
mMedium(aType == eContext_Galley ? nsGkAtoms::screen : nsGkAtoms::print),
mMediaEmulated(mMedium),
mLinkHandler(nullptr),
mInflationDisabledForShrinkWrap(false),
mSystemFontScale(1.0),
mTextZoom(1.0),
@ -1131,6 +1132,9 @@ nsIDocShell* nsPresContext::GetDocShell() const {
return mDocument->GetDocShell();
}
/* virtual */
void nsPresContext::Detach() { SetLinkHandler(nullptr); }
bool nsPresContext::BidiEnabled() const { return Document()->GetBidiEnabled(); }
void nsPresContext::SetBidiEnabled() const { Document()->SetBidiEnabled(); }
@ -2466,6 +2470,12 @@ nsRootPresContext::~nsRootPresContext() {
CancelApplyPluginGeometryTimer();
}
/* virtual */
void nsRootPresContext::Detach() {
// XXXmats maybe also CancelApplyPluginGeometryTimer(); ?
nsPresContext::Detach();
}
void nsRootPresContext::RegisterPluginForGeometryUpdates(nsIContent* aPlugin) {
mRegisteredPlugins.PutEntry(aPlugin);
}

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

@ -52,6 +52,7 @@ class nsITimer;
class nsIContent;
class nsIFrame;
class nsFrameManager;
class nsILinkHandler;
class nsAtom;
class nsIRunnable;
class gfxFontFeatureValueSet;
@ -346,6 +347,17 @@ class nsPresContext : public nsISupports,
nsIDocShell* GetDocShell() const;
// XXX this are going to be replaced with set/get container
void SetLinkHandler(nsILinkHandler* aHandler) { mLinkHandler = aHandler; }
nsILinkHandler* GetLinkHandler() { return mLinkHandler; }
/**
* Detach this pres context - i.e. cancel relevant timers,
* SetLinkHandler(null), etc.
* Only to be used by the DocumentViewer.
*/
virtual void Detach();
/**
* Get the visible area associated with this presentation context.
* This is the size of the visible area that is used for
@ -1123,6 +1135,10 @@ class nsPresContext : public nsISupports,
RefPtr<nsAtom> mMediaEmulated;
RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup;
// This pointer is nulled out through SetLinkHandler() in the destructors of
// the classes which set it. (using SetLinkHandler() again).
nsILinkHandler* MOZ_NON_OWNING_REF mLinkHandler;
public:
// The following are public member variables so that we can use them
// with mozilla::AutoToggle or mozilla::AutoRestore.
@ -1288,6 +1304,7 @@ class nsRootPresContext final : public nsPresContext {
public:
nsRootPresContext(mozilla::dom::Document* aDocument, nsPresContextType aType);
virtual ~nsRootPresContext();
virtual void Detach() override;
/**
* Registers a plugin to receive geometry updates (position and clip

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

@ -2270,8 +2270,8 @@ nsresult nsImageFrame::HandleEvent(nsPresContext* aPresContext,
*aEventStatus = nsEventStatus_eConsumeDoDefault;
clicked = true;
}
nsContentUtils::TriggerLink(anchorNode, uri, target, clicked,
/* isTrusted */ true);
nsContentUtils::TriggerLink(anchorNode, aPresContext, uri, target,
clicked, /* isTrusted */ true);
}
}
}

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

@ -27,6 +27,7 @@
#include "mozilla/dom/Document.h"
#include "mozilla/dom/DocumentInlines.h"
#include "nsImageMap.h"
#include "nsILinkHandler.h"
#include "nsIURL.h"
#include "nsILoadGroup.h"
#include "nsContainerFrame.h"

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

@ -0,0 +1,4 @@
[blob-url-in-main-window-self-navigate-inherits.sub.html]
[Violation report status OK.]
expected: FAIL

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

@ -0,0 +1,4 @@
[activation-behavior.window.html]
[<a> that is not connected should be followed]
expected: FAIL