Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: chrome/browser/prerender/prerender_contents.cc

Issue 2355453002: [NoStatePrefetch] Support only GET and HEAD (Closed)
Patch Set: format Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) {
mmenke 2016/09/20 15:25:32 optional nit: for both the loops, can just do: f
droger 2016/09/21 09:57:48 Done.
242 if (method.compare(kValidHttpMethods[i]) == 0)
mmenke 2016/09/20 15:25:32 Know this is what the old code did, but maybe we s
droger 2016/09/21 09:57:48 TIL According to this: http://stackoverflow.com/q
243 return true;
244 }
245
246 if (prerender_mode() == PREFETCH_ONLY)
247 return false;
248
249 for (size_t i = 0; i < arraysize(kValidHttpMethodsForPrerendering); ++i) {
250 if (method.compare(kValidHttpMethodsForPrerendering[i]) == 0)
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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 void PrerenderContents::AddResourceThrottle( 755 void PrerenderContents::AddResourceThrottle(
725 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { 756 const base::WeakPtr<PrerenderResourceThrottle>& throttle) {
726 resource_throttles_.push_back(throttle); 757 resource_throttles_.push_back(throttle);
727 } 758 }
728 759
729 void PrerenderContents::AddNetworkBytes(int64_t bytes) { 760 void PrerenderContents::AddNetworkBytes(int64_t bytes) {
730 network_bytes_ += bytes; 761 network_bytes_ += bytes;
731 } 762 }
732 763
733 } // namespace prerender 764 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698