| 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/CrossOriginAccessControl.h" | 10 #include "core/fetch/CrossOriginAccessControl.h" |
| 11 #include "core/fetch/ResourceLoaderOptions.h" | 11 #include "core/fetch/ResourceLoaderOptions.h" |
| 12 #include "core/loader/ThreadableLoader.h" | 12 #include "core/loader/ThreadableLoader.h" |
| 13 #include "core/xml/XMLHttpRequest.h" | 13 #include "core/xml/XMLHttpRequest.h" |
| 14 #include "modules/serviceworkers/FetchManager.h" | 14 #include "modules/serviceworkers/FetchManager.h" |
| 15 #include "modules/serviceworkers/RequestInit.h" | 15 #include "modules/serviceworkers/RequestInit.h" |
| 16 #include "platform/NotImplemented.h" | 16 #include "platform/NotImplemented.h" |
| 17 #include "platform/network/HTTPParsers.h" | 17 #include "platform/network/HTTPParsers.h" |
| 18 #include "platform/network/ResourceRequest.h" | 18 #include "platform/network/ResourceRequest.h" |
| 19 #include "platform/weborigin/Referrer.h" | 19 #include "platform/weborigin/Referrer.h" |
| 20 #include "public/platform/WebServiceWorkerRequest.h" | 20 #include "public/platform/WebServiceWorkerRequest.h" |
| 21 | 21 |
| 22 namespace WebCore { | 22 namespace WebCore { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 PassRefPtr<Request> createRequestWithRequestData(PassRefPtr<FetchRequestData> re
quest, const RequestInit& init, FetchRequestData::Mode mode, FetchRequestData::C
redentials credentials, ExceptionState& exceptionState) | 26 PassRefPtrWillBeRawPtr<Request> createRequestWithRequestData(PassRefPtrWillBeRaw
Ptr<FetchRequestData> request, const RequestInit& init, FetchRequestData::Mode m
ode, FetchRequestData::Credentials credentials, ExceptionState& exceptionState) |
| 27 { | 27 { |
| 28 // "6. Let |mode| be |init|'s mode member if it is present, and | 28 // "6. Let |mode| be |init|'s mode member if it is present, and |
| 29 // |fallbackMode| otherwise." | 29 // |fallbackMode| otherwise." |
| 30 // "7. If |mode| is non-null, set |request|'s mode to |mode|." | 30 // "7. If |mode| is non-null, set |request|'s mode to |mode|." |
| 31 if (init.mode == "same-origin") { | 31 if (init.mode == "same-origin") { |
| 32 request->setMode(FetchRequestData::SameOriginMode); | 32 request->setMode(FetchRequestData::SameOriginMode); |
| 33 } else if (init.mode == "no-cors") { | 33 } else if (init.mode == "no-cors") { |
| 34 request->setMode(mode = FetchRequestData::NoCORSMode); | 34 request->setMode(mode = FetchRequestData::NoCORSMode); |
| 35 } else if (init.mode == "cors") { | 35 } else if (init.mode == "cors") { |
| 36 request->setMode(FetchRequestData::CORSMode); | 36 request->setMode(FetchRequestData::CORSMode); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 67 if (!isValidHTTPToken(init.method)) { | 67 if (!isValidHTTPToken(init.method)) { |
| 68 exceptionState.throwTypeError("'" + init.method + "' is not a valid
HTTP method."); | 68 exceptionState.throwTypeError("'" + init.method + "' is not a valid
HTTP method."); |
| 69 return nullptr; | 69 return nullptr; |
| 70 } | 70 } |
| 71 // FIXME: "2. Add case correction as in XMLHttpRequest?" | 71 // FIXME: "2. Add case correction as in XMLHttpRequest?" |
| 72 // "3. Set |request|'s method to |method|." | 72 // "3. Set |request|'s method to |method|." |
| 73 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString
(init.method))); | 73 request->setMethod(XMLHttpRequest::uppercaseKnownHTTPMethod(AtomicString
(init.method))); |
| 74 } | 74 } |
| 75 // "11. Let |r| be a new Request object associated with |request|, Headers | 75 // "11. Let |r| be a new Request object associated with |request|, Headers |
| 76 // object, and FetchBodyStream object." | 76 // object, and FetchBodyStream object." |
| 77 RefPtr<Request> r = Request::create(request); | 77 RefPtrWillBeRawPtr<Request> r = Request::create(request); |
| 78 | 78 |
| 79 // "12. Let |headers| be a copy of |r|'s Headers object." | 79 // "12. Let |headers| be a copy of |r|'s Headers object." |
| 80 // "13. If |init|'s headers member is present, set |headers| to |init|'s | 80 // "13. If |init|'s headers member is present, set |headers| to |init|'s |
| 81 // headers member." | 81 // headers member." |
| 82 // We don't create a copy of r's Headers object when init's headers member | 82 // We don't create a copy of r's Headers object when init's headers member |
| 83 // is present. | 83 // is present. |
| 84 RefPtr<Headers> headers; | 84 RefPtrWillBeRawPtr<Headers> headers = nullptr; |
| 85 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { | 85 if (!init.headers && init.headersDictionary.isUndefinedOrNull()) { |
| 86 headers = r->headers()->createCopy(); | 86 headers = r->headers()->createCopy(); |
| 87 } | 87 } |
| 88 // "14. Empty |r|'s request's header list." | 88 // "14. Empty |r|'s request's header list." |
| 89 r->request()->headerList()->clearList(); | 89 r->request()->headerList()->clearList(); |
| 90 | 90 |
| 91 // "15. If |r|'s request's mode is no CORS, run these substeps: | 91 // "15. If |r|'s request's mode is no CORS, run these substeps: |
| 92 if (r->request()->mode() == FetchRequestData::NoCORSMode) { | 92 if (r->request()->mode() == FetchRequestData::NoCORSMode) { |
| 93 // "1. If |r|'s request's method is not a simple method, throw a | 93 // "1. If |r|'s request's method is not a simple method, throw a |
| 94 // TypeError." | 94 // TypeError." |
| (...skipping 18 matching lines...) Expand all Loading... |
| 113 if (exceptionState.hadException()) | 113 if (exceptionState.hadException()) |
| 114 return nullptr; | 114 return nullptr; |
| 115 // FIXME: Support body. | 115 // FIXME: Support body. |
| 116 // "20. Return |r|." | 116 // "20. Return |r|." |
| 117 return r.release(); | 117 return r.release(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 | 122 |
| 123 PassRefPtr<Request> Request::create(ExecutionContext* context, const String& inp
ut, ExceptionState& exceptionState) | 123 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Request); |
| 124 |
| 125 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, ExceptionState& exceptionState) |
| 124 { | 126 { |
| 125 return create(context, input, Dictionary(), exceptionState); | 127 return create(context, input, Dictionary(), exceptionState); |
| 126 } | 128 } |
| 127 | 129 |
| 128 PassRefPtr<Request> Request::create(ExecutionContext* context, const String& inp
ut, const Dictionary& init, ExceptionState& exceptionState) | 130 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, const Dictionary& init, ExceptionState& exceptionState) |
| 129 { | 131 { |
| 130 // "1. Let |request| be |input|'s associated request, if |input| is a | 132 // "1. Let |request| be |input|'s associated request, if |input| is a |
| 131 // Request object, and a new request otherwise." | 133 // Request object, and a new request otherwise." |
| 132 RefPtr<FetchRequestData> request(FetchRequestData::create(context)); | 134 RefPtrWillBeRawPtr<FetchRequestData> request(FetchRequestData::create(contex
t)); |
| 133 // "2. Set |request| to a restricted copy of itself." | 135 // "2. Set |request| to a restricted copy of itself." |
| 134 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont
ext->url())); | 136 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont
ext->url())); |
| 135 // "5. If |input| is a string, run these substeps:" | 137 // "5. If |input| is a string, run these substeps:" |
| 136 // "1. Let |parsedURL| be the result of parsing |input| with entry settings | 138 // "1. Let |parsedURL| be the result of parsing |input| with entry settings |
| 137 // object's API base URL." | 139 // object's API base URL." |
| 138 KURL parsedURL = context->completeURL(input); | 140 KURL parsedURL = context->completeURL(input); |
| 139 // "2. If |parsedURL| is failure, throw a TypeError." | 141 // "2. If |parsedURL| is failure, throw a TypeError." |
| 140 if (!parsedURL.isValid()) { | 142 if (!parsedURL.isValid()) { |
| 141 exceptionState.throwTypeError("Invalid URL"); | 143 exceptionState.throwTypeError("Invalid URL"); |
| 142 return nullptr; | 144 return nullptr; |
| 143 } | 145 } |
| 144 // "3. Set |request|'s url to |parsedURL|." | 146 // "3. Set |request|'s url to |parsedURL|." |
| 145 request->setURL(parsedURL); | 147 request->setURL(parsedURL); |
| 146 // "4. Set |fallbackMode| to CORS." | 148 // "4. Set |fallbackMode| to CORS." |
| 147 // "5. Set |fallbackCredentials| to omit." | 149 // "5. Set |fallbackCredentials| to omit." |
| 148 return createRequestWithRequestData(request.release(), RequestInit(init), Fe
tchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState); | 150 return createRequestWithRequestData(request.release(), RequestInit(init), Fe
tchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState); |
| 149 } | 151 } |
| 150 | 152 |
| 151 | 153 |
| 152 PassRefPtr<Request> Request::create(ExecutionContext* context, Request* input, E
xceptionState& exceptionState) | 154 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, ExceptionState& exceptionState) |
| 153 { | 155 { |
| 154 return create(context, input, Dictionary(), exceptionState); | 156 return create(context, input, Dictionary(), exceptionState); |
| 155 } | 157 } |
| 156 | 158 |
| 157 PassRefPtr<Request> Request::create(ExecutionContext* context, Request* input, c
onst Dictionary& init, ExceptionState& exceptionState) | 159 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, const Dictionary& init, ExceptionState& exceptionState) |
| 158 { | 160 { |
| 159 // "1. Let |request| be |input|'s associated request, if |input| is a | 161 // "1. Let |request| be |input|'s associated request, if |input| is a |
| 160 // Request object, and a new request otherwise." | 162 // Request object, and a new request otherwise." |
| 161 // "2. Set |request| to a restricted copy of itself." | 163 // "2. Set |request| to a restricted copy of itself." |
| 162 RefPtr<FetchRequestData> request(input->request()->createRestrictedCopy(cont
ext, SecurityOrigin::create(context->url()))); | 164 RefPtrWillBeRawPtr<FetchRequestData> request(input->request()->createRestric
tedCopy(context, SecurityOrigin::create(context->url()))); |
| 163 // "3. Let |fallbackMode| be null." | 165 // "3. Let |fallbackMode| be null." |
| 164 // "4. Let |fallbackCredentials| be null." | 166 // "4. Let |fallbackCredentials| be null." |
| 165 // Instead of using null as a special fallback value, just pass the current | 167 // Instead of using null as a special fallback value, just pass the current |
| 166 // mode and credentials; it has the same effect. | 168 // mode and credentials; it has the same effect. |
| 167 const FetchRequestData::Mode currentMode = request->mode(); | 169 const FetchRequestData::Mode currentMode = request->mode(); |
| 168 const FetchRequestData::Credentials currentCredentials = request->credential
s(); | 170 const FetchRequestData::Credentials currentCredentials = request->credential
s(); |
| 169 return createRequestWithRequestData(request.release(), RequestInit(init), cu
rrentMode, currentCredentials, exceptionState); | 171 return createRequestWithRequestData(request.release(), RequestInit(init), cu
rrentMode, currentCredentials, exceptionState); |
| 170 } | 172 } |
| 171 | 173 |
| 172 PassRefPtr<Request> Request::create(PassRefPtr<FetchRequestData> request) | 174 PassRefPtrWillBeRawPtr<Request> Request::create(PassRefPtrWillBeRawPtr<FetchRequ
estData> request) |
| 173 { | 175 { |
| 174 return adoptRef(new Request(request)); | 176 return adoptRefWillBeNoop(new Request(request)); |
| 175 } | 177 } |
| 176 | 178 |
| 177 Request::Request(PassRefPtr<FetchRequestData> request) | 179 Request::Request(PassRefPtrWillBeRawPtr<FetchRequestData> request) |
| 178 : m_request(request) | 180 : m_request(request) |
| 179 , m_headers(Headers::create(m_request->headerList())) | 181 , m_headers(Headers::create(m_request->headerList())) |
| 180 { | 182 { |
| 181 m_headers->setGuard(Headers::RequestGuard); | 183 m_headers->setGuard(Headers::RequestGuard); |
| 182 ScriptWrappable::init(this); | 184 ScriptWrappable::init(this); |
| 183 } | 185 } |
| 184 | 186 |
| 185 PassRefPtr<Request> Request::create(const blink::WebServiceWorkerRequest& webReq
uest) | 187 PassRefPtrWillBeRawPtr<Request> Request::create(const blink::WebServiceWorkerReq
uest& webRequest) |
| 186 { | 188 { |
| 187 return adoptRef(new Request(webRequest)); | 189 return adoptRefWillBeNoop(new Request(webRequest)); |
| 188 } | 190 } |
| 189 | 191 |
| 190 Request::Request(const blink::WebServiceWorkerRequest& webRequest) | 192 Request::Request(const blink::WebServiceWorkerRequest& webRequest) |
| 191 : m_request(FetchRequestData::create(webRequest)) | 193 : m_request(FetchRequestData::create(webRequest)) |
| 192 , m_headers(Headers::create(m_request->headerList())) | 194 , m_headers(Headers::create(m_request->headerList())) |
| 193 { | 195 { |
| 194 m_headers->setGuard(Headers::RequestGuard); | 196 m_headers->setGuard(Headers::RequestGuard); |
| 195 ScriptWrappable::init(this); | 197 ScriptWrappable::init(this); |
| 196 } | 198 } |
| 197 | 199 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 256 } |
| 255 | 257 |
| 256 PassOwnPtr<ResourceRequest> Request::createResourceRequest() const | 258 PassOwnPtr<ResourceRequest> Request::createResourceRequest() const |
| 257 { | 259 { |
| 258 OwnPtr<ResourceRequest> request = adoptPtr(new ResourceRequest(url())); | 260 OwnPtr<ResourceRequest> request = adoptPtr(new ResourceRequest(url())); |
| 259 request->setHTTPMethod("GET"); | 261 request->setHTTPMethod("GET"); |
| 260 // FIXME: Fill more info. | 262 // FIXME: Fill more info. |
| 261 return request.release(); | 263 return request.release(); |
| 262 } | 264 } |
| 263 | 265 |
| 266 void Request::trace(Visitor* visitor) |
| 267 { |
| 268 visitor->trace(m_request); |
| 269 visitor->trace(m_headers); |
| 270 } |
| 271 |
| 264 } // namespace WebCore | 272 } // namespace WebCore |
| OLD | NEW |