OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/html/ImageData.h" | 30 #include "core/html/ImageData.h" |
31 | 31 |
32 #include "RuntimeEnabledFeatures.h" | 32 #include "RuntimeEnabledFeatures.h" |
33 #include "bindings/v8/ExceptionState.h" | 33 #include "bindings/v8/ExceptionState.h" |
34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 PassRefPtr<ImageData> ImageData::create(const IntSize& size) | 38 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(const IntSize& size) |
39 { | 39 { |
40 Checked<int, RecordOverflow> dataSize = 4; | 40 Checked<int, RecordOverflow> dataSize = 4; |
41 dataSize *= size.width(); | 41 dataSize *= size.width(); |
42 dataSize *= size.height(); | 42 dataSize *= size.height(); |
43 if (dataSize.hasOverflowed()) | 43 if (dataSize.hasOverflowed()) |
44 return nullptr; | 44 return nullptr; |
45 | 45 |
46 return adoptRef(new ImageData(size)); | 46 return adoptRefWillBeNoop(new ImageData(size)); |
47 } | 47 } |
48 | 48 |
49 PassRefPtr<ImageData> ImageData::create(const IntSize& size, PassRefPtr<Uint8Cla
mpedArray> byteArray) | 49 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(const IntSize& size, PassRef
Ptr<Uint8ClampedArray> byteArray) |
50 { | 50 { |
51 Checked<int, RecordOverflow> dataSize = 4; | 51 Checked<int, RecordOverflow> dataSize = 4; |
52 dataSize *= size.width(); | 52 dataSize *= size.width(); |
53 dataSize *= size.height(); | 53 dataSize *= size.height(); |
54 if (dataSize.hasOverflowed()) | 54 if (dataSize.hasOverflowed()) |
55 return nullptr; | 55 return nullptr; |
56 | 56 |
57 if (dataSize.unsafeGet() < 0 | 57 if (dataSize.unsafeGet() < 0 |
58 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) | 58 || static_cast<unsigned>(dataSize.unsafeGet()) > byteArray->length()) |
59 return nullptr; | 59 return nullptr; |
60 | 60 |
61 return adoptRef(new ImageData(size, byteArray)); | 61 return adoptRefWillBeNoop(new ImageData(size, byteArray)); |
62 } | 62 } |
63 | 63 |
64 PassRefPtr<ImageData> ImageData::create(unsigned width, unsigned height, Excepti
onState& exceptionState) | 64 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(unsigned width, unsigned hei
ght, ExceptionState& exceptionState) |
65 { | 65 { |
66 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | 66 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { |
67 exceptionState.throwTypeError("Illegal constructor"); | 67 exceptionState.throwTypeError("Illegal constructor"); |
68 return nullptr; | 68 return nullptr; |
69 } | 69 } |
70 if (!width || !height) { | 70 if (!width || !height) { |
71 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is zero or not a number.", width ? "height" : "width")); | 71 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is zero or not a number.", width ? "height" : "width")); |
72 return nullptr; | 72 return nullptr; |
73 } | 73 } |
74 | 74 |
75 Checked<unsigned, RecordOverflow> dataSize = 4; | 75 Checked<unsigned, RecordOverflow> dataSize = 4; |
76 dataSize *= width; | 76 dataSize *= width; |
77 dataSize *= height; | 77 dataSize *= height; |
78 if (dataSize.hasOverflowed()) { | 78 if (dataSize.hasOverflowed()) { |
79 exceptionState.throwDOMException(IndexSizeError, "The requested image si
ze exceeds the supported range."); | 79 exceptionState.throwDOMException(IndexSizeError, "The requested image si
ze exceeds the supported range."); |
80 return nullptr; | 80 return nullptr; |
81 } | 81 } |
82 | 82 |
83 RefPtr<ImageData> imageData = adoptRef(new ImageData(IntSize(width, height))
); | 83 RefPtrWillBeRawPtr<ImageData> imageData = adoptRefWillBeNoop(new ImageData(I
ntSize(width, height))); |
84 imageData->data()->zeroFill(); | 84 imageData->data()->zeroFill(); |
85 return imageData.release(); | 85 return imageData.release(); |
86 } | 86 } |
87 | 87 |
88 PassRefPtr<ImageData> ImageData::create(Uint8ClampedArray* data, unsigned width,
unsigned height, ExceptionState& exceptionState) | 88 PassRefPtrWillBeRawPtr<ImageData> ImageData::create(Uint8ClampedArray* data, uns
igned width, unsigned height, ExceptionState& exceptionState) |
89 { | 89 { |
90 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { | 90 if (!RuntimeEnabledFeatures::imageDataConstructorEnabled()) { |
91 exceptionState.throwTypeError("Illegal constructor"); | 91 exceptionState.throwTypeError("Illegal constructor"); |
92 return nullptr; | 92 return nullptr; |
93 } | 93 } |
94 if (!data) { | 94 if (!data) { |
95 exceptionState.throwTypeError("Expected a Uint8ClampedArray as first arg
ument."); | 95 exceptionState.throwTypeError("Expected a Uint8ClampedArray as first arg
ument."); |
96 return nullptr; | 96 return nullptr; |
97 } | 97 } |
98 if (!width) { | 98 if (!width) { |
(...skipping 15 matching lines...) Expand all Loading... |
114 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); | 114 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not a multiple of (4 * width)."); |
115 return nullptr; | 115 return nullptr; |
116 } | 116 } |
117 if (!height) { | 117 if (!height) { |
118 height = length / width; | 118 height = length / width; |
119 } else if (height != length / width) { | 119 } else if (height != length / width) { |
120 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); | 120 exceptionState.throwDOMException(IndexSizeError, "The input data byte le
ngth is not equal to (4 * width * height)."); |
121 return nullptr; | 121 return nullptr; |
122 } | 122 } |
123 | 123 |
124 return adoptRef(new ImageData(IntSize(width, height), data)); | 124 return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data)); |
125 } | 125 } |
126 | 126 |
127 ImageData::ImageData(const IntSize& size) | 127 ImageData::ImageData(const IntSize& size) |
128 : m_size(size) | 128 : m_size(size) |
129 , m_data(Uint8ClampedArray::createUninitialized(size.width() * size.height()
* 4)) | 129 , m_data(Uint8ClampedArray::createUninitialized(size.width() * size.height()
* 4)) |
130 { | 130 { |
131 ScriptWrappable::init(this); | 131 ScriptWrappable::init(this); |
132 } | 132 } |
133 | 133 |
134 ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra
y) | 134 ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra
y) |
135 : m_size(size) | 135 : m_size(size) |
136 , m_data(byteArray) | 136 , m_data(byteArray) |
137 { | 137 { |
138 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); | 138 ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.h
eight() * 4) <= m_data->length()); |
139 ScriptWrappable::init(this); | 139 ScriptWrappable::init(this); |
140 } | 140 } |
141 | 141 |
142 } | 142 } |
143 | 143 |
OLD | NEW |