Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / safe_browsing_blocking_page.cc
blobb6f527601585760c266171ebf1acba2905e39700
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 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&client=googlechrome";
60 #else
61 const char kSbDiagnosticUrl[] =
62 "http://safebrowsing.clients.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 // After a malware interstitial where the user opted-in to the report
72 // but clicked "proceed anyway", we delay the call to
73 // MalwareDetails::FinishCollection() by this much time (in
74 // milliseconds).
75 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000;
77 // Constants for the Experience Sampling instrumentation.
78 const char kEventNameMalware[] = "safebrowsing_interstitial_";
79 const char kEventNameHarmful[] = "harmful_interstitial_";
80 const char kEventNamePhishing[] = "phishing_interstitial_";
81 const char kEventNameOther[] = "safebrowsing_other_interstitial_";
83 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap>
84 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER;
86 } // namespace
88 // static
89 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL;
91 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we
92 // don't leak it.
93 class SafeBrowsingBlockingPageFactoryImpl
94 : public SafeBrowsingBlockingPageFactory {
95 public:
96 SafeBrowsingBlockingPage* CreateSafeBrowsingPage(
97 SafeBrowsingUIManager* ui_manager,
98 WebContents* web_contents,
99 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources)
100 override {
101 return new SafeBrowsingBlockingPage(ui_manager, web_contents,
102 unsafe_resources);
105 private:
106 friend struct base::DefaultLazyInstanceTraits<
107 SafeBrowsingBlockingPageFactoryImpl>;
109 SafeBrowsingBlockingPageFactoryImpl() { }
111 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl);
114 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl>
115 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER;
117 // static
118 content::InterstitialPageDelegate::TypeID
119 SafeBrowsingBlockingPage::kTypeForTesting =
120 &SafeBrowsingBlockingPage::kTypeForTesting;
122 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
123 SafeBrowsingUIManager* ui_manager,
124 WebContents* web_contents,
125 const UnsafeResourceList& unsafe_resources)
126 : SecurityInterstitialPage(web_contents, unsafe_resources[0].url),
127 malware_details_proceed_delay_ms_(
128 kMalwareDetailsProceedDelayMilliSeconds),
129 ui_manager_(ui_manager),
130 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)),
131 unsafe_resources_(unsafe_resources),
132 proceeded_(false) {
133 bool malware = false;
134 bool harmful = false;
135 bool phishing = false;
136 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin();
137 iter != unsafe_resources_.end(); ++iter) {
138 const UnsafeResource& resource = *iter;
139 SBThreatType threat_type = resource.threat_type;
140 if (threat_type == SB_THREAT_TYPE_URL_MALWARE ||
141 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) {
142 malware = true;
143 } else if (threat_type == SB_THREAT_TYPE_URL_UNWANTED) {
144 harmful = true;
145 } else {
146 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING ||
147 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL);
148 phishing = true;
151 DCHECK(phishing || malware || harmful);
152 if (malware)
153 interstitial_reason_ = SB_REASON_MALWARE;
154 else if (harmful)
155 interstitial_reason_ = SB_REASON_HARMFUL;
156 else
157 interstitial_reason_ = SB_REASON_PHISHING;
159 // This must be done after calculating |interstitial_reason_| above.
160 // Use same prefix for UMA as for Rappor.
161 set_metrics_helper(new SecurityInterstitialMetricsHelper(
162 web_contents, request_url(), GetMetricPrefix(), GetMetricPrefix(),
163 SecurityInterstitialMetricsHelper::REPORT_RAPPOR,
164 GetSamplingEventName()));
165 metrics_helper()->RecordUserDecision(SecurityInterstitialMetricsHelper::SHOW);
166 metrics_helper()->RecordUserInteraction(
167 SecurityInterstitialMetricsHelper::TOTAL_VISITS);
168 if (IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
169 metrics_helper()->RecordUserDecision(
170 SecurityInterstitialMetricsHelper::PROCEEDING_DISABLED);
173 if (!is_main_frame_load_blocked_) {
174 navigation_entry_index_to_remove_ =
175 web_contents->GetController().GetLastCommittedEntryIndex();
176 } else {
177 navigation_entry_index_to_remove_ = -1;
180 // Start computing malware details. They will be sent only
181 // if the user opts-in on the blocking page later.
182 // If there's more than one malicious resources, it means the user
183 // clicked through the first warning, so we don't prepare additional
184 // reports.
185 if (unsafe_resources.size() == 1 &&
186 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE &&
187 malware_details_.get() == NULL && CanShowMalwareDetailsOption()) {
188 malware_details_ = MalwareDetails::NewMalwareDetails(
189 ui_manager_, web_contents, unsafe_resources[0]);
193 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() {
194 return (!web_contents()->GetBrowserContext()->IsOffTheRecord() &&
195 web_contents()->GetURL().SchemeIs(url::kHttpScheme));
198 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
201 void SafeBrowsingBlockingPage::CommandReceived(const std::string& page_cmd) {
202 if (page_cmd == "\"pageLoadComplete\"") {
203 // content::WaitForRenderFrameReady sends this message when the page
204 // load completes. Ignore it.
205 return;
208 int command = 0;
209 bool retval = base::StringToInt(page_cmd, &command);
210 DCHECK(retval) << page_cmd;
212 switch (command) {
213 case CMD_DO_REPORT: {
214 // User enabled SB Extended Reporting via the checkbox.
215 SetReportingPreference(true);
216 break;
218 case CMD_DONT_REPORT: {
219 // User disabled SB Extended Reporting via the checkbox.
220 SetReportingPreference(false);
221 break;
223 case CMD_OPEN_HELP_CENTER: {
224 // User pressed "Learn more".
225 metrics_helper()->RecordUserInteraction(
226 SecurityInterstitialMetricsHelper::SHOW_LEARN_MORE);
227 GURL learn_more_url(
228 interstitial_reason_ == SB_REASON_PHISHING ?
229 kLearnMorePhishingUrlV2 : kLearnMoreMalwareUrlV2);
230 learn_more_url = google_util::AppendGoogleLocaleParam(
231 learn_more_url, g_browser_process->GetApplicationLocale());
232 OpenURLParams params(learn_more_url,
233 Referrer(),
234 CURRENT_TAB,
235 ui::PAGE_TRANSITION_LINK,
236 false);
237 web_contents()->OpenURL(params);
238 break;
240 case CMD_OPEN_REPORTING_PRIVACY: {
241 // User pressed on the SB Extended Reporting "privacy policy" link.
242 OpenExtendedReportingPrivacyPolicy();
243 break;
245 case CMD_PROCEED: {
246 // User pressed on the button to proceed.
247 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
248 metrics_helper()->RecordUserDecision(
249 SecurityInterstitialMetricsHelper::PROCEED);
250 interstitial_page()->Proceed();
251 // |this| has been deleted after Proceed() returns.
252 break;
254 // If the user can't proceed, fall through to CMD_DONT_PROCEED.
256 case CMD_DONT_PROCEED: {
257 // User pressed on the button to return to safety.
258 // Don't record the user action here because there are other ways of
259 // triggering DontProceed, like clicking the back button.
260 if (is_main_frame_load_blocked_) {
261 // If the load is blocked, we want to close the interstitial and discard
262 // the pending entry.
263 interstitial_page()->DontProceed();
264 // |this| has been deleted after DontProceed() returns.
265 break;
268 // Otherwise the offending entry has committed, and we need to go back or
269 // to a safe page. We will close the interstitial when that page commits.
270 if (web_contents()->GetController().CanGoBack()) {
271 web_contents()->GetController().GoBack();
272 } else {
273 web_contents()->GetController().LoadURL(
274 GURL(chrome::kChromeUINewTabURL),
275 content::Referrer(),
276 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
277 std::string());
279 break;
281 case CMD_OPEN_DIAGNOSTIC: {
282 // User wants to see why this page is blocked.
283 // TODO(felt): element_index will always be 0. See crbug.com/464732
284 size_t element_index = 0;
285 const UnsafeResource& unsafe_resource = unsafe_resources_[element_index];
286 std::string bad_url_spec = unsafe_resource.url.spec();
287 metrics_helper()->RecordUserInteraction(
288 SecurityInterstitialMetricsHelper::SHOW_DIAGNOSTIC);
289 std::string diagnostic =
290 base::StringPrintf(kSbDiagnosticUrl,
291 net::EscapeQueryParamValue(bad_url_spec, true).c_str());
292 GURL diagnostic_url(diagnostic);
293 diagnostic_url = google_util::AppendGoogleLocaleParam(
294 diagnostic_url, g_browser_process->GetApplicationLocale());
295 DCHECK(unsafe_resource.threat_type == SB_THREAT_TYPE_URL_MALWARE ||
296 unsafe_resource.threat_type ==
297 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL ||
298 unsafe_resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED);
299 OpenURLParams params(
300 diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK,
301 false);
302 web_contents()->OpenURL(params);
303 break;
305 case CMD_SHOW_MORE_SECTION: {
306 // User has opened up the hidden text.
307 metrics_helper()->RecordUserInteraction(
308 SecurityInterstitialMetricsHelper::SHOW_ADVANCED);
309 break;
314 void SafeBrowsingBlockingPage::OverrideRendererPrefs(
315 content::RendererPreferences* prefs) {
316 Profile* profile = Profile::FromBrowserContext(
317 web_contents()->GetBrowserContext());
318 renderer_preferences_util::UpdateFromSystemSettings(
319 prefs, profile, web_contents());
322 void SafeBrowsingBlockingPage::OnProceed() {
323 proceeded_ = true;
324 // Send the malware details, if we opted to.
325 FinishMalwareDetails(malware_details_proceed_delay_ms_);
327 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, true);
329 // Check to see if some new notifications of unsafe resources have been
330 // received while we were showing the interstitial.
331 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
332 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
333 SafeBrowsingBlockingPage* blocking_page = NULL;
334 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
335 // Build an interstitial for all the unsafe resources notifications.
336 // Don't show it now as showing an interstitial while an interstitial is
337 // already showing would cause DontProceed() to be invoked.
338 blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_,
339 web_contents(),
340 iter->second);
341 unsafe_resource_map->erase(iter);
344 // Now that this interstitial is gone, we can show the new one.
345 if (blocking_page)
346 blocking_page->Show();
349 content::InterstitialPageDelegate::TypeID
350 SafeBrowsingBlockingPage::GetTypeForTesting() const {
351 return SafeBrowsingBlockingPage::kTypeForTesting;
354 bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const {
355 return is_main_frame_load_blocked_;
358 void SafeBrowsingBlockingPage::OnDontProceed() {
359 // We could have already called Proceed(), in which case we must not notify
360 // the SafeBrowsingUIManager again, as the client has been deleted.
361 if (proceeded_)
362 return;
364 if (!IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)) {
365 metrics_helper()->RecordUserDecision(
366 SecurityInterstitialMetricsHelper::DONT_PROCEED);
369 // Send the malware details, if we opted to.
370 FinishMalwareDetails(0); // No delay
372 NotifySafeBrowsingUIManager(ui_manager_, unsafe_resources_, false);
374 // The user does not want to proceed, clear the queued unsafe resources
375 // notifications we received while the interstitial was showing.
376 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
377 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
378 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
379 NotifySafeBrowsingUIManager(ui_manager_, iter->second, false);
380 unsafe_resource_map->erase(iter);
383 // We don't remove the navigation entry if the tab is being destroyed as this
384 // would trigger a navigation that would cause trouble as the render view host
385 // for the tab has by then already been destroyed. We also don't delete the
386 // current entry if it has been committed again, which is possible on a page
387 // that had a subresource warning.
388 int last_committed_index =
389 web_contents()->GetController().GetLastCommittedEntryIndex();
390 if (navigation_entry_index_to_remove_ != -1 &&
391 navigation_entry_index_to_remove_ != last_committed_index &&
392 !web_contents()->IsBeingDestroyed()) {
393 CHECK(web_contents()->GetController().RemoveEntryAtIndex(
394 navigation_entry_index_to_remove_));
395 navigation_entry_index_to_remove_ = -1;
399 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) {
400 if (malware_details_.get() == NULL)
401 return; // Not all interstitials have malware details (eg phishing).
402 DCHECK_EQ(interstitial_reason_, SB_REASON_MALWARE);
404 const bool enabled =
405 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled);
406 if (!enabled)
407 return;
409 metrics_helper()->RecordUserInteraction(
410 SecurityInterstitialMetricsHelper::EXTENDED_REPORTING_IS_ENABLED);
411 // Finish the malware details collection, send it over.
412 BrowserThread::PostDelayedTask(
413 BrowserThread::IO, FROM_HERE,
414 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()),
415 base::TimeDelta::FromMilliseconds(delay_ms));
418 // static
419 void SafeBrowsingBlockingPage::NotifySafeBrowsingUIManager(
420 SafeBrowsingUIManager* ui_manager,
421 const UnsafeResourceList& unsafe_resources,
422 bool proceed) {
423 BrowserThread::PostTask(
424 BrowserThread::IO, FROM_HERE,
425 base::Bind(&SafeBrowsingUIManager::OnBlockingPageDone,
426 ui_manager, unsafe_resources, proceed));
429 // static
430 SafeBrowsingBlockingPage::UnsafeResourceMap*
431 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() {
432 return g_unsafe_resource_map.Pointer();
435 // static
436 SafeBrowsingBlockingPage* SafeBrowsingBlockingPage::CreateBlockingPage(
437 SafeBrowsingUIManager* ui_manager,
438 WebContents* web_contents,
439 const UnsafeResource& unsafe_resource) {
440 std::vector<UnsafeResource> resources;
441 resources.push_back(unsafe_resource);
442 // Set up the factory if this has not been done already (tests do that
443 // before this method is called).
444 if (!factory_)
445 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer();
446 return factory_->CreateSafeBrowsingPage(ui_manager, web_contents, resources);
449 // static
450 void SafeBrowsingBlockingPage::ShowBlockingPage(
451 SafeBrowsingUIManager* ui_manager,
452 const UnsafeResource& unsafe_resource) {
453 DVLOG(1) << __FUNCTION__ << " " << unsafe_resource.url.spec();
454 WebContents* web_contents = tab_util::GetWebContentsByID(
455 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id);
457 InterstitialPage* interstitial =
458 InterstitialPage::GetInterstitialPage(web_contents);
459 if (interstitial && !unsafe_resource.is_subresource) {
460 // There is already an interstitial showing and we are about to display a
461 // new one for the main frame. Just hide the current one, it is now
462 // irrelevent
463 interstitial->DontProceed();
464 interstitial = NULL;
467 if (!interstitial) {
468 // There are no interstitial currently showing in that tab, go ahead and
469 // show this interstitial.
470 SafeBrowsingBlockingPage* blocking_page =
471 CreateBlockingPage(ui_manager, web_contents, unsafe_resource);
472 blocking_page->Show();
473 return;
476 // This is an interstitial for a page's resource, let's queue it.
477 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
478 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource);
481 // static
482 bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked(
483 const UnsafeResourceList& unsafe_resources) {
484 // Client-side phishing detection interstitials never block the main frame
485 // load, since they happen after the page is finished loading.
486 if (unsafe_resources[0].threat_type ==
487 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL) {
488 return false;
491 // Otherwise, check the threat type.
492 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource;
495 std::string SafeBrowsingBlockingPage::GetMetricPrefix() const {
496 switch (interstitial_reason_) {
497 case SB_REASON_MALWARE:
498 return "malware";
499 case SB_REASON_HARMFUL:
500 return "harmful";
501 case SB_REASON_PHISHING:
502 return "phishing";
504 NOTREACHED();
505 return std::string();
508 std::string SafeBrowsingBlockingPage::GetSamplingEventName() const {
509 switch (interstitial_reason_) {
510 case SB_REASON_MALWARE:
511 return kEventNameMalware;
512 case SB_REASON_HARMFUL:
513 return kEventNameHarmful;
514 case SB_REASON_PHISHING:
515 return kEventNamePhishing;
516 default:
517 return kEventNameOther;
521 void SafeBrowsingBlockingPage::PopulateInterstitialStrings(
522 base::DictionaryValue* load_time_data) {
523 CHECK(load_time_data);
524 CHECK(!unsafe_resources_.empty());
526 load_time_data->SetString("type", "SAFEBROWSING");
527 load_time_data->SetString(
528 "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE));
529 load_time_data->SetString(
530 "openDetails",
531 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON));
532 load_time_data->SetString(
533 "closeDetails",
534 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON));
535 load_time_data->SetString(
536 "primaryButtonText",
537 l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON));
538 load_time_data->SetBoolean(
539 "overridable",
540 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled));
542 switch (interstitial_reason_) {
543 case SB_REASON_MALWARE:
544 PopulateMalwareLoadTimeData(load_time_data);
545 break;
546 case SB_REASON_HARMFUL:
547 PopulateHarmfulLoadTimeData(load_time_data);
548 break;
549 case SB_REASON_PHISHING:
550 PopulatePhishingLoadTimeData(load_time_data);
551 break;
555 void SafeBrowsingBlockingPage::PopulateExtendedReportingOption(
556 base::DictionaryValue* load_time_data) {
557 // Only show checkbox if !(HTTPS || incognito-mode).
558 const bool show = CanShowMalwareDetailsOption();
559 load_time_data->SetBoolean(interstitials::kDisplayCheckBox, show);
560 if (!show)
561 return;
563 const std::string privacy_link = base::StringPrintf(
564 interstitials::kPrivacyLinkHtml, CMD_OPEN_REPORTING_PRIVACY,
565 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str());
566 load_time_data->SetString(
567 interstitials::kOptInLink,
568 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE,
569 base::UTF8ToUTF16(privacy_link)));
570 load_time_data->SetBoolean(
571 interstitials::kBoxChecked,
572 IsPrefEnabled(prefs::kSafeBrowsingExtendedReportingEnabled));
575 void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData(
576 base::DictionaryValue* load_time_data) {
577 load_time_data->SetBoolean("phishing", false);
578 load_time_data->SetString(
579 "heading", l10n_util::GetStringUTF16(IDS_MALWARE_V3_HEADING));
580 load_time_data->SetString(
581 "primaryParagraph",
582 l10n_util::GetStringFUTF16(
583 IDS_MALWARE_V3_PRIMARY_PARAGRAPH,
584 GetFormattedHostName()));
585 load_time_data->SetString(
586 "explanationParagraph",
587 is_main_frame_load_blocked_ ?
588 l10n_util::GetStringFUTF16(
589 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH,
590 GetFormattedHostName()) :
591 l10n_util::GetStringFUTF16(
592 IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE,
593 base::UTF8ToUTF16(web_contents()->GetURL().host()),
594 GetFormattedHostName()));
595 load_time_data->SetString(
596 "finalParagraph",
597 l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH));
599 PopulateExtendedReportingOption(load_time_data);
602 void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData(
603 base::DictionaryValue* load_time_data) {
604 load_time_data->SetBoolean("phishing", false);
605 load_time_data->SetString(
606 "heading", l10n_util::GetStringUTF16(IDS_HARMFUL_V3_HEADING));
607 load_time_data->SetString(
608 "primaryParagraph",
609 l10n_util::GetStringFUTF16(
610 IDS_HARMFUL_V3_PRIMARY_PARAGRAPH,
611 GetFormattedHostName()));
612 load_time_data->SetString(
613 "explanationParagraph",
614 l10n_util::GetStringFUTF16(
615 IDS_HARMFUL_V3_EXPLANATION_PARAGRAPH,
616 GetFormattedHostName()));
617 load_time_data->SetString(
618 "finalParagraph",
619 l10n_util::GetStringUTF16(IDS_HARMFUL_V3_PROCEED_PARAGRAPH));
621 PopulateExtendedReportingOption(load_time_data);
624 void SafeBrowsingBlockingPage::PopulatePhishingLoadTimeData(
625 base::DictionaryValue* load_time_data) {
626 load_time_data->SetBoolean("phishing", true);
627 load_time_data->SetString(
628 "heading",
629 l10n_util::GetStringUTF16(IDS_PHISHING_V3_HEADING));
630 load_time_data->SetString(
631 "primaryParagraph",
632 l10n_util::GetStringFUTF16(
633 IDS_PHISHING_V3_PRIMARY_PARAGRAPH,
634 GetFormattedHostName()));
635 load_time_data->SetString(
636 "explanationParagraph",
637 l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH,
638 GetFormattedHostName()));
639 load_time_data->SetString(
640 "finalParagraph",
641 l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
643 PopulateExtendedReportingOption(load_time_data);