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 "chrome/browser/prerender/prerender_contents.h" | 5 #include "chrome/browser/prerender/prerender_contents.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 using content::RenderViewHost; | 51 using content::RenderViewHost; |
52 using content::ResourceRedirectDetails; | 52 using content::ResourceRedirectDetails; |
53 using content::ResourceType; | 53 using content::ResourceType; |
54 using content::SessionStorageNamespace; | 54 using content::SessionStorageNamespace; |
55 using content::WebContents; | 55 using content::WebContents; |
56 | 56 |
57 namespace prerender { | 57 namespace prerender { |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
| 61 // Valid HTTP methods for both prefetch and prerendering. |
| 62 const char* const kValidHttpMethods[] = { |
| 63 "GET", "HEAD", |
| 64 }; |
| 65 |
| 66 // Additional valid HTTP methods for prerendering. |
| 67 const char* const kValidHttpMethodsForPrerendering[] = { |
| 68 "OPTIONS", "POST", "TRACE", |
| 69 }; |
| 70 |
61 void ResumeThrottles( | 71 void ResumeThrottles( |
62 std::vector<base::WeakPtr<PrerenderResourceThrottle> > throttles) { | 72 std::vector<base::WeakPtr<PrerenderResourceThrottle> > throttles) { |
63 for (size_t i = 0; i < throttles.size(); i++) { | 73 for (size_t i = 0; i < throttles.size(); i++) { |
64 if (throttles[i]) | 74 if (throttles[i]) |
65 throttles[i]->Resume(); | 75 throttles[i]->Resume(); |
66 } | 76 } |
67 } | 77 } |
68 | 78 |
69 } // namespace | 79 } // namespace |
70 | 80 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 226 |
217 bool PrerenderContents::Init() { | 227 bool PrerenderContents::Init() { |
218 return AddAliasURL(prerender_url_); | 228 return AddAliasURL(prerender_url_); |
219 } | 229 } |
220 | 230 |
221 void PrerenderContents::SetPrerenderMode(PrerenderMode mode) { | 231 void PrerenderContents::SetPrerenderMode(PrerenderMode mode) { |
222 DCHECK(!prerendering_has_started_); | 232 DCHECK(!prerendering_has_started_); |
223 prerender_mode_ = mode; | 233 prerender_mode_ = mode; |
224 } | 234 } |
225 | 235 |
| 236 bool PrerenderContents::IsValidHttpMethod(const std::string& method) { |
| 237 DCHECK_NE(prerender_mode(), NO_PRERENDER); |
| 238 // |method| has been canonicalized to upper case at this point so we can just |
| 239 // compare them. |
| 240 DCHECK_EQ(method, base::ToUpperASCII(method)); |
| 241 for (const auto& valid_method : kValidHttpMethods) { |
| 242 if (method == valid_method) |
| 243 return true; |
| 244 } |
| 245 |
| 246 if (prerender_mode() == PREFETCH_ONLY) |
| 247 return false; |
| 248 |
| 249 for (const auto& valid_method : kValidHttpMethodsForPrerendering) { |
| 250 if (method == valid_method) |
| 251 return true; |
| 252 } |
| 253 |
| 254 return false; |
| 255 } |
| 256 |
226 // static | 257 // static |
227 PrerenderContents::Factory* PrerenderContents::CreateFactory() { | 258 PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
228 return new PrerenderContentsFactoryImpl(); | 259 return new PrerenderContentsFactoryImpl(); |
229 } | 260 } |
230 | 261 |
231 // static | 262 // static |
232 PrerenderContents* PrerenderContents::FromWebContents( | 263 PrerenderContents* PrerenderContents::FromWebContents( |
233 content::WebContents* web_contents) { | 264 content::WebContents* web_contents) { |
234 if (!web_contents) | 265 if (!web_contents) |
235 return NULL; | 266 return NULL; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 void PrerenderContents::AddResourceThrottle( | 756 void PrerenderContents::AddResourceThrottle( |
726 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { | 757 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { |
727 resource_throttles_.push_back(throttle); | 758 resource_throttles_.push_back(throttle); |
728 } | 759 } |
729 | 760 |
730 void PrerenderContents::AddNetworkBytes(int64_t bytes) { | 761 void PrerenderContents::AddNetworkBytes(int64_t bytes) { |
731 network_bytes_ += bytes; | 762 network_bytes_ += bytes; |
732 } | 763 } |
733 | 764 |
734 } // namespace prerender | 765 } // namespace prerender |
OLD | NEW |