mirror of
https://github.com/electron/electron.git
synced 2026-10-28 11:44:46 +08:00
* refactor: use PreloadRealmGlobalScope for service worker preloads
Service worker preload scripts ran in Blink's ShadowRealmGlobalScope.
The ShadowRealm proposal has stalled, so Chromium may remove that class.
A new Chromium patch adds PreloadRealmGlobalScope, a global scope that
exposes the same interfaces without depending on any ShadowRealm code,
and Electron now creates the preload context with it.
Uncaught errors and unhandled rejections in a service worker preload
script are now reported through the worker's console. Before, they hit
NOTREACHED() in ShadowRealmGlobalScope.
Calling getEventListeners() from the DevTools console in the preload
context no longer crashes the renderer.
* refactor: generate PreloadRealmGlobalScope IDL bindings in //electron
* ci: normalize include paths in Windows gen headers for clang-tidy
The Windows clang-tidy job runs in a Linux container using generated
headers downloaded from out_gen_artifacts_win_x64. On Windows, Python
code generators such as inspector_protocol/code_generator.py use
os.path.join() and emit backslashes in #include directives, causing
Linux Siso scandeps and clang-tidy on RBE workers to fail with:
gen/third_party/blink/renderer/core/inspector/protocol/forward.h:15:10: error: 'third_party/inspector_protocol\crdtp/error_support.h' file not found [clang-diagnostic-error]
15 | #include "third_party/inspector_protocol\crdtp/error_support.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* fixup! normalize include paths in Windows gen headers for clang-tidy
* fix: resolve root worker context for ShadowRealms nested in preload realms
When a ShadowRealm is created inside a service worker preload realm
(e.g. with --harmony-shadow-realm), its initiator ExecutionContext is
PreloadRealmGlobalScope rather than a WorkerOrWorkletGlobalScope or
ShadowRealmGlobalScope. Previously, GetRootInitiatorExecutionContext()
only walked initiators via To<ShadowRealmGlobalScope>(), which either
stopped at PreloadRealmGlobalScope (failing the subsequent
To<WorkerOrWorkletGlobalScope>() cast on unhandled rejections or console
messages) or performed an invalid downcast to ShadowRealmGlobalScope.
Delegate GetRootInitiatorExecutionContext() to
initiator_execution_context_->GetRootExecutionContext() so nested
ShadowRealms walk through PreloadRealmGlobalScope to the underlying
ServiceWorkerGlobalScope.
* fix: use Supplement<ExecutionContext> for PreloadRealmLifetimeController
Replace V8 embedder data slot storage in PreloadRealmLifetimeController with
blink::Supplement<ExecutionContext> so it cannot collide with NodeBindings
storing node::IsolateData* in kElectronContextEmbedderDataIndex
or require a persistent self root.
* build: track blink pydeps
* chore: update patches
---------
Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com>
82 lines
3.3 KiB
C++
82 lines
3.3 KiB
C++
// Copyright (c) 2026 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef ELECTRON_SHELL_RENDERER_PRELOAD_REALM_GLOBAL_SCOPE_H_
|
|
#define ELECTRON_SHELL_RENDERER_PRELOAD_REALM_GLOBAL_SCOPE_H_
|
|
|
|
#include "base/task/single_thread_task_runner.h"
|
|
#include "third_party/blink/renderer/core/execution_context/execution_context.h" // nogncheck
|
|
#include "third_party/blink/renderer/core/frame/universal_global_scope.h" // nogncheck
|
|
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" // nogncheck
|
|
#include "third_party/blink/renderer/platform/weborigin/kurl.h" // nogncheck
|
|
|
|
namespace blink {
|
|
|
|
// Global scope of the context Electron runs preload scripts in when the
|
|
// context they are attached to (the "initiator") has no isolated worlds of its
|
|
// own, as is the case for service workers. It exposes only the interfaces
|
|
// marked [Exposed=PreloadRealm] or [Exposed=*] and otherwise defers to the
|
|
// initiator, which owns it.
|
|
class PreloadRealmGlobalScope final : public ScriptWrappable,
|
|
public UniversalGlobalScope,
|
|
public ExecutionContext {
|
|
DEFINE_WRAPPERTYPEINFO();
|
|
|
|
public:
|
|
explicit PreloadRealmGlobalScope(
|
|
ExecutionContext* initiator_execution_context);
|
|
|
|
ExecutionContext* GetInitiatorExecutionContext() const {
|
|
return initiator_execution_context_.Get();
|
|
}
|
|
|
|
void Trace(Visitor* visitor) const override;
|
|
|
|
// UniversalGlobalScope:
|
|
ExecutionContext* GetExecutionContext() const override;
|
|
|
|
// MojoBindingContext:
|
|
const BrowserInterfaceBrokerProxy& GetBrowserInterfaceBroker() const override;
|
|
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(
|
|
TaskType task_type) override;
|
|
|
|
// UseCounter:
|
|
void CountUse(mojom::blink::WebFeature feature) override;
|
|
void CountDeprecation(mojom::blink::WebFeature feature) override;
|
|
void CountWebDXFeature(mojom::blink::WebDXFeature feature) override;
|
|
|
|
// ExecutionContext:
|
|
bool IsShadowRealmGlobalScope() const override;
|
|
ExecutionContext* GetRootExecutionContext() override;
|
|
const KURL& Url() const override;
|
|
const KURL& BaseURL() const override;
|
|
KURL CompleteURL(const String& url) const override;
|
|
void DisableEval(const String& error_message) override;
|
|
void SetWasmEvalErrorMessage(const String& error_message) override;
|
|
String UserAgent() const override;
|
|
HttpsState GetHttpsState() const override;
|
|
ResourceFetcher* Fetcher() override;
|
|
void ExceptionThrown(ErrorEvent* error_event,
|
|
SanitizeScriptErrors sanitize_script_errors) override;
|
|
void AddInspectorIssue(AuditsIssue issue) override;
|
|
EventTarget* ErrorEventTarget() override;
|
|
FrameOrWorkerScheduler* GetScheduler() override;
|
|
bool CrossOriginIsolatedCapability() const override;
|
|
bool IsIsolatedContext() const override;
|
|
ukm::UkmRecorder* UkmRecorder() override;
|
|
ukm::SourceId UkmSourceID() const override;
|
|
ExecutionContextToken GetExecutionContextToken() const override;
|
|
bool IsSecureContext() const override;
|
|
|
|
private:
|
|
void AddConsoleMessageImpl(ConsoleMessage* message,
|
|
bool discard_duplicates) override;
|
|
|
|
const Member<ExecutionContext> initiator_execution_context_;
|
|
};
|
|
|
|
} // namespace blink
|
|
|
|
#endif // ELECTRON_SHELL_RENDERER_PRELOAD_REALM_GLOBAL_SCOPE_H_
|