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/captive_portal/captive_portal_service.h" | |
10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
14 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | |
13 #include "chrome/browser/ssl/ssl_blocking_page.h" | 15 #include "chrome/browser/ssl/ssl_blocking_page.h" |
14 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
15 #include "chrome/grit/browser_resources.h" | 17 #include "chrome/grit/browser_resources.h" |
16 #include "content/public/browser/interstitial_page_delegate.h" | 18 #include "content/public/browser/interstitial_page_delegate.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
19 #include "content/public/browser/web_ui_controller.h" | 21 #include "content/public/browser/web_ui_controller.h" |
20 #include "content/public/browser/web_ui_data_source.h" | 22 #include "content/public/browser/web_ui_data_source.h" |
21 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
22 #include "net/base/url_util.h" | 24 #include "net/base/url_util.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
39 const std::string& path, | 41 const std::string& path, |
40 int render_process_id, | 42 int render_process_id, |
41 int render_frame_id, | 43 int render_frame_id, |
42 const content::URLDataSource::GotDataCallback& callback) override; | 44 const content::URLDataSource::GotDataCallback& callback) override; |
43 | 45 |
44 private: | 46 private: |
45 content::WebContents* web_contents_; | 47 content::WebContents* web_contents_; |
46 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); | 48 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); |
47 }; | 49 }; |
48 | 50 |
51 class FakeConnectionInfoDelegate : public CaptivePortalBlockingPage::Delegate { | |
52 public: | |
53 FakeConnectionInfoDelegate(bool is_wifi_connection, std::string wifi_ssid) | |
54 : is_wifi_connection_(is_wifi_connection), wifi_ssid_(wifi_ssid) {} | |
55 ~FakeConnectionInfoDelegate() override {} | |
56 | |
57 bool IsWifiConnection() const override { return is_wifi_connection_; } | |
58 std::string GetWiFiSSID() const override { return wifi_ssid_; } | |
59 | |
60 private: | |
61 const bool is_wifi_connection_; | |
meacer
2015/06/19 21:23:18
no need for const for bool.
Bhanu Dev
2015/06/19 22:35:51
Done.
| |
62 const std::string wifi_ssid_; | |
meacer
2015/06/19 21:23:18
Use a reference here: |const std::string& wifi_ssi
| |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(FakeConnectionInfoDelegate); | |
65 }; | |
Bhanu Dev
2015/06/19 21:09:03
I am not sure if this is the correct place to plac
meacer
2015/06/19 21:23:18
Looks okay, it's obvious from the base class name
Bhanu Dev
2015/06/19 22:35:51
Done.
| |
66 | |
49 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { | 67 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { |
50 // Random parameters for SSL blocking page. | 68 // Random parameters for SSL blocking page. |
51 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; | 69 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; |
52 GURL request_url("https://example.com"); | 70 GURL request_url("https://example.com"); |
53 bool overridable = false; | 71 bool overridable = false; |
54 bool strict_enforcement = false; | 72 bool strict_enforcement = false; |
55 base::Time time_triggered_ = base::Time::NowFromSystemTime(); | 73 base::Time time_triggered_ = base::Time::NowFromSystemTime(); |
56 std::string url_param; | 74 std::string url_param; |
57 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 75 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
58 "url", | 76 "url", |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 SafeBrowsingBlockingPage::UnsafeResource resource; | 150 SafeBrowsingBlockingPage::UnsafeResource resource; |
133 resource.url = request_url; | 151 resource.url = request_url; |
134 resource.threat_type = threat_type; | 152 resource.threat_type = threat_type; |
135 // Create a blocking page without showing the interstitial. | 153 // Create a blocking page without showing the interstitial. |
136 return SafeBrowsingBlockingPage::CreateBlockingPage( | 154 return SafeBrowsingBlockingPage::CreateBlockingPage( |
137 g_browser_process->safe_browsing_service()->ui_manager().get(), | 155 g_browser_process->safe_browsing_service()->ui_manager().get(), |
138 web_contents, | 156 web_contents, |
139 resource); | 157 resource); |
140 } | 158 } |
141 | 159 |
160 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( | |
161 content::WebContents* web_contents) { | |
162 bool is_wifi_connection = 0; | |
meacer
2015/06/19 21:23:19
false instead of 0.
Bhanu Dev
2015/06/19 22:35:51
Done.
| |
163 GURL landing_url("https://captive.portal/login"); | |
164 GURL request_url("https://google.com"); | |
165 std::string wifi_ssid; | |
meacer
2015/06/19 21:23:18
If no "wifi_name" query param is passed this will
| |
166 | |
167 std::string request_url_param; | |
168 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "url", | |
169 &request_url_param)) { | |
170 if (GURL(request_url_param).is_valid()) | |
171 request_url = GURL(request_url_param); | |
172 } | |
173 std::string landing_url_param; | |
174 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "landing_page", | |
175 &landing_url_param)) { | |
176 if (GURL(landing_url_param).is_valid()) | |
177 landing_url = GURL(landing_url_param); | |
178 } | |
179 std::string wifi_connection_param; | |
180 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "is_wifi", | |
181 &wifi_connection_param)) { | |
182 is_wifi_connection = wifi_connection_param == "1"; | |
183 } | |
184 std::string wifi_ssid_param; | |
185 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "wifi_name", | |
186 &wifi_ssid_param)) { | |
187 wifi_ssid = wifi_ssid_param; | |
188 } | |
189 FakeConnectionInfoDelegate* delegate = | |
190 new FakeConnectionInfoDelegate(is_wifi_connection, wifi_ssid); | |
191 net::SSLInfo ssl_info; | |
192 ssl_info.cert = new net::X509Certificate( | |
193 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | |
194 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( | |
195 web_contents, request_url, landing_url, nullptr, ssl_info, | |
196 base::Callback<void(bool)>()); | |
197 blocking_page->SetDelegateForTesting(delegate); | |
Bhanu Dev
2015/06/19 21:09:03
This is a testing function. I am not sure if can I
meacer
2015/06/19 21:23:19
Oh, right :( Let's make it a non-test method and a
| |
198 return blocking_page; | |
199 } | |
200 | |
142 } // namespace | 201 } // namespace |
143 | 202 |
144 InterstitialUI::InterstitialUI(content::WebUI* web_ui) | 203 InterstitialUI::InterstitialUI(content::WebUI* web_ui) |
145 : WebUIController(web_ui) { | 204 : WebUIController(web_ui) { |
146 scoped_ptr<InterstitialHTMLSource> html_source( | 205 scoped_ptr<InterstitialHTMLSource> html_source( |
147 new InterstitialHTMLSource(web_ui->GetWebContents())); | 206 new InterstitialHTMLSource(web_ui->GetWebContents())); |
148 Profile* profile = Profile::FromWebUI(web_ui); | 207 Profile* profile = Profile::FromWebUI(web_ui); |
149 content::URLDataSource::Add(profile, html_source.release()); | 208 content::URLDataSource::Add(profile, html_source.release()); |
150 } | 209 } |
151 | 210 |
(...skipping 27 matching lines...) Expand all Loading... | |
179 void InterstitialHTMLSource::StartDataRequest( | 238 void InterstitialHTMLSource::StartDataRequest( |
180 const std::string& path, | 239 const std::string& path, |
181 int render_process_id, | 240 int render_process_id, |
182 int render_frame_id, | 241 int render_frame_id, |
183 const content::URLDataSource::GotDataCallback& callback) { | 242 const content::URLDataSource::GotDataCallback& callback) { |
184 scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate; | 243 scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate; |
185 if (StartsWithASCII(path, "ssl", true)) { | 244 if (StartsWithASCII(path, "ssl", true)) { |
186 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); | 245 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); |
187 } else if (StartsWithASCII(path, "safebrowsing", true)) { | 246 } else if (StartsWithASCII(path, "safebrowsing", true)) { |
188 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); | 247 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); |
248 } else if (StartsWithASCII(path, "captiveportal", true)) { | |
249 interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents_)); | |
189 } | 250 } |
190 | 251 |
191 std::string html; | 252 std::string html; |
192 if (interstitial_delegate.get()) { | 253 if (interstitial_delegate.get()) { |
193 html = interstitial_delegate.get()->GetHTMLContents(); | 254 html = interstitial_delegate.get()->GetHTMLContents(); |
194 } else { | 255 } else { |
195 html = ResourceBundle::GetSharedInstance() | 256 html = ResourceBundle::GetSharedInstance() |
196 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) | 257 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
197 .as_string(); | 258 .as_string(); |
198 } | 259 } |
199 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 260 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
200 html_bytes->data().assign(html.begin(), html.end()); | 261 html_bytes->data().assign(html.begin(), html.end()); |
201 callback.Run(html_bytes.get()); | 262 callback.Run(html_bytes.get()); |
202 } | 263 } |
OLD | NEW |