Commit 45e270e9 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update Browser commands for Ephemeral Guest profiles.

Updates a few chrome/ui classes for compatibility with ephemeral Guest
profiles. Ephemeral guest profiles are not off-the-record and cannot
open an Incognito window or have bookmarks, but they have history
and Recent Tabs menu, and Clear Browsing Data option.

Please see go/guest-on-disk for more context.

Bug: 1125474
Change-Id: I8a1f6ceb03d4c72f310b225211728f8eaeb0d296
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2449250Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815586}
parent 1089a4c4
...@@ -144,10 +144,7 @@ void OffTheRecordProfileImpl::Init() { ...@@ -144,10 +144,7 @@ void OffTheRecordProfileImpl::Init() {
// Must be done before CreateBrowserContextServices(), since some of them // Must be done before CreateBrowserContextServices(), since some of them
// change behavior based on whether the provided context is a guest session. // change behavior based on whether the provided context is a guest session.
// TODO(https://crbug.com/1125474): Remove |IsEphemeralGuestProfile| when set_is_guest_profile(profile_->IsGuestSession());
// Incognito is disabled for ephemeral Guest profiles.
set_is_guest_profile(profile_->IsGuestSession() ||
profile_->IsEphemeralGuestProfile());
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this); this);
......
...@@ -372,10 +372,7 @@ bool Profile::IsRegularProfile() const { ...@@ -372,10 +372,7 @@ bool Profile::IsRegularProfile() const {
} }
bool Profile::IsIncognitoProfile() const { bool Profile::IsIncognitoProfile() const {
// TODO(https://crbug.com/1125474): Remove |IsEphemeralGuestProfile| when return IsPrimaryOTRProfile() && !IsGuestSession();
// Incognito is disabled for ephemeral Guest profiles.
return IsPrimaryOTRProfile() && !IsGuestSession() &&
!IsEphemeralGuestProfile();
} }
// static // static
......
...@@ -59,7 +59,7 @@ bool BookmarkTabHelper::ShouldShowBookmarkBar() const { ...@@ -59,7 +59,7 @@ bool BookmarkTabHelper::ShouldShowBookmarkBar() const {
Profile::FromBrowserContext(web_contents()->GetBrowserContext()); Profile::FromBrowserContext(web_contents()->GetBrowserContext());
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
if (profile->IsGuestSession()) if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile())
return false; return false;
#endif #endif
......
...@@ -973,19 +973,20 @@ Browser::DownloadCloseType Browser::OkToCloseWithInProgressDownloads( ...@@ -973,19 +973,20 @@ Browser::DownloadCloseType Browser::OkToCloseWithInProgressDownloads(
return DownloadCloseType::kBrowserShutdown; return DownloadCloseType::kBrowserShutdown;
} }
// If there aren't any other windows on our profile, and we're an incognito // If there aren't any other windows on our profile, and we're an Incognito
// profile, and there are downloads associated with that profile, // or Guest profile, and there are downloads associated with that profile,
// those downloads would be cancelled by our window (-> profile) close. // those downloads would be cancelled by our window (-> profile) close.
DownloadCoreService* download_core_service = DownloadCoreService* download_core_service =
DownloadCoreServiceFactory::GetForBrowserContext(profile()); DownloadCoreServiceFactory::GetForBrowserContext(profile());
bool is_guest =
(profile()->IsGuestSession() || profile()->IsEphemeralGuestProfile());
if ((profile_window_count == 0) && if ((profile_window_count == 0) &&
(download_core_service->NonMaliciousDownloadCount() > 0) && (download_core_service->NonMaliciousDownloadCount() > 0) &&
profile()->IsOffTheRecord()) { (profile()->IsIncognitoProfile() || is_guest)) {
*num_downloads_blocking = *num_downloads_blocking =
download_core_service->NonMaliciousDownloadCount(); download_core_service->NonMaliciousDownloadCount();
return profile()->IsGuestSession() return is_guest ? DownloadCloseType::kLastWindowInGuestSession
? DownloadCloseType::kLastWindowInGuestSession : DownloadCloseType::kLastWindowInIncognitoProfile;
: DownloadCloseType::kLastWindowInIncognitoProfile;
} }
// Those are the only conditions under which we will block shutdown. // Those are the only conditions under which we will block shutdown.
...@@ -2133,7 +2134,9 @@ void Browser::RequestPpapiBrokerPermission( ...@@ -2133,7 +2134,9 @@ void Browser::RequestPpapiBrokerPermission(
Profile* profile = Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext()); Profile::FromBrowserContext(web_contents->GetBrowserContext());
// TODO(wad): Add ephemeral device ID support for broker in guest mode. // TODO(wad): Add ephemeral device ID support for broker in guest mode.
if (profile->IsGuestSession()) { // TODO(https://crbug.com/1125474): Update if PPAPI is supported in ephemeral
// Guest profiles.
if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile()) {
std::move(callback).Run(false); std::move(callback).Run(false);
return; return;
} }
...@@ -2996,7 +2999,7 @@ void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { ...@@ -2996,7 +2999,7 @@ void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) {
} }
bool Browser::ShouldShowBookmarkBar() const { bool Browser::ShouldShowBookmarkBar() const {
if (profile_->IsGuestSession()) if (profile_->IsGuestSession() || profile()->IsEphemeralGuestProfile())
return false; return false;
if (browser_defaults::bookmarks_enabled && if (browser_defaults::bookmarks_enabled &&
......
...@@ -962,26 +962,32 @@ void BrowserCommandController::InitCommandState() { ...@@ -962,26 +962,32 @@ void BrowserCommandController::InitCommandState() {
command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
// Show various bits of UI // Show various bits of UI
const bool guest_session =
profile()->IsGuestSession() || profile()->IsSystemProfile();
DCHECK(!profile()->IsSystemProfile()) DCHECK(!profile()->IsSystemProfile())
<< "Ought to never have browser for the system profile."; << "Ought to never have browser for the system profile.";
const bool normal_window = browser_->is_type_normal(); const bool normal_window = browser_->is_type_normal();
UpdateOpenFileState(&command_updater_); UpdateOpenFileState(&command_updater_);
UpdateCommandsForDevTools(); UpdateCommandsForDevTools();
command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager()); command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session); command_updater_.UpdateCommandEnabled(
IDC_SHOW_HISTORY,
(!profile()->IsGuestSession() && !profile()->IsSystemProfile()));
command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true); command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true); command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
command_updater_.UpdateCommandEnabled( command_updater_.UpdateCommandEnabled(
IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord()); IDC_BOOKMARKS_MENU,
(!profile()->IsGuestSession() && !profile()->IsSystemProfile() &&
!profile()->IsEphemeralGuestProfile()));
command_updater_.UpdateCommandEnabled(
IDC_RECENT_TABS_MENU,
(!profile()->IsGuestSession() && !profile()->IsSystemProfile() &&
!profile()->IsIncognitoProfile()));
command_updater_.UpdateCommandEnabled( command_updater_.UpdateCommandEnabled(
IDC_CLEAR_BROWSING_DATA, IDC_CLEAR_BROWSING_DATA,
!guest_session && !profile()->IsIncognitoProfile()); (!profile()->IsGuestSession() && !profile()->IsSystemProfile() &&
!profile()->IsIncognitoProfile()));
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true); command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
// Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu
...@@ -1066,19 +1072,18 @@ void BrowserCommandController::InitCommandState() { ...@@ -1066,19 +1072,18 @@ void BrowserCommandController::InitCommandState() {
void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
CommandUpdater* command_updater, CommandUpdater* command_updater,
Profile* profile) { Profile* profile) {
const bool guest_session = profile->IsGuestSession();
// TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
IncognitoModePrefs::Availability incognito_availability = IncognitoModePrefs::Availability incognito_availability =
IncognitoModePrefs::GetAvailability(profile->GetPrefs()); IncognitoModePrefs::GetAvailability(profile->GetPrefs());
command_updater->UpdateCommandEnabled( command_updater->UpdateCommandEnabled(
IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED); IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
command_updater->UpdateCommandEnabled( command_updater->UpdateCommandEnabled(
IDC_NEW_INCOGNITO_WINDOW, IDC_NEW_INCOGNITO_WINDOW,
incognito_availability != IncognitoModePrefs::DISABLED && !guest_session); incognito_availability != IncognitoModePrefs::DISABLED &&
!profile->IsGuestSession() && !profile->IsEphemeralGuestProfile());
const bool forced_incognito = const bool forced_incognito =
incognito_availability == IncognitoModePrefs::FORCED || incognito_availability == IncognitoModePrefs::FORCED ||
guest_session; // Guest always runs in Incognito mode. profile->IsGuestSession(); // Guest always runs in Incognito mode.
command_updater->UpdateCommandEnabled( command_updater->UpdateCommandEnabled(
IDC_SHOW_BOOKMARK_MANAGER, IDC_SHOW_BOOKMARK_MANAGER,
browser_defaults::bookmarks_enabled && !forced_incognito); browser_defaults::bookmarks_enabled && !forced_incognito);
...@@ -1095,8 +1100,8 @@ void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability( ...@@ -1095,8 +1100,8 @@ void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
enable_extensions && !forced_incognito); enable_extensions && !forced_incognito);
command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito); command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
command_updater->UpdateCommandEnabled(IDC_OPTIONS, command_updater->UpdateCommandEnabled(
!forced_incognito || guest_session); IDC_OPTIONS, !forced_incognito || profile->IsGuestSession());
command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito); command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
} }
...@@ -1242,6 +1247,7 @@ void BrowserCommandController::UpdateCommandsForBookmarkBar() { ...@@ -1242,6 +1247,7 @@ void BrowserCommandController::UpdateCommandsForBookmarkBar() {
command_updater_.UpdateCommandEnabled( command_updater_.UpdateCommandEnabled(
IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled && IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
!profile()->IsGuestSession() && !profile()->IsGuestSession() &&
!profile()->IsEphemeralGuestProfile() &&
!profile()->IsSystemProfile() && !profile()->IsSystemProfile() &&
!profile()->GetPrefs()->IsManagedPreference( !profile()->GetPrefs()->IsManagedPreference(
bookmarks::prefs::kShowBookmarkBar) && bookmarks::prefs::kShowBookmarkBar) &&
......
...@@ -93,7 +93,8 @@ void BrowserList::AddBrowser(Browser* browser) { ...@@ -93,7 +93,8 @@ void BrowserList::AddBrowser(Browser* browser) {
if (browser->window()->IsActive()) if (browser->window()->IsActive())
SetLastActive(browser); SetLastActive(browser);
if (browser->profile()->IsGuestSession()) { if (browser->profile()->IsGuestSession() ||
browser->profile()->IsEphemeralGuestProfile()) {
base::UmaHistogramCounts100( base::UmaHistogramCounts100(
"Browser.WindowCount.Guest", "Browser.WindowCount.Guest",
GetOffTheRecordBrowsersActiveForProfile(browser->profile())); GetOffTheRecordBrowsersActiveForProfile(browser->profile()));
...@@ -351,7 +352,9 @@ size_t BrowserList::GetIncognitoBrowserCount() { ...@@ -351,7 +352,9 @@ size_t BrowserList::GetIncognitoBrowserCount() {
size_t BrowserList::GetGuestBrowserCount() { size_t BrowserList::GetGuestBrowserCount() {
BrowserList* list = BrowserList::GetInstance(); BrowserList* list = BrowserList::GetInstance();
return std::count_if(list->begin(), list->end(), [](Browser* browser) { return std::count_if(list->begin(), list->end(), [](Browser* browser) {
return browser->profile()->IsGuestSession() && !browser->is_type_devtools(); return (browser->profile()->IsGuestSession() ||
browser->profile()->IsEphemeralGuestProfile()) &&
!browser->is_type_devtools();
}); });
} }
......
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