| 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" |
| 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 blink { | 22 namespace blink { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 PassRefPtrWillBeRawPtr<Request> createRequestWithRequestData(PassRefPtrWillBeRaw
Ptr<FetchRequestData> request, const RequestInit& init, FetchRequestData::Mode m
ode, FetchRequestData::Credentials credentials, ExceptionState& exceptionState) | 26 Request* createRequestWithRequestData(FetchRequestData* request, const RequestIn
it& init, FetchRequestData::Mode mode, 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 18 matching lines...) Expand all Loading... |
| 55 // current credentials in Request::create(). So we just set here. | 55 // current credentials in Request::create(). So we just set here. |
| 56 request->setCredentials(credentials); | 56 request->setCredentials(credentials); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // "10. If |init|'s method member is present, let |method| be it and run | 59 // "10. If |init|'s method member is present, let |method| be it and run |
| 60 // these substeps:" | 60 // these substeps:" |
| 61 if (!init.method.isEmpty()) { | 61 if (!init.method.isEmpty()) { |
| 62 // "1. If |method| is not a useful method, throw a TypeError." | 62 // "1. If |method| is not a useful method, throw a TypeError." |
| 63 if (!FetchUtils::isUsefulMethod(init.method)) { | 63 if (!FetchUtils::isUsefulMethod(init.method)) { |
| 64 exceptionState.throwTypeError("'" + init.method + "' HTTP method is
unsupported."); | 64 exceptionState.throwTypeError("'" + init.method + "' HTTP method is
unsupported."); |
| 65 return nullptr; | 65 return 0; |
| 66 } | 66 } |
| 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 0; |
| 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 RefPtrWillBeRawPtr<Request> r = Request::create(request); | 77 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 RefPtrWillBeRawPtr<Headers> headers = nullptr; | 84 Headers* headers = 0; |
| 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." |
| 95 if (!FetchUtils::isSimpleMethod(r->request()->method())) { | 95 if (!FetchUtils::isSimpleMethod(r->request()->method())) { |
| 96 exceptionState.throwTypeError("'" + r->request()->method() + "' is u
nsupported in no-cors mode."); | 96 exceptionState.throwTypeError("'" + r->request()->method() + "' is u
nsupported in no-cors mode."); |
| 97 return nullptr; | 97 return 0; |
| 98 } | 98 } |
| 99 // "Set |r|'s Headers object's guard to |request-no-CORS|. | 99 // "Set |r|'s Headers object's guard to |request-no-CORS|. |
| 100 r->headers()->setGuard(Headers::RequestNoCORSGuard); | 100 r->headers()->setGuard(Headers::RequestNoCORSGuard); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // "16. Fill |r|'s Headers object with |headers|. Rethrow any exceptions." | 103 // "16. Fill |r|'s Headers object with |headers|. Rethrow any exceptions." |
| 104 if (init.headers) { | 104 if (init.headers) { |
| 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, exceptionState); |
| 112 } | 112 } |
| 113 if (exceptionState.hadException()) | 113 if (exceptionState.hadException()) |
| 114 return nullptr; | 114 return 0; |
| 115 // FIXME: Support body. | 115 // FIXME: Support body. |
| 116 // "20. Return |r|." | 116 // "20. Return |r|." |
| 117 return r.release(); | 117 return r; |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 | 122 |
| 123 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Request); | 123 Request* Request::create(ExecutionContext* context, const String& input, Excepti
onState& exceptionState) |
| 124 | |
| 125 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, ExceptionState& exceptionState) | |
| 126 { | 124 { |
| 127 return create(context, input, Dictionary(), exceptionState); | 125 return create(context, input, Dictionary(), exceptionState); |
| 128 } | 126 } |
| 129 | 127 |
| 130 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
String& input, const Dictionary& init, ExceptionState& exceptionState) | 128 Request* Request::create(ExecutionContext* context, const String& input, const D
ictionary& init, ExceptionState& exceptionState) |
| 131 { | 129 { |
| 132 // "1. Let |request| be |input|'s associated request, if |input| is a | 130 // "1. Let |request| be |input|'s associated request, if |input| is a |
| 133 // Request object, and a new request otherwise." | 131 // Request object, and a new request otherwise." |
| 134 RefPtrWillBeRawPtr<FetchRequestData> request(FetchRequestData::create(contex
t)); | 132 FetchRequestData* request(FetchRequestData::create(context)); |
| 135 // "2. Set |request| to a restricted copy of itself." | 133 // "2. Set |request| to a restricted copy of itself." |
| 136 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont
ext->url())); | 134 request = request->createRestrictedCopy(context, SecurityOrigin::create(cont
ext->url())); |
| 137 // "5. If |input| is a string, run these substeps:" | 135 // "5. If |input| is a string, run these substeps:" |
| 138 // "1. Let |parsedURL| be the result of parsing |input| with entry settings | 136 // "1. Let |parsedURL| be the result of parsing |input| with entry settings |
| 139 // object's API base URL." | 137 // object's API base URL." |
| 140 KURL parsedURL = context->completeURL(input); | 138 KURL parsedURL = context->completeURL(input); |
| 141 // "2. If |parsedURL| is failure, throw a TypeError." | 139 // "2. If |parsedURL| is failure, throw a TypeError." |
| 142 if (!parsedURL.isValid()) { | 140 if (!parsedURL.isValid()) { |
| 143 exceptionState.throwTypeError("Invalid URL"); | 141 exceptionState.throwTypeError("Invalid URL"); |
| 144 return nullptr; | 142 return 0; |
| 145 } | 143 } |
| 146 // "3. Set |request|'s url to |parsedURL|." | 144 // "3. Set |request|'s url to |parsedURL|." |
| 147 request->setURL(parsedURL); | 145 request->setURL(parsedURL); |
| 148 // "4. Set |fallbackMode| to CORS." | 146 // "4. Set |fallbackMode| to CORS." |
| 149 // "5. Set |fallbackCredentials| to omit." | 147 // "5. Set |fallbackCredentials| to omit." |
| 150 return createRequestWithRequestData(request.release(), RequestInit(init), Fe
tchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState); | 148 return createRequestWithRequestData(request, RequestInit(init), FetchRequest
Data::CORSMode, FetchRequestData::OmitCredentials, exceptionState); |
| 151 } | 149 } |
| 152 | 150 |
| 153 | 151 |
| 154 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, ExceptionState& exceptionState) | 152 Request* Request::create(ExecutionContext* context, Request* input, ExceptionSta
te& exceptionState) |
| 155 { | 153 { |
| 156 return create(context, input, Dictionary(), exceptionState); | 154 return create(context, input, Dictionary(), exceptionState); |
| 157 } | 155 } |
| 158 | 156 |
| 159 PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
st* input, const Dictionary& init, ExceptionState& exceptionState) | 157 Request* Request::create(ExecutionContext* context, Request* input, const Dictio
nary& init, ExceptionState& exceptionState) |
| 160 { | 158 { |
| 161 // "1. Let |request| be |input|'s associated request, if |input| is a | 159 // "1. Let |request| be |input|'s associated request, if |input| is a |
| 162 // Request object, and a new request otherwise." | 160 // Request object, and a new request otherwise." |
| 163 // "2. Set |request| to a restricted copy of itself." | 161 // "2. Set |request| to a restricted copy of itself." |
| 164 RefPtrWillBeRawPtr<FetchRequestData> request(input->request()->createRestric
tedCopy(context, SecurityOrigin::create(context->url()))); | 162 FetchRequestData* request(input->request()->createRestrictedCopy(context, Se
curityOrigin::create(context->url()))); |
| 165 // "3. Let |fallbackMode| be null." | 163 // "3. Let |fallbackMode| be null." |
| 166 // "4. Let |fallbackCredentials| be null." | 164 // "4. Let |fallbackCredentials| be null." |
| 167 // Instead of using null as a special fallback value, just pass the current | 165 // Instead of using null as a special fallback value, just pass the current |
| 168 // mode and credentials; it has the same effect. | 166 // mode and credentials; it has the same effect. |
| 169 const FetchRequestData::Mode currentMode = request->mode(); | 167 const FetchRequestData::Mode currentMode = request->mode(); |
| 170 const FetchRequestData::Credentials currentCredentials = request->credential
s(); | 168 const FetchRequestData::Credentials currentCredentials = request->credential
s(); |
| 171 return createRequestWithRequestData(request.release(), RequestInit(init), cu
rrentMode, currentCredentials, exceptionState); | 169 return createRequestWithRequestData(request, RequestInit(init), currentMode,
currentCredentials, exceptionState); |
| 172 } | 170 } |
| 173 | 171 |
| 174 PassRefPtrWillBeRawPtr<Request> Request::create(PassRefPtrWillBeRawPtr<FetchRequ
estData> request) | 172 Request* Request::create(FetchRequestData* request) |
| 175 { | 173 { |
| 176 return adoptRefWillBeNoop(new Request(request)); | 174 return new Request(request); |
| 177 } | 175 } |
| 178 | 176 |
| 179 Request::Request(PassRefPtrWillBeRawPtr<FetchRequestData> request) | 177 Request::Request(FetchRequestData* request) |
| 180 : m_request(request) | 178 : m_request(request) |
| 181 , m_headers(Headers::create(m_request->headerList())) | 179 , m_headers(Headers::create(m_request->headerList())) |
| 182 { | 180 { |
| 183 m_headers->setGuard(Headers::RequestGuard); | 181 m_headers->setGuard(Headers::RequestGuard); |
| 184 ScriptWrappable::init(this); | 182 ScriptWrappable::init(this); |
| 185 } | 183 } |
| 186 | 184 |
| 187 PassRefPtrWillBeRawPtr<Request> Request::create(const WebServiceWorkerRequest& w
ebRequest) | 185 Request* Request::create(const WebServiceWorkerRequest& webRequest) |
| 188 { | 186 { |
| 189 return adoptRefWillBeNoop(new Request(webRequest)); | 187 return new Request(webRequest); |
| 190 } | 188 } |
| 191 | 189 |
| 192 Request::Request(const WebServiceWorkerRequest& webRequest) | 190 Request::Request(const WebServiceWorkerRequest& webRequest) |
| 193 : m_request(FetchRequestData::create(webRequest)) | 191 : m_request(FetchRequestData::create(webRequest)) |
| 194 , m_headers(Headers::create(m_request->headerList())) | 192 , m_headers(Headers::create(m_request->headerList())) |
| 195 { | 193 { |
| 196 m_headers->setGuard(Headers::RequestGuard); | 194 m_headers->setGuard(Headers::RequestGuard); |
| 197 ScriptWrappable::init(this); | 195 ScriptWrappable::init(this); |
| 198 } | 196 } |
| 199 | 197 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return ""; | 253 return ""; |
| 256 } | 254 } |
| 257 | 255 |
| 258 void Request::trace(Visitor* visitor) | 256 void Request::trace(Visitor* visitor) |
| 259 { | 257 { |
| 260 visitor->trace(m_request); | 258 visitor->trace(m_request); |
| 261 visitor->trace(m_headers); | 259 visitor->trace(m_headers); |
| 262 } | 260 } |
| 263 | 261 |
| 264 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |