зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1310193 - Remove wrapping of nsISupports as nsISupportsInterfacePointer in transferables. r=smaug
--HG-- extra : rebase_source : 562b3bcd621ad348b7e2ada8151775b188ba58ff
This commit is contained in:
Родитель
8c963f7592
Коммит
f659f51906
|
@ -176,11 +176,8 @@ async function getImageSizeFromClipboard() {
|
|||
|
||||
// Due to the differences in how images could be stored in the clipboard the
|
||||
// checks below are needed. The clipboard could already provide the image as
|
||||
// byte streams, but also as pointer, or as image container. If it's not
|
||||
// possible obtain a byte stream, the function returns `null`.
|
||||
if (image instanceof Ci.nsISupportsInterfacePointer) {
|
||||
image = image.data;
|
||||
}
|
||||
// byte streams or as image container. If it's not possible obtain a
|
||||
// byte stream, the function throws.
|
||||
|
||||
if (image instanceof Ci.imgIContainer) {
|
||||
image = Cc["@mozilla.org/image/tools;1"]
|
||||
|
|
|
@ -183,15 +183,13 @@ function saveToClipboard(base64URI) {
|
|||
const base64Data = base64URI.replace("data:image/png;base64,", "");
|
||||
|
||||
const image = atob(base64Data);
|
||||
const imgPtr = Cc["@mozilla.org/supports-interface-pointer;1"]
|
||||
.createInstance(Ci.nsISupportsInterfacePointer);
|
||||
imgPtr.data = imageTools.decodeImageFromBuffer(image, image.length, "image/png");
|
||||
const img = imageTools.decodeImageFromBuffer(image, image.length, "image/png");
|
||||
|
||||
const transferable = Cc["@mozilla.org/widget/transferable;1"]
|
||||
.createInstance(Ci.nsITransferable);
|
||||
transferable.init(null);
|
||||
transferable.addDataFlavor("image/png");
|
||||
transferable.setTransferData("image/png", imgPtr, -1);
|
||||
transferable.setTransferData("image/png", img, -1);
|
||||
|
||||
Services.clipboard.setData(transferable, null, Services.clipboard.kGlobalClipboard);
|
||||
return L10N.getStr("screenshotCopied");
|
||||
|
|
|
@ -7753,14 +7753,7 @@ nsContentUtils::IPCTransferableToTransferable(const IPCDataTransfer& aDataTransf
|
|||
getter_AddRefs(imageContainer));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISupportsInterfacePointer> imgPtr =
|
||||
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
|
||||
NS_ENSURE_TRUE(imgPtr, NS_ERROR_FAILURE);
|
||||
|
||||
rv = imgPtr->SetData(imageContainer);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aTransferable->SetTransferData(item.flavor().get(), imgPtr, sizeof(nsISupports*));
|
||||
aTransferable->SetTransferData(item.flavor().get(), imageContainer, sizeof(nsISupports*));
|
||||
} else {
|
||||
nsCOMPtr<nsISupportsCString> dataWrapper =
|
||||
do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
|
||||
|
@ -8015,12 +8008,6 @@ nsContentUtils::TransferableToIPCTransferable(nsITransferable* aTransferable,
|
|||
|
||||
item->data() = dataAsShmem;
|
||||
} else {
|
||||
nsCOMPtr<nsISupportsInterfacePointer> sip =
|
||||
do_QueryInterface(data);
|
||||
if (sip) {
|
||||
sip->GetData(getter_AddRefs(data));
|
||||
}
|
||||
|
||||
// Images to be pasted on the clipboard are nsIInputStreams
|
||||
nsCOMPtr<nsIInputStream> stream(do_QueryInterface(data));
|
||||
if (stream) {
|
||||
|
|
|
@ -421,15 +421,8 @@ nsCopySupport::ImageCopy(nsIImageLoadingContent* aImageElement,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsISupportsInterfacePointer>
|
||||
imgPtr(do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = imgPtr->SetData(image);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// copy the image data onto the transferable
|
||||
rv = trans->SetTransferData(kNativeImageMime, imgPtr,
|
||||
rv = trans->SetTransferData(kNativeImageMime, image,
|
||||
sizeof(nsISupports*));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
|
|
@ -1161,19 +1161,9 @@ DataTransfer::ConvertFromVariant(nsIVariant* aVariant,
|
|||
// value 0) as the length.
|
||||
fdp.forget(aSupports);
|
||||
*aLength = nsITransferable::kFlavorHasDataProvider;
|
||||
}
|
||||
else {
|
||||
// wrap the item in an nsISupportsInterfacePointer
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptrSupports =
|
||||
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
|
||||
if (!ptrSupports) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ptrSupports->SetData(data);
|
||||
ptrSupports.forget(aSupports);
|
||||
|
||||
*aLength = sizeof(nsISupportsInterfacePointer *);
|
||||
} else {
|
||||
data.forget(aSupports);
|
||||
*aLength = sizeof(nsISupports *);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
XPCOMUtils.defineLazyServiceGetter(this, "imgTools",
|
||||
"@mozilla.org/image/tools;1", "imgITools");
|
||||
|
||||
const SupportsInterfacePointer = Components.Constructor(
|
||||
"@mozilla.org/supports-interface-pointer;1", "nsISupportsInterfacePointer");
|
||||
const Transferable = Components.Constructor(
|
||||
"@mozilla.org/widget/transferable;1", "nsITransferable");
|
||||
|
||||
|
@ -19,9 +17,9 @@ this.clipboard = class extends ExtensionAPI {
|
|||
return Promise.reject({message: "Writing images to the clipboard is not supported on Android"});
|
||||
}
|
||||
let mimeType = `image/${imageType}`;
|
||||
let container;
|
||||
let img;
|
||||
try {
|
||||
container = imgTools.decodeImageFromArrayBuffer(imageData, mimeType);
|
||||
img = imgTools.decodeImageFromArrayBuffer(imageData, mimeType);
|
||||
} catch (e) {
|
||||
return Promise.reject({message: `Data is not a valid ${imageType} image`});
|
||||
}
|
||||
|
@ -34,13 +32,10 @@ this.clipboard = class extends ExtensionAPI {
|
|||
//
|
||||
// The common protocol for exporting a nsITransferable as an image is:
|
||||
// - Use nsITransferable::GetTransferData to fetch the stored data.
|
||||
// - QI a nsISupportsInterfacePointer and get the underlying pointer.
|
||||
// - QI imgIContainer on the pointer.
|
||||
// - Convert the image to the native clipboard format.
|
||||
//
|
||||
// Below we create a nsITransferable in the above format.
|
||||
let imgPtr = new SupportsInterfacePointer();
|
||||
imgPtr.data = container;
|
||||
let transferable = new Transferable();
|
||||
transferable.init(null);
|
||||
transferable.addDataFlavor(mimeType);
|
||||
|
@ -53,7 +48,7 @@ this.clipboard = class extends ExtensionAPI {
|
|||
// On macOS, nsClipboard::GetNativeClipboardData (nsClipboard.mm) uses
|
||||
// a cached copy of nsITransferable if available, e.g. when the copy
|
||||
// was initiated by the same browser instance. Consequently, the
|
||||
// transferable still holds a nsISupportsInterfacePointer pointer
|
||||
// transferable still holds a imgIContainer pointer
|
||||
// instead of a nsIInputStream, and logic that assumes the data to be
|
||||
// a nsIInputStream instance fails.
|
||||
// For example HTMLEditor::InsertObject (HTMLEditorDataTransfer.cpp)
|
||||
|
@ -68,7 +63,7 @@ this.clipboard = class extends ExtensionAPI {
|
|||
//
|
||||
// Note that the length itself is not really used if the data is not
|
||||
// a string type, so the actual value does not matter.
|
||||
transferable.setTransferData(mimeType, imgPtr, 0);
|
||||
transferable.setTransferData(mimeType, img, 0);
|
||||
|
||||
Services.clipboard.setData(
|
||||
transferable, null, Services.clipboard.kGlobalClipboard);
|
||||
|
|
|
@ -587,14 +587,8 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
|
|||
uint32_t dataSize = 0;
|
||||
nsCOMPtr<nsISupports> transferSupports;
|
||||
aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(transferSupports), &dataSize);
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptrPrimitive(do_QueryInterface(transferSupports));
|
||||
if (!ptrPrimitive)
|
||||
continue;
|
||||
|
||||
nsCOMPtr<nsISupports> primitiveData;
|
||||
ptrPrimitive->GetData(getter_AddRefs(primitiveData));
|
||||
|
||||
nsCOMPtr<imgIContainer> image(do_QueryInterface(primitiveData));
|
||||
nsCOMPtr<imgIContainer> image(do_QueryInterface(transferSupports));
|
||||
if (!image) {
|
||||
NS_WARNING("Image isn't an imgIContainer in transferable");
|
||||
continue;
|
||||
|
@ -647,15 +641,6 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIFile> file(do_QueryInterface(genericFile));
|
||||
if (!file) {
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericFile));
|
||||
|
||||
if (ptr) {
|
||||
ptr->GetData(getter_AddRefs(genericFile));
|
||||
file = do_QueryInterface(genericFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -536,19 +536,18 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard,
|
|||
static const char* const imageMimeTypes[] = {
|
||||
kNativeImageMime, kPNGImageMime, kJPEGImageMime, kJPGImageMime, kGIFImageMime };
|
||||
nsCOMPtr<nsISupports> imageItem;
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptrPrimitive;
|
||||
for (uint32_t i = 0; !ptrPrimitive && i < ArrayLength(imageMimeTypes); i++) {
|
||||
nsCOMPtr<imgIContainer> image;
|
||||
for (uint32_t i = 0; i < ArrayLength(imageMimeTypes); i++) {
|
||||
rv = trans->GetTransferData(imageMimeTypes[i], getter_AddRefs(imageItem), &len);
|
||||
ptrPrimitive = do_QueryInterface(imageItem);
|
||||
image = do_QueryInterface(imageItem);
|
||||
if (image) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ptrPrimitive)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsISupports> primitiveData;
|
||||
ptrPrimitive->GetData(getter_AddRefs(primitiveData));
|
||||
nsCOMPtr<imgIContainer> image(do_QueryInterface(primitiveData));
|
||||
if (!image) // Not getting an image for an image mime type!?
|
||||
if (!image) { // Not getting an image for an image mime type!?
|
||||
return;
|
||||
}
|
||||
|
||||
GdkPixbuf* pixbuf = nsImageToPixbuf::ImageToPixbuf(image);
|
||||
if (!pixbuf)
|
||||
|
|
|
@ -1591,20 +1591,7 @@ CreateUriList(nsIArray *items, gchar **text, gint *length)
|
|||
getter_AddRefs(data),
|
||||
&tmpDataLen);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIFile> file = do_QueryInterface(data);
|
||||
if (!file) {
|
||||
// Sometimes the file is wrapped in a
|
||||
// nsISupportsInterfacePointer. See bug 1310193 for
|
||||
// removing this distinction.
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptr =
|
||||
do_QueryInterface(data);
|
||||
if (ptr) {
|
||||
ptr->GetData(getter_AddRefs(data));
|
||||
file = do_QueryInterface(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (file) {
|
||||
if (nsCOMPtr<nsIFile> file = do_QueryInterface(data)) {
|
||||
nsCOMPtr<nsIURI> fileURI;
|
||||
NS_NewFileURI(getter_AddRefs(fileURI), file);
|
||||
if (fileURI) {
|
||||
|
|
|
@ -901,18 +901,6 @@ nsDataObj::GetDib(const nsACString& inFlavor,
|
|||
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||
mTransferable->GetTransferData(PromiseFlatCString(inFlavor).get(), getter_AddRefs(genericDataWrapper), &len);
|
||||
nsCOMPtr<imgIContainer> image ( do_QueryInterface(genericDataWrapper) );
|
||||
if ( !image ) {
|
||||
// Check if the image was put in an nsISupportsInterfacePointer wrapper.
|
||||
// This might not be necessary any more, but could be useful for backwards
|
||||
// compatibility.
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericDataWrapper));
|
||||
if ( ptr ) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
ptr->GetData(getter_AddRefs(supports));
|
||||
image = do_QueryInterface(supports);
|
||||
}
|
||||
}
|
||||
|
||||
if ( image ) {
|
||||
// use the |nsImageToClipboard| helper class to build up a bitmap. We now own
|
||||
// the bits, and pass them back to the OS in |aSTG|.
|
||||
|
@ -1466,17 +1454,6 @@ HRESULT nsDataObj::DropFile(FORMATETC& aFE, STGMEDIUM& aSTG)
|
|||
mTransferable->GetTransferData(kFileMime, getter_AddRefs(genericDataWrapper),
|
||||
&len);
|
||||
nsCOMPtr<nsIFile> file ( do_QueryInterface(genericDataWrapper) );
|
||||
|
||||
if (!file)
|
||||
{
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericDataWrapper));
|
||||
if (ptr) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
ptr->GetData(getter_AddRefs(supports));
|
||||
file = do_QueryInterface(supports);
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
return E_FAIL;
|
||||
|
||||
|
@ -1531,19 +1508,6 @@ HRESULT nsDataObj::DropImage(FORMATETC& aFE, STGMEDIUM& aSTG)
|
|||
|
||||
mTransferable->GetTransferData(kNativeImageMime, getter_AddRefs(genericDataWrapper), &len);
|
||||
nsCOMPtr<imgIContainer> image(do_QueryInterface(genericDataWrapper));
|
||||
|
||||
if (!image) {
|
||||
// Check if the image was put in an nsISupportsInterfacePointer wrapper.
|
||||
// This might not be necessary any more, but could be useful for backwards
|
||||
// compatibility.
|
||||
nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericDataWrapper));
|
||||
if (ptr) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
ptr->GetData(getter_AddRefs(supports));
|
||||
image = do_QueryInterface(supports);
|
||||
}
|
||||
}
|
||||
|
||||
if (!image)
|
||||
return E_FAIL;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче