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;
// Handoff is not allowed from an incognito profile. To err on the safe side,
// also disallow Handoff from a guest profile.
if (profile->GetProfileType() != Profile::REGULAR_PROFILE)
if (!profile->IsRegularProfile())
return GURL();
if (!webContents)
......
......@@ -401,8 +401,7 @@ bool ChromeAutocompleteProviderClient::IsTabOpenWithURL(
active_tab = active_browser->tab_strip_model()->GetActiveWebContents();
for (auto* browser : *BrowserList::GetInstance()) {
// Only look at same profile (and anonymity level).
if (browser->profile()->IsSameProfile(profile_) &&
browser->profile()->GetProfileType() == profile_->GetProfileType()) {
if (browser->profile()->IsSameProfileAndType(profile_)) {
for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
content::WebContents* web_contents =
browser->tab_strip_model()->GetWebContentsAt(i);
......
......@@ -82,8 +82,7 @@ scoped_refptr<RefcountedKeyedService>
}
scoped_refptr<HostContentSettingsMap> settings_map(new HostContentSettingsMap(
profile->GetPrefs(), profile->IsIncognito(),
profile->GetProfileType() == Profile::GUEST_PROFILE,
profile->GetPrefs(), profile->IsIncognito(), profile->IsGuestProfile(),
/*store_last_modified=*/true,
base::FeatureList::IsEnabled(features::kPermissionDelegation)));
......
......@@ -605,11 +605,8 @@ void MediaEngagementContentsObserver::ReadyToCommitNavigation(
content::WebContents* MediaEngagementContentsObserver::GetOpener() const {
#if !defined(OS_ANDROID)
for (auto* browser : *BrowserList::GetInstance()) {
if (!browser->profile()->IsSameProfile(service_->profile()) ||
browser->profile()->GetProfileType() !=
service_->profile()->GetProfileType()) {
if (!browser->profile()->IsSameProfileAndType(service_->profile()))
continue;
}
int index =
browser->tab_strip_model()->GetIndexOfWebContents(web_contents());
......
......@@ -250,7 +250,7 @@ void OffTheRecordProfileImpl::InitIoData() {
#if !defined(OS_ANDROID)
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
// storage partition. We're not interested in zoom levels in special
......
......@@ -237,6 +237,10 @@ bool Profile::IsIncognito() const {
return GetProfileType() == INCOGNITO_PROFILE;
}
bool Profile::IsGuestProfile() const {
return GetProfileType() == GUEST_PROFILE;
}
bool Profile::IsGuestSession() const {
#if defined(OS_CHROMEOS)
static bool is_guest_session =
......
......@@ -56,6 +56,8 @@ namespace user_prefs {
class PrefRegistrySyncable;
}
class OffTheRecordProfileIOData;
// Instead of adding more members to Profile, consider creating a
// KeyedService. See
// http://dev.chromium.org/developers/design-documents/profile-architecture
......@@ -146,9 +148,6 @@ class Profile : public content::BrowserContext {
// implementations, this is usually the Google-services email address.
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
// is owned by the receiving profile. If the receiving profile is off the
// record, the same profile is returned.
......@@ -228,6 +227,12 @@ class Profile : public content::BrowserContext {
// versa).
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
// 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
......@@ -302,15 +307,25 @@ class Profile : public content::BrowserContext {
std::string GetDebugName();
// Returns whether it's a regular profile. Short-hand for GetProfileType() ==
// REGULAR_PROFILE.
// IsRegularProfile(), IsIncognito(), and IsGuestProfile() are mutually
// exclusive.
// IsSystemProfile() implies that IsRegularProfile() is true.
// IsOffTheRecord() is an equivalent of IsIncognito() || IsGuestProfile().
// Returns whether it's a regular profile.
bool IsRegularProfile() const;
// Returns whether it is an Incognito session. An Incognito session is an
// off-the-record session that is not a guest session.
// Returns whether it is an Incognito profile. An Incognito profile is an
// off-the-record profile that is not a guest profile.
// TODO(https://crbug.com/947933): Replace with IsIncognitProfile.
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;
// Returns whether it is a system profile.
......@@ -391,6 +406,11 @@ class Profile : public content::BrowserContext {
void Wipe();
protected:
friend class OffTheRecordProfileIOData;
// Returns the profile type.
virtual ProfileType GetProfileType() const = 0;
void set_is_guest_profile(bool is_guest_profile) {
is_guest_profile_ = is_guest_profile;
}
......
......@@ -72,7 +72,7 @@ void RestoreTabUsingProfile(Profile* profile) {
bool IsIncognitoAllowed() {
Profile* profile = ProfileManager::GetActiveUserProfile();
return profile && profile->GetProfileType() != Profile::GUEST_PROFILE &&
return profile && !profile->IsGuestProfile() &&
IncognitoModePrefs::GetAvailability(profile->GetPrefs()) !=
IncognitoModePrefs::DISABLED;
}
......
......@@ -169,8 +169,7 @@ std::pair<Browser*, int> GetBrowserAndTabForDisposition(
++browser_it) {
Browser* browser = *browser_it;
// When tab switching, only look at same profile and anonymity level.
if (browser->profile()->IsSameProfile(profile) &&
browser->profile()->GetProfileType() == profile->GetProfileType()) {
if (browser->profile()->IsSameProfileAndType(profile)) {
int index = GetIndexOfExistingTab(browser, params);
if (index >= 0)
return {browser, index};
......
......@@ -337,8 +337,7 @@ bool ChromeAuthenticatorRequestDelegate::IsWebAuthnUIEnabled() {
bool ChromeAuthenticatorRequestDelegate::ShouldDisablePlatformAuthenticators() {
#if defined(OS_MACOSX)
// Touch ID is available in Incognito, but not in Guest mode.
return Profile::FromBrowserContext(browser_context())->GetProfileType() ==
Profile::ProfileType::GUEST_PROFILE;
return Profile::FromBrowserContext(browser_context())->IsGuestProfile();
#else // Windows, Android
return browser_context()->IsOffTheRecord();
#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