Backed out changeset a668ab2d8dd3 (bug 1043853) for bustage

This commit is contained in:
Wes Kocher 2014-08-01 14:25:10 -07:00
parent 6137b7ed31
commit c3f05774be
5 changed files with 62 additions and 94 deletions

View File

@ -54,11 +54,10 @@
#include "nsScriptNameSpaceManager.h"
#include "StructuredCloneTags.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/ErrorEvent.h"
#include "mozilla/dom/ImageDataBinding.h"
#include "mozilla/dom/ImageData.h"
#include "mozilla/dom/StructuredClone.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/ImageDataBinding.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "nsAXPCNativeCallContext.h"
#include "mozilla/CycleCollectedJSRuntime.h"
@ -2812,7 +2811,25 @@ NS_DOMReadStructuredClone(JSContext* cx,
void* closure)
{
if (tag == SCTAG_DOM_IMAGEDATA) {
return ReadStructuredCloneImageData(cx, reader);
// Read the information out of the stream.
uint32_t width, height;
JS::Rooted<JS::Value> dataArray(cx);
if (!JS_ReadUint32Pair(reader, &width, &height) ||
!JS_ReadTypedArray(reader, &dataArray)) {
return nullptr;
}
MOZ_ASSERT(dataArray.isObject());
// Protect the result from a moving GC in ~nsRefPtr.
JS::Rooted<JSObject*> result(cx);
{
// Construct the ImageData.
nsRefPtr<ImageData> imageData = new ImageData(width, height,
dataArray.toObject());
// Wrap it in a JS::Value.
result = imageData->WrapObject(cx);
}
return result;
} else if (tag == SCTAG_DOM_WEBCRYPTO_KEY) {
nsIGlobalObject *global = xpc::GetNativeForGlobal(JS::CurrentGlobalOrNull(cx));
if (!global) {
@ -2846,7 +2863,17 @@ NS_DOMWriteStructuredClone(JSContext* cx,
// Handle ImageData cloning
ImageData* imageData;
if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageData, obj, imageData))) {
return WriteStructuredCloneImageData(cx, writer, imageData);
// Prepare the ImageData internals.
uint32_t width = imageData->Width();
uint32_t height = imageData->Height();
JS::Rooted<JSObject*> dataArray(cx, imageData->GetDataObject());
// Write the internals to the stream.
JSAutoCompartment ac(cx, dataArray);
JS::Rooted<JS::Value> arrayValue(cx, JS::ObjectValue(*dataArray));
return JS_WriteUint32Pair(writer, SCTAG_DOM_IMAGEDATA, 0) &&
JS_WriteUint32Pair(writer, width, height) &&
JS_WriteTypedArray(writer, arrayValue);
}
// Handle Key cloning

View File

@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/dom/StructuredClone.h"
#include "js/StructuredClone.h"
#include "mozilla/dom/ImageData.h"
#include "mozilla/dom/StructuredCloneTags.h"
namespace mozilla {
namespace dom {
JSObject*
ReadStructuredCloneImageData(JSContext* aCx, JSStructuredCloneReader* aReader)
{
// Read the information out of the stream.
uint32_t width, height;
JS::Rooted<JS::Value> dataArray(aCx);
if (!JS_ReadUint32Pair(aReader, &width, &height) ||
!JS_ReadTypedArray(aReader, &dataArray)) {
return nullptr;
}
MOZ_ASSERT(dataArray.isObject());
// Protect the result from a moving GC in ~nsRefPtr.
JS::Rooted<JSObject*> result(aCx);
{
// Construct the ImageData.
nsRefPtr<ImageData> imageData = new ImageData(width, height,
dataArray.toObject());
// Wrap it in a JS::Value.
result = imageData->WrapObject(aCx);
}
return result;
}
bool
WriteStructuredCloneImageData(JSContext* aCx, JSStructuredCloneWriter* aWriter,
ImageData* aImageData)
{
uint32_t width = aImageData->Width();
uint32_t height = aImageData->Height();
JS::Rooted<JSObject*> dataArray(aCx, aImageData->GetDataObject());
JSAutoCompartment ac(aCx, dataArray);
JS::Rooted<JS::Value> arrayValue(aCx, JS::ObjectValue(*dataArray));
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) &&
JS_WriteUint32Pair(aWriter, width, height) &&
JS_WriteTypedArray(aWriter, arrayValue);
}
} // namespace dom
} // namespace mozilla

View File

@ -1,25 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
class JSObject;
struct JSContext;
struct JSStructuredCloneReader;
struct JSStructuredCloneWriter;
namespace mozilla {
namespace dom {
class ImageData;
JSObject*
ReadStructuredCloneImageData(JSContext* aCx, JSStructuredCloneReader* aReader);
bool
WriteStructuredCloneImageData(JSContext* aCx, JSStructuredCloneWriter* aWriter,
ImageData* aImageData);
} // namespace dom
} // namespace mozilla

View File

@ -30,7 +30,6 @@ EXPORTS.mozilla.dom += [
'OwningNonNull.h',
'PrimitiveConversions.h',
'RootedDictionary.h',
'StructuredClone.h',
'ToJSValue.h',
'TypedArray.h',
'UnionMember.h',
@ -82,10 +81,6 @@ UNIFIED_SOURCES += [
'ToJSValue.cpp',
]
SOURCES += [
'StructuredClone.cpp',
]
include('/ipc/chromium/chromium-config.mozbuild')
if CONFIG['MOZ_AUDIO_CHANNEL_MANAGER']:

View File

@ -48,7 +48,6 @@
#include "mozilla/dom/MessageEventBinding.h"
#include "mozilla/dom/MessagePortList.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/StructuredClone.h"
#include "mozilla/dom/WorkerBinding.h"
#include "mozilla/Preferences.h"
#include "nsAlgorithm.h"
@ -353,7 +352,25 @@ struct WorkerStructuredCloneCallbacks
// See if the object is an ImageData.
else if (aTag == SCTAG_DOM_IMAGEDATA) {
MOZ_ASSERT(!aData);
return ReadStructuredCloneImageData(aCx, aReader);
// Read the information out of the stream.
uint32_t width, height;
JS::Rooted<JS::Value> dataArray(aCx);
if (!JS_ReadUint32Pair(aReader, &width, &height) ||
!JS_ReadTypedArray(aReader, &dataArray))
{
return nullptr;
}
MOZ_ASSERT(dataArray.isObject());
{
// Construct the ImageData.
nsRefPtr<ImageData> imageData = new ImageData(width, height,
dataArray.toObject());
// Wrap it in a JS::Value, protected from a moving GC during ~nsRefPtr.
result = imageData->WrapObject(aCx);
}
return result;
}
Error(aCx, 0);
@ -401,7 +418,17 @@ struct WorkerStructuredCloneCallbacks
{
ImageData* imageData = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageData, aObj, imageData))) {
return WriteStructuredCloneImageData(aCx, aWriter, imageData);
// Prepare the ImageData internals.
uint32_t width = imageData->Width();
uint32_t height = imageData->Height();
JS::Rooted<JSObject*> dataArray(aCx, imageData->GetDataObject());
// Write the internals to the stream.
JSAutoCompartment ac(aCx, dataArray);
JS::Rooted<JS::Value> arrayValue(aCx, JS::ObjectValue(*dataArray));
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEDATA, 0) &&
JS_WriteUint32Pair(aWriter, width, height) &&
JS_WriteTypedArray(aWriter, arrayValue);
}
}