Commit 7784def0 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Restrict access to profile type to reduce possible misuses.

Profile::GetProfileType() is made protected to persuade usage of
profile type functions (IsRegularProfile, IsIncognito, IsGuestProfile).

Bug: 947933
Change-Id: Ie049488fa714002b3a0372946040fef82672d440
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1611986Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661299}
parent ade0f560
...@@ -1713,7 +1713,7 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session; ...@@ -1713,7 +1713,7 @@ static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
// Handoff is not allowed from an incognito profile. To err on the safe side, // Handoff is not allowed from an incognito profile. To err on the safe side,
// also disallow Handoff from a guest profile. // also disallow Handoff from a guest profile.
if (profile->GetProfileType() != Profile::REGULAR_PROFILE) if (!profile->IsRegularProfile())
return GURL(); return GURL();
if (!webContents) if (!webContents)
......
...@@ -401,8 +401,7 @@ bool ChromeAutocompleteProviderClient::IsTabOpenWithURL( ...@@ -401,8 +401,7 @@ bool ChromeAutocompleteProviderClient::IsTabOpenWithURL(
active_tab = active_browser->tab_strip_model()->GetActiveWebContents(); active_tab = active_browser->tab_strip_model()->GetActiveWebContents();
for (auto* browser : *BrowserList::GetInstance()) { for (auto* browser : *BrowserList::GetInstance()) {
// Only look at same profile (and anonymity level). // Only look at same profile (and anonymity level).
if (browser->profile()->IsSameProfile(profile_) && if (browser->profile()->IsSameProfileAndType(profile_)) {
browser->profile()->GetProfileType() == profile_->GetProfileType()) {
for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
content::WebContents* web_contents = content::WebContents* web_contents =
browser->tab_strip_model()->GetWebContentsAt(i); browser->tab_strip_model()->GetWebContentsAt(i);
......
...@@ -82,8 +82,7 @@ scoped_refptr<RefcountedKeyedService> ...@@ -82,8 +82,7 @@ scoped_refptr<RefcountedKeyedService>
} }
scoped_refptr<HostContentSettingsMap> settings_map(new HostContentSettingsMap( scoped_refptr<HostContentSettingsMap> settings_map(new HostContentSettingsMap(
profile->GetPrefs(), profile->IsIncognito(), profile->GetPrefs(), profile->IsIncognito(), profile->IsGuestProfile(),
profile->GetProfileType() == Profile::GUEST_PROFILE,
/*store_last_modified=*/true, /*store_last_modified=*/true,
base::FeatureList::IsEnabled(features::kPermissionDelegation))); base::FeatureList::IsEnabled(features::kPermissionDelegation)));
......
...@@ -605,11 +605,8 @@ void MediaEngagementContentsObserver::ReadyToCommitNavigation( ...@@ -605,11 +605,8 @@ void MediaEngagementContentsObserver::ReadyToCommitNavigation(
content::WebContents* MediaEngagementContentsObserver::GetOpener() const { content::WebContents* MediaEngagementContentsObserver::GetOpener() const {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
for (auto* browser : *BrowserList::GetInstance()) { for (auto* browser : *BrowserList::GetInstance()) {
if (!browser->profile()->IsSameProfile(service_->profile()) || if (!browser->profile()->IsSameProfileAndType(service_->profile()))
browser->profile()->GetProfileType() !=
service_->profile()->GetProfileType()) {
continue; continue;
}
int index = int index =
browser->tab_strip_model()->GetIndexOfWebContents(web_contents()); browser->tab_strip_model()->GetIndexOfWebContents(web_contents());
......
...@@ -250,7 +250,7 @@ void OffTheRecordProfileImpl::InitIoData() { ...@@ -250,7 +250,7 @@ void OffTheRecordProfileImpl::InitIoData() {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() { void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() {
DCHECK_NE(INCOGNITO_PROFILE, profile_->GetProfileType()); DCHECK(!profile_->IsIncognito());
// Here we only want to use zoom levels stored in the main-context's default // Here we only want to use zoom levels stored in the main-context's default
// storage partition. We're not interested in zoom levels in special // storage partition. We're not interested in zoom levels in special
......
...@@ -237,6 +237,10 @@ bool Profile::IsIncognito() const { ...@@ -237,6 +237,10 @@ bool Profile::IsIncognito() const {
return GetProfileType() == INCOGNITO_PROFILE; return GetProfileType() == INCOGNITO_PROFILE;
} }
bool Profile::IsGuestProfile() const {
return GetProfileType() == GUEST_PROFILE;
}
bool Profile::IsGuestSession() const { bool Profile::IsGuestSession() const {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
static bool is_guest_session = static bool is_guest_session =
......
...@@ -56,6 +56,8 @@ namespace user_prefs { ...@@ -56,6 +56,8 @@ namespace user_prefs {
class PrefRegistrySyncable; class PrefRegistrySyncable;
} }
class OffTheRecordProfileIOData;
// Instead of adding more members to Profile, consider creating a // Instead of adding more members to Profile, consider creating a
// KeyedService. See // KeyedService. See
// http://dev.chromium.org/developers/design-documents/profile-architecture // http://dev.chromium.org/developers/design-documents/profile-architecture
...@@ -146,9 +148,6 @@ class Profile : public content::BrowserContext { ...@@ -146,9 +148,6 @@ class Profile : public content::BrowserContext {
// implementations, this is usually the Google-services email address. // implementations, this is usually the Google-services email address.
virtual std::string GetProfileUserName() const = 0; virtual std::string GetProfileUserName() const = 0;
// Returns the profile type.
virtual ProfileType GetProfileType() const = 0;
// Return the incognito version of this profile. The returned pointer // Return the incognito version of this profile. The returned pointer
// is owned by the receiving profile. If the receiving profile is off the // is owned by the receiving profile. If the receiving profile is off the
// record, the same profile is returned. // record, the same profile is returned.
...@@ -228,6 +227,12 @@ class Profile : public content::BrowserContext { ...@@ -228,6 +227,12 @@ class Profile : public content::BrowserContext {
// versa). // versa).
virtual bool IsSameProfile(Profile* profile) = 0; virtual bool IsSameProfile(Profile* profile) = 0;
// Returns whether two profiles are the same and of the same type.
bool IsSameProfileAndType(Profile* profile) {
return IsSameProfile(profile) &&
GetProfileType() == profile->GetProfileType();
}
// Returns the time the profile was started. This is not the time the profile // Returns the time the profile was started. This is not the time the profile
// was created, rather it is the time the user started chrome and logged into // was created, rather it is the time the user started chrome and logged into
// this profile. For the single profile case, this corresponds to the time // this profile. For the single profile case, this corresponds to the time
...@@ -302,15 +307,25 @@ class Profile : public content::BrowserContext { ...@@ -302,15 +307,25 @@ class Profile : public content::BrowserContext {
std::string GetDebugName(); std::string GetDebugName();
// Returns whether it's a regular profile. Short-hand for GetProfileType() == // IsRegularProfile(), IsIncognito(), and IsGuestProfile() are mutually
// REGULAR_PROFILE. // exclusive.
// IsSystemProfile() implies that IsRegularProfile() is true.
// IsOffTheRecord() is an equivalent of IsIncognito() || IsGuestProfile().
// Returns whether it's a regular profile.
bool IsRegularProfile() const; bool IsRegularProfile() const;
// Returns whether it is an Incognito session. An Incognito session is an // Returns whether it is an Incognito profile. An Incognito profile is an
// off-the-record session that is not a guest session. // off-the-record profile that is not a guest profile.
// TODO(https://crbug.com/947933): Replace with IsIncognitProfile.
bool IsIncognito() const; bool IsIncognito() const;
// Returns whether it is a guest session. // Returns whether it is a Guest profile. A Guest profile is an off-the-record
// profile in a guest session.
bool IsGuestProfile() const;
// Returns whether it is a guest session. This covers both the guest profile
// and its parent.
virtual bool IsGuestSession() const; virtual bool IsGuestSession() const;
// Returns whether it is a system profile. // Returns whether it is a system profile.
...@@ -391,6 +406,11 @@ class Profile : public content::BrowserContext { ...@@ -391,6 +406,11 @@ class Profile : public content::BrowserContext {
void Wipe(); void Wipe();
protected: protected:
friend class OffTheRecordProfileIOData;
// Returns the profile type.
virtual ProfileType GetProfileType() const = 0;
void set_is_guest_profile(bool is_guest_profile) { void set_is_guest_profile(bool is_guest_profile) {
is_guest_profile_ = is_guest_profile; is_guest_profile_ = is_guest_profile;
} }
......
...@@ -72,7 +72,7 @@ void RestoreTabUsingProfile(Profile* profile) { ...@@ -72,7 +72,7 @@ void RestoreTabUsingProfile(Profile* profile) {
bool IsIncognitoAllowed() { bool IsIncognitoAllowed() {
Profile* profile = ProfileManager::GetActiveUserProfile(); Profile* profile = ProfileManager::GetActiveUserProfile();
return profile && profile->GetProfileType() != Profile::GUEST_PROFILE && return profile && !profile->IsGuestProfile() &&
IncognitoModePrefs::GetAvailability(profile->GetPrefs()) != IncognitoModePrefs::GetAvailability(profile->GetPrefs()) !=
IncognitoModePrefs::DISABLED; IncognitoModePrefs::DISABLED;
} }
......
...@@ -169,8 +169,7 @@ std::pair<Browser*, int> GetBrowserAndTabForDisposition( ...@@ -169,8 +169,7 @@ std::pair<Browser*, int> GetBrowserAndTabForDisposition(
++browser_it) { ++browser_it) {
Browser* browser = *browser_it; Browser* browser = *browser_it;
// When tab switching, only look at same profile and anonymity level. // When tab switching, only look at same profile and anonymity level.
if (browser->profile()->IsSameProfile(profile) && if (browser->profile()->IsSameProfileAndType(profile)) {
browser->profile()->GetProfileType() == profile->GetProfileType()) {
int index = GetIndexOfExistingTab(browser, params); int index = GetIndexOfExistingTab(browser, params);
if (index >= 0) if (index >= 0)
return {browser, index}; return {browser, index};
......
...@@ -337,8 +337,7 @@ bool ChromeAuthenticatorRequestDelegate::IsWebAuthnUIEnabled() { ...@@ -337,8 +337,7 @@ bool ChromeAuthenticatorRequestDelegate::IsWebAuthnUIEnabled() {
bool ChromeAuthenticatorRequestDelegate::ShouldDisablePlatformAuthenticators() { bool ChromeAuthenticatorRequestDelegate::ShouldDisablePlatformAuthenticators() {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
// Touch ID is available in Incognito, but not in Guest mode. // Touch ID is available in Incognito, but not in Guest mode.
return Profile::FromBrowserContext(browser_context())->GetProfileType() == return Profile::FromBrowserContext(browser_context())->IsGuestProfile();
Profile::ProfileType::GUEST_PROFILE;
#else // Windows, Android #else // Windows, Android
return browser_context()->IsOffTheRecord(); return browser_context()->IsOffTheRecord();
#endif #endif
......
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