Commit ed335a35 authored by meacer's avatar meacer Committed by Commit bot

Distinguish between wired and Wi-Fi connections in the captive portal interstitial.

BUG=451272

Review URL: https://codereview.chromium.org/872993003

Cr-Commit-Position: refs/heads/master@{#313434}
parent d722c2ce
...@@ -9878,18 +9878,30 @@ I don't think this site should be blocked! ...@@ -9878,18 +9878,30 @@ I don't think this site should be blocked!
</if> </if>
<!-- Captive portal interstitial --> <!-- Captive portal interstitial -->
<message name="IDS_CAPTIVE_PORTAL_TITLE" desc="Title in the error page when a secure request is blocked because the network is redirecting the request to another page until the user logs in"> <message name="IDS_CAPTIVE_PORTAL_TITLE_WIRED" desc="Title in the error page when a secure request is blocked because the network is redirecting the request to another page until the user logs in">
Connect to Network Connect to Network
</message> </message>
<message name="IDS_CAPTIVE_PORTAL_HEADING" desc="Heading in the error page when a secure request is blocked because a captive portal is manipulating a connection"> <message name="IDS_CAPTIVE_PORTAL_TITLE_WIFI" desc="Title in the error page when a secure request is blocked because the Wi-fi is redirecting the request to another page until the user logs in">
Connect to Wi-Fi
</message>
<message name="IDS_CAPTIVE_PORTAL_HEADING_WIRED" desc="Heading in the error page when a secure request is blocked because a captive portal is manipulating a wired connection (e.g. ethernet)">
Connect to network Connect to network
</message> </message>
<message name="IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH" desc="The primary explanatory paragraph for the captive portal error page for network connections."> <message name="IDS_CAPTIVE_PORTAL_HEADING_WIFI" desc="Heading in the error page when a secure request is blocked because a captive portal is manipulating a Wi-Fi connection">
Connect to Wi-Fi
</message>
<message name="IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED" desc="The primary explanatory paragraph for the captive portal error page for wired network connections.">
The network you are using may require you to visit <ph name="BEGIN_BOLD">&lt;strong&gt;</ph><ph name="LOGIN_URL">$1<ex>example.com</ex></ph><ph name="END_BOLD">&lt;strong&gt;</ph>. The network you are using may require you to visit <ph name="BEGIN_BOLD">&lt;strong&gt;</ph><ph name="LOGIN_URL">$1<ex>example.com</ex></ph><ph name="END_BOLD">&lt;strong&gt;</ph>.
</message> </message>
<message name="IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL" desc="The primary explanatory paragraph for the captive portal error page for network connections when the captive portal login url isn't available."> <message name="IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI" desc="The primary explanatory paragraph for the captive portal error page for Wi-Fi connections.">
The Wi-Fi you are using may require you to visit <ph name="BEGIN_BOLD">&lt;strong&gt;</ph><ph name="LOGIN_URL">$1<ex>example.com</ex></ph><ph name="END_BOLD">&lt;strong&gt;</ph>.
</message>
<message name="IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED" desc="The primary explanatory paragraph for the captive portal error page for network connections when the captive portal login url isn't available.">
The network you are using may require you to visit its login page. The network you are using may require you to visit its login page.
</message> </message>
<message name="IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI" desc="The primary explanatory paragraph for the captive portal error page for Wi-Fi connections when the captive portal login url isn't available.">
The Wi-Fi you are using may require you to visit its login page.
</message>
<message name="IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE" desc="Text for the open login page button"> <message name="IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE" desc="Text for the open login page button">
Connect Connect
</message> </message>
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
#include "net/base/network_change_notifier.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
...@@ -37,6 +38,15 @@ void RecordUMA(CaptivePortalBlockingPageEvent event) { ...@@ -37,6 +38,15 @@ void RecordUMA(CaptivePortalBlockingPageEvent event) {
CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT);
} }
bool IsWifiConnection() {
// |net::NetworkChangeNotifier::GetConnectionType| isn't accurate on Linux and
// Windows. See https://crbug.com/160537 for details.
// TODO(meacer): Add heuristics to get a more accurate connection type on
// these platforms.
return net::NetworkChangeNotifier::GetConnectionType() ==
net::NetworkChangeNotifier::CONNECTION_WIFI;
}
const char kOpenLoginPageCommand[] = "openLoginPage"; const char kOpenLoginPageCommand[] = "openLoginPage";
} // namespace } // namespace
...@@ -52,6 +62,7 @@ CaptivePortalBlockingPage::CaptivePortalBlockingPage( ...@@ -52,6 +62,7 @@ CaptivePortalBlockingPage::CaptivePortalBlockingPage(
const base::Callback<void(bool)>& callback) const base::Callback<void(bool)>& callback)
: SecurityInterstitialPage(web_contents, request_url), : SecurityInterstitialPage(web_contents, request_url),
login_url_(login_url), login_url_(login_url),
is_wifi_connection_(IsWifiConnection()),
callback_(callback) { callback_(callback) {
DCHECK(login_url_.is_valid()); DCHECK(login_url_.is_valid());
RecordUMA(SHOW_ALL); RecordUMA(SHOW_ALL);
...@@ -84,9 +95,15 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings( ...@@ -84,9 +95,15 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings(
"primaryButtonText", "primaryButtonText",
l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE)); l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE));
load_time_data->SetString("tabTitle", load_time_data->SetString("tabTitle",
l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_TITLE)); l10n_util::GetStringUTF16(
is_wifi_connection_ ?
IDS_CAPTIVE_PORTAL_TITLE_WIFI :
IDS_CAPTIVE_PORTAL_TITLE_WIRED));
load_time_data->SetString("heading", load_time_data->SetString("heading",
l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_HEADING)); l10n_util::GetStringUTF16(
is_wifi_connection_ ?
IDS_CAPTIVE_PORTAL_HEADING_WIFI :
IDS_CAPTIVE_PORTAL_HEADING_WIRED));
if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) { if (login_url_.spec() == captive_portal::CaptivePortalDetector::kDefaultURL) {
// Captive portal may intercept requests without HTTP redirects, in which // Captive portal may intercept requests without HTTP redirects, in which
...@@ -95,7 +112,9 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings( ...@@ -95,7 +112,9 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings(
load_time_data->SetString( load_time_data->SetString(
"primaryParagraph", "primaryParagraph",
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL)); is_wifi_connection_ ?
IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIFI :
IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_NO_LOGIN_URL_WIRED));
} else { } else {
std::string languages; std::string languages;
Profile* profile = Profile::FromBrowserContext( Profile* profile = Profile::FromBrowserContext(
...@@ -108,7 +127,10 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings( ...@@ -108,7 +127,10 @@ void CaptivePortalBlockingPage::PopulateInterstitialStrings(
base::i18n::WrapStringWithLTRFormatting(&login_host); base::i18n::WrapStringWithLTRFormatting(&login_host);
load_time_data->SetString( load_time_data->SetString(
"primaryParagraph", "primaryParagraph",
l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH, l10n_util::GetStringFUTF16(
is_wifi_connection_ ?
IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIFI :
IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH_WIRED,
login_host)); login_host));
} }
......
...@@ -37,6 +37,10 @@ class CaptivePortalBlockingPage : public SecurityInterstitialPage { ...@@ -37,6 +37,10 @@ class CaptivePortalBlockingPage : public SecurityInterstitialPage {
// SecurityInterstitialPage method: // SecurityInterstitialPage method:
const void* GetTypeForTesting() const override; const void* GetTypeForTesting() const override;
void SetWiFiConnectionForTesting(bool is_wifi_connection) {
is_wifi_connection_ = is_wifi_connection;
}
protected: protected:
// SecurityInterstitialPage methods: // SecurityInterstitialPage methods:
void PopulateInterstitialStrings( void PopulateInterstitialStrings(
...@@ -49,6 +53,8 @@ class CaptivePortalBlockingPage : public SecurityInterstitialPage { ...@@ -49,6 +53,8 @@ class CaptivePortalBlockingPage : public SecurityInterstitialPage {
private: private:
// URL of the login page, opened when the user clicks the "Connect" button. // URL of the login page, opened when the user clicks the "Connect" button.
GURL login_url_; GURL login_url_;
// True if on a Wi-Fi connection.
bool is_wifi_connection_;
base::Callback<void(bool)> callback_; base::Callback<void(bool)> callback_;
DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPage); DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPage);
......
...@@ -53,6 +53,48 @@ class CaptivePortalBlockingPageTest : public InProcessBrowserTest { ...@@ -53,6 +53,48 @@ class CaptivePortalBlockingPageTest : public InProcessBrowserTest {
DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPageTest); DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPageTest);
}; };
// If the connection is not a Wi-Fi connection, the wired network version of the
// captive portal interstitial should be displayed.
IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
ShowWiredNetworkInterstitial) {
const GURL kLandingUrl("http://captive.portal/landing_url");
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
DCHECK(contents);
// Blocking page is owned by the interstitial.
CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>());
blocking_page->SetWiFiConnectionForTesting(false);
blocking_page->Show();
WaitForInterstitialAttach(contents);
EXPECT_TRUE(
WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame()));
EXPECT_FALSE(
IsInterstitialDisplayingText(contents->GetInterstitialPage(), "Wi-Fi"));
}
// If the connection is a Wi-Fi connection, the Wi-Fi version of the captive
// portal interstitial should be displayed.
IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
ShowWiFiInterstitial) {
const GURL kLandingUrl("http://captive.portal/landing_url");
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
DCHECK(contents);
// Blocking page is owned by the interstitial.
CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>());
blocking_page->SetWiFiConnectionForTesting(true);
blocking_page->Show();
WaitForInterstitialAttach(contents);
EXPECT_TRUE(
WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame()));
EXPECT_TRUE(
IsInterstitialDisplayingText(contents->GetInterstitialPage(), "Wi-Fi"));
}
// The captive portal interstitial should show the login url if the login url // The captive portal interstitial should show the login url if the login url
// is different than the captive portal ping url (i.e. the portal intercepts // is different than the captive portal ping url (i.e. the portal intercepts
// requests via HTTP redirects). // requests via HTTP redirects).
...@@ -65,6 +107,7 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, ...@@ -65,6 +107,7 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
// Blocking page is owned by the interstitial. // Blocking page is owned by the interstitial.
CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>());
blocking_page->SetWiFiConnectionForTesting(false);
blocking_page->Show(); blocking_page->Show();
WaitForInterstitialAttach(contents); WaitForInterstitialAttach(contents);
...@@ -89,6 +132,7 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest, ...@@ -89,6 +132,7 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageTest,
// Blocking page is owned by the interstitial. // Blocking page is owned by the interstitial.
CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>()); contents, GURL(kBrokenSSL), kLandingUrl, base::Callback<void(bool)>());
blocking_page->SetWiFiConnectionForTesting(false);
blocking_page->Show(); blocking_page->Show();
WaitForInterstitialAttach(contents); WaitForInterstitialAttach(contents);
...@@ -130,6 +174,7 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageIDNTest, ...@@ -130,6 +174,7 @@ IN_PROC_BROWSER_TEST_F(CaptivePortalBlockingPageIDNTest,
// Blocking page is owned by the interstitial. // Blocking page is owned by the interstitial.
CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage( CaptivePortalBlockingPage* blocking_page = new CaptivePortalBlockingPage(
contents, GURL(kBrokenSSL), landing_url, base::Callback<void(bool)>()); contents, GURL(kBrokenSSL), landing_url, base::Callback<void(bool)>());
blocking_page->SetWiFiConnectionForTesting(false);
blocking_page->Show(); blocking_page->Show();
WaitForInterstitialAttach(contents); WaitForInterstitialAttach(contents);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment