зеркало из https://github.com/mozilla/gecko-dev.git
Bug 609632 - Insert image files dropped onto editable areas as data: URI images; r=roc a=blocking-beta8+
--HG-- extra : rebase_source : 7ec1941c8052c352e6304fd8affe89d890b1ae1b
This commit is contained in:
Родитель
e77d3901bf
Коммит
4d5d852b13
|
@ -1121,6 +1121,7 @@ NS_IMETHODIMP nsHTMLEditor::PrepareHTMLTransferable(nsITransferable **aTransfera
|
|||
(*aTransferable)->AddDataFlavor(kNativeHTMLMime);
|
||||
}
|
||||
(*aTransferable)->AddDataFlavor(kHTMLMime);
|
||||
(*aTransferable)->AddDataFlavor(kFileMime);
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
PRInt32 clipboardPasteOrder = 1; // order of image-encoding preference
|
||||
|
@ -1320,6 +1321,28 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// Check to see if we can insert an image file
|
||||
PRBool insertAsImage = PR_FALSE;
|
||||
nsCOMPtr<nsIURI> fileURI;
|
||||
if (0 == nsCRT::strcmp(bestFlavor, kFileMime))
|
||||
{
|
||||
nsCOMPtr<nsIFile> fileObj(do_QueryInterface(genericDataObj));
|
||||
if (fileObj && len > 0)
|
||||
{
|
||||
nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1");
|
||||
NS_ENSURE_TRUE(mime, NS_ERROR_FAILURE);
|
||||
nsAutoCString contentType;
|
||||
rv = mime->GetTypeFromFile(fileObj, contentType);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Accept any image type fed to us
|
||||
if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("image/"))) {
|
||||
insertAsImage = PR_TRUE;
|
||||
bestFlavor = contentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == nsCRT::strcmp(bestFlavor, kNativeHTMLMime))
|
||||
{
|
||||
// note cf_html uses utf8, hence use length = len, not len/2 as in flavors below
|
||||
|
@ -1381,13 +1404,23 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
|
|||
0 == nsCRT::strcmp(bestFlavor, kPNGImageMime) ||
|
||||
0 == nsCRT::strcmp(bestFlavor, kGIFImageMime))
|
||||
{
|
||||
nsCOMPtr<nsIInputStream> imageStream(do_QueryInterface(genericDataObj));
|
||||
NS_ENSURE_TRUE(imageStream, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIInputStream> imageStream;
|
||||
if (insertAsImage) {
|
||||
NS_ASSERTION(fileURI, "The file URI should be retrieved earlier");
|
||||
rv = NS_OpenURI(getter_AddRefs(imageStream), fileURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
imageStream = do_QueryInterface(genericDataObj);
|
||||
NS_ENSURE_TRUE(imageStream, NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
nsCString imageData;
|
||||
rv = NS_ConsumeStream(imageStream, PR_UINT32_MAX, imageData);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = imageStream->Close();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
char * base64 = PL_Base64Encode(imageData.get(), imageData.Length(), nsnull);
|
||||
NS_ENSURE_TRUE(base64, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче