v93 ready

This commit is contained in:
Carmelo Messina 2021-09-17 11:36:14 +02:00
parent 571e8591b6
commit 9765d4d994

View file

@ -3,10 +3,10 @@ Date: Fri, 13 Aug 2021 17:10:47 +0000
Subject: Experimental user scripts support preview
needs
add-support-for-ISupportHelpAndFeedback.patch
add-support-for-prefs-addon.patch
---
chrome/android/BUILD.gn | 5 +
.../android/java/res/xml/main_preferences.xml | 5 +
.../chrome/browser/AfterStartupTaskUtils.java | 2 +
.../browser/download/DownloadUtils.java | 6 +
chrome/android/java_sources.gni | 3 +
@ -25,18 +25,17 @@ add-support-for-prefs-addon.patch
chrome/chrome_paks.gni | 2 +
chrome/common/renderer_configuration.mojom | 1 +
chrome/renderer/BUILD.gn | 1 +
.../chrome_content_renderer_client.cc | 36 +
.../chrome_content_renderer_client.cc | 37 +
.../renderer/chrome_render_thread_observer.cc | 3 +
components/components_strings.grd | 1 +
components/user_scripts/android/BUILD.gn | 82 ++
components/user_scripts/android/BUILD.gn | 81 ++
.../java/res/layout/accept_script_item.xml | 160 ++++
.../java/res/layout/accept_script_list.xml | 10 +
.../java/res/layout/scripts_preference.xml | 40 +
.../android/java/res/values/dimens.xml | 11 +
.../main_preferences_addon_userscripts.xml | 29 +
.../java/res/xml/userscripts_preferences.xml | 34 +
.../user_scripts/UserScriptsUtils.java | 84 ++
.../user_scripts/FragmentWindowAndroid.java | 68 ++
.../user_scripts/FragmentWindowAndroid.java | 89 ++
.../user_scripts/IUserScriptsUtils.java | 22 +
.../components/user_scripts/ScriptInfo.java | 37 +
.../user_scripts/ScriptListBaseAdapter.java | 163 ++++
@ -46,7 +45,7 @@ add-support-for-prefs-addon.patch
.../user_scripts/android/java_sources.gni | 18 +
.../android/user_scripts_bridge.cc | 174 ++++
.../android/user_scripts_bridge.h | 31 +
components/user_scripts/browser/BUILD.gn | 91 ++
components/user_scripts/browser/BUILD.gn | 86 ++
.../user_scripts/browser/file_task_runner.cc | 40 +
.../user_scripts/browser/file_task_runner.h | 34 +
.../browser/resources/browser_resources.grd | 14 +
@ -56,7 +55,7 @@ add-support-for-prefs-addon.patch
.../browser/ui/user_scripts_ui.cc | 148 ++++
.../user_scripts/browser/ui/user_scripts_ui.h | 39 +
.../browser/user_script_loader.cc | 721 ++++++++++++++++
.../user_scripts/browser/user_script_loader.h | 171 ++++
.../user_scripts/browser/user_script_loader.h | 170 ++++
.../browser/user_script_pref_info.cc | 34 +
.../browser/user_script_pref_info.h | 72 ++
.../user_scripts/browser/user_script_prefs.cc | 276 ++++++
@ -76,7 +75,7 @@ add-support-for-prefs-addon.patch
.../user_scripts/common/script_constants.h | 33 +
components/user_scripts/common/url_pattern.cc | 803 ++++++++++++++++++
components/user_scripts/common/url_pattern.h | 302 +++++++
.../user_scripts/common/url_pattern_set.cc | 333 ++++++++
.../user_scripts/common/url_pattern_set.cc | 334 ++++++++
.../user_scripts/common/url_pattern_set.h | 161 ++++
components/user_scripts/common/user_script.cc | 317 +++++++
components/user_scripts/common/user_script.h | 403 +++++++++
@ -91,10 +90,10 @@ add-support-for-prefs-addon.patch
.../user_scripts/renderer/injection_host.h | 42 +
.../renderer/resources/greasemonkey_api.js | 82 ++
.../user_scripts_renderer_resources.grd | 14 +
.../user_scripts/renderer/script_context.cc | 213 +++++
.../user_scripts/renderer/script_context.cc | 215 +++++
.../user_scripts/renderer/script_context.h | 70 ++
.../user_scripts/renderer/script_injection.cc | 343 ++++++++
.../user_scripts/renderer/script_injection.h | 156 ++++
.../user_scripts/renderer/script_injection.h | 155 ++++
.../renderer/script_injection_callback.cc | 25 +
.../renderer/script_injection_callback.h | 39 +
.../renderer/script_injection_manager.cc | 417 +++++++++
@ -116,13 +115,12 @@ add-support-for-prefs-addon.patch
.../renderer/web_ui_injection_host.h | 28 +
.../strings/userscripts_strings.grdp | 55 ++
tools/gritsettings/resource_ids.spec | 6 +
110 files changed, 9444 insertions(+), 2 deletions(-)
110 files changed, 9437 insertions(+), 2 deletions(-)
create mode 100755 components/user_scripts/android/BUILD.gn
create mode 100644 components/user_scripts/android/java/res/layout/accept_script_item.xml
create mode 100644 components/user_scripts/android/java/res/layout/accept_script_list.xml
create mode 100644 components/user_scripts/android/java/res/layout/scripts_preference.xml
create mode 100755 components/user_scripts/android/java/res/values/dimens.xml
create mode 100755 components/user_scripts/android/java/res/xml/main_preferences_addon_userscripts.xml
create mode 100644 components/user_scripts/android/java/res/xml/userscripts_preferences.xml
create mode 100755 components/user_scripts/android/java/src/org/chromium/chrome/browser/user_scripts/UserScriptsUtils.java
create mode 100644 components/user_scripts/android/java/src/org/chromium/components/user_scripts/FragmentWindowAndroid.java
@ -208,7 +206,7 @@ add-support-for-prefs-addon.patch
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -244,6 +244,10 @@ android_resources("chrome_app_java_resources") {
@@ -247,6 +247,10 @@ android_resources("chrome_app_java_resources") {
"//third_party/androidx:androidx_preference_preference_java",
"//third_party/androidx:androidx_recyclerview_recyclerview_java",
]
@ -219,7 +217,7 @@ diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
}
if (enable_vr) {
@@ -488,6 +492,7 @@ android_library("chrome_java") {
@@ -505,6 +509,7 @@ android_library("chrome_java") {
"//components/ukm/android:java",
"//components/url_formatter/android:url_formatter_java",
"//components/user_prefs/android:java",
@ -227,6 +225,21 @@ diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
"//components/variations/android:variations_java",
"//components/version_info/android:version_constants_java",
"//components/viz/common:common_java",
diff --git a/chrome/android/java/res/xml/main_preferences.xml b/chrome/android/java/res/xml/main_preferences.xml
--- a/chrome/android/java/res/xml/main_preferences.xml
+++ b/chrome/android/java/res/xml/main_preferences.xml
@@ -80,6 +80,11 @@
android:key="useragent_settings"
android:order="20"
android:title="@string/prefs_useragent_settings"/>
+ <Preference
+ android:fragment="org.chromium.components.user_scripts.UserScriptsPreferences"
+ android:key="userscripts_settings"
+ android:order="20"
+ android:title="@string/prefs_userscripts_settings"/>
<Preference
android:fragment="org.chromium.chrome.browser.language.settings.LanguageSettings"
android:key="languages"
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/AfterStartupTaskUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/AfterStartupTaskUtils.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/AfterStartupTaskUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/AfterStartupTaskUtils.java
@ -257,7 +270,7 @@ diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/Downlo
import java.io.File;
@@ -376,6 +377,11 @@ public class DownloadUtils {
@@ -393,6 +394,11 @@ public class DownloadUtils {
public static boolean openFile(String filePath, String mimeType, String downloadGuid,
OTRProfileID otrProfileID, String originalUrl, String referrer,
@DownloadOpenSource int source, Context context) {
@ -289,7 +302,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
@@ -3384,6 +3384,11 @@ static_library("browser") {
@@ -3359,6 +3359,11 @@ static_library("browser") {
]
deps += [ "//chrome/android/modules/dev_ui/provider:native" ]
}
@ -304,7 +317,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
@@ -139,6 +139,7 @@
@@ -141,6 +141,7 @@
#include "components/translate/core/browser/translate_ranker_impl.h"
#include "components/translate/core/common/translate_util.h"
#include "components/ui_devtools/switches.h"
@ -312,7 +325,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"
@@ -6447,6 +6448,10 @@ const FeatureEntry kFeatureEntries[] = {
@@ -6514,6 +6515,10 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(features::kUserDataSnapshot)},
#endif
@ -326,7 +339,7 @@ diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
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
@@ -4530,7 +4530,8 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
@@ -4478,7 +4478,8 @@ ChromeContentBrowserClient::CreateURLLoaderThrottles(
chrome::mojom::DynamicParams dynamic_params = {
profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch),
profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict),
@ -339,7 +352,7 @@ diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/ch
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
@@ -5140,6 +5140,11 @@ const char kUserDataSnapshotDescription[] =
@@ -5439,6 +5439,11 @@ const char kUserDataSnapshotDescription[] =
"update and restoring them after a version rollback.";
#endif // !defined(OS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)
@ -354,7 +367,7 @@ diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descripti
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
@@ -3017,6 +3017,9 @@ extern const char kUserDataSnapshotName[];
@@ -3168,6 +3168,9 @@ extern const char kUserDataSnapshotName[];
extern const char kUserDataSnapshotDescription[];
#endif // !defined(OS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)
@ -367,7 +380,7 @@ diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptio
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
@@ -230,6 +230,7 @@
@@ -233,6 +233,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"
@ -375,7 +388,7 @@ diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browse
#else // defined(OS_ANDROID)
#include "chrome/browser/accessibility/live_caption_controller.h"
#include "chrome/browser/cart/cart_service.h"
@@ -1022,6 +1023,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
@@ -1132,6 +1133,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
translate::TranslatePrefs::RegisterProfilePrefs(registry);
omnibox::RegisterProfilePrefs(registry);
ZeroSuggestProvider::RegisterProfilePrefs(registry);
@ -397,7 +410,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
@@ -212,6 +212,8 @@
@@ -207,6 +207,8 @@
#include "chrome/browser/ui/cocoa/screentime/screentime_features.h"
#endif
@ -406,7 +419,7 @@ diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
namespace chrome {
void AddProfilesExtraParts(ChromeBrowserMainParts* main_parts) {
@@ -494,6 +496,7 @@ void ChromeBrowserMainExtraPartsProfiles::
@@ -489,6 +491,7 @@ void ChromeBrowserMainExtraPartsProfiles::
#endif
WebDataServiceFactory::GetInstance();
webrtc_event_logging::WebRtcEventLogManagerKeyedServiceFactory::GetInstance();
@ -417,7 +430,7 @@ diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc
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
@@ -114,6 +114,8 @@
@@ -113,6 +113,8 @@
#include "extensions/common/manifest.h"
#endif
@ -426,7 +439,7 @@ diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profile
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
#include "chrome/browser/sessions/session_service_factory.h"
#endif
@@ -1603,6 +1605,13 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
@@ -1512,6 +1514,13 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
}
#endif
@ -443,7 +456,7 @@ diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profile
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
@@ -26,6 +26,8 @@
@@ -29,6 +29,8 @@
#include "chrome/browser/ash/login/signin/oauth2_login_manager_factory.h"
#endif
@ -452,7 +465,7 @@ diff --git a/chrome/browser/profiles/renderer_updater.cc b/chrome/browser/profil
namespace {
#if BUILDFLAG(ENABLE_EXTENSIONS)
@@ -71,6 +73,7 @@ RendererUpdater::RendererUpdater(Profile* profile) : profile_(profile) {
@@ -74,6 +76,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);
@ -460,7 +473,7 @@ diff --git a/chrome/browser/profiles/renderer_updater.cc b/chrome/browser/profil
pref_change_registrar_.Init(pref_service);
pref_change_registrar_.Add(
@@ -85,6 +88,10 @@ RendererUpdater::RendererUpdater(Profile* profile) : profile_(profile) {
@@ -88,6 +91,10 @@ RendererUpdater::RendererUpdater(Profile* profile) : profile_(profile) {
prefs::kAllowedDomainsForApps,
base::BindRepeating(&RendererUpdater::UpdateAllRenderers,
base::Unretained(this)));
@ -471,7 +484,7 @@ diff --git a/chrome/browser/profiles/renderer_updater.cc b/chrome/browser/profil
}
RendererUpdater::~RendererUpdater() {
@@ -208,5 +215,6 @@ void RendererUpdater::UpdateRenderer(
@@ -221,5 +228,6 @@ void RendererUpdater::UpdateRenderer(
->SetConfiguration(chrome::mojom::DynamicParams::New(
force_google_safesearch_.GetValue(),
force_youtube_restrict_.GetValue(),
@ -493,7 +506,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
@@ -83,6 +83,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"
@ -501,7 +514,7 @@ 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"
@@ -633,6 +634,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
@@ -645,6 +646,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<UserActionsUI>;
if (url.host_piece() == chrome::kChromeUIVersionHost)
return &NewWebUI<VersionUI>;
@ -532,7 +545,7 @@ diff --git a/chrome/chrome_paks.gni b/chrome/chrome_paks.gni
diff --git a/chrome/common/renderer_configuration.mojom b/chrome/common/renderer_configuration.mojom
--- a/chrome/common/renderer_configuration.mojom
+++ b/chrome/common/renderer_configuration.mojom
@@ -11,6 +11,7 @@ struct DynamicParams {
@@ -12,6 +12,7 @@ struct DynamicParams {
bool force_safe_search = true;
int32 youtube_restrict = 0;
string allowed_domains_for_apps;
@ -543,7 +556,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
@@ -168,6 +168,7 @@ static_library("renderer") {
@@ -169,6 +169,7 @@ static_library("renderer") {
"//components/feed:buildflags",
"//components/feed:feature_list",
"//components/feed/content/renderer:feed_renderer",
@ -554,17 +567,18 @@ 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
@@ -169,6 +169,8 @@
#include "chrome/renderer/sandbox_status_extension_android.h"
#include "components/continuous_search/renderer/search_result_extractor_impl.h" // nogncheck
#include "components/embedder_support/android/common/url_constants.h"
@@ -250,6 +250,9 @@
#include "chrome/renderer/supervised_user/supervised_user_error_page_controller_delegate_impl.h"
#endif
+#include "components/user_scripts/common/user_scripts_features.h"
+#include "components/user_scripts/renderer/user_scripts_renderer_client.h"
#else
#include "chrome/renderer/cart/commerce_hint_agent.h"
#include "chrome/renderer/media/chrome_speech_recognition_client.h"
@@ -398,6 +400,12 @@ void ChromeContentRendererClient::RenderThreadStarted() {
ChromeExtensionsRendererClient::GetInstance()->RenderThreadStarted();
+
using autofill::AutofillAgent;
using autofill::AutofillAssistantAgent;
using autofill::PasswordAutofillAgent;
@@ -404,6 +407,12 @@ void ChromeContentRendererClient::RenderThreadStarted() {
WebString::FromASCII(extensions::kExtensionScheme));
#endif
+ user_scripts::UserScriptsRendererClient* userscript_client =
@ -576,7 +590,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
#if BUILDFLAG(ENABLE_SPELLCHECK)
if (!spellcheck_)
InitSpellCheck();
@@ -528,6 +536,13 @@ void ChromeContentRendererClient::RenderFrameCreated(
@@ -540,6 +549,13 @@ void ChromeContentRendererClient::RenderFrameCreated(
render_frame, registry);
#endif
@ -590,7 +604,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
#if BUILDFLAG(ENABLE_PLUGINS)
new PepperHelper(render_frame);
#endif
@@ -1499,7 +1514,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentStart(
@@ -1527,7 +1543,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentStart(
ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentStart(
render_frame);
// |render_frame| might be dead by now.
@ -605,7 +619,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
}
void ChromeContentRendererClient::RunScriptsAtDocumentEnd(
@@ -1508,7 +1530,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentEnd(
@@ -1536,7 +1559,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentEnd(
ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentEnd(
render_frame);
// |render_frame| might be dead by now.
@ -620,7 +634,7 @@ diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer
}
void ChromeContentRendererClient::RunScriptsAtDocumentIdle(
@@ -1517,7 +1546,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle(
@@ -1545,7 +1575,14 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle(
ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentIdle(
render_frame);
// |render_frame| might be dead by now.
@ -647,7 +661,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
@@ -251,6 +253,7 @@ void ChromeRenderThreadObserver::SetInitialConfiguration(
@@ -255,6 +257,7 @@ void ChromeRenderThreadObserver::SetInitialConfiguration(
void ChromeRenderThreadObserver::SetConfiguration(
chrome::mojom::DynamicParamsPtr params) {
*GetDynamicConfigParams() = std::move(*params);
@ -670,7 +684,7 @@ diff --git a/components/user_scripts/android/BUILD.gn b/components/user_scripts/
new file mode 100755
--- /dev/null
+++ b/components/user_scripts/android/BUILD.gn
@@ -0,0 +1,82 @@
@@ -0,0 +1,81 @@
+# This file is part of Bromite.
+
+# Bromite is free software: you can redistribute it and/or modify
@ -694,7 +708,6 @@ new file mode 100755
+
+android_resources("java_resources") {
+ sources = [
+ "java/res/xml/main_preferences_addon_userscripts.xml",
+ "java/res/xml/userscripts_preferences.xml",
+ "java/res/layout/accept_script_item.xml",
+ "java/res/layout/accept_script_list.xml",
@ -997,40 +1010,6 @@ new file mode 100755
+ <dimen name="pref_scripts_item_popup_width">260dp</dimen>
+
+</resources>
diff --git a/components/user_scripts/android/java/res/xml/main_preferences_addon_userscripts.xml b/components/user_scripts/android/java/res/xml/main_preferences_addon_userscripts.xml
new file mode 100755
--- /dev/null
+++ b/components/user_scripts/android/java/res/xml/main_preferences_addon_userscripts.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ This file is part of Bromite.
+
+ Bromite is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Bromite is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Bromite. If not, see <https://www.gnu.org/licenses/>.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:orderingFromXml="false">
+
+ <Preference
+ android:fragment="org.chromium.components.user_scripts.UserScriptsPreferences"
+ android:key="userscripts_settings"
+ android:order="20"
+ android:title="@string/prefs_userscripts_settings"/>
+
+</PreferenceScreen>
diff --git a/components/user_scripts/android/java/res/xml/userscripts_preferences.xml b/components/user_scripts/android/java/res/xml/userscripts_preferences.xml
new file mode 100644
--- /dev/null
@ -1164,7 +1143,7 @@ diff --git a/components/user_scripts/android/java/src/org/chromium/components/us
new file mode 100644
--- /dev/null
+++ b/components/user_scripts/android/java/src/org/chromium/components/user_scripts/FragmentWindowAndroid.java
@@ -0,0 +1,68 @@
@@ -0,0 +1,89 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
@ -1184,7 +1163,9 @@ new file mode 100644
+import org.chromium.ui.base.ActivityKeyboardVisibilityDelegate;
+import org.chromium.ui.base.ActivityAndroidPermissionDelegate;
+import org.chromium.ui.base.ImmutableWeakReference;
+import org.chromium.ui.base.IntentWindowAndroid;
+import org.chromium.ui.base.IntentRequestTracker;
+import org.chromium.ui.base.IntentRequestTracker.Delegate;
+import org.chromium.ui.base.WindowAndroid;
+
+import java.lang.ref.WeakReference;
+
@ -1192,46 +1173,65 @@ new file mode 100644
+ * Implements intent sending for a fragment based window. This should be created when
+ * onAttach() is called on the fragment, and destroyed when onDetach() is called.
+ */
+public class FragmentWindowAndroid extends IntentWindowAndroid {
+public class FragmentWindowAndroid extends WindowAndroid {
+ private Fragment mFragment;
+
+ // This WeakReference is purely to avoid gc churn of creating a new WeakReference in
+ // every getActivity call. It is not needed for correctness.
+ private ImmutableWeakReference<Activity> mActivityWeakRefHolder;
+ private static class TrackerDelegateImpl implements Delegate {
+ private final Fragment mFragment;
+ // This WeakReference is purely to avoid gc churn of creating a new WeakReference in
+ // every getActivity call. It is not needed for correctness.
+ private ImmutableWeakReference<Activity> mActivityWeakRefHolder;
+
+ /**
+ * Create an instance of delegate for the given fragment that will own the
+ * IntentRequestTracker.
+ * @param fragment The fragment that owns the IntentRequestTracker.
+ */
+ private TrackerDelegateImpl(Fragment fragment) {
+ mFragment = fragment;
+ }
+
+ @Override
+ public boolean startActivityForResult(Intent intent, int requestCode) {
+ mFragment.startActivityForResult(intent, requestCode, null);
+ return true;
+ }
+
+ @Override
+ public boolean startIntentSenderForResult(IntentSender intentSender, int requestCode) {
+ try {
+ mFragment.startIntentSenderForResult(
+ intentSender, requestCode, new Intent(), 0, 0, 0, null);
+ } catch (IntentSender.SendIntentException e) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void finishActivity(int requestCode) {
+ Activity activity = getActivity().get();
+ if (activity == null) return;
+ activity.finishActivity(requestCode);
+ }
+
+ @Override
+ public final WeakReference<Activity> getActivity() {
+ if (mActivityWeakRefHolder == null
+ || mActivityWeakRefHolder.get() != mFragment.getActivity()) {
+ mActivityWeakRefHolder = new ImmutableWeakReference<>(mFragment.getActivity());
+ }
+ return mActivityWeakRefHolder;
+ }
+ }
+
+ FragmentWindowAndroid(Context context, Fragment fragment) {
+ super(context);
+ super(context, IntentRequestTracker.createFromDelegate(new TrackerDelegateImpl(fragment)));
+ mFragment = fragment;
+
+ setKeyboardDelegate(new ActivityKeyboardVisibilityDelegate(getActivity()));
+ setAndroidPermissionDelegate(new ActivityAndroidPermissionDelegate(getActivity()));
+ }
+
+ @Override
+ protected final boolean startIntentSenderForResult(IntentSender intentSender, int requestCode) {
+ try {
+ mFragment.startIntentSenderForResult(
+ intentSender, requestCode, new Intent(), 0, 0, 0, null);
+ } catch (IntentSender.SendIntentException e) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected final boolean startActivityForResult(Intent intent, int requestCode) {
+ mFragment.startActivityForResult(intent, requestCode, null);
+ return true;
+ }
+
+ @Override
+ public final WeakReference<Activity> getActivity() {
+ if (mActivityWeakRefHolder == null
+ || mActivityWeakRefHolder.get() != mFragment.getActivity()) {
+ mActivityWeakRefHolder = new ImmutableWeakReference<>(mFragment.getActivity());
+ }
+ return mActivityWeakRefHolder;
+ }
+}
\ No newline at end of file
diff --git a/components/user_scripts/android/java/src/org/chromium/components/user_scripts/IUserScriptsUtils.java b/components/user_scripts/android/java/src/org/chromium/components/user_scripts/IUserScriptsUtils.java
@ -1925,7 +1925,7 @@ new file mode 100755
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ // handle picker callback from SelectFileDialog
+ mWindowAndroid.onActivityResult(requestCode, resultCode, data);
+ mWindowAndroid.getIntentRequestTracker().onActivityResult(requestCode, resultCode, data, mWindowAndroid);
+ }
+
+ public void onHelpAndFeebackPressed() {
@ -2221,7 +2221,7 @@ diff --git a/components/user_scripts/browser/BUILD.gn b/components/user_scripts/
new file mode 100755
--- /dev/null
+++ b/components/user_scripts/browser/BUILD.gn
@@ -0,0 +1,91 @@
@@ -0,0 +1,86 @@
+# This file is part of Bromite.
+
+# Bromite is free software: you can redistribute it and/or modify
@ -2307,11 +2307,6 @@ new file mode 100755
+ "grit/userscripts_browser_resources.h",
+ "userscripts_browser_resources.pak",
+ ]
+
+ deps = [
+ "//chrome/browser/resources/web_app_internals:components",
+ "//chrome/browser/ui/webui/internals/web_app:mojo_bindings_js",
+ ]
+}
diff --git a/components/user_scripts/browser/file_task_runner.cc b/components/user_scripts/browser/file_task_runner.cc
new file mode 100755
@ -3399,7 +3394,7 @@ diff --git a/components/user_scripts/browser/user_script_loader.h b/components/u
new file mode 100755
--- /dev/null
+++ b/components/user_scripts/browser/user_script_loader.h
@@ -0,0 +1,171 @@
@@ -0,0 +1,170 @@
+/*
+ This file is part of Bromite.
+
@ -3430,7 +3425,6 @@ new file mode 100755
+#include "base/memory/read_only_shared_memory_region.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "base/scoped_observer.h"
+#include "content/public/browser/render_process_host_creation_observer.h"
+#include "ui/shell_dialogs/select_file_dialog.h"
+#include "content/browser/file_system_access/file_system_chooser.h"
@ -5763,7 +5757,7 @@ diff --git a/components/user_scripts/common/url_pattern_set.cc b/components/user
new file mode 100755
--- /dev/null
+++ b/components/user_scripts/common/url_pattern_set.cc
@@ -0,0 +1,333 @@
@@ -0,0 +1,334 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
@ -5773,6 +5767,7 @@ new file mode 100755
+#include <iterator>
+#include <ostream>
+
+#include "base/containers/contains.h"
+#include "base/logging.h"
+#include "base/stl_util.h"
+#include "base/values.h"
@ -7612,7 +7607,7 @@ diff --git a/components/user_scripts/renderer/script_context.cc b/components/use
new file mode 100755
--- /dev/null
+++ b/components/user_scripts/renderer/script_context.cc
@@ -0,0 +1,213 @@
@@ -0,0 +1,215 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
@ -7621,7 +7616,9 @@ new file mode 100755
+
+#include "base/command_line.h"
+#include "base/containers/flat_set.h"
+#include "base/containers/contains.h"
+#include "base/logging.h"
+#include "base/no_destructor.h"
+#include "base/stl_util.h"
+#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
@ -7998,7 +7995,7 @@ new file mode 100755
+ void OnCompleted(const std::vector<v8::Local<v8::Value>>& result) {
+ if (injection_) {
+ base::TimeTicks timestamp(base::TimeTicks::Now());
+ base::Optional<base::TimeDelta> elapsed;
+ absl::optional<base::TimeDelta> elapsed;
+ // If the script will never execute (such as if the context is destroyed),
+ // willExecute() will not be called, but OnCompleted() will. Only log a
+ // time for execution if the script, in fact, executed.
@ -8196,7 +8193,7 @@ new file mode 100755
+
+void ScriptInjection::OnJsInjectionCompleted(
+ const std::vector<v8::Local<v8::Value>>& results,
+ base::Optional<base::TimeDelta> elapsed) {
+ absl::optional<base::TimeDelta> elapsed) {
+ DCHECK(!did_inject_js_);
+
+ bool expects_results = injector_->ExpectsResults();
@ -8234,13 +8231,13 @@ new file mode 100755
+ run_location_, injected_stylesheets, num_injected_stylesheets);
+ blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame();
+ // Default CSS origin is "author", but can be overridden to "user" by scripts.
+ base::Optional<CSSOrigin> css_origin = injector_->GetCssOrigin();
+ absl::optional<CSSOrigin> css_origin = injector_->GetCssOrigin();
+ blink::WebDocument::CSSOrigin blink_css_origin =
+ css_origin && *css_origin == CSS_ORIGIN_USER
+ ? blink::WebDocument::kUserOrigin
+ : blink::WebDocument::kAuthorOrigin;
+ blink::WebStyleSheetKey style_sheet_key;
+ if (const base::Optional<std::string>& injection_key =
+ if (const absl::optional<std::string>& injection_key =
+ injector_->GetInjectionKey())
+ style_sheet_key = blink::WebString::FromASCII(*injection_key);
+ for (const blink::WebString& css : css_sources)
@ -8253,7 +8250,7 @@ diff --git a/components/user_scripts/renderer/script_injection.h b/components/us
new file mode 100755
--- /dev/null
+++ b/components/user_scripts/renderer/script_injection.h
@@ -0,0 +1,156 @@
@@ -0,0 +1,155 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
@ -8269,7 +8266,6 @@ new file mode 100755
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "base/optional.h"
+#include "../common/user_script.h"
+#include "injection_host.h"
+#include "script_injector.h"
@ -8344,7 +8340,7 @@ new file mode 100755
+ // Called when JS injection for the given frame has been completed or
+ // cancelled.
+ void OnJsInjectionCompleted(const std::vector<v8::Local<v8::Value>>& results,
+ base::Optional<base::TimeDelta> elapsed);
+ absl::optional<base::TimeDelta> elapsed);
+
+ private:
+ class FrameWatcher;
@ -8741,8 +8737,8 @@ new file mode 100755
+ScriptInjectionManager::ScriptInjectionManager(
+ UserScriptSetManager* user_script_set_manager)
+ : user_script_set_manager_(user_script_set_manager),
+ user_script_set_manager_observer_(this) {
+ user_script_set_manager_observer_.Add(user_script_set_manager_);
+ user_script_set_manager_observation_(this) {
+ user_script_set_manager_observation_.Observe(user_script_set_manager_);
+}
+
+ScriptInjectionManager::~ScriptInjectionManager() {
@ -8920,7 +8916,7 @@ new file mode 100755
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/scoped_observer.h"
+#include "base/scoped_observation.h"
+#include "../common/user_script.h"
+#include "script_injection.h"
+#include "user_script_set_manager.h"
@ -9006,8 +9002,8 @@ new file mode 100755
+ // Whether or not dom activity should be logged for scripts injected.
+ bool activity_logging_enabled_ = false;
+
+ ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer>
+ user_script_set_manager_observer_;
+ base::ScopedObservation<UserScriptSetManager, UserScriptSetManager::Observer>
+ user_script_set_manager_observation_{this};
+
+ DISALLOW_COPY_AND_ASSIGN(ScriptInjectionManager);
+};
@ -9062,10 +9058,10 @@ new file mode 100755
+ virtual bool IsUserGesture() const = 0;
+
+ // Returns the CSS origin of this injection.
+ virtual base::Optional<CSSOrigin> GetCssOrigin() const = 0;
+ virtual absl::optional<CSSOrigin> GetCssOrigin() const = 0;
+
+ // Returns the key for this injection, if it's a CSS injection.
+ virtual const base::Optional<std::string> GetInjectionKey() const = 0;
+ virtual const absl::optional<std::string> GetInjectionKey() const = 0;
+
+ // Returns true if the script expects results.
+ virtual bool ExpectsResults() const = 0;
@ -9328,7 +9324,7 @@ new file mode 100755
+ user_script_set_(script_list),
+ script_id_(script_->id()),
+ user_script_set_observer_(this) {
+ user_script_set_observer_.Add(script_list);
+ user_script_set_observer_.Observe(script_list);
+}
+
+UserScriptInjector::~UserScriptInjector() {
@ -9367,12 +9363,12 @@ new file mode 100755
+ return false;
+}
+
+base::Optional<CSSOrigin> UserScriptInjector::GetCssOrigin() const {
+ return base::nullopt;
+absl::optional<CSSOrigin> UserScriptInjector::GetCssOrigin() const {
+ return absl::nullopt;
+}
+
+const base::Optional<std::string> UserScriptInjector::GetInjectionKey() const {
+ return base::nullopt;
+const absl::optional<std::string> UserScriptInjector::GetInjectionKey() const {
+ return absl::nullopt;
+}
+
+bool UserScriptInjector::ShouldInjectJs(
@ -9474,7 +9470,7 @@ new file mode 100755
+#include <string>
+
+#include "base/macros.h"
+#include "base/scoped_observer.h"
+#include "base/scoped_observation.h"
+#include "../common/user_script.h"
+#include "script_injection.h"
+#include "user_script_set.h"
@ -9503,8 +9499,8 @@ new file mode 100755
+ // ScriptInjector implementation.
+ UserScript::InjectionType script_type() const override;
+ bool IsUserGesture() const override;
+ base::Optional<CSSOrigin> GetCssOrigin() const override;
+ const base::Optional<std::string> GetInjectionKey() const override;
+ absl::optional<CSSOrigin> GetCssOrigin() const override;
+ const absl::optional<std::string> GetInjectionKey() const override;
+ bool ExpectsResults() const override;
+ bool ShouldInjectJs(
+ UserScript::RunLocation run_location,
@ -9540,8 +9536,8 @@ new file mode 100755
+ // deleted.
+ int script_id_;
+
+ ScopedObserver<UserScriptSet, UserScriptSet::Observer>
+ user_script_set_observer_;
+ base::ScopedObservation<UserScriptSet, UserScriptSet::Observer>
+ user_script_set_observer_{this};
+
+ DISALLOW_COPY_AND_ASSIGN(UserScriptInjector);
+};
@ -10095,7 +10091,7 @@ new file mode 100755
+ user_script_set_manager_.reset(new UserScriptSetManager());
+ script_injection_manager_.reset(
+ new ScriptInjectionManager(user_script_set_manager_.get()));
+ user_script_set_manager_observer_.Add(user_script_set_manager_.get());
+ user_script_set_manager_observer_.Observe(user_script_set_manager_.get());
+}
+
+UserScriptsDispatcher::~UserScriptsDispatcher() {
@ -10134,7 +10130,7 @@ new file mode 100755
+#include <vector>
+
+#include "base/macros.h"
+#include "base/scoped_observer.h"
+#include "base/scoped_observation.h"
+#include "content/public/renderer/render_thread_observer.h"
+#include "content/public/renderer/render_thread.h"
+#include "../common/host_id.h"
@ -10159,8 +10155,8 @@ new file mode 100755
+
+ std::unique_ptr<ScriptInjectionManager> script_injection_manager_;
+
+ ScopedObserver<UserScriptSetManager, UserScriptSetManager::Observer>
+ user_script_set_manager_observer_;
+ base::ScopedObservation<UserScriptSetManager, UserScriptSetManager::Observer>
+ user_script_set_manager_observer_{this};
+};
+
+}
@ -10462,7 +10458,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
@@ -500,6 +500,12 @@
@@ -536,6 +536,12 @@
"components/autofill/core/browser/autofill_address_rewriter_resources.grd":{
"includes": [2880]
},