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

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

Issue 1509073002: Fixes for Safe Browsing with unrelated pending navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review changes for comment #10 Created 5 years 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 //
5 // Implementation of chrome://interstitials demonstration pages. This code is
6 // not used in displaying any real interstitials.
Charlie Reis 2015/12/17 19:24:18 nit: Please put this comment above the class decla
mattm 2015/12/18 21:41:04 Done.
4 7
5 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h" 8 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h"
6 9
7 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
9 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 14 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
13 #include "chrome/browser/ssl/bad_clock_blocking_page.h" 16 #include "chrome/browser/ssl/bad_clock_blocking_page.h"
14 #include "chrome/browser/ssl/ssl_blocking_page.h" 17 #include "chrome/browser/ssl/ssl_blocking_page.h"
15 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
16 #include "chrome/grit/browser_resources.h" 19 #include "chrome/grit/browser_resources.h"
17 #include "components/grit/components_resources.h" 20 #include "components/grit/components_resources.h"
18 #include "components/security_interstitials/core/ssl_error_ui.h" 21 #include "components/security_interstitials/core/ssl_error_ui.h"
19 #include "content/public/browser/interstitial_page_delegate.h" 22 #include "content/public/browser/interstitial_page_delegate.h"
23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_ui.h" 26 #include "content/public/browser/web_ui.h"
22 #include "content/public/browser/web_ui_controller.h" 27 #include "content/public/browser/web_ui_controller.h"
23 #include "content/public/browser/web_ui_data_source.h" 28 #include "content/public/browser/web_ui_data_source.h"
24 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
25 #include "net/base/url_util.h" 30 #include "net/base/url_util.h"
26 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
27 #include "net/ssl/ssl_info.h" 32 #include "net/ssl/ssl_info.h"
28 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
29 34
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 safe_browsing::SBThreatType threat_type = 185 safe_browsing::SBThreatType threat_type =
181 safe_browsing::SB_THREAT_TYPE_URL_MALWARE; 186 safe_browsing::SB_THREAT_TYPE_URL_MALWARE;
182 GURL request_url("http://example.com"); 187 GURL request_url("http://example.com");
183 std::string url_param; 188 std::string url_param;
184 if (net::GetValueForKeyInQuery(web_contents->GetURL(), 189 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
185 "url", 190 "url",
186 &url_param)) { 191 &url_param)) {
187 if (GURL(url_param).is_valid()) 192 if (GURL(url_param).is_valid())
188 request_url = GURL(url_param); 193 request_url = GURL(url_param);
189 } 194 }
195 GURL main_frame_url(request_url);
196 // TODO(mattm): add flag to change main_frame_url or add dedicated flag to
197 // test subresource interstitials.
190 std::string type_param; 198 std::string type_param;
191 if (net::GetValueForKeyInQuery(web_contents->GetURL(), 199 if (net::GetValueForKeyInQuery(web_contents->GetURL(),
192 "type", 200 "type",
193 &type_param)) { 201 &type_param)) {
202 // TODO(mattm): add param for SB_THREAT_TYPE_URL_UNWANTED.
194 if (type_param == "malware") { 203 if (type_param == "malware") {
195 threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE; 204 threat_type = safe_browsing::SB_THREAT_TYPE_URL_MALWARE;
196 } else if (type_param == "phishing") { 205 } else if (type_param == "phishing") {
197 threat_type = safe_browsing::SB_THREAT_TYPE_URL_PHISHING; 206 threat_type = safe_browsing::SB_THREAT_TYPE_URL_PHISHING;
198 } else if (type_param == "clientside_malware") { 207 } else if (type_param == "clientside_malware") {
199 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; 208 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL;
200 } else if (type_param == "clientside_phishing") { 209 } else if (type_param == "clientside_phishing") {
201 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL; 210 threat_type = safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL;
202 // Interstitials for client side phishing urls load after the page loads
203 // (see SafeBrowsingBlockingPage::IsMainPageLoadBlocked), so there should
204 // either be a new navigation entry, or there shouldn't be any pending
205 // entries. Clear any pending navigation entries.
206 content::NavigationController* controller =
207 &web_contents->GetController();
208 controller->DiscardNonCommittedEntries();
209 } 211 }
210 } 212 }
211 safe_browsing::SafeBrowsingBlockingPage::UnsafeResource resource; 213 safe_browsing::SafeBrowsingBlockingPage::UnsafeResource resource;
212 resource.url = request_url; 214 resource.url = request_url;
213 resource.threat_type = threat_type; 215 resource.is_subresource = request_url != main_frame_url;
214 // Create a blocking page without showing the interstitial. 216 resource.is_subframe = false;
217 resource.threat_type = threat_type;
218 resource.render_process_host_id =
219 web_contents->GetRenderProcessHost()->GetID();
220 resource.render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
221 resource.threat_source = safe_browsing::ThreatSource::LOCAL_PVER3;
222
223 // Normally safebrowsing interstitial types which block the main page load
224 // (SB_THREAT_TYPE_URL_MALWARE, SB_THREAT_TYPE_URL_PHISHING, and
225 // SB_THREAT_TYPE_URL_UNWANTED on main-frame loads) would expect there to be a
226 // pending navigation when the SafeBrowsingBlockingPage is created. This demo
227 // creates a SafeBrowsingBlockingPage but does not actually show a real
228 // interstitial. Instead it extracts the html and displays it manually, so the
229 // parts which depend on the NavigationEntry are not hit.
215 return safe_browsing::SafeBrowsingBlockingPage::CreateBlockingPage( 230 return safe_browsing::SafeBrowsingBlockingPage::CreateBlockingPage(
216 g_browser_process->safe_browsing_service()->ui_manager().get(), 231 g_browser_process->safe_browsing_service()->ui_manager().get(),
217 web_contents, 232 web_contents, main_frame_url, resource);
218 resource);
219 } 233 }
220 234
221 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 235 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
222 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage( 236 CaptivePortalBlockingPage* CreateCaptivePortalBlockingPage(
223 content::WebContents* web_contents) { 237 content::WebContents* web_contents) {
224 bool is_wifi_connection = false; 238 bool is_wifi_connection = false;
225 GURL landing_url("https://captive.portal/login"); 239 GURL landing_url("https://captive.portal/login");
226 GURL request_url("https://google.com"); 240 GURL request_url("https://google.com");
227 // Not initialized to a default value, since non-empty wifi_ssid is 241 // Not initialized to a default value, since non-empty wifi_ssid is
228 // considered a wifi connection, even if is_wifi_connection is false. 242 // considered a wifi connection, even if is_wifi_connection is false.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 html = interstitial_delegate.get()->GetHTMLContents(); 338 html = interstitial_delegate.get()->GetHTMLContents();
325 } else { 339 } else {
326 html = ResourceBundle::GetSharedInstance() 340 html = ResourceBundle::GetSharedInstance()
327 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) 341 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML)
328 .as_string(); 342 .as_string();
329 } 343 }
330 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; 344 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString;
331 html_bytes->data().assign(html.begin(), html.end()); 345 html_bytes->data().assign(html.begin(), html.end());
332 callback.Run(html_bytes.get()); 346 callback.Run(html_bytes.get());
333 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698