diff --git a/docshell/base/moz.build b/docshell/base/moz.build index 0e68eaf66fbc..157c76f7a517 100644 --- a/docshell/base/moz.build +++ b/docshell/base/moz.build @@ -41,8 +41,6 @@ XPIDL_SOURCES += [ 'nsIContentViewer.idl', 'nsIContentViewerContainer.idl', 'nsIContentViewerEdit.idl', - 'nsIContextMenuListener.idl', - 'nsIContextMenuListener2.idl', 'nsIDocCharset.idl', 'nsIDocShell.idl', 'nsIDocShellLoadInfo.idl', @@ -89,7 +87,6 @@ EXPORTS.mozilla.dom += [ UNIFIED_SOURCES += [ 'LoadContext.cpp', 'nsAboutRedirector.cpp', - 'nsContextMenuInfo.cpp', 'nsDefaultURIFixup.cpp', 'nsDocShell.cpp', 'nsDocShellEditorData.cpp', diff --git a/docshell/base/nsContextMenuInfo.cpp b/docshell/base/nsContextMenuInfo.cpp deleted file mode 100644 index 9958a814e67d..000000000000 --- a/docshell/base/nsContextMenuInfo.cpp +++ /dev/null @@ -1,320 +0,0 @@ -/* -*- 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/. */ - -#include "nsContextMenuInfo.h" - -#include "nsIImageLoadingContent.h" -#include "imgLoader.h" -#include "nsIDOMDocument.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIDOMHTMLElement.h" -#include "nsIDOMHTMLHtmlElement.h" -#include "nsIDOMWindow.h" -#include "nsICSSDeclaration.h" -#include "nsIDOMCSSValue.h" -#include "nsIDOMCSSPrimitiveValue.h" -#include "nsNetUtil.h" -#include "nsUnicharUtils.h" -#include "nsIDocument.h" -#include "nsIPrincipal.h" -#include "nsIContentSecurityPolicy.h" -#include "nsIContentPolicy.h" -#include "imgRequestProxy.h" -#include "mozilla/dom/HTMLAnchorElement.h" -#include "mozilla/dom/HTMLAreaElement.h" -#include "mozilla/dom/HTMLLinkElement.h" - -using mozilla::dom::HTMLAnchorElement; -using mozilla::dom::HTMLAreaElement; -using mozilla::dom::HTMLLinkElement; -using mozilla::dom::Element; -using mozilla::ErrorResult; - -NS_IMPL_ISUPPORTS(nsContextMenuInfo, nsIContextMenuInfo) - -nsContextMenuInfo::nsContextMenuInfo() -{ -} - -nsContextMenuInfo::~nsContextMenuInfo() -{ -} - -NS_IMETHODIMP -nsContextMenuInfo::GetMouseEvent(nsIDOMEvent** aEvent) -{ - NS_ENSURE_ARG_POINTER(aEvent); - NS_IF_ADDREF(*aEvent = mMouseEvent); - return NS_OK; -} - -NS_IMETHODIMP -nsContextMenuInfo::GetTargetNode(nsIDOMNode** aNode) -{ - NS_ENSURE_ARG_POINTER(aNode); - NS_IF_ADDREF(*aNode = mDOMNode); - return NS_OK; -} - -NS_IMETHODIMP -nsContextMenuInfo::GetAssociatedLink(nsAString& aHRef) -{ - NS_ENSURE_STATE(mAssociatedLink); - aHRef.Truncate(0); - - nsCOMPtr content(do_QueryInterface(mAssociatedLink)); - nsCOMPtr linkContent; - if (content && - content->IsAnyOfHTMLElements(nsGkAtoms::a, - nsGkAtoms::area, - nsGkAtoms::link)) { - bool hasAttr = content->HasAttr(kNameSpaceID_None, nsGkAtoms::href); - if (hasAttr) { - linkContent = content; - RefPtr anchor = HTMLAnchorElement::FromContent(linkContent); - if (anchor) { - anchor->GetHref(aHRef); - } else { - RefPtr area = HTMLAreaElement::FromContent(linkContent); - if (area) { - area->GetHref(aHRef); - } else { - RefPtr link = HTMLLinkElement::FromContent(linkContent); - if (link) { - link->GetHref(aHRef); - } - } - } - } - } else { - nsCOMPtr curr; - mAssociatedLink->GetParentNode(getter_AddRefs(curr)); - while (curr) { - content = do_QueryInterface(curr); - if (!content) { - break; - } - if (content->IsHTMLElement(nsGkAtoms::a)) { - bool hasAttr; - hasAttr = content->HasAttr(kNameSpaceID_None, nsGkAtoms::href); - if (hasAttr) { - linkContent = content; - RefPtr anchor = HTMLAnchorElement::FromContent(linkContent); - if (anchor) { - anchor->GetHref(aHRef); - } - } else { - linkContent = nullptr; // Links can't be nested. - } - break; - } - - nsCOMPtr temp = curr; - temp->GetParentNode(getter_AddRefs(curr)); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsContextMenuInfo::GetImageContainer(imgIContainer** aImageContainer) -{ - NS_ENSURE_ARG_POINTER(aImageContainer); - NS_ENSURE_STATE(mDOMNode); - - nsCOMPtr request; - GetImageRequest(mDOMNode, getter_AddRefs(request)); - if (request) { - return request->GetImage(aImageContainer); - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsContextMenuInfo::GetImageSrc(nsIURI** aURI) -{ - NS_ENSURE_ARG_POINTER(aURI); - NS_ENSURE_STATE(mDOMNode); - - nsCOMPtr content(do_QueryInterface(mDOMNode)); - NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - return content->GetCurrentURI(aURI); -} - -NS_IMETHODIMP -nsContextMenuInfo::GetBackgroundImageContainer(imgIContainer** aImageContainer) -{ - NS_ENSURE_ARG_POINTER(aImageContainer); - NS_ENSURE_STATE(mDOMNode); - - RefPtr request; - GetBackgroundImageRequest(mDOMNode, getter_AddRefs(request)); - if (request) { - return request->GetImage(aImageContainer); - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsContextMenuInfo::GetBackgroundImageSrc(nsIURI** aURI) -{ - NS_ENSURE_ARG_POINTER(aURI); - NS_ENSURE_STATE(mDOMNode); - - RefPtr request; - GetBackgroundImageRequest(mDOMNode, getter_AddRefs(request)); - if (request) { - return request->GetURI(aURI); - } - - return NS_ERROR_FAILURE; -} - -nsresult -nsContextMenuInfo::GetImageRequest(nsIDOMNode* aDOMNode, imgIRequest** aRequest) -{ - NS_ENSURE_ARG(aDOMNode); - NS_ENSURE_ARG_POINTER(aRequest); - - // Get content - nsCOMPtr content(do_QueryInterface(aDOMNode)); - NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - - return content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, aRequest); -} - -bool -nsContextMenuInfo::HasBackgroundImage(nsIDOMNode* aDOMNode) -{ - NS_ENSURE_TRUE(aDOMNode, false); - - RefPtr request; - GetBackgroundImageRequest(aDOMNode, getter_AddRefs(request)); - - return (request != nullptr); -} - -nsresult -nsContextMenuInfo::GetBackgroundImageRequest(nsIDOMNode* aDOMNode, - imgRequestProxy** aRequest) -{ - - NS_ENSURE_ARG(aDOMNode); - NS_ENSURE_ARG_POINTER(aRequest); - - nsCOMPtr domNode = aDOMNode; - - // special case for the element: if it has no background-image - // we'll defer to - nsCOMPtr htmlElement = do_QueryInterface(domNode); - if (htmlElement) { - nsCOMPtr element = do_QueryInterface(domNode); - nsAutoString nameSpace; - element->GetNamespaceURI(nameSpace); - if (nameSpace.IsEmpty()) { - nsresult rv = GetBackgroundImageRequestInternal(domNode, aRequest); - if (NS_SUCCEEDED(rv) && *aRequest) { - return NS_OK; - } - - // no background-image found - nsCOMPtr document; - domNode->GetOwnerDocument(getter_AddRefs(document)); - nsCOMPtr htmlDocument(do_QueryInterface(document)); - NS_ENSURE_TRUE(htmlDocument, NS_ERROR_FAILURE); - - nsCOMPtr body; - htmlDocument->GetBody(getter_AddRefs(body)); - domNode = do_QueryInterface(body); - NS_ENSURE_TRUE(domNode, NS_ERROR_FAILURE); - } - } - return GetBackgroundImageRequestInternal(domNode, aRequest); -} - -nsresult -nsContextMenuInfo::GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode, - imgRequestProxy** aRequest) -{ - NS_ENSURE_ARG_POINTER(aDOMNode); - - nsCOMPtr domNode = aDOMNode; - nsCOMPtr parentNode; - - nsCOMPtr document; - domNode->GetOwnerDocument(getter_AddRefs(document)); - NS_ENSURE_TRUE(document, NS_ERROR_FAILURE); - - nsCOMPtr window; - document->GetDefaultView(getter_AddRefs(window)); - NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - - auto* piWindow = nsPIDOMWindowOuter::From(window); - nsPIDOMWindowInner* innerWindow = piWindow->GetCurrentInnerWindow(); - MOZ_ASSERT(innerWindow); - - nsCOMPtr primitiveValue; - nsAutoString bgStringValue; - - nsCOMPtr doc(do_QueryInterface(document)); - nsCOMPtr principal = doc ? doc->NodePrincipal() : nullptr; - - while (true) { - nsCOMPtr domElement(do_QueryInterface(domNode)); - // bail for the parent node of the root element or null argument - if (!domElement) { - break; - } - - ErrorResult dummy; - nsCOMPtr computedStyle = - innerWindow->GetComputedStyle(*domElement, EmptyString(), dummy); - dummy.SuppressException(); - if (computedStyle) { - nsCOMPtr cssValue; - computedStyle->GetPropertyCSSValue(NS_LITERAL_STRING("background-image"), - getter_AddRefs(cssValue)); - primitiveValue = do_QueryInterface(cssValue); - if (primitiveValue) { - primitiveValue->GetStringValue(bgStringValue); - if (!bgStringValue.EqualsLiteral("none")) { - nsCOMPtr bgUri; - NS_NewURI(getter_AddRefs(bgUri), bgStringValue); - NS_ENSURE_TRUE(bgUri, NS_ERROR_FAILURE); - - imgLoader* il = imgLoader::NormalLoader(); - NS_ENSURE_TRUE(il, NS_ERROR_FAILURE); - - return il->LoadImage(bgUri, nullptr, nullptr, - doc->GetReferrerPolicy(), principal, 0, nullptr, - nullptr, nullptr, nullptr, nsIRequest::LOAD_NORMAL, - nullptr, nsIContentPolicy::TYPE_INTERNAL_IMAGE, - EmptyString(), - /* aUseUrgentStartForChannel */ false, aRequest); - } - } - - // bail if we encounter non-transparent background-color - computedStyle->GetPropertyCSSValue(NS_LITERAL_STRING("background-color"), - getter_AddRefs(cssValue)); - primitiveValue = do_QueryInterface(cssValue); - if (primitiveValue) { - primitiveValue->GetStringValue(bgStringValue); - if (!bgStringValue.EqualsLiteral("transparent")) { - return NS_ERROR_FAILURE; - } - } - } - - domNode->GetParentNode(getter_AddRefs(parentNode)); - domNode = parentNode; - } - - return NS_ERROR_FAILURE; -} diff --git a/docshell/base/nsContextMenuInfo.h b/docshell/base/nsContextMenuInfo.h deleted file mode 100644 index 998045f97332..000000000000 --- a/docshell/base/nsContextMenuInfo.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- 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 nsContextMenuInfo_h__ -#define nsContextMenuInfo_h__ - -#include "nsCOMPtr.h" -#include "nsIContextMenuListener2.h" -#include "nsIDOMNode.h" -#include "nsIDOMEvent.h" -#include "imgIContainer.h" -#include "imgIRequest.h" - -class ChromeContextMenuListener; -class imgRequestProxy; - -// Helper class for implementors of nsIContextMenuListener2 -class nsContextMenuInfo : public nsIContextMenuInfo -{ - friend class ChromeContextMenuListener; - -public: - nsContextMenuInfo(); - - NS_DECL_ISUPPORTS - NS_DECL_NSICONTEXTMENUINFO - -private: - virtual ~nsContextMenuInfo(); - - void SetMouseEvent(nsIDOMEvent* aEvent) { mMouseEvent = aEvent; } - void SetDOMNode(nsIDOMNode* aNode) { mDOMNode = aNode; } - void SetAssociatedLink(nsIDOMNode* aLink) { mAssociatedLink = aLink; } - - nsresult GetImageRequest(nsIDOMNode* aDOMNode, imgIRequest** aRequest); - - bool HasBackgroundImage(nsIDOMNode* aDOMNode); - - nsresult GetBackgroundImageRequest(nsIDOMNode* aDOMNode, - imgRequestProxy** aRequest); - - nsresult GetBackgroundImageRequestInternal(nsIDOMNode* aDOMNode, - imgRequestProxy** aRequest); - -private: - nsCOMPtr mMouseEvent; - nsCOMPtr mDOMNode; - nsCOMPtr mAssociatedLink; -}; - -#endif // nsContextMenuInfo_h__ diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 64481b182be2..0e24e7462804 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -15,6 +15,7 @@ #include "mozilla/Casting.h" #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/Element.h" +#include "mozilla/dom/HTMLAnchorElement.h" #include "mozilla/dom/PendingGlobalHistoryEntry.h" #include "mozilla/dom/TabChild.h" #include "mozilla/dom/ProfileTimelineMarkerBinding.h" diff --git a/docshell/base/nsDocShellTreeOwner.cpp b/docshell/base/nsDocShellTreeOwner.cpp index 1d1f2d4ec223..041210c16f71 100644 --- a/docshell/base/nsDocShellTreeOwner.cpp +++ b/docshell/base/nsDocShellTreeOwner.cpp @@ -24,8 +24,6 @@ // Interfaces needed to be included #include "nsPresContext.h" -#include "nsIContextMenuListener.h" -#include "nsIContextMenuListener2.h" #include "nsITooltipListener.h" #include "nsIDOMNode.h" #include "nsIDOMNodeList.h" @@ -59,7 +57,6 @@ #include "nsIWebBrowserChromeFocus.h" #include "nsIContent.h" #include "imgIContainer.h" -#include "nsContextMenuInfo.h" #include "nsPresContext.h" #include "nsViewManager.h" #include "nsView.h" @@ -898,19 +895,6 @@ nsDocShellTreeOwner::AddChromeListeners() } } - // install context menus - if (!mChromeContextMenuListener) { - nsCOMPtr contextListener2( - do_QueryInterface(webBrowserChrome)); - nsCOMPtr contextListener( - do_QueryInterface(webBrowserChrome)); - if (contextListener2 || contextListener) { - mChromeContextMenuListener = - new ChromeContextMenuListener(mWebBrowser, webBrowserChrome); - rv = mChromeContextMenuListener->AddChromeListeners(); - } - } - // register dragover and drop event listeners with the listener manager nsCOMPtr target; GetDOMEventTarget(mWebBrowser, getter_AddRefs(target)); @@ -933,10 +917,6 @@ nsDocShellTreeOwner::RemoveChromeListeners() mChromeTooltipListener->RemoveChromeListeners(); mChromeTooltipListener = nullptr; } - if (mChromeContextMenuListener) { - mChromeContextMenuListener->RemoveChromeListeners(); - mChromeContextMenuListener = nullptr; - } nsCOMPtr piTarget; GetDOMEventTarget(mWebBrowser, getter_AddRefs(piTarget)); @@ -1406,276 +1386,3 @@ ChromeTooltipListener::sTooltipCallback(nsITimer* aTimer, self->mPossibleTooltipNode = nullptr; } } - -NS_IMPL_ISUPPORTS(ChromeContextMenuListener, nsIDOMEventListener) - -ChromeContextMenuListener::ChromeContextMenuListener( - nsWebBrowser* aInBrowser, - nsIWebBrowserChrome* aInChrome) - : mContextMenuListenerInstalled(false) - , mWebBrowser(aInBrowser) - , mWebBrowserChrome(aInChrome) -{ -} - -ChromeContextMenuListener::~ChromeContextMenuListener() -{ -} - -// Subscribe to the events that will allow us to track context menus. Bascially, -// this is just the context-menu DOM event. -NS_IMETHODIMP -ChromeContextMenuListener::AddContextMenuListener() -{ - if (mEventTarget) { - nsresult rv = mEventTarget->AddEventListener( - NS_LITERAL_STRING("contextmenu"), this, false, false); - NS_ENSURE_SUCCESS(rv, rv); - - mContextMenuListenerInstalled = true; - } - - return NS_OK; -} - -// Unsubscribe from all the various context menu events that we were listening -// to. -NS_IMETHODIMP -ChromeContextMenuListener::RemoveContextMenuListener() -{ - if (mEventTarget) { - nsresult rv = mEventTarget->RemoveEventListener( - NS_LITERAL_STRING("contextmenu"), this, false); - NS_ENSURE_SUCCESS(rv, rv); - - mContextMenuListenerInstalled = false; - } - - return NS_OK; -} - -// Hook up things to the chrome like context menus and tooltips, if the chrome -// has implemented the right interfaces. -NS_IMETHODIMP -ChromeContextMenuListener::AddChromeListeners() -{ - if (!mEventTarget) { - GetDOMEventTarget(mWebBrowser, getter_AddRefs(mEventTarget)); - } - - // Register the appropriate events for context menus, but only if - // the embedding chrome cares. - nsresult rv = NS_OK; - - nsCOMPtr contextListener2( - do_QueryInterface(mWebBrowserChrome)); - nsCOMPtr contextListener( - do_QueryInterface(mWebBrowserChrome)); - if ((contextListener || contextListener2) && !mContextMenuListenerInstalled) { - rv = AddContextMenuListener(); - } - - return rv; -} - -// Unsubscribe from the various things we've hooked up to the window root. -NS_IMETHODIMP -ChromeContextMenuListener::RemoveChromeListeners() -{ - if (mContextMenuListenerInstalled) { - RemoveContextMenuListener(); - } - - mEventTarget = nullptr; - - // it really doesn't matter if these fail... - return NS_OK; -} - -// We're on call to show the context menu. Dig around in the DOM to find the -// type of object we're dealing with and notify the front end chrome. -NS_IMETHODIMP -ChromeContextMenuListener::HandleEvent(nsIDOMEvent* aMouseEvent) -{ - nsCOMPtr mouseEvent = do_QueryInterface(aMouseEvent); - NS_ENSURE_TRUE(mouseEvent, NS_ERROR_UNEXPECTED); - - bool isDefaultPrevented = false; - aMouseEvent->GetDefaultPrevented(&isDefaultPrevented); - if (isDefaultPrevented) { - return NS_OK; - } - - nsCOMPtr targetNode = - aMouseEvent->InternalDOMEvent()->GetTarget(); - if (!targetNode) { - return NS_ERROR_NULL_POINTER; - } - - nsCOMPtr targetDOMnode; - nsCOMPtr node = do_QueryInterface(targetNode); - if (!node) { - return NS_OK; - } - - // Stop the context menu event going to other windows (bug 78396) - aMouseEvent->PreventDefault(); - - // If the listener is a nsIContextMenuListener2, create the info object - nsCOMPtr menuListener2( - do_QueryInterface(mWebBrowserChrome)); - nsContextMenuInfo* menuInfoImpl = nullptr; - nsCOMPtr menuInfo; - if (menuListener2) { - menuInfoImpl = new nsContextMenuInfo; - menuInfo = menuInfoImpl; - } - - uint32_t flags = nsIContextMenuListener::CONTEXT_NONE; - uint32_t flags2 = nsIContextMenuListener2::CONTEXT_NONE; - - // XXX test for selected text - - uint16_t nodeType; - nsresult res = node->GetNodeType(&nodeType); - NS_ENSURE_SUCCESS(res, res); - - // First, checks for nodes that never have children. - if (nodeType == nsIDOMNode::ELEMENT_NODE) { - nsCOMPtr imageContent(do_QueryInterface(node)); - if (imageContent) { - nsCOMPtr imgUri; - imageContent->GetCurrentURI(getter_AddRefs(imgUri)); - if (imgUri) { - flags |= nsIContextMenuListener::CONTEXT_IMAGE; - flags2 |= nsIContextMenuListener2::CONTEXT_IMAGE; - targetDOMnode = node; - } - } - - nsCOMPtr formControl(do_QueryInterface(node)); - if (formControl) { - if (formControl->ControlType() == NS_FORM_TEXTAREA) { - flags |= nsIContextMenuListener::CONTEXT_TEXT; - flags2 |= nsIContextMenuListener2::CONTEXT_TEXT; - targetDOMnode = node; - } else { - nsCOMPtr inputElement( - do_QueryInterface(formControl)); - if (inputElement) { - flags |= nsIContextMenuListener::CONTEXT_INPUT; - flags2 |= nsIContextMenuListener2::CONTEXT_INPUT; - - if (menuListener2) { - if (formControl->IsSingleLineTextControl(false)) { - flags2 |= nsIContextMenuListener2::CONTEXT_TEXT; - } - } - - targetDOMnode = node; - } - } - } - - // always consume events for plugins who may throw their own context menus - // but not for image objects. Document objects will never be targets or - // ancestors of targets, so that's OK. - nsCOMPtr content = do_QueryInterface(node); - if (content && - (content->IsHTMLElement(nsGkAtoms::embed) || - (!(flags & nsIContextMenuListener::CONTEXT_IMAGE) && - content->IsHTMLElement(nsGkAtoms::object)))) { - return NS_OK; - } - } - - // Bubble out, looking for items of interest - do { - uint16_t nodeType; - res = node->GetNodeType(&nodeType); - NS_ENSURE_SUCCESS(res, res); - - if (nodeType == nsIDOMNode::ELEMENT_NODE) { - - // Test if the element has an associated link - nsCOMPtr element(do_QueryInterface(node)); - - bool hasAttr = false; - res = element->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - - if (NS_SUCCEEDED(res) && hasAttr) { - flags |= nsIContextMenuListener::CONTEXT_LINK; - flags2 |= nsIContextMenuListener2::CONTEXT_LINK; - if (!targetDOMnode) { - targetDOMnode = node; - } - if (menuInfoImpl) { - menuInfoImpl->SetAssociatedLink(node); - } - break; // exit do-while - } - } - - // walk-up-the-tree - nsCOMPtr parentNode; - node->GetParentNode(getter_AddRefs(parentNode)); - node = parentNode; - } while (node); - - if (!flags && !flags2) { - // We found nothing of interest so far, check if we - // have at least an html document. - nsCOMPtr document; - node = do_QueryInterface(targetNode); - node->GetOwnerDocument(getter_AddRefs(document)); - nsCOMPtr htmlDocument(do_QueryInterface(document)); - if (htmlDocument) { - flags |= nsIContextMenuListener::CONTEXT_DOCUMENT; - flags2 |= nsIContextMenuListener2::CONTEXT_DOCUMENT; - targetDOMnode = node; - if (!(flags & nsIContextMenuListener::CONTEXT_IMAGE)) { - // check if this is a background image that the user was trying to click - // on and if the listener is ready for that (only - // nsIContextMenuListener2 and up) - if (menuInfoImpl && menuInfoImpl->HasBackgroundImage(targetDOMnode)) { - flags2 |= nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE; - // For the embedder to get the correct background image - // targetDOMnode must point to the original node. - targetDOMnode = do_QueryInterface(targetNode); - } - } - } - } - - // we need to cache the event target into the focus controller's popupNode - // so we can get at it later from command code, etc.: - - // get the dom window - nsCOMPtr win; - res = mWebBrowser->GetContentDOMWindow(getter_AddRefs(win)); - NS_ENSURE_SUCCESS(res, res); - NS_ENSURE_TRUE(win, NS_ERROR_FAILURE); - - auto* window = nsPIDOMWindowOuter::From(win); - nsCOMPtr root = window->GetTopWindowRoot(); - NS_ENSURE_TRUE(root, NS_ERROR_FAILURE); - if (root) { - // set the window root's popup node to the event target - root->SetPopupNode(targetDOMnode); - } - - // Tell the listener all about the event - if (menuListener2) { - menuInfoImpl->SetMouseEvent(aMouseEvent); - menuInfoImpl->SetDOMNode(targetDOMnode); - menuListener2->OnShowContextMenu(flags2, menuInfo); - } else { - nsCOMPtr menuListener( - do_QueryInterface(mWebBrowserChrome)); - if (menuListener) { - menuListener->OnShowContextMenu(flags, aMouseEvent, targetDOMnode); - } - } - - return NS_OK; -} diff --git a/docshell/base/nsDocShellTreeOwner.h b/docshell/base/nsDocShellTreeOwner.h index d3df51719857..4e9f0c47482a 100644 --- a/docshell/base/nsDocShellTreeOwner.h +++ b/docshell/base/nsDocShellTreeOwner.h @@ -37,7 +37,6 @@ class EventTarget; class nsWebBrowser; class ChromeTooltipListener; -class ChromeContextMenuListener; // {6D10C180-6888-11d4-952B-0020183BF181} #define NS_ICDOCSHELLTREEOWNER_IID \ @@ -120,7 +119,6 @@ protected: // They are separate objects to avoid circular references between |this| // and the DOM. RefPtr mChromeTooltipListener; - RefPtr mChromeContextMenuListener; RefPtr mContentTreeOwner; @@ -203,37 +201,4 @@ private: nsCOMPtr mPossibleTooltipNode; }; -// The class that listens to the chrome events and tells the embedding chrome to -// show context menus, as appropriate. Handles registering itself with the DOM -// with AddChromeListeners() and removing itself with RemoveChromeListeners(). -class ChromeContextMenuListener : public nsIDOMEventListener -{ -protected: - virtual ~ChromeContextMenuListener(); - -public: - NS_DECL_ISUPPORTS - - ChromeContextMenuListener(nsWebBrowser* aInBrowser, - nsIWebBrowserChrome* aInChrome); - - // nsIDOMContextMenuListener - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override; - - // Add/remove the relevant listeners, based on what interfaces - // the embedding chrome implements. - NS_IMETHOD AddChromeListeners(); - NS_IMETHOD RemoveChromeListeners(); - -private: - NS_IMETHOD AddContextMenuListener(); - NS_IMETHOD RemoveContextMenuListener(); - - bool mContextMenuListenerInstalled; - - nsWebBrowser* mWebBrowser; - nsCOMPtr mEventTarget; - nsCOMPtr mWebBrowserChrome; -}; - #endif /* nsDocShellTreeOwner_h__ */ diff --git a/docshell/base/nsIContextMenuListener.idl b/docshell/base/nsIContextMenuListener.idl deleted file mode 100644 index 2e4d1c1e92d0..000000000000 --- a/docshell/base/nsIContextMenuListener.idl +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: IDL; tab-width: 4; 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/. */ - -#include "nsISupports.idl" - -interface nsIDOMEvent; -interface nsIDOMNode; - -/** - * An optional interface for embedding clients wishing to receive - * notifications for context menu events (e.g. generated by - * a user right-mouse clicking on a link). The embedder implements - * this interface on the web browser chrome object associated - * with the window that notifications are required for. When a context - * menu event, the browser will call this interface if present. - * - * @see nsIDOMNode - * @see nsIDOMEvent - */ -[scriptable, uuid(3478b6b0-3875-11d4-94ef-0020183bf181)] -interface nsIContextMenuListener : nsISupports -{ - /** Flag. No context. */ - const unsigned long CONTEXT_NONE = 0; - /** Flag. Context is a link element. */ - const unsigned long CONTEXT_LINK = 1; - /** Flag. Context is an image element. */ - const unsigned long CONTEXT_IMAGE = 2; - /** Flag. Context is the whole document. */ - const unsigned long CONTEXT_DOCUMENT = 4; - /** Flag. Context is a text area element. */ - const unsigned long CONTEXT_TEXT = 8; - /** Flag. Context is an input element. */ - const unsigned long CONTEXT_INPUT = 16; - - /** - * Called when the browser receives a context menu event (e.g. user is right-mouse - * clicking somewhere on the document). The combination of flags, event and node - * provided in the call indicate where and what was clicked on. - * - * The following table describes what context flags and node combinations are - * possible. - * - * - * - * - * - * - * - * - * - *
aContextFlagaNode
CONTEXT_LINK<A>
CONTEXT_IMAGE<IMG>
CONTEXT_IMAGE | CONTEXT_LINK<IMG> - * with an <A> as an ancestor
CONTEXT_INPUT<INPUT>
CONTEXT_TEXT<TEXTAREA>
CONTEXT_DOCUMENT<HTML>
- * - * @param aContextFlags Flags indicating the kind of context. - * @param aEvent The DOM context menu event. - * @param aNode The DOM node most relevant to the context. - * - * @return NS_OK always. - */ - void onShowContextMenu(in unsigned long aContextFlags, in nsIDOMEvent aEvent, in nsIDOMNode aNode); -}; - diff --git a/docshell/base/nsIContextMenuListener2.idl b/docshell/base/nsIContextMenuListener2.idl deleted file mode 100644 index 19d898011276..000000000000 --- a/docshell/base/nsIContextMenuListener2.idl +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; 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/. */ - -#include "nsISupports.idl" - -interface nsIDOMEvent; -interface nsIDOMNode; -interface imgIContainer; -interface nsIURI; -interface nsIContextMenuInfo; - -/* THIS IS A PUBLIC EMBEDDING API */ - -/** - * nsIContextMenuListener2 - * - * This is an extended version of nsIContextMenuListener - * It provides a helper class, nsIContextMenuInfo, to allow access to - * background images as well as various utilities. - * - * @see nsIContextMenuListener - * @see nsIContextMenuInfo - */ - -[scriptable, uuid(7fb719b3-d804-4964-9596-77cf924ee314)] -interface nsIContextMenuListener2 : nsISupports -{ - /** Flag. No context. */ - const unsigned long CONTEXT_NONE = 0; - /** Flag. Context is a link element. */ - const unsigned long CONTEXT_LINK = 1; - /** Flag. Context is an image element. */ - const unsigned long CONTEXT_IMAGE = 2; - /** Flag. Context is the whole document. */ - const unsigned long CONTEXT_DOCUMENT = 4; - /** Flag. Context is a text area element. */ - const unsigned long CONTEXT_TEXT = 8; - /** Flag. Context is an input element. */ - const unsigned long CONTEXT_INPUT = 16; - /** Flag. Context is a background image. */ - const unsigned long CONTEXT_BACKGROUND_IMAGE = 32; - - /** - * Called when the browser receives a context menu event (e.g. user is right-mouse - * clicking somewhere on the document). The combination of flags, along with the - * attributes of aUtils, indicate where and what was clicked on. - * - * The following table describes what context flags and node combinations are - * possible. - * - * aContextFlags aUtils.targetNode - * - * CONTEXT_LINK - * CONTEXT_IMAGE - * CONTEXT_IMAGE | CONTEXT_LINK with as an ancestor - * CONTEXT_INPUT - * CONTEXT_INPUT | CONTEXT_IMAGE with type=image - * CONTEXT_TEXT