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/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 12 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "components/captive_portal/captive_portal_detector.h" | 15 #include "components/captive_portal/captive_portal_detector.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "net/base/network_change_notifier.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 | 21 |
21 #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 22 #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
22 #error This file must be built with ENABLE_CAPTIVE_PORTAL_DETECTION flag. | 23 #error This file must be built with ENABLE_CAPTIVE_PORTAL_DETECTION flag. |
23 #endif | 24 #endif |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Events for UMA. | 28 // Events for UMA. |
28 enum CaptivePortalBlockingPageEvent { | 29 enum CaptivePortalBlockingPageEvent { |
29 SHOW_ALL, | 30 SHOW_ALL, |
30 OPEN_LOGIN_PAGE, | 31 OPEN_LOGIN_PAGE, |
31 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT | 32 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT |
32 }; | 33 }; |
33 | 34 |
34 void RecordUMA(CaptivePortalBlockingPageEvent event) { | 35 void RecordUMA(CaptivePortalBlockingPageEvent event) { |
35 UMA_HISTOGRAM_ENUMERATION("interstitial.captive_portal", | 36 UMA_HISTOGRAM_ENUMERATION("interstitial.captive_portal", |
36 event, | 37 event, |
37 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); | 38 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); |
38 } | 39 } |
39 | 40 |
| 41 bool IsWifiConnection() { |
| 42 return net::NetworkChangeNotifier::GetConnectionType() == |
| 43 net::NetworkChangeNotifier::CONNECTION_WIFI; |
| 44 } |
| 45 |
40 const char kOpenLoginPageCommand[] = "openLoginPage"; | 46 const char kOpenLoginPageCommand[] = "openLoginPage"; |
41 | 47 |
42 } // namespace | 48 } // namespace |
43 | 49 |
44 // static | 50 // static |
45 const void* CaptivePortalBlockingPage::kTypeForTesting = | 51 const void* CaptivePortalBlockingPage::kTypeForTesting = |
46 &CaptivePortalBlockingPage::kTypeForTesting; | 52 &CaptivePortalBlockingPage::kTypeForTesting; |
47 | 53 |
48 CaptivePortalBlockingPage::CaptivePortalBlockingPage( | 54 CaptivePortalBlockingPage::CaptivePortalBlockingPage( |
49 content::WebContents* web_contents, | 55 content::WebContents* web_contents, |
50 const GURL& request_url, | 56 const GURL& request_url, |
51 const GURL& login_url, | 57 const GURL& login_url, |
52 const base::Callback<void(bool)>& callback) | 58 const base::Callback<void(bool)>& callback) |
53 : SecurityInterstitialPage(web_contents, request_url), | 59 : SecurityInterstitialPage(web_contents, request_url), |
54 login_url_(login_url), | 60 login_url_(login_url), |
| 61 is_wifi_connection_(IsWifiConnection()), |
55 callback_(callback) { | 62 callback_(callback) { |
56 DCHECK(login_url_.is_valid()); | 63 DCHECK(login_url_.is_valid()); |
57 RecordUMA(SHOW_ALL); | 64 RecordUMA(SHOW_ALL); |
58 } | 65 } |
59 | 66 |
60 CaptivePortalBlockingPage::~CaptivePortalBlockingPage() { | 67 CaptivePortalBlockingPage::~CaptivePortalBlockingPage() { |
61 // Need to explicity deny the certificate via the callback, otherwise memory | 68 // Need to explicity deny the certificate via the callback, otherwise memory |
62 // is leaked. | 69 // is leaked. |
63 if (!callback_.is_null()) { | 70 if (!callback_.is_null()) { |
64 callback_.Run(false); | 71 callback_.Run(false); |
(...skipping 12 matching lines...) Expand all Loading... |
77 void CaptivePortalBlockingPage::PopulateInterstitialStrings( | 84 void CaptivePortalBlockingPage::PopulateInterstitialStrings( |
78 base::DictionaryValue* load_time_data) { | 85 base::DictionaryValue* load_time_data) { |
79 load_time_data->SetString("iconClass", "icon-offline"); | 86 load_time_data->SetString("iconClass", "icon-offline"); |
80 load_time_data->SetString("type", "CAPTIVE_PORTAL"); | 87 load_time_data->SetString("type", "CAPTIVE_PORTAL"); |
81 load_time_data->SetBoolean("overridable", false); | 88 load_time_data->SetBoolean("overridable", false); |
82 | 89 |
83 load_time_data->SetString( | 90 load_time_data->SetString( |
84 "primaryButtonText", | 91 "primaryButtonText", |
85 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE)); | 92 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE)); |
86 load_time_data->SetString("tabTitle", | 93 load_time_data->SetString("tabTitle", |
87 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_TITLE)); | 94 l10n_util::GetStringUTF16( |
| 95 is_wifi_connection_ ? |
| 96 IDS_CAPTIVE_PORTAL_TITLE_WIFI : |
| 97 IDS_CAPTIVE_PORTAL_TITLE_WIRED)); |
88 load_time_data->SetString("heading", | 98 load_time_data->SetString("heading", |
89 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_HEADING)); | 99 l10n_util::GetStringUTF16( |
| 100 is_wifi_connection_ ? |
| 101 IDS_CAPTIVE_PORTAL_HEADING_WIFI : |
| 102 IDS_CAPTIVE_PORTAL_HEADING_WIRED)); |
90 | 103 |
91 if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) { | 104 if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) { |
92 // Captive portal may intercept requests without HTTP redirects, in which | 105 // Captive portal may intercept requests without HTTP redirects, in which |
93 // case the login url would be the same as the captive portal detection url. | 106 // case the login url would be the same as the captive portal detection url. |
94 // Don't show the login url in that case. | 107 // Don't show the login url in that case. |
95 load_time_data->SetString( | 108 load_time_data->SetString( |
96 "primaryParagraph", | 109 "primaryParagraph", |
97 l10n_util::GetStringUTF16( | 110 l10n_util::GetStringUTF16( |
98 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL)); | 111 is_wifi_connection_ ? |
| 112 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI : |
| 113 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED)); |
99 } else { | 114 } else { |
100 std::string languages; | 115 std::string languages; |
101 Profile* profile = Profile::FromBrowserContext( | 116 Profile* profile = Profile::FromBrowserContext( |
102 web_contents()->GetBrowserContext()); | 117 web_contents()->GetBrowserContext()); |
103 if (profile) | 118 if (profile) |
104 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 119 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
105 | 120 |
106 base::string16 login_host = net::IDNToUnicode(login_url_.host(), languages); | 121 base::string16 login_host = net::IDNToUnicode(login_url_.host(), languages); |
107 if (base::i18n::IsRTL()) | 122 if (base::i18n::IsRTL()) |
108 base::i18n::WrapStringWithLTRFormatting(&login_host); | 123 base::i18n::WrapStringWithLTRFormatting(&login_host); |
109 load_time_data->SetString( | 124 load_time_data->SetString( |
110 "primaryParagraph", | 125 "primaryParagraph", |
111 l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH, | 126 l10n_util::GetStringFUTF16( |
112 login_host)); | 127 is_wifi_connection_ ? |
| 128 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI : |
| 129 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED, |
| 130 login_host)); |
113 } | 131 } |
114 | 132 |
115 // Fill the empty strings to avoid getting debug warnings. | 133 // Fill the empty strings to avoid getting debug warnings. |
116 load_time_data->SetString("openDetails", base::string16()); | 134 load_time_data->SetString("openDetails", base::string16()); |
117 load_time_data->SetString("closeDetails", base::string16()); | 135 load_time_data->SetString("closeDetails", base::string16()); |
118 load_time_data->SetString("explanationParagraph", base::string16()); | 136 load_time_data->SetString("explanationParagraph", base::string16()); |
119 load_time_data->SetString("finalParagraph", base::string16()); | 137 load_time_data->SetString("finalParagraph", base::string16()); |
120 } | 138 } |
121 | 139 |
122 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { | 140 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { |
123 // The response has quotes around it. | 141 // The response has quotes around it. |
124 if (command == std::string("\"") + kOpenLoginPageCommand + "\"") { | 142 if (command == std::string("\"") + kOpenLoginPageCommand + "\"") { |
125 RecordUMA(OPEN_LOGIN_PAGE); | 143 RecordUMA(OPEN_LOGIN_PAGE); |
126 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); | 144 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); |
127 } | 145 } |
128 } | 146 } |
OLD | NEW |