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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-22 21:08:52 +04:00
|
|
|
JSObject*
|
2014-04-09 02:27:18 +04:00
|
|
|
ImageData::WrapObject(JSContext* cx)
|
2012-10-22 21:08:52 +04:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-09 02:27:17 +04:00
|
|
|
return ImageDataBinding::Wrap(cx, this);
|
2012-10-22 21:08:52 +04:00
|
|
|
}
|
|
|
|
|
2012-03-16 13:44:08 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|