diff --git a/libcef/browser/browser_context_keyed_service_factories.cc b/libcef/browser/browser_context_keyed_service_factories.cc index e166113db..f89c3e8c4 100644 --- a/libcef/browser/browser_context_keyed_service_factories.cc +++ b/libcef/browser/browser_context_keyed_service_factories.cc @@ -7,6 +7,7 @@ #include "chrome/browser/content_settings/cookie_settings_factory.h" #include "chrome/browser/plugins/plugin_prefs_factory.h" +#include "chrome/browser/profiles/renderer_updater_factory.h" #include "chrome/browser/spellchecker/spellcheck_factory.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h" @@ -20,6 +21,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() { CookieSettingsFactory::GetInstance(); PluginPrefsFactory::GetInstance(); PrefsTabHelper::GetServiceInstance(); + RendererUpdaterFactory::GetInstance(); SpellcheckServiceFactory::GetInstance(); ThemeServiceFactory::GetInstance(); diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index a9a3a6f8e..c85e1045f 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -56,10 +56,14 @@ #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" #include "chrome/browser/plugins/plugin_utils.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/renderer_updater.h" +#include "chrome/browser/profiles/renderer_updater_factory.h" #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" #include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/google_url_loader_throttle.h" +#include "chrome/common/pref_names.h" #include "chrome/common/webui_url_constants.h" #include "chrome/grit/browser_resources.h" #include "chrome/grit/generated_resources.h" @@ -67,6 +71,7 @@ #include "components/navigation_interception/intercept_navigation_throttle.h" #include "components/navigation_interception/navigation_params.h" #include "components/spellcheck/common/spellcheck.mojom.h" +#include "components/variations/variations_http_header_provider.h" #include "components/version_info/version_info.h" #include "content/browser/frame_host/navigation_handle_impl.h" #include "content/browser/frame_host/render_frame_host_impl.h" @@ -540,8 +545,10 @@ void CefContentBrowserClient::RenderProcessWillLaunch( host->RemoveObserver(CefBrowserInfoManager::GetInstance()); host->AddObserver(CefBrowserInfoManager::GetInstance()); - host->Send( - new CefProcessMsg_SetIsIncognitoProcess(profile->IsOffTheRecord())); + // Forwards dynamic parameters to CefRenderThreadObserver. + Profile* original_profile = profile->GetOriginalProfile(); + RendererUpdaterFactory::GetForProfile(original_profile) + ->InitializeRenderer(host); } bool CefContentBrowserClient::ShouldUseProcessPerSite( @@ -1107,6 +1114,18 @@ CefContentBrowserClient::CreateURLLoaderThrottles( result.push_back(std::make_unique( request.resource_type, frame_tree_node_id)); + Profile* profile = Profile::FromBrowserContext(browser_context); + bool is_off_the_record = profile->IsOffTheRecord(); + + chrome::mojom::DynamicParams dynamic_params = { + profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch), + profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict), + profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps), + variations::VariationsHttpHeaderProvider::GetInstance() + ->GetClientDataHeader(false /* is_signed_in */)}; + result.push_back(std::make_unique( + is_off_the_record, std::move(dynamic_params))); + return result; } diff --git a/libcef/browser/prefs/browser_prefs.cc b/libcef/browser/prefs/browser_prefs.cc index f65d90b35..0fd506a46 100644 --- a/libcef/browser/prefs/browser_prefs.cc +++ b/libcef/browser/prefs/browser_prefs.cc @@ -29,6 +29,7 @@ #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" #include "chrome/common/buildflags.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/net/safe_search_util.h" #include "chrome/common/pref_names.h" #include "chrome/grit/locale_settings.h" #include "components/certificate_transparency/pref_names.h" @@ -232,6 +233,10 @@ std::unique_ptr CreatePrefService(Profile* profile, // Print preferences. // Based on ProfileImpl::RegisterProfilePrefs. + registry->RegisterBooleanPref(prefs::kForceGoogleSafeSearch, false); + registry->RegisterIntegerPref(prefs::kForceYouTubeRestrict, + safe_search_util::YOUTUBE_RESTRICT_OFF); + registry->RegisterStringPref(prefs::kAllowedDomainsForApps, std::string()); registry->RegisterBooleanPref(prefs::kPrintingEnabled, true); registry->RegisterBooleanPref(prefs::kPrintPreviewDisabled, !extensions::PrintPreviewEnabled()); diff --git a/libcef/common/cef_messages.h b/libcef/common/cef_messages.h index 2ed8d4eda..aefdaf601 100644 --- a/libcef/common/cef_messages.h +++ b/libcef/common/cef_messages.h @@ -147,11 +147,6 @@ IPC_MESSAGE_ROUTED0(CefMsg_DidStopLoading) // Based on ChromeViewMsg_LoadBlockedPlugins. IPC_MESSAGE_ROUTED1(CefViewMsg_LoadBlockedPlugins, std::string /* identifier */) -// Sent on process startup to indicate whether this process is running in -// incognito mode. Based on ChromeViewMsg_SetIsIncognitoProcess. -IPC_MESSAGE_CONTROL1(CefProcessMsg_SetIsIncognitoProcess, - bool /* is_incognito_processs */) - // Sent to child processes to add or remove a cross-origin whitelist entry. IPC_MESSAGE_CONTROL2(CefProcessMsg_ModifyCrossOriginWhitelistEntry, bool /* add */, diff --git a/libcef/renderer/render_thread_observer.cc b/libcef/renderer/render_thread_observer.cc index 0372d890d..cffada21b 100644 --- a/libcef/renderer/render_thread_observer.cc +++ b/libcef/renderer/render_thread_observer.cc @@ -15,12 +15,24 @@ #include "content/public/common/service_manager_connection.h" #include "content/public/common/simple_connection_filter.h" #include "content/public/renderer/render_thread.h" +#include "mojo/public/cpp/bindings/strong_binding.h" #include "net/base/net_module.h" #include "services/service_manager/public/cpp/binder_registry.h" +#include "services/service_manager/public/cpp/connector.h" +#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_url.h" #include "third_party/blink/public/web/web_security_policy.h" +namespace { + +chrome::mojom::DynamicParams* GetDynamicConfigParams() { + static base::NoDestructor dynamic_params; + return dynamic_params.get(); +} + +} // namespace + bool CefRenderThreadObserver::is_incognito_process_ = false; CefRenderThreadObserver::CefRenderThreadObserver() @@ -40,12 +52,16 @@ CefRenderThreadObserver::CefRenderThreadObserver() CefRenderThreadObserver::~CefRenderThreadObserver() {} +// static +const chrome::mojom::DynamicParams& +CefRenderThreadObserver::GetDynamicParams() { + return *GetDynamicConfigParams(); +} + bool CefRenderThreadObserver::OnControlMessageReceived( const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(CefRenderThreadObserver, message) - IPC_MESSAGE_HANDLER(CefProcessMsg_SetIsIncognitoProcess, - OnSetIsIncognitoProcess) IPC_MESSAGE_HANDLER(CefProcessMsg_ModifyCrossOriginWhitelistEntry, OnModifyCrossOriginWhitelistEntry) IPC_MESSAGE_HANDLER(CefProcessMsg_ClearCrossOriginWhitelist, @@ -55,11 +71,44 @@ bool CefRenderThreadObserver::OnControlMessageReceived( return handled; } -void CefRenderThreadObserver::OnSetIsIncognitoProcess( - bool is_incognito_process) { +void CefRenderThreadObserver::RegisterMojoInterfaces( + blink::AssociatedInterfaceRegistry* associated_interfaces) { + associated_interfaces->AddInterface(base::Bind( + &CefRenderThreadObserver::OnRendererConfigurationAssociatedRequest, + base::Unretained(this))); +} + +void CefRenderThreadObserver::UnregisterMojoInterfaces( + blink::AssociatedInterfaceRegistry* associated_interfaces) { + associated_interfaces->RemoveInterface( + chrome::mojom::RendererConfiguration::Name_); +} + +void CefRenderThreadObserver::SetInitialConfiguration( + bool is_incognito_process, + chrome::mojom::ChromeOSListenerRequest chromeos_listener_request) { is_incognito_process_ = is_incognito_process; } +void CefRenderThreadObserver::SetConfiguration( + chrome::mojom::DynamicParamsPtr params) { + *GetDynamicConfigParams() = std::move(*params); +} + +void CefRenderThreadObserver::SetContentSettingRules( + const RendererContentSettingRules& rules) {} + +void CefRenderThreadObserver::SetFieldTrialGroup( + const std::string& trial_name, + const std::string& group_name) { + content::RenderThread::Get()->SetFieldTrialGroup(trial_name, group_name); +} + +void CefRenderThreadObserver::OnRendererConfigurationAssociatedRequest( + chrome::mojom::RendererConfigurationAssociatedRequest request) { + renderer_configuration_bindings_.AddBinding(this, std::move(request)); +} + void CefRenderThreadObserver::OnModifyCrossOriginWhitelistEntry( bool add, const Cef_CrossOriginWhiteListEntry_Params& params) { diff --git a/libcef/renderer/render_thread_observer.h b/libcef/renderer/render_thread_observer.h index a4f5960b9..68a252089 100644 --- a/libcef/renderer/render_thread_observer.h +++ b/libcef/renderer/render_thread_observer.h @@ -9,7 +9,10 @@ #include #include "base/compiler_specific.h" +#include "chrome/common/renderer_configuration.mojom.h" +#include "components/content_settings/core/common/content_settings.h" #include "content/public/renderer/render_thread_observer.h" +#include "mojo/public/cpp/bindings/associated_binding_set.h" namespace visitedlink { class VisitedLinkSlave; @@ -17,24 +20,45 @@ class VisitedLinkSlave; struct Cef_CrossOriginWhiteListEntry_Params; -// This class sends and receives control messages on the renderer process. -class CefRenderThreadObserver : public content::RenderThreadObserver { +// This class sends and receives control messages in the renderer process. +class CefRenderThreadObserver : public content::RenderThreadObserver, + public chrome::mojom::RendererConfiguration { public: CefRenderThreadObserver(); ~CefRenderThreadObserver() override; static bool is_incognito_process() { return is_incognito_process_; } - // RenderThreadObserver implementation. - bool OnControlMessageReceived(const IPC::Message& message) override; + // Return the dynamic parameters - those that may change while the + // render process is running. + static const chrome::mojom::DynamicParams& GetDynamicParams(); visitedlink::VisitedLinkSlave* visited_link_slave() { return visited_link_slave_.get(); } private: + // content::RenderThreadObserver: + bool OnControlMessageReceived(const IPC::Message& message) override; + void RegisterMojoInterfaces( + blink::AssociatedInterfaceRegistry* associated_interfaces) override; + void UnregisterMojoInterfaces( + blink::AssociatedInterfaceRegistry* associated_interfaces) override; + + // chrome::mojom::RendererConfiguration: + void SetInitialConfiguration(bool is_incognito_process, + chrome::mojom::ChromeOSListenerRequest + chromeos_listener_request) override; + void SetConfiguration(chrome::mojom::DynamicParamsPtr params) override; + void SetContentSettingRules( + const RendererContentSettingRules& rules) override; + void SetFieldTrialGroup(const std::string& trial_name, + const std::string& group_name) override; + + void OnRendererConfigurationAssociatedRequest( + chrome::mojom::RendererConfigurationAssociatedRequest request); + // Message handlers called on the render thread. - void OnSetIsIncognitoProcess(bool is_incognito_process); void OnModifyCrossOriginWhitelistEntry( bool add, const Cef_CrossOriginWhiteListEntry_Params& params); @@ -44,6 +68,9 @@ class CefRenderThreadObserver : public content::RenderThreadObserver { std::unique_ptr visited_link_slave_; + mojo::AssociatedBindingSet + renderer_configuration_bindings_; + DISALLOW_COPY_AND_ASSIGN(CefRenderThreadObserver); }; diff --git a/libcef/renderer/url_loader_throttle_provider_impl.cc b/libcef/renderer/url_loader_throttle_provider_impl.cc index 697096c3b..f73eb73bc 100644 --- a/libcef/renderer/url_loader_throttle_provider_impl.cc +++ b/libcef/renderer/url_loader_throttle_provider_impl.cc @@ -5,10 +5,12 @@ #include "libcef/renderer/url_loader_throttle_provider_impl.h" #include "libcef/common/extensions/extensions_util.h" +#include "libcef/renderer/render_thread_observer.h" #include #include "base/feature_list.h" +#include "chrome/common/google_url_loader_throttle.h" #include "content/public/common/content_features.h" #include "content/public/renderer/render_frame.h" #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h" @@ -70,6 +72,10 @@ CefURLLoaderThrottleProviderImpl::CreateThrottles( } } + throttles.push_back(std::make_unique( + CefRenderThreadObserver::is_incognito_process(), + CefRenderThreadObserver::GetDynamicParams())); + return throttles; } diff --git a/patch/patch.cfg b/patch/patch.cfg index 98031c536..ee9101901 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -204,6 +204,9 @@ patches = [ }, { # Make some methods of ProfileManager virtual. + # + # Don't create IdentityManager in RendererUpdater. + # https://bitbucket.org/chromiumembedded/cef/issues/1917 'name': 'chrome_browser_profiles', }, { diff --git a/patch/patches/chrome_browser_profiles.patch b/patch/patches/chrome_browser_profiles.patch index 1039ad57b..b7adb1dc4 100644 --- a/patch/patches/chrome_browser_profiles.patch +++ b/patch/patches/chrome_browser_profiles.patch @@ -42,3 +42,37 @@ index 87ecf1fc998b..924c24fa42a2 100644 // Get the path of the last used profile, or if that's undefined, the default // profile. +diff --git chrome/browser/profiles/renderer_updater.cc chrome/browser/profiles/renderer_updater.cc +index 9dd42523f970..b8f5ae89ae3d 100644 +--- chrome/browser/profiles/renderer_updater.cc ++++ chrome/browser/profiles/renderer_updater.cc +@@ -7,6 +7,7 @@ + #include + + #include "base/bind.h" ++#include "cef/libcef/features/features.h" + #include "chrome/browser/content_settings/host_content_settings_map_factory.h" + #include "chrome/browser/profiles/profile.h" + #include "chrome/browser/signin/identity_manager_factory.h" +@@ -60,8 +61,12 @@ void GetGuestViewDefaultContentSettingRules( + + RendererUpdater::RendererUpdater(Profile* profile) + : profile_(profile), identity_manager_observer_(this) { ++#if !BUILDFLAG(ENABLE_CEF) + identity_manager_ = IdentityManagerFactory::GetForProfile(profile); + identity_manager_observer_.Add(identity_manager_); ++#else ++ identity_manager_ = nullptr; ++#endif + #if defined(OS_CHROMEOS) + oauth2_login_manager_ = + chromeos::OAuth2LoginManagerFactory::GetForProfile(profile_); +@@ -228,7 +233,7 @@ void RendererUpdater::UpdateRenderer( + force_google_safesearch_.GetValue(), + force_youtube_restrict_.GetValue(), + allowed_domains_for_apps_.GetValue(), +- identity_manager_->HasPrimaryAccount() ++ identity_manager_ && identity_manager_->HasPrimaryAccount() + ? cached_variation_ids_header_signed_in_ + : cached_variation_ids_header_)); + }