| Index: third_party/WebKit/Source/core/html/ImageData.cpp
|
| diff --git a/third_party/WebKit/Source/core/html/ImageData.cpp b/third_party/WebKit/Source/core/html/ImageData.cpp
|
| index 32726d5aef74e76fa1f9a1d4a83ba2c63ad13014..c13f5ba7dcf892a96064174070e958da69674b06 100644
|
| --- a/third_party/WebKit/Source/core/html/ImageData.cpp
|
| +++ b/third_party/WebKit/Source/core/html/ImageData.cpp
|
| @@ -99,6 +99,39 @@ ImageData* ImageData::create(unsigned width,
|
| return new ImageData(IntSize(width, height), byteArray);
|
| }
|
|
|
| +ImageData* ImageData::create(unsigned width,
|
| + unsigned height,
|
| + String colorSpace,
|
| + ExceptionState& exceptionState) {
|
| + if (!width || !height) {
|
| + exceptionState.throwDOMException(
|
| + IndexSizeError, String::format("The source %s is zero or not a number.",
|
| + width ? "height" : "width"));
|
| + return nullptr;
|
| + }
|
| +
|
| + CheckedNumeric<unsigned> dataSize = 4;
|
| + dataSize *= width;
|
| + dataSize *= height;
|
| + if (!dataSize.IsValid() || static_cast<int>(width) < 0 ||
|
| + static_cast<int>(height) < 0) {
|
| + exceptionState.throwDOMException(
|
| + IndexSizeError,
|
| + "The requested image size exceeds the supported range.");
|
| + return nullptr;
|
| + }
|
| +
|
| + DOMUint8ClampedArray* byteArray =
|
| + DOMUint8ClampedArray::createOrNull(dataSize.ValueOrDie());
|
| + if (!byteArray) {
|
| + exceptionState.throwDOMException(V8Error,
|
| + "Out of memory at ImageData creation");
|
| + return nullptr;
|
| + }
|
| +
|
| + return new ImageData(IntSize(width, height), byteArray, colorSpace);
|
| +}
|
| +
|
| bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data,
|
| unsigned width,
|
| unsigned& lengthInPixels,
|
| @@ -131,6 +164,23 @@ bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data,
|
| return true;
|
| }
|
|
|
| +bool ImageData::validateConstructorArguments(DOMUint8ClampedArray* data,
|
| + unsigned width,
|
| + unsigned& lengthInPixels,
|
| + String colorSpace,
|
| + ExceptionState& exceptionState) {
|
| + if (colorSpace != kLegacyImageDataColorSpaceName &&
|
| + colorSpace != kSRGBImageDataColorSpaceName) {
|
| + exceptionState.throwDOMException(NotSupportedError,
|
| + "The input color space is not supported "
|
| + "in Uint8ClampedArraye-backed image "
|
| + "data.");
|
| + return false;
|
| + }
|
| + return validateConstructorArguments(data, width, lengthInPixels,
|
| + exceptionState);
|
| +}
|
| +
|
| ImageData* ImageData::create(DOMUint8ClampedArray* data,
|
| unsigned width,
|
| ExceptionState& exceptionState) {
|
| @@ -167,6 +217,31 @@ ImageData* ImageData::create(DOMUint8ClampedArray* data,
|
| return new ImageData(IntSize(width, height), data);
|
| }
|
|
|
| +ImageData* ImageData::create(DOMUint8ClampedArray* data,
|
| + unsigned width,
|
| + unsigned height,
|
| + String colorSpace,
|
| + ExceptionState& exceptionState) {
|
| + unsigned lengthInPixels = 0;
|
| + if (!validateConstructorArguments(data, width, lengthInPixels, colorSpace,
|
| + exceptionState)) {
|
| + DCHECK(exceptionState.hadException());
|
| + return nullptr;
|
| + }
|
| + DCHECK_GT(lengthInPixels, 0u);
|
| + DCHECK_GT(width, 0u);
|
| + if (height != lengthInPixels / width) {
|
| + exceptionState.throwDOMException(
|
| + IndexSizeError,
|
| + "The input data byte length is not equal to (4 * width * height).");
|
| + return nullptr;
|
| + }
|
| + return new ImageData(IntSize(width, height), data, colorSpace);
|
| +}
|
| +
|
| +// TODO(zakerinasab): Fix this when ImageBitmap color correction code is landed.
|
| +// Tip: If the source Image Data has a color space, createImageBitmap must
|
| +// respect this color space even when no color space tag is passed to it.
|
| ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState,
|
| EventTarget& eventTarget,
|
| Optional<IntRect> cropRect,
|
| @@ -211,8 +286,10 @@ v8::Local<v8::Object> ImageData::associateWithWrapper(
|
| return wrapper;
|
| }
|
|
|
| -ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray)
|
| - : m_size(size), m_data(byteArray) {
|
| +ImageData::ImageData(const IntSize& size,
|
| + DOMUint8ClampedArray* byteArray,
|
| + String colorSpace)
|
| + : m_size(size), m_colorSpace(colorSpace), m_data(byteArray) {
|
| DCHECK_GE(size.width(), 0);
|
| DCHECK_GE(size.height(), 0);
|
| SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <=
|
|
|