diff options
author | Artem Bochkarev <artem.bochkarev@jetbrains.com> | 2023-04-13 17:46:53 +0700 |
---|---|---|
committer | Artem Bochkarev <artem.bochkarev@jetbrains.com> | 2023-04-14 20:09:43 +0700 |
commit | 77768fe49033cc6b7dbcf66e1f569f7dab06a166 (patch) | |
tree | 183db0471830130fc9446094600b81a6af35f9cb | |
parent | bf9dc8807feea33b7818768d32a977fc7fbae071 (diff) | |
download | jcef-77768fe49033cc6b7dbcf66e1f569f7dab06a166.tar.gz |
JBR-5530 support delayed native context initialization for CefBrowser
-rw-r--r-- | java/org/cef/browser/CefBrowserOsr.java | 3 | ||||
-rw-r--r-- | java/org/cef/browser/CefBrowserOsrWithHandler.java | 2 | ||||
-rw-r--r-- | java/org/cef/browser/CefBrowserWr.java | 3 | ||||
-rw-r--r-- | java/org/cef/browser/CefBrowser_N.java | 321 |
4 files changed, 245 insertions, 84 deletions
diff --git a/java/org/cef/browser/CefBrowserOsr.java b/java/org/cef/browser/CefBrowserOsr.java index f6eb373..3afbbcd 100644 --- a/java/org/cef/browser/CefBrowserOsr.java +++ b/java/org/cef/browser/CefBrowserOsr.java @@ -436,8 +436,7 @@ class CefBrowserOsr extends CefBrowser_N implements CefRenderHandler { createDevTools(getParentBrowser(), getClient(), windowHandle, true, isTransparent_, null, getInspectAt()); } else { - createBrowser(getClient(), windowHandle, getUrl(), true, isTransparent_, null, - getRequestContext()); + createBrowser(getClient(), windowHandle, getUrl(), true, isTransparent_, null); } } else if (hasParent && justCreated_) { notifyAfterParentChanged(); diff --git a/java/org/cef/browser/CefBrowserOsrWithHandler.java b/java/org/cef/browser/CefBrowserOsrWithHandler.java index e5f949b..f731d77 100644 --- a/java/org/cef/browser/CefBrowserOsrWithHandler.java +++ b/java/org/cef/browser/CefBrowserOsrWithHandler.java @@ -58,7 +58,7 @@ public class CefBrowserOsrWithHandler extends CefBrowser_N { public void createImmediately() { long windowHandle = component_ != null ? CefBrowserWr.getWindowHandle(component_) : 0; if (getParentBrowser() == null) { - createBrowser(getClient(), windowHandle, getUrl(), true, false, null, getRequestContext()); + createBrowser(getClient(), windowHandle, getUrl(), true, false, null); } else { createDevTools(getParentBrowser(), getClient(), windowHandle, true, false, null, getInspectAt()); } diff --git a/java/org/cef/browser/CefBrowserWr.java b/java/org/cef/browser/CefBrowserWr.java index a3c77b7..8de470e 100644 --- a/java/org/cef/browser/CefBrowserWr.java +++ b/java/org/cef/browser/CefBrowserWr.java @@ -507,8 +507,7 @@ class CefBrowserWr extends CefBrowser_N { getInspectAt()); return true; } else { - createBrowser(getClient(), windowHandle, getUrl(), false, false, canvas, - getRequestContext()); + createBrowser(getClient(), windowHandle, getUrl(), false, false, canvas); return true; } } else if (hasParent && justCreated_) { diff --git a/java/org/cef/browser/CefBrowser_N.java b/java/org/cef/browser/CefBrowser_N.java index 70fe942..272c7c2 100644 --- a/java/org/cef/browser/CefBrowser_N.java +++ b/java/org/cef/browser/CefBrowser_N.java @@ -4,6 +4,7 @@ package org.cef.browser; +import org.cef.CefApp; import org.cef.CefClient; import org.cef.callback.CefDragData; import org.cef.callback.CefNativeAdapter; @@ -24,6 +25,8 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.awt.event.WindowEvent; +import java.util.ArrayList; +import java.util.List; import java.util.Vector; import javax.swing.SwingUtilities; @@ -34,12 +37,12 @@ import javax.swing.SwingUtilities; * The visibility of this class is "package". To create a new * CefBrowser instance, please use CefBrowserFactory. */ -abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { +abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser, CefAppStateHandler { private static final boolean TRACE_LIFESPAN = Boolean.getBoolean("jcef.trace.cefbrowser_n.lifespan"); private volatile boolean isPending_ = false; private final CefClient client_; private final String url_; - private final CefRequestContext request_context_; + private CefRequestContext request_context_; private volatile CefBrowser_N parent_ = null; private volatile Point inspectAt_ = null; private volatile CefBrowser_N devTools_ = null; @@ -48,13 +51,18 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { private volatile boolean isClosing_ = false; private volatile boolean isCreating_ = false; + private boolean isNativeCtxInitialized_ = false; + private final List<Runnable> delayedActions_ = new ArrayList<>(); + protected CefBrowser_N(CefClient client, String url, CefRequestContext context, CefBrowser_N parent, Point inspectAt) { client_ = client; url_ = url; - request_context_ = context != null ? context : CefRequestContext.getGlobalContext(); + request_context_ = context; parent_ = parent; inspectAt_ = inspectAt; + + CefApp.getInstance().onInitialization(this); } protected String getUrl() { @@ -70,6 +78,22 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { } @Override + public void stateHasChanged(CefApp.CefAppState state) { + if (isClosing_ || isClosed_) + return; + + if (CefApp.CefAppState.INITIALIZED == state) { + synchronized (delayedActions_) { + isNativeCtxInitialized_ = true; + if (request_context_ == null) + request_context_ = CefRequestContext.getGlobalContext(); + delayedActions_.forEach(r -> r.run()); + delayedActions_.clear(); + } + } + } + + @Override public boolean isClosed() { return isClosed_; } @@ -156,23 +180,42 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { protected abstract CefBrowser createDevToolsBrowser(CefClient client, String url, CefRequestContext context, CefBrowser parent, Point inspectAt); + private void executeNative(Runnable nativeRunnable, String name) { + synchronized (delayedActions_) { + if (isNativeCtxInitialized_) + nativeRunnable.run(); + else { + CefLog.Debug("CefBrowser_N: %s: add delayed action %s", this, name); + delayedActions_.add(nativeRunnable); + } + } + } + + private void ensureNativeCtxInitialized() { + if (!isNativeCtxInitialized_ && CefLog.IsDebugEnabled()) { + String m1 = new Throwable().getStackTrace()[1].getMethodName(); + CefLog.Debug("CefBrowser_N: %s: can't invoke native method '%s' before native context initialized", this, m1); + } + } + /** * Create a new browser. */ protected void createBrowser(CefClientHandler clientHandler, long windowHandle, String url, - boolean osr, boolean transparent, Component canvas, CefRequestContext context) { + boolean osr, boolean transparent, Component canvas) { if (isClosing_ || isClosed_ || isCreating_) return; if (getNativeRef("CefBrowser") == 0 && !isPending_) { isCreating_ = true; - try { - if (TRACE_LIFESPAN) CefLog.Debug("CefBrowser_N: %s: started native creation", this); - N_CreateBrowser( - clientHandler, windowHandle, url, osr, transparent, canvas, context); - } catch (UnsatisfiedLinkError err) { - err.printStackTrace(); - } + executeNative(() -> { + try { + if (TRACE_LIFESPAN) CefLog.Debug("CefBrowser_N: %s: started native creation", this); + N_CreateBrowser(clientHandler, windowHandle, url, osr, transparent, canvas, request_context_); + } catch (UnsatisfiedLinkError err) { + err.printStackTrace(); + } + }, "createBrowser"); } } @@ -190,12 +233,14 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { long windowHandle, boolean osr, boolean transparent, Component canvas, Point inspectAt) { if (getNativeRef("CefBrowser") == 0 && !isPending_) { - try { - isPending_ = N_CreateDevTools( - parent, clientHandler, windowHandle, osr, transparent, canvas, inspectAt); - } catch (UnsatisfiedLinkError err) { - err.printStackTrace(); - } + executeNative(() -> { + try { + isPending_ = N_CreateDevTools( + parent, clientHandler, windowHandle, osr, transparent, canvas, inspectAt); + } catch (UnsatisfiedLinkError err) { + err.printStackTrace(); + } + }, "createDevTools"); } } @@ -204,7 +249,10 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final long getWindowHandle(long surfaceHandle) { try { - return N_GetWindowHandle(surfaceHandle); + // NOTE: doesn't use cef ctx + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetWindowHandle(surfaceHandle); } catch (UnsatisfiedLinkError err) { err.printStackTrace(); } @@ -217,10 +265,17 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { super.finalize(); } + // + // NOTE: all native methods checks native CefBrowser pointer at first, + // so they won't use native context before native CefBrowser created + // + @Override public boolean canGoBack() { try { - return N_CanGoBack(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_CanGoBack(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -230,7 +285,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void goBack() { try { - N_GoBack(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_GoBack(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -239,7 +296,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public boolean canGoForward() { try { - return N_CanGoForward(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_CanGoForward(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -249,7 +308,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void goForward() { try { - N_GoForward(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_GoForward(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -258,7 +319,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public boolean isLoading() { try { - return N_IsLoading(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_IsLoading(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -268,7 +331,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void reload() { try { - N_Reload(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_Reload(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -277,7 +342,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void reloadIgnoreCache() { try { - N_ReloadIgnoreCache(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_ReloadIgnoreCache(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -286,7 +353,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void stopLoad() { try { - N_StopLoad(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_StopLoad(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -295,87 +364,105 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public int getIdentifier() { try { - return N_GetIdentifier(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetIdentifier(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return -1; } + return -1; } @Override public CefFrame getMainFrame() { try { - return N_GetMainFrame(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetMainFrame(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return null; } + return null; } @Override public CefFrame getFocusedFrame() { try { - return N_GetFocusedFrame(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetFocusedFrame(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return null; } + return null; } @Override public CefFrame getFrame(long identifier) { try { - return N_GetFrame(identifier); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetFrame(identifier); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return null; } + return null; } @Override public CefFrame getFrame(String name) { try { - return N_GetFrame2(name); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetFrame2(name); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return null; } + return null; } @Override public Vector<Long> getFrameIdentifiers() { try { - return N_GetFrameIdentifiers(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetFrameIdentifiers(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return null; } + return null; } @Override public Vector<String> getFrameNames() { try { - return N_GetFrameNames(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetFrameNames(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return null; } + return null; } @Override public int getFrameCount() { try { - return N_GetFrameCount(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetFrameCount(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); - return -1; } + return -1; } @Override public boolean isPopup() { try { - return N_IsPopup(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_IsPopup(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -385,7 +472,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public boolean hasDocument() { try { - return N_HasDocument(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_HasDocument(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -394,7 +483,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { public void viewSource() { try { - N_ViewSource(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_ViewSource(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -402,7 +493,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { public void getSource(CefStringVisitor visitor) { try { - N_GetSource(visitor); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_GetSource(visitor); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -410,7 +503,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { public void getText(CefStringVisitor visitor) { try { - N_GetText(visitor); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_GetText(visitor); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -419,7 +514,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void loadRequest(CefRequest request) { try { - N_LoadRequest(request); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_LoadRequest(request); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -428,7 +525,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void loadURL(String url) { try { - N_LoadURL(url); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_LoadURL(url); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -437,7 +536,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void executeJavaScript(String code, String url, int line) { try { - N_ExecuteJavaScript(code, url, line); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_ExecuteJavaScript(code, url, line); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -446,7 +547,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public String getURL() { try { - return N_GetURL(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetURL(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -460,6 +563,10 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { if (TRACE_LIFESPAN) CefLog.Debug("CefBrowser_N: %s: close, force=%d", this.toString(), force ? 1 : 0); + synchronized (delayedActions_) { + delayedActions_.clear(); + } + if (getNativeRef("CefBrowser") == 0) { CefLog.Debug("CefBrowser_N: %s: native part of browser wasn't created yet, browser will be closed immediately after creation", this); if (client_ != null) { @@ -477,7 +584,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { } try { - N_Close(force); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_Close(force); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -486,7 +595,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void setFocus(boolean enable) { try { - N_SetFocus(enable); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_SetFocus(enable); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -495,7 +606,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void setWindowVisibility(boolean visible) { try { - N_SetWindowVisibility(visible); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_SetWindowVisibility(visible); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -504,7 +617,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public double getZoomLevel() { try { - return N_GetZoomLevel(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + return N_GetZoomLevel(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -514,7 +629,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void setZoomLevel(double zoomLevel) { try { - N_SetZoomLevel(zoomLevel); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_SetZoomLevel(zoomLevel); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -524,7 +641,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { public void runFileDialog(FileDialogMode mode, String title, String defaultFilePath, Vector<String> acceptFilters, CefRunFileDialogCallback callback) { try { - N_RunFileDialog( + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_RunFileDialog( mode, title, defaultFilePath, acceptFilters, callback); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); @@ -534,7 +653,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void startDownload(String url) { try { - N_StartDownload(url); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_StartDownload(url); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -543,7 +664,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void print() { try { - N_Print(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_Print(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -556,7 +679,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { throw new IllegalArgumentException("path was null or empty"); } try { - N_PrintToPDF(path, settings, callback); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_PrintToPDF(path, settings, callback); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -565,7 +690,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void find(String searchText, boolean forward, boolean matchCase, boolean findNext) { try { - N_Find(searchText, forward, matchCase, findNext); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_Find(searchText, forward, matchCase, findNext); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -574,7 +701,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void stopFinding(boolean clearSelection) { try { - N_StopFinding(clearSelection); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_StopFinding(clearSelection); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -582,7 +711,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { protected final void closeDevTools() { try { - N_CloseDevTools(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_CloseDevTools(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -591,7 +722,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void replaceMisspelling(String word) { try { - N_ReplaceMisspelling(word); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_ReplaceMisspelling(word); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -605,7 +738,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public final void wasResized(int width, int height) { try { - N_WasResized(width, height); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_WasResized(width, height); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -614,7 +749,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public void notifyScreenInfoChanged() { try { - N_NotifyScreenInfoChanged(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_NotifyScreenInfoChanged(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -625,7 +762,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final void invalidate() { try { - N_Invalidate(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_Invalidate(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -638,7 +777,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public final void sendKeyEvent(KeyEvent e) { try { - N_SendKeyEvent(e); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_SendKeyEvent(e); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -651,7 +792,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public final void sendMouseEvent(MouseEvent e) { try { - N_SendMouseEvent(e); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_SendMouseEvent(e); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -664,7 +807,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { @Override public final void sendMouseWheelEvent(MouseWheelEvent e) { try { - N_SendMouseWheelEvent(e); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_SendMouseWheelEvent(e); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -682,7 +827,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { protected final void dragTargetDragEnter( CefDragData dragData, Point pos, int modifiers, int allowedOps) { try { - N_DragTargetDragEnter(dragData, pos, modifiers, allowedOps); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_DragTargetDragEnter(dragData, pos, modifiers, allowedOps); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -696,7 +843,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final void dragTargetDragOver(Point pos, int modifiers, int allowedOps) { try { - N_DragTargetDragOver(pos, modifiers, allowedOps); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_DragTargetDragOver(pos, modifiers, allowedOps); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -709,7 +858,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final void dragTargetDragLeave() { try { - N_DragTargetDragLeave(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_DragTargetDragLeave(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -724,7 +875,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final void dragTargetDrop(Point pos, int modifiers) { try { - N_DragTargetDrop(pos, modifiers); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_DragTargetDrop(pos, modifiers); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -741,7 +894,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final void dragSourceEndedAt(Point pos, int operation) { try { - N_DragSourceEndedAt(pos, operation); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_DragSourceEndedAt(pos, operation); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -758,7 +913,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final void dragSourceSystemDragEnded() { try { - N_DragSourceSystemDragEnded(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_DragSourceSystemDragEnded(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -766,7 +923,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { protected final void updateUI(Rectangle contentRect, Rectangle browserRect) { try { - N_UpdateUI(contentRect, browserRect); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_UpdateUI(contentRect, browserRect); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -776,7 +935,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { if (isClosing_ || isClosed_) return; try { - N_SetParent(windowHandle, canvas); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_SetParent(windowHandle, canvas); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } @@ -788,7 +949,9 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser { */ protected final void notifyMoveOrResizeStarted() { try { - N_NotifyMoveOrResizeStarted(); + ensureNativeCtxInitialized(); + if (isNativeCtxInitialized_) + N_NotifyMoveOrResizeStarted(); } catch (UnsatisfiedLinkError ule) { ule.printStackTrace(); } |