| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011, Google Inc. | |
| 2 // All rights reserved. | |
| 3 // | |
| 4 // Redistribution and use in source and binary forms, with or without | |
| 5 // modification, are permitted provided that the following conditions are | |
| 6 // met: | |
| 7 // | |
| 8 // * Redistributions of source code must retain the above copyright | |
| 9 // notice, this list of conditions and the following disclaimer. | |
| 10 // * Redistributions in binary form must reproduce the above | |
| 11 // copyright notice, this list of conditions and the following disclaimer | |
| 12 // in the documentation and/or other materials provided with the | |
| 13 // distribution. | |
| 14 // * Neither the name of Google Inc. nor the names of its | |
| 15 // contributors may be used to endorse or promote products derived from | |
| 16 // this software without specific prior written permission. | |
| 17 // | |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 | |
| 30 #include "config.h" | |
| 31 #include "DartXMLHttpRequest.h" | |
| 32 | |
| 33 #include "DartDOMWrapper.h" | |
| 34 #include "DartUtilities.h" | |
| 35 #include "DartXMLHttpRequest.h" | |
| 36 #include "ScriptExecutionContext.h" | |
| 37 #include "SecurityOrigin.h" | |
| 38 #include "XMLHttpRequest.h" | |
| 39 | |
| 40 namespace WebCore { | |
| 41 | |
| 42 namespace DartXMLHttpRequestInternal { | |
| 43 | |
| 44 void constructorCallback(Dart_NativeArguments args) | |
| 45 { | |
| 46 DartApiScope dartApiScope; | |
| 47 Dart_Handle exception; | |
| 48 { | |
| 49 ScriptExecutionContext* context = DartUtilities::scriptExecutionContext(
); | |
| 50 if (!context) { | |
| 51 exception = Dart_NewString("XMLHttpRequest constructor's associated
context is not available"); | |
| 52 goto fail; | |
| 53 } | |
| 54 | |
| 55 RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context); | |
| 56 DartDOMWrapper::bindDOMObjectToDartWrapper(xmlHttpRequest.get(), Dart_Ge
tNativeArgument(args, 0)); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 fail: | |
| 61 Dart_ThrowException(exception); | |
| 62 ASSERT_NOT_REACHED(); | |
| 63 } | |
| 64 | |
| 65 void openCallback(Dart_NativeArguments args) | |
| 66 { | |
| 67 DartApiScope dartApiScope; | |
| 68 Dart_Handle exception; | |
| 69 { | |
| 70 XMLHttpRequest* receiver = DartDOMWrapper::receiver<XMLHttpRequest>(args
); | |
| 71 const ParameterAdapter<String> method(Dart_GetNativeArgument(args, 1)); | |
| 72 if (!method.conversionSuccessful()) { | |
| 73 exception = method.exception(); | |
| 74 goto fail; | |
| 75 } | |
| 76 const ParameterAdapter<String> url(Dart_GetNativeArgument(args, 2)); | |
| 77 if (!url.conversionSuccessful()) { | |
| 78 exception = url.exception(); | |
| 79 goto fail; | |
| 80 } | |
| 81 | |
| 82 ScriptExecutionContext* context = DartUtilities::scriptExecutionContext(
); | |
| 83 if (!context) | |
| 84 return; | |
| 85 KURL fullURL = context->completeURL(url); | |
| 86 | |
| 87 const ParameterAdapter<bool> async(Dart_GetNativeArgument(args, 3)); | |
| 88 if (!async.conversionSuccessful()) { | |
| 89 exception = async.exception(); | |
| 90 goto fail; | |
| 91 } | |
| 92 | |
| 93 // FIXME: deal with optional arguments. | |
| 94 ExceptionCode ec = 0; | |
| 95 receiver->open(method, fullURL, async, ec); | |
| 96 if (UNLIKELY(ec)) { | |
| 97 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 98 goto fail; | |
| 99 } | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 fail: | |
| 104 Dart_ThrowException(exception); | |
| 105 ASSERT_NOT_REACHED(); | |
| 106 } | |
| 107 | |
| 108 void sendCallback(Dart_NativeArguments args) | |
| 109 { | |
| 110 DartApiScope dartApiScope; | |
| 111 Dart_Handle exception; | |
| 112 { | |
| 113 XMLHttpRequest* receiver = DartDOMWrapper::receiver<XMLHttpRequest>(args
); | |
| 114 | |
| 115 // FIXME: deal with optional argument. | |
| 116 if (!Dart_IsNull(Dart_GetNativeArgument(args, 1))) { | |
| 117 exception = DartUtilities::notImplementedException(); | |
| 118 goto fail; | |
| 119 } | |
| 120 | |
| 121 ExceptionCode ec = 0; | |
| 122 receiver->send(ec); | |
| 123 if (UNLIKELY(ec)) { | |
| 124 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 125 goto fail; | |
| 126 } | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 fail: | |
| 131 Dart_ThrowException(exception); | |
| 132 ASSERT_NOT_REACHED(); | |
| 133 } | |
| 134 | |
| 135 void responseTextGetter(Dart_NativeArguments args) | |
| 136 { | |
| 137 DartApiScope dartApiScope; | |
| 138 Dart_Handle exception; | |
| 139 { | |
| 140 XMLHttpRequest* receiver = DartDOMWrapper::receiver<XMLHttpRequest>(args
); | |
| 141 | |
| 142 ExceptionCode ec = 0; | |
| 143 DartDOMWrapper::returnValue(args, receiver->responseText(ec)); | |
| 144 if (UNLIKELY(ec)) { | |
| 145 exception = DartDOMWrapper::exceptionCodeToDartException(ec); | |
| 146 goto fail; | |
| 147 } | |
| 148 return; | |
| 149 } | |
| 150 | |
| 151 fail: | |
| 152 Dart_ThrowException(exception); | |
| 153 ASSERT_NOT_REACHED(); | |
| 154 } | |
| 155 | |
| 156 void responseGetter(Dart_NativeArguments args) | |
| 157 { | |
| 158 // FIXME: implement. | |
| 159 DART_UNIMPLEMENTED(); | |
| 160 } | |
| 161 | |
| 162 } // DartXMLHttpRequestInternal | |
| 163 | |
| 164 } // WebCore | |
| OLD | NEW |