Experimental user scripts for v99

Patch from uazo
This commit is contained in:
csagan5 2022-03-06 17:28:45 +01:00
parent e9cfbf1749
commit 3a7e27df6a

View file

@ -76,7 +76,7 @@ See also: components/user_scripts/README.md
.../user_scripts/browser/user_script_loader.h | 169 ++++
.../browser/user_script_pref_info.cc | 34 +
.../browser/user_script_pref_info.h | 72 ++
.../user_scripts/browser/user_script_prefs.cc | 276 ++++++
.../user_scripts/browser/user_script_prefs.cc | 278 ++++++
.../user_scripts/browser/user_script_prefs.h | 62 ++
.../browser/userscripts_browser_client.cc | 78 ++
.../browser/userscripts_browser_client.h | 62 ++
@ -133,7 +133,7 @@ See also: components/user_scripts/README.md
.../renderer/web_ui_injection_host.h | 27 +
.../strings/userscripts_strings.grdp | 55 ++
tools/gritsettings/resource_ids.spec | 6 +
111 files changed, 9573 insertions(+), 2 deletions(-)
111 files changed, 9575 insertions(+), 2 deletions(-)
create mode 100644 components/user_scripts/README.md
create mode 100755 components/user_scripts/android/BUILD.gn
create mode 100644 components/user_scripts/android/java/res/layout/accept_script_item.xml
@ -236,7 +236,7 @@ diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
}
if (enable_vr) {
@@ -535,6 +539,7 @@ android_library("chrome_java") {
@@ -536,6 +540,7 @@ android_library("chrome_java") {
"//components/ukm/android:java",
"//components/url_formatter/android:url_formatter_java",
"//components/user_prefs/android:java",
@ -262,7 +262,7 @@ diff --git a/chrome/android/java/res/xml/main_preferences.xml b/chrome/android/j
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
@@ -68,6 +68,7 @@ import org.chromium.content_public.browser.BrowserStartupController;
@@ -69,6 +69,7 @@ import org.chromium.content_public.browser.BrowserStartupController;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.widget.Toast;
@ -322,7 +322,7 @@ diff --git a/chrome/android/java_sources.gni b/chrome/android/java_sources.gni
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -3531,6 +3531,11 @@ static_library("browser") {
@@ -3533,6 +3533,11 @@ static_library("browser") {
]
deps += [ "//chrome/android/modules/dev_ui/provider:native" ]
}
@ -337,7 +337,7 @@ diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
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
@@ -148,6 +148,7 @@
@@ -149,6 +149,7 @@
#include "components/translate/core/browser/translate_ranker_impl.h"
#include "components/translate/core/common/translate_util.h"
#include "components/ui_devtools/switches.h"
@ -345,7 +345,7 @@ diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
#include "components/version_info/version_info.h"
#include "components/viz/common/features.h"
#include "components/viz/common/switches.h"
@@ -6492,6 +6493,10 @@ const FeatureEntry kFeatureEntries[] = {
@@ -6475,6 +6476,10 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(chromeos::features::kClipboardHistoryScreenshotNudge)},
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
@ -353,13 +353,13 @@ diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
+ flag_descriptions::kEnableLoggingUserScriptsDescription, kOsDesktop | kOsAndroid,
+ FEATURE_VALUE_TYPE(user_scripts::features::kEnableLoggingUserScripts)},
+
#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
{"enable-media-foundation-video-capture",
flag_descriptions::kEnableMediaFoundationVideoCaptureName,
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -4685,7 +4685,8 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
@@ -4677,7 +4677,8 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
chrome::mojom::DynamicParams dynamic_params = {
profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
@ -367,48 +367,48 @@ diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/ch
+ profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps),
+ false /*-> allow_userscript, don't care */};
result.push_back(std::make_unique<GoogleURLLoaderThrottle>(
#if defined(OS_ANDROID)
#if BUILDFLAG(IS_ANDROID)
client_data_header, is_tab_large_enough,
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -5430,6 +5430,11 @@ const char kDynamicTcmallocDescription[] =
#endif // BUILDFLAG(USE_TCMALLOC)
#endif // #if defined(OS_CHROMEOS) || defined(OS_LINUX)
@@ -5438,6 +5438,11 @@ const char kImproveAccessibilityTreeUsingLocalMLDescription[] =
"webpage to a local machine learning library and getting annotations.";
#endif // BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
+const char kEnableLoggingUserScriptsName[] = "Enable logging user scripts component";
+const char kEnableLoggingUserScriptsDescription[] =
+ "Enables logging for troubleshooting feature. "
+ "Enabling logs may make browsing slower.";
+
#if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MAC)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC)
const char kWebShareName[] = "Web Share";
const char kWebShareDescription[] =
diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h
--- a/chrome/browser/flag_descriptions.h
+++ b/chrome/browser/flag_descriptions.h
@@ -3166,6 +3166,9 @@ extern const char kDynamicTcmallocDescription[];
#endif // BUILDFLAG(USE_TCMALLOC)
#endif // #if defined(OS_CHROMEOS) || defined(OS_LINUX)
@@ -3154,6 +3154,9 @@ extern const char kImproveAccessibilityTreeUsingLocalMLName[];
extern const char kImproveAccessibilityTreeUsingLocalMLDescription[];
#endif // #if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
+extern const char kEnableLoggingUserScriptsName[];
+extern const char kEnableLoggingUserScriptsDescription[];
+
#if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MAC)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC)
extern const char kWebShareName[];
extern const char kWebShareDescription[];
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
@@ -235,6 +235,7 @@
@@ -238,6 +238,7 @@
#include "components/ntp_tiles/popular_sites_impl.h"
#include "components/permissions/contexts/geolocation_permission_context_android.h"
#include "components/query_tiles/tile_service_prefs.h"
+#include "components/user_scripts/browser/user_script_prefs.h"
#else // defined(OS_ANDROID)
#else // BUILDFLAG(IS_ANDROID)
#include "chrome/browser/cart/cart_service.h"
#include "chrome/browser/device_api/device_service_impl.h"
@@ -1203,6 +1204,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
@@ -1267,6 +1268,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
translate::TranslatePrefs::RegisterProfilePrefs(registry);
omnibox::RegisterProfilePrefs(registry);
ZeroSuggestProvider::RegisterProfilePrefs(registry);
@ -430,7 +430,7 @@ diff --git a/chrome/browser/profiles/BUILD.gn b/chrome/browser/profiles/BUILD.gn
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
@@ -225,6 +225,8 @@
@@ -229,6 +229,8 @@
#include "chrome/browser/ui/cocoa/screentime/screentime_features.h"
#endif
@ -439,7 +439,7 @@ diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
namespace chrome {
void AddProfilesExtraParts(ChromeBrowserMainParts* main_parts) {
@@ -536,6 +538,7 @@ void ChromeBrowserMainExtraPartsProfiles::
@@ -547,6 +549,7 @@ void ChromeBrowserMainExtraPartsProfiles::
#endif
WebDataServiceFactory::GetInstance();
webrtc_event_logging::WebRtcEventLogManagerKeyedServiceFactory::GetInstance();
@ -459,7 +459,7 @@ diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profile
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
#include "chrome/browser/sessions/app_session_service_factory.h"
#include "chrome/browser/sessions/session_service_factory.h"
@@ -1588,6 +1590,13 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
@@ -1623,6 +1625,13 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
}
#endif
@ -485,7 +485,7 @@ diff --git a/chrome/browser/profiles/renderer_updater.cc b/chrome/browser/profil
namespace {
#if BUILDFLAG(ENABLE_EXTENSIONS)
@@ -79,6 +81,7 @@ RendererUpdater::RendererUpdater(Profile* profile) : profile_(profile) {
@@ -75,6 +77,7 @@ RendererUpdater::RendererUpdater(Profile* profile) : 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);
@ -493,7 +493,7 @@ diff --git a/chrome/browser/profiles/renderer_updater.cc b/chrome/browser/profil
pref_change_registrar_.Init(pref_service);
pref_change_registrar_.Add(
@@ -93,6 +96,10 @@ RendererUpdater::RendererUpdater(Profile* profile) : profile_(profile) {
@@ -89,6 +92,10 @@ RendererUpdater::RendererUpdater(Profile* profile) : profile_(profile) {
prefs::kAllowedDomainsForApps,
base::BindRepeating(&RendererUpdater::UpdateAllRenderers,
base::Unretained(this)));
@ -504,7 +504,7 @@ diff --git a/chrome/browser/profiles/renderer_updater.cc b/chrome/browser/profil
}
RendererUpdater::~RendererUpdater() {
@@ -241,5 +248,6 @@ void RendererUpdater::UpdateRenderer(
@@ -236,5 +243,6 @@ void RendererUpdater::UpdateRenderer(
->SetConfiguration(chrome::mojom::DynamicParams::New(
force_google_safesearch_.GetValue(),
force_youtube_restrict_.GetValue(),
@ -526,7 +526,7 @@ diff --git a/chrome/browser/profiles/renderer_updater.h b/chrome/browser/profile
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
@@ -86,6 +86,7 @@
@@ -85,6 +85,7 @@
#include "components/security_interstitials/content/urls.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "components/site_engagement/content/site_engagement_service.h"
@ -534,19 +534,19 @@ diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrom
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/content_client.h"
@@ -707,6 +708,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
@@ -723,6 +724,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<UserActionsUI>;
if (url.host_piece() == chrome::kChromeUIVersionHost)
return &NewWebUI<VersionUI>;
+ if (url.host_piece() == user_scripts::kChromeUIUserScriptsHost)
+ return &NewWebUI<user_scripts::UserScriptsUI>;
#if !defined(OS_ANDROID)
#if !defined(OS_CHROMEOS)
#if !BUILDFLAG(IS_ANDROID)
#if !BUILDFLAG(IS_CHROMEOS)
diff --git a/chrome/chrome_paks.gni b/chrome/chrome_paks.gni
--- a/chrome/chrome_paks.gni
+++ b/chrome/chrome_paks.gni
@@ -106,6 +106,7 @@ template("chrome_extra_paks") {
@@ -109,6 +109,7 @@ template("chrome_extra_paks") {
"$root_gen_dir/third_party/blink/public/resources/inspector_overlay_resources.pak",
"$root_gen_dir/ui/resources/webui_generated_resources.pak",
"$root_gen_dir/ui/resources/webui_resources.pak",
@ -554,7 +554,7 @@ diff --git a/chrome/chrome_paks.gni b/chrome/chrome_paks.gni
]
deps = [
"//base/tracing/protos:chrome_track_event_resources",
@@ -122,6 +123,7 @@ template("chrome_extra_paks") {
@@ -125,6 +126,7 @@ template("chrome_extra_paks") {
"//third_party/blink/public:devtools_inspector_resources",
"//third_party/blink/public:resources",
"//ui/resources",
@ -576,7 +576,7 @@ diff --git a/chrome/common/renderer_configuration.mojom b/chrome/common/renderer
diff --git a/chrome/renderer/BUILD.gn b/chrome/renderer/BUILD.gn
--- a/chrome/renderer/BUILD.gn
+++ b/chrome/renderer/BUILD.gn
@@ -164,6 +164,7 @@ static_library("renderer") {
@@ -143,6 +143,7 @@ static_library("renderer") {
"//components/feed:feature_list",
"//components/feed/content/renderer:feed_renderer",
"//components/history_clusters/core",
@ -587,7 +587,7 @@ diff --git a/chrome/renderer/BUILD.gn b/chrome/renderer/BUILD.gn
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
@@ -249,6 +249,9 @@
@@ -247,6 +247,9 @@
#include "chrome/renderer/supervised_user/supervised_user_error_page_controller_delegate_impl.h"
#endif
@ -597,7 +597,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
using autofill::AutofillAgent;
using autofill::PasswordAutofillAgent;
using autofill::PasswordGenerationAgent;
@@ -421,6 +424,12 @@ void ChromeContentRendererClient::RenderThreadStarted() {
@@ -419,6 +422,12 @@ void ChromeContentRendererClient::RenderThreadStarted() {
WebString::FromASCII(extensions::kExtensionScheme));
#endif
@ -610,7 +610,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
#if BUILDFLAG(ENABLE_SPELLCHECK)
if (!spellcheck_)
InitSpellCheck();
@@ -557,6 +566,13 @@ void ChromeContentRendererClient::RenderFrameCreated(
@@ -555,6 +564,13 @@ void ChromeContentRendererClient::RenderFrameCreated(
render_frame, registry);
#endif
@ -624,7 +624,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
#if BUILDFLAG(ENABLE_PLUGINS)
new PepperHelper(render_frame);
#endif
@@ -1537,7 +1553,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentStart(
@@ -1540,7 +1556,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentStart(
ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentStart(
render_frame);
// |render_frame| might be dead by now.
@ -639,7 +639,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
}
void ChromeContentRendererClient::RunScriptsAtDocumentEnd(
@@ -1546,7 +1569,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentEnd(
@@ -1549,7 +1572,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentEnd(
ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentEnd(
render_frame);
// |render_frame| might be dead by now.
@ -654,7 +654,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
}
void ChromeContentRendererClient::RunScriptsAtDocumentIdle(
@@ -1555,7 +1585,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle(
@@ -1558,7 +1588,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle(
ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentIdle(
render_frame);
// |render_frame| might be dead by now.
@ -681,7 +681,7 @@ diff --git a/chrome/renderer/chrome_render_thread_observer.cc b/chrome/renderer/
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/renderer/extensions/extension_localization_peer.h"
#endif
@@ -255,6 +257,7 @@ void ChromeRenderThreadObserver::SetInitialConfiguration(
@@ -253,6 +255,7 @@ void ChromeRenderThreadObserver::SetInitialConfiguration(
void ChromeRenderThreadObserver::SetConfiguration(
chrome::mojom::DynamicParamsPtr params) {
*GetDynamicConfigParams() = std::move(*params);
@ -692,7 +692,7 @@ diff --git a/chrome/renderer/chrome_render_thread_observer.cc b/chrome/renderer/
diff --git a/components/components_strings.grd b/components/components_strings.grd
--- a/components/components_strings.grd
+++ b/components/components_strings.grd
@@ -335,6 +335,7 @@
@@ -337,6 +337,7 @@
<part file="undo_strings.grdp" />
<part file="version_ui_strings.grdp" />
<part file="webapps_strings.grdp" />
@ -3837,7 +3837,7 @@ diff --git a/components/user_scripts/browser/user_script_prefs.cc b/components/u
new file mode 100644
--- /dev/null
+++ b/components/user_scripts/browser/user_script_prefs.cc
@@ -0,0 +1,276 @@
@@ -0,0 +1,278 @@
+/*
+ This file is part of Bromite.
+
@ -3865,6 +3865,7 @@ new file mode 100644
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+
+#include "components/prefs/pref_registry_simple.h"
+#include "components/prefs/pref_service.h"
+#include "components/prefs/scoped_user_pref_update.h"
+#include "components/pref_registry/pref_registry_syncable.h"
@ -3896,22 +3897,22 @@ new file mode 100644
+
+class PrefUpdate : public DictionaryPrefUpdate {
+ public:
+ PrefUpdate(const PrefUpdate&) = delete;
+ PrefUpdate& operator=(const PrefUpdate&) = delete;
+ PrefUpdate(PrefService* service,
+ const std::string& id,
+ const std::string& path)
+ : DictionaryPrefUpdate(service, path), id_(id) {}
+
+ PrefUpdate(const PrefUpdate&) = delete;
+ PrefUpdate& operator=(const PrefUpdate&) = delete;
+ ~PrefUpdate() override = default;
+
+ base::DictionaryValue* Get() override {
+ base::DictionaryValue* dict = DictionaryPrefUpdate::Get();
+ base::Value* Get() override {
+ base::Value* dict = DictionaryPrefUpdate::Get();
+ base::Value* dict_item =
+ dict->FindKeyOfType(id_, base::Value::Type::DICTIONARY);
+ if (!dict_item)
+ dict_item = dict->SetKey(id_, base::Value(base::Value::Type::DICTIONARY));
+ return static_cast<base::DictionaryValue*>(dict_item);
+ return dict_item;
+ }
+
+ private:
@ -4000,20 +4001,20 @@ new file mode 100644
+ scriptInfo->force_disabled = (it->get()->force_disabled());
+
+ PrefUpdate update(prefs_, key, kUserScriptsList);
+ base::DictionaryValue* script_dict = update.Get();
+ base::Value* script_dict = update.Get();
+
+ script_dict->SetString(kScriptName, scriptInfo->name());
+ script_dict->SetString(kScriptDescription, scriptInfo->description());
+ script_dict->SetBoolean(kScriptIsEnabled, scriptInfo->enabled);
+ script_dict->SetString(kScriptVersion, scriptInfo->version());
+ script_dict->SetString(kScriptFilePath, scriptInfo->file_path());
+ script_dict->SetString(kScriptUrlSource, scriptInfo->url_source());
+ script_dict->SetString(kScriptParserError, scriptInfo->parser_error());
+ script_dict->SetBoolean(kScriptForceDisabled, scriptInfo->force_disabled);
+ script_dict->SetStringKey(kScriptName, scriptInfo->name());
+ script_dict->SetStringKey(kScriptDescription, scriptInfo->description());
+ script_dict->SetBoolKey(kScriptIsEnabled, scriptInfo->enabled);
+ script_dict->SetStringKey(kScriptVersion, scriptInfo->version());
+ script_dict->SetStringKey(kScriptFilePath, scriptInfo->file_path());
+ script_dict->SetStringKey(kScriptUrlSource, scriptInfo->url_source());
+ script_dict->SetStringKey(kScriptParserError, scriptInfo->parser_error());
+ script_dict->SetBoolKey(kScriptForceDisabled, scriptInfo->force_disabled);
+
+ std::string install_time_str =
+ base::NumberToString(scriptInfo->install_time.ToInternalValue());
+ script_dict->SetString(kScriptInstallTime, install_time_str);
+ script_dict->SetStringKey(kScriptInstallTime, install_time_str);
+
+ if (!scriptInfo->enabled) {
+ it = user_scripts.erase(it);
@ -4025,7 +4026,8 @@ new file mode 100644
+ // remove script from prefs if no more present
+ std::vector<std::string> all_scripts_to_remove;
+ const base::DictionaryValue* dict =
+ prefs_->GetDictionary(kUserScriptsList);
+ &base::Value::AsDictionaryValue(*prefs_->GetDictionary(
+ kUserScriptsList));
+ for (base::DictionaryValue::Iterator script_it(*dict); !script_it.IsAtEnd();
+ script_it.Advance()) {
+ const std::string& key = script_it.key();
@ -4036,7 +4038,7 @@ new file mode 100644
+ }
+
+ DictionaryPrefUpdate update(prefs_, kUserScriptsList);
+ base::DictionaryValue* const update_dict = update.Get();
+ base::Value* const update_dict = update.Get();
+ for (auto key : all_scripts_to_remove) {
+ update_dict->RemoveKey(key);
+ }
@ -4047,7 +4049,7 @@ new file mode 100644
+std::string UserScriptsPrefs::GetScriptsInfo() {
+ std::string json_string;
+
+ const base::DictionaryValue* dict =
+ const base::Value* dict =
+ prefs_->GetDictionary(kUserScriptsList);
+
+ if (dict) {
@ -4065,7 +4067,7 @@ new file mode 100644
+ auto scriptInfo = std::make_unique<UserScriptsListPrefs::ScriptInfo>(
+ script_id, "", base::Time::Now(), false);
+
+ const base::DictionaryValue* scripts =
+ const base::Value* scripts =
+ prefs_->GetDictionary(kUserScriptsList);
+ if (!scripts)
+ return scriptInfo;
@ -4101,16 +4103,16 @@ new file mode 100644
+
+void UserScriptsPrefs::RemoveScriptFromPrefs(const std::string& script_id) {
+ DictionaryPrefUpdate update(prefs_, kUserScriptsList);
+ base::DictionaryValue* const update_dict = update.Get();
+ base::Value* const update_dict = update.Get();
+ update_dict->RemoveKey(script_id);
+}
+
+void UserScriptsPrefs::SetScriptEnabled(const std::string& script_id, bool is_enabled) {
+ PrefUpdate update(prefs_, script_id, kUserScriptsList);
+ base::DictionaryValue* script_dict = update.Get();
+ base::Value* script_dict = update.Get();
+ if (script_dict->FindBoolKey(kScriptForceDisabled).value_or(false))
+ is_enabled = true;
+ script_dict->SetBoolean(kScriptIsEnabled, is_enabled);
+ script_dict->SetBoolKey(kScriptIsEnabled, is_enabled);
+}
+
+}
@ -6228,11 +6230,11 @@ new file mode 100755
+ bool allow_file_access,
+ std::string* error) {
+ std::vector<std::string> patterns;
+ for (size_t i = 0; i < value.GetList().size(); ++i) {
+ std::string item;
+ if (!value.GetString(i, &item))
+ for (const base::Value& pattern : value.GetList()) {
+ const std::string* item = pattern.GetIfString();
+ if (!item)
+ return false;
+ patterns.push_back(item);
+ patterns.push_back(*item);
+ }
+ return Populate(patterns, valid_schemes, allow_file_access, error);
+}
@ -10607,7 +10609,7 @@ new file mode 100755
diff --git a/tools/gritsettings/resource_ids.spec b/tools/gritsettings/resource_ids.spec
--- a/tools/gritsettings/resource_ids.spec
+++ b/tools/gritsettings/resource_ids.spec
@@ -595,6 +595,12 @@
@@ -603,6 +603,12 @@
"components/autofill/core/browser/autofill_address_rewriter_resources.grd":{
"includes": [3720]
},