Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 #include "bindings/v8/V8Binding.h" | 40 #include "bindings/v8/V8Binding.h" |
| 41 #include "bindings/v8/V8Utilities.h" | 41 #include "bindings/v8/V8Utilities.h" |
| 42 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 42 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
| 43 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
| 44 #include "core/inspector/InspectorInstrumentation.h" | 44 #include "core/inspector/InspectorInstrumentation.h" |
| 45 #include "core/page/Frame.h" | 45 #include "core/page/Frame.h" |
| 46 #include "core/workers/WorkerGlobalScope.h" | 46 #include "core/workers/WorkerGlobalScope.h" |
| 47 #include "core/xml/XMLHttpRequest.h" | 47 #include "core/xml/XMLHttpRequest.h" |
| 48 #include "wtf/ArrayBuffer.h" | 48 #include "wtf/ArrayBuffer.h" |
| 49 | 49 |
| 50 #include <v8.h> | |
| 51 | |
| 50 namespace WebCore { | 52 namespace WebCore { |
| 51 | 53 |
| 52 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu e>& args) | 54 void V8XMLHttpRequest::constructorCustom(const v8::FunctionCallbackInfo<v8::Valu e>& args) |
| 53 { | 55 { |
| 54 ScriptExecutionContext* context = getScriptExecutionContext(); | 56 ScriptExecutionContext* context = getScriptExecutionContext(); |
| 55 | 57 |
| 56 RefPtr<SecurityOrigin> securityOrigin; | 58 RefPtr<SecurityOrigin> securityOrigin; |
| 57 if (context->isDocument()) { | 59 if (context->isDocument()) { |
| 58 if (DOMWrapperWorld* world = isolatedWorldForEnteredContext()) | 60 if (DOMWrapperWorld* world = isolatedWorldForEnteredContext()) |
| 59 securityOrigin = world->isolatedWorldSecurityOrigin(); | 61 securityOrigin = world->isolatedWorldSecurityOrigin(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 83 void V8XMLHttpRequest::responseAttrGetterCustom(v8::Local<v8::String> name, cons t v8::PropertyCallbackInfo<v8::Value>& info) | 85 void V8XMLHttpRequest::responseAttrGetterCustom(v8::Local<v8::String> name, cons t v8::PropertyCallbackInfo<v8::Value>& info) |
| 84 { | 86 { |
| 85 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); | 87 XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toNative(info.Holder()); |
| 86 | 88 |
| 87 switch (xmlHttpRequest->responseTypeCode()) { | 89 switch (xmlHttpRequest->responseTypeCode()) { |
| 88 case XMLHttpRequest::ResponseTypeDefault: | 90 case XMLHttpRequest::ResponseTypeDefault: |
| 89 case XMLHttpRequest::ResponseTypeText: | 91 case XMLHttpRequest::ResponseTypeText: |
| 90 responseTextAttrGetterCustom(name, info); | 92 responseTextAttrGetterCustom(name, info); |
| 91 return; | 93 return; |
| 92 | 94 |
| 95 case XMLHttpRequest::ResponseTypeJson: | |
|
abarth-chromium
2013/08/06 19:28:33
ResponseTypeJson -> ResponseTypeJSON
tyoshino (SeeGerritForStatus)
2013/08/07 03:37:46
Done.
| |
| 96 { | |
| 97 ExceptionState es(info.GetIsolate()); | |
| 98 ScriptString jsonSource = xmlHttpRequest->responseJsonSource(es); | |
|
abarth-chromium
2013/08/06 19:28:33
responseJsonSource -> responseJSONSource
tyoshino (SeeGerritForStatus)
2013/08/07 03:37:46
Done.
| |
| 99 if (es.throwIfNeeded()) | |
| 100 return; | |
| 101 | |
| 102 v8::Isolate* isolate = info.GetIsolate(); | |
|
abarth-chromium
2013/08/06 19:28:33
Should we grab the isolate at the top of the block
tyoshino (SeeGerritForStatus)
2013/08/07 03:37:46
Yes! Done
| |
| 103 | |
| 104 if (jsonSource.hasNoValue() || !jsonSource.v8Value()->IsString()) { | |
| 105 v8SetReturnValue(info, v8NullWithCheck(isolate)); | |
| 106 return; | |
| 107 } | |
| 108 | |
| 109 // Catch syntax error. | |
| 110 v8::TryCatch exceptionCatcher; | |
| 111 | |
| 112 v8::Handle<v8::Value> json = v8::JSON::Parse(jsonSource.v8Value().As <v8::String>()); | |
| 113 | |
| 114 if (exceptionCatcher.HasCaught() || json.IsEmpty()) | |
| 115 v8SetReturnValue(info, v8NullWithCheck(isolate)); | |
| 116 else | |
| 117 v8SetReturnValue(info, json); | |
| 118 | |
| 119 return; | |
| 120 } | |
| 121 | |
| 93 case XMLHttpRequest::ResponseTypeDocument: | 122 case XMLHttpRequest::ResponseTypeDocument: |
| 94 { | 123 { |
| 95 ExceptionState es(info.GetIsolate()); | 124 ExceptionState es(info.GetIsolate()); |
| 96 Document* document = xmlHttpRequest->responseXML(es); | 125 Document* document = xmlHttpRequest->responseXML(es); |
| 97 if (es.throwIfNeeded()) | 126 if (es.throwIfNeeded()) |
| 98 return; | 127 return; |
| 99 v8SetReturnValue(info, toV8Fast(document, info, xmlHttpRequest)); | 128 v8SetReturnValue(info, toV8Fast(document, info, xmlHttpRequest)); |
| 100 return; | 129 return; |
| 101 } | 130 } |
| 102 | 131 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 ASSERT(arrayBufferView); | 246 ASSERT(arrayBufferView); |
| 218 xmlHttpRequest->send(arrayBufferView, es); | 247 xmlHttpRequest->send(arrayBufferView, es); |
| 219 } else | 248 } else |
| 220 xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), es); | 249 xmlHttpRequest->send(toWebCoreStringWithNullCheck(arg), es); |
| 221 } | 250 } |
| 222 | 251 |
| 223 es.throwIfNeeded(); | 252 es.throwIfNeeded(); |
| 224 } | 253 } |
| 225 | 254 |
| 226 } // namespace WebCore | 255 } // namespace WebCore |
| OLD | NEW |