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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.cc

Issue 622683006: Refactor security interstitials, add SecurityInterstitialPage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: thestig comments Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implementation of the SafeBrowsingBlockingPage class. 5 // Implementation of the SafeBrowsingBlockingPage class.
6 6
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 25 matching lines...) Expand all
36 #include "components/google/core/browser/google_util.h" 36 #include "components/google/core/browser/google_util.h"
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/interstitial_page.h" 38 #include "content/public/browser/interstitial_page.h"
39 #include "content/public/browser/navigation_controller.h" 39 #include "content/public/browser/navigation_controller.h"
40 #include "content/public/browser/user_metrics.h" 40 #include "content/public/browser/user_metrics.h"
41 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
42 #include "content/public/common/renderer_preferences.h" 42 #include "content/public/common/renderer_preferences.h"
43 #include "grit/browser_resources.h" 43 #include "grit/browser_resources.h"
44 #include "net/base/escape.h" 44 #include "net/base/escape.h"
45 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
46 #include "ui/base/resource/resource_bundle.h"
47 #include "ui/base/webui/jstemplate_builder.h"
48 #include "ui/base/webui/web_ui_util.h"
49 46
50 #if defined(ENABLE_EXTENSIONS) 47 #if defined(ENABLE_EXTENSIONS)
51 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 48 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
52 #endif 49 #endif
53 50
54 using base::UserMetricsAction; 51 using base::UserMetricsAction;
55 using content::BrowserThread; 52 using content::BrowserThread;
56 using content::InterstitialPage; 53 using content::InterstitialPage;
57 using content::OpenURLParams; 54 using content::OpenURLParams;
58 using content::Referrer; 55 using content::Referrer;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 SafeBrowsingBlockingPageFactoryImpl>; 136 SafeBrowsingBlockingPageFactoryImpl>;
140 137
141 SafeBrowsingBlockingPageFactoryImpl() { } 138 SafeBrowsingBlockingPageFactoryImpl() { }
142 139
143 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl); 140 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl);
144 }; 141 };
145 142
146 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl> 143 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl>
147 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER; 144 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER;
148 145
146 // static
147 const void* SafeBrowsingBlockingPage::kTypeForTesting =
148 &SafeBrowsingBlockingPage::kTypeForTesting;
149
149 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( 150 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
150 SafeBrowsingUIManager* ui_manager, 151 SafeBrowsingUIManager* ui_manager,
151 WebContents* web_contents, 152 WebContents* web_contents,
152 const UnsafeResourceList& unsafe_resources) 153 const UnsafeResourceList& unsafe_resources)
153 : malware_details_proceed_delay_ms_( 154 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url),
155 malware_details_proceed_delay_ms_(
154 kMalwareDetailsProceedDelayMilliSeconds), 156 kMalwareDetailsProceedDelayMilliSeconds),
155 ui_manager_(ui_manager), 157 ui_manager_(ui_manager),
156 report_loop_(NULL), 158 report_loop_(NULL),
157 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), 159 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)),
158 unsafe_resources_(unsafe_resources), 160 unsafe_resources_(unsafe_resources),
159 proceeded_(false), 161 proceeded_(false),
160 web_contents_(web_contents),
161 url_(unsafe_resources[0].url),
162 interstitial_page_(NULL),
163 create_view_(true),
164 num_visits_(-1) { 162 num_visits_(-1) {
165 bool malware = false; 163 bool malware = false;
166 bool harmful = false; 164 bool harmful = false;
167 bool phishing = false; 165 bool phishing = false;
168 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); 166 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin();
169 iter != unsafe_resources_.end(); ++iter) { 167 iter != unsafe_resources_.end(); ++iter) {
170 const UnsafeResource& resource = *iter; 168 const UnsafeResource& resource = *iter;
171 SBThreatType threat_type = resource.threat_type; 169 SBThreatType threat_type = resource.threat_type;
172 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || 170 if (threat_type == SB_THREAT_TYPE_URL_MALWARE ||
173 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { 171 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) {
(...skipping 17 matching lines...) Expand all
191 RecordUserDecision(SHOW); 189 RecordUserDecision(SHOW);
192 RecordUserInteraction(TOTAL_VISITS); 190 RecordUserInteraction(TOTAL_VISITS);
193 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) 191 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled))
194 RecordUserDecision(PROCEEDING_DISABLED); 192 RecordUserDecision(PROCEEDING_DISABLED);
195 193
196 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 194 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
197 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 195 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
198 Profile::EXPLICIT_ACCESS); 196 Profile::EXPLICIT_ACCESS);
199 if (history_service) { 197 if (history_service) {
200 history_service->GetVisibleVisitCountToHost( 198 history_service->GetVisibleVisitCountToHost(
201 url_, 199 request_url(),
202 base::Bind(&SafeBrowsingBlockingPage::OnGotHistoryCount, 200 base::Bind(&SafeBrowsingBlockingPage::OnGotHistoryCount,
203 base::Unretained(this)), 201 base::Unretained(this)),
204 &request_tracker_); 202 &request_tracker_);
205 } 203 }
206 204
207 if (!is_main_frame_load_blocked_) { 205 if (!is_main_frame_load_blocked_) {
208 navigation_entry_index_to_remove_ = 206 navigation_entry_index_to_remove_ =
209 web_contents->GetController().GetLastCommittedEntryIndex(); 207 web_contents->GetController().GetLastCommittedEntryIndex();
210 } else { 208 } else {
211 navigation_entry_index_to_remove_ = -1; 209 navigation_entry_index_to_remove_ = -1;
(...skipping 24 matching lines...) Expand all
236 break; 234 break;
237 case TYPE_PHISHING: 235 case TYPE_PHISHING:
238 event_name = kEventNamePhishing; 236 event_name = kEventNamePhishing;
239 break; 237 break;
240 default: 238 default:
241 event_name = kEventNameOther; 239 event_name = kEventNameOther;
242 break; 240 break;
243 } 241 }
244 sampling_event_.reset(new ExperienceSamplingEvent( 242 sampling_event_.reset(new ExperienceSamplingEvent(
245 event_name, 243 event_name,
246 url_, 244 request_url(),
247 web_contents_->GetLastCommittedURL(), 245 web_contents->GetLastCommittedURL(),
248 web_contents_->GetBrowserContext())); 246 web_contents->GetBrowserContext()));
249 #endif 247 #endif
250
251 // Creating interstitial_page_ without showing it leaks memory, so don't
252 // create it here.
253 } 248 }
254 249
255 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { 250 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() {
256 return (!web_contents_->GetBrowserContext()->IsOffTheRecord() && 251 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() &&
257 web_contents_->GetURL().SchemeIs(url::kHttpScheme)); 252 web_contents()->GetURL().SchemeIs(url::kHttpScheme));
258 } 253 }
259 254
260 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { 255 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
261 } 256 }
262 257
263 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { 258 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
264 std::string command(cmd); // Make a local copy so we can modify it. 259 std::string command(cmd); // Make a local copy so we can modify it.
265 // The Jasonified response has quotes, remove them. 260 // The Jasonified response has quotes, remove them.
266 if (command.length() > 1 && command[0] == '"') { 261 if (command.length() > 1 && command[0] == '"') {
267 command = command.substr(1, command.length() - 2); 262 command = command.substr(1, command.length() - 2);
(...skipping 13 matching lines...) Expand all
281 RecordUserInteraction(SHOW_LEARN_MORE); 276 RecordUserInteraction(SHOW_LEARN_MORE);
282 GURL learn_more_url(interstitial_type_ == TYPE_PHISHING ? 277 GURL learn_more_url(interstitial_type_ == TYPE_PHISHING ?
283 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2); 278 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2);
284 learn_more_url = google_util::AppendGoogleLocaleParam( 279 learn_more_url = google_util::AppendGoogleLocaleParam(
285 learn_more_url, g_browser_process->GetApplicationLocale()); 280 learn_more_url, g_browser_process->GetApplicationLocale());
286 OpenURLParams params(learn_more_url, 281 OpenURLParams params(learn_more_url,
287 Referrer(), 282 Referrer(),
288 CURRENT_TAB, 283 CURRENT_TAB,
289 ui::PAGE_TRANSITION_LINK, 284 ui::PAGE_TRANSITION_LINK,
290 false); 285 false);
291 web_contents_->OpenURL(params); 286 web_contents()->OpenURL(params);
292 return; 287 return;
293 } 288 }
294 289
295 if (command == kShowPrivacyCommand) { 290 if (command == kShowPrivacyCommand) {
296 // User pressed "Safe Browsing privacy policy". 291 // User pressed "Safe Browsing privacy policy".
297 RecordUserInteraction(SHOW_PRIVACY_POLICY); 292 RecordUserInteraction(SHOW_PRIVACY_POLICY);
298 GURL privacy_url( 293 GURL privacy_url(
299 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL)); 294 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_URL));
300 privacy_url = google_util::AppendGoogleLocaleParam( 295 privacy_url = google_util::AppendGoogleLocaleParam(
301 privacy_url, g_browser_process->GetApplicationLocale()); 296 privacy_url, g_browser_process->GetApplicationLocale());
302 OpenURLParams params(privacy_url, 297 OpenURLParams params(privacy_url,
303 Referrer(), 298 Referrer(),
304 CURRENT_TAB, 299 CURRENT_TAB,
305 ui::PAGE_TRANSITION_LINK, 300 ui::PAGE_TRANSITION_LINK,
306 false); 301 false);
307 web_contents_->OpenURL(params); 302 web_contents()->OpenURL(params);
308 return; 303 return;
309 } 304 }
310 305
311 bool proceed_blocked = false; 306 bool proceed_blocked = false;
312 if (command == kProceedCommand) { 307 if (command == kProceedCommand) {
313 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) { 308 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
314 proceed_blocked = true; 309 proceed_blocked = true;
315 } else { 310 } else {
316 RecordUserDecision(PROCEED); 311 RecordUserDecision(PROCEED);
317 interstitial_page_->Proceed(); 312 interstitial_page()->Proceed();
318 // |this| has been deleted after Proceed() returns. 313 // |this| has been deleted after Proceed() returns.
319 return; 314 return;
320 } 315 }
321 } 316 }
322 317
323 if (command == kTakeMeBackCommand || proceed_blocked) { 318 if (command == kTakeMeBackCommand || proceed_blocked) {
324 // Don't record the user action here because there are other ways of 319 // Don't record the user action here because there are other ways of
325 // triggering DontProceed, like clicking the back button. 320 // triggering DontProceed, like clicking the back button.
326 if (is_main_frame_load_blocked_) { 321 if (is_main_frame_load_blocked_) {
327 // If the load is blocked, we want to close the interstitial and discard 322 // If the load is blocked, we want to close the interstitial and discard
328 // the pending entry. 323 // the pending entry.
329 interstitial_page_->DontProceed(); 324 interstitial_page()->DontProceed();
330 // |this| has been deleted after DontProceed() returns. 325 // |this| has been deleted after DontProceed() returns.
331 return; 326 return;
332 } 327 }
333 328
334 // Otherwise the offending entry has committed, and we need to go back or 329 // Otherwise the offending entry has committed, and we need to go back or
335 // to a safe page. We will close the interstitial when that page commits. 330 // to a safe page. We will close the interstitial when that page commits.
336 if (web_contents_->GetController().CanGoBack()) { 331 if (web_contents()->GetController().CanGoBack()) {
337 web_contents_->GetController().GoBack(); 332 web_contents()->GetController().GoBack();
338 } else { 333 } else {
339 web_contents_->GetController().LoadURL( 334 web_contents()->GetController().LoadURL(
340 GURL(chrome::kChromeUINewTabURL), 335 GURL(chrome::kChromeUINewTabURL),
341 content::Referrer(), 336 content::Referrer(),
342 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 337 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
343 std::string()); 338 std::string());
344 } 339 }
345 return; 340 return;
346 } 341 }
347 342
348 // The "report error" and "show diagnostic" commands can have a number 343 // The "report error" and "show diagnostic" commands can have a number
349 // appended to them, which is the index of the element they apply to. 344 // appended to them, which is the index of the element they apply to.
(...skipping 28 matching lines...) Expand all
378 diagnostic_url, g_browser_process->GetApplicationLocale()); 373 diagnostic_url, g_browser_process->GetApplicationLocale());
379 DCHECK(unsafe_resources_[element_index].threat_type == 374 DCHECK(unsafe_resources_[element_index].threat_type ==
380 SB_THREAT_TYPE_URL_MALWARE || 375 SB_THREAT_TYPE_URL_MALWARE ||
381 unsafe_resources_[element_index].threat_type == 376 unsafe_resources_[element_index].threat_type ==
382 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || 377 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL ||
383 unsafe_resources_[element_index].threat_type == 378 unsafe_resources_[element_index].threat_type ==
384 SB_THREAT_TYPE_URL_UNWANTED); 379 SB_THREAT_TYPE_URL_UNWANTED);
385 OpenURLParams params( 380 OpenURLParams params(
386 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, 381 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK,
387 false); 382 false);
388 web_contents_->OpenURL(params); 383 web_contents()->OpenURL(params);
389 return; 384 return;
390 } 385 }
391 386
392 if (command == kExpandedSeeMoreCommand) { 387 if (command == kExpandedSeeMoreCommand) {
393 RecordUserInteraction(SHOW_ADVANCED); 388 RecordUserInteraction(SHOW_ADVANCED);
394 return; 389 return;
395 } 390 }
396 391
397 NOTREACHED() << "Unexpected command: " << command; 392 NOTREACHED() << "Unexpected command: " << command;
398 } 393 }
399 394
400 void SafeBrowsingBlockingPage::OverrideRendererPrefs( 395 void SafeBrowsingBlockingPage::OverrideRendererPrefs(
401 content::RendererPreferences* prefs) { 396 content::RendererPreferences* prefs) {
402 Profile* profile = Profile::FromBrowserContext( 397 Profile* profile = Profile::FromBrowserContext(
403 web_contents_->GetBrowserContext()); 398 web_contents()->GetBrowserContext());
404 renderer_preferences_util::UpdateFromSystemSettings( 399 renderer_preferences_util::UpdateFromSystemSettings(
405 prefs, profile, web_contents_); 400 prefs, profile, web_contents());
406 } 401 }
407 402
408 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { 403 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) {
409 Profile* profile = Profile::FromBrowserContext( 404 Profile* profile = Profile::FromBrowserContext(
410 web_contents_->GetBrowserContext()); 405 web_contents()->GetBrowserContext());
411 PrefService* pref = profile->GetPrefs(); 406 PrefService* pref = profile->GetPrefs();
412 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report); 407 pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report);
413 UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report); 408 UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report);
414 } 409 }
415 410
416 void SafeBrowsingBlockingPage::OnProceed() { 411 void SafeBrowsingBlockingPage::OnProceed() {
417 proceeded_ = true; 412 proceeded_ = true;
418 // Send the malware details, if we opted to. 413 // Send the malware details, if we opted to.
419 FinishMalwareDetails(malware_details_proceed_delay_ms_); 414 FinishMalwareDetails(malware_details_proceed_delay_ms_);
420 415
421 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true); 416 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true);
422 417
423 // Check to see if some new notifications of unsafe resources have been 418 // Check to see if some new notifications of unsafe resources have been
424 // received while we were showing the interstitial. 419 // received while we were showing the interstitial.
425 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); 420 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
426 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); 421 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
427 SafeBrowsingBlockingPage* blocking_page = NULL; 422 SafeBrowsingBlockingPage* blocking_page = NULL;
428 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { 423 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
429 // Build an interstitial for all the unsafe resources notifications. 424 // Build an interstitial for all the unsafe resources notifications.
430 // Don't show it now as showing an interstitial while an interstitial is 425 // Don't show it now as showing an interstitial while an interstitial is
431 // already showing would cause DontProceed() to be invoked. 426 // already showing would cause DontProceed() to be invoked.
432 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, web_contents_, 427 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_,
428 web_contents(),
433 iter->second); 429 iter->second);
434 unsafe_resource_map->erase(iter); 430 unsafe_resource_map->erase(iter);
435 } 431 }
436 432
437 // Now that this interstitial is gone, we can show the new one. 433 // Now that this interstitial is gone, we can show the new one.
438 if (blocking_page) 434 if (blocking_page)
439 blocking_page->Show(); 435 blocking_page->Show();
440 } 436 }
441 437
442 void SafeBrowsingBlockingPage::DontCreateViewForTesting() { 438 const void* SafeBrowsingBlockingPage::GetTypeForTesting() const {
443 create_view_ = false; 439 return SafeBrowsingBlockingPage::kTypeForTesting;
444 } 440 }
445 441
446 void SafeBrowsingBlockingPage::Show() { 442 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const {
447 DCHECK(!interstitial_page_); 443 return is_main_frame_load_blocked_;
448 interstitial_page_ = InterstitialPage::Create(
449 web_contents_, is_main_frame_load_blocked_, url_, this);
450 if (!create_view_)
451 interstitial_page_->DontCreateViewForTesting();
452 interstitial_page_->Show();
453 } 444 }
454 445
455 void SafeBrowsingBlockingPage::OnDontProceed() { 446 void SafeBrowsingBlockingPage::OnDontProceed() {
456 // We could have already called Proceed(), in which case we must not notify 447 // We could have already called Proceed(), in which case we must not notify
457 // the SafeBrowsingUIManager again, as the client has been deleted. 448 // the SafeBrowsingUIManager again, as the client has been deleted.
458 if (proceeded_) 449 if (proceeded_)
459 return; 450 return;
460 451
461 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) 452 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled))
462 RecordUserDecision(DONT_PROCEED); 453 RecordUserDecision(DONT_PROCEED);
463 454
464 // Send the malware details, if we opted to. 455 // Send the malware details, if we opted to.
465 FinishMalwareDetails(0); // No delay 456 FinishMalwareDetails(0); // No delay
466 457
467 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false); 458 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false);
468 459
469 // The user does not want to proceed, clear the queued unsafe resources 460 // The user does not want to proceed, clear the queued unsafe resources
470 // notifications we received while the interstitial was showing. 461 // notifications we received while the interstitial was showing.
471 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); 462 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
472 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); 463 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
473 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { 464 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
474 NotifySafeBrowsingUIManager(ui_manager_, iter->second, false); 465 NotifySafeBrowsingUIManager(ui_manager_, iter->second, false);
475 unsafe_resource_map->erase(iter); 466 unsafe_resource_map->erase(iter);
476 } 467 }
477 468
478 // We don't remove the navigation entry if the tab is being destroyed as this 469 // We don't remove the navigation entry if the tab is being destroyed as this
479 // would trigger a navigation that would cause trouble as the render view host 470 // would trigger a navigation that would cause trouble as the render view host
480 // for the tab has by then already been destroyed. We also don't delete the 471 // for the tab has by then already been destroyed. We also don't delete the
481 // current entry if it has been committed again, which is possible on a page 472 // current entry if it has been committed again, which is possible on a page
482 // that had a subresource warning. 473 // that had a subresource warning.
483 int last_committed_index = 474 int last_committed_index =
484 web_contents_->GetController().GetLastCommittedEntryIndex(); 475 web_contents()->GetController().GetLastCommittedEntryIndex();
485 if (navigation_entry_index_to_remove_ != -1 && 476 if (navigation_entry_index_to_remove_ != -1 &&
486 navigation_entry_index_to_remove_ != last_committed_index && 477 navigation_entry_index_to_remove_ != last_committed_index &&
487 !web_contents_->IsBeingDestroyed()) { 478 !web_contents()->IsBeingDestroyed()) {
488 CHECK(web_contents_->GetController().RemoveEntryAtIndex( 479 CHECK(web_contents()->GetController().RemoveEntryAtIndex(
489 navigation_entry_index_to_remove_)); 480 navigation_entry_index_to_remove_));
490 navigation_entry_index_to_remove_ = -1; 481 navigation_entry_index_to_remove_ = -1;
491 } 482 }
492 } 483 }
493 484
494 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success, 485 void SafeBrowsingBlockingPage::OnGotHistoryCount(bool success,
495 int num_visits, 486 int num_visits,
496 base::Time first_visit) { 487 base::Time first_visit) {
497 if (success) 488 if (success)
498 num_visits_ = num_visits; 489 num_visits_ = num_visits;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 // Finish the malware details collection, send it over. 590 // Finish the malware details collection, send it over.
600 BrowserThread::PostDelayedTask( 591 BrowserThread::PostDelayedTask(
601 BrowserThread::IO, FROM_HERE, 592 BrowserThread::IO, FROM_HERE,
602 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), 593 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()),
603 base::TimeDelta::FromMilliseconds(delay_ms)); 594 base::TimeDelta::FromMilliseconds(delay_ms));
604 } 595 }
605 } 596 }
606 597
607 bool SafeBrowsingBlockingPage::IsPrefEnabled(const char* pref) { 598 bool SafeBrowsingBlockingPage::IsPrefEnabled(const char* pref) {
608 Profile* profile = 599 Profile* profile =
609 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 600 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
610 return profile->GetPrefs()->GetBoolean(pref); 601 return profile->GetPrefs()->GetBoolean(pref);
611 } 602 }
612 603
613 // static 604 // static
614 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager( 605 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager(
615 SafeBrowsingUIManager* ui_manager, 606 SafeBrowsingUIManager* ui_manager,
616 const UnsafeResourceList& unsafe_resources, 607 const UnsafeResourceList& unsafe_resources,
617 bool proceed) { 608 bool proceed) {
618 BrowserThread::PostTask( 609 BrowserThread::PostTask(
619 BrowserThread::IO, FROM_HERE, 610 BrowserThread::IO, FROM_HERE,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 // load, since they happen after the page is finished loading. 671 // load, since they happen after the page is finished loading.
681 if (unsafe_resources[0].threat_type == 672 if (unsafe_resources[0].threat_type ==
682 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) { 673 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) {
683 return false; 674 return false;
684 } 675 }
685 676
686 // Otherwise, check the threat type. 677 // Otherwise, check the threat type.
687 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; 678 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource;
688 } 679 }
689 680
690 std::string SafeBrowsingBlockingPage::GetHTMLContents() { 681 void SafeBrowsingBlockingPage::PopulateInterstitialStrings(
691 DCHECK(!unsafe_resources_.empty()); 682 base::DictionaryValue* load_time_data) {
683 CHECK(load_time_data);
684 CHECK(!unsafe_resources_.empty());
692 685
693 // Fill in the shared values. 686 load_time_data->SetString("type", "SAFEBROWSING");
694 base::DictionaryValue load_time_data; 687 load_time_data->SetString(
695 webui::SetFontAndTextDirection(&load_time_data);
696 load_time_data.SetString("type", "SAFEBROWSING");
697 load_time_data.SetString(
698 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE)); 688 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE));
699 load_time_data.SetString( 689 load_time_data->SetString(
700 "openDetails", 690 "openDetails",
701 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON)); 691 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON));
702 load_time_data.SetString( 692 load_time_data->SetString(
703 "closeDetails", 693 "closeDetails",
704 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON)); 694 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON));
705 load_time_data.SetString( 695 load_time_data->SetString(
706 "primaryButtonText", 696 "primaryButtonText",
707 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON)); 697 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON));
708 load_time_data.SetBoolean( 698 load_time_data->SetBoolean(
709 "overridable", 699 "overridable",
710 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); 700 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled));
711 701
712 switch (interstitial_type_) { 702 switch (interstitial_type_) {
713 case TYPE_MALWARE: 703 case TYPE_MALWARE:
714 PopulateMalwareLoadTimeData(&load_time_data); 704 PopulateMalwareLoadTimeData(load_time_data);
715 break; 705 break;
716 case TYPE_HARMFUL: 706 case TYPE_HARMFUL:
717 PopulateHarmfulLoadTimeData(&load_time_data); 707 PopulateHarmfulLoadTimeData(load_time_data);
718 break; 708 break;
719 case TYPE_PHISHING: 709 case TYPE_PHISHING:
720 PopulatePhishingLoadTimeData(&load_time_data); 710 PopulatePhishingLoadTimeData(load_time_data);
721 break; 711 break;
722 } 712 }
723
724 base::StringPiece html(
725 ResourceBundle::GetSharedInstance().GetRawDataResource(
726 IDR_SECURITY_INTERSTITIAL_HTML));
727 return webui::GetI18nTemplateHtml(html, &load_time_data);
728 } 713 }
729 714
730 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData( 715 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData(
731 base::DictionaryValue* load_time_data) { 716 base::DictionaryValue* load_time_data) {
732 load_time_data->SetBoolean("phishing", false); 717 load_time_data->SetBoolean("phishing", false);
733 load_time_data->SetString( 718 load_time_data->SetString(
734 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING)); 719 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING));
735 load_time_data->SetString( 720 load_time_data->SetString(
736 "primaryParagraph", 721 "primaryParagraph",
737 l10n_util::GetStringFUTF16( 722 l10n_util::GetStringFUTF16(
738 IDS_MALWARE_V3_PRIMARY_PARAGRAPH, 723 IDS_MALWARE_V3_PRIMARY_PARAGRAPH,
739 base::UTF8ToUTF16(url_.host()))); 724 GetFormattedHostName()));
740 load_time_data->SetString( 725 load_time_data->SetString(
741 "explanationParagraph", 726 "explanationParagraph",
742 is_main_frame_load_blocked_ ? 727 is_main_frame_load_blocked_ ?
743 l10n_util::GetStringFUTF16( 728 l10n_util::GetStringFUTF16(
744 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH, 729 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH,
745 base::UTF8ToUTF16(url_.host())) : 730 GetFormattedHostName()) :
746 l10n_util::GetStringFUTF16( 731 l10n_util::GetStringFUTF16(
747 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE, 732 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE,
748 base::UTF8ToUTF16(web_contents_->GetURL().host()), 733 base::UTF8ToUTF16(web_contents()->GetURL().host()),
749 base::UTF8ToUTF16(url_.host()))); 734 GetFormattedHostName()));
750 load_time_data->SetString( 735 load_time_data->SetString(
751 "finalParagraph", 736 "finalParagraph",
752 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH)); 737 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH));
753 738
754 load_time_data->SetBoolean(kDisplayCheckBox, CanShowMalwareDetailsOption()); 739 load_time_data->SetBoolean(kDisplayCheckBox, CanShowMalwareDetailsOption());
755 if (CanShowMalwareDetailsOption()) { 740 if (CanShowMalwareDetailsOption()) {
756 std::string privacy_link = base::StringPrintf( 741 std::string privacy_link = base::StringPrintf(
757 kPrivacyLinkHtml, 742 kPrivacyLinkHtml,
758 l10n_util::GetStringUTF8( 743 l10n_util::GetStringUTF8(
759 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); 744 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str());
760 load_time_data->SetString( 745 load_time_data->SetString(
761 "optInLink", 746 "optInLink",
762 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, 747 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE,
763 base::UTF8ToUTF16(privacy_link))); 748 base::UTF8ToUTF16(privacy_link)));
764 load_time_data->SetBoolean( 749 load_time_data->SetBoolean(
765 kBoxChecked, 750 kBoxChecked,
766 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled)); 751 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled));
767 } 752 }
768 } 753 }
769 754
770 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData( 755 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData(
771 base::DictionaryValue* load_time_data) { 756 base::DictionaryValue* load_time_data) {
772 load_time_data->SetBoolean("phishing", false); 757 load_time_data->SetBoolean("phishing", false);
773 load_time_data->SetString( 758 load_time_data->SetString(
774 "heading", l10n_util::GetStringUTF16(IDS_HARMFUL_V3_HEADING)); 759 "heading", l10n_util::GetStringUTF16(IDS_HARMFUL_V3_HEADING));
775 load_time_data->SetString( 760 load_time_data->SetString(
776 "primaryParagraph", 761 "primaryParagraph",
777 l10n_util::GetStringFUTF16( 762 l10n_util::GetStringFUTF16(
778 IDS_HARMFUL_V3_PRIMARY_PARAGRAPH, 763 IDS_HARMFUL_V3_PRIMARY_PARAGRAPH,
779 base::UTF8ToUTF16(url_.host()))); 764 GetFormattedHostName()));
780 load_time_data->SetString( 765 load_time_data->SetString(
781 "explanationParagraph", 766 "explanationParagraph",
782 l10n_util::GetStringFUTF16( 767 l10n_util::GetStringFUTF16(
783 IDS_HARMFUL_V3_EXPLANATION_PARAGRAPH, 768 IDS_HARMFUL_V3_EXPLANATION_PARAGRAPH,
784 base::UTF8ToUTF16(url_.host()))); 769 GetFormattedHostName()));
785 load_time_data->SetString( 770 load_time_data->SetString(
786 "finalParagraph", 771 "finalParagraph",
787 l10n_util::GetStringUTF16(IDS_HARMFUL_V3_PROCEED_PARAGRAPH)); 772 l10n_util::GetStringUTF16(IDS_HARMFUL_V3_PROCEED_PARAGRAPH));
788 773
789 load_time_data->SetBoolean(kDisplayCheckBox, CanShowMalwareDetailsOption()); 774 load_time_data->SetBoolean(kDisplayCheckBox, CanShowMalwareDetailsOption());
790 if (CanShowMalwareDetailsOption()) { 775 if (CanShowMalwareDetailsOption()) {
791 std::string privacy_link = base::StringPrintf( 776 std::string privacy_link = base::StringPrintf(
792 kPrivacyLinkHtml, 777 kPrivacyLinkHtml,
793 l10n_util::GetStringUTF8( 778 l10n_util::GetStringUTF8(
794 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); 779 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str());
(...skipping 10 matching lines...) Expand all
805 void SafeBrowsingBlockingPage::PopulatePhishingLoadTimeData( 790 void SafeBrowsingBlockingPage::PopulatePhishingLoadTimeData(
806 base::DictionaryValue* load_time_data) { 791 base::DictionaryValue* load_time_data) {
807 load_time_data->SetBoolean("phishing", true); 792 load_time_data->SetBoolean("phishing", true);
808 load_time_data->SetString( 793 load_time_data->SetString(
809 "heading", 794 "heading",
810 l10n_util::GetStringUTF16(IDS_PHISHING_V3_HEADING)); 795 l10n_util::GetStringUTF16(IDS_PHISHING_V3_HEADING));
811 load_time_data->SetString( 796 load_time_data->SetString(
812 "primaryParagraph", 797 "primaryParagraph",
813 l10n_util::GetStringFUTF16( 798 l10n_util::GetStringFUTF16(
814 IDS_PHISHING_V3_PRIMARY_PARAGRAPH, 799 IDS_PHISHING_V3_PRIMARY_PARAGRAPH,
815 base::UTF8ToUTF16(url_.host()))); 800 GetFormattedHostName()));
816 load_time_data->SetString( 801 load_time_data->SetString(
817 "explanationParagraph", 802 "explanationParagraph",
818 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH, 803 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH,
819 base::UTF8ToUTF16(url_.host()))); 804 GetFormattedHostName()));
820 load_time_data->SetString( 805 load_time_data->SetString(
821 "finalParagraph", 806 "finalParagraph",
822 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH)); 807 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
823 } 808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698