Commit 272208f4 authored by Mike Pinkerton's avatar Mike Pinkerton Committed by Commit Bot

Add title to iPadOS app switcher.

Adds the domain of the frontmost tab along with the number of tabs
in the window to the UIScene's title, which gets displayed in the
OS-level application switcher next to the application name.

BUG=1132344
TEST=Will show only the domain for a single tab, and correctly
pluralized strings of the number of other tabs when there are
more than one.

Change-Id: Iba8da572f8e042c8ab47092304a729b1b3de8bf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435939
Commit-Queue: Mark Cogan <marq@chromium.org>
Auto-Submit: Mike Pinkerton <pinkerton@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811783}
parent 2ed6b5ec
......@@ -2632,6 +2632,12 @@ New Search
<message name="IDS_IOS_UI_BLOCKED_USE_OTHER_WINDOW_SWITCH_WINDOW_ACTION" desc="Button label that appears on a button to switch to some other window, when the user has multiple windows open, and one window is showing a dialog that has to be interacted with before any other window can be used.">
Switch to Open Window
</message>
<message name="IDS_IOS_APP_SWITCHER_SCENE_TITLE" desc="Shown under the Application title in the OS-level app switcher with the number of tabs in the window">
{count, plural,
=0 {{domain}}
=1 {{domain} and 1 other}
other {{domain} and {count} others}}
</message>
</messages>
</release>
</grit>
0d6a392c1f8ef7d04ce5ccfb4d543d84ee5df0d2
\ No newline at end of file
......@@ -74,6 +74,7 @@ source_set("scene") {
"//ios/chrome/app/application_delegate:app_state_header",
"//ios/chrome/app/application_delegate:tab_opening",
"//ios/chrome/app/application_delegate:url_opener_params",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser",
"//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/browser_state",
......@@ -114,6 +115,7 @@ source_set("scene") {
"//ios/public/provider/chrome/browser/mailto",
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/user_feedback",
"//ui/base:base",
]
public_deps = [
":scene_state_header",
......
......@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/main/scene_controller.h"
#include "base/bind_helpers.h"
#include "base/i18n/message_formatter.h"
#import "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
......@@ -81,6 +82,7 @@
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
#import "ios/chrome/browser/window_activities/window_activity_helpers.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#include "ios/public/provider/chrome/browser/mailto/mailto_handler_provider.h"
#include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
......@@ -88,6 +90,7 @@
#include "ios/web/public/thread/web_task_traits.h"
#import "ios/web/public/web_state.h"
#import "net/base/mac/url_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -313,6 +316,14 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
}
}
// When the scene transitions to inactive (such as when it's being shown in
// the OS app-switcher), update the title for display on iPadOS.
if (@available(iOS 13, *)) {
if (level == SceneActivationLevelForegroundInactive) {
sceneState.scene.title = [self displayTitleForAppSwitcher];
}
}
if (level == SceneActivationLevelForegroundActive) {
if (![self presentSigninUpgradePromoIfPossible]) {
[self presentSignInAccountsViewControllerIfNecessary];
......@@ -732,6 +743,35 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
[self.sceneState.appState removeObserver:self];
}
// Formats string for display on iPadOS application switcher with the
// domain of the foreground tab and the tab count. Assumes the scene is
// visible. Will return nil if there are no tabs.
- (NSString*)displayTitleForAppSwitcher {
DCHECK(self.currentInterface.browser);
web::WebState* webState =
self.currentInterface.browser->GetWebStateList()->GetActiveWebState();
if (!webState)
return nil;
// At this point there is at least one tab.
int numberOfTabs = self.currentInterface.browser->GetWebStateList()->count();
DCHECK(numberOfTabs > 0);
GURL url = webState->GetVisibleURL();
base::string16 urlText = url_formatter::FormatUrl(
url,
url_formatter::kFormatUrlOmitDefaults |
url_formatter::kFormatUrlOmitTrivialSubdomains |
url_formatter::kFormatUrlOmitHTTPS |
url_formatter::kFormatUrlTrimAfterHost,
net::UnescapeRule::SPACES, nullptr, nullptr, nullptr);
base::string16 pattern =
l10n_util::GetStringUTF16(IDS_IOS_APP_SWITCHER_SCENE_TITLE);
base::string16 formattedTitle =
base::i18n::MessageFormatter::FormatWithNamedArgs(
pattern, "domain", urlText, "count", numberOfTabs - 1);
return base::SysUTF16ToNSString(formattedTitle);
}
#pragma mark - First Run
// Initializes the first run UI and presents it to the user.
......
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