diff --git a/libcef/browser/prefs/browser_prefs.cc b/libcef/browser/prefs/browser_prefs.cc index d3cddc39c..b261a3b91 100644 --- a/libcef/browser/prefs/browser_prefs.cc +++ b/libcef/browser/prefs/browser_prefs.cc @@ -88,6 +88,20 @@ std::string GetAcceptLanguageList(Profile* profile) { const char kUserPrefsFileName[] = "UserPrefs.json"; const char kLocalPrefsFileName[] = "LocalPrefs.json"; +void RegisterProfilePrefs(PrefRegistrySimple* registry) { + const base::CommandLine* command_line = + base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kEnablePreferenceTesting)) { + // Preferences used with unit tests. + registry->RegisterBooleanPref("test.bool", true); + registry->RegisterIntegerPref("test.int", 2); + registry->RegisterDoublePref("test.double", 5.0); + registry->RegisterStringPref("test.string", "default"); + registry->RegisterListPref("test.list"); + registry->RegisterDictionaryPref("test.dict"); + } +} + std::unique_ptr CreatePrefService(Profile* profile, const base::FilePath& cache_path, bool persist_user_preferences) { @@ -209,16 +223,6 @@ std::unique_ptr CreatePrefService(Profile* profile, false); registry->RegisterBooleanPref(prefs::kWebRTCAllowLegacyTLSProtocols, false); - if (command_line->HasSwitch(switches::kEnablePreferenceTesting)) { - // Preferences used with unit tests. - registry->RegisterBooleanPref("test.bool", true); - registry->RegisterIntegerPref("test.int", 2); - registry->RegisterDoublePref("test.double", 5.0); - registry->RegisterStringPref("test.string", "default"); - registry->RegisterListPref("test.list"); - registry->RegisterDictionaryPref("test.dict"); - } - if (profile) { // Call RegisterProfilePrefs() for all services listed by // EnsureBrowserContextKeyedServiceFactoriesBuilt(). @@ -235,6 +239,7 @@ std::unique_ptr CreatePrefService(Profile* profile, MediaDeviceIDSalt::RegisterProfilePrefs(registry.get()); ProfileNetworkContextService::RegisterProfilePrefs(registry.get()); safe_browsing::RegisterProfilePrefs(registry.get()); + RegisterProfilePrefs(registry.get()); const std::string& locale = command_line->GetSwitchValueASCII(switches::kLang); diff --git a/libcef/browser/prefs/browser_prefs.h b/libcef/browser/prefs/browser_prefs.h index 5e2f4abc1..fdc442307 100644 --- a/libcef/browser/prefs/browser_prefs.h +++ b/libcef/browser/prefs/browser_prefs.h @@ -11,6 +11,7 @@ namespace base { class FilePath; } +class PrefRegistrySimple; class PrefService; class Profile; @@ -19,6 +20,9 @@ namespace browser_prefs { // Name for the user prefs JSON file. extern const char kUserPrefsFileName[]; +// Register preferences specific to CEF. +void RegisterProfilePrefs(PrefRegistrySimple* registry); + // Create the PrefService used to manage pref registration and storage. // |profile| will be nullptr for the system-level PrefService. std::unique_ptr CreatePrefService(Profile* profile, diff --git a/patch/patches/chrome_runtime.patch b/patch/patches/chrome_runtime.patch index 95dd8b169..1fc8480dd 100644 --- a/patch/patches/chrome_runtime.patch +++ b/patch/patches/chrome_runtime.patch @@ -178,3 +178,37 @@ index 29ba5f21b38f..3ce05420eb78 100644 } base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { +diff --git chrome/browser/prefs/browser_prefs.cc chrome/browser/prefs/browser_prefs.cc +index fbfeff04ce25..f5ab9f9bb8cf 100644 +--- chrome/browser/prefs/browser_prefs.cc ++++ chrome/browser/prefs/browser_prefs.cc +@@ -10,6 +10,7 @@ + #include "build/branding_buildflags.h" + #include "build/build_config.h" + #include "build/chromeos_buildflags.h" ++#include "cef/libcef/features/features.h" + #include "chrome/browser/about_flags.h" + #include "chrome/browser/accessibility/accessibility_labels_service.h" + #include "chrome/browser/accessibility/accessibility_ui.h" +@@ -160,6 +161,10 @@ + #include "chrome/browser/background/background_mode_manager.h" + #endif + ++#if BUILDFLAG(ENABLE_CEF) ++#include "cef/libcef/browser/prefs/browser_prefs.h" ++#endif ++ + #if BUILDFLAG(ENABLE_EXTENSIONS) + #include "chrome/browser/accessibility/animation_policy_prefs.h" + #include "chrome/browser/apps/platform_apps/shortcut_manager.h" +@@ -959,6 +964,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, + RegisterSessionServiceLogProfilePrefs(registry); + #endif + ++#if BUILDFLAG(ENABLE_CEF) ++ browser_prefs::RegisterProfilePrefs(registry); ++#endif ++ + #if BUILDFLAG(ENABLE_EXTENSIONS) + ExtensionWebUI::RegisterProfilePrefs(registry); + RegisterAnimationPolicyPrefs(registry); diff --git a/tests/ceftests/preference_unittest.cc b/tests/ceftests/preference_unittest.cc index 8c190d3d4..f687f31dd 100644 --- a/tests/ceftests/preference_unittest.cc +++ b/tests/ceftests/preference_unittest.cc @@ -31,6 +31,11 @@ const char kPrefString[] = "string"; const char kPrefList[] = "list"; const char kPrefDict[] = "dict"; +std::string* PendingAction() { + static std::string str; + return &str; +} + // Browser-side app delegate. class PreferenceBrowserTest : public client::ClientAppBrowser::Delegate { public: @@ -77,7 +82,7 @@ void ValidateBool(CefRefPtr context, value = context->GetPreference(name); EXPECT_TRUE(value.get()); EXPECT_EQ(VTYPE_BOOL, value->GetType()); - EXPECT_EQ(expected, value->GetBool()); + EXPECT_EQ(expected, value->GetBool()) << *PendingAction(); } void ValidateInt(CefRefPtr context, @@ -100,7 +105,7 @@ void ValidateInt(CefRefPtr context, value = context->GetPreference(name); EXPECT_TRUE(value.get()); EXPECT_EQ(VTYPE_INT, value->GetType()); - EXPECT_EQ(expected, value->GetInt()); + EXPECT_EQ(expected, value->GetInt()) << *PendingAction(); } void ValidateDouble(CefRefPtr context, @@ -123,7 +128,7 @@ void ValidateDouble(CefRefPtr context, value = context->GetPreference(name); EXPECT_TRUE(value.get()); EXPECT_EQ(VTYPE_DOUBLE, value->GetType()); - EXPECT_EQ(expected, value->GetDouble()); + EXPECT_EQ(expected, value->GetDouble()) << *PendingAction(); } void ValidateString(CefRefPtr context, @@ -146,7 +151,8 @@ void ValidateString(CefRefPtr context, value = context->GetPreference(name); EXPECT_TRUE(value.get()); EXPECT_EQ(VTYPE_STRING, value->GetType()); - EXPECT_STREQ(expected.c_str(), value->GetString().ToString().c_str()); + EXPECT_STREQ(expected.c_str(), value->GetString().ToString().c_str()) + << *PendingAction(); } void ValidateList(CefRefPtr context, @@ -216,7 +222,7 @@ void ValidateNoExist(CefRefPtr context, } value = context->GetPreference(name); - EXPECT_FALSE(value.get()); + EXPECT_FALSE(value.get()) << *PendingAction(); } void PopulateRootDefaults(CefRefPtr val) { @@ -448,23 +454,37 @@ TEST(PreferenceTest, GlobalSetGetShared) { CefRequestContextSettings settings; CefRefPtr context4 = CefRequestContext::CreateContext(settings, nullptr); - EXPECT_TRUE(context.get()); + EXPECT_TRUE(context4.get()); // Set/get the values on the first context. + *PendingAction() = "Set/get the values on the first context"; ValidateSetGet(context, event); event->Wait(); // Get the values from the 2nd and 3rd contexts. They should be the same. + *PendingAction() = "Get the values from the 2nd context."; ValidateGet(context2, event); event->Wait(); + *PendingAction() = "Get the values from the 3rd context."; ValidateGet(context3, event); event->Wait(); - // Get the values from the 4th context. They should be at the default. - ValidateDefaults(context4, false, event); + // Get the values from the 4th context. + *PendingAction() = "Get the values from the 4th context."; + if (IsChromeRuntimeEnabled()) { + // With the Chrome runtime, prefs set via an incognito profile will become + // an overlay on top of the global (parent) profile. The incognito profile + // shares the prefs in this case because they were set via the global + // profile. + ValidateGet(context4, event); + } else { + // They should be at the default. + ValidateDefaults(context4, false, event); + } event->Wait(); // Reset to the default values. + *PendingAction() = "Reset to the default values."; ValidateDefaults(context, true, event); event->Wait(); } @@ -524,23 +544,30 @@ TEST(PreferenceTest, CustomSetGetShared) { // Unassociated context. CefRefPtr context4 = CefRequestContext::CreateContext(settings, nullptr); - EXPECT_TRUE(context.get()); + EXPECT_TRUE(context4.get()); // Set/get the values on the first context. + *PendingAction() = "Set/get the values on the first context"; ValidateSetGet(context, event); event->Wait(); // Get the values from the 2nd and 3d contexts. They should be the same. + *PendingAction() = "Get the values from the 2nd context."; ValidateGet(context2, event); event->Wait(); + *PendingAction() = "Get the values from the 3rd context."; ValidateGet(context3, event); event->Wait(); // Get the values from the 4th context. They should be at the default. + // This works with the Chrome runtime because the preference changes only + // exist in the other incognito profile's overlay. + *PendingAction() = "Get the values from the 4th context."; ValidateDefaults(context4, false, event); event->Wait(); // Reset to the default values. + *PendingAction() = "Reset to the default values."; ValidateDefaults(context, true, event); event->Wait(); }