OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008, 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2010 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/core/v8/V8XMLHttpRequest.h" | 32 #include "bindings/core/v8/V8XMLHttpRequest.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionMessages.h" | 34 #include "bindings/core/v8/ExceptionMessages.h" |
35 #include "bindings/core/v8/ExceptionState.h" | 35 #include "bindings/core/v8/ExceptionState.h" |
| 36 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 37 #include "bindings/core/v8/V8ArrayBufferView.h" |
36 #include "bindings/core/v8/V8Binding.h" | 38 #include "bindings/core/v8/V8Binding.h" |
37 #include "bindings/core/v8/V8Blob.h" | 39 #include "bindings/core/v8/V8Blob.h" |
38 #include "bindings/core/v8/V8Document.h" | 40 #include "bindings/core/v8/V8Document.h" |
39 #include "bindings/core/v8/V8FormData.h" | 41 #include "bindings/core/v8/V8FormData.h" |
40 #include "bindings/core/v8/V8HTMLDocument.h" | 42 #include "bindings/core/v8/V8HTMLDocument.h" |
41 #include "bindings/core/v8/V8ReadableStream.h" | 43 #include "bindings/core/v8/V8ReadableStream.h" |
42 #include "bindings/core/v8/V8Stream.h" | 44 #include "bindings/core/v8/V8Stream.h" |
43 #include "bindings/core/v8/custom/V8ArrayBufferCustom.h" | |
44 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h" | |
45 #include "core/dom/Document.h" | 45 #include "core/dom/Document.h" |
46 #include "core/inspector/InspectorInstrumentation.h" | 46 #include "core/inspector/InspectorInstrumentation.h" |
47 #include "core/streams/ReadableStream.h" | 47 #include "core/streams/ReadableStream.h" |
48 #include "core/streams/Stream.h" | 48 #include "core/streams/Stream.h" |
49 #include "core/workers/WorkerGlobalScope.h" | 49 #include "core/workers/WorkerGlobalScope.h" |
50 #include "core/xml/XMLHttpRequest.h" | 50 #include "core/xml/XMLHttpRequest.h" |
51 #include "wtf/ArrayBuffer.h" | |
52 #include <v8.h> | 51 #include <v8.h> |
53 | 52 |
54 namespace blink { | 53 namespace blink { |
55 | 54 |
56 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu
e>& info) | 55 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu
e>& info) |
57 { | 56 { |
58 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); | 57 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); |
59 | 58 |
60 RefPtr<SecurityOrigin> securityOrigin; | 59 RefPtr<SecurityOrigin> securityOrigin; |
61 if (context->isDocument()) { | 60 if (context->isDocument()) { |
62 DOMWrapperWorld& world = DOMWrapperWorld::current(info.GetIsolate()); | 61 DOMWrapperWorld& world = DOMWrapperWorld::current(info.GetIsolate()); |
63 if (world.isIsolatedWorld()) | 62 if (world.isIsolatedWorld()) |
64 securityOrigin = world.isolatedWorldSecurityOrigin(); | 63 securityOrigin = world.isolatedWorldSecurityOrigin(); |
65 } | 64 } |
66 | 65 |
67 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(c
ontext, securityOrigin); | 66 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(c
ontext, securityOrigin); |
68 | 67 |
69 v8::Handle<v8::Object> wrapper = info.Holder(); | 68 v8::Handle<v8::Object> wrapper = info.Holder(); |
70 V8DOMWrapper::associateObjectWithWrapper<V8XMLHttpRequest>(xmlHttpRequest.re
lease(), &wrapperTypeInfo, wrapper, info.GetIsolate()); | 69 xmlHttpRequest->associateWithWrapper(xmlHttpRequest->wrapperTypeInfo(), wrap
per, info.GetIsolate()); |
71 info.GetReturnValue().Set(wrapper); | 70 info.GetReturnValue().Set(wrapper); |
72 } | 71 } |
73 | 72 |
74 void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallb
ackInfo<v8::Value>& info) | 73 void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallb
ackInfo<v8::Value>& info) |
75 { | 74 { |
76 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder()); | 75 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder()); |
77 ExceptionState exceptionState(ExceptionState::GetterContext, "responseText",
"XMLHttpRequest", info.Holder(), info.GetIsolate()); | 76 ExceptionState exceptionState(ExceptionState::GetterContext, "responseText",
"XMLHttpRequest", info.Holder(), info.GetIsolate()); |
78 ScriptString text = xmlHttpRequest->responseText(exceptionState); | 77 ScriptString text = xmlHttpRequest->responseText(exceptionState); |
79 if (exceptionState.throwIfNeeded()) | 78 if (exceptionState.throwIfNeeded()) |
80 return; | 79 return; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 140 |
142 case XMLHttpRequest::ResponseTypeStream: | 141 case XMLHttpRequest::ResponseTypeStream: |
143 { | 142 { |
144 ReadableStream* stream = xmlHttpRequest->responseStream(); | 143 ReadableStream* stream = xmlHttpRequest->responseStream(); |
145 v8SetReturnValueFast(info, stream, xmlHttpRequest); | 144 v8SetReturnValueFast(info, stream, xmlHttpRequest); |
146 return; | 145 return; |
147 } | 146 } |
148 | 147 |
149 case XMLHttpRequest::ResponseTypeArrayBuffer: | 148 case XMLHttpRequest::ResponseTypeArrayBuffer: |
150 { | 149 { |
151 ArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(); | 150 DOMArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(); |
152 if (arrayBuffer) { | |
153 arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationOb
server::instanceTemplate()); | |
154 } | |
155 v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest); | 151 v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest); |
156 return; | 152 return; |
157 } | 153 } |
158 } | 154 } |
159 } | 155 } |
160 | 156 |
161 void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value
>& info) | 157 void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value
>& info) |
162 { | 158 { |
163 // Four cases: | 159 // Four cases: |
164 // open(method, url) | 160 // open(method, url) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 Blob* blob = V8Blob::toImpl(object); | 229 Blob* blob = V8Blob::toImpl(object); |
234 ASSERT(blob); | 230 ASSERT(blob); |
235 xmlHttpRequest->send(blob, exceptionState); | 231 xmlHttpRequest->send(blob, exceptionState); |
236 } else if (V8FormData::hasInstance(arg, info.GetIsolate())) { | 232 } else if (V8FormData::hasInstance(arg, info.GetIsolate())) { |
237 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); | 233 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); |
238 DOMFormData* domFormData = V8FormData::toImpl(object); | 234 DOMFormData* domFormData = V8FormData::toImpl(object); |
239 ASSERT(domFormData); | 235 ASSERT(domFormData); |
240 xmlHttpRequest->send(domFormData, exceptionState); | 236 xmlHttpRequest->send(domFormData, exceptionState); |
241 } else if (V8ArrayBuffer::hasInstance(arg, info.GetIsolate())) { | 237 } else if (V8ArrayBuffer::hasInstance(arg, info.GetIsolate())) { |
242 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); | 238 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); |
243 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(object); | 239 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(object); |
244 ASSERT(arrayBuffer); | 240 ASSERT(arrayBuffer); |
245 xmlHttpRequest->send(arrayBuffer, exceptionState); | 241 xmlHttpRequest->send(arrayBuffer->buffer(), exceptionState); |
246 } else if (V8ArrayBufferView::hasInstance(arg, info.GetIsolate())) { | 242 } else if (V8ArrayBufferView::hasInstance(arg, info.GetIsolate())) { |
247 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); | 243 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); |
248 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object)
; | 244 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(obje
ct); |
249 ASSERT(arrayBufferView); | 245 ASSERT(arrayBufferView); |
250 xmlHttpRequest->send(arrayBufferView, exceptionState); | 246 xmlHttpRequest->send(arrayBufferView->view(), exceptionState); |
251 } else { | 247 } else { |
252 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, argString, ar
g); | 248 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, argString, ar
g); |
253 xmlHttpRequest->send(argString, exceptionState); | 249 xmlHttpRequest->send(argString, exceptionState); |
254 } | 250 } |
255 } | 251 } |
256 | 252 |
257 exceptionState.throwIfNeeded(); | 253 exceptionState.throwIfNeeded(); |
258 } | 254 } |
259 | 255 |
260 } // namespace blink | 256 } // namespace blink |
OLD | NEW |