363 lines
15 KiB
Diff
363 lines
15 KiB
Diff
From: Your Name <you@example.com>
|
|
Date: Mon, 6 Mar 2023 10:10:19 +0000
|
|
Subject: 111 ADDTO Experimental user scripts support
|
|
|
|
---
|
|
components/user_scripts/browser/BUILD.gn | 4 --
|
|
.../browser/resources/user-script-ui/BUILD.gn | 4 --
|
|
.../browser/ui/user_scripts_ui.cc | 3 +-
|
|
.../browser/user_script_loader.cc | 1 -
|
|
.../user_scripts/browser/user_script_loader.h | 1 -
|
|
.../user_scripts/browser/user_script_prefs.cc | 60 ++++++++++---------
|
|
components/user_scripts/common/constants.h | 6 --
|
|
.../user_scripts/common/url_pattern_set.cc | 18 +++---
|
|
.../user_scripts/common/url_pattern_set.h | 6 +-
|
|
.../renderer/extension_frame_helper.h | 1 -
|
|
.../user_scripts/renderer/script_context.h | 1 -
|
|
.../user_scripts/renderer/script_injection.cc | 1 -
|
|
.../user_scripts/renderer/script_injection.h | 1 -
|
|
.../renderer/script_injection_manager.cc | 2 -
|
|
.../renderer/script_injection_manager.h | 1 -
|
|
15 files changed, 45 insertions(+), 65 deletions(-)
|
|
|
|
diff --git a/components/user_scripts/browser/BUILD.gn b/components/user_scripts/browser/BUILD.gn
|
|
--- a/components/user_scripts/browser/BUILD.gn
|
|
+++ b/components/user_scripts/browser/BUILD.gn
|
|
@@ -66,10 +66,6 @@ source_set("browser_sources") {
|
|
]
|
|
}
|
|
|
|
-group("closure_compile") {
|
|
- deps = [ "resources/user-script-ui:closure_compile" ]
|
|
-}
|
|
-
|
|
grit("userscripts_browser_resources") {
|
|
source = "resources/browser_resources.grd"
|
|
|
|
diff --git a/components/user_scripts/browser/resources/user-script-ui/BUILD.gn b/components/user_scripts/browser/resources/user-script-ui/BUILD.gn
|
|
--- a/components/user_scripts/browser/resources/user-script-ui/BUILD.gn
|
|
+++ b/components/user_scripts/browser/resources/user-script-ui/BUILD.gn
|
|
@@ -1,9 +1,5 @@
|
|
import("//third_party/closure_compiler/compile_js.gni")
|
|
|
|
-js_type_check("closure_compile") {
|
|
- deps = [ ":view_script_source" ]
|
|
-}
|
|
-
|
|
js_library("view_script_source") {
|
|
sources = [ "user-scripts-ui.js" ]
|
|
deps = [
|
|
diff --git a/components/user_scripts/browser/ui/user_scripts_ui.cc b/components/user_scripts/browser/ui/user_scripts_ui.cc
|
|
--- a/components/user_scripts/browser/ui/user_scripts_ui.cc
|
|
+++ b/components/user_scripts/browser/ui/user_scripts_ui.cc
|
|
@@ -18,7 +18,6 @@
|
|
|
|
#include <memory>
|
|
|
|
-#include "base/bind.h"
|
|
#include "base/json/json_string_value_serializer.h"
|
|
#include "base/memory/writable_shared_memory_region.h"
|
|
#include "base/strings/string_util.h"
|
|
@@ -112,7 +111,7 @@ void UserScriptsUIHandler::OnScriptsLoaded(
|
|
std::unique_ptr<user_scripts::UserScriptList> user_scripts) {
|
|
loaded_scripts_ = std::move(user_scripts);
|
|
|
|
- base::ListValue response;
|
|
+ base::Value::List response;
|
|
for (const std::unique_ptr<user_scripts::UserScript>& script : *loaded_scripts_) {
|
|
if (script->key() == script_key) {
|
|
base::Value::Dict scriptData;
|
|
diff --git a/components/user_scripts/browser/user_script_loader.cc b/components/user_scripts/browser/user_script_loader.cc
|
|
--- a/components/user_scripts/browser/user_script_loader.cc
|
|
+++ b/components/user_scripts/browser/user_script_loader.cc
|
|
@@ -23,7 +23,6 @@
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
-#include "base/bind.h"
|
|
#include "base/memory/writable_shared_memory_region.h"
|
|
#include "base/strings/string_util.h"
|
|
#include "base/strings/strcat.h"
|
|
diff --git a/components/user_scripts/browser/user_script_loader.h b/components/user_scripts/browser/user_script_loader.h
|
|
--- a/components/user_scripts/browser/user_script_loader.h
|
|
+++ b/components/user_scripts/browser/user_script_loader.h
|
|
@@ -22,7 +22,6 @@
|
|
#include <memory>
|
|
#include <set>
|
|
|
|
-#include "base/callback_forward.h"
|
|
#include "base/compiler_specific.h"
|
|
#include "base/memory/read_only_shared_memory_region.h"
|
|
#include "base/memory/weak_ptr.h"
|
|
diff --git a/components/user_scripts/browser/user_script_prefs.cc b/components/user_scripts/browser/user_script_prefs.cc
|
|
--- a/components/user_scripts/browser/user_script_prefs.cc
|
|
+++ b/components/user_scripts/browser/user_script_prefs.cc
|
|
@@ -29,6 +29,8 @@
|
|
#include "components/prefs/pref_service.h"
|
|
#include "components/prefs/scoped_user_pref_update.h"
|
|
#include "components/pref_registry/pref_registry_syncable.h"
|
|
+#include "services/preferences/public/cpp/dictionary_value_update.h"
|
|
+#include "services/preferences/public/cpp/scoped_pref_update.h"
|
|
#include "user_script_prefs.h"
|
|
#include "user_script_pref_info.h"
|
|
#include "../common/user_script.h"
|
|
@@ -55,23 +57,24 @@ const char kScriptUrlSource[] = "url_source";
|
|
const char kScriptParserError[] = "parser_error";
|
|
const char kScriptForceDisabled[] = "force_disabled";
|
|
|
|
-class PrefUpdate : public DictionaryPrefUpdate {
|
|
+class PrefUpdate : public ::prefs::ScopedDictionaryPrefUpdate {
|
|
public:
|
|
PrefUpdate(PrefService* service,
|
|
const std::string& id,
|
|
const std::string& path)
|
|
- : DictionaryPrefUpdate(service, path), id_(id) {}
|
|
+ : ::prefs::ScopedDictionaryPrefUpdate(service, path), id_(id) {}
|
|
|
|
PrefUpdate(const PrefUpdate&) = delete;
|
|
PrefUpdate& operator=(const PrefUpdate&) = delete;
|
|
~PrefUpdate() override = default;
|
|
|
|
- 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));
|
|
+ std::unique_ptr<::prefs::DictionaryValueUpdate> Get() override {
|
|
+ std::unique_ptr<::prefs::DictionaryValueUpdate> dict =
|
|
+ ScopedDictionaryPrefUpdate::Get();
|
|
+ std::unique_ptr<::prefs::DictionaryValueUpdate> dict_item;
|
|
+ if (!dict->GetDictionaryWithoutPathExpansion(id_, &dict_item)) {
|
|
+ dict_item = dict->SetDictionaryWithoutPathExpansion(id_, base::Value::Dict());
|
|
+ }
|
|
return dict_item;
|
|
}
|
|
|
|
@@ -161,20 +164,20 @@ void UserScriptsPrefs::CompareWithPrefs(UserScriptList& user_scripts) {
|
|
scriptInfo->force_disabled = (it->get()->force_disabled());
|
|
|
|
PrefUpdate update(prefs_, key, kUserScriptsList);
|
|
- base::Value* script_dict = update.Get();
|
|
+ std::unique_ptr<::prefs::DictionaryValueUpdate> script_dict = update.Get();
|
|
|
|
- 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);
|
|
+ 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);
|
|
|
|
std::string install_time_str =
|
|
base::NumberToString(scriptInfo->install_time.ToInternalValue());
|
|
- script_dict->SetStringKey(kScriptInstallTime, install_time_str);
|
|
+ script_dict->SetString(kScriptInstallTime, install_time_str);
|
|
|
|
if (!scriptInfo->enabled) {
|
|
it = user_scripts.erase(it);
|
|
@@ -194,10 +197,10 @@ void UserScriptsPrefs::CompareWithPrefs(UserScriptList& user_scripts) {
|
|
}
|
|
}
|
|
|
|
- DictionaryPrefUpdate update(prefs_, kUserScriptsList);
|
|
- base::Value* const update_dict = update.Get();
|
|
+ ::prefs::ScopedDictionaryPrefUpdate update(prefs_, kUserScriptsList);
|
|
+ std::unique_ptr<::prefs::DictionaryValueUpdate> update_dict = update.Get();
|
|
for (auto key : all_scripts_to_remove) {
|
|
- update_dict->RemoveKey(key);
|
|
+ update_dict->RemoveWithoutPathExpansion(key, nullptr);
|
|
}
|
|
|
|
return;
|
|
@@ -254,17 +257,18 @@ std::unique_ptr<UserScriptsListPrefs::ScriptInfo> UserScriptsPrefs::CreateScript
|
|
}
|
|
|
|
void UserScriptsPrefs::RemoveScriptFromPrefs(const std::string& script_id) {
|
|
- DictionaryPrefUpdate update(prefs_, kUserScriptsList);
|
|
- base::Value* const update_dict = update.Get();
|
|
- update_dict->RemoveKey(script_id);
|
|
+ ::prefs::ScopedDictionaryPrefUpdate update(prefs_, kUserScriptsList);
|
|
+ std::unique_ptr<::prefs::DictionaryValueUpdate> const update_dict = update.Get();
|
|
+ update_dict->RemoveWithoutPathExpansion(script_id, nullptr);
|
|
}
|
|
|
|
void UserScriptsPrefs::SetScriptEnabled(const std::string& script_id, bool is_enabled) {
|
|
PrefUpdate update(prefs_, script_id, kUserScriptsList);
|
|
- base::Value* script_dict = update.Get();
|
|
- if (script_dict->FindBoolKey(kScriptForceDisabled).value_or(false))
|
|
- is_enabled = true;
|
|
- script_dict->SetBoolKey(kScriptIsEnabled, is_enabled);
|
|
+ std::unique_ptr<::prefs::DictionaryValueUpdate> script_dict = update.Get();
|
|
+ bool force_disabled;
|
|
+ script_dict->GetBoolean(kScriptForceDisabled, &force_disabled);
|
|
+ if (force_disabled) is_enabled = false;
|
|
+ script_dict->SetBoolean(kScriptIsEnabled, is_enabled);
|
|
}
|
|
|
|
}
|
|
diff --git a/components/user_scripts/common/constants.h b/components/user_scripts/common/constants.h
|
|
--- a/components/user_scripts/common/constants.h
|
|
+++ b/components/user_scripts/common/constants.h
|
|
@@ -5,12 +5,6 @@
|
|
#ifndef USERSCRIPTS_COMMON_CONSTANTS_H_
|
|
#define USERSCRIPTS_COMMON_CONSTANTS_H_
|
|
|
|
-#include "base/files/file_path.h"
|
|
-#include "base/strings/string_piece_forward.h"
|
|
-#include "components/services/app_service/public/mojom/types.mojom.h"
|
|
-#include "components/version_info/channel.h"
|
|
-#include "ui/base/layout.h"
|
|
-
|
|
namespace user_scripts {
|
|
|
|
// The origin of injected CSS.
|
|
diff --git a/components/user_scripts/common/url_pattern_set.cc b/components/user_scripts/common/url_pattern_set.cc
|
|
--- a/components/user_scripts/common/url_pattern_set.cc
|
|
+++ b/components/user_scripts/common/url_pattern_set.cc
|
|
@@ -274,14 +274,14 @@ bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const {
|
|
return false;
|
|
}
|
|
|
|
-std::unique_ptr<base::ListValue> URLPatternSet::ToValue() const {
|
|
- std::unique_ptr<base::ListValue> value(new base::ListValue);
|
|
- for (auto i = patterns_.cbegin(); i != patterns_.cend(); ++i) {
|
|
- base::Value pattern_str_value(i->GetAsString());
|
|
- if (!base::Contains(value->GetList(), pattern_str_value))
|
|
- value->Append(std::move(pattern_str_value));
|
|
+base::Value::List URLPatternSet::ToValue() const {
|
|
+ base::Value::List result;
|
|
+ for (const auto& pattern : patterns_) {
|
|
+ base::Value pattern_str_value(pattern.GetAsString());
|
|
+ if (!base::Contains(result, pattern_str_value))
|
|
+ result.Append(std::move(pattern_str_value));
|
|
}
|
|
- return value;
|
|
+ return result;
|
|
}
|
|
|
|
bool URLPatternSet::Populate(const std::vector<std::string>& patterns,
|
|
@@ -318,12 +318,12 @@ std::unique_ptr<std::vector<std::string>> URLPatternSet::ToStringVector()
|
|
return value;
|
|
}
|
|
|
|
-bool URLPatternSet::Populate(const base::ListValue& value,
|
|
+bool URLPatternSet::Populate(const base::Value::List& value,
|
|
int valid_schemes,
|
|
bool allow_file_access,
|
|
std::string* error) {
|
|
std::vector<std::string> patterns;
|
|
- for (const base::Value& pattern : value.GetList()) {
|
|
+ for (const base::Value& pattern : value) {
|
|
const std::string* item = pattern.GetIfString();
|
|
if (!item)
|
|
return false;
|
|
diff --git a/components/user_scripts/common/url_pattern_set.h b/components/user_scripts/common/url_pattern_set.h
|
|
--- a/components/user_scripts/common/url_pattern_set.h
|
|
+++ b/components/user_scripts/common/url_pattern_set.h
|
|
@@ -11,12 +11,12 @@
|
|
#include <memory>
|
|
#include <set>
|
|
|
|
+#include "base/values.h"
|
|
#include "url_pattern.h"
|
|
|
|
class GURL;
|
|
|
|
namespace base {
|
|
-class ListValue;
|
|
class Value;
|
|
}
|
|
|
|
@@ -134,8 +134,8 @@ class URLPatternSet {
|
|
bool OverlapsWith(const URLPatternSet& other) const;
|
|
|
|
// Converts to and from Value for serialization to preferences.
|
|
- std::unique_ptr<base::ListValue> ToValue() const;
|
|
- bool Populate(const base::ListValue& value,
|
|
+ base::Value::List ToValue() const;
|
|
+ bool Populate(const base::Value::List& value,
|
|
int valid_schemes,
|
|
bool allow_file_access,
|
|
std::string* error);
|
|
diff --git a/components/user_scripts/renderer/extension_frame_helper.h b/components/user_scripts/renderer/extension_frame_helper.h
|
|
--- a/components/user_scripts/renderer/extension_frame_helper.h
|
|
+++ b/components/user_scripts/renderer/extension_frame_helper.h
|
|
@@ -8,7 +8,6 @@
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
-#include "base/callback_forward.h"
|
|
#include "base/memory/weak_ptr.h"
|
|
#include "content/public/renderer/render_frame_observer.h"
|
|
#include "content/public/renderer/render_frame_observer_tracker.h"
|
|
diff --git a/components/user_scripts/renderer/script_context.h b/components/user_scripts/renderer/script_context.h
|
|
--- a/components/user_scripts/renderer/script_context.h
|
|
+++ b/components/user_scripts/renderer/script_context.h
|
|
@@ -10,7 +10,6 @@
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
-#include "base/callback.h"
|
|
#include "base/compiler_specific.h"
|
|
#include "base/threading/thread_checker.h"
|
|
#include "base/unguessable_token.h"
|
|
diff --git a/components/user_scripts/renderer/script_injection.cc b/components/user_scripts/renderer/script_injection.cc
|
|
--- a/components/user_scripts/renderer/script_injection.cc
|
|
+++ b/components/user_scripts/renderer/script_injection.cc
|
|
@@ -7,7 +7,6 @@
|
|
#include <map>
|
|
#include <utility>
|
|
|
|
-#include "base/bind.h"
|
|
#include "base/feature_list.h"
|
|
#include "base/lazy_instance.h"
|
|
#include "base/metrics/histogram_macros.h"
|
|
diff --git a/components/user_scripts/renderer/script_injection.h b/components/user_scripts/renderer/script_injection.h
|
|
--- a/components/user_scripts/renderer/script_injection.h
|
|
+++ b/components/user_scripts/renderer/script_injection.h
|
|
@@ -10,7 +10,6 @@
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
-#include "base/callback.h"
|
|
#include "base/memory/weak_ptr.h"
|
|
#include "base/values.h"
|
|
#include "../common/user_script.h"
|
|
diff --git a/components/user_scripts/renderer/script_injection_manager.cc b/components/user_scripts/renderer/script_injection_manager.cc
|
|
--- a/components/user_scripts/renderer/script_injection_manager.cc
|
|
+++ b/components/user_scripts/renderer/script_injection_manager.cc
|
|
@@ -8,10 +8,8 @@
|
|
#include <utility>
|
|
|
|
#include "base/auto_reset.h"
|
|
-#include "base/bind.h"
|
|
#include "base/feature_list.h"
|
|
#include "base/memory/weak_ptr.h"
|
|
-#include "base/threading/thread_task_runner_handle.h"
|
|
#include "base/values.h"
|
|
#include "base/logging.h"
|
|
#include "content/public/renderer/render_frame.h"
|
|
diff --git a/components/user_scripts/renderer/script_injection_manager.h b/components/user_scripts/renderer/script_injection_manager.h
|
|
--- a/components/user_scripts/renderer/script_injection_manager.h
|
|
+++ b/components/user_scripts/renderer/script_injection_manager.h
|
|
@@ -5,7 +5,6 @@
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
-#include "base/callback.h"
|
|
#include "base/scoped_observation.h"
|
|
#include "../common/user_script.h"
|
|
#include "script_injection.h"
|
|
--
|
|
2.25.1
|