Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 5 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_util.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 13 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 15 #include "components/captive_portal/captive_portal_detector.h" | 16 #include "components/captive_portal/captive_portal_detector.h" |
| 17 #include "components/wifi/wifi_service.h" | |
| 16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 17 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 18 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 19 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 21 | 23 |
| 22 #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 24 #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 23 #error This file must be built with ENABLE_CAPTIVE_PORTAL_DETECTION flag. | 25 #error This file must be built with ENABLE_CAPTIVE_PORTAL_DETECTION flag. |
| 24 #endif | 26 #endif |
| 25 | 27 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 40 | 42 |
| 41 bool IsWifiConnection() { | 43 bool IsWifiConnection() { |
| 42 // |net::NetworkChangeNotifier::GetConnectionType| isn't accurate on Linux and | 44 // |net::NetworkChangeNotifier::GetConnectionType| isn't accurate on Linux and |
| 43 // Windows. See https://crbug.com/160537 for details. | 45 // Windows. See https://crbug.com/160537 for details. |
| 44 // TODO(meacer): Add heuristics to get a more accurate connection type on | 46 // TODO(meacer): Add heuristics to get a more accurate connection type on |
| 45 // these platforms. | 47 // these platforms. |
| 46 return net::NetworkChangeNotifier::GetConnectionType() == | 48 return net::NetworkChangeNotifier::GetConnectionType() == |
| 47 net::NetworkChangeNotifier::CONNECTION_WIFI; | 49 net::NetworkChangeNotifier::CONNECTION_WIFI; |
| 48 } | 50 } |
| 49 | 51 |
| 52 std::string GetWiFiName() { | |
| 53 std::string ssid; | |
| 54 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 55 scoped_ptr<wifi::WiFiService> wifi_service(wifi::WiFiService::Create()); | |
| 56 wifi_service->Initialize(NULL); | |
| 57 std::string error; | |
| 58 wifi_service->GetConnectedNetworkSSID(&ssid, &error); | |
| 59 if (!error.empty()) | |
| 60 return ""; | |
| 61 #endif | |
| 62 // TODO(meacer): Handle non UTF8 SSIDs. | |
| 63 if (!base::IsStringUTF8(ssid)) | |
| 64 return ""; | |
| 65 return ssid; | |
| 66 } | |
| 67 | |
| 50 const char kOpenLoginPageCommand[] = "openLoginPage"; | 68 const char kOpenLoginPageCommand[] = "openLoginPage"; |
| 51 | 69 |
| 52 } // namespace | 70 } // namespace |
| 53 | 71 |
| 54 // static | 72 // static |
| 55 const void* CaptivePortalBlockingPage::kTypeForTesting = | 73 const void* CaptivePortalBlockingPage::kTypeForTesting = |
| 56 &CaptivePortalBlockingPage::kTypeForTesting; | 74 &CaptivePortalBlockingPage::kTypeForTesting; |
| 57 | 75 |
| 58 CaptivePortalBlockingPage::CaptivePortalBlockingPage( | 76 CaptivePortalBlockingPage::CaptivePortalBlockingPage( |
| 59 content::WebContents* web_contents, | 77 content::WebContents* web_contents, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 load_time_data->SetString("heading", | 120 load_time_data->SetString("heading", |
| 103 l10n_util::GetStringUTF16( | 121 l10n_util::GetStringUTF16( |
| 104 is_wifi_connection_ ? | 122 is_wifi_connection_ ? |
| 105 IDS_CAPTIVE_PORTAL_HEADING_WIFI : | 123 IDS_CAPTIVE_PORTAL_HEADING_WIFI : |
| 106 IDS_CAPTIVE_PORTAL_HEADING_WIRED)); | 124 IDS_CAPTIVE_PORTAL_HEADING_WIRED)); |
| 107 | 125 |
| 108 if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) { | 126 if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) { |
| 109 // Captive portal may intercept requests without HTTP redirects, in which | 127 // Captive portal may intercept requests without HTTP redirects, in which |
| 110 // case the login url would be the same as the captive portal detection url. | 128 // case the login url would be the same as the captive portal detection url. |
| 111 // Don't show the login url in that case. | 129 // Don't show the login url in that case. |
| 112 load_time_data->SetString( | 130 if (!is_wifi_connection_) { |
|
felt
2015/01/29 22:59:57
nit: kind of a weird construction -- why not the o
meacer
2015/01/29 23:53:29
Done.
| |
| 113 "primaryParagraph", | 131 load_time_data->SetString( |
| 114 l10n_util::GetStringUTF16( | 132 "primaryParagraph", |
| 115 is_wifi_connection_ ? | 133 l10n_util::GetStringUTF16( |
| 116 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI : | 134 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED)); |
| 117 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED)); | 135 } else { |
| 136 if (wifi_ssid_.empty()) | |
| 137 wifi_ssid_ = GetWiFiName(); | |
| 138 if (!wifi_ssid_.empty()) { | |
| 139 load_time_data->SetString( | |
| 140 "primaryParagraph", | |
| 141 l10n_util::GetStringFUTF16( | |
| 142 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI_SSID, | |
| 143 net::EscapeForHTML(base::UTF8ToUTF16(wifi_ssid_)))); | |
| 144 } else { | |
| 145 load_time_data->SetString( | |
| 146 "primaryParagraph", | |
| 147 l10n_util::GetStringUTF16( | |
| 148 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI)); | |
| 149 } | |
| 150 } | |
| 118 } else { | 151 } else { |
| 119 std::string languages; | 152 std::string languages; |
| 120 Profile* profile = Profile::FromBrowserContext( | 153 Profile* profile = Profile::FromBrowserContext( |
| 121 web_contents()->GetBrowserContext()); | 154 web_contents()->GetBrowserContext()); |
| 122 if (profile) | 155 if (profile) |
| 123 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 156 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 124 | 157 |
| 125 base::string16 login_host = net::IDNToUnicode(login_url_.host(), languages); | 158 base::string16 login_host = net::IDNToUnicode(login_url_.host(), languages); |
| 126 if (base::i18n::IsRTL()) | 159 if (base::i18n::IsRTL()) |
| 127 base::i18n::WrapStringWithLTRFormatting(&login_host); | 160 base::i18n::WrapStringWithLTRFormatting(&login_host); |
| 128 load_time_data->SetString( | 161 |
| 129 "primaryParagraph", | 162 if (!is_wifi_connection_) { |
|
felt
2015/01/29 22:59:57
same here
| |
| 130 l10n_util::GetStringFUTF16( | 163 load_time_data->SetString( |
| 131 is_wifi_connection_ ? | 164 "primaryParagraph", |
| 132 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI : | 165 l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED, |
| 133 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED, | 166 login_host)); |
| 134 login_host)); | 167 } else { |
| 168 if (wifi_ssid_.empty()) | |
| 169 wifi_ssid_ = GetWiFiName(); | |
| 170 if (!wifi_ssid_.empty()) { | |
| 171 load_time_data->SetString( | |
| 172 "primaryParagraph", | |
| 173 l10n_util::GetStringFUTF16( | |
| 174 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI_SSID, | |
| 175 net::EscapeForHTML(base::UTF8ToUTF16(wifi_ssid_)), | |
| 176 login_host)); | |
| 177 } else { | |
| 178 load_time_data->SetString( | |
| 179 "primaryParagraph", | |
| 180 l10n_util::GetStringFUTF16( | |
| 181 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI, | |
| 182 login_host)); | |
| 183 } | |
| 184 } | |
| 135 } | 185 } |
| 136 | 186 |
| 137 // Fill the empty strings to avoid getting debug warnings. | 187 // Fill the empty strings to avoid getting debug warnings. |
| 138 load_time_data->SetString("openDetails", base::string16()); | 188 load_time_data->SetString("openDetails", base::string16()); |
| 139 load_time_data->SetString("closeDetails", base::string16()); | 189 load_time_data->SetString("closeDetails", base::string16()); |
| 140 load_time_data->SetString("explanationParagraph", base::string16()); | 190 load_time_data->SetString("explanationParagraph", base::string16()); |
| 141 load_time_data->SetString("finalParagraph", base::string16()); | 191 load_time_data->SetString("finalParagraph", base::string16()); |
| 142 } | 192 } |
| 143 | 193 |
| 144 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { | 194 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { |
| 145 // The response has quotes around it. | 195 // The response has quotes around it. |
| 146 if (command == std::string("\"") + kOpenLoginPageCommand + "\"") { | 196 if (command == std::string("\"") + kOpenLoginPageCommand + "\"") { |
| 147 RecordUMA(OPEN_LOGIN_PAGE); | 197 RecordUMA(OPEN_LOGIN_PAGE); |
| 148 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); | 198 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); |
| 149 } | 199 } |
| 150 } | 200 } |
| OLD | NEW |