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

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

Issue 887573002: Add Wi-Fi SSID to captive portal interstitial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: felt comments Created 5 years, 11 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
index 9467695de15947bc595a6c0c2a2e254c10144936..cae5aed5cae133f869258aa17b8a718b97ebc7fa 100644
--- a/chrome/browser/ssl/captive_portal_blocking_page.cc
+++ b/chrome/browser/ssl/captive_portal_blocking_page.cc
@@ -7,12 +7,14 @@
#include "base/i18n/rtl.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/captive_portal/captive_portal_detector.h"
+#include "components/wifi/wifi_service.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "net/base/net_util.h"
@@ -47,6 +49,22 @@ bool IsWifiConnection() {
net::NetworkChangeNotifier::CONNECTION_WIFI;
}
+std::string GetWiFiName() {
+ std::string ssid;
+#if defined(OS_WIN) || defined(OS_MACOSX)
+ scoped_ptr<wifi::WiFiService> wifi_service(wifi::WiFiService::Create());
+ wifi_service->Initialize(NULL);
+ std::string error;
+ wifi_service->GetConnectedNetworkSSID(&ssid, &error);
+ if (!error.empty())
+ return "";
+#endif
+ // TODO(meacer): Handle non UTF8 SSIDs.
+ if (!base::IsStringUTF8(ssid))
+ return "";
+ return ssid;
+}
+
const char kOpenLoginPageCommand[] = "openLoginPage";
} // namespace
@@ -109,13 +127,30 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings(
// Captive portal may intercept requests without HTTP redirects, in which
// case the login url would be the same as the captive portal detection url.
// Don't show the login url in that case.
- load_time_data->SetString(
- "primaryParagraph",
- l10n_util::GetStringUTF16(
- is_wifi_connection_ ?
- IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI :
- IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED));
+ if (is_wifi_connection_) {
+ if (wifi_ssid_.empty())
+ wifi_ssid_ = GetWiFiName();
+ if (wifi_ssid_.empty()) {
+ load_time_data->SetString(
+ "primaryParagraph",
+ l10n_util::GetStringUTF16(
+ IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI));
+ } else {
+ load_time_data->SetString(
+ "primaryParagraph",
+ l10n_util::GetStringFUTF16(
+ IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI_SSID,
+ net::EscapeForHTML(base::UTF8ToUTF16(wifi_ssid_))));
+ }
+ } else {
+ // Non-WiFi connection:
+ load_time_data->SetString(
+ "primaryParagraph",
+ l10n_util::GetStringUTF16(
+ IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED));
+ }
} else {
+ // Portal redirection was done with HTTP redirects, show the login URL.
std::string languages;
Profile* profile = Profile::FromBrowserContext(
web_contents()->GetBrowserContext());
@@ -125,13 +160,31 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings(
base::string16 login_host = net::IDNToUnicode(login_url_.host(), languages);
if (base::i18n::IsRTL())
base::i18n::WrapStringWithLTRFormatting(&login_host);
- load_time_data->SetString(
- "primaryParagraph",
- l10n_util::GetStringFUTF16(
- is_wifi_connection_ ?
- IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI :
- IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED,
- login_host));
+
+ if (is_wifi_connection_) {
+ if (wifi_ssid_.empty())
+ wifi_ssid_ = GetWiFiName();
+ if (wifi_ssid_.empty()) {
+ load_time_data->SetString(
+ "primaryParagraph",
+ l10n_util::GetStringFUTF16(
+ IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI,
+ login_host));
+ } else {
+ load_time_data->SetString(
+ "primaryParagraph",
+ l10n_util::GetStringFUTF16(
+ IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI_SSID,
+ net::EscapeForHTML(base::UTF8ToUTF16(wifi_ssid_)),
+ login_host));
+ }
+ } else {
+ // Non-WiFi connection:
+ load_time_data->SetString(
+ "primaryParagraph",
+ l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED,
+ login_host));
+ }
}
// Fill the empty strings to avoid getting debug warnings.
« no previous file with comments | « chrome/browser/ssl/captive_portal_blocking_page.h ('k') | chrome/browser/ssl/captive_portal_blocking_page_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698