Bug 743615 - Handle ImageData in the main thread runtime callbacks. r=bent

This commit is contained in:
Bobby Holley 2012-04-24 12:58:07 +02:00
Родитель c1fbbaa1d6
Коммит b495532ca4
2 изменённых файлов: 63 добавлений и 2 удалений

Просмотреть файл

@ -44,9 +44,15 @@ namespace dom {
enum StructuredCloneTags {
SCTAG_BASE = JS_SCTAG_USER_MIN,
// These tags are used only for main thread structured clone.
SCTAG_DOM_BLOB,
SCTAG_DOM_FILE,
SCTAG_DOM_FILELIST,
// These tags are used for both main thread and workers.
SCTAG_DOM_IMAGEDATA,
SCTAG_DOM_MAX
};

Просмотреть файл

@ -86,6 +86,8 @@
#include "WrapperFactory.h"
#include "nsGlobalWindow.h"
#include "nsScriptNameSpaceManager.h"
#include "StructuredCloneTags.h"
#include "mozilla/dom/ImageData.h"
#include "nsJSPrincipals.h"
@ -113,6 +115,7 @@
#include "sampler.h"
using namespace mozilla;
using namespace mozilla::dom;
const size_t gStackSize = 8192;
@ -3610,7 +3613,36 @@ NS_DOMReadStructuredClone(JSContext* cx,
uint32_t data,
void* closure)
{
// We don't currently support any extensions to structured cloning.
if (tag == SCTAG_DOM_IMAGEDATA) {
// Read the information out of the stream.
uint32_t width, height;
JS::Value dataArray;
if (!JS_ReadUint32Pair(reader, &width, &height) ||
!JS_ReadTypedArray(reader, &dataArray)) {
return nsnull;
}
MOZ_ASSERT(dataArray.isObject());
// Construct the ImageData.
nsCOMPtr<nsIDOMImageData> imageData = new ImageData(width, height,
dataArray.toObject());
// Wrap it in a jsval.
JSObject* global = JS_GetGlobalForScopeChain(cx);
if (!global) {
return nsnull;
}
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
JS::Value val;
nsresult rv =
nsContentUtils::WrapNative(cx, global, imageData, &val,
getter_AddRefs(wrapper));
if (NS_FAILED(rv)) {
return nsnull;
}
return val.toObjectOrNull();
}
// Don't know what this is. Bail.
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
return nsnull;
}
@ -3621,7 +3653,30 @@ NS_DOMWriteStructuredClone(JSContext* cx,
JSObject* obj,
void *closure)
{
// We don't currently support any extensions to structured cloning.
nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
nsISupports *native = wrappedNative ? wrappedNative->Native() : nsnull;
nsCOMPtr<nsIDOMImageData> imageData = do_QueryInterface(native);
if (imageData) {
// Prepare the ImageData internals.
PRUint32 width, height;
JS::Value dataArray;
if (NS_FAILED(imageData->GetWidth(&width)) ||
NS_FAILED(imageData->GetHeight(&height)) ||
NS_FAILED(imageData->GetData(cx, &dataArray)))
{
return false;
}
// Write the internals to the stream.
return JS_WriteUint32Pair(writer, SCTAG_DOM_IMAGEDATA, 0) &&
JS_WriteUint32Pair(writer, width, height) &&
JS_WriteTypedArray(writer, dataArray);
}
// Don't know what this is. Bail.
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_DOM_DATA_CLONE_ERR);
return JS_FALSE;
}