Bug 1448876 - Get rid of nsIClipboardDragDropHooks and nsIClipboardDragDropHookList interfaces r=bz

nsIClipboardDragDropHooks and nsIClipboardDragDropHookList allow XUL apps
to customize drag and drop operation and paste operation.  However, this
feature was used only by ChatZilla and it doesn't work on Gecko anymore.
So, we can get rid of them from our tree.

MozReview-Commit-ID: Ibs3V1gI8Ry

--HG--
extra : rebase_source : 83428293d59aaca432d76c71b214aa7799f7f9de
This commit is contained in:
Masayuki Nakano 2018-03-26 23:56:53 +09:00
Родитель 8404f212bd
Коммит ec04470e25
15 изменённых файлов: 1 добавлений и 496 удалений

Просмотреть файл

@ -86,7 +86,6 @@ UNIFIED_SOURCES += [
'nsDocShellEditorData.cpp',
'nsDocShellEnumerator.cpp',
'nsDocShellLoadInfo.cpp',
'nsDocShellTransferableHooks.cpp',
'nsDocShellTreeOwner.cpp',
'nsDSURIContentListener.cpp',
'nsPingListener.cpp',

Просмотреть файл

@ -176,7 +176,6 @@
#include "nsDocShellEnumerator.h"
#include "nsDocShellLoadInfo.h"
#include "nsDocShellLoadTypes.h"
#include "nsDocShellTransferableHooks.h"
#include "nsDOMCID.h"
#include "nsDOMNavigationTiming.h"
#include "nsDSURIContentListener.h"
@ -629,11 +628,6 @@ nsDocShell::GetInterface(const nsIID& aIID, void** aSink)
GetEditingSession(getter_AddRefs(es));
es.forget(aSink);
return *aSink ? NS_OK : NS_NOINTERFACE;
} else if (aIID.Equals(NS_GET_IID(nsIClipboardDragDropHookList)) &&
NS_SUCCEEDED(EnsureTransferableHookData())) {
*aSink = mTransferableHookData;
NS_ADDREF((nsISupports*)*aSink);
return NS_OK;
} else if (aIID.Equals(NS_GET_IID(nsISelectionDisplay))) {
nsIPresShell* shell = GetPresShell();
if (shell) {
@ -5510,8 +5504,6 @@ nsDocShell::Destroy()
mEditorData = nullptr;
mTransferableHookData = nullptr;
// Save the state of the current document, before destroying the window.
// This is needed to capture the state of a frameset when the new document
// causes the frameset to be destroyed...
@ -12999,18 +12991,6 @@ nsDocShell::EnsureEditorData()
return mEditorData ? NS_OK : NS_ERROR_NOT_AVAILABLE;
}
nsresult
nsDocShell::EnsureTransferableHookData()
{
MOZ_ASSERT(!mIsBeingDestroyed);
if (!mTransferableHookData) {
mTransferableHookData = new nsTransferableHookData();
}
return NS_OK;
}
nsresult
nsDocShell::EnsureFind()
{

Просмотреть файл

@ -74,7 +74,6 @@ typedef uint32_t ScreenOrientationInternal;
} // namespace dom
} // namespace mozilla
class nsIClipboardDragDropHookList;
class nsICommandManager;
class nsIContentViewer;
class nsIController;
@ -964,9 +963,6 @@ private: // data members
// Editor data, if this document is designMode or contentEditable.
nsAutoPtr<nsDocShellEditorData> mEditorData;
// Transferable hooks/callbacks
nsCOMPtr<nsIClipboardDragDropHookList> mTransferableHookData;
// Secure browser UI object
nsCOMPtr<nsISecureBrowserUI> mSecurityUI;

Просмотреть файл

@ -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/. */
#include "nsDocShellTransferableHooks.h"
#include "nsIClipboardDragDropHooks.h"
#include "nsIClipboardDragDropHookList.h"
#include "nsArrayEnumerator.h"
nsTransferableHookData::nsTransferableHookData()
{
}
nsTransferableHookData::~nsTransferableHookData()
{
}
NS_IMPL_ISUPPORTS(nsTransferableHookData, nsIClipboardDragDropHookList)
NS_IMETHODIMP
nsTransferableHookData::AddClipboardDragDropHooks(
nsIClipboardDragDropHooks* aOverrides)
{
NS_ENSURE_ARG(aOverrides);
// don't let a hook be added more than once
if (mHookList.IndexOfObject(aOverrides) == -1) {
if (!mHookList.AppendObject(aOverrides)) {
return NS_ERROR_FAILURE;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsTransferableHookData::RemoveClipboardDragDropHooks(
nsIClipboardDragDropHooks* aOverrides)
{
NS_ENSURE_ARG(aOverrides);
if (!mHookList.RemoveObject(aOverrides)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsTransferableHookData::GetHookEnumerator(nsISimpleEnumerator** aResult)
{
return NS_NewArrayEnumerator(aResult, mHookList);
}

Просмотреть файл

@ -1,28 +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 nsDocShellTransferableHooks_h__
#define nsDocShellTransferableHooks_h__
#include "nsIClipboardDragDropHookList.h"
#include "nsCOMArray.h"
class nsIClipboardDragDropHooks;
class nsTransferableHookData : public nsIClipboardDragDropHookList
{
public:
nsTransferableHookData();
NS_DECL_ISUPPORTS
NS_DECL_NSICLIPBOARDDRAGDROPHOOKLIST
protected:
virtual ~nsTransferableHookData();
nsCOMArray<nsIClipboardDragDropHooks> mHookList;
};
#endif // nsDocShellTransferableHooks_h__

Просмотреть файл

@ -26,8 +26,6 @@
#include "nsIDocShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIClipboardDragDropHooks.h"
#include "nsIClipboardDragDropHookList.h"
#include "nsIClipboardHelper.h"
#include "nsISelectionController.h"
@ -279,12 +277,8 @@ SelectionCopyHelper(nsISelection *aSel, nsIDocument *aDoc,
}
if (doPutOnClipboard && clipboard) {
bool actuallyPutOnClipboard = true;
nsCopySupport::DoHooks(aDoc, trans, &actuallyPutOnClipboard);
// put the transferable on the clipboard
if (actuallyPutOnClipboard)
clipboard->SetData(trans, nullptr, aClipboardID);
clipboard->SetData(trans, nullptr, aClipboardID);
}
// Return the transferable to the caller if requested.
@ -351,49 +345,6 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode,
aTransferable);
}
nsresult nsCopySupport::DoHooks(nsIDocument *aDoc, nsITransferable *aTrans,
bool *aDoPutOnClipboard)
{
NS_ENSURE_ARG(aDoc);
*aDoPutOnClipboard = true;
nsCOMPtr<nsISupports> container = aDoc->GetContainer();
nsCOMPtr<nsIClipboardDragDropHookList> hookObj = do_GetInterface(container);
if (!hookObj) return NS_ERROR_FAILURE;
nsCOMPtr<nsISimpleEnumerator> enumerator;
hookObj->GetHookEnumerator(getter_AddRefs(enumerator));
if (!enumerator) return NS_ERROR_FAILURE;
// the logic here should follow the behavior specified in
// nsIClipboardDragDropHooks.h
nsCOMPtr<nsIClipboardDragDropHooks> override;
nsCOMPtr<nsISupports> isupp;
bool hasMoreHooks = false;
nsresult rv = NS_OK;
while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreHooks))
&& hasMoreHooks)
{
rv = enumerator->GetNext(getter_AddRefs(isupp));
if (NS_FAILED(rv)) break;
override = do_QueryInterface(isupp);
if (override)
{
#ifdef DEBUG
nsresult hookResult =
#endif
override->OnCopyOrDrag(nullptr, aTrans, aDoPutOnClipboard);
NS_ASSERTION(NS_SUCCEEDED(hookResult), "OnCopyOrDrag hook failed");
if (!*aDoPutOnClipboard)
break;
}
}
return rv;
}
nsresult
nsCopySupport::GetContents(const nsACString& aMimeType, uint32_t aFlags, nsISelection *aSel, nsIDocument *aDoc, nsAString& outdata)
{

Просмотреть файл

@ -33,8 +33,6 @@ class nsCopySupport
static nsresult ClearSelectionCache();
static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc,
int16_t aClipboardID, bool aWithRubyAnnotation);
static nsresult DoHooks(nsIDocument *aDoc, nsITransferable *aTrans,
bool *aDoPutOnClipboard);
// Get the selection, or entire document, in the format specified by the mime type
// (text/html or text/plain). If aSel is non-null, use it, otherwise get the entire

Просмотреть файл

@ -37,9 +37,6 @@
#include "mozilla/dom/Selection.h"
#include "mozilla/layers/KeyboardMap.h"
#include "nsIClipboardDragDropHooks.h"
#include "nsIClipboardDragDropHookList.h"
using namespace mozilla;
using namespace mozilla::layers;
@ -918,101 +915,6 @@ nsGoBackCommand::DoWebNavCommand(const char *aCommandName, nsIWebNavigation* aWe
}
#endif
/*---------------------------------------------------------------------------
nsClipboardDragDropHookCommand
params value type possible values
"addhook" isupports nsIClipboardDragDropHooks as nsISupports
"removehook" isupports nsIClipboardDragDropHooks as nsISupports
----------------------------------------------------------------------------*/
class nsClipboardDragDropHookCommand final : public nsIControllerCommand
{
~nsClipboardDragDropHookCommand() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICONTROLLERCOMMAND
protected:
// no member variables, please, we're stateless!
};
NS_IMPL_ISUPPORTS(nsClipboardDragDropHookCommand, nsIControllerCommand)
NS_IMETHODIMP
nsClipboardDragDropHookCommand::IsCommandEnabled(const char * aCommandName,
nsISupports *aCommandContext,
bool *outCmdEnabled)
{
*outCmdEnabled = true;
return NS_OK;
}
NS_IMETHODIMP
nsClipboardDragDropHookCommand::DoCommand(const char *aCommandName,
nsISupports *aCommandContext)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsClipboardDragDropHookCommand::DoCommandParams(const char *aCommandName,
nsICommandParams *aParams,
nsISupports *aCommandContext)
{
NS_ENSURE_ARG(aParams);
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aCommandContext);
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
nsIDocShell *docShell = window->GetDocShell();
nsCOMPtr<nsIClipboardDragDropHookList> obj = do_GetInterface(docShell);
if (!obj) return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsISupports> isuppHook;
nsresult returnValue = NS_OK;
nsresult rv = aParams->GetISupportsValue("addhook", getter_AddRefs(isuppHook));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIClipboardDragDropHooks> hook = do_QueryInterface(isuppHook);
if (hook)
returnValue = obj->AddClipboardDragDropHooks(hook);
else
returnValue = NS_ERROR_INVALID_ARG;
}
rv = aParams->GetISupportsValue("removehook", getter_AddRefs(isuppHook));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIClipboardDragDropHooks> hook = do_QueryInterface(isuppHook);
if (hook)
{
rv = obj->RemoveClipboardDragDropHooks(hook);
if (NS_FAILED(rv) && NS_SUCCEEDED(returnValue))
returnValue = rv;
}
else
returnValue = NS_ERROR_INVALID_ARG;
}
return returnValue;
}
NS_IMETHODIMP
nsClipboardDragDropHookCommand::GetCommandStateParams(const char *aCommandName,
nsICommandParams *aParams,
nsISupports *aCommandContext)
{
NS_ENSURE_ARG_POINTER(aParams);
return aParams->SetBooleanValue("state_enabled", true);
}
class nsLookUpDictionaryCommand final : public nsIControllerCommand
{
public:
@ -1279,8 +1181,6 @@ nsWindowCommandRegistration::RegisterWindowCommands(
NS_REGISTER_ONE_COMMAND(nsGoForwardCommand, "cmd_browserForward");
#endif
NS_REGISTER_ONE_COMMAND(nsClipboardDragDropHookCommand, "cmd_clipboardDragDropHook");
NS_REGISTER_ONE_COMMAND(nsLookUpDictionaryCommand, "cmd_lookUpDictionary");
return rv;

Просмотреть файл

@ -10,9 +10,6 @@
#include "mozilla/dom/Selection.h"
#include "nsComponentManagerUtils.h"
#include "nsError.h"
#include "nsIClipboardDragDropHookList.h"
// hooks
#include "nsIClipboardDragDropHooks.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsIDOMDocument.h"
@ -20,7 +17,6 @@
#include "nsIDocument.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsINode.h"
#include "nsISimpleEnumerator.h"
class nsISupports;
class nsRange;
@ -183,52 +179,4 @@ EditorUtils::IsDescendantOf(const nsINode& aNode,
return false;
}
/******************************************************************************
* utility methods for drag/drop/copy/paste hooks
*****************************************************************************/
nsresult
EditorHookUtils::GetHookEnumeratorFromDocument(nsIDOMDocument* aDoc,
nsISimpleEnumerator** aResult)
{
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell = doc->GetDocShell();
nsCOMPtr<nsIClipboardDragDropHookList> hookObj = do_GetInterface(docShell);
NS_ENSURE_TRUE(hookObj, NS_ERROR_FAILURE);
return hookObj->GetHookEnumerator(aResult);
}
bool
EditorHookUtils::DoInsertionHook(nsIDOMDocument* aDoc,
nsIDOMEvent* aDropEvent,
nsITransferable *aTrans)
{
nsCOMPtr<nsISimpleEnumerator> enumerator;
GetHookEnumeratorFromDocument(aDoc, getter_AddRefs(enumerator));
NS_ENSURE_TRUE(enumerator, true);
bool hasMoreHooks = false;
while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreHooks)) &&
hasMoreHooks) {
nsCOMPtr<nsISupports> isupp;
if (NS_FAILED(enumerator->GetNext(getter_AddRefs(isupp)))) {
break;
}
nsCOMPtr<nsIClipboardDragDropHooks> override = do_QueryInterface(isupp);
if (override) {
bool doInsert = true;
DebugOnly<nsresult> hookResult =
override->OnPasteOrDrop(aDropEvent, aTrans, &doInsert);
NS_ASSERTION(NS_SUCCEEDED(hookResult), "hook failure in OnPasteOrDrop");
NS_ENSURE_TRUE(doInsert, false);
}
}
return true;
}
} // namespace mozilla

Просмотреть файл

@ -546,18 +546,6 @@ public:
EditorDOMPoint* aOutPoint);
};
class EditorHookUtils final
{
public:
static bool DoInsertionHook(nsIDOMDocument* aDoc, nsIDOMEvent* aEvent,
nsITransferable* aTrans);
private:
static nsresult GetHookEnumeratorFromDocument(
nsIDOMDocument*aDoc,
nsISimpleEnumerator** aEnumerator);
};
} // namespace mozilla
#endif // #ifndef mozilla_EditorUtils_h

Просмотреть файл

@ -1415,13 +1415,6 @@ HTMLEditor::Paste(int32_t aSelectionType)
}
}
// handle transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc;
GetDocument(getter_AddRefs(domdoc));
if (!EditorHookUtils::DoInsertionHook(domdoc, nullptr, trans)) {
return NS_OK;
}
return InsertFromTransferable(trans, nullptr, contextStr, infoStr, bHavePrivateHTMLFlavor,
nullptr, 0, true);
}
@ -1435,12 +1428,6 @@ HTMLEditor::PasteTransferable(nsITransferable* aTransferable)
return NS_OK;
}
// handle transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
if (!EditorHookUtils::DoInsertionHook(domdoc, nullptr, aTransferable)) {
return NS_OK;
}
nsAutoString contextStr, infoStr;
return InsertFromTransferable(aTransferable, nullptr, contextStr, infoStr, false,
nullptr, 0, true);

Просмотреть файл

@ -310,12 +310,6 @@ TextEditor::Paste(int32_t aSelectionType)
// Get the Data from the clipboard
if (NS_SUCCEEDED(clipboard->GetData(trans, aSelectionType)) &&
IsModifiable()) {
// handle transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
if (!EditorHookUtils::DoInsertionHook(domdoc, nullptr, trans)) {
return NS_OK;
}
rv = InsertTextFromTransferable(trans, nullptr, 0, true);
}
}
@ -336,12 +330,6 @@ TextEditor::PasteTransferable(nsITransferable* aTransferable)
return NS_OK;
}
// handle transferable hooks
nsCOMPtr<nsIDOMDocument> domdoc = GetDOMDocument();
if (!EditorHookUtils::DoInsertionHook(domdoc, nullptr, aTransferable)) {
return NS_OK;
}
return InsertTextFromTransferable(aTransferable, nullptr, 0, true);
}

Просмотреть файл

@ -94,8 +94,6 @@ XPIDL_SOURCES += [
'nsIBaseWindow.idl',
'nsIBidiKeyboard.idl',
'nsIClipboard.idl',
'nsIClipboardDragDropHookList.idl',
'nsIClipboardDragDropHooks.idl',
'nsIClipboardHelper.idl',
'nsIClipboardOwner.idl',
'nsIColorPicker.idl',

Просмотреть файл

@ -1,45 +0,0 @@
/* 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 nsIClipboardDragDropHooks;
interface nsISimpleEnumerator;
/**
* Please note that the following api is not intended for embedders;
* it is intended as an internal (to gecko). Embedders can indirectly
* call these by sending commands (see description in
* nsIClipboardDragDropHooks.idl).
*
* Internal gecko usage is accomplished by calling get_Interface on a
* docshell.
*/
// 876A2015-6B66-11D7-8F18-0003938A9D96
[scriptable,uuid(876A2015-6B66-11D7-8F18-0003938A9D96)]
interface nsIClipboardDragDropHookList : nsISupports
{
/**
* Add a hook to list.
* @param aHooks implementation of hooks
*/
void addClipboardDragDropHooks(in nsIClipboardDragDropHooks aHooks);
/**
* Remove a hook from list (note if this implementation is not present
* in the list then removal will be ignored).
* @param aHooks implementation of hooks
*/
void removeClipboardDragDropHooks(in nsIClipboardDragDropHooks aHooks);
/**
* Gets an enumerator for all hooks which have been added.
* @return nsISimpleEnumerator for nsIClipboardDragDropHooks
*/
nsISimpleEnumerator getHookEnumerator();
};

Просмотреть файл

@ -1,101 +0,0 @@
/* 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 nsITransferable;
interface nsIDragSession;
interface nsIDOMEvent;
/**
* Interfaces for overriding the built-in drag, drop, copy, and paste
* implementations in the content area and editors. Use this to do things
* such as prevent a drag from starting, adding or removing
* data and flavors, or preventing the drop.
*
* Embedders who want to have these hooks made available should implement
* nsIClipboardDragDropHooks and use the command manager to send the
* appropriate commands with these parameters/settings:
* command: cmd_clipboardDragDropHook
*
* params value type possible values
* "addhook" isupports nsIClipboardDragDropHooks as nsISupports
* "removehook" isupports nsIClipboardDragDropHooks as nsISupports
*
* Notes:
* * Overrides/hooks need to be added to each window (as appropriate).
* Adding them to the first window does not enable them for every window.
* * If more than one implementation is set for a window, the hooks will be
* called in the order they are added.
* * Adding the same hook to the same window will not add a second call.
* Each hook can only be called once per user action/api.
* * Not all hooks are guaranteed to be called. If there are multiple hooks
* set for a window, any of them has an opportunity to cancel the action
* so no further processing will occur.
* * If any errors occur (without setting the boolean result) the default
* action will occur.
* * AllowDrop will be called MANY times during drag so ensure that it is
* efficient.
*/
[scriptable,uuid(e03e6c5e-0d84-4c0b-8739-e6b8d51922de)]
interface nsIClipboardDragDropHooks : nsISupports
{
/**
* Prevents the drag from starting
*
* @param event DOM event (drag gesture)
*
* @return TRUE drag can proceed
* @return FALSE drag is cancelled, does not go to OS
*/
boolean allowStartDrag(in nsIDOMEvent event);
/**
* Tells gecko whether a drop is allowed on this content area
*
* @param event DOM event (drag over)
* @param session the drag session from which client can get
* the flavors present or the actual data
*
* @return TRUE indicates to OS that if a drop does happen on this
* browser, it will be accepted.
* @return FALSE indicates to OS drop is not allowed. On win32, this
* will change the cursor to "reject".
*/
boolean allowDrop(in nsIDOMEvent event, in nsIDragSession session);
/**
* Alter the flavors or data presented to the OS
* Used for drag and copy actions
* Because this can be called many times, it is highly recommended
* that the implementation be very efficient so user feedback is
* not negatively impacted.
*
* @param event DOM event (drag drop); null if triggered by copy.
* @param trans the transferable holding the list of flavors
* and the data for each flavor
*
* @return TRUE copy/drag can proceed
* @return FALSE copy/drag is cancelled, does not go to OS
*/
boolean onCopyOrDrag(in nsIDOMEvent aEvent, in nsITransferable trans);
/**
* Provide an alternative action to the built-in behavior when
* something is dropped on the browser or in an editor
*
* @param event DOM event (drag drop); null if triggered by paste.
* @param trans the transferable holding the list of flavors
* and the data for each flavor
*
* @return TRUE action was handled, do not perform built-in
* behavior
* @return FALSE action was not overridden, do built-in behavior
*/
boolean onPasteOrDrop(in nsIDOMEvent event, in nsITransferable trans);
};