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_number_conversions.h" | |
7 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 11 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
11 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
12 #include "chrome/browser/ssl/ssl_blocking_page.h" | 13 #include "chrome/browser/ssl/ssl_blocking_page.h" |
13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/grit/browser_resources.h" | |
14 #include "content/public/browser/interstitial_page_delegate.h" | 16 #include "content/public/browser/interstitial_page_delegate.h" |
15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
17 #include "content/public/browser/web_ui_controller.h" | 19 #include "content/public/browser/web_ui_controller.h" |
18 #include "content/public/browser/web_ui_data_source.h" | 20 #include "content/public/browser/web_ui_data_source.h" |
19 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
20 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
21 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
22 #include "net/ssl/ssl_info.h" | 24 #include "net/ssl/ssl_info.h" |
25 #include "ui/base/resource/resource_bundle.h" | |
23 | 26 |
24 namespace { | 27 namespace { |
25 | 28 |
26 class InterstitialHTMLSource : public content::URLDataSource { | 29 class InterstitialHTMLSource : public content::URLDataSource { |
27 public: | 30 public: |
28 InterstitialHTMLSource(Profile* profile, | 31 InterstitialHTMLSource(Profile* profile, |
29 content::WebContents* web_contents); | 32 content::WebContents* web_contents); |
30 ~InterstitialHTMLSource() override; | 33 ~InterstitialHTMLSource() override; |
31 | 34 |
32 // content::URLDataSource: | 35 // content::URLDataSource: |
(...skipping 11 matching lines...) Expand all Loading... | |
44 content::WebContents* web_contents_; | 47 content::WebContents* web_contents_; |
45 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); | 48 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); |
46 }; | 49 }; |
47 | 50 |
48 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { | 51 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { |
49 // Random parameters for SSL blocking page. | 52 // Random parameters for SSL blocking page. |
50 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; | 53 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; |
51 GURL request_url("https://example.com"); | 54 GURL request_url("https://example.com"); |
52 bool overridable = false; | 55 bool overridable = false; |
53 bool strict_enforcement = false; | 56 bool strict_enforcement = false; |
57 base::Time time_triggered_ = base::Time::NowFromSystemTime(); | |
54 std::string url_param; | 58 std::string url_param; |
55 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 59 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
56 "url", | 60 "url", |
57 &url_param)) { | 61 &url_param)) { |
58 if (GURL(url_param).is_valid()) | 62 if (GURL(url_param).is_valid()) |
59 request_url = GURL(url_param); | 63 request_url = GURL(url_param); |
60 } | 64 } |
61 std::string overridable_param; | 65 std::string overridable_param; |
62 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 66 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
63 "overridable", | 67 "overridable", |
64 &overridable_param)) { | 68 &overridable_param)) { |
65 overridable = overridable_param == "1"; | 69 overridable = overridable_param == "1"; |
66 } | 70 } |
67 std::string strict_enforcement_param; | 71 std::string strict_enforcement_param; |
68 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 72 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
69 "strict_enforcement", | 73 "strict_enforcement", |
70 &strict_enforcement_param)) { | 74 &strict_enforcement_param)) { |
71 strict_enforcement = strict_enforcement_param == "1"; | 75 strict_enforcement = strict_enforcement_param == "1"; |
72 } | 76 } |
77 std::string clock_manipulation_param; | |
78 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "clock_manipulation", | |
79 &clock_manipulation_param) == 1) { | |
80 cert_error = net::ERR_CERT_DATE_INVALID; | |
81 int time_offset; | |
82 if (base::StringToInt(clock_manipulation_param, &time_offset)) { | |
83 time_triggered_ += base::TimeDelta::FromDays(365 * time_offset); | |
84 } else { | |
85 time_triggered_ += base::TimeDelta::FromDays(365*2); | |
Bernhard Bauer
2015/02/26 14:21:44
Add spaces around the asterisk?
fahl
2015/02/26 17:33:19
Done.
| |
86 } | |
87 } | |
73 net::SSLInfo ssl_info; | 88 net::SSLInfo ssl_info; |
74 ssl_info.cert = new net::X509Certificate( | 89 ssl_info.cert = new net::X509Certificate( |
75 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 90 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
76 // This delegate doesn't create an interstitial. | 91 // This delegate doesn't create an interstitial. |
77 int options_mask = 0; | 92 int options_mask = 0; |
78 if (overridable) | 93 if (overridable) |
79 options_mask |= SSLBlockingPage::OVERRIDABLE; | 94 options_mask |= SSLBlockingPage::OVERRIDABLE; |
80 if (strict_enforcement) | 95 if (strict_enforcement) |
81 options_mask |= SSLBlockingPage::STRICT_ENFORCEMENT; | 96 options_mask |= SSLBlockingPage::STRICT_ENFORCEMENT; |
82 return new SSLBlockingPage(web_contents, | 97 return new SSLBlockingPage(web_contents, |
83 cert_error, | 98 cert_error, |
84 ssl_info, | 99 ssl_info, |
85 request_url, | 100 request_url, |
86 options_mask, | 101 options_mask, |
87 base::Callback<void(bool)>()); | 102 base::Callback<void(bool)>(), |
103 time_triggered_); | |
88 } | 104 } |
89 | 105 |
90 SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage( | 106 SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage( |
91 content::WebContents* web_contents) { | 107 content::WebContents* web_contents) { |
92 SBThreatType threat_type = SB_THREAT_TYPE_URL_MALWARE; | 108 SBThreatType threat_type = SB_THREAT_TYPE_URL_MALWARE; |
93 GURL request_url("http://example.com"); | 109 GURL request_url("http://example.com"); |
94 std::string url_param; | 110 std::string url_param; |
95 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 111 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
96 "url", | 112 "url", |
97 &url_param)) { | 113 &url_param)) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 if (StartsWithASCII(path, "ssl", true)) { | 194 if (StartsWithASCII(path, "ssl", true)) { |
179 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); | 195 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); |
180 } else if (StartsWithASCII(path, "safebrowsing", true)) { | 196 } else if (StartsWithASCII(path, "safebrowsing", true)) { |
181 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); | 197 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); |
182 } | 198 } |
183 | 199 |
184 std::string html; | 200 std::string html; |
185 if (interstitial_delegate.get()) { | 201 if (interstitial_delegate.get()) { |
186 html = interstitial_delegate.get()->GetHTMLContents(); | 202 html = interstitial_delegate.get()->GetHTMLContents(); |
187 } else { | 203 } else { |
188 html = "<html><head><title>Interstitials</title></head>" | 204 html = ResourceBundle::GetSharedInstance() |
189 "<body><h2>Choose an interstitial<h2>" | 205 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
Bernhard Bauer
2015/02/26 14:21:44
Nit: Alignment
| |
190 "<h3>SSL</h3>" | 206 .as_string(); |
191 "<a href='ssl'>example.com</a><br>" | |
192 "<a href='ssl?url=https://google.com'>SSL (google.com)</a><br>" | |
193 "<a href='ssl?overridable=1&strict_enforcement=0'>" | |
194 " example.com (Overridable)</a>" | |
195 "<br><br>" | |
196 "<h3>SafeBrowsing</h3>" | |
197 "<a href='safebrowsing?type=malware'>Malware</a><br>" | |
198 "<a href='safebrowsing?type=phishing'>Phishing</a><br>" | |
199 "<a href='safebrowsing?type=clientside_malware'>" | |
200 " Client Side Malware</a><br>" | |
201 "<a href='safebrowsing?type=clientside_phishing'>" | |
202 " Client Side Phishing</a><br>" | |
203 "</body></html>"; | |
204 } | 207 } |
205 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 208 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
206 html_bytes->data().assign(html.begin(), html.end()); | 209 html_bytes->data().assign(html.begin(), html.end()); |
207 callback.Run(html_bytes.get()); | 210 callback.Run(html_bytes.get()); |
208 } | 211 } |
OLD | NEW |