Have clipboard implementations that care about flushing data to the OS clipboard register for xpcom-shutdown notification, rather than being notified by nsAppRunner directly. Bug 239390, r=bsmedberg, sr=blizzard.

This commit is contained in:
bryner%brianryner.com 2004-06-10 20:39:11 +00:00
Родитель 5be5e5bb3f
Коммит 2666a9d913
14 изменённых файлов: 47 добавлений и 122 удалений

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

@ -72,7 +72,6 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsIWindowMediator.h"
#include "nsIDOMWindowInternal.h"
#include "nsIClipboard.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsICmdLineHandler.h"
@ -786,18 +785,6 @@ static nsresult DoOnShutdown()
}
}
// at this point, all that is on the clipboard is a proxy object, but that object
// won't be valid once the app goes away. As a result, we need to force the data
// out of that proxy and properly onto the clipboard. This can't be done in the
// clipboard service's shutdown routine because it requires the parser/etc which
// has already been shutdown by the time the clipboard is shut down.
{
// scoping this in a block to force release
nsCOMPtr<nsIClipboard> clipService(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_SUCCEEDED(rv))
clipService->ForceDataToClipboard(nsIClipboard::kGlobalClipboard);
}
return rv;
}

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

@ -82,17 +82,6 @@ interface nsIClipboard : nsISupports
void emptyClipboard ( in long aWhichClipboard ) ;
/**
* Some platforms support deferred notification for putting data on the clipboard
* This method forces the data onto the clipboard in its various formats
* This may be used if the application going away.
*
* @param aWhichClipboard Specifies the clipboard to which this operation applies.
* @result NS_OK if successful.
*/
void forceDataToClipboard ( in long aWhichClipboard ) ;
/**
* This provides a way to give correct UI feedback about, for instance, a paste
* should be allowed. It does _NOT_ actually retreive the data and should be a very

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

@ -334,20 +334,3 @@ nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable, PRInt32 aWh
return rv;
}
//
// No-op.
//
NS_IMETHODIMP nsClipboard::ForceDataToClipboard()
{
#ifdef DEBUG_CLIPBOARD
printf(" nsClipboard::ForceDataToClipboard()\n");
#endif /* DEBUG_CLIPBOARD */
// make sure we have a good transferable
if (nsnull == mTransferable) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -55,9 +55,6 @@ public:
nsClipboard();
virtual ~nsClipboard();
// nsIClipboard
NS_IMETHOD ForceDataToClipboard();
static void SetTopLevelView(BView *v);

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

@ -753,30 +753,6 @@ nsClipboard::SelectionReceiver (GtkWidget *aWidget,
}
}
/**
* Some platforms support deferred notification for putting data on the clipboard
* This method forces the data onto the clipboard in its various formats
* This may be used if the application going away.
*
* @result NS_OK if successful.
*/
NS_IMETHODIMP nsClipboard::ForceDataToClipboard(PRInt32 aWhichClipboard)
{
#ifdef DEBUG_CLIPBOARD
g_print(" nsClipboard::ForceDataToClipboard()\n");
#endif /* DEBUG_CLIPBOARD */
// make sure we have a good transferable
nsCOMPtr<nsITransferable> transferable(GetTransferable(aWhichClipboard));
if (nsnull == transferable) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsClipboard::HasDataMatchingFlavors(nsISupportsArray* aFlavorList,
PRInt32 aWhichClipboard,

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

@ -348,15 +348,6 @@ nsClipboard::EmptyClipboard(PRInt32 aWhichClipboard)
return NS_OK;
}
NS_IMETHODIMP
nsClipboard::ForceDataToClipboard(PRInt32 aWhichClipboard)
{
// We don't have a way to force data to the clipboard since
// there's no common place to put clipboard data.
return NS_OK;
}
NS_IMETHODIMP
nsClipboard::HasDataMatchingFlavors(nsISupportsArray *aFlavorList,
PRInt32 aWhichClipboard, PRBool *_retval)

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

@ -94,7 +94,7 @@ nsClipboard::~nsClipboard()
// Take data off the transferrable and put it on the clipboard in as many formats
// as are registered.
//
// NOTE: This code could all live in ForceDataToClipboard() and this could be a NOOP.
// NOTE: This code could all live in a shutdown observer and this could be a NOOP.
// If speed and large data sizes are an issue, we should move that code there and only
// do it on an app switch.
//

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

@ -61,7 +61,6 @@ public:
virtual ~nsClipboard();
// nsIClipboard
//NS_IMETHOD ForceDataToClipboard();
NS_IMETHOD HasDataMatchingFlavors(nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval);
protected:

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

@ -73,11 +73,20 @@ nsClipboard::nsClipboard() : nsBaseClipboard()
RegisterClipboardFormat(kURLMime);
RegisterClipboardFormat(kNativeImageMime);
RegisterClipboardFormat(kNativeHTMLMime);
// Register for a shutdown notification so that we can flush data
// to the OS clipboard.
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
if (observerService)
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
nsClipboard::~nsClipboard()
{}
NS_IMPL_ISUPPORTS_INHERITED1(nsClipboard, nsBaseClipboard, nsIObserver)
nsresult nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard)
{
if (aWhichClipboard != kGlobalClipboard)
@ -394,8 +403,13 @@ ULONG nsClipboard::GetFormatID(const char *aMimeStr)
return RegisterClipboardFormat(aMimeStr);
}
NS_IMETHODIMP nsClipboard::ForceDataToClipboard(PRInt32 aWhichClipboard)
// nsIObserver
NS_IMETHODIMP
nsClipboard::Observe(nsISupports *aSubject, const char *aTopic,
PRUnichar *aData)
{
// This will be called on shutdown.
// make sure we have a good transferable
if (!mTransferable || aWhichClipboard != kGlobalClipboard)
return NS_ERROR_FAILURE;

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

@ -40,6 +40,7 @@
#include "nsWidgetDefs.h"
#include "nsBaseClipboard.h"
#include "nsIObserver.h"
class nsITransferable;
class nsIClipboardOwner;
@ -52,13 +53,20 @@ struct IDataObject;
struct FormatRecord;
class nsClipboard : public nsBaseClipboard
class nsClipboard : public nsBaseClipboard,
public nsIObserver
{
public:
nsClipboard();
virtual ~nsClipboard();
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// nsIObserver
NS_DECL_NSIOBSERVER
// nsIClipboard
NS_IMETHOD ForceDataToClipboard(PRInt32 aWhichClipboard);
NS_IMETHOD HasDataMatchingFlavors(nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval);

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

@ -483,30 +483,6 @@ nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable,
return NS_OK;
}
/**
* Some platforms support deferred notification for putting data on the clipboard
* This method forces the data onto the clipboard in its various formats
* This may be used if the application going away.
*
* @result NS_OK if successful.
*/
NS_IMETHODIMP nsClipboard::ForceDataToClipboard(PRInt32 aWhichClipboard)
{
if (aWhichClipboard == kSelectionClipboard)
return (NS_ERROR_FAILURE);
#ifdef DEBUG_CLIPBOARD
printf(" nsClipboard::ForceDataToClipboard()\n");
#endif /* DEBUG_CLIPBOARD */
// make sure we have a good transferable
nsITransferable *transferable = GetTransferable(aWhichClipboard);
if (!transferable)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsClipboard::HasDataMatchingFlavors(nsISupportsArray* aFlavorList,
PRInt32 aWhichClipboard,

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

@ -67,6 +67,7 @@
#include "nsNetUtil.h"
#include "nsIImage.h"
#include "nsIObserverService.h"
// oddly, this isn't in the MSVC headers anywhere.
@ -83,6 +84,12 @@ nsClipboard::nsClipboard() : nsBaseClipboard()
mIgnoreEmptyNotification = PR_FALSE;
mWindow = nsnull;
// Register for a shutdown notification so that we can flush data
// to the OS clipboard.
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
if (observerService)
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
//-------------------------------------------------------------------------
@ -93,6 +100,8 @@ nsClipboard::~nsClipboard()
}
NS_IMPL_ISUPPORTS_INHERITED1(nsClipboard, nsBaseClipboard, nsIObserver)
//-------------------------------------------------------------------------
UINT nsClipboard::GetFormat(const char* aMimeStr)
{
@ -859,8 +868,11 @@ nsClipboard::GetNativeClipboardData ( nsITransferable * aTransferable, PRInt32 a
//-------------------------------------------------------------------------
NS_IMETHODIMP nsClipboard::ForceDataToClipboard ( PRInt32 aWhichClipboard )
NS_IMETHODIMP
nsClipboard::Observe(nsISupports *aSubject, const char *aTopic,
PRUnichar *aData)
{
// This will be called on shutdown.
::OleFlushClipboard();
::CloseClipboard();

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

@ -39,6 +39,7 @@
#define nsClipboard_h__
#include "nsBaseClipboard.h"
#include "nsIObserver.h"
#include <windows.h>
class nsITransferable;
@ -50,15 +51,20 @@ struct IDataObject;
* Native Win32 Clipboard wrapper
*/
class nsClipboard : public nsBaseClipboard
class nsClipboard : public nsBaseClipboard,
public nsIObserver
{
public:
nsClipboard();
virtual ~nsClipboard();
// nsIClipboard
NS_IMETHOD ForceDataToClipboard ( PRInt32 aWhichClipboard );
NS_DECL_ISUPPORTS_INHERITED
// nsIObserver
NS_DECL_NSIOBSERVER
// nsIClipboard
NS_IMETHOD HasDataMatchingFlavors(nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval);
// Internal Native Routines

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

@ -70,7 +70,6 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsIWindowMediator.h"
#include "nsIDOMWindowInternal.h"
#include "nsIClipboard.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsICmdLineHandler.h"
@ -809,18 +808,6 @@ static nsresult DoOnShutdown()
}
}
// at this point, all that is on the clipboard is a proxy object, but that object
// won't be valid once the app goes away. As a result, we need to force the data
// out of that proxy and properly onto the clipboard. This can't be done in the
// clipboard service's shutdown routine because it requires the parser/etc which
// has already been shutdown by the time the clipboard is shut down.
{
// scoping this in a block to force release
nsCOMPtr<nsIClipboard> clipService(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
if (NS_SUCCEEDED(rv))
clipService->ForceDataToClipboard(nsIClipboard::kGlobalClipboard);
}
return rv;
}