Commit f4a513cb authored by dalyk's avatar dalyk Committed by Commit Bot

Give captive portal popup windows a special window title.

The phrase "Network Sign-in" will be included in the window title to
indicate the purpose of these windows. The position of the phrase
depends on the platform so that existing window title formatting
patterns are preserved.

Bug: 10161646
Change-Id: If49bb5fef304346488cb56cf11d5a043ccb473c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2081333
Commit-Queue: Katharine Daly <dalyk@google.com>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747551}
parent 2356b78e
......@@ -235,6 +235,24 @@ If you update this file, be sure also to update google_chrome_strings.grd. -->
Chromium - <ph name="PAGE_TITLE">$1<ex>Google</ex></ph>
</message>
</if>
<if expr="not chromeos and not is_macosx">
<!-- Captive Portal Browser Window Title Format -->
<message name="IDS_CAPTIVE_PORTAL_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for titles displayed in captive portal popup windows">
<ph name="PAGE_TITLE">$1<ex>Google</ex></ph> - Network Sign-in - Chromium
</message>
</if>
<if expr="chromeos">
<!-- Captive Portal Browser Window Title Format -->
<message name="IDS_CAPTIVE_PORTAL_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for titles displayed in captive portal popup windows">
Chromium - Network Sign-in - <ph name="PAGE_TITLE">$1<ex>Google</ex></ph>
</message>
</if>
<if expr="is_macosx">
<!-- Captive Portal Browser Window Title Format -->
<message name="IDS_CAPTIVE_PORTAL_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for titles displayed in captive portal popup windows">
<ph name="PAGE_TITLE">$1<ex>Google</ex></ph> - Network Sign-in
</message>
</if>
<!-- Accessible window title format - includes the channel, and the same
on all browser platforms rather than different on Chrome OS. -->
<message name="IDS_ACCESSIBLE_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for the accessible name of a tabbed browser window">
......
......@@ -241,6 +241,24 @@ chromium_strings.grd. -->
Chrome - <ph name="PAGE_TITLE">$1<ex>Google</ex></ph>
</message>
</if>
<if expr="not chromeos and not is_macosx">
<!-- Captive Portal Browser Window Title Format -->
<message name="IDS_CAPTIVE_PORTAL_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for titles displayed in captive portal popup windows">
<ph name="PAGE_TITLE">$1<ex>Google</ex></ph> - Network Sign-in - Chrome
</message>
</if>
<if expr="chromeos">
<!-- Captive Portal Browser Window Title Format -->
<message name="IDS_CAPTIVE_PORTAL_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for titles displayed in captive portal popup windows">
Chrome - Network Sign-in - <ph name="PAGE_TITLE">$1<ex>Google</ex></ph>
</message>
</if>
<if expr="is_macosx">
<!-- Captive Portal Browser Window Title Format -->
<message name="IDS_CAPTIVE_PORTAL_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for titles displayed in captive portal popup windows">
<ph name="PAGE_TITLE">$1<ex>Google</ex></ph> - Network Sign-in
</message>
</if>
<!-- Accessible window title format - includes the channel, and the same
on all browser platforms rather than different on Chrome OS. -->
<message name="IDS_ACCESSIBLE_BROWSER_WINDOW_TITLE_FORMAT" desc="The format for the accessible name of a tabbed browser window">
......
......@@ -163,6 +163,7 @@
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/bubble/bubble_controller.h"
#include "components/captive_portal/core/buildflags.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/favicon/content/content_favicon_driver.h"
#include "components/find_in_page/find_tab_helper.h"
......@@ -251,6 +252,10 @@
#include "components/session_manager/core/session_manager.h"
#endif
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
#include "components/captive_portal/content/captive_portal_tab_helper.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/extension_browser_window_helper.h"
#endif
......@@ -798,6 +803,21 @@ base::string16 Browser::GetWindowTitleFromWebContents(
if (contents) {
title = FormatTitleForDisplay(app_controller_ ? app_controller_->GetTitle()
: contents->GetTitle());
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
// If the app name is requested and this is a captive portal window, the
// title should indicate that this is a captive portal window. Captive
// portal windows should always be pop-ups, and the is_captive_portal_window
// condition should not change over the lifetime of a WebContents.
if (include_app_name &&
captive_portal::CaptivePortalTabHelper::FromWebContents(contents) &&
captive_portal::CaptivePortalTabHelper::FromWebContents(contents)
->is_captive_portal_window()) {
DCHECK(is_type_popup());
return l10n_util::GetStringFUTF16(
IDS_CAPTIVE_PORTAL_BROWSER_WINDOW_TITLE_FORMAT,
title.empty() ? CoreTabHelper::GetDefaultTitle() : title);
}
#endif
}
// If there is no title, leave it empty for apps.
......
......@@ -71,6 +71,7 @@
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/captive_portal/core/buildflags.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/embedder_support/switches.h"
#include "components/javascript_dialogs/app_modal_dialog_controller.h"
......@@ -451,6 +452,35 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, Title) {
EXPECT_EQ(test_title, tab_title);
}
#if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
// Check that the title is different when a page is opened in a captive portal
// window.
IN_PROC_BROWSER_TEST_F(BrowserTest, CaptivePortalWindowTitle) {
const GURL url = ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(kTitle2File));
NavigateParams captive_portal_params(browser(), url,
ui::PAGE_TRANSITION_TYPED);
captive_portal_params.disposition = WindowOpenDisposition::NEW_POPUP;
captive_portal_params.is_captive_portal_popup = true;
ui_test_utils::NavigateToURL(&captive_portal_params);
base::string16 captive_portal_window_title =
chrome::FindBrowserWithWebContents(
captive_portal_params.navigated_or_inserted_contents)
->GetWindowTitleForCurrentTab(true /* include_app_name */);
NavigateParams normal_params(browser(), url, ui::PAGE_TRANSITION_TYPED);
normal_params.disposition = WindowOpenDisposition::NEW_POPUP;
ui_test_utils::NavigateToURL(&normal_params);
base::string16 normal_window_title =
chrome::FindBrowserWithWebContents(
normal_params.navigated_or_inserted_contents)
->GetWindowTitleForCurrentTab(true /* include_app_name */);
ASSERT_NE(captive_portal_window_title, normal_window_title);
}
#endif
IN_PROC_BROWSER_TEST_F(BrowserTest, NoJavaScriptDialogsActivateTab) {
// Set up two tabs, with the tab at index 0 active.
GURL url(ui_test_utils::GetTestUrl(
......
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