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

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

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Const all the things Created 6 years, 6 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/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..ef2bd4601f0555d7651191c5dcfe6c9a1778f4e8
--- /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"
mmenke 2014/06/24 18:09:26 I don't think this is used.
meacer 2014/10/22 23:04:28 Not referred from this class anymore.
+#include "grit/generated_resources.h"
+#include "net/base/net_errors.h"
mmenke 2014/06/24 18:09:26 I don't think this is used.
meacer 2014/10/22 23:04:28 Done.
+#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_SHOW_DETAILS = 2
+};
+
+// Events for UMA.
+enum CaptivePortalBlockingPageEvent {
+ SHOW_ALL,
+ OPEN_LOGIN_PAGE,
+ SHOW_DETAILS,
+ 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),
+ 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());
mmenke 2014/06/24 18:09:26 Need the header for atoi.
meacer 2014/10/22 23:04:28 Code not used anymore.
+ if (cmd == CMD_OPEN_LOGIN_PAGE) {
+ RecordUMA(OPEN_LOGIN_PAGE);
+#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
+ CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents_, true);
+#endif
+ } else if (cmd == CMD_SHOW_DETAILS) {
+ RecordUMA(SHOW_DETAILS);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698