Chromium Code Reviews| Index: chrome/browser/ui/webui/interstitials/interstitial_ui.cc |
| diff --git a/chrome/browser/ui/webui/interstitials/interstitial_ui.cc b/chrome/browser/ui/webui/interstitials/interstitial_ui.cc |
| index 7845d3f37e86da62b25113a95368115a20e59caa..2ca87661e664bb34743affc2a12bec17bb94bbe3 100644 |
| --- a/chrome/browser/ui/webui/interstitials/interstitial_ui.cc |
| +++ b/chrome/browser/ui/webui/interstitials/interstitial_ui.cc |
| @@ -12,6 +12,7 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| +#include "chrome/browser/safe_browsing/test_safe_browsing_blocking_page_quiet.h" |
| #include "chrome/browser/safe_browsing/ui_manager.h" |
| #include "chrome/browser/ssl/bad_clock_blocking_page.h" |
| #include "chrome/browser/ssl/ssl_blocking_page.h" |
| @@ -35,11 +36,14 @@ |
| #include "net/cert/x509_util.h" |
| #include "net/ssl/ssl_info.h" |
| #include "ui/base/resource/resource_bundle.h" |
| +#include "ui/base/webui/web_ui_util.h" |
| #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| #endif |
| +using security_interstitials::TestSafeBrowsingBlockingPageQuiet; |
| + |
| namespace { |
| // NSS requires that serial numbers be unique even for the same issuer; |
| @@ -264,6 +268,52 @@ safe_browsing::SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage( |
| web_contents, main_frame_url, resource); |
| } |
| +TestSafeBrowsingBlockingPageQuiet* CreateSafeBrowsingQuietBlockingPage( |
| + content::WebContents* web_contents) { |
| + safe_browsing::SBThreatType threat_type = |
| + safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
| + GURL request_url("http://example.com"); |
| + std::string url_param; |
| + if (net::GetValueForKeyInQuery(web_contents->GetURL(), "url", &url_param)) { |
| + if (GURL(url_param).is_valid()) |
| + request_url = GURL(url_param); |
| + } |
| + GURL main_frame_url(request_url); |
| + std::string type_param; |
| + bool is_giant_webview = false; |
| + if (net::GetValueForKeyInQuery(web_contents->GetURL(), "type", &type_param)) { |
| + if (type_param == "malware") { |
| + threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
| + } else if (type_param == "phishing") { |
| + threat_type = safe_browsing::SB_THREAT_TYPE_URL_PHISHING; |
| + } else if (type_param == "giant") { |
| + threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; |
|
felt
2017/05/20 00:00:06
Is the giant the same for malware & phishing?
edwardjung
2017/05/22 11:29:51
Yes. Only the icon is shown. Did you want to speci
|
| + is_giant_webview = true; |
| + } |
| + } |
| + safe_browsing::SafeBrowsingBlockingPage::UnsafeResource resource; |
| + resource.url = request_url; |
| + resource.is_subresource = request_url != main_frame_url; |
| + resource.is_subframe = false; |
| + resource.threat_type = threat_type; |
| + resource.web_contents_getter = |
| + security_interstitials::UnsafeResource::GetWebContentsGetter( |
| + web_contents->GetRenderProcessHost()->GetID(), |
| + web_contents->GetMainFrame()->GetRoutingID()); |
| + resource.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3; |
| + |
| + // Normally safebrowsing interstitial types which block the main page load |
| + // (SB_THREAT_TYPE_URL_MALWARE, SB_THREAT_TYPE_URL_PHISHING, and |
| + // SB_THREAT_TYPE_URL_UNWANTED on main-frame loads) would expect there to be a |
| + // pending navigation when the SafeBrowsingBlockingPage is created. This demo |
| + // creates a SafeBrowsingBlockingPage but does not actually show a real |
| + // interstitial. Instead it extracts the html and displays it manually, so the |
| + // parts which depend on the NavigationEntry are not hit. |
| + return TestSafeBrowsingBlockingPageQuiet::CreateBlockingPage( |
| + g_browser_process->safe_browsing_service()->ui_manager().get(), |
| + web_contents, main_frame_url, resource, is_giant_webview); |
| +} |
| + |
| #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( |
| content::WebContents* web_contents) { |
| @@ -353,11 +403,18 @@ void InterstitialHTMLSource::StartDataRequest( |
| return; |
| } |
| std::unique_ptr<content::InterstitialPageDelegate> interstitial_delegate; |
| + std::string html; |
| if (base::StartsWith(path, "ssl", base::CompareCase::SENSITIVE)) { |
| interstitial_delegate.reset(CreateSSLBlockingPage(web_contents)); |
| } else if (base::StartsWith(path, "safebrowsing", |
| base::CompareCase::SENSITIVE)) { |
| interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents)); |
| + } else if (base::StartsWith(path, "quietsafebrowsing", |
| + base::CompareCase::SENSITIVE)) { |
| + TestSafeBrowsingBlockingPageQuiet* blocking_page = |
| + CreateSafeBrowsingQuietBlockingPage(web_contents); |
| + interstitial_delegate.reset(blocking_page); |
| + html = blocking_page->GetHTML(); |
| } else if (base::StartsWith(path, "clock", base::CompareCase::SENSITIVE)) { |
| interstitial_delegate.reset(CreateBadClockBlockingPage(web_contents)); |
| } |
| @@ -368,15 +425,18 @@ void InterstitialHTMLSource::StartDataRequest( |
| interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents)); |
| } |
| #endif |
| - std::string html; |
| - if (base::StartsWith(path, "supervised_user", base::CompareCase::SENSITIVE)) { |
| - html = GetSupervisedUserInterstitialHTML(path); |
| - } else if (interstitial_delegate.get()) { |
| - html = interstitial_delegate.get()->GetHTMLContents(); |
| - } else { |
| - html = ResourceBundle::GetSharedInstance() |
| - .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
| - .as_string(); |
| + if (html.length() == 0 && !base::StartsWith(path, "quietsafebrowsing", |
|
felt
2017/05/20 00:00:06
why do you need to add that check?
edwardjung
2017/05/22 11:29:51
For quiet Safe browsing the HTML is assigned above
|
| + base::CompareCase::SENSITIVE)) { |
| + if (base::StartsWith(path, "supervised_user", |
| + base::CompareCase::SENSITIVE)) { |
| + html = GetSupervisedUserInterstitialHTML(path); |
| + } else if (interstitial_delegate.get()) { |
| + html = interstitial_delegate.get()->GetHTMLContents(); |
| + } else { |
| + html = ResourceBundle::GetSharedInstance() |
| + .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
| + .as_string(); |
| + } |
| } |
| scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
| html_bytes->data().assign(html.begin(), html.end()); |