Skip to content

Commit

Permalink
chore: cherry-pick 11505c3867 from chromium (#32912)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppontes committed Feb 21, 2022
1 parent f9cf232 commit fa37e15
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions patches/chromium/.patches
Expand Up @@ -149,6 +149,7 @@ do_not_select_vulkan_device_based_on_the_passed_in_gpu_info_on_linux.patch
handle_potentiallydanglingmarkup_for_cssimagevalue.patch
fire_iframe_onload_for_cross-origin-initiated_same-document.patch
merge_m-97_serial_check_for_detached_buffers_when_writing.patch
cleanup_pausablecriptexecutor_usage.patch
m98_fs_fix_fileutil_lifetime_issue.patch
cherry-pick-be50c60b4225.patch
cherry-pick-ebc188ad769e.patch
Expand Down
138 changes: 138 additions & 0 deletions patches/chromium/cleanup_pausablecriptexecutor_usage.patch
@@ -0,0 +1,138 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dave Tapuska <dtapuska@chromium.org>
Date: Tue, 8 Feb 2022 15:58:40 +0000
Subject: Cleanup PausablecriptExecutor usage.

Improve performance of API so we don't have to go from
WTF::String->WebString->WTF::String for execution.

Ensure the Executor is traced via the PausableScriptExecutor.

BUG=1289384

(cherry picked from commit c8231f9a89460fd8336e6c0d8e10347f52f540ec)

Change-Id: If9badab91222c49c08a983c60132ce71b183e951
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3407654
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#963010}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3443262
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/4758@{#1109}
Cr-Branched-From: 4a2cf4baf90326df19c3ee70ff987960d59a386e-refs/heads/main@{#950365}

diff --git a/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc b/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc
index 71653584749ef80143f3312a85a9537edd35f014..60377e12f05d298aa512a2eda5358c8bea49d114 100644
--- a/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc
+++ b/third_party/blink/renderer/core/frame/local_frame_mojo_handler.cc
@@ -211,15 +211,16 @@ v8::MaybeLocal<v8::Value> CallMethodOnFrame(LocalFrame* local_frame,

// A wrapper class used as the callback for JavaScript executed
// in an isolated world.
-class JavaScriptIsolatedWorldRequest
- : public GarbageCollected<JavaScriptIsolatedWorldRequest>,
- public WebScriptExecutionCallback {
+class JavaScriptIsolatedWorldRequest : public PausableScriptExecutor::Executor,
+ public WebScriptExecutionCallback {
using JavaScriptExecuteRequestInIsolatedWorldCallback =
mojom::blink::LocalFrame::JavaScriptExecuteRequestInIsolatedWorldCallback;

public:
JavaScriptIsolatedWorldRequest(
LocalFrame* local_frame,
+ int32_t world_id,
+ const String& script,
bool wants_result,
mojom::blink::LocalFrame::JavaScriptExecuteRequestInIsolatedWorldCallback
callback);
@@ -229,27 +230,53 @@ class JavaScriptIsolatedWorldRequest
const JavaScriptIsolatedWorldRequest&) = delete;
~JavaScriptIsolatedWorldRequest() override;

- // WebScriptExecutionCallback:
- void Completed(const WebVector<v8::Local<v8::Value>>& result) override;
+ // PausableScriptExecutor::Executor overrides.
+ Vector<v8::Local<v8::Value>> Execute(LocalDOMWindow*) override;
+
+ void Trace(Visitor* visitor) const override;

- void Trace(Visitor* visitor) const { visitor->Trace(local_frame_); }
+ // WebScriptExecutionCallback overrides.
+ void Completed(const WebVector<v8::Local<v8::Value>>& result) override;

private:
Member<LocalFrame> local_frame_;
+ int32_t world_id_;
+ String script_;
bool wants_result_;
JavaScriptExecuteRequestInIsolatedWorldCallback callback_;
};

JavaScriptIsolatedWorldRequest::JavaScriptIsolatedWorldRequest(
LocalFrame* local_frame,
+ int32_t world_id,
+ const String& script,
bool wants_result,
JavaScriptExecuteRequestInIsolatedWorldCallback callback)
: local_frame_(local_frame),
+ world_id_(world_id),
+ script_(script),
wants_result_(wants_result),
- callback_(std::move(callback)) {}
+ callback_(std::move(callback)) {
+ DCHECK_GT(world_id, DOMWrapperWorld::kMainWorldId);
+}

JavaScriptIsolatedWorldRequest::~JavaScriptIsolatedWorldRequest() = default;

+void JavaScriptIsolatedWorldRequest::Trace(Visitor* visitor) const {
+ PausableScriptExecutor::Executor::Trace(visitor);
+ visitor->Trace(local_frame_);
+}
+
+Vector<v8::Local<v8::Value>> JavaScriptIsolatedWorldRequest::Execute(
+ LocalDOMWindow* window) {
+ // Note: An error event in an isolated world will never be dispatched to
+ // a foreign world.
+ ClassicScript* classic_script = ClassicScript::CreateUnspecifiedScript(
+ script_, SanitizeScriptErrors::kDoNotSanitize);
+ return {classic_script->RunScriptInIsolatedWorldAndReturnValue(window,
+ world_id_)};
+}
+
void JavaScriptIsolatedWorldRequest::Completed(
const WebVector<v8::Local<v8::Value>>& result) {
base::Value value;
@@ -269,7 +296,6 @@ void JavaScriptIsolatedWorldRequest::Completed(
if (new_value)
value = base::Value::FromUniquePtrValue(std::move(new_value));
}
-
std::move(callback_).Run(std::move(value));
}

@@ -927,13 +953,16 @@ void LocalFrameMojoHandler::JavaScriptExecuteRequestInIsolatedWorld(
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
scoped_refptr<DOMWrapperWorld> isolated_world =
DOMWrapperWorld::EnsureIsolatedWorld(ToIsolate(frame_), world_id);
- ScriptSourceCode source_code = ScriptSourceCode(javascript);
- HeapVector<ScriptSourceCode> sources;
- sources.Append(&source_code, 1);
- auto* executor = MakeGarbageCollected<PausableScriptExecutor>(
- DomWindow(), std::move(isolated_world), sources, false /* user_gesture */,
+
+ // This member will be traced as the |executor| on the PausableScriptExector.
+ auto* execution_request =
MakeGarbageCollected<JavaScriptIsolatedWorldRequest>(
- frame_, wants_result, std::move(callback)));
+ frame_, world_id, javascript, wants_result, std::move(callback));
+
+ auto* executor = MakeGarbageCollected<PausableScriptExecutor>(
+ DomWindow(), ToScriptState(frame_, *isolated_world),
+ /*callback=*/execution_request,
+ /*executor=*/execution_request);
executor->Run();
}

0 comments on commit fa37e15

Please sign in to comment.