Skip to content

Commit 8ca1f71

Browse files
committed
add some defensive coding
1 parent bfc44b0 commit 8ca1f71

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

emain/emain-ipc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function initIpcHandlers() {
209209

210210
electron.ipcMain.on("webview-image-contextmenu", (event: electron.IpcMainEvent, payload: { src: string }) => {
211211
const menu = new electron.Menu();
212-
const win = getWaveWindowByWebContentsId(event.sender.hostWebContents.id);
212+
const win = getWaveWindowByWebContentsId(event.sender.hostWebContents?.id);
213213
if (win == null) {
214214
return;
215215
}
@@ -353,6 +353,7 @@ export function initIpcHandlers() {
353353
const png = PNG.sync.read(overlayBuffer);
354354
const color = fac.prepareResult(fac.getColorFromArray4(png.data));
355355
const ww = getWaveWindowByWebContentsId(event.sender.id);
356+
if (ww == null) return;
356357
ww.setTitleBarOverlay({
357358
color: unamePlatform === "linux" ? color.rgba : "#00000000",
358359
symbolColor: color.isDark ? "white" : "black",

emain/emain-tabview.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ function computeBgColor(fullConfig: FullConfigType): string {
109109
const wcIdToWaveTabMap = new Map<number, WaveTabView>();
110110

111111
export function getWaveTabViewByWebContentsId(webContentsId: number): WaveTabView {
112+
if (webContentsId == null) {
113+
return null;
114+
}
112115
return wcIdToWaveTabMap.get(webContentsId);
113116
}
114117

@@ -313,6 +316,9 @@ export async function getOrCreateWebViewForTab(waveWindowId: string, tabId: stri
313316
tabView.webContents.on("will-frame-navigate", shFrameNavHandler);
314317
tabView.webContents.on("did-attach-webview", (event, wc) => {
315318
wc.setWindowOpenHandler((details) => {
319+
if (wc == null || wc.isDestroyed() || tabView.webContents == null || tabView.webContents.isDestroyed()) {
320+
return { action: "deny" };
321+
}
316322
tabView.webContents.send("webview-new-window", wc.id, details);
317323
return { action: "deny" };
318324
});

emain/emain-window.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ export function getWaveWindowByTabId(tabId: string): WaveBrowserWindow {
674674
}
675675

676676
export function getWaveWindowByWebContentsId(webContentsId: number): WaveBrowserWindow {
677+
if (webContentsId == null) {
678+
return null;
679+
}
677680
const tabView = getWaveTabViewByWebContentsId(webContentsId);
678681
if (tabView == null) {
679682
return null;

0 commit comments

Comments
 (0)