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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8de17eefb45b22aa0d9b5c5c391d7d8ec9209cc0 |
--- /dev/null |
+++ b/chrome/browser/ui/webui/interstitials/interstitial_ui.cc |
@@ -0,0 +1,162 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/webui/interstitials/interstitial_ui.h" |
+ |
+#include "base/strings/string_util.h" |
+#include "chrome/browser/browser_process.h" |
+#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/ssl/ssl_blocking_page.h" |
+#include "chrome/common/url_constants.h" |
+#include "content/public/browser/interstitial_page_delegate.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/browser/web_ui.h" |
+#include "content/public/browser/web_ui_controller.h" |
+#include "content/public/browser/web_ui_data_source.h" |
+#include "grit/browser_resources.h" |
+#include "net/base/net_errors.h" |
+#include "net/base/url_util.h" |
+#include "net/cert/x509_certificate.h" |
+#include "net/ssl/ssl_info.h" |
+ |
+namespace { |
+ |
+SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { |
+ // Random parameters for SSL blocking page. |
+ int cert_error = net::ERR_CERT_COMMON_NAME_INVALID; |
+ GURL request_url("http://example.com"); |
+ bool overridable = false; |
+ bool strict_enforcement = false; |
+ base::Callback<void(bool)> callback; |
+ for (net::QueryIterator it(web_contents->GetURL()); |
+ !it.IsAtEnd(); |
+ it.Advance()) { |
+ if (it.GetKey() == "overridable") { |
+ overridable = it.GetValue() == "1"; |
+ } else if (it.GetKey() == "strict_enforcement") { |
+ strict_enforcement = it.GetValue() == "1"; |
+ } else if (it.GetKey() == "url") { |
+ request_url = GURL(it.GetValue()); |
+ } |
+ } |
+ scoped_refptr<net::X509Certificate> cert1( |
+ new net::X509Certificate(request_url.host(), "CA", |
+ base::Time::Max(), base::Time::Max())); |
+ net::SSLInfo ssl_info; |
+ ssl_info.cert = cert1; |
+ // This delegate doesn't create an interstitial. |
+ return new SSLBlockingPage(web_contents, false, cert_error, ssl_info, |
+ request_url, overridable, strict_enforcement, |
+ callback); |
+} |
+ |
+SafeBrowsingBlockingPage* CreateSafebrowsingBlockingPage( |
felt
2014/07/15 01:35:07
nit: usually spelled as SafeBrowsing (capital 'B')
meacer
2014/07/15 19:48:06
Done.
|
+ content::WebContents* web_contents) { |
+ SBThreatType threat_type = SB_THREAT_TYPE_URL_MALWARE; |
+ GURL request_url("http://example.com"); |
+ for (net::QueryIterator it(web_contents->GetURL()); |
+ !it.IsAtEnd(); |
+ it.Advance()) { |
+ if (it.GetKey() == "type") { |
+ if (it.GetValue() == "malware") { |
+ threat_type = SB_THREAT_TYPE_URL_MALWARE; |
+ } else if (it.GetValue() == "phishing") { |
+ threat_type = SB_THREAT_TYPE_URL_PHISHING; |
+ } else if (it.GetValue() == "clientside_malware") { |
+ threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
+ } else if (it.GetValue() == "clientside_phishing") { |
+ threat_type = SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL; |
+ } |
+ } else if (it.GetKey() == "url") { |
+ request_url = GURL(it.GetValue()); |
+ } |
+ } |
+ SafeBrowsingBlockingPage::UnsafeResource resource; |
+ resource.url = request_url; |
+ resource.threat_type = threat_type; |
+ return SafeBrowsingBlockingPage::CreateBlockingPage( |
+ g_browser_process->safe_browsing_service()->ui_manager(), |
+ web_contents, |
+ resource); |
+} |
+ |
+} // namespace |
+ |
+InterstitialUI::InterstitialUI(content::WebUI* web_ui) |
+ : WebUIController(web_ui) { |
+ Profile* profile = Profile::FromWebUI(web_ui); |
+ scoped_ptr<InterstitialHTMLSource> html_source( |
+ new InterstitialHTMLSource(profile->GetOriginalProfile(), |
+ web_ui->GetWebContents())); |
+ content::URLDataSource::Add(profile, html_source.release()); |
+} |
+ |
+InterstitialUI::~InterstitialUI() { |
+} |
+ |
+// InterstitialUI::InterstitialHTMLSource |
+ |
+InterstitialUI::InterstitialHTMLSource::InterstitialHTMLSource( |
+ Profile* profile, |
+ content::WebContents* web_contents) |
+ : profile_(profile), |
+ web_contents_(web_contents) { |
+} |
+ |
+InterstitialUI::InterstitialHTMLSource::~InterstitialHTMLSource() { |
+} |
+ |
+std::string InterstitialUI::InterstitialHTMLSource::GetMimeType( |
+ const std::string& mime_type) const { |
+ return "text/html"; |
+} |
+ |
+std::string InterstitialUI::InterstitialHTMLSource::GetSource() const { |
+ return chrome::kChromeUIInterstitialHost; |
+} |
+ |
+bool InterstitialUI::InterstitialHTMLSource::ShouldAddContentSecurityPolicy() |
+ const { |
+ return false; |
+} |
+ |
+void InterstitialUI::InterstitialHTMLSource::StartDataRequest( |
+ const std::string& path, |
+ int render_process_id, |
+ int render_frame_id, |
+ const content::URLDataSource::GotDataCallback& callback) { |
+ scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate; |
+ if (StartsWithASCII(path, "ssl", true)) { |
+ interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); |
+ } else if (StartsWithASCII(path, "safebrowsing", true)) { |
+ interstitial_delegate.reset(CreateSafebrowsingBlockingPage(web_contents_)); |
+ } |
+ |
+ std::string html; |
+ if (interstitial_delegate.get()) { |
+ html = interstitial_delegate.get()->GetHTMLContents(); |
+ } else { |
+ html = "<html><head><title>Interstitials</title></head>" |
+ "<body><h2>Choose an interstitial<h2>" |
+ "<h3>SSL</h3>" |
+ "<a href='ssl'>example.com</a><br>" |
+ "<a href='ssl?url=https://google.com'>SSL (google.com)</a><br>" |
felt
2014/07/15 01:35:07
ahh the passing parameters is pretty slick
meacer
2014/07/15 19:48:06
Looking forward to bug reports where people use we
|
+ "<a href='ssl?overridable=1&strict_enforcement=0'>" |
+ " example.com (Overridable)</a>" |
+ "<br><br>" |
+ "<h3>SafeBrowsing</h3>" |
+ "<a href='safebrowsing?type=malware'>Malware</a><br>" |
+ "<a href='safebrowsing?type=clientside_malware'>" |
+ " Client Side Malware</a><br>" |
+ "<a href='safebrowsing?type=phishing'>Phishing</a><br>" |
+ "<a href='safebrowsing?type=clientside_phishing'>" |
+ " Client Side Phishing</a><br>" |
+ "</body></html>"; |
+ } |
+ scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
+ html_bytes->data().assign(html.begin(), html.end()); |
+ callback.Run(html_bytes.get()); |
+} |