Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / safe_browsing / safe_browsing_blocking_page.cc
blob111ee38c7e54ddf2aca585db7f2d831b897a1df0
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
3 // found in the LICENSE file.
4 //
5 // Implementation of the SafeBrowsingBlockingPage class.
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
9 #include <string>
11 #include "base/bind.h"
12 #include "base/command_line.h"
13 #include "base/i18n/rtl.h"
14 #include "base/lazy_instance.h"
15 #include "base/metrics/field_trial.h"
16 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_piece.h"
20 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/time.h"
23 #include "base/values.h"
24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/renderer_preferences_util.h"
27 #include "chrome/browser/safe_browsing/malware_details.h"
28 #include "chrome/browser/safe_browsing/ui_manager.h"
29 #include "chrome/browser/tab_contents/tab_util.h"
30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/pref_names.h"
32 #include "chrome/common/url_constants.h"
33 #include "chrome/grit/generated_resources.h"
34 #include "chrome/grit/locale_settings.h"
35 #include "components/google/core/browser/google_util.h"
36 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/interstitial_page.h"
38 #include "content/public/browser/navigation_controller.h"
39 #include "content/public/browser/user_metrics.h"
40 #include "content/public/browser/web_contents.h"
41 #include "content/public/common/renderer_preferences.h"
42 #include "grit/browser_resources.h"
43 #include "net/base/escape.h"
44 #include "ui/base/l10n/l10n_util.h"
46 using base::UserMetricsAction;
47 using content::BrowserThread;
48 using content::InterstitialPage;
49 using content::OpenURLParams;
50 using content::Referrer;
51 using content::WebContents;
53 namespace {
55 // For malware interstitial pages, we link the problematic URL to Google's
56 // diagnostic page.
57 #if defined(GOOGLE_CHROME_BUILD)
58 const char kSbDiagnosticUrl[] =
59 "https://www.google.com/safebrowsing/diagnostic?site=%s&client=googlechrome";
60 #else
61 const char kSbDiagnosticUrl[] =
62 "https://www.google.com/safebrowsing/diagnostic?site=%s&client=chromium";
63 #endif
65 // URL for malware and phishing, V2.
66 const char kLearnMoreMalwareUrlV2[] =
67 "https://www.google.com/transparencyreport/safebrowsing/";
68 const char kLearnMorePhishingUrlV2[] =
69 "https://www.google.com/transparencyreport/safebrowsing/";
71 // Constants for the V4 phishing string upgrades.
72 const char kSocialEngineeringTrial[] = "SafeBrowsingSocialEngineeringStrings";
73 const char kSocialEngineeringEnabled[] = "Enabled";
75 // After a malware interstitial where the user opted-in to the report
76 // but clicked "proceed anyway", we delay the call to
77 // MalwareDetails::FinishCollection() by this much time (in
78 // milliseconds).
79 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000;
81 // Constants for the Experience Sampling instrumentation.
82 const char kEventNameMalware[] = "safebrowsing_interstitial_";
83 const char kEventNameHarmful[] = "harmful_interstitial_";
84 const char kEventNamePhishing[] = "phishing_interstitial_";
85 const char kEventNameOther[] = "safebrowsing_other_interstitial_";
87 // Constants for the V4 phishing string upgrades.
88 const char kReportPhishingErrorUrl[] =
89 "https://www.google.com/safebrowsing/report_error/";
90 const char kReportPhishingErrorTrial[] = "SafeBrowsingReportPhishingErrorLink";
91 const char kReportPhishingErrorEnabled[] = "Enabled";
93 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap>
94 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER;
96 } // namespace
98 // static
99 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL;
101 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we
102 // don't leak it.
103 class SafeBrowsingBlockingPageFactoryImpl
104 : public SafeBrowsingBlockingPageFactory {
105 public:
106 SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
107 SafeBrowsingUIManager* ui_manager,
108 WebContents* web_contents,
109 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources)
110 override {
111 return new SafeBrowsingBlockingPage(ui_manager, web_contents,
112 unsafe_resources);
115 private:
116 friend struct base::DefaultLazyInstanceTraits<
117 SafeBrowsingBlockingPageFactoryImpl>;
119 SafeBrowsingBlockingPageFactoryImpl() { }
121 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl);
124 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl>
125 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER;
127 // static
128 content::InterstitialPageDelegate::TypeID
129 SafeBrowsingBlockingPage::kTypeForTesting =
130 &SafeBrowsingBlockingPage::kTypeForTesting;
132 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
133 SafeBrowsingUIManager* ui_manager,
134 WebContents* web_contents,
135 const UnsafeResourceList& unsafe_resources)
136 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url),
137 malware_details_proceed_delay_ms_(
138 kMalwareDetailsProceedDelayMilliSeconds),
139 ui_manager_(ui_manager),
140 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)),
141 unsafe_resources_(unsafe_resources),
142 proceeded_(false) {
143 bool malware = false;
144 bool harmful = false;
145 bool phishing = false;
146 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin();
147 iter != unsafe_resources_.end(); ++iter) {
148 const UnsafeResource& resource = *iter;
149 SBThreatType threat_type = resource.threat_type;
150 if (threat_type == SB_THREAT_TYPE_URL_MALWARE ||
151 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) {
152 malware = true;
153 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) {
154 harmful = true;
155 } else {
156 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING ||
157 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL);
158 phishing = true;
161 DCHECK(phishing || malware || harmful);
162 if (malware)
163 interstitial_reason_ = SB_REASON_MALWARE;
164 else if (harmful)
165 interstitial_reason_ = SB_REASON_HARMFUL;
166 else
167 interstitial_reason_ = SB_REASON_PHISHING;
169 // This must be done after calculating |interstitial_reason_| above.
170 security_interstitials::MetricsHelper::ReportDetails reporting_info;
171 reporting_info.metric_prefix = GetMetricPrefix();
172 reporting_info.extra_suffix = GetExtraMetricsSuffix();
173 reporting_info.rappor_prefix = GetRapporPrefix();
174 reporting_info.rappor_report_type = rappor::SAFEBROWSING_RAPPOR_TYPE;
175 set_metrics_helper(new ChromeMetricsHelper(
176 web_contents, request_url(), reporting_info, GetSamplingEventName()));
177 metrics_helper()->RecordUserDecision(
178 security_interstitials::MetricsHelper::SHOW);
179 metrics_helper()->RecordUserInteraction(
180 security_interstitials::MetricsHelper::TOTAL_VISITS);
181 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
182 metrics_helper()->RecordUserDecision(
183 security_interstitials::MetricsHelper::PROCEEDING_DISABLED);
186 if (!is_main_frame_load_blocked_) {
187 navigation_entry_index_to_remove_ =
188 web_contents->GetController().GetLastCommittedEntryIndex();
189 } else {
190 navigation_entry_index_to_remove_ = -1;
193 // Start computing malware details. They will be sent only
194 // if the user opts-in on the blocking page later.
195 // If there's more than one malicious resources, it means the user
196 // clicked through the first warning, so we don't prepare additional
197 // reports.
198 if (unsafe_resources.size() == 1 &&
199 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE &&
200 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) {
201 malware_details_ = MalwareDetails::NewMalwareDetails(
202 ui_manager_, web_contents, unsafe_resources[0]);
206 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() {
207 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() &&
208 web_contents()->GetURL().SchemeIs(url::kHttpScheme) &&
209 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed));
212 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
215 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) {
216 if (page_cmd == "\"pageLoadComplete\"") {
217 // content::WaitForRenderFrameReady sends this message when the page
218 // load completes. Ignore it.
219 return;
222 int command = 0;
223 bool retval = base::StringToInt(page_cmd, &command);
224 DCHECK(retval) << page_cmd;
226 switch (command) {
227 case CMD_DO_REPORT: {
228 // User enabled SB Extended Reporting via the checkbox.
229 SetReportingPreference(true);
230 break;
232 case CMD_DONT_REPORT: {
233 // User disabled SB Extended Reporting via the checkbox.
234 SetReportingPreference(false);
235 break;
237 case CMD_OPEN_HELP_CENTER: {
238 // User pressed "Learn more".
239 metrics_helper()->RecordUserInteraction(
240 security_interstitials::MetricsHelper::SHOW_LEARN_MORE);
241 GURL learn_more_url(
242 interstitial_reason_ == SB_REASON_PHISHING ?
243 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2);
244 learn_more_url = google_util::AppendGoogleLocaleParam(
245 learn_more_url, g_browser_process->GetApplicationLocale());
246 OpenURLParams params(learn_more_url,
247 Referrer(),
248 CURRENT_TAB,
249 ui::PAGE_TRANSITION_LINK,
250 false);
251 web_contents()->OpenURL(params);
252 break;
254 case CMD_OPEN_REPORTING_PRIVACY: {
255 // User pressed on the SB Extended Reporting "privacy policy" link.
256 OpenExtendedReportingPrivacyPolicy();
257 break;
259 case CMD_PROCEED: {
260 // User pressed on the button to proceed.
261 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
262 metrics_helper()->RecordUserDecision(
263 security_interstitials::MetricsHelper::PROCEED);
264 interstitial_page()->Proceed();
265 // |this| has been deleted after Proceed() returns.
266 break;
268 // If the user can't proceed, fall through to CMD_DONT_PROCEED.
270 case CMD_DONT_PROCEED: {
271 // User pressed on the button to return to safety.
272 // Don't record the user action here because there are other ways of
273 // triggering DontProceed, like clicking the back button.
274 if (is_main_frame_load_blocked_) {
275 // If the load is blocked, we want to close the interstitial and discard
276 // the pending entry.
277 interstitial_page()->DontProceed();
278 // |this| has been deleted after DontProceed() returns.
279 break;
282 // Otherwise the offending entry has committed, and we need to go back or
283 // to a safe page. We will close the interstitial when that page commits.
284 if (web_contents()->GetController().CanGoBack()) {
285 web_contents()->GetController().GoBack();
286 } else {
287 web_contents()->GetController().LoadURL(
288 GURL(chrome::kChromeUINewTabURL),
289 content::Referrer(),
290 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
291 std::string());
293 break;
295 case CMD_OPEN_DIAGNOSTIC: {
296 // User wants to see why this page is blocked.
297 const UnsafeResource& unsafe_resource = unsafe_resources_[0];
298 std::string bad_url_spec = unsafe_resource.url.spec();
299 metrics_helper()->RecordUserInteraction(
300 security_interstitials::MetricsHelper::SHOW_DIAGNOSTIC);
301 std::string diagnostic =
302 base::StringPrintf(kSbDiagnosticUrl,
303 net::EscapeQueryParamValue(bad_url_spec, true).c_str());
304 GURL diagnostic_url(diagnostic);
305 diagnostic_url = google_util::AppendGoogleLocaleParam(
306 diagnostic_url, g_browser_process->GetApplicationLocale());
307 DCHECK(unsafe_resource.threat_type == SB_THREAT_TYPE_URL_MALWARE ||
308 unsafe_resource.threat_type ==
309 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL ||
310 unsafe_resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED);
311 OpenURLParams params(
312 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK,
313 false);
314 web_contents()->OpenURL(params);
315 break;
317 case CMD_SHOW_MORE_SECTION: {
318 // User has opened up the hidden text.
319 metrics_helper()->RecordUserInteraction(
320 security_interstitials::MetricsHelper::SHOW_ADVANCED);
321 break;
323 case CMD_REPORT_PHISHING_ERROR: {
324 // User wants to report a phishing error.
325 metrics_helper()->RecordUserInteraction(
326 security_interstitials::MetricsHelper::REPORT_PHISHING_ERROR);
327 GURL phishing_error_url(kReportPhishingErrorUrl);
328 phishing_error_url = google_util::AppendGoogleLocaleParam(
329 phishing_error_url, g_browser_process->GetApplicationLocale());
330 OpenURLParams params(phishing_error_url, Referrer(), CURRENT_TAB,
331 ui::PAGE_TRANSITION_LINK, false);
332 web_contents()->OpenURL(params);
333 break;
338 void SafeBrowsingBlockingPage::OverrideRendererPrefs(
339 content::RendererPreferences* prefs) {
340 Profile* profile = Profile::FromBrowserContext(
341 web_contents()->GetBrowserContext());
342 renderer_preferences_util::UpdateFromSystemSettings(
343 prefs, profile, web_contents());
346 void SafeBrowsingBlockingPage::OnProceed() {
347 proceeded_ = true;
348 // Send the malware details, if we opted to.
349 FinishMalwareDetails(malware_details_proceed_delay_ms_);
351 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true);
353 // Check to see if some new notifications of unsafe resources have been
354 // received while we were showing the interstitial.
355 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
356 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
357 SafeBrowsingBlockingPage* blocking_page = NULL;
358 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
359 // Build an interstitial for all the unsafe resources notifications.
360 // Don't show it now as showing an interstitial while an interstitial is
361 // already showing would cause DontProceed() to be invoked.
362 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_,
363 web_contents(),
364 iter->second);
365 unsafe_resource_map->erase(iter);
368 // Now that this interstitial is gone, we can show the new one.
369 if (blocking_page)
370 blocking_page->Show();
373 content::InterstitialPageDelegate::TypeID
374 SafeBrowsingBlockingPage::GetTypeForTesting() const {
375 return SafeBrowsingBlockingPage::kTypeForTesting;
378 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const {
379 return is_main_frame_load_blocked_;
382 void SafeBrowsingBlockingPage::OnDontProceed() {
383 // We could have already called Proceed(), in which case we must not notify
384 // the SafeBrowsingUIManager again, as the client has been deleted.
385 if (proceeded_)
386 return;
388 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
389 metrics_helper()->RecordUserDecision(
390 security_interstitials::MetricsHelper::DONT_PROCEED);
393 // Send the malware details, if we opted to.
394 FinishMalwareDetails(0); // No delay
396 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false);
398 // The user does not want to proceed, clear the queued unsafe resources
399 // notifications we received while the interstitial was showing.
400 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
401 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
402 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
403 NotifySafeBrowsingUIManager(ui_manager_, iter->second, false);
404 unsafe_resource_map->erase(iter);
407 // We don't remove the navigation entry if the tab is being destroyed as this
408 // would trigger a navigation that would cause trouble as the render view host
409 // for the tab has by then already been destroyed. We also don't delete the
410 // current entry if it has been committed again, which is possible on a page
411 // that had a subresource warning.
412 int last_committed_index =
413 web_contents()->GetController().GetLastCommittedEntryIndex();
414 if (navigation_entry_index_to_remove_ != -1 &&
415 navigation_entry_index_to_remove_ != last_committed_index &&
416 !web_contents()->IsBeingDestroyed()) {
417 CHECK(web_contents()->GetController().RemoveEntryAtIndex(
418 navigation_entry_index_to_remove_));
419 navigation_entry_index_to_remove_ = -1;
423 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) {
424 if (malware_details_.get() == NULL)
425 return; // Not all interstitials have malware details (eg phishing).
426 DCHECK_EQ(interstitial_reason_, SB_REASON_MALWARE);
428 const bool enabled =
429 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled) &&
430 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed);
431 if (!enabled)
432 return;
434 metrics_helper()->RecordUserInteraction(
435 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED);
436 // Finish the malware details collection, send it over.
437 BrowserThread::PostDelayedTask(
438 BrowserThread::IO, FROM_HERE,
439 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()),
440 base::TimeDelta::FromMilliseconds(delay_ms));
443 // static
444 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager(
445 SafeBrowsingUIManager* ui_manager,
446 const UnsafeResourceList& unsafe_resources,
447 bool proceed) {
448 BrowserThread::PostTask(
449 BrowserThread::IO, FROM_HERE,
450 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone,
451 ui_manager, unsafe_resources, proceed));
454 // static
455 SafeBrowsingBlockingPage::UnsafeResourceMap*
456 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() {
457 return g_unsafe_resource_map.Pointer();
460 // static
461 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage(
462 SafeBrowsingUIManager* ui_manager,
463 WebContents* web_contents,
464 const UnsafeResource& unsafe_resource) {
465 std::vector<UnsafeResource> resources;
466 resources.push_back(unsafe_resource);
467 // Set up the factory if this has not been done already (tests do that
468 // before this method is called).
469 if (!factory_)
470 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer();
471 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents, resources);
474 // static
475 void SafeBrowsingBlockingPage::ShowBlockingPage(
476 SafeBrowsingUIManager* ui_manager,
477 const UnsafeResource& unsafe_resource) {
478 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec();
479 WebContents* web_contents = tab_util::GetWebContentsByID(
480 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id);
482 InterstitialPage* interstitial =
483 InterstitialPage::GetInterstitialPage(web_contents);
484 if (interstitial && !unsafe_resource.is_subresource) {
485 // There is already an interstitial showing and we are about to display a
486 // new one for the main frame. Just hide the current one, it is now
487 // irrelevent
488 interstitial->DontProceed();
489 interstitial = NULL;
492 if (!interstitial) {
493 // There are no interstitial currently showing in that tab, go ahead and
494 // show this interstitial.
495 SafeBrowsingBlockingPage* blocking_page =
496 CreateBlockingPage(ui_manager, web_contents, unsafe_resource);
497 blocking_page->Show();
498 return;
501 // This is an interstitial for a page's resource, let's queue it.
502 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
503 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource);
506 // static
507 bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked(
508 const UnsafeResourceList& unsafe_resources) {
509 // Client-side phishing detection interstitials never block the main frame
510 // load, since they happen after the page is finished loading.
511 if (unsafe_resources[0].threat_type ==
512 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) {
513 return false;
516 // Otherwise, check the threat type.
517 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource;
520 std::string SafeBrowsingBlockingPage::GetMetricPrefix() const {
521 bool primary_subresource = unsafe_resources_[0].is_subresource;
522 switch (interstitial_reason_) {
523 case SB_REASON_MALWARE:
524 return primary_subresource ? "malware_subresource" : "malware";
525 case SB_REASON_HARMFUL:
526 return primary_subresource ? "harmful_subresource" : "harmful";
527 case SB_REASON_PHISHING:
528 return primary_subresource ? "phishing_subresource" : "phishing";
530 NOTREACHED();
531 return std::string();
534 // We populate a parallel set of metrics to differentiate some threat sources.
535 std::string SafeBrowsingBlockingPage::GetExtraMetricsSuffix() const {
536 switch (unsafe_resources_[0].threat_source) {
537 case SafeBrowsingUIManager::FROM_DATA_SAVER:
538 return "from_data_saver";
539 case SafeBrowsingUIManager::FROM_DEVICE:
540 return "from_device";
541 case SafeBrowsingUIManager::FROM_UNKNOWN:
542 break;
544 NOTREACHED();
545 return std::string();
548 std::string SafeBrowsingBlockingPage::GetRapporPrefix() const {
549 switch (interstitial_reason_) {
550 case SB_REASON_MALWARE:
551 return "malware";
552 case SB_REASON_HARMFUL:
553 return "harmful";
554 case SB_REASON_PHISHING:
555 return "phishing";
557 NOTREACHED();
558 return std::string();
561 std::string SafeBrowsingBlockingPage::GetSamplingEventName() const {
562 switch (interstitial_reason_) {
563 case SB_REASON_MALWARE:
564 return kEventNameMalware;
565 case SB_REASON_HARMFUL:
566 return kEventNameHarmful;
567 case SB_REASON_PHISHING:
568 return kEventNamePhishing;
569 default:
570 return kEventNameOther;
574 void SafeBrowsingBlockingPage::PopulateInterstitialStrings(
575 base::DictionaryValue* load_time_data) {
576 CHECK(load_time_data);
577 CHECK(!unsafe_resources_.empty());
579 load_time_data->SetString("type", "SAFEBROWSING");
580 load_time_data->SetString(
581 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE));
582 load_time_data->SetString(
583 "openDetails",
584 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON));
585 load_time_data->SetString(
586 "closeDetails",
587 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON));
588 load_time_data->SetString(
589 "primaryButtonText",
590 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON));
591 load_time_data->SetBoolean(
592 "overridable",
593 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled));
595 switch (interstitial_reason_) {
596 case SB_REASON_MALWARE:
597 PopulateMalwareLoadTimeData(load_time_data);
598 break;
599 case SB_REASON_HARMFUL:
600 PopulateHarmfulLoadTimeData(load_time_data);
601 break;
602 case SB_REASON_PHISHING:
603 PopulatePhishingLoadTimeData(load_time_data);
604 break;
608 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption(
609 base::DictionaryValue* load_time_data) {
610 // Only show checkbox if !(HTTPS || incognito-mode).
611 const bool show = CanShowMalwareDetailsOption();
612 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show);
613 if (!show)
614 return;
616 const std::string privacy_link = base::StringPrintf(
617 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY,
618 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str());
619 load_time_data->SetString(
620 interstitials::kOptInLink,
621 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE,
622 base::UTF8ToUTF16(privacy_link)));
623 load_time_data->SetBoolean(
624 interstitials::kBoxChecked,
625 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled));
628 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData(
629 base::DictionaryValue* load_time_data) {
630 load_time_data->SetBoolean("phishing", false);
631 load_time_data->SetString(
632 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING));
633 load_time_data->SetString(
634 "primaryParagraph",
635 l10n_util::GetStringFUTF16(
636 IDS_MALWARE_V3_PRIMARY_PARAGRAPH,
637 GetFormattedHostName()));
638 load_time_data->SetString(
639 "explanationParagraph",
640 is_main_frame_load_blocked_ ?
641 l10n_util::GetStringFUTF16(
642 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH,
643 GetFormattedHostName()) :
644 l10n_util::GetStringFUTF16(
645 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE,
646 base::UTF8ToUTF16(web_contents()->GetURL().host()),
647 GetFormattedHostName()));
648 load_time_data->SetString(
649 "finalParagraph",
650 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH));
652 PopulateExtendedReportingOption(load_time_data);
655 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData(
656 base::DictionaryValue* load_time_data) {
657 load_time_data->SetBoolean("phishing", false);
658 load_time_data->SetString(
659 "heading", l10n_util::GetStringUTF16(IDS_HARMFUL_V3_HEADING));
660 load_time_data->SetString(
661 "primaryParagraph",
662 l10n_util::GetStringFUTF16(
663 IDS_HARMFUL_V3_PRIMARY_PARAGRAPH,
664 GetFormattedHostName()));
665 load_time_data->SetString(
666 "explanationParagraph",
667 l10n_util::GetStringFUTF16(
668 IDS_HARMFUL_V3_EXPLANATION_PARAGRAPH,
669 GetFormattedHostName()));
670 load_time_data->SetString(
671 "finalParagraph",
672 l10n_util::GetStringUTF16(IDS_HARMFUL_V3_PROCEED_PARAGRAPH));
674 PopulateExtendedReportingOption(load_time_data);
677 void SafeBrowsingBlockingPage::PopulatePhishingLoadTimeData(
678 base::DictionaryValue* load_time_data) {
679 bool use_social_engineering_strings =
680 base::FieldTrialList::FindFullName(kSocialEngineeringTrial) ==
681 kSocialEngineeringEnabled;
682 load_time_data->SetBoolean("phishing", true);
683 load_time_data->SetString(
684 "heading", l10n_util::GetStringUTF16(use_social_engineering_strings
685 ? IDS_PHISHING_V4_HEADING
686 : IDS_PHISHING_V3_HEADING));
687 load_time_data->SetString(
688 "primaryParagraph",
689 l10n_util::GetStringFUTF16(use_social_engineering_strings
690 ? IDS_PHISHING_V4_PRIMARY_PARAGRAPH
691 : IDS_PHISHING_V3_PRIMARY_PARAGRAPH,
692 GetFormattedHostName()));
693 load_time_data->SetString(
694 "explanationParagraph",
695 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH,
696 GetFormattedHostName()));
698 if (base::FieldTrialList::FindFullName(kReportPhishingErrorTrial) ==
699 kReportPhishingErrorEnabled) {
700 load_time_data->SetString(
701 "finalParagraph", l10n_util::GetStringUTF16(
702 IDS_PHISHING_V4_PROCEED_AND_REPORT_PARAGRAPH));
703 } else {
704 load_time_data->SetString(
705 "finalParagraph",
706 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
709 PopulateExtendedReportingOption(load_time_data);