diff --git a/mozilla/docshell/base/Makefile.in b/mozilla/docshell/base/Makefile.in index d4a6993d5af..e72dd63fe51 100644 --- a/mozilla/docshell/base/Makefile.in +++ b/mozilla/docshell/base/Makefile.in @@ -97,6 +97,7 @@ CPPSRCS = \ nsWebShell.cpp \ nsDocShellLoadInfo.cpp \ nsDocShellEditorData.cpp \ + nsDocShellTransferableHooks.cpp \ nsDocShellEnumerator.cpp \ nsDSURIContentListener.cpp \ nsDefaultURIFixup.cpp \ diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 013c5d5da73..d60a756ca2b 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -241,11 +241,13 @@ nsDocShell::nsDocShell(): mUseExternalProtocolHandler(PR_FALSE), mDisallowPopupWindows(PR_FALSE), mIsBeingDestroyed(PR_FALSE), + mIsExecutingOnLoadHandler(PR_FALSE), + mEditorData(nsnull), + mTransferableHookData(nsnull), mParent(nsnull), mTreeOwner(nsnull), mChromeEventHandler(nsnull), - mIsPrintingOrPP(PR_FALSE), - mIsExecutingOnLoadHandler(PR_FALSE) + mIsPrintingOrPP(PR_FALSE) { #ifdef PR_LOGGING if (! gDocShellLog) @@ -427,6 +429,19 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) return NS_NOINTERFACE; } + else if (aIID.Equals(NS_GET_IID(nsIClipboardDragDropHookList)) + && NS_SUCCEEDED(EnsureTransferableHookData())) { + nsCOMPtr hook = + NS_STATIC_CAST(nsIClipboardDragDropHookList *, mTransferableHookData); + if (hook) + { + *aSink = hook; + NS_ADDREF((nsISupports *)*aSink); + return NS_OK; + } + + return NS_NOINTERFACE; + } else if (aIID.Equals(NS_GET_IID(nsISelectionDisplay))) { nsCOMPtr shell; nsresult rv = GetPresShell(getter_AddRefs(shell)); @@ -2976,6 +2991,10 @@ nsDocShell::Destroy() delete mEditorData; mEditorData = 0; + NS_IF_RELEASE(NS_STATIC_CAST(nsIClipboardDragDropHookList *, mTransferableHookData)); + delete mTransferableHookData; + mTransferableHookData = nsnull; + // 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... @@ -6718,6 +6737,18 @@ nsDocShell::EnsureEditorData() return mEditorData ? NS_OK : NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsDocShell::EnsureTransferableHookData() +{ + if (!mTransferableHookData) { + mTransferableHookData = new nsTransferableHookData(); + if (!mTransferableHookData) return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(NS_STATIC_CAST(nsIClipboardDragDropHookList *, mTransferableHookData)); + } + + return NS_OK; +} + NS_IMETHODIMP nsDocShell::EnsureFind() { diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 67854911fc7..9df0f3ef8c3 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -79,6 +79,7 @@ #include "nsIURIFixup.h" #include "nsIWebBrowserFind.h" #include "nsIHttpChannel.h" +#include "nsDocShellTransferableHooks.h" #define MAKE_LOAD_TYPE(type, flags) ((type) | ((flags) << 16)) @@ -246,6 +247,7 @@ protected: NS_IMETHOD EnsureContentListener(); NS_IMETHOD EnsureScriptEnvironment(); NS_IMETHOD EnsureEditorData(); + nsresult EnsureTransferableHookData(); NS_IMETHOD EnsureFind(); NS_IMETHOD RefreshURIFromQueue(); NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI, const PRUnichar *aURL); @@ -359,6 +361,9 @@ protected: // Editor stuff nsDocShellEditorData* mEditorData; // editor data, if any + // Transferable hooks/callbacks + nsTransferableHookData* mTransferableHookData; + // WEAK REFERENCES BELOW HERE. // Note these are intentionally not addrefd. Doing so will create a cycle. // For that reasons don't use nsCOMPtr. diff --git a/mozilla/docshell/base/nsDocShellTransferableHooks.cpp b/mozilla/docshell/base/nsDocShellTransferableHooks.cpp new file mode 100644 index 00000000000..b07e4ce527b --- /dev/null +++ b/mozilla/docshell/base/nsDocShellTransferableHooks.cpp @@ -0,0 +1,92 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator. + * + * The Initial Developer of the Original Code is + * Netscape Communications. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Kathleen Brade + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsCOMPtr.h" +#include "nsCOMArray.h" +#include "nsDocShellTransferableHooks.h" +#include "nsIClipboardDragDropHooks.h" +#include "nsIClipboardDragDropHookList.h" +#include "nsISimpleEnumerator.h" +#include "nsArrayEnumerator.h" + +nsTransferableHookData::nsTransferableHookData() +{ +} + + +nsTransferableHookData::~nsTransferableHookData() +{ +} + +//***************************************************************************** +// nsIClipboardDragDropHookList +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(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); +} diff --git a/mozilla/docshell/base/nsDocShellTransferableHooks.h b/mozilla/docshell/base/nsDocShellTransferableHooks.h new file mode 100644 index 00000000000..84d0bfd376d --- /dev/null +++ b/mozilla/docshell/base/nsDocShellTransferableHooks.h @@ -0,0 +1,62 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla Communicator. + * + * The Initial Developer of the Original Code is + * Netscape Communications. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Kathleen Brade + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDocShellTransferableHooks_h__ +#define nsDocShellTransferableHooks_h__ + +#ifndef nsCOMPtr_h___ +#include "nsCOMPtr.h" +#endif + +#include "nsIClipboardDragDropHooks.h" +#include "nsIClipboardDragDropHookList.h" +#include "nsCOMArray.h" + + +class nsTransferableHookData : public nsIClipboardDragDropHookList +{ +public: + nsTransferableHookData(); + virtual ~nsTransferableHookData(); + NS_DECL_ISUPPORTS + NS_DECL_NSICLIPBOARDDRAGDROPHOOKLIST + +protected: + nsCOMArray mHookList; +}; + +#endif nsDocShellTransferableHooks_h__