mirror of
https://github.com/electron/electron.git
synced 2026-10-28 11:44:46 +08:00
* refactor: create ipcRenderer natively
`ipcRenderer` and the internal `ipcRendererInternal` were JavaScript
classes extending EventEmitter that forwarded to an `electron_renderer_ipc`
binding object, and a start-up module registered them as the targets for
incoming messages. The binding now builds both objects itself when it is
loaded into a context: instances of the shared native EventEmitter class
with `send`/`sendSync`/`invoke`/`postMessage`/`sendToHost` implemented in
C++ on an intermediate prototype (so, as before, they are not own
properties and work unbound), and it registers them for incoming messages.
The TypeScript modules re-export the binding's objects.
gin_helper::GetNodeEventEmitterConstructor() caches one EventEmitter class
per context so that these objects and the class exposed to scripts share a
prototype.
* refactor: create contextBridge natively
The `contextBridge` module was a JavaScript wrapper that checked
`process.contextIsolated` and forwarded to the
`electron_renderer_context_bridge` binding. The binding now exports the
module object directly, doing the context isolation check in C++ (the
frame's web preference, or always allowed in a service worker preload
realm), and in debug builds attaches the `internalContextBridge` helpers
the tests use.
* refactor: make webFrame an EventEmitter natively
The `webFrame` module wrapped the `electron_renderer_web_frame` binding in
JavaScript to make `WebFrame` an EventEmitter, to start emitting
'isolated-world-created' when something first listens for it, and to
implement the deprecated `routingId` / `findFrameByRoutingId()` with a
synchronous internal IPC to the browser.
The binding now chains `WebFrame.prototype` to the context's native
EventEmitter, hooks `on()` and friends for the lazy 'isolated-world-created'
registration, and implements the two deprecated members over a sync call on
ElectronWebContentsUtility, so the browser-side IPC handlers go away. The
renderer `crashReporter` module likewise re-exports its binding.
* refactor: receive transferred shared textures in the renderer natively
`sharedTexture.sendSharedTexture()` reached the target frame through an
internal IPC round trip answered by the renderer-side `sharedTexture`
module, which imported the texture, replied with its sync token and called
the receiver registered with `setSharedTextureReceiver()`.
That now happens over mojom::ElectronFrame::ReceiveSharedTexture(),
implemented by ElectronApiServiceImpl: it imports the texture with the
`electron_common_shared_texture` binding in the frame's Electron context,
replies with the frame creation sync token (or the error), and invokes the
registered receiver with the same `{ importedSharedTexture }` object as
before. The receiver is registered natively by the binding, so the
renderer module is a plain re-export and the last `invokeInWebFrameMain`
helper is removed.
* fix: address review comments on the native renderer API modules
- Import a transferred shared texture by calling
shared_texture::FinishTransferSharedTexture() directly rather than going
through the binding's exports object.
- WebFrame's listener hooks carry the EventEmitter.prototype method they
defer to as callback data instead of looking it up on every call.