Bug 888900 - Make sure the clipboard is always flushed at shutdown on win32 (r=jimm)

This commit is contained in:
Bill McCloskey 2013-07-18 13:31:53 -07:00
Родитель 2a3d3d167f
Коммит 8ea3fc6605
2 изменённых файлов: 28 добавлений и 1 удалений

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

@ -32,6 +32,7 @@
#include "nsCRT.h" #include "nsCRT.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsEscape.h" #include "nsEscape.h"
#include "nsIObserverService.h"
#ifdef PR_LOGGING #ifdef PR_LOGGING
PRLogModuleInfo* gWin32ClipboardLog = nullptr; PRLogModuleInfo* gWin32ClipboardLog = nullptr;
@ -56,6 +57,13 @@ nsClipboard::nsClipboard() : nsBaseClipboard()
mIgnoreEmptyNotification = false; mIgnoreEmptyNotification = false;
mWindow = nullptr; mWindow = nullptr;
// 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);
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -66,6 +74,19 @@ nsClipboard::~nsClipboard()
} }
NS_IMPL_ISUPPORTS_INHERITED1(nsClipboard, nsBaseClipboard, nsIObserver)
NS_IMETHODIMP
nsClipboard::Observe(nsISupports *aSubject, const char *aTopic,
const PRUnichar *aData)
{
// This will be called on shutdown.
::OleFlushClipboard();
::CloseClipboard();
return NS_OK;
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
UINT nsClipboard::GetFormat(const char* aMimeStr) UINT nsClipboard::GetFormat(const char* aMimeStr)
{ {

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

@ -20,13 +20,19 @@ struct IDataObject;
* Native Win32 Clipboard wrapper * Native Win32 Clipboard wrapper
*/ */
class nsClipboard : public nsBaseClipboard class nsClipboard : public nsBaseClipboard,
public nsIObserver
{ {
public: public:
nsClipboard(); nsClipboard();
virtual ~nsClipboard(); virtual ~nsClipboard();
NS_DECL_ISUPPORTS_INHERITED
// nsIObserver
NS_DECL_NSIOBSERVER
// nsIClipboard // nsIClipboard
NS_IMETHOD HasDataMatchingFlavors(const char** aFlavorList, uint32_t aLength, NS_IMETHOD HasDataMatchingFlavors(const char** aFlavorList, uint32_t aLength,
int32_t aWhichClipboard, bool *_retval); int32_t aWhichClipboard, bool *_retval);