Issue #2721 - Remove nsILinkHandler.

This interface inly has a single implementation behind it, which is also
only used in 2 places after the previous commit. That's a lot of
additional complexity and compiler indirection for no good reason.
This change removes the interface and uses direct nsDocShell::Cast calls
instead of going through the interface in the few places left now that
we no longer build on a presentation context for links.
This commit is contained in:
Moonchild 2025-06-10 01:51:14 +02:00 • committed by roytam1
commit c3f1c0cdba
16 changed files with 88 additions and 160 deletions

View file

@ -38,7 +38,6 @@ XPIDL_MODULE = 'docshell'
EXPORTS += [ EXPORTS += [
'nsDocShellLoadTypes.h', 'nsDocShellLoadTypes.h',
'nsILinkHandler.h',
'nsIScrollObserver.h', 'nsIScrollObserver.h',
'nsIWebShellServices.h', 'nsIWebShellServices.h',
'SerializedLoadContext.h', 'SerializedLoadContext.h',

View file

@ -956,7 +956,6 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider) NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider)
NS_INTERFACE_MAP_ENTRY(nsILoadContext) NS_INTERFACE_MAP_ENTRY(nsILoadContext)
NS_INTERFACE_MAP_ENTRY(nsIWebShellServices) NS_INTERFACE_MAP_ENTRY(nsIWebShellServices)
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
NS_INTERFACE_MAP_ENTRY(nsIClipboardCommands) NS_INTERFACE_MAP_ENTRY(nsIClipboardCommands)
NS_INTERFACE_MAP_ENTRY(nsIDOMStorageManager) NS_INTERFACE_MAP_ENTRY(nsIDOMStorageManager)
NS_INTERFACE_MAP_ENTRY(nsINetworkInterceptController) NS_INTERFACE_MAP_ENTRY(nsINetworkInterceptController)
@ -14058,7 +14057,7 @@ OnLinkClickEvent::OnLinkClickEvent(nsDocShell* aHandler,
{ {
} }
NS_IMETHODIMP nsresult
nsDocShell::OnLinkClick(nsIContent* aContent, nsDocShell::OnLinkClick(nsIContent* aContent,
nsIURI* aURI, nsIURI* aURI,
const char16_t* aTargetSpec, const char16_t* aTargetSpec,
@ -14110,7 +14109,7 @@ nsDocShell::OnLinkClick(nsIContent* aContent,
return NS_DispatchToCurrentThread(ev); return NS_DispatchToCurrentThread(ev);
} }
NS_IMETHODIMP nsresult
nsDocShell::OnLinkClickSync(nsIContent* aContent, nsDocShell::OnLinkClickSync(nsIContent* aContent,
nsIURI* aURI, nsIURI* aURI,
const char16_t* aTargetSpec, const char16_t* aTargetSpec,
@ -14276,7 +14275,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent,
return rv; return rv;
} }
NS_IMETHODIMP nsresult
nsDocShell::OnOverLink(nsIContent* aContent, nsDocShell::OnOverLink(nsIContent* aContent,
nsIURI* aURI, nsIURI* aURI,
const char16_t* aTargetSpec) const char16_t* aTargetSpec)
@ -14329,7 +14328,7 @@ nsDocShell::OnOverLink(nsIContent* aContent,
return rv; return rv;
} }
NS_IMETHODIMP nsresult
nsDocShell::OnLeaveLink() nsDocShell::OnLeaveLink()
{ {
nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner)); nsCOMPtr<nsIWebBrowserChrome> browserChrome(do_GetInterface(mTreeOwner));

View file

@ -51,7 +51,6 @@
#include "nsIAuthPromptProvider.h" #include "nsIAuthPromptProvider.h"
#include "nsILoadContext.h" #include "nsILoadContext.h"
#include "nsIWebShellServices.h" #include "nsIWebShellServices.h"
#include "nsILinkHandler.h"
#include "nsIClipboardCommands.h" #include "nsIClipboardCommands.h"
#include "nsITabParent.h" #include "nsITabParent.h"
#include "nsCRT.h" #include "nsCRT.h"
@ -143,7 +142,6 @@ class nsDocShell final
, public nsIAuthPromptProvider , public nsIAuthPromptProvider
, public nsILoadContext , public nsILoadContext
, public nsIWebShellServices , public nsIWebShellServices
, public nsILinkHandler
, public nsIClipboardCommands , public nsIClipboardCommands
, public nsIDOMStorageManager , public nsIDOMStorageManager
, public nsINetworkInterceptController , public nsINetworkInterceptController
@ -193,28 +191,70 @@ public:
// nsIWebProgressListener has methods with identical names... // nsIWebProgressListener has methods with identical names...
NS_FORWARD_NSISECURITYEVENTSINK(nsDocLoader::) NS_FORWARD_NSISECURITYEVENTSINK(nsDocLoader::)
// nsILinkHandler /**
NS_IMETHOD OnLinkClick(nsIContent* aContent, * Process a click on a link.
nsIURI* aURI, *
const char16_t* aTargetSpec, * @param aContent the content for the frame that generated the trigger
const nsAString& aFileName, * @param aURI a URI object that defines the destination for the link
nsIInputStream* aPostDataStream, * @param aTargetSpec indicates where the link is targeted (may be an empty
nsIInputStream* aHeadersDataStream, * string)
bool aIsTrusted, * @param aFileName non-null when the link should be downloaded as the given file
nsIPrincipal* aTriggeringPrincipal) override; * @param aPostDataStream the POST data to send
NS_IMETHOD OnLinkClickSync(nsIContent* aContent, * @param aHeadersDataStream ??? (only used for plugins)
nsIURI* aURI, * @param aIsTrusted false if the triggerer is an untrusted DOM event.
const char16_t* aTargetSpec, * @param aTriggeringPrincipal, if not passed explicitly we fall back to
const nsAString& aFileName, * the document's principal.
nsIInputStream* aPostDataStream = 0, */
nsIInputStream* aHeadersDataStream = 0, nsresult OnLinkClick(nsIContent* aContent,
nsIDocShell** aDocShell = 0, nsIURI* aURI,
nsIRequest** aRequest = 0, const char16_t* aTargetSpec,
nsIPrincipal* aTriggeringPrincipal = nullptr) override; const nsAString& aFileName,
NS_IMETHOD OnOverLink(nsIContent* aContent, nsIInputStream* aPostDataStream,
nsIURI* aURI, nsIInputStream* aHeadersDataStream,
const char16_t* aTargetSpec) override; bool aIsTrusted,
NS_IMETHOD OnLeaveLink() override; nsIPrincipal* aTriggeringPrincipal);
/**
* 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 ??? (only used for plugins)
* @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.
*/
nsresult OnLinkClickSync(nsIContent* aContent,
nsIURI* aURI,
const char16_t* aTargetSpec,
const nsAString& aFileName,
nsIInputStream* aPostDataStream = nullptr,
nsIInputStream* aHeadersDataStream = nullptr,
nsIDocShell** aDocShell = nullptr,
nsIRequest** aRequest = nullptr,
nsIPrincipal* aTriggeringPrincipal = 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 char16_t* aTargetSpec);
/**
* Process the mouse leaving a link.
*/
nsresult OnLeaveLink();
nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(uint32_t aLoadType); nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(uint32_t aLoadType);
uint32_t ConvertDocShellLoadInfoToLoadType( uint32_t ConvertDocShellLoadInfoToLoadType(

View file

@ -1,99 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 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 aPostDataStream the POST data to send
* @param aFileName non-null when the link should be downloaded as the given file
* @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.
*/
NS_IMETHOD OnLinkClick(nsIContent* aContent,
nsIURI* aURI,
const char16_t* aTargetSpec,
const nsAString& aFileName,
nsIInputStream* aPostDataStream,
nsIInputStream* aHeadersDataStream,
bool aIsTrusted,
nsIPrincipal* aTriggeringPrincipal) = 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 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.
*/
NS_IMETHOD OnLinkClickSync(nsIContent* aContent,
nsIURI* aURI,
const char16_t* aTargetSpec,
const nsAString& aFileName,
nsIInputStream* aPostDataStream = 0,
nsIInputStream* aHeadersDataStream = 0,
nsIDocShell** aDocShell = 0,
nsIRequest** aRequest = 0,
nsIPrincipal* aTriggeringPrincipal = 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 char16_t* aTargetSpec) = 0;
/**
* Process the mouse leaving a link.
*/
NS_IMETHOD OnLeaveLink() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsILinkHandler, NS_ILINKHANDLER_IID)
#endif /* nsILinkHandler_h___ */

View file

@ -27,7 +27,6 @@
#include "nsIContentIterator.h" #include "nsIContentIterator.h"
#include "nsFocusManager.h" #include "nsFocusManager.h"
#include "nsFrameManager.h" #include "nsFrameManager.h"
#include "nsILinkHandler.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsContainerFrame.h" #include "nsContainerFrame.h"

View file

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

View file

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

View file

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

View file

@ -49,6 +49,7 @@
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
#include "nsIWebProgress.h" #include "nsIWebProgress.h"
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsDocShell.h" // for ::Cast
#include "nsIPrompt.h" #include "nsIPrompt.h"
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
@ -776,9 +777,8 @@ HTMLFormElement::SubmitSubmission(HTMLFormSubmission* aFormSubmission)
// If there is no link handler, then we won't actually be able to submit. // If there is no link handler, then we won't actually be able to submit.
nsIDocument* doc = GetComposedDoc(); nsIDocument* doc = GetComposedDoc();
nsCOMPtr<nsISupports> container = doc ? doc->GetContainer() : nullptr; nsCOMPtr<nsIDocShell> container = doc ? doc->GetDocShell() : nullptr;
nsCOMPtr<nsILinkHandler> linkHandler(do_QueryInterface(container)); if (!container || IsEditable()) {
if (!linkHandler || IsEditable()) {
mIsSubmitting = false; mIsSubmitting = false;
return NS_OK; return NS_OK;
} }
@ -857,12 +857,12 @@ HTMLFormElement::SubmitSubmission(HTMLFormSubmission* aFormSubmission)
getter_AddRefs(postDataStream)); getter_AddRefs(postDataStream));
NS_ENSURE_SUBMIT_SUCCESS(rv); NS_ENSURE_SUBMIT_SUCCESS(rv);
rv = linkHandler->OnLinkClickSync(this, actionURI, rv = nsDocShell::Cast(container)->OnLinkClickSync(this, actionURI,
target.get(), target.get(),
NullString(), NullString(),
postDataStream, nullptr, postDataStream, nullptr,
getter_AddRefs(docShell), getter_AddRefs(docShell),
getter_AddRefs(mSubmittingRequest)); getter_AddRefs(mSubmittingRequest));
NS_ENSURE_SUBMIT_SUCCESS(rv); NS_ENSURE_SUBMIT_SUCCESS(rv);
} }

View file

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

View file

@ -79,6 +79,7 @@ else:
] ]
LOCAL_INCLUDES += [ LOCAL_INCLUDES += [
'/docshell/base',
'/dom/base', '/dom/base',
'/dom/plugins/ipc', '/dom/plugins/ipc',
'/layout/generic', '/layout/generic',

View file

@ -27,7 +27,6 @@ using mozilla::DefaultXDisplay;
#include "nsIStringStream.h" #include "nsIStringStream.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "nsILinkHandler.h"
#include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeItem.h"
#include "nsIWebBrowserChrome.h" #include "nsIWebBrowserChrome.h"
#include "nsLayoutUtils.h" #include "nsLayoutUtils.h"
@ -46,6 +45,7 @@ using mozilla::DefaultXDisplay;
#include "nsIScriptSecurityManager.h" #include "nsIScriptSecurityManager.h"
#include "nsIScrollableFrame.h" #include "nsIScrollableFrame.h"
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsDocShell.h" // for ::Cast
#include "ImageContainer.h" #include "ImageContainer.h"
#include "nsIDOMHTMLCollection.h" #include "nsIDOMHTMLCollection.h"
#include "GLContext.h" #include "GLContext.h"
@ -440,10 +440,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,
} }
// the container of the pres context will give us the link handler // the container of the pres context will give us the link handler
nsCOMPtr<nsISupports> container = presContext->GetContainerWeak(); nsCOMPtr<nsIDocShell> container = presContext->GetDocShell();
NS_ENSURE_TRUE(container,NS_ERROR_FAILURE); NS_ENSURE_TRUE(container,NS_ERROR_FAILURE);
nsCOMPtr<nsILinkHandler> lh = do_QueryInterface(container);
NS_ENSURE_TRUE(lh, NS_ERROR_FAILURE);
nsAutoString unitarget; nsAutoString unitarget;
if ((0 == PL_strcmp(aTarget, "newwindow")) || if ((0 == PL_strcmp(aTarget, "newwindow")) ||
@ -495,8 +493,14 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,
triggeringPrincipal = BasePrincipal::CreateCodebasePrincipal(uri, attrs); triggeringPrincipal = BasePrincipal::CreateCodebasePrincipal(uri, attrs);
} }
rv = lh->OnLinkClick(content, uri, unitarget.get(), NullString(), rv = nsDocShell::Cast(container)->OnLinkClick(content,
aPostStream, headersDataStream, true, triggeringPrincipal); uri,
unitarget.get(),
NullString(),
aPostStream,
headersDataStream,
true,
triggeringPrincipal);
return rv; return rv;
} }

View file

@ -34,7 +34,6 @@
#include "nsIDOMHTMLAnchorElement.h" #include "nsIDOMHTMLAnchorElement.h"
#include "nsISelectionController.h" #include "nsISelectionController.h"
#include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLDocument.h"
#include "nsILinkHandler.h"
#include "nsIInlineSpellChecker.h" #include "nsIInlineSpellChecker.h"
#include "mozilla/css/Loader.h" #include "mozilla/css/Loader.h"

View file

@ -24,7 +24,6 @@
#include "nsIWritablePropertyBag2.h" #include "nsIWritablePropertyBag2.h"
#include "nsSubDocumentFrame.h" #include "nsSubDocumentFrame.h"
#include "nsILinkHandler.h"
#include "nsIDOMDocument.h" #include "nsIDOMDocument.h"
#include "nsISelectionListener.h" #include "nsISelectionListener.h"
#include "mozilla/dom/Selection.h" #include "mozilla/dom/Selection.h"

View file

@ -52,7 +52,6 @@ class nsITheme;
class nsIContent; class nsIContent;
class nsIFrame; class nsIFrame;
class nsFrameManager; class nsFrameManager;
class nsILinkHandler;
class nsIAtom; class nsIAtom;
class nsIRunnable; class nsIRunnable;
class gfxUserFontEntry; class gfxUserFontEntry;

View file

@ -3,13 +3,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsImageBoxFrame.h" #include "nsImageBoxFrame.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
#include "nsRenderingContext.h" #include "nsRenderingContext.h"
@ -26,7 +19,6 @@
#include "nsIPresShell.h" #include "nsIPresShell.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsImageMap.h" #include "nsImageMap.h"
#include "nsILinkHandler.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsILoadGroup.h" #include "nsILoadGroup.h"
#include "nsContainerFrame.h" #include "nsContainerFrame.h"