// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_PREF_NAMES_H_
#define EXTENSIONS_BROWSER_PREF_NAMES_H_

#include <string>

#include "build/build_config.h"
#include "extensions/common/api/types.h"

// Preference keys which are needed by both the ExtensionPrefs and by external
// clients, such as APIs.

namespace extensions {
namespace pref_names {

// If the given `scope` is persisted, return true and populate `result` with the
// appropriate property (i.e. one of kPref*) within a kExtensions dictionary. If
// `scope` is not persisted, return false, and leave `result` unchanged.
bool ScopeToPrefName(extensions::api::types::ChromeSettingScope scope,
                     std::string* result);

// Browser-level preferences ---------------------------------------------------

// Whether we have run the extension-alert system (see ExtensionGlobalError)
// at least once for this profile.
inline constexpr char kAlertsInitialized[] = "extensions.alerts.initialized";

// The sites that are allowed to install extensions. These sites should be
// allowed to install extensions without the scary dangerous downloads bar.
// Also, when off-store-extension installs are disabled, these sites are exempt.
inline constexpr char kAllowedInstallSites[] =
    "extensions.allowed_install_sites";

// A list of allowed extension types. Extensions can only be installed if their
// type is on this allowlist or alternatively on kInstallAllowList or
// kInstallForceList.
inline constexpr char kAllowedTypes[] = "extensions.allowed_types";

// A boolean that tracks whether apps are allowed to enter fullscreen mode.
inline constexpr char kAppFullscreenAllowed[] = "apps.fullscreen.allowed";

// A boolean indicating if external extensions are blocked from installing.
inline constexpr char kBlockExternalExtensions[] =
    "extensions.block_external_extensions";

// Records the last time the CWS Info Service downloaded information about
// currently installed extensions from the Chrome Web Store, successfully
// compared it with the information stored in extension_prefs and updated the
// latter if necessary. The timestamp therefore represents the "freshness" of
// the CWS information saved.
inline constexpr char kCWSInfoTimestamp[] = "extensions.cws_info_timestamp";
inline constexpr char kCWSInfoFetchErrorTimestamp[] =
    "extensions.cws_info_fetch_error_timestamp";

// A preference for a list of Component extensions that have been
// uninstalled/removed and should not be reloaded.
inline constexpr char kDeletedComponentExtensions[] =
    "extensions.deleted_component_extensions";

// A list of app origins that will grant a long-lived background lifetime to
// the connecting extension, if connected to them via persistent messaging
// ports. The value is controlled by the
// `ExtensionExtendedBackgroundLifetimeForPortConnectionsToUrls` policy.
inline constexpr char kExtendedBackgroundLifetimeForPortConnectionsToUrls[] =
    "extensions.extended_background_lifetime_urls";

// Dictionary pref that keeps track of per-extension settings. The keys are
// extension ids.
inline constexpr char kExtensions[] = "extensions.settings";

// Dictionary pref that manages extensions, controlled by policy.
// Values are expected to conform to the schema of the ExtensionManagement
// policy.
inline constexpr char kExtensionManagement[] = "extensions.management";

// An integer that indicates the availability of extensions that are unpublished
// on the Chrome Web Store. More details can be found at
// ExtensionUnpublishedAvailability.yaml
inline constexpr char kExtensionUnpublishedAvailability[] =
    "extensions.unpublished_availability";

// An allowlist of extension ids the user can install: exceptions from the
// following denylist.
inline constexpr char kInstallAllowList[] = "extensions.install.allowlist";

// A denylist, containing extensions the user cannot install. This list can
// contain "*" meaning all extensions. This list should not be confused with the
// extension blocklist, which is Google controlled.
inline constexpr char kInstallDenyList[] = "extensions.install.denylist";

// A list containing extensions that Chrome will silently install
// at startup time. It is a list of strings, each string contains
// an extension ID and an update URL, delimited by a semicolon.
// This preference is set by an admin policy, and meant to be only
// accessed through extensions::ExternalPolicyProvider.
inline constexpr char kInstallForceList[] = "extensions.install.forcelist";

// A list containing the ids of extensions that Chrome will install disabled for
// acceptance by the user. This preference is typically populated from the
// contents of the "initial_extensions" list in the installation's
// inital_preferences file only for the initial profile during first run.
inline constexpr char kInitialInstallList[] = "extensions.install.initiallist";

// String pref indicates the name of the provider of the `kInitialInstallList`.
inline constexpr char kInitialInstallProviderName[] =
    "extensions.install.initialprovidername";

// A dictionary containing, for each extension id, additional
// OAuth redirect URLs that will be allowed in chrome.identity API.
inline constexpr char kOAuthRedirectUrls[] = "extensions.oauth_redirect_urls";

// String pref for what version chrome was last time the extension prefs were
// loaded.
inline constexpr char kLastChromeVersion[] = "extensions.last_chrome_version";

// Blocklist and allowlist for Native Messaging Hosts.
inline constexpr char kNativeMessagingBlocklist[] =
    "native_messaging.blocklist";
inline constexpr char kNativeMessagingAllowlist[] =
    "native_messaging.allowlist";

// Flag allowing usage of Native Messaging hosts installed on user level.
inline constexpr char kNativeMessagingUserLevelHosts[] =
    "native_messaging.user_level_hosts";

// A preference that tracks extensions pinned to the toolbar. This is a list
// object stored in the Preferences file. The extensions are stored by ID.
inline constexpr char kPinnedExtensions[] = "extensions.pinned_extensions";

// Pref for policy to enable/disable loading extension from command line
inline constexpr char kExtensionInstallTypeBlocklist[] =
    "extensions.extension_install_type_blocklist";

// Properties in kExtensions dictionaries --------------------------------------

// The time at which the extension was installed, used to record the time to
// first extension action click metric. Only set on initial installation.
inline constexpr char kPrefInstallTimeForActionMetric[] =
    "install_time_for_action_metric";

// Extension-controlled preferences.
inline constexpr char kPrefPreferences[] = "preferences";

// Extension-controlled incognito preferences.
inline constexpr char kPrefIncognitoPreferences[] = "incognito_preferences";

// Extension-controlled regular-only preferences.
inline constexpr char kPrefRegularOnlyPreferences[] =
    "regular_only_preferences";

// Extension-set content settings.
inline constexpr char kPrefContentSettings[] = "content_settings";

// Extension-set incognito content settings.
inline constexpr char kPrefIncognitoContentSettings[] =
    "incognito_content_settings";

// Per-profile UUID to distinguish global shortcut sessions for
// org.freedesktop.portal.GlobalShortcuts.
inline constexpr char kGlobalShortcutsUuid[] =
    "extensions.global_shortcuts.uuid";

// Boolean that specifies whether ExtensionInstallCloudPolicyChecks is enabled.
// This pref is used by both the profile and the browser, it can be found in the
// local state as well as the profile prefs.
inline constexpr char kExtensionInstallCloudPolicyChecksEnabled[] =
    "extensions.install.cloud_policy_checks_enabled";

// A pref that stores the expiration time for the enterprise promotion banner
// on the Chrome Web Store. After this time, the banner will not be shown
// anymore.
inline constexpr char kEnterprisePromotionExpirationTime[] =
    "extensions.enterprise_promotion.expiration_time";

// A pref that stores whether the enterprise promotion banner on the Chrome
// Web Store has been dismissed by the user by clicking the banner button.
inline constexpr char kHasDismissedEnterprisePromotion[] =
    "extensions.has_dismissed_enterprise_promotion";

// A pref that stores whether the extension was pinned to the toolbar by default
// upon installation. This excludes extensions that are pinned by default due to
// policies.
inline constexpr char kWasPinnedByDefault[] = "was_pinned_by_default";

}  // namespace pref_names
}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_PREF_NAMES_H_
