mirror of
https://github.com/electron/electron.git
synced 2026-02-26 03:01:17 -05:00
* fix: add patch to avoid crash in worker with nodeintegration enabled [worker_global_scope.cc(111)] Check failed: url_.IsValid(). * fix: loading dedicated/shared worker over custom protocols Backports https://chromium-review.googlesource.com/c/chromium/src/+/1798250 that distinguishes loading the main script resource of dedicated/shared worker, this allows us to register a custom URLLoaderFactory. * spec: add crash test for worker with nodeIntegrationInWorker * update patches * Remove extra patchlist patches * Fixup patch * update patches Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Electron Bot <anonymous@electronjs.org>
80 lines
2.3 KiB
C++
80 lines
2.3 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 "base/lazy_instance.h"
|
|
#include "base/threading/thread_local.h"
|
|
#include "shell/common/api/electron_bindings.h"
|
|
#include "shell/common/asar/asar_util.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::LazyInstance<
|
|
base::ThreadLocalPointer<WebWorkerObserver>>::DestructorAtExit lazy_tls =
|
|
LAZY_INSTANCE_INITIALIZER;
|
|
|
|
} // namespace
|
|
|
|
// static
|
|
WebWorkerObserver* WebWorkerObserver::GetCurrent() {
|
|
WebWorkerObserver* self = lazy_tls.Pointer()->Get();
|
|
return self ? self : new WebWorkerObserver;
|
|
}
|
|
|
|
WebWorkerObserver::WebWorkerObserver()
|
|
: node_bindings_(
|
|
NodeBindings::Create(NodeBindings::BrowserEnvironment::WORKER)),
|
|
electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) {
|
|
lazy_tls.Pointer()->Set(this);
|
|
}
|
|
|
|
WebWorkerObserver::~WebWorkerObserver() {
|
|
lazy_tls.Pointer()->Set(nullptr);
|
|
node::FreeEnvironment(node_bindings_->uv_env());
|
|
node::FreeIsolateData(node_bindings_->isolate_data());
|
|
asar::ClearArchives();
|
|
}
|
|
|
|
void WebWorkerObserver::WorkerScriptReadyForEvaluation(
|
|
v8::Local<v8::Context> worker_context) {
|
|
v8::Context::Scope context_scope(worker_context);
|
|
|
|
// Start the embed thread.
|
|
node_bindings_->PrepareMessageLoop();
|
|
|
|
// Setup node environment for each window.
|
|
bool initialized = node::InitializeContext(worker_context);
|
|
CHECK(initialized);
|
|
node::Environment* env =
|
|
node_bindings_->CreateEnvironment(worker_context, nullptr);
|
|
|
|
// Add Electron extended APIs.
|
|
electron_bindings_->BindTo(env->isolate(), env->process_object());
|
|
|
|
// Load everything.
|
|
node_bindings_->LoadEnvironment(env);
|
|
|
|
// Make uv loop being wrapped by window context.
|
|
node_bindings_->set_uv_env(env);
|
|
|
|
// Give the node loop a run to make sure everything is ready.
|
|
node_bindings_->RunMessageLoop();
|
|
}
|
|
|
|
void WebWorkerObserver::ContextWillDestroy(v8::Local<v8::Context> context) {
|
|
node::Environment* env = node::Environment::GetCurrent(context);
|
|
if (env)
|
|
gin_helper::EmitEvent(env->isolate(), env->process_object(), "exit");
|
|
|
|
delete this;
|
|
}
|
|
|
|
} // namespace electron
|