#579: M1218456 +backbugs -nsILinkHandler removal, with changes for 45

This commit is contained in:
Cameron Kaiser 2019-11-16 15:45:56 -08:00
parent d89529ac0b
commit 5e0cd430c2
21 changed files with 74 additions and 117 deletions

View File

@ -16,6 +16,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/Animation.h"
#include "mozilla/dom/Attr.h"
#include "nsDocShell.h"
#include "nsDOMAttributeMap.h"
#include "nsIAtom.h"
#include "nsIContentInlines.h"
@ -26,7 +27,6 @@
#include "nsIContentIterator.h"
#include "nsFocusManager.h"
#include "nsFrameManager.h"
#include "nsILinkHandler.h"
#include "nsIScriptGlobalObject.h"
#include "nsIURL.h"
#include "nsContainerFrame.h"
@ -2171,12 +2171,15 @@ Element::GetPrimaryFrame(mozFlushType aType)
nsresult
Element::LeaveLink(nsPresContext* aPresContext)
{
nsILinkHandler *handler = aPresContext->GetLinkHandler();
if (!handler) {
if (!aPresContext || !aPresContext->Document()->LinkHandlingEnabled()) {
return NS_OK;
}
return handler->OnLeaveLink();
nsIDocShell* shell = aPresContext->Document()->GetDocShell();
if (!shell) {
return NS_OK;
}
return nsDocShell::Cast(shell)->OnLeaveLink();
}
nsresult
@ -2941,7 +2944,6 @@ Element::CheckHandleEventForLinksPrecondition(EventChainVisitor& aVisitor,
(aVisitor.mEvent->mMessage != eMouseClick) &&
(aVisitor.mEvent->mMessage != eKeyPress) &&
(aVisitor.mEvent->mMessage != eLegacyDOMActivate)) ||
!aVisitor.mPresContext ||
aVisitor.mEvent->mFlags.mMultipleActionsPrevented) {
return false;
}
@ -2985,7 +2987,7 @@ Element::PreHandleEventForLinks(EventChainPreVisitor& aVisitor)
if (!focusEvent || !focusEvent->isRefocus) {
nsAutoString target;
GetLinkTarget(target);
nsContentUtils::TriggerLink(this, aVisitor.mPresContext, absURI, target,
nsContentUtils::TriggerLink(this, absURI, target,
false, true, true);
// Make sure any ancestor links don't also TriggerLink
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
@ -3038,27 +3040,28 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor)
case eMouseDown:
{
if (aVisitor.mEvent->AsMouseEvent()->button ==
WidgetMouseEvent::eLeftButton) {
// don't make the link grab the focus if there is no link handler
nsILinkHandler *handler = aVisitor.mPresContext->GetLinkHandler();
nsIDocument *document = GetComposedDoc();
if (handler && document) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
WidgetMouseEvent::eLeftButton &&
OwnerDoc()->LinkHandlingEnabled()) {
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
if (IsInComposedDoc()) {
if (nsIFocusManager* fm = nsFocusManager::GetFocusManager()) {
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(this);
fm->SetFocus(elem, 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.
// 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()) {
nsCOMPtr<nsISpeculativeConnect>
speculator(do_QueryInterface(nsContentUtils::GetIOService()));
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(handler);
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(shell);
// We need bug 1304219 for this part, but this will suffice for now.
//speculator->SpeculativeConnect2(absURI, NodePrincipal(), ir);
speculator->SpeculativeConnect(absURI, ir);
@ -3076,19 +3079,16 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor)
}
// The default action is simply to dispatch DOMActivate
nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
if (shell) {
// 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.detail = 1;
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.detail = 1;
rv = shell->HandleDOMEventWithTarget(this, &actEvent, &status);
if (NS_SUCCEEDED(rv)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
rv = EventDispatcher::Dispatch(this, aVisitor.mPresContext, &actEvent,
nullptr, &status);
if (NS_SUCCEEDED(rv)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
}
break;
@ -3100,7 +3100,7 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor)
GetLinkTarget(target);
const InternalUIEvent* activeEvent = aVisitor.mEvent->AsUIEvent();
MOZ_ASSERT(activeEvent);
nsContentUtils::TriggerLink(this, aVisitor.mPresContext, absURI, target,
nsContentUtils::TriggerLink(this, absURI, target,
true, true, activeEvent->IsTrustable());
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}

View File

@ -18,7 +18,6 @@
#include "mozilla/EventStates.h" // for member
#include "mozilla/dom/DirectionalityUtils.h"
#include "nsIDOMElement.h"
#include "nsILinkHandler.h"
#include "nsINodeList.h"
#include "nsNodeUtils.h"
#include "nsAttrAndChildArray.h"

View File

@ -32,7 +32,6 @@
#include "nsIDOMNodeList.h"
#include "nsIContentIterator.h"
#include "nsFocusManager.h"
#include "nsILinkHandler.h"
#include "nsIScriptGlobalObject.h"
#include "nsIURL.h"
#include "nsNetUtil.h"

View File

@ -81,6 +81,7 @@
#include "nsCycleCollectionParticipant.h"
#include "nsCycleCollector.h"
#include "nsDataHashtable.h"
#include "nsDocShell.h"
#include "nsDocShellCID.h"
#include "nsDocument.h"
#include "nsDOMCID.h"
@ -4795,25 +4796,24 @@ nsContentUtils::CombineResourcePrincipals(nsCOMPtr<nsIPrincipal>* aResourcePrinc
/* static */
void
nsContentUtils::TriggerLink(nsIContent *aContent, nsPresContext *aPresContext,
nsContentUtils::TriggerLink(nsIContent *aContent,
nsIURI *aLinkURI, const nsString &aTargetSpec,
bool aClick, bool aIsUserTriggered,
bool aIsTrusted)
{
NS_ASSERTION(aPresContext, "Need a nsPresContext");
NS_PRECONDITION(aLinkURI, "No link URI");
if (aContent->IsEditable()) {
if (aContent->IsEditable() || !aContent->OwnerDoc()->LinkHandlingEnabled()) {
return;
}
nsILinkHandler *handler = aPresContext->GetLinkHandler();
if (!handler) {
nsCOMPtr<nsIDocShell> docShell = aContent->OwnerDoc()->GetDocShell();
if (!docShell) {
return;
}
if (!aClick) {
handler->OnOverLink(aContent, aLinkURI, aTargetSpec.get());
nsDocShell::Cast(docShell)->OnOverLink(aContent, aLinkURI, aTargetSpec.get());
return;
}
@ -4848,7 +4848,7 @@ nsContentUtils::TriggerLink(nsIContent *aContent, nsPresContext *aPresContext,
fileName.SetIsVoid(true); // No actionable download attribute was found.
}
handler->OnLinkClick(aContent, aLinkURI,
nsDocShell::Cast(docShell)->OnLinkClick(aContent, aLinkURI,
fileName.IsVoid() ? aTargetSpec.get() : EmptyString().get(),
fileName, nullptr, nullptr, aIsTrusted);
}

View File

@ -1506,7 +1506,6 @@ public:
* 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
@ -1517,7 +1516,7 @@ public:
* @param aIsTrusted If false, JS Context will be pushed to stack
* when the link is triggered.
*/
static void TriggerLink(nsIContent *aContent, nsPresContext *aPresContext,
static void TriggerLink(nsIContent *aContent,
nsIURI *aLinkURI, const nsString& aTargetSpec,
bool aClick, bool aIsUserTriggered,
bool aIsTrusted);

View File

@ -1435,6 +1435,7 @@ nsIDocument::nsIDocument()
mPostedFlushUserFontSet(false),
mDidFireDOMContentLoaded(true),
mFrameRequestCallbacksScheduled(false),
mLinksEnabled(true),
mPartID(0),
mUserHasInteracted(false)
{

View File

@ -1358,7 +1358,8 @@ public:
virtual void SetContainer(nsDocShell* aContainer);
/**
* Get the container (docshell) for this document.
* Get the container (docshell) for this document. Virtual so that
* the shell service can call it.
*/
virtual nsISupports* GetContainer() const;
@ -2679,6 +2680,9 @@ public:
bool InlineScriptAllowedByCSP();
void SetLinkHandlingEnabled(bool aValue) { mLinksEnabled = aValue; }
bool LinkHandlingEnabled() { return mLinksEnabled; }
protected:
bool GetUseCounter(mozilla::UseCounter aUseCounter)
{
@ -2960,6 +2964,10 @@ protected:
// UpdateFrameRequestCallbackSchedulingState.
bool mFrameRequestCallbacksScheduled : 1;
// False if we've disabled link handling for elements inside this document,
// true otherwise.
bool mLinksEnabled : 1;
enum Type {
eUnknown, // should never be used
eHTML,

View File

@ -61,7 +61,6 @@
#include "nsIDOMNodeList.h"
#include "nsIEditor.h"
#include "nsIEditorIMESupport.h"
#include "nsILinkHandler.h"
#include "mozilla/dom/NodeInfo.h"
#include "mozilla/dom/NodeInfoInlines.h"
#include "nsIPresShell.h"

View File

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

View File

@ -23,6 +23,7 @@
#include "nsPresContext.h"
#include "nsIDocument.h"
#include "nsIFormControlFrame.h"
#include "nsILinkHandler.h"
#include "nsError.h"
#include "nsContentUtils.h"
#include "nsInterfaceHashtable.h"

View File

@ -8,7 +8,6 @@
#include "nsCOMPtr.h"
#include "nsIForm.h"
#include "nsILinkHandler.h"
#include "nsIDocument.h"
#include "nsGkAtoms.h"
#include "nsIFormControl.h"

View File

@ -653,22 +653,9 @@ nsGenericHTMLElement::CheckHandleEventForAnchorsPreconditions(
{
NS_PRECONDITION(nsCOMPtr<Link>(do_QueryObject(this)),
"should be called only when |this| implements |Link|");
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);
// When disconnected, only <a> should navigate away per
// https://html.spec.whatwg.org/#cannot-navigate
return IsInComposedDoc() || IsHTMLElement(nsGkAtoms::a);
}
nsresult

View File

@ -187,6 +187,12 @@ SVGAElement::IsAttributeMapped(const nsIAtom* name) const
bool
SVGAElement::IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse)
{
// There are some backbugs in
// https://hg.mozilla.org/mozilla-central/rev/fc09b999be43
if (!OwnerDoc()->LinkHandlingEnabled()) {
return false;
}
nsCOMPtr<nsIURI> uri;
if (IsLink(getter_AddRefs(uri))) {
if (aTabIndex) {

View File

@ -34,7 +34,6 @@
#include "nsIDOMHTMLAnchorElement.h"
#include "nsISelectionController.h"
#include "nsIDOMHTMLDocument.h"
#include "nsILinkHandler.h"
#include "nsIInlineSpellChecker.h"
#include "mozilla/CSSStyleSheet.h"
@ -143,13 +142,10 @@ nsHTMLEditor::~nsHTMLEditor()
// free any default style propItems
RemoveAllDefaultProperties();
if (mLinkHandler && mDocWeak)
{
nsCOMPtr<nsIPresShell> ps = GetPresShell();
if (ps && ps->GetPresContext())
{
ps->GetPresContext()->SetLinkHandler(mLinkHandler);
if (mDisabledLinkHandling) {
nsCOMPtr<nsIDocument> doc = GetDocument();
if (doc) {
doc->SetLinkHandlingEnabled(mOldLinkHandlingEnabled);
}
}
@ -268,14 +264,12 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc,
mHTMLCSSUtils = new nsHTMLCSSUtils(this);
// disable links
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsPresContext *context = presShell->GetPresContext();
NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
if (!IsPlaintextEditor() && !IsInteractionAllowed()) {
mLinkHandler = context->GetLinkHandler();
context->SetLinkHandler(nullptr);
mDisabledLinkHandling = true;
mOldLinkHandlingEnabled = doc->LinkHandlingEnabled();
doc->SetLinkHandlingEnabled(false);
}
// init the type-in state

View File

@ -46,7 +46,6 @@ class nsITransferable;
class nsIClipboard;
class TypeInState;
class nsIContentFilter;
class nsILinkHandler;
class nsTableOuterFrame;
class nsIDOMRange;
class nsRange;
@ -954,7 +953,8 @@ protected:
void AddMouseClickListener(nsIDOMElement * aElement);
void RemoveMouseClickListener(nsIDOMElement * aElement);
nsCOMPtr<nsILinkHandler> mLinkHandler;
bool mDisabledLinkHandling = false;
bool mOldLinkHandlingEnabled = false;
public:

View File

@ -24,7 +24,6 @@
#include "nsIWritablePropertyBag2.h"
#include "nsSubDocumentFrame.h"
#include "nsILinkHandler.h"
#include "nsIDOMDocument.h"
#include "nsISelectionListener.h"
#include "mozilla/dom/Selection.h"
@ -884,12 +883,7 @@ 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->SetContainer(mContainer);
mPresContext->SetLinkHandler(linkHandler);
}
// Set script-context-owner in the document
@ -1368,7 +1362,6 @@ AttachContainerRecurse(nsIDocShell* aShell)
viewer->GetPresContext(getter_AddRefs(pc));
if (pc) {
pc->SetContainer(static_cast<nsDocShell*>(aShell));
pc->SetLinkHandler(nsCOMPtr<nsILinkHandler>(do_QueryInterface(aShell)));
}
nsCOMPtr<nsIPresShell> presShell;
viewer->GetPresShell(getter_AddRefs(presShell));
@ -2081,12 +2074,6 @@ nsDocumentViewer::Show(void)
return rv;
if (mPresContext && base_win) {
nsCOMPtr<nsILinkHandler> linkHandler(do_GetInterface(base_win));
if (linkHandler) {
mPresContext->SetLinkHandler(linkHandler);
}
mPresContext->SetContainer(mContainer);
}

View File

@ -1720,7 +1720,6 @@ nsPresContext::GetDocShell() const
nsPresContext::Detach()
{
SetContainer(nullptr);
SetLinkHandler(nullptr);
if (mShell) {
mShell->CancelInvalidatePresShellIfHidden();
}

View File

@ -50,7 +50,6 @@ class nsITheme;
class nsIContent;
class nsIFrame;
class nsFrameManager;
class nsILinkHandler;
class nsIAtom;
class nsIRunnable;
class gfxUserFontEntry;
@ -436,13 +435,8 @@ public:
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), SetContainer(null) etc.
* Detach this pres context - i.e. cancel relevant timers, etc.
* Only to be used by the DocumentViewer.
*/
virtual void Detach();
@ -1228,10 +1222,6 @@ protected:
nsIAtom* MOZ_UNSAFE_REF("always a static atom") mMedium; // initialized by subclass ctors
nsCOMPtr<nsIAtom> mMediaEmulated;
// 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;
// Formerly mLangGroup; moving from charset-oriented langGroup to
// maintaining actual language settings everywhere (see bug 524107).
// This may in fact hold a langGroup such as x-western rather than

View File

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

View File

@ -2061,7 +2061,7 @@ nsImageFrame::HandleEvent(nsPresContext* aPresContext,
*aEventStatus = nsEventStatus_eConsumeDoDefault;
clicked = true;
}
nsContentUtils::TriggerLink(anchorNode, aPresContext, uri, target,
nsContentUtils::TriggerLink(anchorNode, uri, target,
clicked, true, true);
}
}

View File

@ -26,7 +26,6 @@
#include "nsIPresShell.h"
#include "nsIDocument.h"
#include "nsImageMap.h"
#include "nsILinkHandler.h"
#include "nsIURL.h"
#include "nsILoadGroup.h"
#include "nsContainerFrame.h"