Chromium Code Reviews| Index: chrome/browser/ssl/captive_portal_blocking_page.cc |
| diff --git a/chrome/browser/ssl/captive_portal_blocking_page.cc b/chrome/browser/ssl/captive_portal_blocking_page.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c6b12611736f5fee12cfb53bd6fb907056d794d3 |
| --- /dev/null |
| +++ b/chrome/browser/ssl/captive_portal_blocking_page.cc |
| @@ -0,0 +1,129 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| + |
| +#include "base/i18n/rtl.h" |
| +#include "base/metrics/histogram.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/localized_error.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "content/public/browser/interstitial_page.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "grit/browser_resources.h" |
| +#include "grit/generated_resources.h" |
| +#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_CAPTIVE_PORTAL_DETECTION) |
| +#include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| +#endif |
| + |
| +namespace { |
| + |
| +// These represent the commands sent by captive_portal.html. |
| +enum CaptivePortalBlockingPageCommands { |
| + CMD_OPEN_LOGIN_PAGE = 1, |
| + CMD_MORE = 2 |
| +}; |
| + |
| +// Events for UMA. |
| +enum CaptivePortalBlockingPageEvent { |
| + SHOW_ALL, |
| + OPEN_LOGIN_PAGE, |
| + MORE, |
| + CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT |
| +}; |
| + |
| +void RecordUMA(CaptivePortalBlockingPageEvent event) { |
| + UMA_HISTOGRAM_ENUMERATION("interstitial.captive_portal", |
| + event, |
| + CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); |
| +} |
| + |
| +void GetStrings(base::DictionaryValue* strings, |
| + const GURL& request_url, |
| + const std::string& accept_languages) { |
| + webui::SetFontAndTextDirection(strings); |
| + strings->SetString("iconClass", "icon-offline"); |
| + base::string16 url_string(net::FormatUrl( |
| + request_url, accept_languages, net::kFormatUrlOmitNothing, |
| + net::UnescapeRule::NORMAL, NULL, NULL, NULL)); |
| + // URLs are always LTR. |
| + if (base::i18n::IsRTL()) |
| + base::i18n::WrapStringWithLTRFormatting(&url_string); |
| + strings->SetString("title", |
| + l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_TITLE, url_string)); |
| + strings->SetString("heading", |
| + l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_HEADING)); |
| + strings->SetString( |
| + "primaryButtonText", |
| + l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE)); |
| + strings->SetString( |
| + "openDetails", |
| + l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_MORE)); |
| + strings->SetString( |
| + "closeDetails", |
| + l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_LESS)); |
| + strings->SetString( |
| + "primaryParagraph", |
| + l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH, |
| + url_string)); |
| + strings->SetString( |
| + "explanationParagraph", |
| + l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_DETAILS, |
| + url_string)); |
| +} |
| + |
| +} // namespace |
| + |
| +CaptivePortalBlockingPage::CaptivePortalBlockingPage( |
| + content::WebContents* web_contents, |
| + const GURL& request_url) |
| + : web_contents_(web_contents), |
|
mmenke
2014/06/20 16:07:08
nit: +2 indent.
meacer
2014/06/20 23:28:14
Done.
|
| + request_url_(request_url) { |
| + interstitial_page_ = content::InterstitialPage::Create( |
| + web_contents_, true, request_url, this); |
| + interstitial_page_->Show(); |
| + RecordUMA(SHOW_ALL); |
| +} |
| + |
| +CaptivePortalBlockingPage::~CaptivePortalBlockingPage() { |
| +} |
| + |
| +std::string CaptivePortalBlockingPage::GetHTMLContents() { |
| + int resource_id = IDR_CAPTIVE_PORTAL_HTML; |
| + const base::StringPiece template_html( |
| + ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| + |
| + Profile* profile = Profile::FromBrowserContext( |
| + web_contents_->GetBrowserContext()); |
| + const std::string accept_languages = |
| + profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| + const std::string locale = g_browser_process->GetApplicationLocale(); |
| + |
| + base::DictionaryValue strings; |
| + GetStrings(&strings, request_url_, accept_languages); |
| + webui::UseVersion2 version; |
| + return webui::GetI18nTemplateHtml(template_html, &strings); |
| +} |
| + |
| +void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { |
| + int cmd = atoi(command.c_str()); |
| + if (cmd == CMD_OPEN_LOGIN_PAGE) { |
| + RecordUMA(OPEN_LOGIN_PAGE); |
| +#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
|
mmenke
2014/06/20 16:07:08
Think it makes more sense just to exclude this fil
meacer
2014/06/20 23:28:14
Hmm, I was thinking if we enable portal pings on W
|
| + CaptivePortalTabHelper::FromWebContents(web_contents_)->OpenLoginTab(true); |
| +#endif |
| + } else if (cmd == CMD_MORE) { |
| + RecordUMA(MORE); |
| + } |
| +} |