Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5648)

Unified Diff: chrome/browser/ssl/ssl_blocking_page.cc

Issue 622683006: Refactor security interstitials, add SecurityInterstitialPage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/ssl_blocking_page.cc
diff --git a/chrome/browser/ssl/ssl_blocking_page.cc b/chrome/browser/ssl/ssl_blocking_page.cc
index 9bdbc9cf49cc642960dc7d0a5730d46b82b21b94..46f979e139e6a5a25888d089a316d5faac70b48f 100644
--- a/chrome/browser/ssl/ssl_blocking_page.cc
+++ b/chrome/browser/ssl/ssl_blocking_page.cc
@@ -44,9 +44,6 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.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"
@@ -310,15 +307,13 @@ SSLBlockingPage::SSLBlockingPage(content::WebContents* web_contents,
const GURL& request_url,
int options_mask,
const base::Callback<void(bool)>& callback)
- : callback_(callback),
- web_contents_(web_contents),
+ : SecurityInterstitialPage(web_contents, request_url),
+ callback_(callback),
cert_error_(cert_error),
ssl_info_(ssl_info),
- request_url_(request_url),
overridable_(options_mask & OVERRIDABLE &&
!(options_mask & STRICT_ENFORCEMENT)),
strict_enforcement_((options_mask & STRICT_ENFORCEMENT) != 0),
- interstitial_page_(NULL),
internal_(false),
num_visits_(-1),
expired_but_previously_allowed_(
@@ -326,7 +321,7 @@ SSLBlockingPage::SSLBlockingPage(content::WebContents* web_contents,
Profile* profile = Profile::FromBrowserContext(
web_contents->GetBrowserContext());
// For UMA stats.
- if (net::IsHostnameNonUnique(request_url_.HostNoBrackets()))
+ if (net::IsHostnameNonUnique(request_url.HostNoBrackets()))
internal_ = true;
RecordSSLBlockingPageEventStats(SHOW_ALL);
if (overridable_) {
@@ -337,7 +332,7 @@ SSLBlockingPage::SSLBlockingPage(content::WebContents* web_contents,
profile, Profile::EXPLICIT_ACCESS);
if (history_service) {
history_service->GetVisibleVisitCountToHost(
- request_url_,
+ request_url,
base::Bind(&SSLBlockingPage::OnGotHistoryCount,
base::Unretained(this)),
&request_tracker_);
@@ -345,9 +340,9 @@ SSLBlockingPage::SSLBlockingPage(content::WebContents* web_contents,
}
ssl_error_classification_.reset(new SSLErrorClassification(
- web_contents_,
+ web_contents,
base::Time::NowFromSystemTime(),
- request_url_,
+ request_url,
cert_error_,
*ssl_info_.cert.get()));
ssl_error_classification_->RecordUMAStatistics(overridable_);
@@ -366,15 +361,23 @@ SSLBlockingPage::SSLBlockingPage(content::WebContents* web_contents,
event_name.append(net::ErrorToString(cert_error_));
sampling_event_.reset(new ExperienceSamplingEvent(
event_name,
- request_url_,
- web_contents_->GetLastCommittedURL(),
- web_contents_->GetBrowserContext()));
+ request_url,
+ web_contents->GetLastCommittedURL(),
+ web_contents->GetBrowserContext()));
#endif
// Creating an interstitial without showing (e.g. from chrome://interstitials)
// it leaks memory, so don't create it here.
}
+bool SSLBlockingPage::ShouldCreateNewNavigation() const {
+ return true;
+}
+
+SecurityInterstitialPage::Type SSLBlockingPage::GetTypeForTesting() const {
+ return SecurityInterstitialPage::SSL;
+}
+
SSLBlockingPage::~SSLBlockingPage() {
// InvalidCommonNameSeverityScore() and InvalidDateSeverityScore() are in the
// destructor because they depend on knowing whether captive portal detection
@@ -404,67 +407,57 @@ SSLBlockingPage::~SSLBlockingPage() {
}
}
-void SSLBlockingPage::Show() {
- DCHECK(!interstitial_page_);
- interstitial_page_ = InterstitialPage::Create(
- web_contents_, true, request_url_, this);
- interstitial_page_->Show();
-}
-
-std::string SSLBlockingPage::GetHTMLContents() {
- base::DictionaryValue load_time_data;
- base::string16 url(ASCIIToUTF16(request_url_.host()));
- if (base::i18n::IsRTL())
- base::i18n::WrapStringWithLTRFormatting(&url);
- webui::SetFontAndTextDirection(&load_time_data);
-
+void SSLBlockingPage::PopulateLoadTimeData(
+ base::DictionaryValue* load_time_data) {
+ CHECK(load_time_data);
+ base::string16 url(GetFormattedHostName());
// Shared values for both the overridable and non-overridable versions.
- load_time_data.SetString("type", "SSL");
- load_time_data.SetBoolean("overridable", overridable_);
- load_time_data.SetString(
+ load_time_data->SetString("type", "SSL");
+ load_time_data->SetBoolean("overridable", overridable_);
+ load_time_data->SetString(
"tabTitle", l10n_util::GetStringUTF16(IDS_SSL_V2_TITLE));
- load_time_data.SetString(
+ load_time_data->SetString(
"heading", l10n_util::GetStringUTF16(IDS_SSL_V2_HEADING));
base::Time now = base::Time::NowFromSystemTime();
bool bad_clock = IsErrorDueToBadClock(now, cert_error_);
if (bad_clock) {
- load_time_data.SetString("primaryParagraph",
+ load_time_data->SetString("primaryParagraph",
l10n_util::GetStringFUTF16(
IDS_SSL_CLOCK_ERROR,
url,
base::TimeFormatShortDate(now)));
} else {
- load_time_data.SetString(
+ load_time_data->SetString(
"primaryParagraph",
l10n_util::GetStringFUTF16(IDS_SSL_V2_PRIMARY_PARAGRAPH, url));
}
- load_time_data.SetString(
+ load_time_data->SetString(
"openDetails",
l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON));
- load_time_data.SetString(
+ load_time_data->SetString(
"closeDetails",
l10n_util::GetStringUTF16(IDS_SSL_V2_CLOSE_DETAILS_BUTTON));
- load_time_data.SetString("errorCode", net::ErrorToString(cert_error_));
+ load_time_data->SetString("errorCode", net::ErrorToString(cert_error_));
if (overridable_) {
SSLErrorInfo error_info =
SSLErrorInfo::CreateError(
SSLErrorInfo::NetErrorToErrorType(cert_error_),
ssl_info_.cert.get(),
- request_url_);
+ request_url());
if (bad_clock) {
- load_time_data.SetString("explanationParagraph",
+ load_time_data->SetString("explanationParagraph",
l10n_util::GetStringFUTF16(
IDS_SSL_CLOCK_ERROR_EXPLANATION, url));
} else {
- load_time_data.SetString("explanationParagraph", error_info.details());
+ load_time_data->SetString("explanationParagraph", error_info.details());
}
- load_time_data.SetString(
+ load_time_data->SetString(
"primaryButtonText",
l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON));
- load_time_data.SetString(
+ load_time_data->SetString(
"finalParagraph",
l10n_util::GetStringFUTF16(IDS_SSL_OVERRIDABLE_PROCEED_PARAGRAPH,
url));
@@ -473,26 +466,26 @@ std::string SSLBlockingPage::GetHTMLContents() {
SSLErrorInfo::NetErrorToErrorType(cert_error_);
if (type == SSLErrorInfo::CERT_INVALID && SSLErrorClassification::
MaybeWindowsLacksSHA256Support()) {
- load_time_data.SetString(
+ load_time_data->SetString(
"explanationParagraph",
l10n_util::GetStringFUTF16(
IDS_SSL_NONOVERRIDABLE_MORE_INVALID_SP3, url));
} else if (bad_clock) {
- load_time_data.SetString("explanationParagraph",
+ load_time_data->SetString("explanationParagraph",
l10n_util::GetStringFUTF16(
IDS_SSL_CLOCK_ERROR_EXPLANATION, url));
} else {
- load_time_data.SetString("explanationParagraph",
+ load_time_data->SetString("explanationParagraph",
l10n_util::GetStringFUTF16(
IDS_SSL_NONOVERRIDABLE_MORE, url));
}
- load_time_data.SetString(
+ load_time_data->SetString(
"primaryButtonText",
l10n_util::GetStringUTF16(IDS_SSL_NONOVERRIDABLE_RELOAD_BUTTON));
// Customize the help link depending on the specific error type.
// Only mark as HSTS if none of the more specific error types apply, and use
// INVALID as a fallback if no other string is appropriate.
- load_time_data.SetInteger("errorType", type);
+ load_time_data->SetInteger("errorType", type);
int help_string = IDS_SSL_NONOVERRIDABLE_INVALID;
switch (type) {
case SSLErrorInfo::CERT_REVOKED:
@@ -508,33 +501,28 @@ std::string SSLBlockingPage::GetHTMLContents() {
if (strict_enforcement_)
help_string = IDS_SSL_NONOVERRIDABLE_HSTS;
}
- load_time_data.SetString(
+ load_time_data->SetString(
"finalParagraph", l10n_util::GetStringFUTF16(help_string, url));
}
// Set debugging information at the bottom of the warning.
- load_time_data.SetString(
+ load_time_data->SetString(
"subject", ssl_info_.cert->subject().GetDisplayName());
- load_time_data.SetString(
+ load_time_data->SetString(
"issuer", ssl_info_.cert->issuer().GetDisplayName());
- load_time_data.SetString(
+ load_time_data->SetString(
"expirationDate",
base::TimeFormatShortDate(ssl_info_.cert->valid_expiry()));
- load_time_data.SetString(
+ load_time_data->SetString(
"currentDate", base::TimeFormatShortDate(now));
std::vector<std::string> encoded_chain;
ssl_info_.cert->GetPEMEncodedChain(&encoded_chain);
- load_time_data.SetString("pem", JoinString(encoded_chain, std::string()));
-
- base::StringPiece html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IRD_SECURITY_INTERSTITIAL_HTML));
- return webui::GetI18nTemplateHtml(html, &load_time_data);
+ load_time_data->SetString("pem", JoinString(encoded_chain, std::string()));
}
void SSLBlockingPage::OverrideEntry(NavigationEntry* entry) {
int cert_id = content::CertStore::GetInstance()->StoreCert(
- ssl_info_.cert.get(), web_contents_->GetRenderProcessHost()->GetID());
+ ssl_info_.cert.get(), web_contents()->GetRenderProcessHost()->GetID());
DCHECK(cert_id);
entry->GetSSL().security_style =
@@ -553,11 +541,11 @@ void SSLBlockingPage::CommandReceived(const std::string& command) {
DCHECK(retval);
switch (cmd) {
case CMD_DONT_PROCEED: {
- interstitial_page_->DontProceed();
+ interstitial_page()->DontProceed();
break;
}
case CMD_PROCEED: {
- interstitial_page_->Proceed();
+ interstitial_page()->Proceed();
break;
}
case CMD_MORE: {
@@ -570,7 +558,7 @@ void SSLBlockingPage::CommandReceived(const std::string& command) {
}
case CMD_RELOAD: {
// The interstitial can't refresh itself.
- web_contents_->GetController().Reload(true);
+ web_contents()->GetController().Reload(true);
break;
}
case CMD_HELP: {
@@ -581,7 +569,7 @@ void SSLBlockingPage::CommandReceived(const std::string& command) {
if (sampling_event_.get())
sampling_event_->set_has_viewed_learn_more(true);
#endif
- web_contents_->GetController().LoadURLWithParams(help_page_params);
+ web_contents()->GetController().LoadURLWithParams(help_page_params);
break;
}
case CMD_CLOCK: {
@@ -597,7 +585,7 @@ void SSLBlockingPage::CommandReceived(const std::string& command) {
void SSLBlockingPage::OverrideRendererPrefs(
content::RendererPreferences* prefs) {
Profile* profile = Profile::FromBrowserContext(
- web_contents_->GetBrowserContext());
+ web_contents()->GetBrowserContext());
renderer_preferences_util::UpdateFromSystemSettings(prefs, profile);
}

Powered by Google App Engine
This is Rietveld 408576698