| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/fetchers/resource_fetcher_impl.h" | 5 #include "content/renderer/fetchers/resource_fetcher_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "third_party/WebKit/public/platform/Platform.h" | 13 #include "third_party/WebKit/public/platform/Platform.h" |
| 14 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 14 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 15 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 #include "third_party/WebKit/public/platform/WebURL.h" | 17 #include "third_party/WebKit/public/platform/WebURL.h" |
| 17 #include "third_party/WebKit/public/platform/WebURLError.h" | 18 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 18 #include "third_party/WebKit/public/platform/WebURLLoader.h" | 19 #include "third_party/WebKit/public/platform/WebURLLoader.h" |
| 19 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 20 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 20 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 21 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 21 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
| 22 #include "third_party/WebKit/public/web/WebFrame.h" | 23 #include "third_party/WebKit/public/web/WebFrame.h" |
| 23 #include "third_party/WebKit/public/web/WebKit.h" | 24 #include "third_party/WebKit/public/web/WebKit.h" |
| 24 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 25 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 const Callback& callback) { | 176 const Callback& callback) { |
| 176 DCHECK(!loader_); | 177 DCHECK(!loader_); |
| 177 DCHECK(!client_); | 178 DCHECK(!client_); |
| 178 DCHECK(!request_.isNull()); | 179 DCHECK(!request_.isNull()); |
| 179 if (!request_.httpBody().isNull()) | 180 if (!request_.httpBody().isNull()) |
| 180 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; | 181 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; |
| 181 | 182 |
| 182 request_.setRequestContext(request_context); | 183 request_.setRequestContext(request_context); |
| 183 request_.setFrameType(frame_type); | 184 request_.setFrameType(frame_type); |
| 184 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); | 185 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); |
| 185 frame->dispatchWillSendRequest(request_); | 186 request_.addHTTPOriginIfNeeded(blink::WebSecurityOrigin::createUnique()); |
| 186 | 187 |
| 187 client_.reset(new ClientImpl(this, callback)); | 188 client_.reset(new ClientImpl(this, callback)); |
| 188 | 189 |
| 189 loader_.reset(blink::Platform::current()->createURLLoader()); | 190 loader_.reset(blink::Platform::current()->createURLLoader()); |
| 190 loader_->loadAsynchronously(request_, client_.get()); | 191 loader_->loadAsynchronously(request_, client_.get()); |
| 191 | 192 |
| 192 // No need to hold on to the request; reset it now. | 193 // No need to hold on to the request; reset it now. |
| 193 request_ = blink::WebURLRequest(); | 194 request_ = blink::WebURLRequest(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) { | 197 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) { |
| 197 DCHECK(loader_); | 198 DCHECK(loader_); |
| 198 DCHECK(client_); | 199 DCHECK(client_); |
| 199 DCHECK(!client_->completed()); | 200 DCHECK(!client_->completed()); |
| 200 | 201 |
| 201 timeout_timer_.Start(FROM_HERE, timeout, this, &ResourceFetcherImpl::Cancel); | 202 timeout_timer_.Start(FROM_HERE, timeout, this, &ResourceFetcherImpl::Cancel); |
| 202 } | 203 } |
| 203 | 204 |
| 204 void ResourceFetcherImpl::OnLoadComplete() { | 205 void ResourceFetcherImpl::OnLoadComplete() { |
| 205 timeout_timer_.Stop(); | 206 timeout_timer_.Stop(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void ResourceFetcherImpl::Cancel() { | 209 void ResourceFetcherImpl::Cancel() { |
| 209 loader_->cancel(); | 210 loader_->cancel(); |
| 210 client_->Cancel(); | 211 client_->Cancel(); |
| 211 } | 212 } |
| 212 | 213 |
| 213 } // namespace content | 214 } // namespace content |
| OLD | NEW |