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
Родитель 7f36b280a9
Коммит 86de6958fb
14 изменённых файлов: 47 добавлений и 206 удалений

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

@ -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.
//

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

@ -1,85 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 ***** */
//
// Mike Pinkerton
// Netscape Communications
//
// Native MacOS Clipboard Implementation of nsIClipboard. This contains
// the FE-specific implementations of the pure virtuals in nsBaseClipboard
//
#ifndef nsClipboard_h__
#define nsClipboard_h__
#include "nsBaseClipboard.h"
#include "Types.h"
class nsITransferable;
class nsClipboard : public nsBaseClipboard
{
public:
nsClipboard();
virtual ~nsClipboard();
// nsIClipboard
//NS_IMETHOD ForceDataToClipboard();
NS_IMETHOD HasDataMatchingFlavors(nsISupportsArray *aFlavorList, PRInt32 aWhichClipboard, PRBool *_retval);
protected:
// impelement the native clipboard behavior
NS_IMETHOD SetNativeClipboardData ( PRInt32 aWhichClipboard );
NS_IMETHOD GetNativeClipboardData ( nsITransferable * aTransferable, PRInt32 aWhichClipboard );
// helper to get the data off the clipboard. Caller responsible for deleting
// |outData| with delete[].
nsresult GetDataOffClipboard ( ResType inMacFlavor, void** outData, PRInt32* outDataSize ) ;
// helper to check if the data is really there
PRBool CheckIfFlavorPresent ( ResType inMacFlavor ) ;
// actually places data on the clipboard
nsresult PutOnClipboard ( ResType inFlavor, const void* inData, PRInt32 inLen ) ;
}; // nsClipboard
#endif // nsClipboard_h__

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

@ -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;
}