Backing out bug 444800

This commit is contained in:
Kathleen Brade 2008-10-14 10:06:35 -04:00
parent f2deabcd32
commit eb14288e2b
7 changed files with 22 additions and 135 deletions

View File

@ -23,8 +23,6 @@
* Pierre Phaneuf <pp@ludusdesign.com>
* Sean Echevarria <sean@beatnik.com>
* David Gardiner <david.gardiner@unisa.edu.au>
* Kathleen Brade <brade@comcast.net>
* Mark Smith <mcs@pearlcrescent.com>
*
* 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
@ -106,8 +104,7 @@ UINT nsClipboard::GetFormat(const char* aMimeStr)
else if (strcmp(aMimeStr, kUnicodeMime) == 0)
format = CF_UNICODETEXT;
#ifndef WINCE
else if (strcmp(aMimeStr, kJPEGImageMime) == 0 ||
strcmp(aMimeStr, kPNGImageMime) == 0)
else if (strcmp(aMimeStr, kJPEGImageMime) == 0)
format = CF_DIB;
else if (strcmp(aMimeStr, kFileMime) == 0 ||
strcmp(aMimeStr, kFilePromiseMime) == 0)
@ -334,15 +331,14 @@ nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void ** aData, PRUint32 * aLe
}
//-------------------------------------------------------------------------
nsresult nsClipboard::GetNativeDataOffClipboard(nsIWidget * aWindow, UINT /*aIndex*/, const char* aMIMEFormat, void ** aData, PRUint32 * aLen)
nsresult nsClipboard::GetNativeDataOffClipboard(nsIWidget * aWindow, UINT /*aIndex*/, UINT aFormat, void ** aData, PRUint32 * aLen)
{
HGLOBAL hglb;
nsresult result = NS_ERROR_FAILURE;
UINT format = GetFormat(aMIMEFormat);
HWND nativeWin = nsnull;//(HWND)aWindow->GetNativeData(NS_NATIVE_WINDOW);
if (::OpenClipboard(nativeWin)) {
hglb = ::GetClipboardData(format);
hglb = ::GetClipboardData(aFormat);
result = GetGlobalData(hglb, aData, aLen);
::CloseClipboard();
}
@ -408,7 +404,7 @@ static HRESULT FillSTGMedium(IDataObject * aDataObject, UINT aFormat, LPFORMATET
//-------------------------------------------------------------------------
nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aIndex, const char * aMIMEFormat, void ** aData, PRUint32 * aLen)
nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aIndex, UINT aFormat, void ** aData, PRUint32 * aLen)
{
nsresult result = NS_ERROR_FAILURE;
*aData = nsnull;
@ -417,7 +413,7 @@ nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject * aDataObject, UINT
if ( !aDataObject )
return result;
UINT format = GetFormat(aMIMEFormat);
UINT format = aFormat;
HRESULT hres = S_FALSE;
// XXX at the moment we only support global memory transfers
@ -479,7 +475,7 @@ nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject * aDataObject, UINT
{
nsImageFromClipboard converter;
nsIInputStream * inputStream;
converter.GetEncodedImageStream (clipboardData, aMIMEFormat, &inputStream ); // addrefs for us, don't release
converter.GetEncodedImageStream (clipboardData, &inputStream ); // addrefs for us, don't release
if ( inputStream ) {
*aData = inputStream;
*aLen = sizeof(nsIInputStream*);
@ -600,6 +596,7 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
if ( currentFlavor ) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
UINT format = GetFormat(flavorStr);
// Try to get the data using the desired flavor. This might fail, but all is
// not lost.
@ -607,11 +604,11 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
PRUint32 dataLen = 0;
PRBool dataFound = PR_FALSE;
if (nsnull != aDataObject) {
if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aDataObject, anIndex, flavorStr, &data, &dataLen)) )
if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aDataObject, anIndex, format, &data, &dataLen)) )
dataFound = PR_TRUE;
}
else if (nsnull != aWindow) {
if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aWindow, anIndex, flavorStr, &data, &dataLen)) )
if ( NS_SUCCEEDED(GetNativeDataOffClipboard(aWindow, anIndex, format, &data, &dataLen)) )
dataFound = PR_TRUE;
}
@ -654,8 +651,7 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
}
nsMemory::Free(data);
}
else if ( strcmp(flavorStr, kJPEGImageMime) == 0 ||
strcmp(flavorStr, kPNGImageMime) == 0) {
else if ( strcmp(flavorStr, kJPEGImageMime) == 0) {
nsIInputStream * imageStream = reinterpret_cast<nsIInputStream*>(data);
genericDataWrapper = do_QueryInterface(imageStream);
NS_IF_RELEASE(imageStream);
@ -729,7 +725,7 @@ nsClipboard :: FindUnicodeFromPlainText ( IDataObject* inDataObject, UINT inInde
// 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.
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, kTextMime, outData, outDataLen);
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kTextMime), outData, outDataLen);
if ( NS_SUCCEEDED(loadResult) && *outData ) {
const char* castedText = reinterpret_cast<char*>(*outData);
PRUnichar* convertedText = nsnull;
@ -763,7 +759,7 @@ nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, v
{
PRBool dataFound = PR_FALSE;
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, kFileMime, outData, outDataLen);
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kFileMime), outData, outDataLen);
if ( NS_SUCCEEDED(loadResult) && *outData ) {
// we have a file path in |data|. Is it an internet shortcut or a normal file?
const nsDependentString filepath(static_cast<PRUnichar*>(*outData));
@ -814,7 +810,7 @@ nsClipboard :: FindURLFromNativeURL ( IDataObject* inDataObject, UINT inIndex, v
void* tempOutData = nsnull;
PRUint32 tempDataLen = 0;
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, CFSTR_INETURLW, &tempOutData, &tempDataLen);
nsresult loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, ::RegisterClipboardFormat(CFSTR_INETURLW), &tempOutData, &tempDataLen);
if ( NS_SUCCEEDED(loadResult) && tempOutData ) {
nsDependentString urlString(static_cast<PRUnichar*>(tempOutData));
// the internal mozilla URL format, text/x-moz-url, contains
@ -826,7 +822,7 @@ nsClipboard :: FindURLFromNativeURL ( IDataObject* inDataObject, UINT inIndex, v
dataFound = PR_TRUE;
}
else {
loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, CFSTR_INETURLA, &tempOutData, &tempDataLen);
loadResult = GetNativeDataOffClipboard(inDataObject, inIndex, ::RegisterClipboardFormat(CFSTR_INETURLA), &tempOutData, &tempDataLen);
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.

View File

@ -73,8 +73,8 @@ public:
UINT anIndex,
nsIWidget * aWindow,
nsITransferable * aTransferable);
static nsresult GetNativeDataOffClipboard(nsIWidget * aWindow, UINT aIndex, const char * aMIMEFormat, void ** aData, PRUint32 * aLen);
static nsresult GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aIndex, const char * aMIMEFormat, void ** aData, PRUint32 * aLen);
static nsresult GetNativeDataOffClipboard(nsIWidget * aWindow, UINT aIndex, UINT aFormat, void ** aData, PRUint32 * aLen);
static nsresult GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aIndex, UINT aFormat, void ** aData, PRUint32 * aLen);
static nsresult GetGlobalData(HGLOBAL aHGBL, void ** aData, PRUint32 * aLen);
static UINT GetFormat(const char* aMimeStr);

View File

@ -22,8 +22,6 @@
* Contributor(s):
* Mike Pinkerton <pinkerton@netscape.com>
* Gus Verdun <gustavoverdun@aol.com>
* Kathleen Brade <brade@comcast.net>
* Mark Smith <mcs@pearlcrescent.com>
*
* 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
@ -40,7 +38,6 @@
* ***** END LICENSE BLOCK ***** */
#include "nsITransferable.h"
#include "nsImageClipboard.h"
#include "nsGfxCIID.h"
#include "nsMemory.h"
@ -205,13 +202,12 @@ nsImageFromClipboard :: ~nsImageFromClipboard ( )
//
// GetEncodedImageStream
//
// Take the raw clipboard image data and convert it to aMIMEFormat in the form of a nsIInputStream
// Take the raw clipboard image data and convert it to a JPG in the form of a nsIInputStream
//
nsresult
nsImageFromClipboard ::GetEncodedImageStream (unsigned char * aClipboardData, const char * aMIMEFormat, nsIInputStream** aInputStream )
nsImageFromClipboard ::GetEncodedImageStream (unsigned char * aClipboardData, nsIInputStream** aInputStream )
{
NS_ENSURE_ARG_POINTER (aInputStream);
NS_ENSURE_ARG_POINTER (aMIMEFormat);
nsresult rv;
*aInputStream = nsnull;
@ -229,16 +225,9 @@ nsImageFromClipboard ::GetEncodedImageStream (unsigned char * aClipboardData, co
BYTE * pGlobal = (BYTE *) aClipboardData;
// Convert the clipboard image into RGB packed pixel data
rv = ConvertColorBitMap((unsigned char *) (pGlobal + header->bmiHeader.biSize), header, rgbData);
// if that succeeded, encode the bitmap as aMIMEFormat data. Don't return early or we risk leaking rgbData
// if that succeeded, encode the bitmap as a JPG. Don't return early or we risk leaking rgbData
if (NS_SUCCEEDED(rv)) {
nsCAutoString encoderCID(NS_LITERAL_CSTRING("@mozilla.org/image/encoder;2?type="));
// Map image/jpg to image/jpeg (which is how the encoder is registered).
if (strcmp(aMIMEFormat, kJPEGImageMime) == 0)
encoderCID.Append("image/jpeg");
else
encoderCID.Append(aMIMEFormat);
nsCOMPtr<imgIEncoder> encoder = do_CreateInstance(encoderCID.get(), &rv);
nsCOMPtr<imgIEncoder> encoder = do_CreateInstance("@mozilla.org/image/encoder;2?type=image/jpeg", &rv);
if (NS_SUCCEEDED(rv)){
rv = encoder->InitFromData(rgbData, 0, width, height, 3 * width /* RGB * # pixels in a row */,
imgIEncoder::INPUT_FORMAT_RGB, EmptyString());

View File

@ -22,8 +22,6 @@
* Contributor(s):
* Mike Pinkerton <pinkerton@netscape.com>
* Gus Verdun <gustavoverdun@aol.com>
* Kathleen Brade <brade@comcast.net>
* Mark Smith <mcs@pearlcrescent.com>
*
* 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
@ -113,7 +111,7 @@ public:
~nsImageFromClipboard ( ) ;
// Retrieve the newly created image
nsresult GetEncodedImageStream (unsigned char * aClipboardData, const char * aMIMEFormat, nsIInputStream** outImage);
nsresult GetEncodedImageStream (unsigned char * aClipboardData, nsIInputStream** outImage);
private:

View File

@ -292,7 +292,7 @@ nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource,
void* tempOutData = nsnull;
PRUint32 tempDataLen = 0;
nsresult loadResult = nsClipboard::GetNativeDataOffClipboard(
pIDataSource, 0, CFSTR_PREFERREDDROPEFFECT, &tempOutData, &tempDataLen);
pIDataSource, 0, ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT), &tempOutData, &tempDataLen);
if (NS_SUCCEEDED(loadResult) && tempOutData) {
NS_ASSERTION(tempDataLen == 2, "Expected word size");
WORD preferredEffect = *((WORD*)tempOutData);

View File

@ -45,7 +45,6 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = test_bug343416.xul \
test_bug444800.xul \
test_keycodes.xul \
$(NULL)

View File

@ -1,95 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin"
type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=444800
-->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Mozilla Bug 444800" onload="initAndRunTests()">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"/>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=444800"
target="_blank">Mozilla Bug 444800</a>
<p/>
<img id="bitm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%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FAAAA%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FAAAA%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FAAAA"/>
<p/>
<pre id="test">
</pre>
</body>
<script class="testbody" type="application/javascript">
<![CDATA[
const knsIClipboard = Components.interfaces.nsIClipboard;
function copyImageToClipboard()
{
var tmpNode = document.popupNode;
document.popupNode = document.getElementById("bitmapImage");
const kCmd = "cmd_copyImageContents";
var controller = top.document.commandDispatcher
.getControllerForCommand(kCmd);
ok((controller && controller.isCommandEnabled(kCmd)), "have copy command");
controller.doCommand(kCmd);
document.popupNode = tmpNode;
}
function runImageClipboardTests(aCBSvc, aImageType)
{
// Verify that hasDataMatchingFlavors() is working correctly.
var typeArray = [ aImageType ];
var hasImage = aCBSvc.hasDataMatchingFlavors(typeArray, typeArray.length,
knsIClipboard.kGlobalClipboard);
ok(hasImage, aImageType + " - hasDataMatchingFlavors()");
// Verify that getData() is working correctly.
var xfer = Components.classes["@mozilla.org/widget/transferable;1"]
.createInstance(Components.interfaces.nsITransferable);
xfer.addDataFlavor(aImageType);
aCBSvc.getData(xfer, knsIClipboard.kGlobalClipboard);
var typeObj = {}, dataObj = {}, lenObj = {};
xfer.getAnyTransferData(typeObj, dataObj, lenObj);
var gotValue = (null != dataObj.value);
ok(gotValue, aImageType + " - getData() returned a value");
if (gotValue)
{
const knsIInputStream = Components.interfaces.nsIInputStream;
var imgStream = dataObj.value.QueryInterface(knsIInputStream);
ok((null != imgStream), aImageType + " - got an nsIInputStream");
var bytesAvailable = imgStream.available();
ok((bytesAvailable > 10), aImageType + " - got some data");
}
}
function initAndRunTests()
{
SimpleTest.waitForExplicitFinish();
copyImageToClipboard();
var cbSvc = Components.classes["@mozilla.org/widget/clipboard;1"]
.getService(knsIClipboard);
// Work around a problem on Windows where clipboard is not ready after copy.
setTimeout(function() { runTests(cbSvc); }, 0);
}
function runTests(aCBSvc)
{
runImageClipboardTests(aCBSvc, "image/png");
runImageClipboardTests(aCBSvc, "image/jpg");
SimpleTest.finish();
}
]]>
</script>
</window>