Bug 1413248 - Remove nsIContextMenuListener, nsIContextMenuListener2 and nsContextMenuInfo as they are unused. r=qdot

--HG--
extra : rebase_source : e219d10f4516a79c2503362c07e02429da490209
This commit is contained in:
Marco Castelluccio 2017-10-31 17:23:15 +00:00
parent c1537027d2
commit 7cdad0f284
8 changed files with 1 additions and 891 deletions

View File

@ -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',

View File

@ -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<nsIContent> content(do_QueryInterface(mAssociatedLink));
nsCOMPtr<nsIContent> linkContent;
if (content &&
content->IsAnyOfHTMLElements(nsGkAtoms::a,
nsGkAtoms::area,
nsGkAtoms::link)) {
bool hasAttr = content->HasAttr(kNameSpaceID_None, nsGkAtoms::href);
if (hasAttr) {
linkContent = content;
RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContent(linkContent);
if (anchor) {
anchor->GetHref(aHRef);
} else {
RefPtr<HTMLAreaElement> area = HTMLAreaElement::FromContent(linkContent);
if (area) {
area->GetHref(aHRef);
} else {
RefPtr<HTMLLinkElement> link = HTMLLinkElement::FromContent(linkContent);
if (link) {
link->GetHref(aHRef);
}
}
}
}
} else {
nsCOMPtr<nsIDOMNode> 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<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContent(linkContent);
if (anchor) {
anchor->GetHref(aHRef);
}
} else {
linkContent = nullptr; // Links can't be nested.
}
break;
}
nsCOMPtr<nsIDOMNode> 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<imgIRequest> 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<nsIImageLoadingContent> 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<imgRequestProxy> 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<imgRequestProxy> 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<nsIImageLoadingContent> 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<imgRequestProxy> 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<nsIDOMNode> domNode = aDOMNode;
// special case for the <html> element: if it has no background-image
// we'll defer to <body>
nsCOMPtr<nsIDOMHTMLHtmlElement> htmlElement = do_QueryInterface(domNode);
if (htmlElement) {
nsCOMPtr<nsIDOMHTMLElement> 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<nsIDOMDocument> document;
domNode->GetOwnerDocument(getter_AddRefs(document));
nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(document));
NS_ENSURE_TRUE(htmlDocument, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMHTMLElement> 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<nsIDOMNode> domNode = aDOMNode;
nsCOMPtr<nsIDOMNode> parentNode;
nsCOMPtr<nsIDOMDocument> document;
domNode->GetOwnerDocument(getter_AddRefs(document));
NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);
nsCOMPtr<mozIDOMWindowProxy> 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<nsIDOMCSSPrimitiveValue> primitiveValue;
nsAutoString bgStringValue;
nsCOMPtr<nsIDocument> doc(do_QueryInterface(document));
nsCOMPtr<nsIPrincipal> principal = doc ? doc->NodePrincipal() : nullptr;
while (true) {
nsCOMPtr<Element> domElement(do_QueryInterface(domNode));
// bail for the parent node of the root element or null argument
if (!domElement) {
break;
}
ErrorResult dummy;
nsCOMPtr<nsICSSDeclaration> computedStyle =
innerWindow->GetComputedStyle(*domElement, EmptyString(), dummy);
dummy.SuppressException();
if (computedStyle) {
nsCOMPtr<nsIDOMCSSValue> 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<nsIURI> 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;
}

View File

@ -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<nsIDOMEvent> mMouseEvent;
nsCOMPtr<nsIDOMNode> mDOMNode;
nsCOMPtr<nsIDOMNode> mAssociatedLink;
};
#endif // nsContextMenuInfo_h__

View File

@ -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"

View File

@ -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<nsIContextMenuListener2> contextListener2(
do_QueryInterface(webBrowserChrome));
nsCOMPtr<nsIContextMenuListener> 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<EventTarget> target;
GetDOMEventTarget(mWebBrowser, getter_AddRefs(target));
@ -933,10 +917,6 @@ nsDocShellTreeOwner::RemoveChromeListeners()
mChromeTooltipListener->RemoveChromeListeners();
mChromeTooltipListener = nullptr;
}
if (mChromeContextMenuListener) {
mChromeContextMenuListener->RemoveChromeListeners();
mChromeContextMenuListener = nullptr;
}
nsCOMPtr<EventTarget> 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<nsIContextMenuListener2> contextListener2(
do_QueryInterface(mWebBrowserChrome));
nsCOMPtr<nsIContextMenuListener> 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<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
NS_ENSURE_TRUE(mouseEvent, NS_ERROR_UNEXPECTED);
bool isDefaultPrevented = false;
aMouseEvent->GetDefaultPrevented(&isDefaultPrevented);
if (isDefaultPrevented) {
return NS_OK;
}
nsCOMPtr<EventTarget> targetNode =
aMouseEvent->InternalDOMEvent()->GetTarget();
if (!targetNode) {
return NS_ERROR_NULL_POINTER;
}
nsCOMPtr<nsIDOMNode> targetDOMnode;
nsCOMPtr<nsIDOMNode> 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<nsIContextMenuListener2> menuListener2(
do_QueryInterface(mWebBrowserChrome));
nsContextMenuInfo* menuInfoImpl = nullptr;
nsCOMPtr<nsIContextMenuInfo> 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<nsIImageLoadingContent> imageContent(do_QueryInterface(node));
if (imageContent) {
nsCOMPtr<nsIURI> imgUri;
imageContent->GetCurrentURI(getter_AddRefs(imgUri));
if (imgUri) {
flags |= nsIContextMenuListener::CONTEXT_IMAGE;
flags2 |= nsIContextMenuListener2::CONTEXT_IMAGE;
targetDOMnode = node;
}
}
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(node));
if (formControl) {
if (formControl->ControlType() == NS_FORM_TEXTAREA) {
flags |= nsIContextMenuListener::CONTEXT_TEXT;
flags2 |= nsIContextMenuListener2::CONTEXT_TEXT;
targetDOMnode = node;
} else {
nsCOMPtr<nsIDOMHTMLInputElement> 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<nsIContent> 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<nsIDOMElement> 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<nsIDOMNode> 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<nsIDOMDocument> document;
node = do_QueryInterface(targetNode);
node->GetOwnerDocument(getter_AddRefs(document));
nsCOMPtr<nsIDOMHTMLDocument> 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<mozIDOMWindowProxy> 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<nsPIWindowRoot> 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<nsIContextMenuListener> menuListener(
do_QueryInterface(mWebBrowserChrome));
if (menuListener) {
menuListener->OnShowContextMenu(flags, aMouseEvent, targetDOMnode);
}
}
return NS_OK;
}

View File

@ -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<ChromeTooltipListener> mChromeTooltipListener;
RefPtr<ChromeContextMenuListener> mChromeContextMenuListener;
RefPtr<nsDocShellTreeOwner> mContentTreeOwner;
@ -203,37 +201,4 @@ private:
nsCOMPtr<nsIDOMNode> 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<mozilla::dom::EventTarget> mEventTarget;
nsCOMPtr<nsIWebBrowserChrome> mWebBrowserChrome;
};
#endif /* nsDocShellTreeOwner_h__ */

View File

@ -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.
*
* <TABLE>
* <TR><TD><B>aContextFlag</B></TD><TD>aNode</TD></TR>
* <TR><TD>CONTEXT_LINK</TD><TD>&lt;A&gt;</TD></TR>
* <TR><TD>CONTEXT_IMAGE</TD><TD>&lt;IMG&gt;</TD></TR>
* <TR><TD>CONTEXT_IMAGE | CONTEXT_LINK</TD><TD>&lt;IMG&gt;
* with an &lt;A&gt; as an ancestor</TD></TR>
* <TR><TD>CONTEXT_INPUT</TD><TD>&lt;INPUT&gt;</TD></TR>
* <TR><TD>CONTEXT_TEXT</TD><TD>&lt;TEXTAREA&gt;</TD></TR>
* <TR><TD>CONTEXT_DOCUMENT</TD><TD>&lt;HTML&gt;</TD></TR>
* </TABLE>
*
* @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 <CODE>NS_OK</CODE> always.
*/
void onShowContextMenu(in unsigned long aContextFlags, in nsIDOMEvent aEvent, in nsIDOMNode aNode);
};

View File

@ -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 <CODE>aUtils</CODE>, indicate where and what was clicked on.
*
* The following table describes what context flags and node combinations are
* possible.
*
* aContextFlags aUtils.targetNode
*
* CONTEXT_LINK <A>
* CONTEXT_IMAGE <IMG>
* CONTEXT_IMAGE | CONTEXT_LINK <IMG> with <A> as an ancestor
* CONTEXT_INPUT <INPUT>
* CONTEXT_INPUT | CONTEXT_IMAGE <INPUT> with type=image
* CONTEXT_TEXT <TEXTAREA>
* CONTEXT_DOCUMENT <HTML>
* CONTEXT_BACKGROUND_IMAGE <HTML> with background image
*
* @param aContextFlags Flags indicating the kind of context.
* @param aUtils Context information and helper utilities.
*
* @see nsIContextMenuInfo
*/
void onShowContextMenu(in unsigned long aContextFlags, in nsIContextMenuInfo aUtils);
};
/**
* nsIContextMenuInfo
*
* A helper object for implementors of nsIContextMenuListener2.
*/
[scriptable, uuid(2f977d56-5485-11d4-87e2-0010a4e75ef2)]
interface nsIContextMenuInfo : nsISupports
{
/**
* The DOM context menu event.
*/
readonly attribute nsIDOMEvent mouseEvent;
/**
* The DOM node most relevant to the context.
*/
readonly attribute nsIDOMNode targetNode;
/**
* Given the <CODE>CONTEXT_LINK</CODE> flag, <CODE>targetNode</CODE> may not
* nescesarily be a link. This returns the anchor from <CODE>targetNode</CODE>
* if it has one or that of its nearest ancestor if it does not.
*/
readonly attribute AString associatedLink;
/**
* Given the <CODE>CONTEXT_IMAGE</CODE> flag, these methods can be
* used in order to get the image for viewing, saving, or for the clipboard.
*
* @return <CODE>NS_OK</CODE> if successful, otherwise <CODE>NS_ERROR_FAILURE</CODE> if no
* image was found, or NS_ERROR_NULL_POINTER if an internal error occurs where we think there
* is an image, but for some reason it cannot be returned.
*/
readonly attribute imgIContainer imageContainer;
readonly attribute nsIURI imageSrc;
/**
* Given the <CODE>CONTEXT_BACKGROUND_IMAGE</CODE> flag, these methods can be
* used in order to get the image for viewing, saving, or for the clipboard.
*
* @return <CODE>NS_OK</CODE> if successful, otherwise <CODE>NS_ERROR_FAILURE</CODE> if no background
* image was found, or NS_ERROR_NULL_POINTER if an internal error occurs where we think there is a
* background image, but for some reason it cannot be returned.
*/
readonly attribute imgIContainer backgroundImageContainer;
readonly attribute nsIURI backgroundImageSrc;
};