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