Skip to content

Commit

Permalink
#579: M1218456 +backbugs -nsILinkHandler removal, with changes for 45
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Nov 16, 2019
1 parent d89529a commit 5e0cd43
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 118 deletions.
62 changes: 31 additions & 31 deletions dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;

rv = shell->HandleDOMEventWithTarget(this, &actEvent, &status);
if (NS_SUCCEEDED(rv)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
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 = EventDispatcher::Dispatch(this, aVisitor.mPresContext, &actEvent,
nullptr, &status);
if (NS_SUCCEEDED(rv)) {
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}
}
break;
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion dom/base/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion dom/base/FragmentOrElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 7 additions & 7 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,6 @@ 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
Expand All @@ -1517,7 +1516,7 @@ class nsContentUtils
* @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);
Expand Down
1 change: 1 addition & 0 deletions dom/base/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ nsIDocument::nsIDocument()
mPostedFlushUserFontSet(false),
mDidFireDOMContentLoaded(true),
mFrameRequestCallbacksScheduled(false),
mLinksEnabled(true),
mPartID(0),
mUserHasInteracted(false)
{
Expand Down
10 changes: 9 additions & 1 deletion dom/base/nsIDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,8 @@ class nsIDocument : public nsINode
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;

Expand Down Expand Up @@ -2679,6 +2680,9 @@ class nsIDocument : public nsINode

bool InlineScriptAllowedByCSP();

void SetLinkHandlingEnabled(bool aValue) { mLinksEnabled = aValue; }
bool LinkHandlingEnabled() { return mLinksEnabled; }

protected:
bool GetUseCounter(mozilla::UseCounter aUseCounter)
{
Expand Down Expand Up @@ -2960,6 +2964,10 @@ class nsIDocument : public nsINode
// 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,
Expand Down
1 change: 0 additions & 1 deletion dom/base/nsINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 3 additions & 10 deletions dom/html/HTMLAnchorElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dom/html/HTMLFormElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion dom/html/nsFormSubmission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "nsCOMPtr.h"
#include "nsIForm.h"
#include "nsILinkHandler.h"
#include "nsIDocument.h"
#include "nsGkAtoms.h"
#include "nsIFormControl.h"
Expand Down
19 changes: 3 additions & 16 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions dom/svg/SVGAElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 9 additions & 15 deletions editor/libeditor/nsHTMLEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "nsIDOMHTMLAnchorElement.h"
#include "nsISelectionController.h"
#include "nsIDOMHTMLDocument.h"
#include "nsILinkHandler.h"
#include "nsIInlineSpellChecker.h"

#include "mozilla/CSSStyleSheet.h"
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions editor/libeditor/nsHTMLEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class nsITransferable;
class nsIClipboard;
class TypeInState;
class nsIContentFilter;
class nsILinkHandler;
class nsTableOuterFrame;
class nsIDOMRange;
class nsRange;
Expand Down Expand Up @@ -954,7 +953,8 @@ class nsHTMLEditor final : public nsPlaintextEditor,
void AddMouseClickListener(nsIDOMElement * aElement);
void RemoveMouseClickListener(nsIDOMElement * aElement);

nsCOMPtr<nsILinkHandler> mLinkHandler;
bool mDisabledLinkHandling = false;
bool mOldLinkHandlingEnabled = false;

public:

Expand Down
Loading

0 comments on commit 5e0cd43

Please sign in to comment.