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_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 11 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
13 #include "chrome/browser/ssl/ssl_blocking_page.h" | 13 #include "chrome/browser/ssl/ssl_blocking_page.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/grit/browser_resources.h" | 15 #include "chrome/grit/browser_resources.h" |
16 #include "content/public/browser/interstitial_page_delegate.h" | 16 #include "content/public/browser/interstitial_page_delegate.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
19 #include "content/public/browser/web_ui_controller.h" | 19 #include "content/public/browser/web_ui_controller.h" |
20 #include "content/public/browser/web_ui_data_source.h" | 20 #include "content/public/browser/web_ui_data_source.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
23 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
24 #include "net/ssl/ssl_info.h" | 24 #include "net/ssl/ssl_info.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 | 26 |
| 27 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 28 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 29 #endif |
| 30 |
27 namespace { | 31 namespace { |
28 | 32 |
29 class InterstitialHTMLSource : public content::URLDataSource { | 33 class InterstitialHTMLSource : public content::URLDataSource { |
30 public: | 34 public: |
31 explicit InterstitialHTMLSource(content::WebContents* web_contents); | 35 explicit InterstitialHTMLSource(content::WebContents* web_contents); |
32 ~InterstitialHTMLSource() override; | 36 ~InterstitialHTMLSource() override; |
33 | 37 |
34 // content::URLDataSource: | 38 // content::URLDataSource: |
35 std::string GetMimeType(const std::string& mime_type) const override; | 39 std::string GetMimeType(const std::string& mime_type) const override; |
36 std::string GetSource() const override; | 40 std::string GetSource() const override; |
37 bool ShouldAddContentSecurityPolicy() const override; | 41 bool ShouldAddContentSecurityPolicy() const override; |
38 void StartDataRequest( | 42 void StartDataRequest( |
39 const std::string& path, | 43 const std::string& path, |
40 int render_process_id, | 44 int render_process_id, |
41 int render_frame_id, | 45 int render_frame_id, |
42 const content::URLDataSource::GotDataCallback& callback) override; | 46 const content::URLDataSource::GotDataCallback& callback) override; |
43 | 47 |
44 private: | 48 private: |
45 content::WebContents* web_contents_; | 49 content::WebContents* web_contents_; |
46 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); | 50 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); |
47 }; | 51 }; |
48 | 52 |
| 53 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 54 class FakeConnectionInfoDelegate : public CaptivePortalBlockingPage::Delegate { |
| 55 public: |
| 56 FakeConnectionInfoDelegate(bool is_wifi_connection, std::string wifi_ssid) |
| 57 : is_wifi_connection_(is_wifi_connection), wifi_ssid_(wifi_ssid) {} |
| 58 ~FakeConnectionInfoDelegate() override {} |
| 59 |
| 60 bool IsWifiConnection() const override { return is_wifi_connection_; } |
| 61 std::string GetWiFiSSID() const override { return wifi_ssid_; } |
| 62 |
| 63 private: |
| 64 bool is_wifi_connection_; |
| 65 const std::string wifi_ssid_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(FakeConnectionInfoDelegate); |
| 68 }; |
| 69 #endif |
| 70 |
49 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { | 71 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { |
50 // Random parameters for SSL blocking page. | 72 // Random parameters for SSL blocking page. |
51 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; | 73 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; |
52 GURL request_url("https://example.com"); | 74 GURL request_url("https://example.com"); |
53 bool overridable = false; | 75 bool overridable = false; |
54 bool strict_enforcement = false; | 76 bool strict_enforcement = false; |
55 base::Time time_triggered_ = base::Time::NowFromSystemTime(); | 77 base::Time time_triggered_ = base::Time::NowFromSystemTime(); |
56 std::string url_param; | 78 std::string url_param; |
57 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 79 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
58 "url", | 80 "url", |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 SafeBrowsingBlockingPage::UnsafeResource resource; | 154 SafeBrowsingBlockingPage::UnsafeResource resource; |
133 resource.url = request_url; | 155 resource.url = request_url; |
134 resource.threat_type = threat_type; | 156 resource.threat_type = threat_type; |
135 // Create a blocking page without showing the interstitial. | 157 // Create a blocking page without showing the interstitial. |
136 return SafeBrowsingBlockingPage::CreateBlockingPage( | 158 return SafeBrowsingBlockingPage::CreateBlockingPage( |
137 g_browser_process->safe_browsing_service()->ui_manager().get(), | 159 g_browser_process->safe_browsing_service()->ui_manager().get(), |
138 web_contents, | 160 web_contents, |
139 resource); | 161 resource); |
140 } | 162 } |
141 | 163 |
| 164 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 165 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( |
| 166 content::WebContents* web_contents) { |
| 167 bool is_wifi_connection = false; |
| 168 GURL landing_url("https://captive.portal/login"); |
| 169 GURL request_url("https://google.com"); |
| 170 // Not initialized to a default value, since non-empty wifi_ssid is |
| 171 // considered a wifi connection, even if is_wifi_connection is false. |
| 172 std::string wifi_ssid; |
| 173 |
| 174 std::string request_url_param; |
| 175 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "url", |
| 176 &request_url_param)) { |
| 177 if (GURL(request_url_param).is_valid()) |
| 178 request_url = GURL(request_url_param); |
| 179 } |
| 180 std::string landing_url_param; |
| 181 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "landing_page", |
| 182 &landing_url_param)) { |
| 183 if (GURL(landing_url_param).is_valid()) |
| 184 landing_url = GURL(landing_url_param); |
| 185 } |
| 186 std::string wifi_connection_param; |
| 187 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "is_wifi", |
| 188 &wifi_connection_param)) { |
| 189 is_wifi_connection = wifi_connection_param == "1"; |
| 190 } |
| 191 std::string wifi_ssid_param; |
| 192 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "wifi_name", |
| 193 &wifi_ssid_param)) { |
| 194 wifi_ssid = wifi_ssid_param; |
| 195 } |
| 196 FakeConnectionInfoDelegate* delegate = |
| 197 new FakeConnectionInfoDelegate(is_wifi_connection, wifi_ssid); |
| 198 net::SSLInfo ssl_info; |
| 199 ssl_info.cert = new net::X509Certificate( |
| 200 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
| 201 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( |
| 202 web_contents, request_url, landing_url, nullptr, ssl_info, |
| 203 base::Callback<void(bool)>()); |
| 204 blocking_page->SetDelegate(delegate); |
| 205 return blocking_page; |
| 206 } |
| 207 #endif |
| 208 |
142 } // namespace | 209 } // namespace |
143 | 210 |
144 InterstitialUI::InterstitialUI(content::WebUI* web_ui) | 211 InterstitialUI::InterstitialUI(content::WebUI* web_ui) |
145 : WebUIController(web_ui) { | 212 : WebUIController(web_ui) { |
146 scoped_ptr<InterstitialHTMLSource> html_source( | 213 scoped_ptr<InterstitialHTMLSource> html_source( |
147 new InterstitialHTMLSource(web_ui->GetWebContents())); | 214 new InterstitialHTMLSource(web_ui->GetWebContents())); |
148 Profile* profile = Profile::FromWebUI(web_ui); | 215 Profile* profile = Profile::FromWebUI(web_ui); |
149 content::URLDataSource::Add(profile, html_source.release()); | 216 content::URLDataSource::Add(profile, html_source.release()); |
150 } | 217 } |
151 | 218 |
(...skipping 29 matching lines...) Expand all Loading... |
181 int render_process_id, | 248 int render_process_id, |
182 int render_frame_id, | 249 int render_frame_id, |
183 const content::URLDataSource::GotDataCallback& callback) { | 250 const content::URLDataSource::GotDataCallback& callback) { |
184 scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate; | 251 scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate; |
185 if (base::StartsWith(path, "ssl", base::CompareCase::SENSITIVE)) { | 252 if (base::StartsWith(path, "ssl", base::CompareCase::SENSITIVE)) { |
186 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); | 253 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); |
187 } else if (base::StartsWith(path, "safebrowsing", | 254 } else if (base::StartsWith(path, "safebrowsing", |
188 base::CompareCase::SENSITIVE)) { | 255 base::CompareCase::SENSITIVE)) { |
189 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); | 256 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); |
190 } | 257 } |
191 | 258 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 259 else if (base::StartsWithASCII(path, "captiveportal", true)) |
| 260 { |
| 261 interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents_)); |
| 262 } |
| 263 #endif |
192 std::string html; | 264 std::string html; |
193 if (interstitial_delegate.get()) { | 265 if (interstitial_delegate.get()) { |
194 html = interstitial_delegate.get()->GetHTMLContents(); | 266 html = interstitial_delegate.get()->GetHTMLContents(); |
195 } else { | 267 } else { |
196 html = ResourceBundle::GetSharedInstance() | 268 html = ResourceBundle::GetSharedInstance() |
197 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) | 269 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
198 .as_string(); | 270 .as_string(); |
199 } | 271 } |
200 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 272 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
201 html_bytes->data().assign(html.begin(), html.end()); | 273 html_bytes->data().assign(html.begin(), html.end()); |
202 callback.Run(html_bytes.get()); | 274 callback.Run(html_bytes.get()); |
203 } | 275 } |
OLD | NEW |