Chromium Code Reviews| 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/bad_clock_blocking_page.h" | 13 #include "chrome/browser/ssl/bad_clock_blocking_page.h" |
| 14 #include "chrome/browser/ssl/ssl_blocking_page.h" | 14 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/grit/browser_resources.h" | 16 #include "chrome/grit/browser_resources.h" |
| 17 #include "components/grit/components_resources.h" | 17 #include "components/grit/components_resources.h" |
| 18 #include "content/public/browser/interstitial_page_delegate.h" | 18 #include "content/public/browser/interstitial_page_delegate.h" |
| 19 #include "content/public/browser/render_process_host.h" | |
| 20 #include "content/public/browser/render_view_host.h" | |
| 19 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
| 21 #include "content/public/browser/web_ui_controller.h" | 23 #include "content/public/browser/web_ui_controller.h" |
| 22 #include "content/public/browser/web_ui_data_source.h" | 24 #include "content/public/browser/web_ui_data_source.h" |
| 23 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 24 #include "net/base/url_util.h" | 26 #include "net/base/url_util.h" |
| 25 #include "net/cert/x509_certificate.h" | 27 #include "net/cert/x509_certificate.h" |
| 26 #include "net/ssl/ssl_info.h" | 28 #include "net/ssl/ssl_info.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 28 | 30 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 safe_browsing::SBThreatType threat_type = | 181 safe_browsing::SBThreatType threat_type = |
| 180 safe_browsing::SB_THREAT_TYPE_URL_MALWARE; | 182 safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
| 181 GURL request_url("http://example.com"); | 183 GURL request_url("http://example.com"); |
| 182 std::string url_param; | 184 std::string url_param; |
| 183 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 185 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
| 184 "url", | 186 "url", |
| 185 &url_param)) { | 187 &url_param)) { |
| 186 if (GURL(url_param).is_valid()) | 188 if (GURL(url_param).is_valid()) |
| 187 request_url = GURL(url_param); | 189 request_url = GURL(url_param); |
| 188 } | 190 } |
| 191 GURL main_frame_url(request_url); | |
| 192 // TODO(mattm): add flag to change main_frame_url or add dedicated flag to | |
| 193 // test subresource interstitials. | |
| 189 std::string type_param; | 194 std::string type_param; |
| 190 if (net::GetValueForKeyInQuery(web_contents->GetURL(), | 195 if (net::GetValueForKeyInQuery(web_contents->GetURL(), |
| 191 "type", | 196 "type", |
| 192 &type_param)) { | 197 &type_param)) { |
| 198 // TODO(mattm): add param for SB_THREAT_TYPE_URL_UNWANTED. | |
| 193 if (type_param == "malware") { | 199 if (type_param == "malware") { |
| 194 threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; | 200 threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
| 195 } else if (type_param == "phishing") { | 201 } else if (type_param == "phishing") { |
| 196 threat_type = safe_browsing::SB_THREAT_TYPE_URL_PHISHING; | 202 threat_type = safe_browsing::SB_THREAT_TYPE_URL_PHISHING; |
| 197 } else if (type_param == "clientside_malware") { | 203 } else if (type_param == "clientside_malware") { |
| 198 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; | 204 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
| 199 } else if (type_param == "clientside_phishing") { | 205 } else if (type_param == "clientside_phishing") { |
| 200 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL; | 206 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL; |
| 201 // Interstitials for client side phishing urls load after the page loads | |
| 202 // (see SafeBrowsingBlockingPage::IsMainPageLoadBlocked), so there should | |
| 203 // either be a new navigation entry, or there shouldn't be any pending | |
| 204 // entries. Clear any pending navigation entries. | |
| 205 content::NavigationController* controller = | |
| 206 &web_contents->GetController(); | |
| 207 controller->DiscardNonCommittedEntries(); | |
| 208 } | 207 } |
| 209 } | 208 } |
| 210 safe_browsing::SafeBrowsingBlockingPage::UnsafeResource resource; | 209 safe_browsing::SafeBrowsingBlockingPage::UnsafeResource resource; |
| 211 resource.url = request_url; | 210 resource.url = request_url; |
| 212 resource.threat_type = threat_type; | 211 resource.is_subresource = request_url != main_frame_url; |
| 213 // Create a blocking page without showing the interstitial. | 212 resource.is_subframe = false; |
| 213 resource.threat_type = threat_type; | |
| 214 resource.render_process_host_id = | |
| 215 web_contents->GetRenderProcessHost()->GetID(); | |
| 216 resource.render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); | |
| 217 resource.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; | |
| 218 // Normally safebrowsing interstitial types which block the main page load | |
|
Charlie Reis
2015/12/11 05:39:25
nit: Blank line before.
mattm
2015/12/15 01:42:25
Done.
| |
| 219 // (SB_THREAT_TYPE_URL_MALWARE, SB_THREAT_TYPE_URL_PHISHING, and | |
| 220 // SB_THREAT_TYPE_URL_UNWANTED on main-frame loads) would expect there to be a | |
| 221 // pending navigation when the SafeBrowsingBlockingPage is created. This test | |
|
Charlie Reis
2015/12/11 05:39:25
"This test" -> I'm confused. This isn't test code
mattm
2015/12/15 01:42:25
I couldn't quite think of proper wording. This isn
Charlie Reis
2015/12/17 19:24:18
Ah, cool! I didn't realize that page existed.
| |
| 222 // creates a SafeBrowsingBlockingPage but does not actually show a real | |
| 223 // interstitial. Instead it extracts the html and displays it manually, so the | |
| 224 // parts which depend on the NavigationEntry are not hit. | |
| 214 return safe_browsing::SafeBrowsingBlockingPage::CreateBlockingPage( | 225 return safe_browsing::SafeBrowsingBlockingPage::CreateBlockingPage( |
| 215 g_browser_process->safe_browsing_service()->ui_manager().get(), | 226 g_browser_process->safe_browsing_service()->ui_manager().get(), |
| 216 web_contents, | 227 web_contents, resource, main_frame_url); |
| 217 resource); | |
| 218 } | 228 } |
| 219 | 229 |
| 220 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 230 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 221 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( | 231 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( |
| 222 content::WebContents* web_contents) { | 232 content::WebContents* web_contents) { |
| 223 bool is_wifi_connection = false; | 233 bool is_wifi_connection = false; |
| 224 GURL landing_url("https://captive.portal/login"); | 234 GURL landing_url("https://captive.portal/login"); |
| 225 GURL request_url("https://google.com"); | 235 GURL request_url("https://google.com"); |
| 226 // Not initialized to a default value, since non-empty wifi_ssid is | 236 // Not initialized to a default value, since non-empty wifi_ssid is |
| 227 // considered a wifi connection, even if is_wifi_connection is false. | 237 // considered a wifi connection, even if is_wifi_connection is false. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 html = interstitial_delegate.get()->GetHTMLContents(); | 333 html = interstitial_delegate.get()->GetHTMLContents(); |
| 324 } else { | 334 } else { |
| 325 html = ResourceBundle::GetSharedInstance() | 335 html = ResourceBundle::GetSharedInstance() |
| 326 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) | 336 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
| 327 .as_string(); | 337 .as_string(); |
| 328 } | 338 } |
| 329 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 339 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
| 330 html_bytes->data().assign(html.begin(), html.end()); | 340 html_bytes->data().assign(html.begin(), html.end()); |
| 331 callback.Run(html_bytes.get()); | 341 callback.Run(html_bytes.get()); |
| 332 } | 342 } |
| OLD | NEW |