From 733789f40b40aa820e2c8c6d66eec8c336eda55d Mon Sep 17 00:00:00 2001 From: wuggy Date: Sat, 19 Sep 2026 07:22:05 -0700 Subject: [PATCH] Revert "Issue #2721 - Remove nsILinkHandler." This reverts commit c3f1c0cdba02079541c5c06f90a8a9ee532b34e6. --- docshell/base/moz.build | 1 + docshell/base/nsDocShell.cpp | 9 +- docshell/base/nsDocShell.h | 88 ++++++------------- docshell/base/nsILinkHandler.h | 99 ++++++++++++++++++++++ dom/base/Element.cpp | 1 + dom/base/Element.h | 1 + dom/base/FragmentOrElement.cpp | 1 + dom/base/nsINode.cpp | 1 + dom/html/HTMLFormElement.cpp | 18 ++-- dom/html/HTMLFormSubmission.cpp | 1 + dom/plugins/base/moz.build | 1 - dom/plugins/base/nsPluginInstanceOwner.cpp | 16 ++-- editor/libeditor/HTMLEditor.cpp | 1 + layout/base/nsDocumentViewer.cpp | 1 + layout/base/nsPresContext.h | 1 + layout/xul/nsImageBoxFrame.cpp | 8 ++ 16 files changed, 160 insertions(+), 88 deletions(-) create mode 100644 docshell/base/nsILinkHandler.h diff --git a/docshell/base/moz.build b/docshell/base/moz.build index 62a31ae0a2..697d1a31a7 100644 --- a/docshell/base/moz.build +++ b/docshell/base/moz.build @@ -38,6 +38,7 @@ XPIDL_MODULE = 'docshell' EXPORTS += [ 'nsDocShellLoadTypes.h', + 'nsILinkHandler.h', 'nsIScrollObserver.h', 'nsIWebShellServices.h', 'SerializedLoadContext.h', diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index aad1cb7533..459ed7523a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -956,6 +956,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell) NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider) NS_INTERFACE_MAP_ENTRY(nsILoadContext) NS_INTERFACE_MAP_ENTRY(nsIWebShellServices) + NS_INTERFACE_MAP_ENTRY(nsILinkHandler) NS_INTERFACE_MAP_ENTRY(nsIClipboardCommands) NS_INTERFACE_MAP_ENTRY(nsIDOMStorageManager) NS_INTERFACE_MAP_ENTRY(nsINetworkInterceptController) @@ -14057,7 +14058,7 @@ OnLinkClickEvent::OnLinkClickEvent(nsDocShell* aHandler, { } -nsresult +NS_IMETHODIMP nsDocShell::OnLinkClick(nsIContent* aContent, nsIURI* aURI, const char16_t* aTargetSpec, @@ -14109,7 +14110,7 @@ nsDocShell::OnLinkClick(nsIContent* aContent, return NS_DispatchToCurrentThread(ev); } -nsresult +NS_IMETHODIMP nsDocShell::OnLinkClickSync(nsIContent* aContent, nsIURI* aURI, const char16_t* aTargetSpec, @@ -14275,7 +14276,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, return rv; } -nsresult +NS_IMETHODIMP nsDocShell::OnOverLink(nsIContent* aContent, nsIURI* aURI, const char16_t* aTargetSpec) @@ -14328,7 +14329,7 @@ nsDocShell::OnOverLink(nsIContent* aContent, return rv; } -nsresult +NS_IMETHODIMP nsDocShell::OnLeaveLink() { nsCOMPtr browserChrome(do_GetInterface(mTreeOwner)); diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 60facc81af..2bb71911b9 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -51,6 +51,7 @@ #include "nsIAuthPromptProvider.h" #include "nsILoadContext.h" #include "nsIWebShellServices.h" +#include "nsILinkHandler.h" #include "nsIClipboardCommands.h" #include "nsITabParent.h" #include "nsCRT.h" @@ -142,6 +143,7 @@ class nsDocShell final , public nsIAuthPromptProvider , public nsILoadContext , public nsIWebShellServices + , public nsILinkHandler , public nsIClipboardCommands , public nsIDOMStorageManager , public nsINetworkInterceptController @@ -191,70 +193,28 @@ public: // nsIWebProgressListener has methods with identical names... NS_FORWARD_NSISECURITYEVENTSINK(nsDocLoader::) - /** - * 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 ??? (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. - */ - nsresult OnLinkClick(nsIContent* aContent, - nsIURI* aURI, - const char16_t* aTargetSpec, - const nsAString& aFileName, - nsIInputStream* aPostDataStream, - nsIInputStream* aHeadersDataStream, - bool aIsTrusted, - 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(); + // nsILinkHandler + NS_IMETHOD OnLinkClick(nsIContent* aContent, + nsIURI* aURI, + const char16_t* aTargetSpec, + const nsAString& aFileName, + nsIInputStream* aPostDataStream, + nsIInputStream* aHeadersDataStream, + bool aIsTrusted, + nsIPrincipal* aTriggeringPrincipal) override; + 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) override; + NS_IMETHOD OnOverLink(nsIContent* aContent, + nsIURI* aURI, + const char16_t* aTargetSpec) override; + NS_IMETHOD OnLeaveLink() override; nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(uint32_t aLoadType); uint32_t ConvertDocShellLoadInfoToLoadType( diff --git a/docshell/base/nsILinkHandler.h b/docshell/base/nsILinkHandler.h new file mode 100644 index 0000000000..c7e9db6959 --- /dev/null +++ b/docshell/base/nsILinkHandler.h @@ -0,0 +1,99 @@ +/* -*- 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___ */ diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 18858a159f..e8b4364ad6 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -27,6 +27,7 @@ #include "nsIContentIterator.h" #include "nsFocusManager.h" #include "nsFrameManager.h" +#include "nsILinkHandler.h" #include "nsIScriptGlobalObject.h" #include "nsIURL.h" #include "nsContainerFrame.h" diff --git a/dom/base/Element.h b/dom/base/Element.h index 14c53ae465..45c952cae9 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -17,6 +17,7 @@ #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" diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 073e0bc192..be9fd44974 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -31,6 +31,7 @@ #include "nsIDOMNodeList.h" #include "nsIContentIterator.h" #include "nsFocusManager.h" +#include "nsILinkHandler.h" #include "nsIScriptGlobalObject.h" #include "nsIURL.h" #include "nsNetUtil.h" diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index abfa901d80..0a82eecf7a 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -60,6 +60,7 @@ #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" diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index a5f2442489..3a6c8c293b 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -49,7 +49,6 @@ #include "nsIInterfaceRequestorUtils.h" #include "nsIWebProgress.h" #include "nsIDocShell.h" -#include "nsDocShell.h" // for ::Cast #include "nsIPrompt.h" #include "nsIStringBundle.h" @@ -812,8 +811,9 @@ HTMLFormElement::SubmitSubmission(HTMLFormSubmission* aFormSubmission) // If there is no link handler, then we won't actually be able to submit. nsIDocument* doc = GetComposedDoc(); - nsCOMPtr container = doc ? doc->GetDocShell() : nullptr; - if (!container || IsEditable()) { + nsCOMPtr container = doc ? doc->GetContainer() : nullptr; + nsCOMPtr linkHandler(do_QueryInterface(container)); + if (!linkHandler || IsEditable()) { mIsSubmitting = false; return NS_OK; } @@ -892,12 +892,12 @@ HTMLFormElement::SubmitSubmission(HTMLFormSubmission* aFormSubmission) getter_AddRefs(postDataStream)); NS_ENSURE_SUBMIT_SUCCESS(rv); - rv = nsDocShell::Cast(container)->OnLinkClickSync(this, actionURI, - target.get(), - NullString(), - postDataStream, nullptr, - getter_AddRefs(docShell), - getter_AddRefs(mSubmittingRequest)); + rv = linkHandler->OnLinkClickSync(this, actionURI, + target.get(), + NullString(), + postDataStream, nullptr, + getter_AddRefs(docShell), + getter_AddRefs(mSubmittingRequest)); NS_ENSURE_SUBMIT_SUCCESS(rv); } diff --git a/dom/html/HTMLFormSubmission.cpp b/dom/html/HTMLFormSubmission.cpp index 573e54c674..6a931858b3 100644 --- a/dom/html/HTMLFormSubmission.cpp +++ b/dom/html/HTMLFormSubmission.cpp @@ -7,6 +7,7 @@ #include "nsCOMPtr.h" #include "nsIForm.h" +#include "nsILinkHandler.h" #include "nsIDocument.h" #include "nsGkAtoms.h" #include "nsIFormControl.h" diff --git a/dom/plugins/base/moz.build b/dom/plugins/base/moz.build index b5efcf3b8c..1b6658c283 100644 --- a/dom/plugins/base/moz.build +++ b/dom/plugins/base/moz.build @@ -79,7 +79,6 @@ else: ] LOCAL_INCLUDES += [ - '/docshell/base', '/dom/base', '/dom/plugins/ipc', '/layout/generic', diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index adcfacac37..a424af6e17 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -27,6 +27,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" @@ -45,7 +46,6 @@ using mozilla::DefaultXDisplay; #include "nsIScriptSecurityManager.h" #include "nsIScrollableFrame.h" #include "nsIDocShell.h" -#include "nsDocShell.h" // for ::Cast #include "ImageContainer.h" #include "nsIDOMHTMLCollection.h" #include "GLContext.h" @@ -440,8 +440,10 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, } // the container of the pres context will give us the link handler - nsCOMPtr container = presContext->GetDocShell(); + nsCOMPtr container = presContext->GetContainerWeak(); NS_ENSURE_TRUE(container,NS_ERROR_FAILURE); + nsCOMPtr lh = do_QueryInterface(container); + NS_ENSURE_TRUE(lh, NS_ERROR_FAILURE); nsAutoString unitarget; if ((0 == PL_strcmp(aTarget, "newwindow")) || @@ -493,14 +495,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, triggeringPrincipal = BasePrincipal::CreateCodebasePrincipal(uri, attrs); } - rv = nsDocShell::Cast(container)->OnLinkClick(content, - uri, - unitarget.get(), - NullString(), - aPostStream, - headersDataStream, - true, - triggeringPrincipal); + rv = lh->OnLinkClick(content, uri, unitarget.get(), NullString(), + aPostStream, headersDataStream, true, triggeringPrincipal); return rv; } diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 767856a1bc..895de90206 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -34,6 +34,7 @@ #include "nsIDOMHTMLAnchorElement.h" #include "nsISelectionController.h" #include "nsIDOMHTMLDocument.h" +#include "nsILinkHandler.h" #include "nsIInlineSpellChecker.h" #include "mozilla/css/Loader.h" diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 1bde07d467..e10980aecc 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -24,6 +24,7 @@ #include "nsIWritablePropertyBag2.h" #include "nsSubDocumentFrame.h" +#include "nsILinkHandler.h" #include "nsIDOMDocument.h" #include "nsISelectionListener.h" #include "mozilla/dom/Selection.h" diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 0b2f6a17f0..ba99cdf070 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -52,6 +52,7 @@ class nsITheme; class nsIContent; class nsIFrame; class nsFrameManager; +class nsILinkHandler; class nsIAtom; class nsIRunnable; class gfxUserFontEntry; diff --git a/layout/xul/nsImageBoxFrame.cpp b/layout/xul/nsImageBoxFrame.cpp index 2116d39fb0..aa00c5174d 100644 --- a/layout/xul/nsImageBoxFrame.cpp +++ b/layout/xul/nsImageBoxFrame.cpp @@ -3,6 +3,13 @@ * 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/. */ +// +// Eric Vaughan +// Netscape Communications +// +// See documentation in associated header file +// + #include "nsImageBoxFrame.h" #include "nsGkAtoms.h" #include "nsRenderingContext.h" @@ -19,6 +26,7 @@ #include "nsIPresShell.h" #include "nsIDocument.h" #include "nsImageMap.h" +#include "nsILinkHandler.h" #include "nsIURL.h" #include "nsILoadGroup.h" #include "nsContainerFrame.h"