![electron-roller[bot]](/assets/img/avatar_default.png)
* chore: bump chromium in DEPS to 134.0.6998.1 * chore: bump chromium in DEPS to 134.0.6998.5 * chore: bump chromium in DEPS to 134.0.6998.3 * chore: bump chromium to 134.0.6988.0 (main) (#45334) * chore: bump chromium in DEPS to 134.0.6976.0 * chore: update mas_avoid_private_macos_api_usage.patch.patch https://chromium-review.googlesource.com/c/chromium/src/+/6171046 process_info_mac.cc -> process_info_mac.mm * chore: update build_do_not_depend_on_packed_resource_integrity.patch https://chromium-review.googlesource.com/c/chromium/src/+/6196857 * chore: update feat_add_support_for_missing_dialog_features_to_shell_dialogs.patch https://chromium-review.googlesource.com/c/chromium/src/+/6182296 https://chromium-review.googlesource.com/c/chromium/src/+/6183404 https://chromium-review.googlesource.com/c/chromium/src/+/6187853 A lot changed in the upstream implementation. There's a good chance I got this wrong as threading has changed and moved some variables into globals. * chore: remove build_remove_vr_directx_helpers_dependency.patch https://chromium-review.googlesource.com/c/chromium/src/+/6186102 This landed upstream * chore: e patches all * chore: update net::CookieInclusionStatus::ExclusionReason enum https://chromium-review.googlesource.com/c/chromium/src/+/6183252 https://chromium-review.googlesource.com/c/chromium/src/+/6185544 * chore: update content::WebAuthenticationDelegate import https://chromium-review.googlesource.com/c/chromium/src/+/6189769 * Revert "chore: disable focus handling test due to win32/ia32 regression" This reverts commit 1a57ba5d59848d0c841ddda59c9299a4f957452a. * chore: bump chromium in DEPS to 134.0.6978.0 * chore: bump chromium in DEPS to 134.0.6980.0 * chore: bump chromium in DEPS to 134.0.6982.0 * chore: bump chromium in DEPS to 134.0.6984.0 * 6196281: Allow direct embedder IsPdfInternalPluginAllowedOrigin() interaction https://chromium-review.googlesource.com/c/chromium/src/+/6196281 * 6196283: Delete PdfInternalPluginDelegate https://chromium-review.googlesource.com/c/chromium/src/+/6196283 * chore: update patches * chore: bump chromium in DEPS to 134.0.6986.0 * chore: update patches * 6205762: Support option to use window.showSaveFilePicker() in PDF attachment code https://chromium-review.googlesource.com/c/chromium/src/+/6205762 See also: * https://issues.chromium.org/issues/373852607 * 5939153: [PDF] Add PdfUseShowSaveFilePicker feature flag | https://chromium-review.googlesource.com/c/chromium/src/+/5939153 * 6205761: Delete spurious Ink-specific code in pdf_viewer.ts | https://chromium-review.googlesource.com/c/chromium/src/+/6205761 * 6209609: Remove WebVector: Automatic changes https://chromium-review.googlesource.com/c/chromium/src/+/6209609 * 6205488: UI: make QT5 optional https://chromium-review.googlesource.com/c/chromium/src/+/6205488 * 6178281: Rename pak files from branding strings https://chromium-review.googlesource.com/c/chromium/src/+/6178281 * fixup! 6209609: Remove WebVector: Automatic changes https://chromium-review.googlesource.com/c/chromium/src/+/6209609 * 6193249: Switch from safe_browsing::EventResult to enterprise_connectors:EventResult https://chromium-review.googlesource.com/c/chromium/src/+/6193249 * 6197457: Remove Pause/ResumeReadingBodyFromNet IPCs https://chromium-review.googlesource.com/c/chromium/src/+/6197457 * 6191230: Record total time spent on a picture in picture window https://chromium-review.googlesource.com/c/chromium/src/+/6191230 * chore: bump chromium in DEPS to 134.0.6988.0 * chore: update patches * 6215440: Remove base/ranges/. https://chromium-review.googlesource.com/c/chromium/src/+/6215440 * Disable unsafe buffers error Not sure what changed, but we're now seeing unsafe buffer errors in Chromium code, at least when using reclient. Will update this comment if we find out the cause. * 6187853: SelectFileDialogLinuxPortal: Use dbus_xdg::Request and DbusType https://chromium-review.googlesource.com/c/chromium/src/+/6187853 * fix `setDisplayMediaRequestHandler` test Given how this test is written, I would expect this assertion to be false. It seems the oppositue was true before, but that was also acknowledged to be suprising. Seems that the underlying implementation is now fixed and works as expected. * fixup! 6187853: SelectFileDialogLinuxPortal: Use dbus_xdg::Request and DbusType https://chromium-review.googlesource.com/c/chromium/src/+/6187853 * chore: udpate patches * Multiple PRS: https://chromium-review.googlesource.com/c/chromium/src/+/6185544 | https://chromium-review.googlesource.com/c/chromium/src/+/6183252 * fix: cast enum class to numeric type * fix: add 1 to MAX_EXCLUSION_REASON because enum values are zero-based, and we want the total count of reasons. * Reapply "chore: disable focus handling test due to win32/ia32 regression" This reverts commit 760b1a519b5919b483c66bc3096eeefb4d7011f4. * refactor: use ExclusionReasonBitset::kValueCount for size --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: Samuel Maddock <smaddock@slack-corp.com> Co-authored-by: clavin <clavin@electronjs.org> Co-authored-by: alice <alice@makenotion.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> (cherry picked from commit 213165a467b84b3fb979a869d9bf10ad21e2d78e) --------- Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
130 lines
4.4 KiB
C++
130 lines
4.4 KiB
C++
// Copyright (c) 2017 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/renderer/web_worker_observer.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "base/no_destructor.h"
|
|
#include "base/threading/thread_local.h"
|
|
#include "shell/common/api/electron_bindings.h"
|
|
#include "shell/common/gin_helper/event_emitter_caller.h"
|
|
#include "shell/common/node_bindings.h"
|
|
#include "shell/common/node_includes.h"
|
|
|
|
namespace electron {
|
|
|
|
namespace {
|
|
|
|
static base::NoDestructor<base::ThreadLocalOwnedPointer<WebWorkerObserver>>
|
|
lazy_tls;
|
|
|
|
} // namespace
|
|
|
|
// static
|
|
WebWorkerObserver* WebWorkerObserver::GetCurrent() {
|
|
return lazy_tls->Get();
|
|
}
|
|
|
|
// static
|
|
WebWorkerObserver* WebWorkerObserver::Create() {
|
|
auto obs = std::make_unique<WebWorkerObserver>();
|
|
auto* obs_raw = obs.get();
|
|
lazy_tls->Set(std::move(obs));
|
|
return obs_raw;
|
|
}
|
|
|
|
WebWorkerObserver::WebWorkerObserver()
|
|
: node_bindings_(
|
|
NodeBindings::Create(NodeBindings::BrowserEnvironment::kWorker)),
|
|
electron_bindings_(
|
|
std::make_unique<ElectronBindings>(node_bindings_->uv_loop())) {}
|
|
|
|
WebWorkerObserver::~WebWorkerObserver() = default;
|
|
|
|
void WebWorkerObserver::WorkerScriptReadyForEvaluation(
|
|
v8::Local<v8::Context> worker_context) {
|
|
v8::Context::Scope context_scope(worker_context);
|
|
auto* isolate = worker_context->GetIsolate();
|
|
v8::MicrotasksScope microtasks_scope(
|
|
worker_context, v8::MicrotasksScope::kDoNotRunMicrotasks);
|
|
|
|
// Start the embed thread.
|
|
node_bindings_->PrepareEmbedThread();
|
|
|
|
// Setup node tracing controller.
|
|
if (!node::tracing::TraceEventHelper::GetAgent())
|
|
node::tracing::TraceEventHelper::SetAgent(node::CreateAgent());
|
|
|
|
// Setup node environment for each window.
|
|
v8::Maybe<bool> initialized = node::InitializeContext(worker_context);
|
|
CHECK(!initialized.IsNothing() && initialized.FromJust());
|
|
std::shared_ptr<node::Environment> env =
|
|
node_bindings_->CreateEnvironment(worker_context, nullptr);
|
|
|
|
// We need to use the Blink implementation of fetch in web workers
|
|
// Node.js deletes the global fetch function when their fetch implementation
|
|
// is disabled, so we need to save and re-add it after the Node.js environment
|
|
// is loaded. See corresponding change in node/init.ts.
|
|
v8::Local<v8::Object> global = worker_context->Global();
|
|
|
|
std::vector<std::string> keys = {"fetch", "Response", "FormData",
|
|
"Request", "Headers", "EventSource"};
|
|
for (const auto& key : keys) {
|
|
v8::MaybeLocal<v8::Value> value =
|
|
global->Get(worker_context, gin::StringToV8(isolate, key.c_str()));
|
|
if (!value.IsEmpty()) {
|
|
std::string blink_key = "blink" + key;
|
|
global
|
|
->Set(worker_context, gin::StringToV8(isolate, blink_key.c_str()),
|
|
value.ToLocalChecked())
|
|
.Check();
|
|
}
|
|
}
|
|
|
|
// Add Electron extended APIs.
|
|
electron_bindings_->BindTo(env->isolate(), env->process_object());
|
|
|
|
// Load everything.
|
|
node_bindings_->LoadEnvironment(env.get());
|
|
|
|
// Make uv loop being wrapped by window context.
|
|
node_bindings_->set_uv_env(env.get());
|
|
|
|
// Give the node loop a run to make sure everything is ready.
|
|
node_bindings_->StartPolling();
|
|
|
|
// Keep the environment alive until we free it in ContextWillDestroy()
|
|
environments_.insert(std::move(env));
|
|
}
|
|
|
|
void WebWorkerObserver::ContextWillDestroy(v8::Local<v8::Context> context) {
|
|
node::Environment* env = node::Environment::GetCurrent(context);
|
|
if (env) {
|
|
v8::Context::Scope context_scope(env->context());
|
|
gin_helper::EmitEvent(env->isolate(), env->process_object(), "exit");
|
|
}
|
|
|
|
// Destroying the node environment will also run the uv loop,
|
|
// Node.js expects `kExplicit` microtasks policy and will run microtasks
|
|
// checkpoints after every call into JavaScript. Since we use a different
|
|
// policy in the renderer - switch to `kExplicit`
|
|
v8::MicrotaskQueue* microtask_queue = context->GetMicrotaskQueue();
|
|
auto old_policy = microtask_queue->microtasks_policy();
|
|
DCHECK_EQ(microtask_queue->GetMicrotasksScopeDepth(), 0);
|
|
microtask_queue->set_microtasks_policy(v8::MicrotasksPolicy::kExplicit);
|
|
|
|
base::EraseIf(environments_,
|
|
[env](auto const& item) { return item.get() == env; });
|
|
|
|
microtask_queue->set_microtasks_policy(old_policy);
|
|
|
|
// ElectronBindings is tracking node environments.
|
|
electron_bindings_->EnvironmentDestroyed(env);
|
|
|
|
if (lazy_tls->Get())
|
|
lazy_tls->Set(nullptr);
|
|
}
|
|
|
|
} // namespace electron
|