adapted for v106
This commit is contained in:
@@ -106,7 +106,7 @@ License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
|
||||
.../common/user_scripts_features.h | 34 +
|
||||
components/user_scripts/common/view_type.cc | 39 +
|
||||
components/user_scripts/common/view_type.h | 48 ++
|
||||
components/user_scripts/renderer/BUILD.gn | 67 ++
|
||||
components/user_scripts/renderer/BUILD.gn | 65 ++
|
||||
.../renderer/extension_frame_helper.cc | 95 +++
|
||||
.../renderer/extension_frame_helper.h | 91 ++
|
||||
.../user_scripts/renderer/injection_host.cc | 12 +
|
||||
@@ -114,11 +114,9 @@ License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
|
||||
.../renderer/resources/greasemonkey_api.js | 82 ++
|
||||
.../user_scripts_renderer_resources.grd | 14 +
|
||||
.../user_scripts/renderer/script_context.cc | 215 +++++
|
||||
.../user_scripts/renderer/script_context.h | 69 ++
|
||||
.../user_scripts/renderer/script_injection.cc | 343 ++++++++
|
||||
.../user_scripts/renderer/script_injection.h | 154 ++++
|
||||
.../renderer/script_injection_callback.cc | 25 +
|
||||
.../renderer/script_injection_callback.h | 38 +
|
||||
.../user_scripts/renderer/script_context.h | 68 ++
|
||||
.../user_scripts/renderer/script_injection.cc | 309 +++++++
|
||||
.../user_scripts/renderer/script_injection.h | 155 ++++
|
||||
.../renderer/script_injection_manager.cc | 417 +++++++++
|
||||
.../renderer/script_injection_manager.h | 101 +++
|
||||
.../user_scripts/renderer/script_injector.h | 96 +++
|
||||
@@ -136,9 +134,9 @@ License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
|
||||
.../renderer/user_scripts_renderer_client.h | 37 +
|
||||
.../renderer/web_ui_injection_host.cc | 40 +
|
||||
.../renderer/web_ui_injection_host.h | 27 +
|
||||
.../strings/userscripts_strings.grdp | 57 ++
|
||||
.../strings/userscripts_strings.grdp | 54 ++
|
||||
tools/gritsettings/resource_ids.spec | 6 +
|
||||
111 files changed, 9595 insertions(+), 2 deletions(-)
|
||||
109 files changed, 9493 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
|
||||
@@ -206,8 +204,6 @@ License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html
|
||||
create mode 100755 components/user_scripts/renderer/script_context.h
|
||||
create mode 100755 components/user_scripts/renderer/script_injection.cc
|
||||
create mode 100755 components/user_scripts/renderer/script_injection.h
|
||||
create mode 100755 components/user_scripts/renderer/script_injection_callback.cc
|
||||
create mode 100755 components/user_scripts/renderer/script_injection_callback.h
|
||||
create mode 100755 components/user_scripts/renderer/script_injection_manager.cc
|
||||
create mode 100755 components/user_scripts/renderer/script_injection_manager.h
|
||||
create mode 100755 components/user_scripts/renderer/script_injector.h
|
||||
@@ -413,7 +409,7 @@ diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browse
|
||||
#else // BUILDFLAG(IS_ANDROID)
|
||||
#include "chrome/browser/autofill_assistant/password_change/apc_client.h"
|
||||
#include "chrome/browser/cart/cart_service.h"
|
||||
@@ -1324,6 +1325,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
|
||||
@@ -1323,6 +1324,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
|
||||
translate::TranslatePrefs::RegisterProfilePrefs(registry);
|
||||
omnibox::RegisterProfilePrefs(registry);
|
||||
ZeroSuggestProvider::RegisterProfilePrefs(registry);
|
||||
@@ -7349,7 +7345,7 @@ diff --git a/components/user_scripts/renderer/BUILD.gn b/components/user_scripts
|
||||
new file mode 100755
|
||||
--- /dev/null
|
||||
+++ b/components/user_scripts/renderer/BUILD.gn
|
||||
@@ -0,0 +1,67 @@
|
||||
@@ -0,0 +1,65 @@
|
||||
+# Copyright 2015 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.
|
||||
@@ -7383,8 +7379,6 @@ new file mode 100755
|
||||
+ "injection_host.h",
|
||||
+ "script_injection_manager.cc",
|
||||
+ "script_injection_manager.h",
|
||||
+ "script_injection_callback.cc",
|
||||
+ "script_injection_callback.h",
|
||||
+ "script_injection.cc",
|
||||
+ "script_injection.h",
|
||||
+ "script_injector.h",
|
||||
@@ -8006,7 +8000,7 @@ diff --git a/components/user_scripts/renderer/script_context.h b/components/user
|
||||
new file mode 100755
|
||||
--- /dev/null
|
||||
+++ b/components/user_scripts/renderer/script_context.h
|
||||
@@ -0,0 +1,69 @@
|
||||
@@ -0,0 +1,68 @@
|
||||
+// 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.
|
||||
@@ -8024,7 +8018,6 @@ new file mode 100755
|
||||
+#include "base/threading/thread_checker.h"
|
||||
+#include "base/unguessable_token.h"
|
||||
+#include "../common/script_constants.h"
|
||||
+#include "script_injection_callback.h"
|
||||
+#include "url/gurl.h"
|
||||
+#include "v8/include/v8.h"
|
||||
+
|
||||
@@ -8080,7 +8073,7 @@ diff --git a/components/user_scripts/renderer/script_injection.cc b/components/u
|
||||
new file mode 100755
|
||||
--- /dev/null
|
||||
+++ b/components/user_scripts/renderer/script_injection.cc
|
||||
@@ -0,0 +1,343 @@
|
||||
@@ -0,0 +1,309 @@
|
||||
+// 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.
|
||||
@@ -8101,7 +8094,6 @@ new file mode 100755
|
||||
+#include "content/public/renderer/render_frame_observer.h"
|
||||
+#include "content/public/renderer/v8_value_converter.h"
|
||||
+#include "../common/host_id.h"
|
||||
+#include "script_injection_callback.h"
|
||||
+#include "scripts_run_info.h"
|
||||
+#include "third_party/blink/public/platform/web_isolated_world_info.h"
|
||||
+#include "third_party/blink/public/platform/web_security_origin.h"
|
||||
@@ -8159,38 +8151,6 @@ new file mode 100755
|
||||
+ return id;
|
||||
+}
|
||||
+
|
||||
+// This class manages its own lifetime.
|
||||
+class TimedScriptInjectionCallback : public ScriptInjectionCallback {
|
||||
+ public:
|
||||
+ TimedScriptInjectionCallback(base::WeakPtr<ScriptInjection> injection)
|
||||
+ : ScriptInjectionCallback(
|
||||
+ base::BindOnce(&TimedScriptInjectionCallback::OnCompleted,
|
||||
+ base::Unretained(this))),
|
||||
+ injection_(injection) {}
|
||||
+ ~TimedScriptInjectionCallback() override {}
|
||||
+
|
||||
+ void OnCompleted(const std::vector<v8::Local<v8::Value>>& result) {
|
||||
+ if (injection_) {
|
||||
+ base::TimeTicks timestamp(base::TimeTicks::Now());
|
||||
+ 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.
|
||||
+ if (!start_time_.is_null())
|
||||
+ elapsed = timestamp - start_time_;
|
||||
+ injection_->OnJsInjectionCompleted(result, elapsed);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ void WillExecute() override {
|
||||
+ start_time_ = base::TimeTicks::Now();
|
||||
+ }
|
||||
+
|
||||
+ private:
|
||||
+ base::WeakPtr<ScriptInjection> injection_;
|
||||
+ base::TimeTicks start_time_;
|
||||
+};
|
||||
+
|
||||
+} // namespace
|
||||
+
|
||||
+// Watches for the deletion of a RenderFrame, after which is_valid will return
|
||||
@@ -8339,10 +8299,6 @@ new file mode 100755
|
||||
+ run_location_, executing_scripts, num_injected_js_scripts);
|
||||
+ DCHECK(!sources.empty());
|
||||
+ int world_id = GetIsolatedWorldIdForInstance(injection_host_.get());
|
||||
+ bool is_user_gesture = injector_->IsUserGesture();
|
||||
+
|
||||
+ std::unique_ptr<blink::WebScriptExecutionCallback> callback(
|
||||
+ new TimedScriptInjectionCallback(weak_ptr_factory_.GetWeakPtr()));
|
||||
+
|
||||
+ base::ElapsedTimer exec_timer;
|
||||
+
|
||||
@@ -8357,21 +8313,24 @@ new file mode 100755
|
||||
+ injector_->script_type() == UserScript::CONTENT_SCRIPT &&
|
||||
+ (run_location_ == UserScript::DOCUMENT_END ||
|
||||
+ run_location_ == UserScript::DOCUMENT_IDLE);
|
||||
+ blink::WebLocalFrame::ScriptExecutionType execution_option =
|
||||
+ blink::mojom::EvaluationTiming execution_option =
|
||||
+ should_execute_asynchronously
|
||||
+ ? blink::WebLocalFrame::kAsynchronousBlockingOnload
|
||||
+ : blink::WebLocalFrame::kSynchronous;
|
||||
+ ? blink::mojom::EvaluationTiming::kAsynchronous
|
||||
+ : blink::mojom::EvaluationTiming::kSynchronous;
|
||||
+
|
||||
+ render_frame_->GetWebFrame()->RequestExecuteScript(
|
||||
+ world_id, sources, is_user_gesture,
|
||||
+ execution_option, callback.release(),
|
||||
+ world_id, sources, blink::mojom::UserActivationOption::kDoNotActivate,
|
||||
+ execution_option,
|
||||
+ blink::mojom::LoadEventBlockingOption::kBlock,
|
||||
+ base::BindOnce(&ScriptInjection::OnJsInjectionCompleted,
|
||||
+ weak_ptr_factory_.GetWeakPtr()),
|
||||
+ blink::BackForwardCacheAware::kPossiblyDisallow,
|
||||
+ blink::WebLocalFrame::PromiseBehavior::kDontWait);
|
||||
+}
|
||||
+ blink::mojom::PromiseResultOption::kDoNotWait);
|
||||
+ }
|
||||
+
|
||||
+void ScriptInjection::OnJsInjectionCompleted(
|
||||
+ const std::vector<v8::Local<v8::Value>>& results,
|
||||
+ absl::optional<base::TimeDelta> elapsed) {
|
||||
+ const blink::WebVector<v8::Local<v8::Value>>& results,
|
||||
+ base::TimeTicks start_time) {
|
||||
+ DCHECK(!did_inject_js_);
|
||||
+
|
||||
+ bool expects_results = injector_->ExpectsResults();
|
||||
@@ -8428,7 +8387,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,154 @@
|
||||
@@ -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.
|
||||
@@ -8446,6 +8405,7 @@ new file mode 100755
|
||||
+#include "../common/user_script.h"
|
||||
+#include "injection_host.h"
|
||||
+#include "script_injector.h"
|
||||
+#include "third_party/blink/public/web/web_script_execution_callback.h"
|
||||
+
|
||||
+struct HostID;
|
||||
+
|
||||
@@ -8518,8 +8478,8 @@ 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,
|
||||
+ absl::optional<base::TimeDelta> elapsed);
|
||||
+ void OnJsInjectionCompleted(const blink::WebVector<v8::Local<v8::Value>>& results,
|
||||
+ base::TimeTicks start_time);
|
||||
+
|
||||
+ private:
|
||||
+ class FrameWatcher;
|
||||
@@ -8583,79 +8543,6 @@ new file mode 100755
|
||||
+} // namespace extensions
|
||||
+
|
||||
+#endif // USERSCRIPTS_RENDERER_SCRIPT_INJECTION_H_
|
||||
diff --git a/components/user_scripts/renderer/script_injection_callback.cc b/components/user_scripts/renderer/script_injection_callback.cc
|
||||
new file mode 100755
|
||||
--- /dev/null
|
||||
+++ b/components/user_scripts/renderer/script_injection_callback.cc
|
||||
@@ -0,0 +1,25 @@
|
||||
+// Copyright 2015 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.
|
||||
+
|
||||
+#include "script_injection_callback.h"
|
||||
+
|
||||
+#include "third_party/blink/public/platform/web_vector.h"
|
||||
+
|
||||
+namespace user_scripts {
|
||||
+
|
||||
+ScriptInjectionCallback::ScriptInjectionCallback(
|
||||
+ CompleteCallback injection_completed_callback)
|
||||
+ : injection_completed_callback_(std::move(injection_completed_callback)) {}
|
||||
+
|
||||
+ScriptInjectionCallback::~ScriptInjectionCallback() {
|
||||
+}
|
||||
+
|
||||
+void ScriptInjectionCallback::Completed(
|
||||
+ const blink::WebVector<v8::Local<v8::Value>>& result) {
|
||||
+ std::vector<v8::Local<v8::Value>> stl_result(result.begin(), result.end());
|
||||
+ std::move(injection_completed_callback_).Run(stl_result);
|
||||
+ delete this;
|
||||
+}
|
||||
+
|
||||
+} // namespace extensions
|
||||
diff --git a/components/user_scripts/renderer/script_injection_callback.h b/components/user_scripts/renderer/script_injection_callback.h
|
||||
new file mode 100755
|
||||
--- /dev/null
|
||||
+++ b/components/user_scripts/renderer/script_injection_callback.h
|
||||
@@ -0,0 +1,38 @@
|
||||
+// Copyright 2015 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.
|
||||
+
|
||||
+#ifndef USERSCRIPTS_RENDERER_SCRIPT_INJECTION_CALLBACK_H_
|
||||
+#define USERSCRIPTS_RENDERER_SCRIPT_INJECTION_CALLBACK_H_
|
||||
+
|
||||
+#include <vector>
|
||||
+
|
||||
+#include "base/callback.h"
|
||||
+#include "third_party/blink/public/web/web_script_execution_callback.h"
|
||||
+#include "v8/include/v8.h"
|
||||
+
|
||||
+namespace user_scripts {
|
||||
+
|
||||
+// A wrapper around a callback to notify a script injection when injection
|
||||
+// completes.
|
||||
+// This class manages its own lifetime.
|
||||
+class ScriptInjectionCallback : public blink::WebScriptExecutionCallback {
|
||||
+ public:
|
||||
+ ScriptInjectionCallback(const ScriptInjectionCallback&) = delete;
|
||||
+ ScriptInjectionCallback& operator=(const ScriptInjectionCallback&) = delete;
|
||||
+ using CompleteCallback =
|
||||
+ base::OnceCallback<void(const std::vector<v8::Local<v8::Value>>& result)>;
|
||||
+
|
||||
+ explicit ScriptInjectionCallback(
|
||||
+ CompleteCallback injection_completed_callback);
|
||||
+ ~ScriptInjectionCallback() override;
|
||||
+
|
||||
+ void Completed(const blink::WebVector<v8::Local<v8::Value>>& result) override;
|
||||
+
|
||||
+ private:
|
||||
+ CompleteCallback injection_completed_callback_;
|
||||
+};
|
||||
+
|
||||
+} // namespace extensions
|
||||
+
|
||||
+#endif // USERSCRIPTS_RENDERER_SCRIPT_INJECTION_CALLBACK_H_
|
||||
diff --git a/components/user_scripts/renderer/script_injection_manager.cc b/components/user_scripts/renderer/script_injection_manager.cc
|
||||
new file mode 100755
|
||||
--- /dev/null
|
||||
@@ -10570,7 +10457,7 @@ diff --git a/components/user_scripts/strings/userscripts_strings.grdp b/componen
|
||||
new file mode 100755
|
||||
--- /dev/null
|
||||
+++ b/components/user_scripts/strings/userscripts_strings.grdp
|
||||
@@ -0,0 +1,57 @@
|
||||
@@ -0,0 +1,54 @@
|
||||
+<?xml version="1.0" encoding="utf-8"?>
|
||||
+<grit-part>
|
||||
+
|
||||
@@ -10620,9 +10507,6 @@ new file mode 100755
|
||||
+
|
||||
+NOTE: only install user scripts that you have verified are secure, user scripts can steal your credentials and data.
|
||||
+ </message>
|
||||
+ <message name="IDS_YES" desc=". [CHAR-LIMIT=32]" formatter_data="android_java">
|
||||
+ Yes
|
||||
+ </message>
|
||||
+ <message name="IDS_NO" desc=". [CHAR-LIMIT=32]" formatter_data="android_java">
|
||||
+ No
|
||||
+ </message>
|
||||
|
||||
Reference in New Issue
Block a user