2012-03-16 13:44:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 et tw=78: */
|
|
|
|
/* 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/ImageData.h"
|
|
|
|
|
2014-01-28 17:04:40 +04:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2013-09-10 19:29:43 +04:00
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
2012-10-22 21:08:52 +04:00
|
|
|
#include "mozilla/dom/ImageDataBinding.h"
|
2012-03-16 13:44:08 +04:00
|
|
|
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(ImageData)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(ImageData)
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(ImageData)
|
|
|
|
|
2012-03-16 13:44:08 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ImageData)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ImageData)
|
2012-06-11 03:44:50 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mData)
|
2012-03-16 13:44:08 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ImageData)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ImageData)
|
|
|
|
tmp->DropData();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-01-28 17:04:40 +04:00
|
|
|
//static
|
2014-08-28 02:43:55 +04:00
|
|
|
already_AddRefed<ImageData>
|
2014-01-28 17:04:40 +04:00
|
|
|
ImageData::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const uint32_t aWidth,
|
|
|
|
const uint32_t aHeight,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (aWidth == 0 || aHeight == 0) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
CheckedInt<uint32_t> length = CheckedInt<uint32_t>(aWidth) * aHeight * 4;
|
|
|
|
if (!length.isValid()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-16 22:08:00 +04:00
|
|
|
js::AssertSameCompartment(aGlobal.Context(), aGlobal.Get());
|
|
|
|
JSObject* data = Uint8ClampedArray::Create(aGlobal.Context(),
|
2014-01-28 17:04:40 +04:00
|
|
|
length.value());
|
|
|
|
if (!data) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-08-28 02:43:55 +04:00
|
|
|
nsRefPtr<ImageData> imageData = new ImageData(aWidth, aHeight, *data);
|
|
|
|
return imageData.forget();
|
2014-01-28 17:04:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
2014-08-28 02:43:55 +04:00
|
|
|
already_AddRefed<ImageData>
|
2014-01-28 17:04:40 +04:00
|
|
|
ImageData::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const Uint8ClampedArray& aData,
|
|
|
|
const uint32_t aWidth,
|
|
|
|
const Optional<uint32_t>& aHeight,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-28 01:32:41 +04:00
|
|
|
aData.ComputeLengthAndData();
|
|
|
|
|
2014-01-28 17:04:40 +04:00
|
|
|
uint32_t length = aData.Length();
|
|
|
|
if (length == 0 || length % 4) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
length /= 4;
|
|
|
|
if (aWidth == 0) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
uint32_t height = length / aWidth;
|
|
|
|
if (length != aWidth * height ||
|
|
|
|
(aHeight.WasPassed() && aHeight.Value() != height)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-08-28 02:43:55 +04:00
|
|
|
nsRefPtr<ImageData> imageData = new ImageData(aWidth, height, *aData.Obj());
|
|
|
|
return imageData.forget();
|
2014-01-28 17:04:40 +04:00
|
|
|
}
|
|
|
|
|
2012-03-16 13:44:08 +04:00
|
|
|
void
|
|
|
|
ImageData::HoldData()
|
|
|
|
{
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2012-03-16 13:44:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ImageData::DropData()
|
|
|
|
{
|
|
|
|
if (mData) {
|
2013-04-03 05:14:24 +04:00
|
|
|
mData = nullptr;
|
2013-08-17 00:10:17 +04:00
|
|
|
mozilla::DropJSObjects(this);
|
2012-03-16 13:44:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 00:56:42 +03:00
|
|
|
bool
|
Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, Codegen.py, and
StructuredClone.cpp. The rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/WrapObject\((JSContext *\* *(?:aCx|cx)),(\s*)(JS::MutableHandle<JSObject\*> aReflector)/WrapObject(\1,\2JS::Handle<JSObject*> aGivenProto,\2\3/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx)), this, aReflector/\1, this, aGivenProto, aReflector/'
2015-03-19 17:13:32 +03:00
|
|
|
ImageData::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
|
2012-10-22 21:08:52 +04:00
|
|
|
{
|
Bug 1117172 part 2. Change the non-wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, Codegen.py, and
StructuredClone.cpp. The rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/WrapObject\((JSContext *\* *(?:aCx|cx)),(\s*)(JS::MutableHandle<JSObject\*> aReflector)/WrapObject(\1,\2JS::Handle<JSObject*> aGivenProto,\2\3/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx)), this, aReflector/\1, this, aGivenProto, aReflector/'
2015-03-19 17:13:32 +03:00
|
|
|
return ImageDataBinding::Wrap(aCx, this, aGivenProto, aReflector);
|
2012-10-22 21:08:52 +04:00
|
|
|
}
|
|
|
|
|
2012-03-16 13:44:08 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|