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

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

Issue 368143002: Add a chrome://interstitials page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix client side phishing interstitial Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h"
6
7 #include "base/strings/string_util.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
12 #include "chrome/browser/ssl/ssl_blocking_page.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/public/browser/interstitial_page_delegate.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_controller.h"
18 #include "content/public/browser/web_ui_data_source.h"
19 #include "grit/browser_resources.h"
20 #include "net/base/net_errors.h"
21 #include "net/base/url_util.h"
22 #include "net/cert/x509_certificate.h"
23 #include "net/ssl/ssl_info.h"
24
25 namespace {
26
27 class InterstitialHTMLSource : public content::URLDataSource {
28 public:
29 InterstitialHTMLSource(Profile* profile,
30 content::WebContents* web_contents);
31 virtual ~InterstitialHTMLSource();
32
33 // content::URLDataSource:
34 virtual std::string GetMimeType(const std::string& mime_type) const OVERRIDE;
35 virtual std::string GetSource() const OVERRIDE;
36 virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE;
37 virtual void StartDataRequest(
38 const std::string& path,
39 int render_process_id,
40 int render_frame_id,
41 const content::URLDataSource::GotDataCallback& callback) OVERRIDE;
42
43 private:
44 Profile* profile_;
45 content::WebContents* web_contents_;
46 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource);
47 };
48
49 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) {
50 // Random parameters for SSL blocking page.
51 int cert_error = net::ERR_CERT_CONTAINS_ERRORS;
52 GURL request_url("https://example.com");
53 bool overridable = false;
54 bool strict_enforcement = false;
55 std::string url_param;
56 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
57 "url",
58 &url_param)) {
59 request_url = GURL(url_param);
60 }
61 std::string overridable_param;
62 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
63 "overridable",
64 &overridable_param)) {
65 overridable = overridable_param == "1";
66 }
67 std::string strict_enforcement_param;
68 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
69 "strict_enforcement",
70 &strict_enforcement_param)) {
71 strict_enforcement = strict_enforcement_param == "1";
72 }
73 net::SSLInfo ssl_info;
74 ssl_info.cert = new net::X509Certificate(
75 request_url.host(), "CA", base::Time::Max(), base::Time::Max());
76 // This delegate doesn't create an interstitial.
77 return SSLBlockingPage::CreateForWebUI(web_contents, cert_error, ssl_info,
78 request_url, overridable,
79 strict_enforcement);
80 }
81
82 SafeBrowsingBlockingPage* CreateSafeBrowsingBlockingPage(
83 content::WebContents* web_contents) {
84 SBThreatType threat_type = SB_THREAT_TYPE_URL_MALWARE;
85 GURL request_url("http://example.com");
86 std::string url_param;
87 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
88 "url",
89 &url_param)) {
90 request_url = GURL(url_param);
91 }
92 std::string type_param;
93 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
94 "type",
95 &type_param)) {
96 if (type_param == "malware") {
97 threat_type = SB_THREAT_TYPE_URL_MALWARE;
98 } else if (type_param == "phishing") {
99 threat_type = SB_THREAT_TYPE_URL_PHISHING;
100 } else if (type_param == "clientside_malware") {
101 threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL;
102 } else if (type_param == "clientside_phishing") {
103 threat_type = SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL;
104 // Interstitials for client side phishing urls load after the page loads
105 // (see SafeBrowsingBlockingPage::IsMainPageLoadBlocked), so there should
106 // either be a new navigation entry, or there shouldn't be any pending
107 // entries. Clear any pending navigation entries.
108 content::NavigationController* controller =
109 &web_contents->GetController();
110 controller->DiscardNonCommittedEntries();
meacer 2014/07/17 21:24:09 SafeBrowsingBlockingPage::IsMainPageLoadBlocked on
111 }
112 }
113 SafeBrowsingBlockingPage::UnsafeResource resource;
114 resource.url = request_url;
115 resource.threat_type = threat_type;
116 return SafeBrowsingBlockingPage::CreateBlockingPage(
117 g_browser_process->safe_browsing_service()->ui_manager(),
118 web_contents,
119 resource);
120 }
121
122 } // namespace
123
124 InterstitialUI::InterstitialUI(content::WebUI* web_ui)
125 : WebUIController(web_ui) {
126 Profile* profile = Profile::FromWebUI(web_ui);
127 scoped_ptr<InterstitialHTMLSource> html_source(
128 new InterstitialHTMLSource(profile->GetOriginalProfile(),
129 web_ui->GetWebContents()));
130 content::URLDataSource::Add(profile, html_source.release());
131 }
132
133 InterstitialUI::~InterstitialUI() {
134 }
135
136 // InterstitialHTMLSource
137
138 InterstitialHTMLSource::InterstitialHTMLSource(
139 Profile* profile,
140 content::WebContents* web_contents)
141 : profile_(profile),
142 web_contents_(web_contents) {
143 }
144
145 InterstitialHTMLSource::~InterstitialHTMLSource() {
146 }
147
148 std::string InterstitialHTMLSource::GetMimeType(
149 const std::string& mime_type) const {
150 return "text/html";
151 }
152
153 std::string InterstitialHTMLSource::GetSource() const {
154 return chrome::kChromeUIInterstitialHost;
155 }
156
157 bool InterstitialHTMLSource::ShouldAddContentSecurityPolicy()
158 const {
159 return false;
160 }
161
162 void InterstitialHTMLSource::StartDataRequest(
163 const std::string& path,
164 int render_process_id,
165 int render_frame_id,
166 const content::URLDataSource::GotDataCallback& callback) {
167 scoped_ptr<content::InterstitialPageDelegate> interstitial_delegate;
168 if (StartsWithASCII(path, "ssl", true)) {
169 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_));
170 } else if (StartsWithASCII(path, "safebrowsing", true)) {
171 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_));
172 }
173
174 std::string html;
175 if (interstitial_delegate.get()) {
176 html = interstitial_delegate.get()->GetHTMLContents();
177 } else {
178 html = "<html><head><title>Interstitials</title></head>"
179 "<body><h2>Choose an interstitial<h2>"
180 "<h3>SSL</h3>"
181 "<a href='ssl'>example.com</a><br>"
182 "<a href='ssl?url=https://google.com'>SSL (google.com)</a><br>"
183 "<a href='ssl?overridable=1&strict_enforcement=0'>"
184 " example.com (Overridable)</a>"
185 "<br><br>"
186 "<h3>SafeBrowsing</h3>"
187 "<a href='safebrowsing?type=malware'>Malware</a><br>"
188 "<a href='safebrowsing?type=phishing'>Phishing</a><br>"
189 "<a href='safebrowsing?type=clientside_malware'>"
190 " Client Side Malware</a><br>"
191 "<a href='safebrowsing?type=clientside_phishing'>"
192 " Client Side Phishing</a><br>"
193 "</body></html>";
194 }
195 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString;
196 html_bytes->data().assign(html.begin(), html.end());
197 callback.Run(html_bytes.get());
198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698