OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui/interstitials/interstitial_ui.h" | 5 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 content::WebContents* web_contents_; | 44 content::WebContents* web_contents_; |
45 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); | 45 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); |
46 }; | 46 }; |
47 | 47 |
48 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { | 48 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { |
49 // Random parameters for SSL blocking page. | 49 // Random parameters for SSL blocking page. |
50 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; | 50 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; |
51 GURL request_url("https://example.com"); | 51 GURL request_url("https://example.com"); |
52 bool overridable = false; | 52 bool overridable = false; |
53 bool strict_enforcement = false; | 53 bool strict_enforcement = false; |
54 base::Time time_triggered_ = base::Time::NowFromSystemTime(); | |
55 | |
54 std::string url_param; | 56 std::string url_param; |
55 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 57 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
56 "url", | 58 "url", |
57 &url_param)) { | 59 &url_param)) { |
58 if (GURL(url_param).is_valid()) | 60 if (GURL(url_param).is_valid()) |
59 request_url = GURL(url_param); | 61 request_url = GURL(url_param); |
60 } | 62 } |
61 std::string overridable_param; | 63 std::string overridable_param; |
62 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 64 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
63 "overridable", | 65 "overridable", |
64 &overridable_param)) { | 66 &overridable_param)) { |
65 overridable = overridable_param == "1"; | 67 overridable = overridable_param == "1"; |
66 } | 68 } |
67 std::string strict_enforcement_param; | 69 std::string strict_enforcement_param; |
68 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 70 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
69 "strict_enforcement", | 71 "strict_enforcement", |
70 &strict_enforcement_param)) { | 72 &strict_enforcement_param)) { |
71 strict_enforcement = strict_enforcement_param == "1"; | 73 strict_enforcement = strict_enforcement_param == "1"; |
72 } | 74 } |
75 | |
76 std::string clock_manipulation_param; | |
77 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "clock_manipulation", | |
78 &clock_manipulation_param) == 1) { | |
79 cert_error = net::ERR_CERT_DATE_INVALID; | |
80 time_triggered_ += | |
81 base::TimeDelta::FromDays(365 * atoi(clock_manipulation_param.c_str())); | |
82 } | |
83 | |
73 net::SSLInfo ssl_info; | 84 net::SSLInfo ssl_info; |
74 ssl_info.cert = new net::X509Certificate( | 85 ssl_info.cert = new net::X509Certificate( |
75 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 86 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
76 // This delegate doesn't create an interstitial. | 87 // This delegate doesn't create an interstitial. |
77 int options_mask = 0; | 88 int options_mask = 0; |
78 if (overridable) | 89 if (overridable) |
79 options_mask |= SSLBlockingPage::OVERRIDABLE; | 90 options_mask |= SSLBlockingPage::OVERRIDABLE; |
80 if (strict_enforcement) | 91 if (strict_enforcement) |
81 options_mask |= SSLBlockingPage::STRICT_ENFORCEMENT; | 92 options_mask |= SSLBlockingPage::STRICT_ENFORCEMENT; |
82 return new SSLBlockingPage(web_contents, | 93 return new SSLBlockingPage(web_contents, cert_error, ssl_info, request_url, |
83 cert_error, | 94 options_mask, base::Callback<void(bool)>(), |
84 ssl_info, | 95 time_triggered_); |
85 request_url, | |
86 options_mask, | |
87 base::Callback<void(bool)>()); | |
88 } | 96 } |
89 | 97 |
90 SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage( | 98 SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage( |
91 content::WebContents* web_contents) { | 99 content::WebContents* web_contents) { |
92 SBThreatType threat_type = SB_THREAT_TYPE_URL_MALWARE; | 100 SBThreatType threat_type = SB_THREAT_TYPE_URL_MALWARE; |
93 GURL request_url("http://example.com"); | 101 GURL request_url("http://example.com"); |
94 std::string url_param; | 102 std::string url_param; |
95 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 103 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
96 "url", | 104 "url", |
97 &url_param)) { | 105 &url_param)) { |
(...skipping 24 matching lines...) Expand all Loading... | |
122 SafeBrowsingBlockingPage::UnsafeResource resource; | 130 SafeBrowsingBlockingPage::UnsafeResource resource; |
123 resource.url = request_url; | 131 resource.url = request_url; |
124 resource.threat_type = threat_type; | 132 resource.threat_type = threat_type; |
125 // Create a blocking page without showing the interstitial. | 133 // Create a blocking page without showing the interstitial. |
126 return SafeBrowsingBlockingPage::CreateBlockingPage( | 134 return SafeBrowsingBlockingPage::CreateBlockingPage( |
127 g_browser_process->safe_browsing_service()->ui_manager().get(), | 135 g_browser_process->safe_browsing_service()->ui_manager().get(), |
128 web_contents, | 136 web_contents, |
129 resource); | 137 resource); |
130 } | 138 } |
131 | 139 |
132 } // namespace | 140 } // namespace |
lgarron
2015/02/24 02:28:37
Nit: still an uneeded extra space in the diff.
fahl
2015/02/24 21:23:23
Done.
| |
133 | 141 |
134 InterstitialUI::InterstitialUI(content::WebUI* web_ui) | 142 InterstitialUI::InterstitialUI(content::WebUI* web_ui) |
135 : WebUIController(web_ui) { | 143 : WebUIController(web_ui) { |
136 Profile* profile = Profile::FromWebUI(web_ui); | 144 Profile* profile = Profile::FromWebUI(web_ui); |
137 scoped_ptr<InterstitialHTMLSource> html_source( | 145 scoped_ptr<InterstitialHTMLSource> html_source( |
138 new InterstitialHTMLSource(profile->GetOriginalProfile(), | 146 new InterstitialHTMLSource(profile->GetOriginalProfile(), |
139 web_ui->GetWebContents())); | 147 web_ui->GetWebContents())); |
140 content::URLDataSource::Add(profile, html_source.release()); | 148 content::URLDataSource::Add(profile, html_source.release()); |
141 } | 149 } |
142 | 150 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 if (StartsWithASCII(path, "ssl", true)) { | 186 if (StartsWithASCII(path, "ssl", true)) { |
179 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); | 187 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); |
180 } else if (StartsWithASCII(path, "safebrowsing", true)) { | 188 } else if (StartsWithASCII(path, "safebrowsing", true)) { |
181 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); | 189 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); |
182 } | 190 } |
183 | 191 |
184 std::string html; | 192 std::string html; |
185 if (interstitial_delegate.get()) { | 193 if (interstitial_delegate.get()) { |
186 html = interstitial_delegate.get()->GetHTMLContents(); | 194 html = interstitial_delegate.get()->GetHTMLContents(); |
187 } else { | 195 } else { |
188 html = "<html><head><title>Interstitials</title></head>" | 196 html = "<html><head><title>Interstitials</title></head>" |
189 "<body><h2>Choose an interstitial<h2>" | 197 "<body><h2>Choose an interstitial<h2>" |
190 "<h3>SSL</h3>" | 198 "<h3>SSL</h3>" |
191 "<a href='ssl'>example.com</a><br>" | 199 "<a href='ssl'>example.com</a><br>" |
192 "<a href='ssl?url=https://google.com'>SSL (google.com)</a><br>" | 200 "<a href='ssl?url=https://google.com'>SSL (google.com)</a><br>" |
193 "<a href='ssl?overridable=1&strict_enforcement=0'>" | 201 "<a href='ssl?overridable=1&strict_enforcement=0'>" |
194 " example.com (Overridable)</a>" | 202 " example.com (Overridable)</a><br>" |
195 "<br><br>" | 203 "<a href='ssl?clock_manipulation=1'>Clock is ahead</a><br>" |
196 "<h3>SafeBrowsing</h3>" | 204 "<a href='ssl?clock_manipulation=-1'>Clock is behind</a><br>" |
197 "<a href='safebrowsing?type=malware'>Malware</a><br>" | 205 "<br><br>" |
198 "<a href='safebrowsing?type=phishing'>Phishing</a><br>" | 206 "<h3>SafeBrowsing</h3>" |
199 "<a href='safebrowsing?type=clientside_malware'>" | 207 "<a href='safebrowsing?type=malware'>Malware</a><br>" |
200 " Client Side Malware</a><br>" | 208 "<a href='safebrowsing?type=phishing'>Phishing</a><br>" |
201 "<a href='safebrowsing?type=clientside_phishing'>" | 209 "<a href='safebrowsing?type=clientside_malware'>" |
202 " Client Side Phishing</a><br>" | 210 " Client Side Malware</a><br>" |
203 "</body></html>"; | 211 "<a href='safebrowsing?type=clientside_phishing'>" |
212 " Client Side Phishing</a><br>" | |
213 "</body></html>"; | |
204 } | 214 } |
215 | |
lgarron
2015/02/24 02:28:37
Also an extra space.
fahl
2015/02/24 21:23:23
Done.
| |
205 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 216 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
206 html_bytes->data().assign(html.begin(), html.end()); | 217 html_bytes->data().assign(html.begin(), html.end()); |
207 callback.Run(html_bytes.get()); | 218 callback.Run(html_bytes.get()); |
208 } | 219 } |
OLD | NEW |