| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "Request.h" | 6 #include "Request.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/fetch/FetchUtils.h" | 10 #include "core/fetch/FetchUtils.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ASSERT(init.headersDictionary.isUndefinedOrNull()); | 105 ASSERT(init.headersDictionary.isUndefinedOrNull()); |
| 106 r->headers()->fillWith(init.headers.get(), exceptionState); | 106 r->headers()->fillWith(init.headers.get(), exceptionState); |
| 107 } else if (!init.headersDictionary.isUndefinedOrNull()) { | 107 } else if (!init.headersDictionary.isUndefinedOrNull()) { |
| 108 r->headers()->fillWith(init.headersDictionary, exceptionState); | 108 r->headers()->fillWith(init.headersDictionary, exceptionState); |
| 109 } else { | 109 } else { |
| 110 ASSERT(headers); | 110 ASSERT(headers); |
| 111 r->headers()->fillWith(headers.get(), exceptionState); | 111 r->headers()->fillWith(headers.get(), exceptionState); |
| 112 } | 112 } |
| 113 if (exceptionState.hadException()) | 113 if (exceptionState.hadException()) |
| 114 return nullptr; | 114 return nullptr; |
| 115 // FIXME: Support body. | 115 // "17. If |init|'s body member is present, run these substeps:" |
| 116 // "20. Return |r|." | 116 if (init.bodyBlobHandle) { |
| 117 // "1. Let |stream| and |Content-Type| be the result of extracting |
| 118 // |init|'s body member." |
| 119 // "2. Set |r|'s request's body to |stream|." |
| 120 // "3.If |Content-Type| is non-null and |r|'s request's header list |
| 121 // contains no header named `Content-Type`, append |
| 122 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any |
| 123 // exception." |
| 124 r->setBodyBlobHandle(init.bodyBlobHandle); |
| 125 if (!init.bodyBlobHandle->type().isEmpty() && !r->headers()->has("Conten
t-Type", exceptionState)) { |
| 126 r->headers()->append("Content-Type", init.bodyBlobHandle->type(), ex
ceptionState); |
| 127 } |
| 128 if (exceptionState.hadException()) |
| 129 return nullptr; |
| 130 } |
| 131 // "18. Set |r|'s FetchBodyStream object's MIME type to the result of |
| 132 // extracting a MIME type from |r|'s request's header list." |
| 133 // FIXME: We don't have MIME type in FetchBodyStream object yet. |
| 134 |
| 135 // "19. Return |r|." |
| 117 return r.release(); | 136 return r.release(); |
| 118 } | 137 } |
| 119 | 138 |
| 120 | 139 |
| 121 } // namespace | 140 } // namespace |
| 122 | 141 |
| 123 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Request); | 142 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Request); |
| 124 | 143 |
| 125 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, ExceptionState& exceptionState) | 144 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, ExceptionState& exceptionState) |
| 126 { | 145 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 140 KURL parsedURL = context->completeURL(input); | 159 KURL parsedURL = context->completeURL(input); |
| 141 // "2. If |parsedURL| is failure, throw a TypeError." | 160 // "2. If |parsedURL| is failure, throw a TypeError." |
| 142 if (!parsedURL.isValid()) { | 161 if (!parsedURL.isValid()) { |
| 143 exceptionState.throwTypeError("Invalid URL"); | 162 exceptionState.throwTypeError("Invalid URL"); |
| 144 return nullptr; | 163 return nullptr; |
| 145 } | 164 } |
| 146 // "3. Set |request|'s url to |parsedURL|." | 165 // "3. Set |request|'s url to |parsedURL|." |
| 147 request->setURL(parsedURL); | 166 request->setURL(parsedURL); |
| 148 // "4. Set |fallbackMode| to CORS." | 167 // "4. Set |fallbackMode| to CORS." |
| 149 // "5. Set |fallbackCredentials| to omit." | 168 // "5. Set |fallbackCredentials| to omit." |
| 150 return createRequestWithRequestData(request.release(), RequestInit(init), Fe
tchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState); | 169 return createRequestWithRequestData(request.release(), RequestInit(context,
init, exceptionState), FetchRequestData::CORSMode, FetchRequestData::OmitCredent
ials, exceptionState); |
| 151 } | 170 } |
| 152 | 171 |
| 153 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, ExceptionState& exceptionState) | 172 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, ExceptionState& exceptionState) |
| 154 { | 173 { |
| 155 return create(context, input, Dictionary(), exceptionState); | 174 return create(context, input, Dictionary(), exceptionState); |
| 156 } | 175 } |
| 157 | 176 |
| 158 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, const Dictionary& init, ExceptionState& exceptionState) | 177 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, const Dictionary& init, ExceptionState& exceptionState) |
| 159 { | 178 { |
| 160 // "1. Let |request| be |input|'s associated request, if |input| is a | 179 // "1. Let |request| be |input|'s associated request, if |input| is a |
| 161 // Request object, and a new request otherwise." | 180 // Request object, and a new request otherwise." |
| 162 // "2. Set |request| to a restricted copy of itself." | 181 // "2. Set |request| to a restricted copy of itself." |
| 163 RefPtrWillBeRawPtr<FetchRequestData> request(input->request()->createRestric
tedCopy(context, SecurityOrigin::create(context->url()))); | 182 RefPtrWillBeRawPtr<FetchRequestData> request(input->request()->createRestric
tedCopy(context, SecurityOrigin::create(context->url()))); |
| 164 // "3. Let |fallbackMode| be null." | 183 // "3. Let |fallbackMode| be null." |
| 165 // "4. Let |fallbackCredentials| be null." | 184 // "4. Let |fallbackCredentials| be null." |
| 166 // Instead of using null as a special fallback value, just pass the current | 185 // Instead of using null as a special fallback value, just pass the current |
| 167 // mode and credentials; it has the same effect. | 186 // mode and credentials; it has the same effect. |
| 168 const FetchRequestData::Mode currentMode = request->mode(); | 187 const FetchRequestData::Mode currentMode = request->mode(); |
| 169 const FetchRequestData::Credentials currentCredentials = request->credential
s(); | 188 const FetchRequestData::Credentials currentCredentials = request->credential
s(); |
| 170 return createRequestWithRequestData(request.release(), RequestInit(init), cu
rrentMode, currentCredentials, exceptionState); | 189 return createRequestWithRequestData(request.release(), RequestInit(context,
init, exceptionState), currentMode, currentCredentials, exceptionState); |
| 171 } | 190 } |
| 172 | 191 |
| 173 PassRefPtrWillBeRawPtr<Request> Request::create(PassRefPtrWillBeRawPtr<FetchRequ
estData> request) | 192 PassRefPtrWillBeRawPtr<Request> Request::create(PassRefPtrWillBeRawPtr<FetchRequ
estData> request) |
| 174 { | 193 { |
| 175 return adoptRefWillBeNoop(new Request(request)); | 194 return adoptRefWillBeNoop(new Request(request)); |
| 176 } | 195 } |
| 177 | 196 |
| 178 Request::Request(PassRefPtrWillBeRawPtr<FetchRequestData> request) | 197 Request::Request(PassRefPtrWillBeRawPtr<FetchRequestData> request) |
| 179 : m_request(request) | 198 : m_request(request) |
| 180 , m_headers(Headers::create(m_request->headerList())) | 199 , m_headers(Headers::create(m_request->headerList())) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 return "omit"; | 276 return "omit"; |
| 258 case FetchRequestData::SameOriginCredentials: | 277 case FetchRequestData::SameOriginCredentials: |
| 259 return "same-origin"; | 278 return "same-origin"; |
| 260 case FetchRequestData::IncludeCredentials: | 279 case FetchRequestData::IncludeCredentials: |
| 261 return "include"; | 280 return "include"; |
| 262 } | 281 } |
| 263 ASSERT_NOT_REACHED(); | 282 ASSERT_NOT_REACHED(); |
| 264 return ""; | 283 return ""; |
| 265 } | 284 } |
| 266 | 285 |
| 286 void Request::setBodyBlobHandle(PassRefPtr<BlobDataHandle>blobHandle) |
| 287 { |
| 288 m_request->setBlobDataHandle(blobHandle); |
| 289 } |
| 290 |
| 267 void Request::trace(Visitor* visitor) | 291 void Request::trace(Visitor* visitor) |
| 268 { | 292 { |
| 269 visitor->trace(m_request); | 293 visitor->trace(m_request); |
| 270 visitor->trace(m_headers); | 294 visitor->trace(m_headers); |
| 271 visitor->trace(m_fetchBodyStream); | 295 visitor->trace(m_fetchBodyStream); |
| 272 } | 296 } |
| 273 | 297 |
| 274 } // namespace blink | 298 } // namespace blink |
| OLD | NEW |