mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
cbc917768b
- Bug 1266578 - OOM crash if malloc fails in ProcessIncomingMessages(). r=billm (5eca51be20) - Bug 1261340: Don't refer to |ScopedFreePtrTraits| in |RawDBusConnection|, r=shuang (61996db57c) - Bug 1246931: Move |DBusWatcher| into its own files, r=shuang (a7fc4a68c3) - Bug 1246931: Add support for |RefPtr<DBusConnection>| and convert callers, r=shuang (6c07d3e8d3) - Bug 1246931: Add support for |RefPtr<DBusMessage>|, r=shuang (c0ed14cc2b) - Bug 1246931: Add support for |RefPtr<DBusPendingCall>|, r=shuang (a007a15699) - Bug 1246931: Use |DBusConnection| in |DBusWatcher|, r=shuang (11b5eaf535) - Bug 1246931: Add DBus I/O helpers, r=shuang (be249fa65b) - Bug 1264398 - Avoid extra assign() on windows in IPC code (r=jld) (0f31b798a3) - Bug 1261231: Fix shutdown leak in imgLoader::GetInstance. r=gabor (96e5143c41) - Bug 1256999 - Use nsIDocument for ImageCacheKey. r=bz r=seth (cd4765ce34) - Bug 1257101. imgFrame::IsImageComplete says whether we've had pixels decoded to the whole image rect, but it's used to check if the frame is finished decoding. These are different things when the image has more than one progress pass. r=seth (06d619410f) - Bug 1222596. If RasterImage::LookupFrame does (some) sync decoding and encouters an error we don't want to return the surface with an error. r=seth (c4dbc8e0d5) - Bug 763784 - Make VectorImage::GetAnimated check for CSS animations. r=dholbert (4d0e5b88eb) - Bug 1210745 - Update CheckProgressConsistency() to match current ImageLib behavior. r=tn (2317b24fcc) - Bug 1249576. Add crashtest. (485f03120b) - Bug 1251091. Add crashtest. (7e1682a1e6) - Bug 1253362. SVGDocumentWrapper::IsAnimated can be called after SVGDocumentWrapper::DestroyViewer so null check mViewer. r=dholbert (2b4a1c4619) - Bug 1210745. Change image progress asserts to allow transparency to be posted after the size is posted. r=seth (699f3c5496) - Bug 1209780. Use the DrawResult return value of imgIContainer::Draw in the cocoa code. r=seth (abaea789e3) - No Bug - Remove some unnecessary SVGImageContext.h includes and add comments. r=sparky (8232661a23) - cleanup style (de33e4bfa8) - Bug 860857, support custom datatransfer types using a special type, r=smaug,jmathies,mstange (cf7e19deb6) - Bug 1248459 - Don't query out-of-bounds selection; r=masayuki (86c127f143) - Bug 1261671 - ContentEventHandler::ConvertToRootRelativeOffset() should return the root-relative result in the frame's own appUnits, not the root's appUnits in the case when they're different. r=masayuki (2cd72b5ebc) - Bug 1266702 - Clean up formatting in dom/events/DataTransfer.* and mark some methods const, r=jwatt (bd439cdad5)
209 lines
7.3 KiB
C++
209 lines
7.3 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
//
|
|
// Part of the reason these routines are all in once place is so that as new
|
|
// data flavors are added that are known to be one-byte or two-byte strings, or even
|
|
// raw binary data, then we just have to go to one place to change how the data
|
|
// moves into/out of the primitives and native line endings.
|
|
//
|
|
// If you add new flavors that have special consideration (binary data or one-byte
|
|
// char* strings), please update all the helper classes in this file.
|
|
//
|
|
// For now, this is the assumption that we are making:
|
|
// - text/plain is always a char*
|
|
// - anything else is a char16_t*
|
|
//
|
|
|
|
|
|
#include "nsPrimitiveHelpers.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsXPCOM.h"
|
|
#include "nsISupportsPrimitives.h"
|
|
#include "nsITransferable.h"
|
|
#include "nsIComponentManager.h"
|
|
#include "nsLinebreakConverter.h"
|
|
#include "nsReadableUtils.h"
|
|
|
|
|
|
//
|
|
// CreatePrimitiveForData
|
|
//
|
|
// Given some data and the flavor it corresponds to, creates the appropriate
|
|
// nsISupports* wrapper for passing across IDL boundaries. Right now, everything
|
|
// creates a two-byte |nsISupportsString|, except for "text/plain" and native
|
|
// platform HTML (CF_HTML on win32)
|
|
//
|
|
void
|
|
nsPrimitiveHelpers :: CreatePrimitiveForData ( const char* aFlavor, const void* aDataBuff,
|
|
uint32_t aDataLen, nsISupports** aPrimitive )
|
|
{
|
|
if ( !aPrimitive )
|
|
return;
|
|
|
|
if ( strcmp(aFlavor,kTextMime) == 0 || strcmp(aFlavor,kNativeHTMLMime) == 0 ||
|
|
strcmp(aFlavor,kRTFMime) == 0 || strcmp(aFlavor,kCustomTypesMime) == 0) {
|
|
nsCOMPtr<nsISupportsCString> primitive =
|
|
do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID);
|
|
if ( primitive ) {
|
|
const char * start = reinterpret_cast<const char*>(aDataBuff);
|
|
primitive->SetData(Substring(start, start + aDataLen));
|
|
NS_ADDREF(*aPrimitive = primitive);
|
|
}
|
|
}
|
|
else {
|
|
nsCOMPtr<nsISupportsString> primitive =
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
|
if (primitive ) {
|
|
if (aDataLen % 2) {
|
|
auto buffer = mozilla::MakeUnique<char[]>(aDataLen + 1);
|
|
if (!MOZ_LIKELY(buffer))
|
|
return;
|
|
|
|
memcpy(buffer.get(), aDataBuff, aDataLen);
|
|
buffer[aDataLen] = 0;
|
|
const char16_t* start = reinterpret_cast<const char16_t*>(buffer.get());
|
|
// recall that length takes length as characters, not bytes
|
|
primitive->SetData(Substring(start, start + (aDataLen + 1) / 2));
|
|
} else {
|
|
const char16_t* start = reinterpret_cast<const char16_t*>(aDataBuff);
|
|
// recall that length takes length as characters, not bytes
|
|
primitive->SetData(Substring(start, start + (aDataLen / 2)));
|
|
}
|
|
NS_ADDREF(*aPrimitive = primitive);
|
|
}
|
|
}
|
|
|
|
} // CreatePrimitiveForData
|
|
|
|
//
|
|
// CreatePrimitiveForCFHTML
|
|
//
|
|
// Platform specific CreatePrimitive, windows CF_HTML.
|
|
//
|
|
void
|
|
nsPrimitiveHelpers :: CreatePrimitiveForCFHTML ( const void* aDataBuff,
|
|
uint32_t* aDataLen, nsISupports** aPrimitive )
|
|
{
|
|
if (!aPrimitive)
|
|
return;
|
|
|
|
nsCOMPtr<nsISupportsString> primitive =
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
|
|
if (!primitive)
|
|
return;
|
|
|
|
// We need to duplicate the input buffer, since the removal of linebreaks
|
|
// might reallocte it.
|
|
void* utf8 = moz_xmalloc(*aDataLen);
|
|
if (!utf8)
|
|
return;
|
|
memcpy(utf8, aDataBuff, *aDataLen);
|
|
int32_t signedLen = static_cast<int32_t>(*aDataLen);
|
|
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(kTextMime, &utf8, &signedLen);
|
|
*aDataLen = signedLen;
|
|
|
|
nsAutoString str(NS_ConvertUTF8toUTF16(reinterpret_cast<const char*>(utf8), *aDataLen));
|
|
free(utf8);
|
|
*aDataLen = str.Length() * sizeof(char16_t);
|
|
primitive->SetData(str);
|
|
NS_ADDREF(*aPrimitive = primitive);
|
|
}
|
|
|
|
|
|
//
|
|
// CreateDataFromPrimitive
|
|
//
|
|
// Given a nsISupports* primitive and the flavor it represents, creates a new data
|
|
// buffer with the data in it. This data will be null terminated, but the length
|
|
// parameter does not reflect that.
|
|
//
|
|
void
|
|
nsPrimitiveHelpers :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive,
|
|
void** aDataBuff, uint32_t aDataLen )
|
|
{
|
|
if ( !aDataBuff )
|
|
return;
|
|
|
|
*aDataBuff = nullptr;
|
|
|
|
if ( strcmp(aFlavor,kTextMime) == 0 || strcmp(aFlavor,kCustomTypesMime) == 0) {
|
|
nsCOMPtr<nsISupportsCString> plainText ( do_QueryInterface(aPrimitive) );
|
|
if ( plainText ) {
|
|
nsAutoCString data;
|
|
plainText->GetData ( data );
|
|
*aDataBuff = ToNewCString(data);
|
|
}
|
|
}
|
|
else {
|
|
nsCOMPtr<nsISupportsString> doubleByteText ( do_QueryInterface(aPrimitive) );
|
|
if ( doubleByteText ) {
|
|
nsAutoString data;
|
|
doubleByteText->GetData ( data );
|
|
*aDataBuff = ToNewUnicode(data);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// ConvertPlatformToDOMLinebreaks
|
|
//
|
|
// Given some data, convert from the platform linebreaks into the LF expected by the
|
|
// DOM. This will attempt to convert the data in place, but the buffer may still need to
|
|
// be reallocated regardless (disposing the old buffer is taken care of internally, see
|
|
// the note below).
|
|
//
|
|
// NOTE: this assumes that it can use 'free' to dispose of the old buffer.
|
|
//
|
|
nsresult
|
|
nsLinebreakHelpers :: ConvertPlatformToDOMLinebreaks ( const char* inFlavor, void** ioData,
|
|
int32_t* ioLengthInBytes )
|
|
{
|
|
NS_ASSERTION ( ioData && *ioData && ioLengthInBytes, "Bad Params");
|
|
if ( !(ioData && *ioData && ioLengthInBytes) )
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
nsresult retVal = NS_OK;
|
|
|
|
if ( strcmp(inFlavor, kTextMime) == 0 || strcmp(inFlavor, kRTFMime) == 0) {
|
|
char* buffAsChars = reinterpret_cast<char*>(*ioData);
|
|
char* oldBuffer = buffAsChars;
|
|
retVal = nsLinebreakConverter::ConvertLineBreaksInSitu ( &buffAsChars, nsLinebreakConverter::eLinebreakAny,
|
|
nsLinebreakConverter::eLinebreakContent,
|
|
*ioLengthInBytes, ioLengthInBytes );
|
|
if ( NS_SUCCEEDED(retVal) ) {
|
|
if ( buffAsChars != oldBuffer ) // check if buffer was reallocated
|
|
free ( oldBuffer );
|
|
*ioData = buffAsChars;
|
|
}
|
|
}
|
|
else if ( strcmp(inFlavor, "image/jpeg") == 0 ) {
|
|
// I'd assume we don't want to do anything for binary data....
|
|
}
|
|
else {
|
|
char16_t* buffAsUnichar = reinterpret_cast<char16_t*>(*ioData);
|
|
char16_t* oldBuffer = buffAsUnichar;
|
|
int32_t newLengthInChars;
|
|
retVal = nsLinebreakConverter::ConvertUnicharLineBreaksInSitu ( &buffAsUnichar, nsLinebreakConverter::eLinebreakAny,
|
|
nsLinebreakConverter::eLinebreakContent,
|
|
*ioLengthInBytes / sizeof(char16_t), &newLengthInChars );
|
|
if ( NS_SUCCEEDED(retVal) ) {
|
|
if ( buffAsUnichar != oldBuffer ) // check if buffer was reallocated
|
|
free ( oldBuffer );
|
|
*ioData = buffAsUnichar;
|
|
*ioLengthInBytes = newLengthInChars * sizeof(char16_t);
|
|
}
|
|
}
|
|
|
|
return retVal;
|
|
|
|
} // ConvertPlatformToDOMLinebreaks
|