Chromium Code Reviews| Index: chrome/browser/predictors/resource_prefetch_predictor.cc |
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc |
| index b3e5453c80cbe4e99348edcae0fc2768844a6668..e2fcaf799c697f59009e327025df6a2232f6f401 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_predictor.cc |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.cc |
| @@ -52,6 +52,8 @@ const char* kFontMimeTypes[] = {"font/woff2", |
| const size_t kNumSampleHosts = 50; |
| const size_t kReportReadinessThreshold = 50; |
| +bool g_allow_port_in_urls = false; |
|
alexilin
2017/03/15 17:56:26
Why global flag and static setter instead of membe
|
| + |
| // For reporting events of interest that are not tied to any navigation. |
| enum ReportingEvent { |
| REPORTING_EVENT_ALL_HISTORY_CLEARED = 0, |
| @@ -273,16 +275,21 @@ bool ResourcePrefetchPredictor::ShouldRecordRedirect( |
| // static |
| bool ResourcePrefetchPredictor::IsHandledMainPage(net::URLRequest* request) { |
| - return request->url().SchemeIsHTTPOrHTTPS(); |
| + const GURL& url = request->url(); |
| + bool bad_port = !g_allow_port_in_urls && url.has_port(); |
| + return url.SchemeIsHTTPOrHTTPS() && !bad_port; |
| } |
| // static |
| bool ResourcePrefetchPredictor::IsHandledSubresource( |
| net::URLRequest* response, |
| content::ResourceType resource_type) { |
| + const GURL& url = response->url(); |
| + bool bad_port = !g_allow_port_in_urls && url.has_port(); |
| if (!response->first_party_for_cookies().SchemeIsHTTPOrHTTPS() || |
| - !response->url().SchemeIsHTTPOrHTTPS()) |
| + !url.SchemeIsHTTPOrHTTPS() || bad_port) { |
| return false; |
| + } |
| std::string mime_type; |
| response->GetMimeType(&mime_type); |
| @@ -398,6 +405,11 @@ bool ResourcePrefetchPredictor::GetRedirectEndpoint( |
| return true; |
| } |
| +// static |
| +void ResourcePrefetchPredictor::SetAllowPortInUrlsForTesting(bool state) { |
| + g_allow_port_in_urls = state; |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // ResourcePrefetchPredictor nested types. |