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

Side by Side Diff: chrome/browser/ssl/captive_portal_blocking_page.cc

Issue 872993003: Distinguish between wired and wifi connections in the captive portal interstitial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment about the accuracy of GetConnectionType 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 unified diff | Download patch
OLDNEW
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 // |net::NetworkChangeNotifier::GetConnectionType| isn't accurate on Linux and
43 // Windows. See https://crbug.com/160537 for details.
44 // TODO(meacer): Add heuristics to get a more accurate connection type on
45 // these platforms.
46 return net::NetworkChangeNotifier::GetConnectionType() ==
47 net::NetworkChangeNotifier::CONNECTION_WIFI;
48 }
49
40 const char kOpenLoginPageCommand[] = "openLoginPage"; 50 const char kOpenLoginPageCommand[] = "openLoginPage";
41 51
42 } // namespace 52 } // namespace
43 53
44 // static 54 // static
45 const void* CaptivePortalBlockingPage::kTypeForTesting = 55 const void* CaptivePortalBlockingPage::kTypeForTesting =
46 &CaptivePortalBlockingPage::kTypeForTesting; 56 &CaptivePortalBlockingPage::kTypeForTesting;
47 57
48 CaptivePortalBlockingPage::CaptivePortalBlockingPage( 58 CaptivePortalBlockingPage::CaptivePortalBlockingPage(
49 content::WebContents* web_contents, 59 content::WebContents* web_contents,
50 const GURL& request_url, 60 const GURL& request_url,
51 const GURL& login_url, 61 const GURL& login_url,
52 const base::Callback<void(bool)>& callback) 62 const base::Callback<void(bool)>& callback)
53 : SecurityInterstitialPage(web_contents, request_url), 63 : SecurityInterstitialPage(web_contents, request_url),
54 login_url_(login_url), 64 login_url_(login_url),
65 is_wifi_connection_(IsWifiConnection()),
55 callback_(callback) { 66 callback_(callback) {
56 DCHECK(login_url_.is_valid()); 67 DCHECK(login_url_.is_valid());
57 RecordUMA(SHOW_ALL); 68 RecordUMA(SHOW_ALL);
58 } 69 }
59 70
60 CaptivePortalBlockingPage::~CaptivePortalBlockingPage() { 71 CaptivePortalBlockingPage::~CaptivePortalBlockingPage() {
61 // Need to explicity deny the certificate via the callback, otherwise memory 72 // Need to explicity deny the certificate via the callback, otherwise memory
62 // is leaked. 73 // is leaked.
63 if (!callback_.is_null()) { 74 if (!callback_.is_null()) {
64 callback_.Run(false); 75 callback_.Run(false);
(...skipping 12 matching lines...) Expand all
77 void CaptivePortalBlockingPage::PopulateInterstitialStrings( 88 void CaptivePortalBlockingPage::PopulateInterstitialStrings(
78 base::DictionaryValue* load_time_data) { 89 base::DictionaryValue* load_time_data) {
79 load_time_data->SetString("iconClass", "icon-offline"); 90 load_time_data->SetString("iconClass", "icon-offline");
80 load_time_data->SetString("type", "CAPTIVE_PORTAL"); 91 load_time_data->SetString("type", "CAPTIVE_PORTAL");
81 load_time_data->SetBoolean("overridable", false); 92 load_time_data->SetBoolean("overridable", false);
82 93
83 load_time_data->SetString( 94 load_time_data->SetString(
84 "primaryButtonText", 95 "primaryButtonText",
85 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE)); 96 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE));
86 load_time_data->SetString("tabTitle", 97 load_time_data->SetString("tabTitle",
87 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_TITLE)); 98 l10n_util::GetStringUTF16(
99 is_wifi_connection_ ?
100 IDS_CAPTIVE_PORTAL_TITLE_WIFI :
101 IDS_CAPTIVE_PORTAL_TITLE_WIRED));
88 load_time_data->SetString("heading", 102 load_time_data->SetString("heading",
89 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_HEADING)); 103 l10n_util::GetStringUTF16(
104 is_wifi_connection_ ?
105 IDS_CAPTIVE_PORTAL_HEADING_WIFI :
106 IDS_CAPTIVE_PORTAL_HEADING_WIRED));
90 107
91 if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) { 108 if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) {
92 // Captive portal may intercept requests without HTTP redirects, in which 109 // 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. 110 // case the login url would be the same as the captive portal detection url.
94 // Don't show the login url in that case. 111 // Don't show the login url in that case.
95 load_time_data->SetString( 112 load_time_data->SetString(
96 "primaryParagraph", 113 "primaryParagraph",
97 l10n_util::GetStringUTF16( 114 l10n_util::GetStringUTF16(
98 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL)); 115 is_wifi_connection_ ?
116 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI :
117 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED));
99 } else { 118 } else {
100 std::string languages; 119 std::string languages;
101 Profile* profile = Profile::FromBrowserContext( 120 Profile* profile = Profile::FromBrowserContext(
102 web_contents()->GetBrowserContext()); 121 web_contents()->GetBrowserContext());
103 if (profile) 122 if (profile)
104 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); 123 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
105 124
106 base::string16 login_host = net::IDNToUnicode(login_url_.host(), languages); 125 base::string16 login_host = net::IDNToUnicode(login_url_.host(), languages);
107 if (base::i18n::IsRTL()) 126 if (base::i18n::IsRTL())
108 base::i18n::WrapStringWithLTRFormatting(&login_host); 127 base::i18n::WrapStringWithLTRFormatting(&login_host);
109 load_time_data->SetString( 128 load_time_data->SetString(
110 "primaryParagraph", 129 "primaryParagraph",
111 l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH, 130 l10n_util::GetStringFUTF16(
112 login_host)); 131 is_wifi_connection_ ?
132 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI :
133 IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED,
134 login_host));
113 } 135 }
114 136
115 // Fill the empty strings to avoid getting debug warnings. 137 // Fill the empty strings to avoid getting debug warnings.
116 load_time_data->SetString("openDetails", base::string16()); 138 load_time_data->SetString("openDetails", base::string16());
117 load_time_data->SetString("closeDetails", base::string16()); 139 load_time_data->SetString("closeDetails", base::string16());
118 load_time_data->SetString("explanationParagraph", base::string16()); 140 load_time_data->SetString("explanationParagraph", base::string16());
119 load_time_data->SetString("finalParagraph", base::string16()); 141 load_time_data->SetString("finalParagraph", base::string16());
120 } 142 }
121 143
122 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { 144 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) {
123 // The response has quotes around it. 145 // The response has quotes around it.
124 if (command == std::string("\"") + kOpenLoginPageCommand + "\"") { 146 if (command == std::string("\"") + kOpenLoginPageCommand + "\"") {
125 RecordUMA(OPEN_LOGIN_PAGE); 147 RecordUMA(OPEN_LOGIN_PAGE);
126 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); 148 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true);
127 } 149 }
128 } 150 }
OLDNEW
« 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