2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:01:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-03-23 18:37:34 +03:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* 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/
|
1999-03-23 18:37:34 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1999-03-23 18:37:34 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2000-02-04 03:39:15 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2000-08-04 02:05:09 +04:00
|
|
|
* Sean Echevarria <sean@beatnik.com>
|
2004-12-07 17:13:54 +03:00
|
|
|
* David Gardiner <david.gardiner@unisa.edu.au>
|
2008-10-20 19:21:02 +04:00
|
|
|
* Kathleen Brade <brade@comcast.net>
|
|
|
|
* Mark Smith <mcs@pearlcrescent.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-19 02:01:16 +04:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-19 02:01:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-19 02:01:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-03-23 18:37:34 +03:00
|
|
|
|
|
|
|
#include "nsClipboard.h"
|
2003-10-08 00:39:25 +04:00
|
|
|
#include <ole2.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
#include <intshcut.h>
|
1999-03-23 18:37:34 +03:00
|
|
|
|
2002-10-17 10:47:01 +04:00
|
|
|
// shellapi.h is needed to build with WIN32_LEAN_AND_MEAN
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
1999-04-17 17:49:39 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-03-23 18:37:34 +03:00
|
|
|
#include "nsDataObj.h"
|
|
|
|
#include "nsIClipboardOwner.h"
|
1999-05-14 01:53:57 +04:00
|
|
|
#include "nsString.h"
|
2008-09-10 12:15:54 +04:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
1999-04-01 18:40:52 +04:00
|
|
|
#include "nsIFormatConverter.h"
|
1999-04-17 17:49:39 +04:00
|
|
|
#include "nsITransferable.h"
|
1999-08-25 12:35:06 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
1999-08-25 12:35:06 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
1999-09-05 00:04:26 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2006-05-02 10:20:16 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
1999-09-22 04:40:14 +04:00
|
|
|
#include "nsPrimitiveHelpers.h"
|
2001-01-23 04:09:58 +03:00
|
|
|
#include "nsImageClipboard.h"
|
1999-03-24 00:26:41 +03:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2002-01-08 04:31:25 +03:00
|
|
|
#include "nsNetUtil.h"
|
2008-09-10 12:15:54 +04:00
|
|
|
#include "nsEscape.h"
|
1999-05-07 23:55:45 +04:00
|
|
|
|
2011-08-16 23:30:44 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PRLogModuleInfo* gWin32ClipboardLog = nsnull;
|
|
|
|
#endif
|
2000-08-03 04:47:36 +04:00
|
|
|
|
2002-05-02 01:58:38 +04:00
|
|
|
// oddly, this isn't in the MSVC headers anywhere.
|
2008-08-30 01:26:56 +04:00
|
|
|
UINT nsClipboard::CF_HTML = ::RegisterClipboardFormatW(L"HTML Format");
|
2002-05-02 01:58:38 +04:00
|
|
|
|
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsClipboard constructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1999-03-26 18:43:48 +03:00
|
|
|
nsClipboard::nsClipboard() : nsBaseClipboard()
|
1999-03-23 18:37:34 +03:00
|
|
|
{
|
2011-08-16 23:30:44 +04:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!gWin32ClipboardLog) {
|
|
|
|
gWin32ClipboardLog = PR_NewLogModule("nsClipboard");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
mIgnoreEmptyNotification = false;
|
1999-03-26 18:43:48 +03:00
|
|
|
mWindow = nsnull;
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// nsClipboard destructor
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsClipboard::~nsClipboard()
|
|
|
|
{
|
1999-03-24 00:26:41 +03:00
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
//-------------------------------------------------------------------------
|
1999-09-05 00:04:26 +04:00
|
|
|
UINT nsClipboard::GetFormat(const char* aMimeStr)
|
1999-03-23 18:37:34 +03:00
|
|
|
{
|
2002-12-11 09:40:46 +03:00
|
|
|
UINT format;
|
1999-03-23 18:37:34 +03:00
|
|
|
|
2002-12-11 09:40:46 +03:00
|
|
|
if (strcmp(aMimeStr, kTextMime) == 0)
|
1999-03-26 18:43:48 +03:00
|
|
|
format = CF_TEXT;
|
2002-12-11 09:40:46 +03:00
|
|
|
else if (strcmp(aMimeStr, kUnicodeMime) == 0)
|
1999-03-26 18:43:48 +03:00
|
|
|
format = CF_UNICODETEXT;
|
2008-10-20 19:21:02 +04:00
|
|
|
else if (strcmp(aMimeStr, kJPEGImageMime) == 0 ||
|
|
|
|
strcmp(aMimeStr, kPNGImageMime) == 0)
|
1999-05-05 03:14:57 +04:00
|
|
|
format = CF_DIB;
|
2003-06-07 03:30:47 +04:00
|
|
|
else if (strcmp(aMimeStr, kFileMime) == 0 ||
|
|
|
|
strcmp(aMimeStr, kFilePromiseMime) == 0)
|
1999-05-05 03:14:57 +04:00
|
|
|
format = CF_HDROP;
|
2002-12-11 09:40:46 +03:00
|
|
|
else if (strcmp(aMimeStr, kNativeHTMLMime) == 0)
|
2002-05-07 23:45:58 +04:00
|
|
|
format = CF_HTML;
|
2000-05-03 02:39:08 +04:00
|
|
|
else
|
2008-08-30 01:26:56 +04:00
|
|
|
format = ::RegisterClipboardFormatW(NS_ConvertASCIItoUTF16(aMimeStr).get());
|
|
|
|
|
1999-03-26 18:43:48 +03:00
|
|
|
return format;
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2004-12-07 17:13:54 +03:00
|
|
|
nsresult nsClipboard::CreateNativeDataObject(nsITransferable * aTransferable, IDataObject ** aDataObj, nsIURI * uri)
|
1999-03-23 18:37:34 +03:00
|
|
|
{
|
1999-04-07 00:25:09 +04:00
|
|
|
if (nsnull == aTransferable) {
|
1999-03-23 18:37:34 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-05-05 03:14:57 +04:00
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
// Create our native DataObject that implements
|
|
|
|
// the OLE IDataObject interface
|
2004-12-07 17:13:54 +03:00
|
|
|
nsDataObj * dataObj = new nsDataObj(uri);
|
|
|
|
|
|
|
|
if (!dataObj)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
1999-05-05 03:14:57 +04:00
|
|
|
dataObj->AddRef();
|
|
|
|
|
2005-08-11 04:37:53 +04:00
|
|
|
// Now set it up with all the right data flavors & enums
|
1999-05-05 03:14:57 +04:00
|
|
|
nsresult res = SetupNativeDataObject(aTransferable, dataObj);
|
|
|
|
if (NS_OK == res) {
|
|
|
|
*aDataObj = dataObj;
|
|
|
|
} else {
|
|
|
|
delete dataObj;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsresult nsClipboard::SetupNativeDataObject(nsITransferable * aTransferable, IDataObject * aDataObj)
|
|
|
|
{
|
|
|
|
if (nsnull == aTransferable || nsnull == aDataObj) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
nsDataObj * dObj = static_cast<nsDataObj *>(aDataObj);
|
1999-03-23 18:37:34 +03:00
|
|
|
|
|
|
|
// Now give the Transferable to the DataObject
|
|
|
|
// for getting the data out of it
|
1999-05-05 03:14:57 +04:00
|
|
|
dObj->SetTransferable(aTransferable);
|
1999-04-07 00:25:09 +04:00
|
|
|
|
|
|
|
// Get the transferable list of data flavors
|
1999-08-25 12:35:06 +04:00
|
|
|
nsCOMPtr<nsISupportsArray> dfList;
|
|
|
|
aTransferable->FlavorsTransferableCanExport(getter_AddRefs(dfList));
|
1999-03-23 18:37:34 +03:00
|
|
|
|
1999-04-01 18:40:52 +04:00
|
|
|
// Walk through flavors that contain data and register them
|
|
|
|
// into the DataObj as supported flavors
|
1999-03-23 18:37:34 +03:00
|
|
|
PRUint32 i;
|
1999-08-25 12:35:06 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
dfList->Count(&cnt);
|
1999-05-13 08:56:04 +04:00
|
|
|
for (i=0;i<cnt;i++) {
|
1999-08-25 12:35:06 +04:00
|
|
|
nsCOMPtr<nsISupports> genericFlavor;
|
|
|
|
dfList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> currentFlavor ( do_QueryInterface(genericFlavor) );
|
1999-08-25 12:35:06 +04:00
|
|
|
if ( currentFlavor ) {
|
1999-09-05 00:04:26 +04:00
|
|
|
nsXPIDLCString flavorStr;
|
|
|
|
currentFlavor->ToString(getter_Copies(flavorStr));
|
1999-08-25 12:35:06 +04:00
|
|
|
UINT format = GetFormat(flavorStr);
|
1999-03-26 18:43:48 +03:00
|
|
|
|
2001-01-23 04:09:58 +03:00
|
|
|
// Now tell the native IDataObject about both our mime type and
|
|
|
|
// the native data format
|
1999-03-23 18:37:34 +03:00
|
|
|
FORMATETC fe;
|
1999-04-17 17:49:39 +04:00
|
|
|
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
|
1999-08-25 12:35:06 +04:00
|
|
|
dObj->AddDataFlavor(flavorStr, &fe);
|
2000-01-29 23:24:50 +03:00
|
|
|
|
2000-05-03 02:39:08 +04:00
|
|
|
// Do various things internal to the implementation, like map one
|
|
|
|
// flavor to another or add additional flavors based on what's required
|
|
|
|
// for the win32 impl.
|
2000-02-23 01:40:38 +03:00
|
|
|
if ( strcmp(flavorStr, kUnicodeMime) == 0 ) {
|
2000-05-03 02:39:08 +04:00
|
|
|
// if we find text/unicode, also advertise text/plain (which we will convert
|
|
|
|
// on our own in nsDataObj::GetText().
|
2001-01-23 04:09:58 +03:00
|
|
|
FORMATETC textFE;
|
|
|
|
SET_FORMATETC(textFE, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
|
|
|
|
dObj->AddDataFlavor(kTextMime, &textFE);
|
2000-05-03 02:39:08 +04:00
|
|
|
}
|
2001-02-21 02:27:57 +03:00
|
|
|
else if ( strcmp(flavorStr, kHTMLMime) == 0 ) {
|
|
|
|
// if we find text/html, also advertise win32's html flavor (which we will convert
|
|
|
|
// on our own in nsDataObj::GetText().
|
|
|
|
FORMATETC htmlFE;
|
2002-05-02 01:58:38 +04:00
|
|
|
SET_FORMATETC(htmlFE, CF_HTML, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
|
2001-02-21 02:27:57 +03:00
|
|
|
dObj->AddDataFlavor(kHTMLMime, &htmlFE);
|
|
|
|
}
|
2001-01-23 04:09:58 +03:00
|
|
|
else if ( strcmp(flavorStr, kURLMime) == 0 ) {
|
2000-05-03 02:39:08 +04:00
|
|
|
// if we're a url, in addition to also being text, we need to register
|
|
|
|
// the "file" flavors so that the win32 shell knows to create an internet
|
|
|
|
// shortcut when it sees one of these beasts.
|
2001-01-23 04:09:58 +03:00
|
|
|
FORMATETC shortcutFE;
|
2004-07-16 11:28:10 +04:00
|
|
|
SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
|
|
|
dObj->AddDataFlavor(kURLMime, &shortcutFE);
|
|
|
|
SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
2001-01-23 04:09:58 +03:00
|
|
|
dObj->AddDataFlavor(kURLMime, &shortcutFE);
|
|
|
|
SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_FILECONTENTS), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
|
|
|
dObj->AddDataFlavor(kURLMime, &shortcutFE);
|
2004-07-16 11:28:10 +04:00
|
|
|
SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_INETURLA), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
|
|
|
dObj->AddDataFlavor(kURLMime, &shortcutFE);
|
|
|
|
SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_INETURLW), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
2001-01-23 04:09:58 +03:00
|
|
|
dObj->AddDataFlavor(kURLMime, &shortcutFE);
|
2000-01-29 23:24:50 +03:00
|
|
|
}
|
2001-01-23 04:09:58 +03:00
|
|
|
else if ( strcmp(flavorStr, kPNGImageMime) == 0 || strcmp(flavorStr, kJPEGImageMime) == 0 ||
|
2002-04-23 18:24:48 +04:00
|
|
|
strcmp(flavorStr, kGIFImageMime) == 0 || strcmp(flavorStr, kNativeImageMime) == 0 ) {
|
2001-01-23 04:09:58 +03:00
|
|
|
// if we're an image, register the native bitmap flavor
|
|
|
|
FORMATETC imageFE;
|
|
|
|
SET_FORMATETC(imageFE, CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
|
|
|
dObj->AddDataFlavor(flavorStr, &imageFE);
|
|
|
|
}
|
2003-06-07 03:30:47 +04:00
|
|
|
else if ( strcmp(flavorStr, kFilePromiseMime) == 0 ) {
|
|
|
|
// if we're a file promise flavor, also register the
|
|
|
|
// CFSTR_PREFERREDDROPEFFECT format. The data object
|
|
|
|
// returns a value of DROPEFFECTS_MOVE to the drop target
|
|
|
|
// when it asks for the value of this format. This causes
|
|
|
|
// the file to be moved from the temporary location instead
|
|
|
|
// of being copied. The right thing to do here is to call
|
|
|
|
// SetData() on the data object and set the value of this format
|
|
|
|
// to DROPEFFECTS_MOVE on this particular data object. But,
|
|
|
|
// since all the other clipboard formats follow the model of setting
|
|
|
|
// data on the data object only when the drop object calls GetData(),
|
|
|
|
// I am leaving this format's value hard coded in the data object.
|
|
|
|
// We can change this if other consumers of this format get added to this
|
|
|
|
// codebase and they need different values.
|
|
|
|
FORMATETC shortcutFE;
|
|
|
|
SET_FORMATETC(shortcutFE, ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT), 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
|
|
|
|
dObj->AddDataFlavor(kFilePromiseMime, &shortcutFE);
|
|
|
|
}
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
}
|
1999-04-01 18:40:52 +04:00
|
|
|
|
1999-04-07 00:25:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2000-04-14 06:52:58 +04:00
|
|
|
NS_IMETHODIMP nsClipboard::SetNativeClipboardData ( PRInt32 aWhichClipboard )
|
1999-04-07 00:25:09 +04:00
|
|
|
{
|
2000-04-14 06:52:58 +04:00
|
|
|
if ( aWhichClipboard != kGlobalClipboard )
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
mIgnoreEmptyNotification = true;
|
1999-04-07 00:25:09 +04:00
|
|
|
|
|
|
|
// make sure we have a good transferable
|
|
|
|
if (nsnull == mTransferable) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDataObject * dataObj;
|
2004-12-07 17:13:54 +03:00
|
|
|
if ( NS_SUCCEEDED(CreateNativeDataObject(mTransferable, &dataObj, NULL)) ) { // this add refs dataObj
|
2000-08-19 23:30:52 +04:00
|
|
|
::OleSetClipboard(dataObj);
|
|
|
|
dataObj->Release();
|
2006-03-24 17:52:24 +03:00
|
|
|
} else {
|
|
|
|
// Clear the native clipboard
|
|
|
|
::OleSetClipboard(NULL);
|
1999-04-07 00:25:09 +04:00
|
|
|
}
|
1999-03-23 18:37:34 +03:00
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
mIgnoreEmptyNotification = false;
|
1999-03-24 00:26:41 +03:00
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-07 00:25:09 +04:00
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
//-------------------------------------------------------------------------
|
1999-04-17 17:49:39 +04:00
|
|
|
nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void ** aData, PRUint32 * aLen)
|
1999-04-07 00:25:09 +04:00
|
|
|
{
|
1999-12-08 01:45:01 +03:00
|
|
|
// Allocate a new memory buffer and copy the data from global memory.
|
2002-05-07 23:45:58 +04:00
|
|
|
// Recall that win98 allocates to nearest DWORD boundary. As a safety
|
|
|
|
// precaution, allocate an extra 2 bytes (but don't report them!) and
|
|
|
|
// null them out to ensure that all of our strlen calls will succeed.
|
1999-04-07 00:25:09 +04:00
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
|
|
|
if (aHGBL != NULL) {
|
2005-08-11 04:37:53 +04:00
|
|
|
LPSTR lpStr = (LPSTR) GlobalLock(aHGBL);
|
|
|
|
DWORD allocSize = GlobalSize(aHGBL);
|
2007-07-08 11:08:04 +04:00
|
|
|
char* data = static_cast<char*>(nsMemory::Alloc(allocSize + sizeof(PRUnichar)));
|
1999-12-08 01:45:01 +03:00
|
|
|
if ( data ) {
|
2002-05-07 23:45:58 +04:00
|
|
|
memcpy ( data, lpStr, allocSize );
|
|
|
|
data[allocSize] = data[allocSize + 1] = '\0'; // null terminate for safety
|
|
|
|
|
2005-08-11 04:37:53 +04:00
|
|
|
GlobalUnlock(aHGBL);
|
1999-12-08 01:45:01 +03:00
|
|
|
*aData = data;
|
|
|
|
*aLen = allocSize;
|
2002-05-07 23:45:58 +04:00
|
|
|
|
1999-12-08 01:45:01 +03:00
|
|
|
result = NS_OK;
|
1999-04-07 00:25:09 +04:00
|
|
|
}
|
1999-12-08 01:45:01 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-04-23 18:38:27 +04:00
|
|
|
// We really shouldn't ever get here
|
|
|
|
// but just in case
|
1999-04-07 00:25:09 +04:00
|
|
|
*aData = nsnull;
|
|
|
|
*aLen = 0;
|
|
|
|
LPVOID lpMsgBuf;
|
|
|
|
|
2008-08-30 01:26:56 +04:00
|
|
|
FormatMessageW(
|
1999-04-07 00:25:09 +04:00
|
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
2008-08-30 01:26:56 +04:00
|
|
|
(LPWSTR) &lpMsgBuf,
|
1999-04-07 00:25:09 +04:00
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
// Display the string.
|
2008-08-30 01:26:56 +04:00
|
|
|
MessageBoxW( NULL, (LPCWSTR) lpMsgBuf, L"GetLastError", MB_OK|MB_ICONINFORMATION );
|
1999-04-07 00:25:09 +04:00
|
|
|
|
|
|
|
// Free the buffer.
|
|
|
|
LocalFree( lpMsgBuf );
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
1999-04-23 18:38:27 +04:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2008-10-14 18:06:35 +04:00
|
|
|
nsresult nsClipboard::GetNativeDataOffClipboard(nsIWidget * aWindow, UINT /*aIndex*/, UINT aFormat, void ** aData, PRUint32 * aLen)
|
1999-03-23 18:37:34 +03:00
|
|
|
{
|
|
|
|
HGLOBAL hglb;
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
|
|
|
|
1999-03-24 00:26:41 +03:00
|
|
|
HWND nativeWin = nsnull;//(HWND)aWindow->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (::OpenClipboard(nativeWin)) {
|
2008-10-14 18:06:35 +04:00
|
|
|
hglb = ::GetClipboardData(aFormat);
|
1999-04-07 00:25:09 +04:00
|
|
|
result = GetGlobalData(hglb, aData, aLen);
|
1999-03-23 18:37:34 +03:00
|
|
|
::CloseClipboard();
|
|
|
|
}
|
1999-04-07 00:25:09 +04:00
|
|
|
return result;
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
1999-07-09 23:39:22 +04:00
|
|
|
static void DisplayErrCode(HRESULT hres)
|
|
|
|
{
|
2001-03-08 08:12:30 +03:00
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_pinkerton)
|
1999-07-09 23:39:22 +04:00
|
|
|
if (hres == E_INVALIDARG) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("E_INVALIDARG\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == E_UNEXPECTED) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("E_UNEXPECTED\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == E_OUTOFMEMORY) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("E_OUTOFMEMORY\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == DV_E_LINDEX ) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_LINDEX\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == DV_E_FORMATETC) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_FORMATETC\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == DV_E_TYMED) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_TYMED\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == DV_E_DVASPECT) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_DVASPECT\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == OLE_E_NOTRUNNING) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("OLE_E_NOTRUNNING\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == STG_E_MEDIUMFULL) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("STG_E_MEDIUMFULL\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == DV_E_CLIPFORMAT) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_CLIPFORMAT\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else
|
|
|
|
if (hres == S_OK) {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("S_OK\n"));
|
1999-07-09 23:39:22 +04:00
|
|
|
} else {
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS,
|
|
|
|
("****** DisplayErrCode 0x%X\n", hres));
|
1999-07-09 23:39:22 +04:00
|
|
|
}
|
|
|
|
#endif
|
2001-03-08 08:12:30 +03:00
|
|
|
}
|
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
//-------------------------------------------------------------------------
|
1999-05-05 03:14:57 +04:00
|
|
|
static HRESULT FillSTGMedium(IDataObject * aDataObject, UINT aFormat, LPFORMATETC pFE, LPSTGMEDIUM pSTM, DWORD aTymed)
|
1999-04-07 00:25:09 +04:00
|
|
|
{
|
1999-05-05 03:14:57 +04:00
|
|
|
SET_FORMATETC(*pFE, aFormat, 0, DVASPECT_CONTENT, -1, aTymed);
|
1999-04-07 00:25:09 +04:00
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
// Starting by querying for the data to see if we can get it as from global memory
|
1999-05-05 03:14:57 +04:00
|
|
|
HRESULT hres = S_FALSE;
|
1999-07-09 23:39:22 +04:00
|
|
|
hres = aDataObject->QueryGetData(pFE);
|
|
|
|
DisplayErrCode(hres);
|
|
|
|
if (S_OK == hres) {
|
1999-05-05 03:14:57 +04:00
|
|
|
hres = aDataObject->GetData(pFE, pSTM);
|
1999-07-09 23:39:22 +04:00
|
|
|
DisplayErrCode(hres);
|
|
|
|
}
|
|
|
|
return hres;
|
|
|
|
}
|
1999-04-07 00:25:09 +04:00
|
|
|
|
1999-05-05 03:14:57 +04:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2008-10-20 19:21:02 +04:00
|
|
|
// If aFormat is CF_DIB, aMIMEImageFormat must be a type for which we have
|
|
|
|
// an image encoder (e.g. image/png).
|
|
|
|
// For other values of aFormat, it is OK to pass null for aMIMEImageFormat.
|
|
|
|
nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aIndex, UINT aFormat, const char * aMIMEImageFormat, void ** aData, PRUint32 * aLen)
|
1999-05-05 03:14:57 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
2000-04-26 05:04:13 +04:00
|
|
|
*aData = nsnull;
|
|
|
|
*aLen = 0;
|
1999-05-05 03:14:57 +04:00
|
|
|
|
2000-04-26 05:04:13 +04:00
|
|
|
if ( !aDataObject )
|
1999-05-05 03:14:57 +04:00
|
|
|
return result;
|
|
|
|
|
2008-10-14 18:06:35 +04:00
|
|
|
UINT format = aFormat;
|
1999-05-05 03:14:57 +04:00
|
|
|
HRESULT hres = S_FALSE;
|
|
|
|
|
|
|
|
// XXX at the moment we only support global memory transfers
|
|
|
|
// It is here where we will add support for native images
|
|
|
|
// and IStream
|
|
|
|
FORMATETC fe;
|
|
|
|
STGMEDIUM stm;
|
|
|
|
hres = FillSTGMedium(aDataObject, format, &fe, &stm, TYMED_HGLOBAL);
|
|
|
|
|
1999-07-09 23:39:22 +04:00
|
|
|
// Currently this is only handling TYMED_HGLOBAL data
|
|
|
|
// For Text, Dibs, Files, and generic data (like HTML)
|
1999-05-05 03:14:57 +04:00
|
|
|
if (S_OK == hres) {
|
2004-07-16 11:28:10 +04:00
|
|
|
static CLIPFORMAT fileDescriptorFlavorA = ::RegisterClipboardFormat( CFSTR_FILEDESCRIPTORA );
|
|
|
|
static CLIPFORMAT fileDescriptorFlavorW = ::RegisterClipboardFormat( CFSTR_FILEDESCRIPTORW );
|
2001-12-18 01:51:39 +03:00
|
|
|
static CLIPFORMAT fileFlavor = ::RegisterClipboardFormat( CFSTR_FILECONTENTS );
|
2011-09-30 17:14:44 +04:00
|
|
|
static CLIPFORMAT preferredDropEffect = ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT);
|
|
|
|
|
1999-05-05 03:14:57 +04:00
|
|
|
switch (stm.tymed) {
|
2000-05-03 02:39:08 +04:00
|
|
|
case TYMED_HGLOBAL:
|
1999-05-05 03:14:57 +04:00
|
|
|
{
|
|
|
|
switch (fe.cfFormat) {
|
1999-11-18 05:40:49 +03:00
|
|
|
case CF_TEXT:
|
1999-05-05 03:14:57 +04:00
|
|
|
{
|
1999-12-08 01:45:01 +03:00
|
|
|
// Get the data out of the global data handle. The size we return
|
|
|
|
// should not include the null because the other platforms don't
|
|
|
|
// use nulls, so just return the length we get back from strlen(),
|
|
|
|
// since we know CF_TEXT is null terminated. Recall that GetGlobalData()
|
|
|
|
// returns the size of the allocated buffer, not the size of the data
|
|
|
|
// (on 98, these are not the same) so we can't use that.
|
|
|
|
PRUint32 allocLen = 0;
|
|
|
|
if ( NS_SUCCEEDED(GetGlobalData(stm.hGlobal, aData, &allocLen)) ) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*aLen = strlen ( reinterpret_cast<char*>(*aData) );
|
1999-12-08 01:45:01 +03:00
|
|
|
result = NS_OK;
|
1999-05-05 03:14:57 +04:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2000-05-03 02:39:08 +04:00
|
|
|
case CF_UNICODETEXT:
|
1999-11-18 05:40:49 +03:00
|
|
|
{
|
1999-12-08 01:45:01 +03:00
|
|
|
// Get the data out of the global data handle. The size we return
|
|
|
|
// should not include the null because the other platforms don't
|
|
|
|
// use nulls, so just return the length we get back from strlen(),
|
|
|
|
// since we know CF_UNICODETEXT is null terminated. Recall that GetGlobalData()
|
|
|
|
// returns the size of the allocated buffer, not the size of the data
|
|
|
|
// (on 98, these are not the same) so we can't use that.
|
|
|
|
PRUint32 allocLen = 0;
|
|
|
|
if ( NS_SUCCEEDED(GetGlobalData(stm.hGlobal, aData, &allocLen)) ) {
|
2012-04-04 04:22:42 +04:00
|
|
|
*aLen = nsCRT::strlen(reinterpret_cast<PRUnichar*>(*aData)) * 2;
|
1999-12-08 01:45:01 +03:00
|
|
|
result = NS_OK;
|
1999-11-18 05:40:49 +03:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
1999-05-05 03:14:57 +04:00
|
|
|
case CF_DIB :
|
2008-10-20 19:21:02 +04:00
|
|
|
if (aMIMEImageFormat)
|
1999-05-05 03:14:57 +04:00
|
|
|
{
|
2006-09-13 23:52:44 +04:00
|
|
|
PRUint32 allocLen = 0;
|
|
|
|
unsigned char * clipboardData;
|
2008-10-20 19:21:02 +04:00
|
|
|
if (NS_SUCCEEDED(GetGlobalData(stm.hGlobal, (void **)&clipboardData, &allocLen)))
|
2006-09-13 23:52:44 +04:00
|
|
|
{
|
|
|
|
nsImageFromClipboard converter;
|
|
|
|
nsIInputStream * inputStream;
|
2008-10-20 19:21:02 +04:00
|
|
|
converter.GetEncodedImageStream(clipboardData, aMIMEImageFormat, &inputStream); // addrefs for us, don't release
|
2006-09-13 23:52:44 +04:00
|
|
|
if ( inputStream ) {
|
|
|
|
*aData = inputStream;
|
|
|
|
*aLen = sizeof(nsIInputStream*);
|
|
|
|
result = NS_OK;
|
|
|
|
}
|
1999-07-09 23:39:22 +04:00
|
|
|
}
|
1999-05-05 03:14:57 +04:00
|
|
|
} break;
|
|
|
|
|
1999-05-07 23:55:45 +04:00
|
|
|
case CF_HDROP :
|
|
|
|
{
|
2000-04-26 05:04:13 +04:00
|
|
|
// in the case of a file drop, multiple files are stashed within a
|
|
|
|
// single data object. In order to match mozilla's D&D apis, we
|
|
|
|
// just pull out the file at the requested index, pretending as
|
|
|
|
// if there really are multiple drag items.
|
2005-08-11 04:37:53 +04:00
|
|
|
HDROP dropFiles = (HDROP) GlobalLock(stm.hGlobal);
|
2000-04-26 05:04:13 +04:00
|
|
|
|
2006-05-02 10:20:16 +04:00
|
|
|
UINT numFiles = ::DragQueryFileW(dropFiles, 0xFFFFFFFF, NULL, 0);
|
2000-04-26 05:04:13 +04:00
|
|
|
NS_ASSERTION ( numFiles > 0, "File drop flavor, but no files...hmmmm" );
|
|
|
|
NS_ASSERTION ( aIndex < numFiles, "Asked for a file index out of range of list" );
|
1999-05-07 23:55:45 +04:00
|
|
|
if (numFiles > 0) {
|
2006-05-02 10:20:16 +04:00
|
|
|
UINT fileNameLen = ::DragQueryFileW(dropFiles, aIndex, nsnull, 0);
|
2007-07-08 11:08:04 +04:00
|
|
|
PRUnichar* buffer = reinterpret_cast<PRUnichar*>(nsMemory::Alloc((fileNameLen + 1) * sizeof(PRUnichar)));
|
2000-04-26 05:04:13 +04:00
|
|
|
if ( buffer ) {
|
2006-05-02 10:20:16 +04:00
|
|
|
::DragQueryFileW(dropFiles, aIndex, buffer, fileNameLen + 1);
|
2000-04-26 05:04:13 +04:00
|
|
|
*aData = buffer;
|
2006-05-02 10:20:16 +04:00
|
|
|
*aLen = fileNameLen * sizeof(PRUnichar);
|
2000-04-26 05:04:13 +04:00
|
|
|
result = NS_OK;
|
1999-05-07 23:55:45 +04:00
|
|
|
}
|
2000-04-26 05:04:13 +04:00
|
|
|
else
|
|
|
|
result = NS_ERROR_OUT_OF_MEMORY;
|
1999-05-07 23:55:45 +04:00
|
|
|
}
|
2005-08-11 04:37:53 +04:00
|
|
|
GlobalUnlock (stm.hGlobal) ;
|
2000-04-26 05:04:13 +04:00
|
|
|
|
1999-05-07 23:55:45 +04:00
|
|
|
} break;
|
|
|
|
|
1999-07-09 23:39:22 +04:00
|
|
|
default: {
|
2004-07-16 11:28:10 +04:00
|
|
|
if ( fe.cfFormat == fileDescriptorFlavorA || fe.cfFormat == fileDescriptorFlavorW || fe.cfFormat == fileFlavor ) {
|
2000-05-03 02:39:08 +04:00
|
|
|
NS_WARNING ( "Mozilla doesn't yet understand how to read this type of file flavor" );
|
2000-08-17 08:19:14 +04:00
|
|
|
}
|
2005-08-11 04:37:53 +04:00
|
|
|
else
|
|
|
|
{
|
2000-08-17 08:19:14 +04:00
|
|
|
// Get the data out of the global data handle. The size we return
|
|
|
|
// should not include the null because the other platforms don't
|
|
|
|
// use nulls, so just return the length we get back from strlen(),
|
|
|
|
// since we know CF_UNICODETEXT is null terminated. Recall that GetGlobalData()
|
|
|
|
// returns the size of the allocated buffer, not the size of the data
|
|
|
|
// (on 98, these are not the same) so we can't use that.
|
|
|
|
//
|
|
|
|
// NOTE: we are assuming that anything that falls into this default case
|
|
|
|
// is unicode. As we start to get more kinds of binary data, this
|
|
|
|
// may become an incorrect assumption. Stay tuned.
|
|
|
|
PRUint32 allocLen = 0;
|
|
|
|
if ( NS_SUCCEEDED(GetGlobalData(stm.hGlobal, aData, &allocLen)) ) {
|
2002-05-03 18:19:11 +04:00
|
|
|
if ( fe.cfFormat == CF_HTML ) {
|
|
|
|
// CF_HTML is actually UTF8, not unicode, so disregard the assumption
|
2002-05-07 23:45:58 +04:00
|
|
|
// above. We have to check the header for the actual length, and we'll
|
|
|
|
// do that in FindPlatformHTML(). For now, return the allocLen. This
|
|
|
|
// case is mostly to ensure we don't try to call strlen on the buffer.
|
|
|
|
*aLen = allocLen;
|
2011-09-30 17:14:44 +04:00
|
|
|
} else if (fe.cfFormat == preferredDropEffect) {
|
|
|
|
// As per the MSDN doc entitled: "Shell Clipboard Formats"
|
|
|
|
// CFSTR_PREFERREDDROPEFFECT should return a DWORD
|
|
|
|
// Reference: http://msdn.microsoft.com/en-us/library/bb776902(v=vs.85).aspx
|
|
|
|
NS_ASSERTION(allocLen == sizeof(DWORD),
|
|
|
|
"CFSTR_PREFERREDDROPEFFECT should return a DWORD");
|
|
|
|
*aLen = allocLen;
|
|
|
|
} else {
|
2012-04-04 04:22:42 +04:00
|
|
|
*aLen = nsCRT::strlen(reinterpret_cast<PRUnichar*>(*aData)) *
|
2011-09-30 17:14:44 +04:00
|
|
|
sizeof(PRUnichar);
|
2002-05-03 18:19:11 +04:00
|
|
|
}
|
2000-08-17 08:19:14 +04:00
|
|
|
result = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2000-05-03 02:39:08 +04:00
|
|
|
} break;
|
1999-05-05 03:14:57 +04:00
|
|
|
} // switch
|
|
|
|
} break;
|
|
|
|
|
1999-07-09 23:39:22 +04:00
|
|
|
case TYMED_GDI:
|
|
|
|
{
|
2001-06-20 09:48:45 +04:00
|
|
|
#ifdef DEBUG
|
2011-08-16 23:30:44 +04:00
|
|
|
PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS,
|
|
|
|
("*********************** TYMED_GDI\n"));
|
2001-06-20 09:48:45 +04:00
|
|
|
#endif
|
1999-07-09 23:39:22 +04:00
|
|
|
} break;
|
|
|
|
|
1999-05-05 03:14:57 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
} //switch
|
2000-05-09 03:26:06 +04:00
|
|
|
|
|
|
|
ReleaseStgMedium(&stm);
|
1999-04-07 00:25:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
//-------------------------------------------------------------------------
|
1999-04-17 17:49:39 +04:00
|
|
|
nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
|
2000-04-26 05:04:13 +04:00
|
|
|
UINT anIndex,
|
1999-04-17 17:49:39 +04:00
|
|
|
nsIWidget * aWindow,
|
|
|
|
nsITransferable * aTransferable)
|
1999-03-23 18:37:34 +03:00
|
|
|
{
|
|
|
|
// make sure we have a good transferable
|
1999-08-25 12:35:06 +04:00
|
|
|
if ( !aTransferable )
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-04-07 00:25:09 +04:00
|
|
|
|
1999-08-25 12:35:06 +04:00
|
|
|
nsresult res = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// get flavor list that includes all flavors that can be written (including ones
|
|
|
|
// obtained through conversion)
|
|
|
|
nsCOMPtr<nsISupportsArray> flavorList;
|
|
|
|
res = aTransferable->FlavorsTransferableCanImport ( getter_AddRefs(flavorList) );
|
|
|
|
if ( NS_FAILED(res) )
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-03-23 18:37:34 +03:00
|
|
|
|
|
|
|
// Walk through flavors and see which flavor is on the clipboard them on the native clipboard,
|
|
|
|
PRUint32 i;
|
1999-08-25 12:35:06 +04:00
|
|
|
PRUint32 cnt;
|
|
|
|
flavorList->Count(&cnt);
|
1999-05-13 08:56:04 +04:00
|
|
|
for (i=0;i<cnt;i++) {
|
1999-08-25 12:35:06 +04:00
|
|
|
nsCOMPtr<nsISupports> genericFlavor;
|
|
|
|
flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> currentFlavor ( do_QueryInterface(genericFlavor) );
|
1999-08-25 12:35:06 +04:00
|
|
|
if ( currentFlavor ) {
|
1999-09-05 00:04:26 +04:00
|
|
|
nsXPIDLCString flavorStr;
|
|
|
|
currentFlavor->ToString(getter_Copies(flavorStr));
|
2008-10-14 18:06:35 +04:00
|
|
|
UINT format = GetFormat(flavorStr);
|
1999-03-23 18:37:34 +03:00
|
|
|
|
2000-08-03 04:47:36 +04:00
|
|
|
// Try to get the data using the desired flavor. This might fail, but all is
|
|
|
|
// not lost.
|
|
|
|
void* data = nsnull;
|
|
|
|
PRUint32 dataLen = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dataFound = false;
|
1999-04-17 17:49:39 +04:00
|
|
|
if (nsnull != aDataObject) {
|
2008-10-20 19:21:02 +04:00
|
|
|
if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aDataObject, anIndex, format, flavorStr, &data, &dataLen)) )
|
2011-10-02 06:16:19 +04:00
|
|
|
dataFound = true;
|
1999-12-09 22:50:50 +03:00
|
|
|
}
|
|
|
|
else if (nsnull != aWindow) {
|
2008-10-14 18:06:35 +04:00
|
|
|
if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aWindow, anIndex, format, &data, &dataLen)) )
|
2011-10-02 06:16:19 +04:00
|
|
|
dataFound = true;
|
1999-08-25 12:35:06 +04:00
|
|
|
}
|
2000-08-03 04:47:36 +04:00
|
|
|
|
|
|
|
// This is our second chance to try to find some data, having not found it
|
|
|
|
// when directly asking for the flavor. Let's try digging around in other
|
|
|
|
// flavors to help satisfy our craving for data.
|
2000-02-02 01:26:21 +03:00
|
|
|
if ( !dataFound ) {
|
2000-08-03 04:47:36 +04:00
|
|
|
if ( strcmp(flavorStr, kUnicodeMime) == 0 )
|
|
|
|
dataFound = FindUnicodeFromPlainText ( aDataObject, anIndex, &data, &dataLen );
|
2007-11-17 16:22:13 +03:00
|
|
|
else if ( strcmp(flavorStr, kURLMime) == 0 ) {
|
|
|
|
// drags from other windows apps expose the native
|
|
|
|
// CFSTR_INETURL{A,W} flavor
|
|
|
|
dataFound = FindURLFromNativeURL ( aDataObject, anIndex, &data, &dataLen );
|
|
|
|
if ( !dataFound )
|
|
|
|
dataFound = FindURLFromLocalFile ( aDataObject, anIndex, &data, &dataLen );
|
|
|
|
}
|
2000-02-02 01:26:21 +03:00
|
|
|
} // if we try one last ditch effort to find our data
|
|
|
|
|
2000-08-03 04:47:36 +04:00
|
|
|
// Hopefully by this point we've found it and can go about our business
|
2000-02-02 01:26:21 +03:00
|
|
|
if ( dataFound ) {
|
1999-12-09 22:50:50 +03:00
|
|
|
nsCOMPtr<nsISupports> genericDataWrapper;
|
2006-05-02 10:20:16 +04:00
|
|
|
if ( strcmp(flavorStr, kFileMime) == 0 ) {
|
|
|
|
// we have a file path in |data|. Create an nsLocalFile object.
|
2007-07-08 11:08:04 +04:00
|
|
|
nsDependentString filepath(reinterpret_cast<PRUnichar*>(data));
|
2006-05-02 10:20:16 +04:00
|
|
|
nsCOMPtr<nsILocalFile> file;
|
2011-10-02 06:16:19 +04:00
|
|
|
if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, false, getter_AddRefs(file))) )
|
2006-05-02 10:20:16 +04:00
|
|
|
genericDataWrapper = do_QueryInterface(file);
|
2006-09-13 23:52:44 +04:00
|
|
|
nsMemory::Free(data);
|
2006-05-02 10:20:16 +04:00
|
|
|
}
|
2002-05-07 23:45:58 +04:00
|
|
|
else if ( strcmp(flavorStr, kNativeHTMLMime) == 0) {
|
|
|
|
// the editor folks want CF_HTML exactly as it's on the clipboard, no conversions,
|
|
|
|
// no fancy stuff. Pull it off the clipboard, stuff it into a wrapper and hand
|
|
|
|
// it back to them.
|
|
|
|
if ( FindPlatformHTML(aDataObject, anIndex, &data, &dataLen) )
|
|
|
|
nsPrimitiveHelpers::CreatePrimitiveForData ( flavorStr, data, dataLen, getter_AddRefs(genericDataWrapper) );
|
|
|
|
else
|
2006-09-13 23:52:44 +04:00
|
|
|
{
|
|
|
|
nsMemory::Free(data);
|
2002-05-07 23:45:58 +04:00
|
|
|
continue; // something wrong with this flavor, keep looking for other data
|
2006-09-13 23:52:44 +04:00
|
|
|
}
|
|
|
|
nsMemory::Free(data);
|
|
|
|
}
|
2008-10-20 19:21:02 +04:00
|
|
|
else if ( strcmp(flavorStr, kJPEGImageMime) == 0 ||
|
|
|
|
strcmp(flavorStr, kPNGImageMime) == 0) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIInputStream * imageStream = reinterpret_cast<nsIInputStream*>(data);
|
2006-09-13 23:52:44 +04:00
|
|
|
genericDataWrapper = do_QueryInterface(imageStream);
|
|
|
|
NS_IF_RELEASE(imageStream);
|
2002-05-02 01:58:38 +04:00
|
|
|
}
|
2002-05-07 23:45:58 +04:00
|
|
|
else {
|
2000-04-26 05:04:13 +04:00
|
|
|
// we probably have some form of text. The DOM only wants LF, so convert from Win32 line
|
|
|
|
// endings to DOM line endings.
|
2007-07-08 11:08:04 +04:00
|
|
|
PRInt32 signedLen = static_cast<PRInt32>(dataLen);
|
2000-04-26 05:04:13 +04:00
|
|
|
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks ( flavorStr, &data, &signedLen );
|
|
|
|
dataLen = signedLen;
|
|
|
|
|
|
|
|
nsPrimitiveHelpers::CreatePrimitiveForData ( flavorStr, data, dataLen, getter_AddRefs(genericDataWrapper) );
|
2006-09-13 23:52:44 +04:00
|
|
|
nsMemory::Free(data);
|
2000-04-26 05:04:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION ( genericDataWrapper, "About to put null data into the transferable" );
|
1999-12-09 22:50:50 +03:00
|
|
|
aTransferable->SetTransferData(flavorStr, genericDataWrapper, dataLen);
|
2000-02-02 01:26:21 +03:00
|
|
|
res = NS_OK;
|
2006-05-02 10:20:16 +04:00
|
|
|
|
2000-04-26 05:04:13 +04:00
|
|
|
// we found one, get out of the loop
|
1999-12-03 02:18:23 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
1999-12-03 02:18:23 +03:00
|
|
|
} // foreach flavor
|
|
|
|
|
1999-04-17 17:49:39 +04:00
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-08-03 04:47:36 +04:00
|
|
|
|
2002-05-07 23:45:58 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// FindPlatformHTML
|
|
|
|
//
|
|
|
|
// Someone asked for the OS CF_HTML flavor. We give it back to them exactly as-is.
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-05-07 23:45:58 +04:00
|
|
|
nsClipboard :: FindPlatformHTML ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen )
|
|
|
|
{
|
2011-09-21 21:22:53 +04:00
|
|
|
// Reference: MSDN doc entitled "HTML Clipboard Format"
|
|
|
|
// http://msdn.microsoft.com/en-us/library/aa767917(VS.85).aspx#unknown_854
|
|
|
|
// CF_HTML is UTF8, not unicode. We also can't rely on it being null-terminated
|
|
|
|
// so we have to check the CF_HTML header for the correct length.
|
|
|
|
// The length we return is the bytecount from the beginning of the selected data to the end
|
|
|
|
// of the selected data, without the null termination. Because it's UTF8, we're guaranteed
|
|
|
|
// the header is ASCII.
|
|
|
|
|
|
|
|
if (!outData || !*outData) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2011-09-21 21:22:53 +04:00
|
|
|
}
|
2002-05-07 23:45:58 +04:00
|
|
|
|
2012-01-13 18:37:33 +04:00
|
|
|
char version[8] = { 0 };
|
2011-09-21 21:22:53 +04:00
|
|
|
PRInt32 startOfData = 0;
|
|
|
|
PRInt32 endOfData = 0;
|
2012-01-13 18:37:33 +04:00
|
|
|
int numFound = sscanf((char*)*outData, "Version:%7s\nStartHTML:%d\nEndHTML:%d",
|
|
|
|
version, &startOfData, &endOfData);
|
2011-09-21 21:22:53 +04:00
|
|
|
|
|
|
|
if (numFound != 3 || startOfData < -1 || endOfData < -1) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2002-05-07 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
2011-09-21 21:22:53 +04:00
|
|
|
// Fixup the start and end markers if they have no context (set to -1)
|
|
|
|
if (startOfData == -1) {
|
|
|
|
startOfData = 0;
|
|
|
|
}
|
|
|
|
if (endOfData == -1) {
|
|
|
|
endOfData = *outDataLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we were passed sane values within our buffer size.
|
|
|
|
if (!endOfData || startOfData >= endOfData ||
|
|
|
|
endOfData > *outDataLen) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2011-09-21 21:22:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We want to return the buffer not offset by startOfData because it will be
|
|
|
|
// parsed out later (probably by nsHTMLEditor::ParseCFHTML) when it is still
|
|
|
|
// in CF_HTML format.
|
|
|
|
*outDataLen = endOfData;
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2002-05-07 23:45:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-03 04:47:36 +04:00
|
|
|
//
|
2007-11-17 16:22:13 +03:00
|
|
|
// FindUnicodeFromPlainText
|
2000-08-03 04:47:36 +04:00
|
|
|
//
|
|
|
|
// we are looking for text/unicode and we failed to find it on the clipboard first,
|
|
|
|
// try again with text/plain. If that is present, convert it to unicode.
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2000-08-03 04:47:36 +04:00
|
|
|
nsClipboard :: FindUnicodeFromPlainText ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen )
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dataFound = false;
|
2000-08-03 04:47:36 +04:00
|
|
|
|
|
|
|
// we are looking for text/unicode and we failed to find it on the clipboard first,
|
|
|
|
// try again with text/plain. If that is present, convert it to unicode.
|
2008-10-20 19:21:02 +04:00
|
|
|
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kTextMime), nsnull, outData, outDataLen);
|
2000-08-03 04:47:36 +04:00
|
|
|
if ( NS_SUCCEEDED(loadResult) && *outData ) {
|
2007-07-08 11:08:04 +04:00
|
|
|
const char* castedText = reinterpret_cast<char*>(*outData);
|
2000-08-03 04:47:36 +04:00
|
|
|
PRUnichar* convertedText = nsnull;
|
|
|
|
PRInt32 convertedTextLen = 0;
|
|
|
|
nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode ( castedText, *outDataLen,
|
|
|
|
&convertedText, &convertedTextLen );
|
|
|
|
if ( convertedText ) {
|
|
|
|
// out with the old, in with the new
|
|
|
|
nsMemory::Free(*outData);
|
|
|
|
*outData = convertedText;
|
|
|
|
*outDataLen = convertedTextLen * sizeof(PRUnichar);
|
2011-10-02 06:16:19 +04:00
|
|
|
dataFound = true;
|
2000-08-03 04:47:36 +04:00
|
|
|
}
|
|
|
|
} // if plain text data on clipboard
|
|
|
|
|
|
|
|
return dataFound;
|
|
|
|
|
|
|
|
} // FindUnicodeFromPlainText
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// FindURLFromLocalFile
|
|
|
|
//
|
|
|
|
// we are looking for a URL and couldn't find it, try again with looking for
|
|
|
|
// a local file. If we have one, it may either be a normal file or an internet shortcut.
|
|
|
|
// In both cases, however, we can get a URL (it will be a file:// url in the
|
|
|
|
// local file case).
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2000-08-03 04:47:36 +04:00
|
|
|
nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen )
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dataFound = false;
|
2000-08-03 04:47:36 +04:00
|
|
|
|
2008-10-20 19:21:02 +04:00
|
|
|
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kFileMime), nsnull, outData, outDataLen);
|
2000-08-03 04:47:36 +04:00
|
|
|
if ( NS_SUCCEEDED(loadResult) && *outData ) {
|
2004-07-16 00:21:44 +04:00
|
|
|
// we have a file path in |data|. Is it an internet shortcut or a normal file?
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsDependentString filepath(static_cast<PRUnichar*>(*outData));
|
2004-07-16 00:21:44 +04:00
|
|
|
nsCOMPtr<nsILocalFile> file;
|
2011-10-02 06:16:19 +04:00
|
|
|
nsresult rv = NS_NewLocalFile(filepath, true, getter_AddRefs(file));
|
2009-03-27 17:31:12 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsMemory::Free(*outData);
|
2004-07-16 00:21:44 +04:00
|
|
|
return dataFound;
|
2009-03-27 17:31:12 +03:00
|
|
|
}
|
2000-08-04 02:05:09 +04:00
|
|
|
|
2004-07-16 00:21:44 +04:00
|
|
|
if ( IsInternetShortcut(filepath) ) {
|
2009-03-27 17:31:12 +03:00
|
|
|
nsMemory::Free(*outData);
|
2004-07-16 00:21:44 +04:00
|
|
|
nsCAutoString url;
|
|
|
|
ResolveShortcut( file, url );
|
|
|
|
if ( !url.IsEmpty() ) {
|
2000-08-04 02:05:09 +04:00
|
|
|
// convert it to unicode and pass it out
|
2009-03-27 17:31:12 +03:00
|
|
|
nsDependentString urlString(UTF8ToNewUnicode(url));
|
|
|
|
// the internal mozilla URL format, text/x-moz-url, contains
|
|
|
|
// URL\ntitle. We can guess the title from the file's name.
|
|
|
|
nsAutoString title;
|
|
|
|
file->GetLeafName(title);
|
|
|
|
// We rely on IsInternetShortcut check that file has a .url extension.
|
|
|
|
title.SetLength(title.Length() - 4);
|
|
|
|
if (title.IsEmpty())
|
|
|
|
title = urlString;
|
|
|
|
*outData = ToNewUnicode(urlString + NS_LITERAL_STRING("\n") + title);
|
2012-04-04 04:22:42 +04:00
|
|
|
*outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar);
|
2000-08-04 02:05:09 +04:00
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
dataFound = true;
|
2000-08-03 04:47:36 +04:00
|
|
|
}
|
2000-08-04 02:05:09 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we have a normal file, use some Necko objects to get our file path
|
2004-07-16 00:21:44 +04:00
|
|
|
nsCAutoString urlSpec;
|
|
|
|
NS_GetURLSpecFromFile(file, urlSpec);
|
|
|
|
|
|
|
|
// convert it to unicode and pass it out
|
|
|
|
nsMemory::Free(*outData);
|
|
|
|
*outData = UTF8ToNewUnicode(urlSpec);
|
2012-04-04 04:22:42 +04:00
|
|
|
*outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar);
|
2011-10-02 06:16:19 +04:00
|
|
|
dataFound = true;
|
2000-08-04 02:05:09 +04:00
|
|
|
} // else regular file
|
2000-08-03 04:47:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return dataFound;
|
|
|
|
} // FindURLFromLocalFile
|
|
|
|
|
2007-11-17 16:22:13 +03:00
|
|
|
//
|
|
|
|
// FindURLFromNativeURL
|
|
|
|
//
|
|
|
|
// we are looking for a URL and couldn't find it using our internal
|
|
|
|
// URL flavor, so look for it using the native URL flavor,
|
|
|
|
// CF_INETURLSTRW (We don't handle CF_INETURLSTRA currently)
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-11-17 16:22:13 +03:00
|
|
|
nsClipboard :: FindURLFromNativeURL ( IDataObject* inDataObject, UINT inIndex, void** outData, PRUint32* outDataLen )
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dataFound = false;
|
2007-11-17 16:22:13 +03:00
|
|
|
|
|
|
|
void* tempOutData = nsnull;
|
|
|
|
PRUint32 tempDataLen = 0;
|
2008-10-20 19:21:02 +04:00
|
|
|
|
|
|
|
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, ::RegisterClipboardFormat(CFSTR_INETURLW), nsnull, &tempOutData, &tempDataLen);
|
2007-11-17 16:22:13 +03:00
|
|
|
if ( NS_SUCCEEDED(loadResult) && tempOutData ) {
|
|
|
|
nsDependentString urlString(static_cast<PRUnichar*>(tempOutData));
|
|
|
|
// the internal mozilla URL format, text/x-moz-url, contains
|
|
|
|
// URL\ntitle. Since we don't actually have a title here,
|
|
|
|
// just repeat the URL to fake it.
|
|
|
|
*outData = ToNewUnicode(urlString + NS_LITERAL_STRING("\n") + urlString);
|
2012-04-04 04:22:42 +04:00
|
|
|
*outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar);
|
2007-11-17 16:22:13 +03:00
|
|
|
nsMemory::Free(tempOutData);
|
2011-10-02 06:16:19 +04:00
|
|
|
dataFound = true;
|
2007-11-17 16:22:13 +03:00
|
|
|
}
|
2008-09-10 12:15:54 +04:00
|
|
|
else {
|
2008-10-20 19:21:02 +04:00
|
|
|
loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, ::RegisterClipboardFormat(CFSTR_INETURLA), nsnull, &tempOutData, &tempDataLen);
|
2008-09-10 12:15:54 +04:00
|
|
|
if ( NS_SUCCEEDED(loadResult) && tempOutData ) {
|
|
|
|
// CFSTR_INETURLA is (currently) equal to CFSTR_SHELLURL which is equal to CF_TEXT
|
|
|
|
// which is by definition ANSI encoded.
|
|
|
|
nsCString urlUnescapedA;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool unescaped = NS_UnescapeURL(static_cast<char*>(tempOutData), tempDataLen, esc_OnlyNonASCII | esc_SkipControl, urlUnescapedA);
|
2008-09-10 12:15:54 +04:00
|
|
|
|
|
|
|
nsString urlString;
|
|
|
|
if (unescaped)
|
|
|
|
NS_CopyNativeToUnicode(urlUnescapedA, urlString);
|
|
|
|
else
|
|
|
|
NS_CopyNativeToUnicode(nsDependentCString(static_cast<char*>(tempOutData), tempDataLen), urlString);
|
|
|
|
|
|
|
|
// the internal mozilla URL format, text/x-moz-url, contains
|
|
|
|
// URL\ntitle. Since we don't actually have a title here,
|
|
|
|
// just repeat the URL to fake it.
|
|
|
|
*outData = ToNewUnicode(urlString + NS_LITERAL_STRING("\n") + urlString);
|
2012-04-04 04:22:42 +04:00
|
|
|
*outDataLen = nsCRT::strlen(static_cast<PRUnichar*>(*outData)) * sizeof(PRUnichar);
|
2008-09-10 12:15:54 +04:00
|
|
|
nsMemory::Free(tempOutData);
|
2011-10-02 06:16:19 +04:00
|
|
|
dataFound = true;
|
2008-09-10 12:15:54 +04:00
|
|
|
}
|
|
|
|
}
|
2007-11-17 16:22:13 +03:00
|
|
|
|
|
|
|
return dataFound;
|
|
|
|
} // FindURLFromNativeURL
|
2000-08-03 04:47:36 +04:00
|
|
|
|
2000-08-04 02:05:09 +04:00
|
|
|
//
|
|
|
|
// ResolveShortcut
|
|
|
|
//
|
2000-08-03 04:47:36 +04:00
|
|
|
void
|
2004-07-16 00:21:44 +04:00
|
|
|
nsClipboard :: ResolveShortcut ( nsILocalFile* aFile, nsACString& outURL )
|
2000-08-03 04:47:36 +04:00
|
|
|
{
|
2004-07-16 00:21:44 +04:00
|
|
|
nsCOMPtr<nsIFileProtocolHandler> fph;
|
|
|
|
nsresult rv = NS_GetFileProtocolHandler(getter_AddRefs(fph));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = fph->ReadURLFile(aFile, getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
uri->GetSpec(outURL);
|
2000-08-03 04:47:36 +04:00
|
|
|
} // ResolveShortcut
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// IsInternetShortcut
|
|
|
|
//
|
|
|
|
// A file is an Internet Shortcut if it ends with .URL
|
|
|
|
//
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-05-02 10:20:16 +04:00
|
|
|
nsClipboard :: IsInternetShortcut ( const nsAString& inFileName )
|
2000-08-03 04:47:36 +04:00
|
|
|
{
|
2006-05-02 10:20:16 +04:00
|
|
|
return StringEndsWith(inFileName, NS_LITERAL_STRING(".url"), nsCaseInsensitiveStringComparator());
|
2000-08-03 04:47:36 +04:00
|
|
|
} // IsInternetShortcut
|
|
|
|
|
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2001-01-23 04:09:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsClipboard::GetNativeClipboardData ( nsITransferable * aTransferable, PRInt32 aWhichClipboard )
|
1999-04-17 17:49:39 +04:00
|
|
|
{
|
|
|
|
// make sure we have a good transferable
|
2001-01-23 04:09:58 +03:00
|
|
|
if ( !aTransferable || aWhichClipboard != kGlobalClipboard )
|
1999-04-17 17:49:39 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult res;
|
|
|
|
|
1999-04-23 18:38:27 +04:00
|
|
|
// This makes sure we can use the OLE functionality for the clipboard
|
1999-04-17 17:49:39 +04:00
|
|
|
IDataObject * dataObj;
|
|
|
|
if (S_OK == ::OleGetClipboard(&dataObj)) {
|
1999-04-23 18:38:27 +04:00
|
|
|
// Use OLE IDataObject for clipboard operations
|
2000-04-26 05:04:13 +04:00
|
|
|
res = GetDataFromDataObject(dataObj, 0, nsnull, aTransferable);
|
2001-01-23 04:09:58 +03:00
|
|
|
dataObj->Release();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// do it the old manual way
|
2000-04-26 05:04:13 +04:00
|
|
|
res = GetDataFromDataObject(nsnull, 0, mWindow, aTransferable);
|
1999-04-17 17:49:39 +04:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
|
1999-03-23 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
1999-03-24 00:26:41 +03:00
|
|
|
|
1999-09-17 06:43:08 +04:00
|
|
|
//-------------------------------------------------------------------------
|
2007-11-20 22:06:30 +03:00
|
|
|
NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(const char** aFlavorList,
|
|
|
|
PRUint32 aLength,
|
|
|
|
PRInt32 aWhichClipboard,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
1999-09-17 06:43:08 +04:00
|
|
|
{
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = false;
|
2007-11-20 22:06:30 +03:00
|
|
|
if (aWhichClipboard != kGlobalClipboard || !aFlavorList)
|
2000-04-14 06:52:58 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-11-20 22:06:30 +03:00
|
|
|
for (PRUint32 i = 0;i < aLength; ++i) {
|
2000-02-02 01:26:21 +03:00
|
|
|
#ifdef NS_DEBUG
|
2007-11-20 22:06:30 +03:00
|
|
|
if (strcmp(aFlavorList[i], kTextMime) == 0)
|
|
|
|
NS_WARNING ( "DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode INSTEAD" );
|
2000-02-02 01:26:21 +03:00
|
|
|
#endif
|
|
|
|
|
2007-11-20 22:06:30 +03:00
|
|
|
UINT format = GetFormat(aFlavorList[i]);
|
|
|
|
if (IsClipboardFormatAvailable(format)) {
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = true;
|
2007-11-20 22:06:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We haven't found the exact flavor the client asked for, but maybe we can
|
|
|
|
// still find it from something else that's on the clipboard...
|
|
|
|
if (strcmp(aFlavorList[i], kUnicodeMime) == 0) {
|
|
|
|
// client asked for unicode and it wasn't present, check if we have CF_TEXT.
|
|
|
|
// We'll handle the actual data substitution in the data object.
|
|
|
|
if (IsClipboardFormatAvailable(GetFormat(kTextMime)))
|
2011-10-02 06:16:19 +04:00
|
|
|
*_retval = true;
|
2000-02-02 01:26:21 +03:00
|
|
|
}
|
1999-09-17 06:43:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|