1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/prerender/prerender_util.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/strings/string_util.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/resource_type.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_canon.h"
#include "url/url_util.h"
using content::ResourceType;
namespace prerender {
namespace {
enum PrerenderSchemeCancelReason {
PRERENDER_SCHEME_CANCEL_REASON_EXTERNAL_PROTOCOL,
PRERENDER_SCHEME_CANCEL_REASON_DATA,
PRERENDER_SCHEME_CANCEL_REASON_BLOB,
PRERENDER_SCHEME_CANCEL_REASON_FILE,
PRERENDER_SCHEME_CANCEL_REASON_FILESYSTEM,
PRERENDER_SCHEME_CANCEL_REASON_WEBSOCKET,
PRERENDER_SCHEME_CANCEL_REASON_FTP,
PRERENDER_SCHEME_CANCEL_REASON_CHROME,
PRERENDER_SCHEME_CANCEL_REASON_CHROME_EXTENSION,
PRERENDER_SCHEME_CANCEL_REASON_ABOUT,
PRERENDER_SCHEME_CANCEL_REASON_UNKNOWN,
PRERENDER_SCHEME_CANCEL_REASON_MAX,
};
void ReportPrerenderSchemeCancelReason(PrerenderSchemeCancelReason reason) {
UMA_HISTOGRAM_ENUMERATION(
"Prerender.SchemeCancelReason", reason,
PRERENDER_SCHEME_CANCEL_REASON_MAX);
}
} // namespace
bool MaybeGetQueryStringBasedAliasURL(
const GURL& url, GURL* alias_url) {
DCHECK(alias_url);
url::Parsed parsed;
url::ParseStandardURL(url.spec().c_str(), url.spec().length(), &parsed);
url::Component query = parsed.query;
url::Component key, value;
while (url::ExtractQueryKeyValue(url.spec().c_str(), &query, &key, &value)) {
if (key.len != 3 || strncmp(url.spec().c_str() + key.begin, "url", key.len))
continue;
// We found a url= query string component.
if (value.len < 1)
continue;
url::RawCanonOutputW<1024> decoded_url;
url::DecodeURLEscapeSequences(url.spec().c_str() + value.begin, value.len,
&decoded_url);
GURL new_url(base::string16(decoded_url.data(), decoded_url.length()));
if (!new_url.is_empty() && new_url.is_valid()) {
*alias_url = new_url;
return true;
}
return false;
}
return false;
}
bool IsGoogleDomain(const GURL& url) {
return base::StartsWithASCII(url.host(), std::string("www.google."), true);
}
bool IsGoogleSearchResultURL(const GURL& url) {
if (!IsGoogleDomain(url))
return false;
return (url.path().empty() ||
base::StartsWithASCII(url.path(), std::string("/search"), true) ||
(url.path() == "/") ||
base::StartsWithASCII(url.path(), std::string("/webhp"), true));
}
void ReportPrerenderExternalURL() {
ReportPrerenderSchemeCancelReason(
PRERENDER_SCHEME_CANCEL_REASON_EXTERNAL_PROTOCOL);
}
void ReportUnsupportedPrerenderScheme(const GURL& url) {
if (url.SchemeIs("data")) {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_DATA);
} else if (url.SchemeIs("blob")) {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_BLOB);
} else if (url.SchemeIsFile()) {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_FILE);
} else if (url.SchemeIsFileSystem()) {
ReportPrerenderSchemeCancelReason(
PRERENDER_SCHEME_CANCEL_REASON_FILESYSTEM);
} else if (url.SchemeIs("ws") || url.SchemeIs("wss")) {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_WEBSOCKET);
} else if (url.SchemeIs("ftp")) {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_FTP);
} else if (url.SchemeIs("chrome")) {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_CHROME);
} else if (url.SchemeIs("chrome-extension")) {
ReportPrerenderSchemeCancelReason(
PRERENDER_SCHEME_CANCEL_REASON_CHROME_EXTENSION);
} else if (url.SchemeIs("about")) {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_ABOUT);
} else {
ReportPrerenderSchemeCancelReason(PRERENDER_SCHEME_CANCEL_REASON_UNKNOWN);
}
}
} // namespace prerender
|