Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/ui/webui/interstitials/interstitial_ui.cc

Issue 1189413003: Added CaptivePortal Interstitial to chrome://interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some style changes Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 bool is_wifi_connection_;
62 const std::string wifi_ssid_;
63
64 DISALLOW_COPY_AND_ASSIGN(FakeConnectionInfoDelegate);
65 };
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
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 = false;
163 GURL landing_url("https://captive.portal/login");
164 GURL request_url("https://google.com");
165 // Not initialized to a default value, since non-empty wifi_ssid is
166 // considered a wifi connection, even if is_wifi_connection is false
meacer 2015/06/19 22:50:37 nit: Period at the end of the comment.
Bhanu Dev 2015/06/19 23:21:33 Done.
167 std::string wifi_ssid;
168
169 std::string request_url_param;
170 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "url",
171 &request_url_param)) {
172 if (GURL(request_url_param).is_valid())
173 request_url = GURL(request_url_param);
174 }
175 std::string landing_url_param;
176 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "landing_page",
177 &landing_url_param)) {
178 if (GURL(landing_url_param).is_valid())
179 landing_url = GURL(landing_url_param);
180 }
181 std::string wifi_connection_param;
182 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "is_wifi",
183 &wifi_connection_param)) {
184 is_wifi_connection = wifi_connection_param == "1";
185 }
186 std::string wifi_ssid_param;
187 if (net::GetValueForKeyInQuery(web_contents->GetURL(), "wifi_name",
188 &wifi_ssid_param)) {
189 wifi_ssid = wifi_ssid_param;
190 }
191 FakeConnectionInfoDelegate* delegate =
192 new FakeConnectionInfoDelegate(is_wifi_connection, wifi_ssid);
193 net::SSLInfo ssl_info;
194 ssl_info.cert = new net::X509Certificate(
195 request_url.host(), "CA", base::Time::Max(), base::Time::Max());
196 CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
197 web_contents, request_url, landing_url, nullptr, ssl_info,
198 base::Callback<void(bool)>());
199 blocking_page->SetDelegate(delegate);
200 return blocking_page;
201 }
202
142 } // namespace 203 } // namespace
143 204
144 InterstitialUI::InterstitialUI(content::WebUI* web_ui) 205 InterstitialUI::InterstitialUI(content::WebUI* web_ui)
145 : WebUIController(web_ui) { 206 : WebUIController(web_ui) {
146 scoped_ptr<InterstitialHTMLSource> html_source( 207 scoped_ptr<InterstitialHTMLSource> html_source(
147 new InterstitialHTMLSource(web_ui->GetWebContents())); 208 new InterstitialHTMLSource(web_ui->GetWebContents()));
148 Profile* profile = Profile::FromWebUI(web_ui); 209 Profile* profile = Profile::FromWebUI(web_ui);
149 content::URLDataSource::Add(profile, html_source.release()); 210 content::URLDataSource::Add(profile, html_source.release());
150 } 211 }
151 212
(...skipping 27 matching lines...) Expand all
179 void InterstitialHTMLSource::StartDataRequest( 240 void InterstitialHTMLSource::StartDataRequest(
180 const std::string& path, 241 const std::string& path,
181 int render_process_id, 242 int render_process_id,
182 int render_frame_id, 243 int render_frame_id,
183 const content::URLDataSource::GotDataCallback& callback) { 244 const content::URLDataSource::GotDataCallback& callback) {
184 scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate; 245 scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate;
185 if (StartsWithASCII(path, "ssl", true)) { 246 if (StartsWithASCII(path, "ssl", true)) {
186 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); 247 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_));
187 } else if (StartsWithASCII(path, "safebrowsing", true)) { 248 } else if (StartsWithASCII(path, "safebrowsing", true)) {
188 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); 249 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_));
250 } else if (StartsWithASCII(path, "captiveportal", true)) {
251 interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents_));
189 } 252 }
190 253
191 std::string html; 254 std::string html;
192 if (interstitial_delegate.get()) { 255 if (interstitial_delegate.get()) {
193 html = interstitial_delegate.get()->GetHTMLContents(); 256 html = interstitial_delegate.get()->GetHTMLContents();
194 } else { 257 } else {
195 html = ResourceBundle::GetSharedInstance() 258 html = ResourceBundle::GetSharedInstance()
196 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) 259 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML)
197 .as_string(); 260 .as_string();
198 } 261 }
199 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; 262 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString;
200 html_bytes->data().assign(html.begin(), html.end()); 263 html_bytes->data().assign(html.begin(), html.end());
201 callback.Run(html_bytes.get()); 264 callback.Run(html_bytes.get());
202 } 265 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698