Skip to content

Commit 1e9d088

Browse files
committed
dispose some jcef components
1 parent 486f337 commit 1e9d088

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/main/java/org/digma/intellij/plugin/jaegerui/JaegerUIFileEditor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
public class JaegerUIFileEditor extends UserDataHolderBase implements FileEditor {
1515

16-
private final VirtualFile file;
16+
private final JaegerUIVirtualFile file;
1717

1818
@Nullable
1919
private JCefComponent jCefComponent;
2020

21+
private boolean disposed = false;
22+
2123
public JaegerUIFileEditor(Project project, JaegerUIVirtualFile file) {
2224
this.file = file;
2325
jCefComponent = createJcefComponent(project, file);
@@ -81,7 +83,7 @@ public boolean isModified() {
8183

8284
@Override
8385
public boolean isValid() {
84-
return true;
86+
return !disposed;
8587
}
8688

8789
@Override
@@ -100,6 +102,8 @@ public void dispose() {
100102
jCefComponent.dispose();
101103
jCefComponent = null;
102104
}
105+
disposed = true;
106+
file.setValid(false);
103107
}
104108

105109
}

src/main/java/org/digma/intellij/plugin/jaegerui/JaegerUIFileEditorProvider.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
2222
return new JaegerUIFileEditor(project, (JaegerUIVirtualFile) file);
2323
}
2424

25-
@Override
26-
public void disposeEditor(@NotNull FileEditor editor) {
27-
FileEditorProvider.super.disposeEditor(editor);
28-
}
29-
30-
3125
@Override
3226
public @NotNull @NonNls String getEditorTypeId() {
3327
return JAEGER_UI_EDITOR_TYPE;

src/main/java/org/digma/intellij/plugin/jaegerui/JaegerUIVirtualFile.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
public class JaegerUIVirtualFile extends LightVirtualFile implements DigmaVirtualFileMarker {
1515

16+
//todo: not sure this key is necessary, it is not used
1617
public static final Key<String> JAEGER_UI_EDITOR_KEY = Key.create("Digma.JAEGER_UI_EDITOR_KEY");
1718
private String jaegerBaseUrl;
1819
private String traceId;

src/main/kotlin/org/digma/intellij/plugin/ui/jcef/JCefComponent.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,24 @@ private constructor(
373373

374374
jbCefClient.cefClient.addDisplayHandler(JCefDisplayHandler(name))
375375

376-
jbCefBrowser.jbCefClient.addLifeSpanHandler(LifeSpanHandle(schemeHandlerFactory), jbCefBrowser.cefBrowser)
376+
val lifeSpanHandle = LifeSpanHandle(schemeHandlerFactory)
377+
jbCefClient.addLifeSpanHandler(lifeSpanHandle, jbCefBrowser.cefBrowser)
377378

378379
downloadAdapterRef?.get()?.let {
379-
jbCefClient.cefClient.addDownloadHandler(it)
380+
jbCefClient.addDownloadHandler(it, jbCefBrowser.cefBrowser)
380381
}
381382

382383
val jCefComponent =
383384
JCefComponent(project, parentDisposable, name, jbCefBrowser, cefMessageRouter)
384385

385-
//usually the component that holds a reference to JCefComponent needs to call JCefComponent.dispose.
386-
//when a parentDisposable is supplied then use it also to dispose, worst case dispose will be called twice.
387386
Disposer.register(parentDisposable) {
388-
jCefComponent.dispose()
387+
cefMessageRouter.removeHandler(messageRouterHandler)
388+
cefMessageRouter.dispose()
389+
jbCefClient.cefClient.removeMessageRouter(cefMessageRouter)
390+
jbCefClient.removeLifeSpanHandler(lifeSpanHandle, jbCefBrowser.cefBrowser)
391+
downloadAdapterRef?.get()?.let {
392+
jbCefClient.removeDownloadHandle(it, jbCefBrowser.cefBrowser)
393+
}
389394
}
390395

391396

@@ -421,4 +426,5 @@ class LifeSpanHandle(private val schemeHandlerFactory: BaseSchemeHandlerFactory)
421426
schemeHandlerFactory.getSchema(), null, schemeHandlerFactory
422427
)
423428
}
429+
424430
}

0 commit comments

Comments
 (0)