1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ENTERPRISE_UTIL_MANAGED_BROWSER_UTILS_H_
#define CHROME_BROWSER_ENTERPRISE_UTIL_MANAGED_BROWSER_UTILS_H_
// Util functions relating to managed browsers.
#include <string>
#include "base/functional/bind.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "net/base/host_port_pair.h"
#include "net/ssl/client_cert_identity.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
struct AccountInfo;
class GURL;
class PrefRegistrySimple;
class Profile;
namespace enterprise_util {
enum EnterpriseProfileBadgingTemporarySetting : int {
kHide = 0,
kShowOnUnmanagedDevices = 1,
kShowOnAllDevices = 2,
kShowOnManagedDevices = 3
};
// Represents which type of managed environment we have.
enum class ManagementEnvironment { kNone, kSchool, kWork };
// Determines whether the browser with `profile` as its primary profile is
// managed. This is determined by looking it there are any policies applied or
// if `profile` is an enterprise profile.
bool IsBrowserManaged(Profile* profile);
// Extracts the domain from provided |email| if it's an email address and
// returns an empty string, otherwise.
std::string GetDomainFromEmail(const std::string& email);
// Returns an HTTPS URL for the host and port identified by `host_port_pair`.
// This is intended to be used to build a `requesting_url` for
// `AutoSelectCertificates`.
GURL GetRequestingUrl(const net::HostPortPair host_port_pair);
// Partitions |client_certs| according to the value of the
// |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for the
// |requesting_url|. If a filter is set, all certs that match the
// filter will be returned in |matching_client_certs|, and all certificates
// that don't in |nonmatching_client_certs|. If no filter is set, then
// all certificates will be returned in |nonmatching_client_certs|.
void AutoSelectCertificates(
Profile* profile,
const GURL& requesting_url,
net::ClientCertIdentityList client_certs,
net::ClientCertIdentityList* matching_client_certs,
net::ClientCertIdentityList* nonmatching_client_certs);
// Returns true if the given pref is set through a machine-scope policy.
bool IsMachinePolicyPref(const std::string& pref_name);
void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
// Sets attribute entry 'user_accepted_account_management' of `profile` to
// `accepted`.
void SetUserAcceptedAccountManagement(Profile* profile, bool accepted);
// Returns true is the user has accepted account management through the
// enterprise account confirmation dialog.
bool UserAcceptedAccountManagement(Profile* profile);
// Returns true if the user has consented to sync or has accepted account
// management through the enterprise account confirmation dialog.
bool ProfileCanBeManaged(Profile* profile);
ManagementEnvironment GetManagementEnvironment(Profile* profile,
const AccountInfo& account_info);
// Returns false if the toolbar enterprise badging is disabled by policy.
bool IsEnterpriseBadgingEnabledForToolbar(Profile* profile);
bool CanShowEnterpriseBadgingForAvatar(Profile* profile);
bool CanShowEnterpriseBadgingForMenu(Profile* profile);
bool CanShowEnterpriseProfileUI(Profile* profile);
bool CanShowEnterpriseBadgingForNTPFooter(Profile* profile);
bool IsCustomEnterpriseBadgingForNTPFooter(Profile* profile);
// Sets the enterprise label if an `EnterpriseCustomLabel` has been set which
// will replace the profile name where it is used.
void SetEnterpriseProfileLabel(Profile* profile);
// Checks `email_domain` against the list of pre-defined known consumer domains.
// Use this for optimization purposes when you want to skip some code paths for
// most non-managed (=consumer) users with domains like gmail.com. Note that it
// can still return `false` for consumer domains which are not hardcoded in
// implementation.
bool IsKnownConsumerDomain(const std::string& email_domain);
// Returns an enterprise icon hosted at `url` for `profile` using `callback`.
// An empty image is returned in case `url` is invalid or we fail to fetch the
// image.
void GetManagementIcon(const GURL& url,
Profile* profile,
base::OnceCallback<void(const gfx::Image&)> callback);
// Returns the default enterprise label "Work"/"School" or the
// `EnterpriseCustomLabel` set by policy if present.
// `truncated` indicates whether the label returned needs to be truncated.
std::u16string GetEnterpriseLabel(Profile* profile, bool truncated = false);
} // namespace enterprise_util
#endif // CHROME_BROWSER_ENTERPRISE_UTIL_MANAGED_BROWSER_UTILS_H_
|