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.
5 // Implementation of the SafeBrowsingBlockingPage class.
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
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
;
55 // For malware interstitial pages, we link the problematic URL to Google's
57 #if defined(GOOGLE_CHROME_BUILD)
58 const char kSbDiagnosticUrl
[] =
59 "https://www.google.com/safebrowsing/diagnostic?site=%s&client=googlechrome";
61 const char kSbDiagnosticUrl
[] =
62 "https://www.google.com/safebrowsing/diagnostic?site=%s&client=chromium";
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
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
;
99 SafeBrowsingBlockingPageFactory
* SafeBrowsingBlockingPage::factory_
= NULL
;
101 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we
103 class SafeBrowsingBlockingPageFactoryImpl
104 : public SafeBrowsingBlockingPageFactory
{
106 SafeBrowsingBlockingPage
* CreateSafeBrowsingPage(
107 SafeBrowsingUIManager
* ui_manager
,
108 WebContents
* web_contents
,
109 const SafeBrowsingBlockingPage::UnsafeResourceList
& unsafe_resources
)
111 return new SafeBrowsingBlockingPage(ui_manager
, web_contents
,
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
;
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
),
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
) {
153 } else if (threat_type
== SB_THREAT_TYPE_URL_UNWANTED
) {
156 DCHECK(threat_type
== SB_THREAT_TYPE_URL_PHISHING
||
157 threat_type
== SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL
);
161 DCHECK(phishing
|| malware
|| harmful
);
163 interstitial_reason_
= SB_REASON_MALWARE
;
165 interstitial_reason_
= SB_REASON_HARMFUL
;
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
.rappor_prefix
= GetRapporPrefix();
173 reporting_info
.rappor_report_type
= rappor::SAFEBROWSING_RAPPOR_TYPE
;
174 set_metrics_helper(new ChromeMetricsHelper(
175 web_contents
, request_url(), reporting_info
, GetSamplingEventName()));
176 metrics_helper()->RecordUserDecision(
177 security_interstitials::MetricsHelper::SHOW
);
178 metrics_helper()->RecordUserInteraction(
179 security_interstitials::MetricsHelper::TOTAL_VISITS
);
180 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled
)) {
181 metrics_helper()->RecordUserDecision(
182 security_interstitials::MetricsHelper::PROCEEDING_DISABLED
);
185 if (!is_main_frame_load_blocked_
) {
186 navigation_entry_index_to_remove_
=
187 web_contents
->GetController().GetLastCommittedEntryIndex();
189 navigation_entry_index_to_remove_
= -1;
192 // Start computing malware details. They will be sent only
193 // if the user opts-in on the blocking page later.
194 // If there's more than one malicious resources, it means the user
195 // clicked through the first warning, so we don't prepare additional
197 if (unsafe_resources
.size() == 1 &&
198 unsafe_resources
[0].threat_type
== SB_THREAT_TYPE_URL_MALWARE
&&
199 malware_details_
.get() == NULL
&& CanShowMalwareDetailsOption()) {
200 malware_details_
= MalwareDetails::NewMalwareDetails(
201 ui_manager_
, web_contents
, unsafe_resources
[0]);
205 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() {
206 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() &&
207 web_contents()->GetURL().SchemeIs(url::kHttpScheme
) &&
208 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed
));
211 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
214 void SafeBrowsingBlockingPage::CommandReceived(const std::string
& page_cmd
) {
215 if (page_cmd
== "\"pageLoadComplete\"") {
216 // content::WaitForRenderFrameReady sends this message when the page
217 // load completes. Ignore it.
222 bool retval
= base::StringToInt(page_cmd
, &command
);
223 DCHECK(retval
) << page_cmd
;
226 case CMD_DO_REPORT
: {
227 // User enabled SB Extended Reporting via the checkbox.
228 SetReportingPreference(true);
231 case CMD_DONT_REPORT
: {
232 // User disabled SB Extended Reporting via the checkbox.
233 SetReportingPreference(false);
236 case CMD_OPEN_HELP_CENTER
: {
237 // User pressed "Learn more".
238 metrics_helper()->RecordUserInteraction(
239 security_interstitials::MetricsHelper::SHOW_LEARN_MORE
);
241 interstitial_reason_
== SB_REASON_PHISHING
?
242 kLearnMorePhishingUrlV2
: kLearnMoreMalwareUrlV2
);
243 learn_more_url
= google_util::AppendGoogleLocaleParam(
244 learn_more_url
, g_browser_process
->GetApplicationLocale());
245 OpenURLParams
params(learn_more_url
,
248 ui::PAGE_TRANSITION_LINK
,
250 web_contents()->OpenURL(params
);
253 case CMD_OPEN_REPORTING_PRIVACY
: {
254 // User pressed on the SB Extended Reporting "privacy policy" link.
255 OpenExtendedReportingPrivacyPolicy();
259 // User pressed on the button to proceed.
260 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled
)) {
261 metrics_helper()->RecordUserDecision(
262 security_interstitials::MetricsHelper::PROCEED
);
263 interstitial_page()->Proceed();
264 // |this| has been deleted after Proceed() returns.
267 // If the user can't proceed, fall through to CMD_DONT_PROCEED.
269 case CMD_DONT_PROCEED
: {
270 // User pressed on the button to return to safety.
271 // Don't record the user action here because there are other ways of
272 // triggering DontProceed, like clicking the back button.
273 if (is_main_frame_load_blocked_
) {
274 // If the load is blocked, we want to close the interstitial and discard
275 // the pending entry.
276 interstitial_page()->DontProceed();
277 // |this| has been deleted after DontProceed() returns.
281 // Otherwise the offending entry has committed, and we need to go back or
282 // to a safe page. We will close the interstitial when that page commits.
283 if (web_contents()->GetController().CanGoBack()) {
284 web_contents()->GetController().GoBack();
286 web_contents()->GetController().LoadURL(
287 GURL(chrome::kChromeUINewTabURL
),
289 ui::PAGE_TRANSITION_AUTO_TOPLEVEL
,
294 case CMD_OPEN_DIAGNOSTIC
: {
295 // User wants to see why this page is blocked.
296 const UnsafeResource
& unsafe_resource
= unsafe_resources_
[0];
297 std::string bad_url_spec
= unsafe_resource
.url
.spec();
298 metrics_helper()->RecordUserInteraction(
299 security_interstitials::MetricsHelper::SHOW_DIAGNOSTIC
);
300 std::string diagnostic
=
301 base::StringPrintf(kSbDiagnosticUrl
,
302 net::EscapeQueryParamValue(bad_url_spec
, true).c_str());
303 GURL
diagnostic_url(diagnostic
);
304 diagnostic_url
= google_util::AppendGoogleLocaleParam(
305 diagnostic_url
, g_browser_process
->GetApplicationLocale());
306 DCHECK(unsafe_resource
.threat_type
== SB_THREAT_TYPE_URL_MALWARE
||
307 unsafe_resource
.threat_type
==
308 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL
||
309 unsafe_resource
.threat_type
== SB_THREAT_TYPE_URL_UNWANTED
);
310 OpenURLParams
params(
311 diagnostic_url
, Referrer(), CURRENT_TAB
, ui::PAGE_TRANSITION_LINK
,
313 web_contents()->OpenURL(params
);
316 case CMD_SHOW_MORE_SECTION
: {
317 // User has opened up the hidden text.
318 metrics_helper()->RecordUserInteraction(
319 security_interstitials::MetricsHelper::SHOW_ADVANCED
);
322 case CMD_REPORT_PHISHING_ERROR
: {
323 // User wants to report a phishing error.
324 metrics_helper()->RecordUserInteraction(
325 security_interstitials::MetricsHelper::REPORT_PHISHING_ERROR
);
326 GURL
phishing_error_url(kReportPhishingErrorUrl
);
327 phishing_error_url
= google_util::AppendGoogleLocaleParam(
328 phishing_error_url
, g_browser_process
->GetApplicationLocale());
329 OpenURLParams
params(phishing_error_url
, Referrer(), CURRENT_TAB
,
330 ui::PAGE_TRANSITION_LINK
, false);
331 web_contents()->OpenURL(params
);
337 void SafeBrowsingBlockingPage::OverrideRendererPrefs(
338 content::RendererPreferences
* prefs
) {
339 Profile
* profile
= Profile::FromBrowserContext(
340 web_contents()->GetBrowserContext());
341 renderer_preferences_util::UpdateFromSystemSettings(
342 prefs
, profile
, web_contents());
345 void SafeBrowsingBlockingPage::OnProceed() {
347 // Send the malware details, if we opted to.
348 FinishMalwareDetails(malware_details_proceed_delay_ms_
);
350 NotifySafeBrowsingUIManager(ui_manager_
, unsafe_resources_
, true);
352 // Check to see if some new notifications of unsafe resources have been
353 // received while we were showing the interstitial.
354 UnsafeResourceMap
* unsafe_resource_map
= GetUnsafeResourcesMap();
355 UnsafeResourceMap::iterator iter
= unsafe_resource_map
->find(web_contents());
356 SafeBrowsingBlockingPage
* blocking_page
= NULL
;
357 if (iter
!= unsafe_resource_map
->end() && !iter
->second
.empty()) {
358 // Build an interstitial for all the unsafe resources notifications.
359 // Don't show it now as showing an interstitial while an interstitial is
360 // already showing would cause DontProceed() to be invoked.
361 blocking_page
= factory_
->CreateSafeBrowsingPage(ui_manager_
,
364 unsafe_resource_map
->erase(iter
);
367 // Now that this interstitial is gone, we can show the new one.
369 blocking_page
->Show();
372 content::InterstitialPageDelegate::TypeID
373 SafeBrowsingBlockingPage::GetTypeForTesting() const {
374 return SafeBrowsingBlockingPage::kTypeForTesting
;
377 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const {
378 return is_main_frame_load_blocked_
;
381 void SafeBrowsingBlockingPage::OnDontProceed() {
382 // We could have already called Proceed(), in which case we must not notify
383 // the SafeBrowsingUIManager again, as the client has been deleted.
387 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled
)) {
388 metrics_helper()->RecordUserDecision(
389 security_interstitials::MetricsHelper::DONT_PROCEED
);
392 // Send the malware details, if we opted to.
393 FinishMalwareDetails(0); // No delay
395 NotifySafeBrowsingUIManager(ui_manager_
, unsafe_resources_
, false);
397 // The user does not want to proceed, clear the queued unsafe resources
398 // notifications we received while the interstitial was showing.
399 UnsafeResourceMap
* unsafe_resource_map
= GetUnsafeResourcesMap();
400 UnsafeResourceMap::iterator iter
= unsafe_resource_map
->find(web_contents());
401 if (iter
!= unsafe_resource_map
->end() && !iter
->second
.empty()) {
402 NotifySafeBrowsingUIManager(ui_manager_
, iter
->second
, false);
403 unsafe_resource_map
->erase(iter
);
406 // We don't remove the navigation entry if the tab is being destroyed as this
407 // would trigger a navigation that would cause trouble as the render view host
408 // for the tab has by then already been destroyed. We also don't delete the
409 // current entry if it has been committed again, which is possible on a page
410 // that had a subresource warning.
411 int last_committed_index
=
412 web_contents()->GetController().GetLastCommittedEntryIndex();
413 if (navigation_entry_index_to_remove_
!= -1 &&
414 navigation_entry_index_to_remove_
!= last_committed_index
&&
415 !web_contents()->IsBeingDestroyed()) {
416 CHECK(web_contents()->GetController().RemoveEntryAtIndex(
417 navigation_entry_index_to_remove_
));
418 navigation_entry_index_to_remove_
= -1;
422 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms
) {
423 if (malware_details_
.get() == NULL
)
424 return; // Not all interstitials have malware details (eg phishing).
425 DCHECK_EQ(interstitial_reason_
, SB_REASON_MALWARE
);
428 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled
) &&
429 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingOptInAllowed
);
433 metrics_helper()->RecordUserInteraction(
434 security_interstitials::MetricsHelper::EXTENDED_REPORTING_IS_ENABLED
);
435 // Finish the malware details collection, send it over.
436 BrowserThread::PostDelayedTask(
437 BrowserThread::IO
, FROM_HERE
,
438 base::Bind(&MalwareDetails::FinishCollection
, malware_details_
.get()),
439 base::TimeDelta::FromMilliseconds(delay_ms
));
443 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager(
444 SafeBrowsingUIManager
* ui_manager
,
445 const UnsafeResourceList
& unsafe_resources
,
447 BrowserThread::PostTask(
448 BrowserThread::IO
, FROM_HERE
,
449 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone
,
450 ui_manager
, unsafe_resources
, proceed
));
454 SafeBrowsingBlockingPage::UnsafeResourceMap
*
455 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() {
456 return g_unsafe_resource_map
.Pointer();
460 SafeBrowsingBlockingPage
* SafeBrowsingBlockingPage::CreateBlockingPage(
461 SafeBrowsingUIManager
* ui_manager
,
462 WebContents
* web_contents
,
463 const UnsafeResource
& unsafe_resource
) {
464 std::vector
<UnsafeResource
> resources
;
465 resources
.push_back(unsafe_resource
);
466 // Set up the factory if this has not been done already (tests do that
467 // before this method is called).
469 factory_
= g_safe_browsing_blocking_page_factory_impl
.Pointer();
470 return factory_
->CreateSafeBrowsingPage(ui_manager
, web_contents
, resources
);
474 void SafeBrowsingBlockingPage::ShowBlockingPage(
475 SafeBrowsingUIManager
* ui_manager
,
476 const UnsafeResource
& unsafe_resource
) {
477 DVLOG(1) << __FUNCTION__
<< " " << unsafe_resource
.url
.spec();
478 WebContents
* web_contents
= tab_util::GetWebContentsByID(
479 unsafe_resource
.render_process_host_id
, unsafe_resource
.render_view_id
);
481 InterstitialPage
* interstitial
=
482 InterstitialPage::GetInterstitialPage(web_contents
);
483 if (interstitial
&& !unsafe_resource
.is_subresource
) {
484 // There is already an interstitial showing and we are about to display a
485 // new one for the main frame. Just hide the current one, it is now
487 interstitial
->DontProceed();
492 // There are no interstitial currently showing in that tab, go ahead and
493 // show this interstitial.
494 SafeBrowsingBlockingPage
* blocking_page
=
495 CreateBlockingPage(ui_manager
, web_contents
, unsafe_resource
);
496 blocking_page
->Show();
500 // This is an interstitial for a page's resource, let's queue it.
501 UnsafeResourceMap
* unsafe_resource_map
= GetUnsafeResourcesMap();
502 (*unsafe_resource_map
)[web_contents
].push_back(unsafe_resource
);
506 bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked(
507 const UnsafeResourceList
& unsafe_resources
) {
508 // Client-side phishing detection interstitials never block the main frame
509 // load, since they happen after the page is finished loading.
510 if (unsafe_resources
[0].threat_type
==
511 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL
) {
515 // Otherwise, check the threat type.
516 return unsafe_resources
.size() == 1 && !unsafe_resources
[0].is_subresource
;
519 std::string
SafeBrowsingBlockingPage::GetMetricPrefix() const {
520 bool primary_subresource
= unsafe_resources_
[0].is_subresource
;
521 switch (interstitial_reason_
) {
522 case SB_REASON_MALWARE
:
523 return primary_subresource
? "malware_subresource" : "malware";
524 case SB_REASON_HARMFUL
:
525 return primary_subresource
? "harmful_subresource" : "harmful";
526 case SB_REASON_PHISHING
:
527 return primary_subresource
? "phishing_subresource" : "phishing";
530 return std::string();
533 std::string
SafeBrowsingBlockingPage::GetRapporPrefix() const {
534 switch (interstitial_reason_
) {
535 case SB_REASON_MALWARE
:
537 case SB_REASON_HARMFUL
:
539 case SB_REASON_PHISHING
:
543 return std::string();
546 std::string
SafeBrowsingBlockingPage::GetSamplingEventName() const {
547 switch (interstitial_reason_
) {
548 case SB_REASON_MALWARE
:
549 return kEventNameMalware
;
550 case SB_REASON_HARMFUL
:
551 return kEventNameHarmful
;
552 case SB_REASON_PHISHING
:
553 return kEventNamePhishing
;
555 return kEventNameOther
;
559 void SafeBrowsingBlockingPage::PopulateInterstitialStrings(
560 base::DictionaryValue
* load_time_data
) {
561 CHECK(load_time_data
);
562 CHECK(!unsafe_resources_
.empty());
564 load_time_data
->SetString("type", "SAFEBROWSING");
565 load_time_data
->SetString(
566 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE
));
567 load_time_data
->SetString(
569 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON
));
570 load_time_data
->SetString(
572 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON
));
573 load_time_data
->SetString(
575 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON
));
576 load_time_data
->SetBoolean(
578 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled
));
580 switch (interstitial_reason_
) {
581 case SB_REASON_MALWARE
:
582 PopulateMalwareLoadTimeData(load_time_data
);
584 case SB_REASON_HARMFUL
:
585 PopulateHarmfulLoadTimeData(load_time_data
);
587 case SB_REASON_PHISHING
:
588 PopulatePhishingLoadTimeData(load_time_data
);
593 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption(
594 base::DictionaryValue
* load_time_data
) {
595 // Only show checkbox if !(HTTPS || incognito-mode).
596 const bool show
= CanShowMalwareDetailsOption();
597 load_time_data
->SetBoolean(interstitials::kDisplayCheckBox
, show
);
601 const std::string privacy_link
= base::StringPrintf(
602 interstitials::kPrivacyLinkHtml
, CMD_OPEN_REPORTING_PRIVACY
,
603 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE
).c_str());
604 load_time_data
->SetString(
605 interstitials::kOptInLink
,
606 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE
,
607 base::UTF8ToUTF16(privacy_link
)));
608 load_time_data
->SetBoolean(
609 interstitials::kBoxChecked
,
610 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled
));
613 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData(
614 base::DictionaryValue
* load_time_data
) {
615 load_time_data
->SetBoolean("phishing", false);
616 load_time_data
->SetString(
617 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING
));
618 load_time_data
->SetString(
620 l10n_util::GetStringFUTF16(
621 IDS_MALWARE_V3_PRIMARY_PARAGRAPH
,
622 GetFormattedHostName()));
623 load_time_data
->SetString(
624 "explanationParagraph",
625 is_main_frame_load_blocked_
?
626 l10n_util::GetStringFUTF16(
627 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH
,
628 GetFormattedHostName()) :
629 l10n_util::GetStringFUTF16(
630 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE
,
631 base::UTF8ToUTF16(web_contents()->GetURL().host()),
632 GetFormattedHostName()));
633 load_time_data
->SetString(
635 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH
));
637 PopulateExtendedReportingOption(load_time_data
);
640 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData(
641 base::DictionaryValue
* load_time_data
) {
642 load_time_data
->SetBoolean("phishing", false);
643 load_time_data
->SetString(
644 "heading", l10n_util::GetStringUTF16(IDS_HARMFUL_V3_HEADING
));
645 load_time_data
->SetString(
647 l10n_util::GetStringFUTF16(
648 IDS_HARMFUL_V3_PRIMARY_PARAGRAPH
,
649 GetFormattedHostName()));
650 load_time_data
->SetString(
651 "explanationParagraph",
652 l10n_util::GetStringFUTF16(
653 IDS_HARMFUL_V3_EXPLANATION_PARAGRAPH
,
654 GetFormattedHostName()));
655 load_time_data
->SetString(
657 l10n_util::GetStringUTF16(IDS_HARMFUL_V3_PROCEED_PARAGRAPH
));
659 PopulateExtendedReportingOption(load_time_data
);
662 void SafeBrowsingBlockingPage::PopulatePhishingLoadTimeData(
663 base::DictionaryValue
* load_time_data
) {
664 bool use_social_engineering_strings
=
665 base::FieldTrialList::FindFullName(kSocialEngineeringTrial
) ==
666 kSocialEngineeringEnabled
;
667 load_time_data
->SetBoolean("phishing", true);
668 load_time_data
->SetString(
669 "heading", l10n_util::GetStringUTF16(use_social_engineering_strings
670 ? IDS_PHISHING_V4_HEADING
671 : IDS_PHISHING_V3_HEADING
));
672 load_time_data
->SetString(
674 l10n_util::GetStringFUTF16(use_social_engineering_strings
675 ? IDS_PHISHING_V4_PRIMARY_PARAGRAPH
676 : IDS_PHISHING_V3_PRIMARY_PARAGRAPH
,
677 GetFormattedHostName()));
678 load_time_data
->SetString(
679 "explanationParagraph",
680 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH
,
681 GetFormattedHostName()));
683 if (base::FieldTrialList::FindFullName(kReportPhishingErrorTrial
) ==
684 kReportPhishingErrorEnabled
) {
685 load_time_data
->SetString(
686 "finalParagraph", l10n_util::GetStringUTF16(
687 IDS_PHISHING_V4_PROCEED_AND_REPORT_PARAGRAPH
));
689 load_time_data
->SetString(
691 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH
));
694 PopulateExtendedReportingOption(load_time_data
);