mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add visualization for Chrome configuration changes (fixes #3892)
- Add new API to retrieve/observe configuration values. - cefclient: Add https://tests/config to inspect configuration values in real time.
This commit is contained in:
@ -4,10 +4,28 @@
|
||||
|
||||
#include "cef/libcef/browser/global_preference_manager_impl.h"
|
||||
|
||||
#include "base/metrics/field_trial_list_including_low_anonymity.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "cef/libcef/browser/context.h"
|
||||
#include "cef/libcef/browser/prefs/pref_helper.h"
|
||||
#include "cef/libcef/browser/thread_util.h"
|
||||
#include "cef/libcef/common/api_version_util.h"
|
||||
#include "chrome/browser/about_flags.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "components/flags_ui/pref_service_flags_storage.h"
|
||||
#include "components/variations/synthetic_trials_active_group_id_provider.h"
|
||||
|
||||
namespace {
|
||||
|
||||
std::string GetActiveGroupNameAsString(
|
||||
const base::FieldTrial::ActiveGroup& group) {
|
||||
constexpr std::string_view kNonBreakingHyphenUTF8 = "\xE2\x80\x91";
|
||||
std::string result = group.trial_name + ":" + group.group_name;
|
||||
base::ReplaceChars(result, "-", kNonBreakingHyphenUTF8, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool CefGlobalPreferenceManagerImpl::HasPreference(const CefString& name) {
|
||||
CEF_REQUIRE_UIT_RETURN(false);
|
||||
@ -40,6 +58,77 @@ bool CefGlobalPreferenceManagerImpl::SetPreference(const CefString& name,
|
||||
value, error);
|
||||
}
|
||||
|
||||
CefRefPtr<CefRegistration>
|
||||
CefGlobalPreferenceManagerImpl::AddPreferenceObserver(
|
||||
const CefString& name,
|
||||
CefRefPtr<CefPreferenceObserver> observer) {
|
||||
CEF_API_REQUIRE_ADDED(CEF_NEXT);
|
||||
CEF_REQUIRE_UIT_RETURN(nullptr);
|
||||
return CefContext::Get()->GetPrefRegistrar()->AddObserver(name, observer);
|
||||
}
|
||||
|
||||
// static
|
||||
void CefPreferenceManager::GetChromeVariationsAsSwitches(
|
||||
std::vector<CefString>& switches) {
|
||||
CEF_API_REQUIRE_ADDED(CEF_NEXT);
|
||||
|
||||
// Verify that the context is in a valid state.
|
||||
if (!CONTEXT_STATE_VALID()) {
|
||||
DCHECK(false) << "context not valid";
|
||||
return;
|
||||
}
|
||||
|
||||
switches.clear();
|
||||
|
||||
// Based on ChromeFeatureListCreator::ConvertFlagsToSwitches().
|
||||
|
||||
flags_ui::PrefServiceFlagsStorage flags_storage(
|
||||
g_browser_process->local_state());
|
||||
base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
|
||||
about_flags::ConvertFlagsToSwitches(&flags_storage, &command_line,
|
||||
flags_ui::kNoSentinels);
|
||||
|
||||
for (const auto& arg : command_line.argv()) {
|
||||
if (!arg.empty()) {
|
||||
switches.push_back(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void CefPreferenceManager::GetChromeVariationsAsStrings(
|
||||
std::vector<CefString>& strings) {
|
||||
CEF_API_REQUIRE_ADDED(CEF_NEXT);
|
||||
|
||||
// Verify that the context is in a valid state.
|
||||
if (!CONTEXT_STATE_VALID()) {
|
||||
DCHECK(false) << "context not valid";
|
||||
return;
|
||||
}
|
||||
|
||||
strings.clear();
|
||||
|
||||
// Based on components/webui/version/version_handler_helper.cc
|
||||
// GetVariationsList().
|
||||
|
||||
base::FieldTrial::ActiveGroups active_groups;
|
||||
// Include low anonymity trial groups in the version string, as it is only
|
||||
// displayed locally (and is useful for diagnostics purposes).
|
||||
base::FieldTrialListIncludingLowAnonymity::
|
||||
GetActiveFieldTrialGroupsForTesting(&active_groups);
|
||||
|
||||
for (const auto& group : active_groups) {
|
||||
strings.push_back(GetActiveGroupNameAsString(group));
|
||||
}
|
||||
|
||||
// Synthetic field trials.
|
||||
for (const auto& group :
|
||||
variations::SyntheticTrialsActiveGroupIdProvider::GetInstance()
|
||||
->GetGroups()) {
|
||||
strings.push_back(GetActiveGroupNameAsString(group.active_group()));
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefPreferenceManager>
|
||||
CefPreferenceManager::GetGlobalPreferenceManager() {
|
||||
|
Reference in New Issue
Block a user