Skip to content

Commit

Permalink
Update to CEF 130.1.9+gfc42567+chromium-130.0.6723.70
Browse files Browse the repository at this point in the history
This adapts JCEF to a significant change in CEF: the removal of the Alloy Bootstrap. It makes JCEF use the Alloy Runtime mode for "normal" browser windows (because Chrome-style windows can't be integrated into existing native parents, which is how JCEF integrates browsers into Java UI) and changes the DevTools handling to open the DevTools in a separate pop-up window. The latter is necessary because DevTools are unsupported in an Alloy-style window by CEF at the moment, thus it's no longer possible to integrate the DevTools into Java windows.
  • Loading branch information
S1artie authored and magreenblatt committed Nov 11, 2024
1 parent 8b4225a commit 7e0ef9d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 59 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON)

# Specify the CEF distribution version.
if(NOT DEFINED CEF_VERSION)
set(CEF_VERSION "127.3.1+g6cbb30e+chromium-127.0.6533.100")
set(CEF_VERSION "130.1.9+gfc42567+chromium-130.0.6723.70")
endif()

# Determine the platform.
Expand Down
10 changes: 0 additions & 10 deletions java/org/cef/CefSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,6 @@ public ColorType clone() {
*/
public String locales_dir_path = null;

/**
* Set to true to disable loading of pack files for resources and locales.
* A resource bundle handler must be provided for the browser and render
* processes via CefApp::GetResourceBundleHandler() if loading of pack files
* is disabled. Also configurable using the "disable-pack-loading" command-
* line switch.
*/
public boolean pack_loading_disabled = false;

/**
* Set to a value between 1024 and 65535 to enable remote debugging on the
* specified port. For example, if 8080 is specified the remote debugging URL
Expand Down Expand Up @@ -278,7 +269,6 @@ public CefSettings clone() {
tmp.javascript_flags = javascript_flags;
tmp.resources_dir_path = resources_dir_path;
tmp.locales_dir_path = locales_dir_path;
tmp.pack_loading_disabled = pack_loading_disabled;
tmp.remote_debugging_port = remote_debugging_port;
tmp.uncaught_exception_stack_size = uncaught_exception_stack_size;
if (background_color != null) tmp.background_color = background_color.clone();
Expand Down
15 changes: 9 additions & 6 deletions java/org/cef/browser/CefBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,18 +337,21 @@ public void runFileDialog(FileDialogMode mode, String title, String defaultFileP
public void stopFinding(boolean clearSelection);

/**
* Get an instance of the DevTools to be displayed in its own window or to be
* embedded within your UI. Only one instance per browser is available.
* Get an instance of the DevTools to be displayed in its own window.
*/
public CefBrowser getDevTools();
public void openDevTools();

/**
* Get an instance of the DevTools to be displayed in its own window or to be
* embedded within your UI. Only one instance per browser is available.
* Open an instance of the DevTools to be displayed in its own window.
*
* @param inspectAt a position in the UI which should be inspected.
*/
public CefBrowser getDevTools(Point inspectAt);
public void openDevTools(Point inspectAt);

/**
* Close the DevTools.
*/
public void closeDevTools();

/**
* Get an instance of a client that can be used to leverage the DevTools
Expand Down
16 changes: 6 additions & 10 deletions java/org/cef/browser/CefBrowser_N.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ abstract class CefBrowser_N extends CefNativeAdapter implements CefBrowser {
private final CefRequestContext request_context_;
private volatile CefBrowser_N parent_ = null;
private volatile Point inspectAt_ = null;
private volatile CefBrowser_N devTools_ = null;
private volatile CefDevToolsClient devToolsClient_ = null;
private boolean closeAllowed_ = false;
private volatile boolean isClosed_ = false;
Expand Down Expand Up @@ -134,7 +133,6 @@ public synchronized void onBeforeClose() {
if (request_context_ != null) request_context_.dispose();
if (parent_ != null) {
parent_.closeDevTools();
parent_.devTools_ = null;
parent_ = null;
}
if (devToolsClient_ != null) {
Expand All @@ -143,16 +141,13 @@ public synchronized void onBeforeClose() {
}

@Override
public CefBrowser getDevTools() {
return getDevTools(null);
public void openDevTools() {
openDevTools(null);
}

@Override
public synchronized CefBrowser getDevTools(Point inspectAt) {
if (devTools_ == null) {
devTools_ = createDevToolsBrowser(client_, url_, request_context_, this, inspectAt);
}
return devTools_;
public synchronized void openDevTools(Point inspectAt) {
createDevToolsBrowser(client_, url_, request_context_, this, inspectAt).createImmediately();
}

@Override
Expand Down Expand Up @@ -594,7 +589,8 @@ public void stopFinding(boolean clearSelection) {
}
}

protected final void closeDevTools() {
@Override
public void closeDevTools() {
try {
N_CloseDevTools();
} catch (UnsatisfiedLinkError ule) {
Expand Down
8 changes: 4 additions & 4 deletions java/tests/detailed/dialog/DevToolsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

@SuppressWarnings("serial")
public class DevToolsDialog extends JDialog {
private final CefBrowser devTools_;
private final CefBrowser browser_;
public DevToolsDialog(Frame owner, String title, CefBrowser browser) {
this(owner, title, browser, null);
}

public DevToolsDialog(Frame owner, String title, CefBrowser browser, Point inspectAt) {
super(owner, title, false);
browser_ = browser;

setLayout(new BorderLayout());
setSize(800, 600);
setLocation(owner.getLocation().x + 20, owner.getLocation().y + 20);

devTools_ = browser.getDevTools(inspectAt);
add(devTools_.getUIComponent());
browser.openDevTools(inspectAt);

addComponentListener(new ComponentAdapter() {
@Override
Expand All @@ -41,7 +41,7 @@ public void componentHidden(ComponentEvent e) {

@Override
public void dispose() {
devTools_.close(true);
browser_.closeDevTools();
super.dispose();
}
}
46 changes: 26 additions & 20 deletions native/CefBrowser_N.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,29 @@ void create(std::shared_ptr<JNIObjectsForCreate> objs,
if (!lifeSpanHandler.get())
return;

CefRefPtr<CefBrowser> parentBrowser =
GetCefFromJNIObject<CefBrowser>(env, objs->jparentBrowser, "CefBrowser");

CefWindowInfo windowInfo;
CefBrowserSettings settings;

// If parentBrowser is set, we want to show the DEV-Tools for that browser.
// Since that cannot be an Alloy-style window, it cannot be integrated into
// Java UI but must be opened as a pop-up.
if (parentBrowser.get() != nullptr) {
CefPoint inspectAt;
if (objs->jinspectAt != nullptr) {
int x, y;
GetJNIPoint(env, objs->jinspectAt, &x, &y);
inspectAt.Set(x, y);
}

parentBrowser->GetHost()->ShowDevTools(windowInfo, clientHandler.get(),
settings, inspectAt);
JNI_CALL_VOID_METHOD(env, objs->jbrowser, "notifyBrowserCreated", "()V");
return;
}

if (osr == JNI_FALSE) {
CefRect rect;
CefRefPtr<WindowHandler> windowHandler =
Expand Down Expand Up @@ -978,8 +1000,6 @@ void create(std::shared_ptr<JNIObjectsForCreate> objs,
windowInfo.SetAsWindowless((CefWindowHandle)windowHandle);
}

CefBrowserSettings settings;

if (transparent == JNI_FALSE) {
// Specify an opaque background color (white) to disable transparency.
settings.background_color = CefColorSetARGB(255, 255, 255, 255);
Expand All @@ -998,27 +1018,10 @@ void create(std::shared_ptr<JNIObjectsForCreate> objs,
CefRefPtr<CefRequestContext> context = GetCefFromJNIObject<CefRequestContext>(
env, objs->jcontext, "CefRequestContext");

CefRefPtr<CefBrowser> parentBrowser =
GetCefFromJNIObject<CefBrowser>(env, objs->jparentBrowser, "CefBrowser");

// Add a global ref that will be released in LifeSpanHandler::OnAfterCreated.
jobject globalRef = env->NewGlobalRef(objs->jbrowser);
lifeSpanHandler->registerJBrowser(globalRef);

// If parentBrowser is set, we want to show the DEV-Tools for that browser
if (parentBrowser.get() != nullptr) {
CefPoint inspectAt;
if (objs->jinspectAt != nullptr) {
int x, y;
GetJNIPoint(env, objs->jinspectAt, &x, &y);
inspectAt.Set(x, y);
}
parentBrowser->GetHost()->ShowDevTools(windowInfo, clientHandler.get(),
settings, inspectAt);
JNI_CALL_VOID_METHOD(env, objs->jbrowser, "notifyBrowserCreated", "()V");
return;
}

CefRefPtr<CefDictionaryValue> extra_info;
auto router_configs = BrowserProcessHandler::GetMessageRouterConfigs();
if (router_configs) {
Expand All @@ -1027,6 +1030,10 @@ void create(std::shared_ptr<JNIObjectsForCreate> objs,
extra_info->SetList("router_configs", router_configs);
}

// JCEF requires Alloy runtime style for "normal" browsers in order for them
// to be integratable into Java UI.
windowInfo.runtime_style = CEF_RUNTIME_STYLE_ALLOY;

bool result = CefBrowserHost::CreateBrowser(
windowInfo, clientHandler.get(), strUrl, settings, extra_info, context);
if (!result) {
Expand Down Expand Up @@ -1524,7 +1531,6 @@ Java_org_cef_browser_CefBrowser_1N_N_1SetWindowVisibility(JNIEnv* env,
}
#endif
}

JNIEXPORT jdouble JNICALL
Java_org_cef_browser_CefBrowser_1N_N_1GetZoomLevel(JNIEnv* env, jobject obj) {
CefRefPtr<CefBrowser> browser = JNI_GET_BROWSER_OR_RETURN(env, obj, 0.0);
Expand Down
2 changes: 0 additions & 2 deletions native/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ CefSettings GetJNISettings(JNIEnv* env, jobject obj) {
CefString(&settings.locales_dir_path) = tmp;
tmp.clear();
}
GetJNIFieldBoolean(env, cls, obj, "pack_loading_disabled",
&settings.pack_loading_disabled);
GetJNIFieldInt(env, cls, obj, "remote_debugging_port",
&settings.remote_debugging_port);
GetJNIFieldInt(env, cls, obj, "uncaught_exception_stack_size",
Expand Down
12 changes: 6 additions & 6 deletions native/request_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ void RequestHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,

ScopedJNIString jerrorString(env, error_string);

JNI_CALL_VOID_METHOD(
env, handle_, "onRenderProcessTerminated",
"(Lorg/cef/browser/CefBrowser;"
"Lorg/cef/handler/CefRequestHandler$TerminationStatus;"
"ILjava/lang/String;)V",
jbrowser.get(), jstatus.get(), error_code, jerrorString.get());
JNI_CALL_VOID_METHOD(env, handle_, "onRenderProcessTerminated",
"(Lorg/cef/browser/CefBrowser;"
"Lorg/cef/handler/CefRequestHandler$TerminationStatus;"
"ILjava/lang/String;)V",
jbrowser.get(), jstatus.get(), error_code,
jerrorString.get());
}

0 comments on commit 7e0ef9d

Please sign in to comment.