#include "chrome/browser/enterprise/util/managed_browser_utils.h"
#include <memory>
#include <string_view>
#include <utility>
#include <vector>
#include "base/notreached.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "chrome/browser/image_fetcher/image_fetcher_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/common/pref_names.h"
#include "components/certificate_matching/certificate_principal_pattern.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/image_fetcher/core/image_fetcher.h"
#include "components/image_fetcher/core/image_fetcher_service.h"
#include "components/image_fetcher/core/image_fetcher_types.h"
#include "components/image_fetcher/core/request_metadata.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/account_managed_status_finder.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "net/base/host_port_pair.h"
#include "net/cert/x509_certificate.h"
#include "net/ssl/client_cert_identity.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#include <jni.h>
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/managed_ui.h"
#include "components/enterprise/browser/reporting/common_pref_names.h"
#include "chrome/browser/enterprise/util/jni_headers/ManagedBrowserUtils_jni.h"
#endif
namespace enterprise_util {
namespace {
base::Value::List GetCertAutoSelectionFilters(Profile* profile,
const GURL& requesting_url) { … }
bool CertMatchesSelectionFilters(
const net::ClientCertIdentity& client_cert,
const base::Value::List& auto_selection_filters) { … }
void OnManagementIconReceived(
base::OnceCallback<void(const gfx::Image&)> callback,
const gfx::Image& icon,
const image_fetcher::RequestMetadata& metadata) { … }
}
bool IsBrowserManaged(Profile* profile) { … }
std::string GetDomainFromEmail(const std::string& email) { … }
GURL GetRequestingUrl(const net::HostPortPair host_port_pair) { … }
void AutoSelectCertificates(
Profile* profile,
const GURL& requesting_url,
net::ClientCertIdentityList client_certs,
net::ClientCertIdentityList* matching_client_certs,
net::ClientCertIdentityList* nonmatching_client_certs) { … }
bool IsMachinePolicyPref(const std::string& pref_name) { … }
void RegisterLocalStatePrefs(PrefRegistrySimple* registry) { … }
void SetUserAcceptedAccountManagement(Profile* profile, bool accepted) { … }
bool UserAcceptedAccountManagement(Profile* profile) { … }
bool ProfileCanBeManaged(Profile* profile) { … }
ManagementEnvironment GetManagementEnvironment(
Profile* profile,
const AccountInfo& account_info) { … }
bool CanShowEnterpriseBadging(Profile* profile) { … }
bool IsKnownConsumerDomain(const std::string& email_domain) { … }
#if BUILDFLAG(IS_ANDROID)
jboolean JNI_ManagedBrowserUtils_IsBrowserManaged(JNIEnv* env,
Profile* profile) {
return policy::ManagementServiceFactory::GetForProfile(profile)
->IsBrowserManaged();
}
jboolean JNI_ManagedBrowserUtils_IsProfileManaged(JNIEnv* env,
Profile* profile) {
return policy::ManagementServiceFactory::GetForProfile(profile)
->IsAccountManaged();
}
base::android::ScopedJavaLocalRef<jstring> JNI_ManagedBrowserUtils_GetTitle(
JNIEnv* env,
Profile* profile) {
return base::android::ConvertUTF16ToJavaString(
env, chrome::GetManagementPageSubtitle(profile));
}
jboolean JNI_ManagedBrowserUtils_IsBrowserReportingEnabled(JNIEnv* env) {
return g_browser_process->local_state()->GetBoolean(
enterprise_reporting::kCloudReportingEnabled);
}
jboolean JNI_ManagedBrowserUtils_IsProfileReportingEnabled(JNIEnv* env,
Profile* profile) {
return profile->GetPrefs()->GetBoolean(
enterprise_reporting::kCloudProfileReportingEnabled);
}
#endif
void GetManagementIcon(const GURL& url,
Profile* profile,
base::OnceCallback<void(const gfx::Image&)> callback) { … }
}