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" | 45 #include "core/dom/DOMArrayBufferDeallocationObserver.h" |
44 #include "bindings/core/v8/custom/V8ArrayBufferViewCustom.h" | |
45 #include "core/dom/Document.h" | 46 #include "core/dom/Document.h" |
46 #include "core/inspector/InspectorInstrumentation.h" | 47 #include "core/inspector/InspectorInstrumentation.h" |
47 #include "core/streams/ReadableStream.h" | 48 #include "core/streams/ReadableStream.h" |
48 #include "core/streams/Stream.h" | 49 #include "core/streams/Stream.h" |
49 #include "core/workers/WorkerGlobalScope.h" | 50 #include "core/workers/WorkerGlobalScope.h" |
50 #include "core/xml/XMLHttpRequest.h" | 51 #include "core/xml/XMLHttpRequest.h" |
51 #include "wtf/ArrayBuffer.h" | |
52 #include <v8.h> | 52 #include <v8.h> |
53 | 53 |
54 namespace blink { | 54 namespace blink { |
55 | 55 |
56 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu
e>& info) | 56 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu
e>& info) |
57 { | 57 { |
58 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); | 58 ExecutionContext* context = currentExecutionContext(info.GetIsolate()); |
59 | 59 |
60 RefPtr<SecurityOrigin> securityOrigin; | 60 RefPtr<SecurityOrigin> securityOrigin; |
61 if (context->isDocument()) { | 61 if (context->isDocument()) { |
62 DOMWrapperWorld& world = DOMWrapperWorld::current(info.GetIsolate()); | 62 DOMWrapperWorld& world = DOMWrapperWorld::current(info.GetIsolate()); |
63 if (world.isIsolatedWorld()) | 63 if (world.isIsolatedWorld()) |
64 securityOrigin = world.isolatedWorldSecurityOrigin(); | 64 securityOrigin = world.isolatedWorldSecurityOrigin(); |
65 } | 65 } |
66 | 66 |
67 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(c
ontext, securityOrigin); | 67 RefPtrWillBeRawPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(c
ontext, securityOrigin); |
68 | 68 |
69 v8::Handle<v8::Object> wrapper = info.Holder(); | 69 v8::Handle<v8::Object> wrapper = info.Holder(); |
70 V8DOMWrapper::associateObjectWithWrapper<V8XMLHttpRequest>(xmlHttpRequest.re
lease(), &wrapperTypeInfo, wrapper, info.GetIsolate()); | 70 xmlHttpRequest->associateWithWrapper(xmlHttpRequest->wrapperTypeInfo(), wrap
per, info.GetIsolate()); |
71 info.GetReturnValue().Set(wrapper); | 71 info.GetReturnValue().Set(wrapper); |
72 } | 72 } |
73 | 73 |
74 void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallb
ackInfo<v8::Value>& info) | 74 void V8XMLHttpRequest::responseTextAttributeGetterCustom(const v8::PropertyCallb
ackInfo<v8::Value>& info) |
75 { | 75 { |
76 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder()); | 76 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder()); |
77 ExceptionState exceptionState(ExceptionState::GetterContext, "responseText",
"XMLHttpRequest", info.Holder(), info.GetIsolate()); | 77 ExceptionState exceptionState(ExceptionState::GetterContext, "responseText",
"XMLHttpRequest", info.Holder(), info.GetIsolate()); |
78 ScriptString text = xmlHttpRequest->responseText(exceptionState); | 78 ScriptString text = xmlHttpRequest->responseText(exceptionState); |
79 if (exceptionState.throwIfNeeded()) | 79 if (exceptionState.throwIfNeeded()) |
80 return; | 80 return; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 case XMLHttpRequest::ResponseTypeStream: | 142 case XMLHttpRequest::ResponseTypeStream: |
143 { | 143 { |
144 ReadableStream* stream = xmlHttpRequest->responseStream(); | 144 ReadableStream* stream = xmlHttpRequest->responseStream(); |
145 v8SetReturnValueFast(info, stream, xmlHttpRequest); | 145 v8SetReturnValueFast(info, stream, xmlHttpRequest); |
146 return; | 146 return; |
147 } | 147 } |
148 | 148 |
149 case XMLHttpRequest::ResponseTypeArrayBuffer: | 149 case XMLHttpRequest::ResponseTypeArrayBuffer: |
150 { | 150 { |
151 ArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(); | 151 DOMArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(); |
152 if (arrayBuffer) { | 152 if (arrayBuffer) { |
153 arrayBuffer->setDeallocationObserver(V8ArrayBufferDeallocationOb
server::instanceTemplate()); | 153 arrayBuffer->setDeallocationObserver(DOMArrayBufferDeallocationO
bserver::instance()); |
154 } | 154 } |
155 v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest); | 155 v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest); |
156 return; | 156 return; |
157 } | 157 } |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value
>& info) | 161 void V8XMLHttpRequest::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value
>& info) |
162 { | 162 { |
163 // Four cases: | 163 // Four cases: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 Blob* blob = V8Blob::toImpl(object); | 233 Blob* blob = V8Blob::toImpl(object); |
234 ASSERT(blob); | 234 ASSERT(blob); |
235 xmlHttpRequest->send(blob, exceptionState); | 235 xmlHttpRequest->send(blob, exceptionState); |
236 } else if (V8FormData::hasInstance(arg, info.GetIsolate())) { | 236 } else if (V8FormData::hasInstance(arg, info.GetIsolate())) { |
237 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); | 237 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); |
238 DOMFormData* domFormData = V8FormData::toImpl(object); | 238 DOMFormData* domFormData = V8FormData::toImpl(object); |
239 ASSERT(domFormData); | 239 ASSERT(domFormData); |
240 xmlHttpRequest->send(domFormData, exceptionState); | 240 xmlHttpRequest->send(domFormData, exceptionState); |
241 } else if (V8ArrayBuffer::hasInstance(arg, info.GetIsolate())) { | 241 } else if (V8ArrayBuffer::hasInstance(arg, info.GetIsolate())) { |
242 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); | 242 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); |
243 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(object); | 243 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(object); |
244 ASSERT(arrayBuffer); | 244 ASSERT(arrayBuffer); |
245 xmlHttpRequest->send(arrayBuffer, exceptionState); | 245 xmlHttpRequest->send(arrayBuffer->buffer(), exceptionState); |
246 } else if (V8ArrayBufferView::hasInstance(arg, info.GetIsolate())) { | 246 } else if (V8ArrayBufferView::hasInstance(arg, info.GetIsolate())) { |
247 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); | 247 v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(arg); |
248 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(object)
; | 248 DOMArrayBufferView* arrayBufferView = V8ArrayBufferView::toImpl(obje
ct); |
249 ASSERT(arrayBufferView); | 249 ASSERT(arrayBufferView); |
250 xmlHttpRequest->send(arrayBufferView, exceptionState); | 250 xmlHttpRequest->send(arrayBufferView->view(), exceptionState); |
251 } else { | 251 } else { |
252 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, argString, ar
g); | 252 TOSTRING_VOID(V8StringResource<TreatNullAsNullString>, argString, ar
g); |
253 xmlHttpRequest->send(argString, exceptionState); | 253 xmlHttpRequest->send(argString, exceptionState); |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 exceptionState.throwIfNeeded(); | 257 exceptionState.throwIfNeeded(); |
258 } | 258 } |
259 | 259 |
260 } // namespace blink | 260 } // namespace blink |
OLD | NEW |