| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "third_party/WebKit/public/platform/Platform.h" | 10 #include "third_party/WebKit/public/platform/Platform.h" |
| 11 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 11 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
| 12 #include "third_party/WebKit/public/platform/WebURL.h" | 12 #include "third_party/WebKit/public/platform/WebURL.h" |
| 13 #include "third_party/WebKit/public/platform/WebURLError.h" | 13 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLLoader.h" | 14 #include "third_party/WebKit/public/platform/WebURLLoader.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 15 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 16 #include "third_party/WebKit/public/web/WebDocument.h" | 16 #include "third_party/WebKit/public/web/WebDocument.h" |
| 17 #include "third_party/WebKit/public/web/WebFrame.h" | 17 #include "third_party/WebKit/public/web/WebFrame.h" |
| 18 #include "third_party/WebKit/public/web/WebKit.h" | 18 #include "third_party/WebKit/public/web/WebKit.h" |
| 19 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 19 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 20 | 20 |
| 21 using base::TimeDelta; | 21 using base::TimeDelta; |
| 22 using blink::WebFrame; | 22 using blink::WebFrame; |
| 23 using blink::WebHTTPBody; | 23 using blink::WebHTTPBody; |
| 24 using blink::WebSecurityPolicy; | 24 using blink::WebSecurityPolicy; |
| 25 using blink::WebURLError; | 25 using blink::WebURLError; |
| 26 using blink::WebURLLoader; | 26 using blink::WebURLLoader; |
| 27 using blink::WebURLLoaderOptions; |
| 27 using blink::WebURLRequest; | 28 using blink::WebURLRequest; |
| 28 using blink::WebURLResponse; | 29 using blink::WebURLResponse; |
| 29 | 30 |
| 30 namespace content { | 31 namespace content { |
| 31 | 32 |
| 32 // static | 33 // static |
| 33 ResourceFetcher* ResourceFetcher::Create(const GURL& url) { | 34 ResourceFetcher* ResourceFetcher::Create(const GURL& url) { |
| 34 return new ResourceFetcherImpl(url); | 35 return new ResourceFetcherImpl(url); |
| 35 } | 36 } |
| 36 | 37 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 blink::WebReferrerPolicyDefault, | 71 blink::WebReferrerPolicyDefault, |
| 71 request_.url(), | 72 request_.url(), |
| 72 blink::WebString::fromUTF8(value)); | 73 blink::WebString::fromUTF8(value)); |
| 73 request_.setHTTPReferrer(referrer, blink::WebReferrerPolicyDefault); | 74 request_.setHTTPReferrer(referrer, blink::WebReferrerPolicyDefault); |
| 74 } else { | 75 } else { |
| 75 request_.setHTTPHeaderField(blink::WebString::fromUTF8(header), | 76 request_.setHTTPHeaderField(blink::WebString::fromUTF8(header), |
| 76 blink::WebString::fromUTF8(value)); | 77 blink::WebString::fromUTF8(value)); |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 81 void ResourceFetcherImpl::SetLoaderOptions(const WebURLLoaderOptions& options) { |
| 82 options_ = options; |
| 83 } |
| 84 |
| 80 void ResourceFetcherImpl::Start(WebFrame* frame, | 85 void ResourceFetcherImpl::Start(WebFrame* frame, |
| 81 WebURLRequest::RequestContext request_context, | 86 WebURLRequest::RequestContext request_context, |
| 82 WebURLRequest::FrameType frame_type, | 87 WebURLRequest::FrameType frame_type, |
| 83 LoaderType loader_type, | 88 LoaderType loader_type, |
| 84 const Callback& callback) { | 89 const Callback& callback) { |
| 85 DCHECK(!loader_); | 90 DCHECK(!loader_); |
| 86 DCHECK(!request_.isNull()); | 91 DCHECK(!request_.isNull()); |
| 87 DCHECK(callback_.is_null()); | 92 DCHECK(callback_.is_null()); |
| 88 DCHECK(!completed()); | 93 DCHECK(!completed()); |
| 89 if (!request_.httpBody().isNull()) | 94 if (!request_.httpBody().isNull()) |
| 90 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; | 95 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; |
| 91 | 96 |
| 92 callback_ = callback; | 97 callback_ = callback; |
| 93 | 98 |
| 94 request_.setRequestContext(request_context); | 99 request_.setRequestContext(request_context); |
| 95 request_.setFrameType(frame_type); | 100 request_.setFrameType(frame_type); |
| 96 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); | 101 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); |
| 97 frame->dispatchWillSendRequest(request_); | 102 frame->dispatchWillSendRequest(request_); |
| 98 | 103 |
| 99 switch (loader_type) { | 104 switch (loader_type) { |
| 100 case PLATFORM_LOADER: | 105 case PLATFORM_LOADER: |
| 101 loader_.reset(blink::Platform::current()->createURLLoader()); | 106 loader_.reset(blink::Platform::current()->createURLLoader()); |
| 102 break; | 107 break; |
| 103 case FRAME_ASSOCIATED_LOADER: | 108 case FRAME_ASSOCIATED_LOADER: |
| 104 loader_.reset(frame->createAssociatedURLLoader()); | 109 loader_.reset(frame->createAssociatedURLLoader(options_)); |
| 105 break; | 110 break; |
| 106 } | 111 } |
| 107 loader_->loadAsynchronously(request_, this); | 112 loader_->loadAsynchronously(request_, this); |
| 108 | 113 |
| 109 // No need to hold on to the request. | 114 // No need to hold on to the request. |
| 110 request_.reset(); | 115 request_.reset(); |
| 111 } | 116 } |
| 112 | 117 |
| 113 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) { | 118 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) { |
| 114 DCHECK(loader_); | 119 DCHECK(loader_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 128 callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(), | 133 callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(), |
| 129 status() == LOAD_FAILED ? std::string() : data()); | 134 status() == LOAD_FAILED ? std::string() : data()); |
| 130 } | 135 } |
| 131 | 136 |
| 132 void ResourceFetcherImpl::Cancel() { | 137 void ResourceFetcherImpl::Cancel() { |
| 133 loader_->cancel(); | 138 loader_->cancel(); |
| 134 WebURLLoaderClientImpl::Cancel(); | 139 WebURLLoaderClientImpl::Cancel(); |
| 135 } | 140 } |
| 136 | 141 |
| 137 } // namespace content | 142 } // namespace content |
| OLD | NEW |