| Index: chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
|
| diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
|
| index 172ca09c8b385f63b9bd495b1b1d50bbf7b72f52..d8bae10b93fef5caecb4d5a2415d827b939577b2 100644
|
| --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
|
| +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc
|
| @@ -42,9 +42,6 @@
|
| #include "grit/browser_resources.h"
|
| #include "net/base/escape.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| -#include "ui/base/resource/resource_bundle.h"
|
| -#include "ui/base/webui/jstemplate_builder.h"
|
| -#include "ui/base/webui/web_ui_util.h"
|
|
|
| #if defined(ENABLE_EXTENSIONS)
|
| #include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h"
|
| @@ -149,17 +146,14 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
|
| SafeBrowsingUIManager* ui_manager,
|
| WebContents* web_contents,
|
| const UnsafeResourceList& unsafe_resources)
|
| - : malware_details_proceed_delay_ms_(
|
| + : SecurityInterstitialPage(web_contents, unsafe_resources[0].url),
|
| + malware_details_proceed_delay_ms_(
|
| kMalwareDetailsProceedDelayMilliSeconds),
|
| ui_manager_(ui_manager),
|
| report_loop_(NULL),
|
| is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)),
|
| unsafe_resources_(unsafe_resources),
|
| proceeded_(false),
|
| - web_contents_(web_contents),
|
| - url_(unsafe_resources[0].url),
|
| - interstitial_page_(NULL),
|
| - create_view_(true),
|
| num_visits_(-1) {
|
| bool malware = false;
|
| bool harmful = false;
|
| @@ -197,7 +191,7 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
|
| Profile::EXPLICIT_ACCESS);
|
| if (history_service) {
|
| history_service->GetVisibleVisitCountToHost(
|
| - url_,
|
| + request_url(),
|
| base::Bind(&SafeBrowsingBlockingPage::OnGotHistoryCount,
|
| base::Unretained(this)),
|
| &request_tracker_);
|
| @@ -242,18 +236,15 @@ SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
|
| }
|
| sampling_event_.reset(new ExperienceSamplingEvent(
|
| event_name,
|
| - url_,
|
| - web_contents_->GetLastCommittedURL(),
|
| - web_contents_->GetBrowserContext()));
|
| + request_url(),
|
| + web_contents->GetLastCommittedURL(),
|
| + web_contents->GetBrowserContext()));
|
| #endif
|
| -
|
| - // Creating interstitial_page_ without showing it leaks memory, so don't
|
| - // create it here.
|
| }
|
|
|
| bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() {
|
| - return (!web_contents_->GetBrowserContext()->IsOffTheRecord() &&
|
| - web_contents_->GetURL().SchemeIs(url::kHttpScheme));
|
| + return (!web_contents()->GetBrowserContext()->IsOffTheRecord() &&
|
| + web_contents()->GetURL().SchemeIs(url::kHttpScheme));
|
| }
|
|
|
| SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
|
| @@ -287,7 +278,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
|
| CURRENT_TAB,
|
| ui::PAGE_TRANSITION_LINK,
|
| false);
|
| - web_contents_->OpenURL(params);
|
| + web_contents()->OpenURL(params);
|
| return;
|
| }
|
|
|
| @@ -303,7 +294,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
|
| CURRENT_TAB,
|
| ui::PAGE_TRANSITION_LINK,
|
| false);
|
| - web_contents_->OpenURL(params);
|
| + web_contents()->OpenURL(params);
|
| return;
|
| }
|
|
|
| @@ -313,7 +304,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
|
| proceed_blocked = true;
|
| } else {
|
| RecordUserDecision(PROCEED);
|
| - interstitial_page_->Proceed();
|
| + interstitial_page()->Proceed();
|
| // |this| has been deleted after Proceed() returns.
|
| return;
|
| }
|
| @@ -325,17 +316,17 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
|
| if (is_main_frame_load_blocked_) {
|
| // If the load is blocked, we want to close the interstitial and discard
|
| // the pending entry.
|
| - interstitial_page_->DontProceed();
|
| + interstitial_page()->DontProceed();
|
| // |this| has been deleted after DontProceed() returns.
|
| return;
|
| }
|
|
|
| // Otherwise the offending entry has committed, and we need to go back or
|
| // to a safe page. We will close the interstitial when that page commits.
|
| - if (web_contents_->GetController().CanGoBack()) {
|
| - web_contents_->GetController().GoBack();
|
| + if (web_contents()->GetController().CanGoBack()) {
|
| + web_contents()->GetController().GoBack();
|
| } else {
|
| - web_contents_->GetController().LoadURL(
|
| + web_contents()->GetController().LoadURL(
|
| GURL(chrome::kChromeUINewTabURL),
|
| content::Referrer(),
|
| ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
| @@ -382,7 +373,7 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
|
| OpenURLParams params(
|
| diagnostic_url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK,
|
| false);
|
| - web_contents_->OpenURL(params);
|
| + web_contents()->OpenURL(params);
|
| return;
|
| }
|
|
|
| @@ -397,13 +388,13 @@ void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
|
| void SafeBrowsingBlockingPage::OverrideRendererPrefs(
|
| content::RendererPreferences* prefs) {
|
| Profile* profile = Profile::FromBrowserContext(
|
| - web_contents_->GetBrowserContext());
|
| + web_contents()->GetBrowserContext());
|
| renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
|
| }
|
|
|
| void SafeBrowsingBlockingPage::SetReportingPreference(bool report) {
|
| Profile* profile = Profile::FromBrowserContext(
|
| - web_contents_->GetBrowserContext());
|
| + web_contents()->GetBrowserContext());
|
| PrefService* pref = profile->GetPrefs();
|
| pref->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, report);
|
| UMA_HISTOGRAM_BOOLEAN("SB2.SetExtendedReportingEnabled", report);
|
| @@ -419,13 +410,14 @@ void SafeBrowsingBlockingPage::OnProceed() {
|
| // Check to see if some new notifications of unsafe resources have been
|
| // received while we were showing the interstitial.
|
| UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
|
| - UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_);
|
| + UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
|
| SafeBrowsingBlockingPage* blocking_page = NULL;
|
| if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
|
| // Build an interstitial for all the unsafe resources notifications.
|
| // Don't show it now as showing an interstitial while an interstitial is
|
| // already showing would cause DontProceed() to be invoked.
|
| - blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_, web_contents_,
|
| + blocking_page = factory_->CreateSafeBrowsingPage(ui_manager_,
|
| + web_contents(),
|
| iter->second);
|
| unsafe_resource_map->erase(iter);
|
| }
|
| @@ -435,17 +427,13 @@ void SafeBrowsingBlockingPage::OnProceed() {
|
| blocking_page->Show();
|
| }
|
|
|
| -void SafeBrowsingBlockingPage::DontCreateViewForTesting() {
|
| - create_view_ = false;
|
| +SecurityInterstitialPage::Type SafeBrowsingBlockingPage::GetTypeForTesting()
|
| + const {
|
| + return SecurityInterstitialPage::SAFEBROWSING;
|
| }
|
|
|
| -void SafeBrowsingBlockingPage::Show() {
|
| - DCHECK(!interstitial_page_);
|
| - interstitial_page_ = InterstitialPage::Create(
|
| - web_contents_, is_main_frame_load_blocked_, url_, this);
|
| - if (!create_view_)
|
| - interstitial_page_->DontCreateViewForTesting();
|
| - interstitial_page_->Show();
|
| +bool SafeBrowsingBlockingPage::ShouldCreateNewNavigation() const {
|
| + return is_main_frame_load_blocked_;
|
| }
|
|
|
| void SafeBrowsingBlockingPage::OnDontProceed() {
|
| @@ -465,7 +453,7 @@ void SafeBrowsingBlockingPage::OnDontProceed() {
|
| // The user does not want to proceed, clear the queued unsafe resources
|
| // notifications we received while the interstitial was showing.
|
| UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
|
| - UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_);
|
| + UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents());
|
| if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
|
| NotifySafeBrowsingUIManager(ui_manager_, iter->second, false);
|
| unsafe_resource_map->erase(iter);
|
| @@ -477,11 +465,11 @@ void SafeBrowsingBlockingPage::OnDontProceed() {
|
| // current entry if it has been committed again, which is possible on a page
|
| // that had a subresource warning.
|
| int last_committed_index =
|
| - web_contents_->GetController().GetLastCommittedEntryIndex();
|
| + web_contents()->GetController().GetLastCommittedEntryIndex();
|
| if (navigation_entry_index_to_remove_ != -1 &&
|
| navigation_entry_index_to_remove_ != last_committed_index &&
|
| - !web_contents_->IsBeingDestroyed()) {
|
| - CHECK(web_contents_->GetController().RemoveEntryAtIndex(
|
| + !web_contents()->IsBeingDestroyed()) {
|
| + CHECK(web_contents()->GetController().RemoveEntryAtIndex(
|
| navigation_entry_index_to_remove_));
|
| navigation_entry_index_to_remove_ = -1;
|
| }
|
| @@ -602,7 +590,7 @@ void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) {
|
|
|
| bool SafeBrowsingBlockingPage::IsPrefEnabled(const char* pref) {
|
| Profile* profile =
|
| - Profile::FromBrowserContext(web_contents_->GetBrowserContext());
|
| + Profile::FromBrowserContext(web_contents()->GetBrowserContext());
|
| return profile->GetPrefs()->GetBoolean(pref);
|
| }
|
|
|
| @@ -683,44 +671,38 @@ bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked(
|
| return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource;
|
| }
|
|
|
| -std::string SafeBrowsingBlockingPage::GetHTMLContents() {
|
| - DCHECK(!unsafe_resources_.empty());
|
| +void SafeBrowsingBlockingPage::PopulateLoadTimeData(
|
| + base::DictionaryValue* load_time_data) {
|
| + CHECK(load_time_data);
|
| + CHECK(!unsafe_resources_.empty());
|
|
|
| - // Fill in the shared values.
|
| - base::DictionaryValue load_time_data;
|
| - webui::SetFontAndTextDirection(&load_time_data);
|
| - load_time_data.SetString("type", "SAFEBROWSING");
|
| - load_time_data.SetString(
|
| + load_time_data->SetString("type", "SAFEBROWSING");
|
| + load_time_data->SetString(
|
| "tabTitle", l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_TITLE));
|
| - load_time_data.SetString(
|
| + load_time_data->SetString(
|
| "openDetails",
|
| l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_OPEN_DETAILS_BUTTON));
|
| - load_time_data.SetString(
|
| + load_time_data->SetString(
|
| "closeDetails",
|
| l10n_util::GetStringUTF16(IDS_SAFEBROWSING_V3_CLOSE_DETAILS_BUTTON));
|
| - load_time_data.SetString(
|
| + load_time_data->SetString(
|
| "primaryButtonText",
|
| l10n_util::GetStringUTF16(IDS_SAFEBROWSING_OVERRIDABLE_SAFETY_BUTTON));
|
| - load_time_data.SetBoolean(
|
| + load_time_data->SetBoolean(
|
| "overridable",
|
| !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled));
|
|
|
| switch (interstitial_type_) {
|
| case TYPE_MALWARE:
|
| - PopulateMalwareLoadTimeData(&load_time_data);
|
| + PopulateMalwareLoadTimeData(load_time_data);
|
| break;
|
| case TYPE_HARMFUL:
|
| - PopulateHarmfulLoadTimeData(&load_time_data);
|
| + PopulateHarmfulLoadTimeData(load_time_data);
|
| break;
|
| case TYPE_PHISHING:
|
| - PopulatePhishingLoadTimeData(&load_time_data);
|
| + PopulatePhishingLoadTimeData(load_time_data);
|
| break;
|
| }
|
| -
|
| - base::StringPiece html(
|
| - ResourceBundle::GetSharedInstance().GetRawDataResource(
|
| - IRD_SECURITY_INTERSTITIAL_HTML));
|
| - return webui::GetI18nTemplateHtml(html, &load_time_data);
|
| }
|
|
|
| void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData(
|
| @@ -732,17 +714,17 @@ void SafeBrowsingBlockingPage::PopulateMalwareLoadTimeData(
|
| "primaryParagraph",
|
| l10n_util::GetStringFUTF16(
|
| IDS_MALWARE_V3_PRIMARY_PARAGRAPH,
|
| - base::UTF8ToUTF16(url_.host())));
|
| + GetFormattedHostName()));
|
| load_time_data->SetString(
|
| "explanationParagraph",
|
| is_main_frame_load_blocked_ ?
|
| l10n_util::GetStringFUTF16(
|
| IDS_MALWARE_V3_EXPLANATION_PARAGRAPH,
|
| - base::UTF8ToUTF16(url_.host())) :
|
| + GetFormattedHostName()) :
|
| l10n_util::GetStringFUTF16(
|
| IDS_MALWARE_V3_EXPLANATION_PARAGRAPH_SUBRESOURCE,
|
| - base::UTF8ToUTF16(web_contents_->GetURL().host()),
|
| - base::UTF8ToUTF16(url_.host())));
|
| + base::UTF8ToUTF16(web_contents()->GetURL().host()),
|
| + GetFormattedHostName()));
|
| load_time_data->SetString(
|
| "finalParagraph",
|
| l10n_util::GetStringUTF16(IDS_MALWARE_V3_PROCEED_PARAGRAPH));
|
| @@ -772,12 +754,12 @@ void SafeBrowsingBlockingPage::PopulateHarmfulLoadTimeData(
|
| "primaryParagraph",
|
| l10n_util::GetStringFUTF16(
|
| IDS_HARMFUL_V3_PRIMARY_PARAGRAPH,
|
| - base::UTF8ToUTF16(url_.host())));
|
| + GetFormattedHostName()));
|
| load_time_data->SetString(
|
| "explanationParagraph",
|
| l10n_util::GetStringFUTF16(
|
| IDS_HARMFUL_V3_EXPLANATION_PARAGRAPH,
|
| - base::UTF8ToUTF16(url_.host())));
|
| + GetFormattedHostName()));
|
| load_time_data->SetString(
|
| "finalParagraph",
|
| l10n_util::GetStringUTF16(IDS_HARMFUL_V3_PROCEED_PARAGRAPH));
|
| @@ -808,11 +790,11 @@ void SafeBrowsingBlockingPage::PopulatePhishingLoadTimeData(
|
| "primaryParagraph",
|
| l10n_util::GetStringFUTF16(
|
| IDS_PHISHING_V3_PRIMARY_PARAGRAPH,
|
| - base::UTF8ToUTF16(url_.host())));
|
| + GetFormattedHostName()));
|
| load_time_data->SetString(
|
| "explanationParagraph",
|
| l10n_util::GetStringFUTF16(IDS_PHISHING_V3_EXPLANATION_PARAGRAPH,
|
| - base::UTF8ToUTF16(url_.host())));
|
| + GetFormattedHostName()));
|
| load_time_data->SetString(
|
| "finalParagraph",
|
| l10n_util::GetStringUTF16(IDS_PHISHING_V3_PROCEED_PARAGRAPH));
|
|
|