зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1350254 part 2. Switch ImageData to [Serializable]. r=baku
Differential Revision: https://phabricator.services.mozilla.com/D35716 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
68a52b3c30
Коммит
75224691ef
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "ImageContainer.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/BlobBinding.h"
|
||||
#include "mozilla/dom/CryptoKey.h"
|
||||
#include "mozilla/dom/StructuredCloneBlob.h"
|
||||
|
@ -27,9 +28,6 @@
|
|||
#include "mozilla/dom/FormData.h"
|
||||
#include "mozilla/dom/ImageBitmap.h"
|
||||
#include "mozilla/dom/ImageBitmapBinding.h"
|
||||
#include "mozilla/dom/ImageData.h"
|
||||
#include "mozilla/dom/ImageDataBinding.h"
|
||||
#include "mozilla/dom/StructuredClone.h"
|
||||
#include "mozilla/dom/MessagePort.h"
|
||||
#include "mozilla/dom/MessagePortBinding.h"
|
||||
#include "mozilla/dom/OffscreenCanvas.h"
|
||||
|
@ -43,6 +41,7 @@
|
|||
#include "mozilla/dom/URLSearchParams.h"
|
||||
#include "mozilla/dom/URLSearchParamsBinding.h"
|
||||
#include "mozilla/dom/WebCryptoCommon.h"
|
||||
#include "mozilla/dom/WebIDLSerializable.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/ipc/BackgroundChild.h"
|
||||
#include "mozilla/ipc/BackgroundUtils.h"
|
||||
|
@ -349,8 +348,15 @@ JSObject* StructuredCloneHolder::ReadFullySerializableObjects(
|
|||
JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag) {
|
||||
AssertTagValues();
|
||||
|
||||
if (aTag == SCTAG_DOM_IMAGEDATA) {
|
||||
return ReadStructuredCloneImageData(aCx, aReader);
|
||||
nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
|
||||
if (!global) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WebIDLDeserializer deserializer =
|
||||
LookupDeserializer(StructuredCloneTags(aTag));
|
||||
if (deserializer) {
|
||||
return deserializer(aCx, global, aReader);
|
||||
}
|
||||
|
||||
if (aTag == SCTAG_DOM_WEBCRYPTO_KEY || aTag == SCTAG_DOM_URLSEARCHPARAMS ||
|
||||
|
@ -358,11 +364,6 @@ JSObject* StructuredCloneHolder::ReadFullySerializableObjects(
|
|||
aTag == SCTAG_DOM_DOMRECT || aTag == SCTAG_DOM_DOMRECT_READONLY ||
|
||||
aTag == SCTAG_DOM_DOMQUAD || aTag == SCTAG_DOM_DOMMATRIX ||
|
||||
aTag == SCTAG_DOM_DOMMATRIX_READONLY) {
|
||||
nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
|
||||
if (!global) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Prevent the return value from being trashed by a GC during ~nsRefPtr.
|
||||
JS::Rooted<JSObject*> result(aCx);
|
||||
{
|
||||
|
@ -500,14 +501,16 @@ bool StructuredCloneHolder::WriteFullySerializableObjects(
|
|||
JS::Handle<JSObject*> aObj) {
|
||||
AssertTagValues();
|
||||
|
||||
JS::Rooted<JSObject*> obj(aCx, aObj);
|
||||
// Window and Location are not serializable, so it's OK to just do a static
|
||||
// unwrap here.
|
||||
JS::Rooted<JSObject*> obj(aCx, js::CheckedUnwrapStatic(aObj));
|
||||
if (!obj) {
|
||||
return xpc::Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
}
|
||||
|
||||
// See if this is a ImageData object.
|
||||
{
|
||||
ImageData* imageData = nullptr;
|
||||
if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageData, &obj, imageData))) {
|
||||
return WriteStructuredCloneImageData(aCx, aWriter, imageData);
|
||||
}
|
||||
const DOMJSClass* domClass = GetDOMClass(obj);
|
||||
if (domClass && domClass->mSerializer) {
|
||||
return domClass->mSerializer(aCx, aWriter, obj);
|
||||
}
|
||||
|
||||
// Handle URLSearchParams cloning
|
||||
|
|
|
@ -1,59 +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.
|
||||
RefPtr<ImageData> imageData =
|
||||
new ImageData(width, height, dataArray.toObject());
|
||||
// Wrap it in a JS::Value.
|
||||
if (!imageData->WrapObject(aCx, nullptr, &result)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
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());
|
||||
if (!JS_WrapObject(aCx, &dataArray)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
|
@ -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
|
|
@ -50,7 +50,6 @@ EXPORTS.mozilla.dom += [
|
|||
'RootedDictionary.h',
|
||||
'SimpleGlobalObject.h',
|
||||
'SpiderMonkeyInterface.h',
|
||||
'StructuredClone.h',
|
||||
'ToJSValue.h',
|
||||
'TypedArray.h',
|
||||
'UnionMember.h',
|
||||
|
@ -116,10 +115,6 @@ UNIFIED_SOURCES += [
|
|||
'WebIDLGlobalNameHash.cpp',
|
||||
]
|
||||
|
||||
SOURCES += [
|
||||
'StructuredClone.cpp',
|
||||
]
|
||||
|
||||
# Some tests, including those for for maplike and setlike, require bindings
|
||||
# to be built, which means they must be included in libxul. This breaks the
|
||||
# "no test classes are exported" rule stated in the test/ directory, but it's
|
||||
|
|
|
@ -106,5 +106,34 @@ bool ImageData::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
|
|||
return ImageData_Binding::Wrap(aCx, this, aGivenProto, aReflector);
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<ImageData> ImageData::ReadStructuredClone(
|
||||
JSContext* aCx, nsIGlobalObject* aGlobal,
|
||||
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());
|
||||
|
||||
RefPtr<ImageData> imageData =
|
||||
new ImageData(width, height, dataArray.toObject());
|
||||
return imageData.forget();
|
||||
}
|
||||
|
||||
bool ImageData::WriteStructuredClone(JSContext* aCx,
|
||||
JSStructuredCloneWriter* aWriter) const {
|
||||
JS::Rooted<JS::Value> arrayValue(aCx, JS::ObjectValue(*GetDataObject()));
|
||||
if (!JS_WrapValue(aCx, &arrayValue)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return JS_WriteUint32Pair(aWriter, Width(), Height()) &&
|
||||
JS_WriteTypedArray(aWriter, arrayValue);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "js/RootingAPI.h"
|
||||
#include "js/StructuredClone.h"
|
||||
|
||||
class nsIGlobalObject;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -51,6 +54,13 @@ class ImageData final : public nsISupports {
|
|||
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
|
||||
JS::MutableHandle<JSObject*> aReflector);
|
||||
|
||||
//[Serializable] implementation
|
||||
static already_AddRefed<ImageData> ReadStructuredClone(
|
||||
JSContext* aCx, nsIGlobalObject* aGlobal,
|
||||
JSStructuredCloneReader* aReader);
|
||||
bool WriteStructuredClone(JSContext* aCx,
|
||||
JSStructuredCloneWriter* aWriter) const;
|
||||
|
||||
private:
|
||||
void HoldData();
|
||||
void DropData();
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
|
||||
[Constructor(unsigned long sw, unsigned long sh),
|
||||
Constructor(Uint8ClampedArray data, unsigned long sw, optional unsigned long sh),
|
||||
Exposed=(Window,Worker)]
|
||||
Exposed=(Window,Worker),
|
||||
Serializable]
|
||||
interface ImageData {
|
||||
[Constant]
|
||||
readonly attribute unsigned long width;
|
||||
|
|
Загрузка…
Ссылка в новой задаче