From: Your Name Date: Wed, 12 Oct 2022 09:19:46 +0000 Subject: WIN ADDTO Experimental user scripts support --- chrome/browser/BUILD.gn | 12 +++++++----- chrome/browser/about_flags.cc | 2 ++ chrome/browser/prefs/browser_prefs.cc | 2 ++ chrome/browser/profiles/BUILD.gn | 4 +++- ...chrome_browser_main_extra_parts_profiles.cc | 4 ++++ chrome/browser/profiles/profile_manager.cc | 4 ++++ chrome/browser/profiles/renderer_updater.cc | 11 ++++++++++- chrome/browser/profiles/renderer_updater.h | 2 ++ .../webui/chrome_web_ui_controller_factory.cc | 2 ++ chrome/renderer/BUILD.gn | 7 ++++++- .../renderer/chrome_content_renderer_client.cc | 18 ++++++++++++++++++ .../renderer/chrome_render_thread_observer.cc | 2 ++ 12 files changed, 62 insertions(+), 8 deletions(-) diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -3492,11 +3492,13 @@ static_library("browser") { ] deps += [ "//chrome/android/modules/dev_ui/provider:native" ] } - deps += [ - "//components/user_scripts/common", - "//components/user_scripts/browser", - "//components/user_scripts/android", - ] + if (is_android) { + deps += [ + "//components/user_scripts/common", + "//components/user_scripts/browser", + "//components/user_scripts/android", + ] + } } else { #!is_android sources += [ diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -7343,9 +7343,11 @@ const FeatureEntry kFeatureEntries[] = { FEATURE_VALUE_TYPE(ash::features::kClipboardHistoryNudgeSessionReset)}, #endif // BUILDFLAG(IS_CHROMEOS_ASH) +#if BUILDFLAG(IS_ANDROID) {"enable-userscripts-log", flag_descriptions::kEnableLoggingUserScriptsName, flag_descriptions::kEnableLoggingUserScriptsDescription, kOsDesktop | kOsAndroid, FEATURE_VALUE_TYPE(user_scripts::features::kEnableLoggingUserScripts)}, +#endif #if BUILDFLAG(IS_WIN) {"enable-media-foundation-video-capture", diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -1403,7 +1403,9 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, translate::TranslatePrefs::RegisterProfilePrefs(registry); omnibox::RegisterProfilePrefs(registry); ZeroSuggestProvider::RegisterProfilePrefs(registry); +#if BUILDFLAG(IS_ANDROID) user_scripts::UserScriptsPrefs::RegisterProfilePrefs(registry); +#endif #if BUILDFLAG(ENABLE_SESSION_SERVICE) RegisterSessionServiceLogProfilePrefs(registry); diff --git a/chrome/browser/profiles/BUILD.gn b/chrome/browser/profiles/BUILD.gn --- a/chrome/browser/profiles/BUILD.gn +++ b/chrome/browser/profiles/BUILD.gn @@ -57,10 +57,12 @@ source_set("profile") { "//components/profile_metrics", "//components/sync/driver", "//components/variations", - "//components/user_scripts/browser", "//content/public/browser", "//extensions/buildflags", ] + if (is_android) { + deps += [ "//components/user_scripts/browser" ] + } if (enable_extensions) { deps += [ "//extensions/browser" ] } diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc --- a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc +++ b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc @@ -408,7 +408,9 @@ #include "chrome/browser/user_notes/user_note_service_factory.h" #endif +#if BUILDFLAG(IS_ANDROID) #include "components/user_scripts/browser/userscripts_browser_client.h" +#endif namespace chrome { @@ -933,7 +935,9 @@ void ChromeBrowserMainExtraPartsProfiles:: #endif WebDataServiceFactory::GetInstance(); webrtc_event_logging::WebRtcEventLogManagerKeyedServiceFactory::GetInstance(); +#if BUILDFLAG(IS_ANDROID) user_scripts::UserScriptsBrowserClient::GetInstance(); +#endif } void ChromeBrowserMainExtraPartsProfiles::PreProfileInit() { diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -103,7 +103,9 @@ #include "extensions/common/manifest.h" #endif +#if BUILDFLAG(IS_ANDROID) #include "components/user_scripts/browser/userscripts_browser_client.h" +#endif #if BUILDFLAG(ENABLE_SESSION_SERVICE) #include "chrome/browser/sessions/app_session_service_factory.h" @@ -1452,11 +1454,13 @@ void ProfileManager::DoFinalInitForServices(Profile* profile, #endif +#if BUILDFLAG(IS_ANDROID) user_scripts::UserScriptsBrowserClient* userscript_client = user_scripts::UserScriptsBrowserClient::GetInstance(); if (userscript_client) { userscript_client->SetProfile(profile); } +#endif #if BUILDFLAG(ENABLE_SUPERVISED_USERS) // Initialization needs to happen after extension system initialization (for diff --git a/chrome/browser/profiles/renderer_updater.cc b/chrome/browser/profiles/renderer_updater.cc --- a/chrome/browser/profiles/renderer_updater.cc +++ b/chrome/browser/profiles/renderer_updater.cc @@ -53,7 +53,9 @@ RendererUpdater::RendererUpdater(Profile* profile) force_google_safesearch_.Init(prefs::kForceGoogleSafeSearch, pref_service); force_youtube_restrict_.Init(prefs::kForceYouTubeRestrict, pref_service); allowed_domains_for_apps_.Init(prefs::kAllowedDomainsForApps, pref_service); +#if BUILDFLAG(IS_ANDROID) activate_userscripts_.Init(user_scripts::prefs::kUserScriptsEnabled, pref_service); +#endif pref_change_registrar_.Init(pref_service); pref_change_registrar_.Add( @@ -68,10 +70,12 @@ RendererUpdater::RendererUpdater(Profile* profile) prefs::kAllowedDomainsForApps, base::BindRepeating(&RendererUpdater::UpdateAllRenderers, base::Unretained(this))); +#if BUILDFLAG(IS_ANDROID) pref_change_registrar_.Add( user_scripts::prefs::kUserScriptsEnabled, base::BindRepeating(&RendererUpdater::UpdateAllRenderers, base::Unretained(this))); +#endif } RendererUpdater::~RendererUpdater() { @@ -193,5 +197,10 @@ chrome::mojom::DynamicParamsPtr RendererUpdater::CreateRendererDynamicParams() return chrome::mojom::DynamicParams::New( force_google_safesearch_.GetValue(), force_youtube_restrict_.GetValue(), allowed_domains_for_apps_.GetValue(), - activate_userscripts_.GetValue()); +#if BUILDFLAG(IS_ANDROID) + activate_userscripts_.GetValue() +#else + false +#endif + ); } diff --git a/chrome/browser/profiles/renderer_updater.h b/chrome/browser/profiles/renderer_updater.h --- a/chrome/browser/profiles/renderer_updater.h +++ b/chrome/browser/profiles/renderer_updater.h @@ -93,7 +93,9 @@ class RendererUpdater : public KeyedService, // Prefs that we sync to the renderers. BooleanPrefMember force_google_safesearch_; +#if BUILDFLAG(IS_ANDROID) BooleanPrefMember activate_userscripts_; +#endif IntegerPrefMember force_youtube_restrict_; StringPrefMember allowed_domains_for_apps_; }; diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -860,8 +860,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, return &NewWebUI; if (url.host_piece() == chrome::kChromeUIVersionHost) return &NewWebUI; +#if BUILDFLAG(IS_ANDROID) if (url.host_piece() == user_scripts::kChromeUIUserScriptsHost) return &NewWebUI; +#endif #if !BUILDFLAG(IS_ANDROID) #if !BUILDFLAG(IS_CHROMEOS) diff --git a/chrome/renderer/BUILD.gn b/chrome/renderer/BUILD.gn --- a/chrome/renderer/BUILD.gn +++ b/chrome/renderer/BUILD.gn @@ -140,7 +140,6 @@ static_library("renderer") { "//components/content_capture/common", "//components/content_capture/renderer", "//components/content_settings/common:mojom", - "//components/user_scripts/renderer", "//components/content_settings/renderer", "//components/continuous_search/renderer", "//components/dom_distiller/content/renderer", @@ -217,6 +216,12 @@ static_library("renderer") { "//v8", ] + if (is_android) { + deps += [ + "//components/user_scripts/renderer", + ] + } + data_deps = [ "//tools/v8_context_snapshot" ] configs += [ "//build/config/compiler:wexit_time_destructors" ] diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -252,8 +252,10 @@ #include "chrome/renderer/media/chrome_key_systems.h" #endif +#if BUILDFLAG(IS_ANDROID) #include "components/user_scripts/common/user_scripts_features.h" #include "components/user_scripts/renderer/user_scripts_renderer_client.h" +#endif using autofill::AutofillAgent; using autofill::PasswordAutofillAgent; @@ -430,11 +432,13 @@ void ChromeContentRendererClient::RenderThreadStarted() { WebString::FromASCII(extensions::kExtensionScheme)); #endif +#if BUILDFLAG(IS_ANDROID) user_scripts::UserScriptsRendererClient* userscript_client = user_scripts::UserScriptsRendererClient::GetInstance(); if (userscript_client) { userscript_client->RenderThreadStarted(); } +#endif #if BUILDFLAG(ENABLE_SPELLCHECK) if (!spellcheck_) @@ -600,12 +604,14 @@ void ChromeContentRendererClient::RenderFrameCreated( render_frame, registry); #endif +#if BUILDFLAG(IS_ANDROID) user_scripts::UserScriptsRendererClient* userscript_client = user_scripts::UserScriptsRendererClient::GetInstance(); if (userscript_client) { userscript_client->RenderFrameCreated( render_frame, registry); } +#endif #if BUILDFLAG(ENABLE_PPAPI) new PepperHelper(render_frame); @@ -1609,6 +1615,9 @@ void ChromeContentRendererClient::RunScriptsAtDocumentStart( ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentStart( render_frame); // |render_frame| might be dead by now. +#endif +#if BUILDFLAG(IS_ANDROID) +#if BUILDFLAG(ENABLE_EXTENSIONS) static_assert(false, "Compiler error: extensions cannot be enabled with user scripts"); #endif user_scripts::UserScriptsRendererClient* userscript_client = @@ -1617,6 +1626,7 @@ void ChromeContentRendererClient::RunScriptsAtDocumentStart( userscript_client->RunScriptsAtDocumentStart( render_frame); } +#endif } void ChromeContentRendererClient::RunScriptsAtDocumentEnd( @@ -1625,6 +1635,9 @@ void ChromeContentRendererClient::RunScriptsAtDocumentEnd( ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentEnd( render_frame); // |render_frame| might be dead by now. +#endif +#if BUILDFLAG(IS_ANDROID) +#if BUILDFLAG(ENABLE_EXTENSIONS) static_assert(false, "Compiler error: extensions cannot be enabled with user scripts"); #endif user_scripts::UserScriptsRendererClient* userscript_client = @@ -1633,6 +1646,7 @@ void ChromeContentRendererClient::RunScriptsAtDocumentEnd( userscript_client->RunScriptsAtDocumentEnd( render_frame); } +#endif } void ChromeContentRendererClient::RunScriptsAtDocumentIdle( @@ -1641,6 +1655,9 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle( ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentIdle( render_frame); // |render_frame| might be dead by now. +#endif +#if BUILDFLAG(IS_ANDROID) +#if BUILDFLAG(ENABLE_EXTENSIONS) static_assert(false, "Compiler error: extensions cannot be enabled with user scripts"); #endif user_scripts::UserScriptsRendererClient* userscript_client = @@ -1649,6 +1666,7 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle( userscript_client->RunScriptsAtDocumentIdle( render_frame); } +#endif } void ChromeContentRendererClient:: diff --git a/chrome/renderer/chrome_render_thread_observer.cc b/chrome/renderer/chrome_render_thread_observer.cc --- a/chrome/renderer/chrome_render_thread_observer.cc +++ b/chrome/renderer/chrome_render_thread_observer.cc @@ -220,7 +220,9 @@ void ChromeRenderThreadObserver::SetInitialConfiguration( void ChromeRenderThreadObserver::SetConfiguration( chrome::mojom::DynamicParamsPtr params) { *GetDynamicConfigParams() = std::move(*params); +#if BUILDFLAG(IS_ANDROID) user_scripts::UserScriptsRendererClient::GetInstance()->ConfigurationUpdated(); +#endif } void ChromeRenderThreadObserver::OnRendererConfigurationAssociatedRequest( -- 2.25.1