-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Preferences
Pete Miller edited this page Jul 22, 2021
·
1 revision
Chromium's wiki entry for preferences is quite detailed but also somewhat outdated. Here's a simple overview of the few parts of how to create and access a new preference for Brave:
- The string for the preference key, usually
kMyPrefName = "brave.my_pref_name"
(either inbrave/common/pref_names.h
or, more preferrably, local to a component atbrave/components/myComponent/common/prefs.h
) - The registration of the preference type and default value
RegisterBooleanPref(kMyPrefName, true)
(inbrave_profile_prefs.cc
orMyComponent::RegisterProfilePrefs
) - Getting the pref value in some code somewhere (
profile()->GetPrefs()->GetBooleanPref
) - Allowing the user to set the pref on the settings page by adding a polymer settings control pointing at the new setting key
"brave.my_pref_name"
- Allowing the settings page
chrome.settingsPrivate
API to access the setting (inbrave/browser/extensions/api/settings_private/brave_prefs_util.cc
)