Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	CMakeLists.txt
#	java/org/cef/CefApp.java
#	java/org/cef/CefClient.java
#	java/org/cef/browser/CefBrowserFactory.java
#	java/org/cef/browser/CefBrowserOsr.java
#	java/org/cef/browser/CefBrowserWr.java
#	java/org/cef/browser/CefBrowser_N.java
#	java/tests/detailed/MainFrame.java
#	java/tests/simple/MainFrame.java
#	native/CefBrowser_N.cpp
#	native/CefBrowser_N.h
  • Loading branch information
1zun4 committed Mar 12, 2024
2 parents 4f24f98 + 0b8e42e commit 5b2d278
Show file tree
Hide file tree
Showing 45 changed files with 1,268 additions and 106 deletions.
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,9 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON)
# CEF configuration.
#

# Specify the CEF branch
if(NOT DEFINED CEF_BRANCH)
set(CEF_BRANCH "5845")
endif()

# Specify the CEF distribution version.
if(NOT DEFINED CEF_VERSION)
set(CEF_VERSION "116.0.27+gd8c85ac+chromium-116.0.5845.190")
set(CEF_VERSION "122.1.10+gc902316+chromium-122.0.6261.112")
endif()

# Determine the platform.
Expand Down Expand Up @@ -172,7 +167,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Download and extract the CEF binary distribution (executes DownloadCEF.cmake).
include(DownloadCEF)
DownloadCEF("${CEF_PLATFORM}" "${CEF_BRANCH}" "${CEF_VERSION}" "${CMAKE_SOURCE_DIR}/third_party/cef")
DownloadCEF("${CEF_PLATFORM}" "${CEF_VERSION}" "${CMAKE_SOURCE_DIR}/third_party/cef")

# Add the CEF binary distribution's cmake/ directory to the module path.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")
Expand Down
14 changes: 12 additions & 2 deletions java/org/cef/CefApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class CefVersion {
public final int CHROME_VERSION_PATCH;

private CefVersion(int jcefCommitNo, int cefMajor, int cefMinor, int cefPatch,
int cefCommitNo, int chrMajor, int chrMin, int chrBuild, int chrPatch) {
int cefCommitNo, int chrMajor, int chrMin, int chrBuild, int chrPatch) {
JCEF_COMMIT_NUMBER = jcefCommitNo;

CEF_VERSION_MAJOR = cefMajor;
Expand Down Expand Up @@ -102,6 +102,12 @@ public enum CefAppState {
*/
INITIALIZED,

/**
* CEF initialization has failed (for example due to a second process using
* the same root_cache_path).
*/
INITIALIZATION_FAILED,

/**
* CefApp is in its shutdown process. All CefClients and CefBrowser
* instances will be disposed. No new CefClient or CefBrowser is allowed to
Expand Down Expand Up @@ -384,7 +390,11 @@ private final void initialize() {
settings.locales_dir_path = localesPath.normalize().toAbsolutePath().toString();
}

if (N_Initialize(appHandler_, settings)) setState(CefAppState.INITIALIZED);
if (N_Initialize(appHandler_, settings)) {
setState(CefAppState.INITIALIZED);
} else {
setState(CefAppState.INITIALIZATION_FAILED);
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions java/org/cef/CefBrowserSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

package org.cef;

/**
* Browser initialization settings. Specify NULL or 0 to get the recommended
* default values. The consequences of using custom values may not be well
* tested. Many of these and other settings can also configured using command-
* line switches.
*/
public class CefBrowserSettings {
/**
* The maximum rate in frames per second (fps) that CefRenderHandler::OnPaint
* will be called for a windowless browser. The actual fps may be lower if
* the browser cannot generate frames at the requested rate. The minimum
* value is 1 and the maximum value is 60 (default 30). This value can also
* be changed dynamically via {@code CefBrowser#setWindowlessFrameRate}
*/
public int windowless_frame_rate = 0;

public CefBrowserSettings() {}

@Override
public CefBrowserSettings clone() {
CefBrowserSettings tmp = new CefBrowserSettings();
tmp.windowless_frame_rate = windowless_frame_rate;
return tmp;
}
}
50 changes: 35 additions & 15 deletions java/org/cef/CefClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Vector;
import java.util.function.Consumer;

import javax.swing.SwingUtilities;

Expand Down Expand Up @@ -85,16 +86,20 @@ public void dispose() {

// CefClientHandler

public CefBrowser createBrowser(
String url, boolean isTransparent) {
return createBrowser(url, isTransparent, null);
public CefBrowser createBrowser(String url, boolean isOffscreenRendered, boolean isTransparent,
CefRequestContext context) {
if (isDisposed_)
throw new IllegalStateException("Can't create browser. CefClient is disposed");
return CefBrowserFactory.create(
this, url, isOffscreenRendered, isTransparent, context, null);
}

public CefBrowser createBrowser(String url, boolean isTransparent,
CefRequestContext context) {
public CefBrowser createBrowser(String url, boolean isOffscreenRendered, boolean isTransparent,
CefRequestContext context, CefBrowserSettings settings) {
if (isDisposed_)
throw new IllegalStateException("Can't create browser. CefClient is disposed");
return CefBrowserFactory.create(this, url, isTransparent, context);
return CefBrowserFactory.create(
this, url, isOffscreenRendered, isTransparent, context, settings);
}

@Override
Expand Down Expand Up @@ -125,7 +130,7 @@ protected CefDialogHandler getDialogHandler() {
protected CefDisplayHandler getDisplayHandler() {
return this;
}

@Override
protected CefAudioHandler getAudioHandler() {
return this;
Expand Down Expand Up @@ -263,6 +268,12 @@ public void onTitleChange(CefBrowser browser, String title) {
displayHandler_.onTitleChange(browser, title);
}

@Override
public void OnFullscreenModeChange(CefBrowser browser, boolean fullscreen) {
if (displayHandler_ != null && browser != null)
displayHandler_.OnFullscreenModeChange(browser, fullscreen);
}

@Override
public boolean onTooltip(CefBrowser browser, String text) {
if (displayHandler_ != null && browser != null) {
Expand Down Expand Up @@ -687,6 +698,15 @@ public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects,
realHandler.onPaint(browser, popup, dirtyRects, buffer, width, height);
}

@Override
public void addOnPaintListener(Consumer<CefPaintEvent> listener) {}

@Override
public void setOnPaintListener(Consumer<CefPaintEvent> listener) {}

@Override
public void removeOnPaintListener(Consumer<CefPaintEvent> listener) {}

@Override
public boolean startDragging(CefBrowser browser, CefDragData dragData, int mask, int x, int y) {
if (browser == null) return false;
Expand Down Expand Up @@ -791,39 +811,39 @@ public void onMouseEvent(
public boolean getScreenInfo(CefBrowser arg0, CefScreenInfo arg1) {
return false;
}

// CefAudioHandler

public CefClient addAudioHandler(CefAudioHandler handler) {
if (audioHandler_ == null) audioHandler_ = handler;
return this;
}

public void removeAudioHandler() {
audioHandler_ = null;
}

@Override
public boolean getAudioParameters(CefBrowser browser, CefAudioParameters params) {
if (audioHandler_ != null) return audioHandler_.getAudioParameters(browser, params);
return false;
}

@Override
public void onAudioStreamStarted(CefBrowser browser, CefAudioParameters params, int channels) {
if (audioHandler_ != null) audioHandler_.onAudioStreamStarted(browser, params, channels);
}

@Override
public void onAudioStreamPacket(CefBrowser browser, float[] data, int frames, long pts) {
if (audioHandler_ != null) audioHandler_.onAudioStreamPacket(browser, data, frames, pts);
}

@Override
public void onAudioStreamStopped(CefBrowser browser) {
if (audioHandler_ != null) audioHandler_.onAudioStreamStopped(browser);
}

@Override
public void onAudioStreamError(CefBrowser browser, String text) {
if (audioHandler_ != null) audioHandler_.onAudioStreamError(browser, text);
Expand Down
32 changes: 31 additions & 1 deletion java/org/cef/CefSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,39 @@ public ColorType clone() {
* The location where cache data will be stored on disk. If empty an in-memory
* cache will be used for some features and a temporary disk cache for others.
* HTML5 databases such as localStorage will only persist across sessions if a
* cache path is specified.
* cache path is specified. If this is set and root_cache_path is also set, the cache_path
* directory must reside within root_cache_path.
*/
public String cache_path = null;

/**
* The root directory for installation-specific data and the parent directory
* for profile-specific data. All CefSettings.cache_path and
* CefRequestContextSettings.cache_path values must have this parent
* directory in common. If this value is empty and CefSettings.cache_path is
* non-empty then it will default to the CefSettings.cache_path value. Any
* non-empty value must be an absolute path. If both values are empty then
* the default platform-specific directory will be used
* ("~/.config/cef_user_data" directory on Linux, "~/Library/Application
* Support/CEF/User Data" directory on MacOS, "AppData\Local\CEF\User Data"
* directory under the user profile directory on Windows). Use of the default
* directory is not recommended in production applications (see below).
*
* Multiple application instances writing to the same root_cache_path
* directory could result in data corruption. A process singleton lock based
* on the root_cache_path value is therefore used to protect against this.
* This singleton behavior applies to all CEF-based applications using
* version 120 or newer. You should customize root_cache_path for your
* application and implement CefAppHandler::
* onAlreadyRunningAppRelaunch, which will then be called on any app relaunch
* with the same root_cache_path value.
*
* Failure to set the root_cache_path value correctly may result in startup
* crashes or other unexpected behaviors (for example, the sandbox blocking
* read/write access to certain files).
*/
public String root_cache_path = null;

/**
* To persist session cookies (cookies without an expiry date or validity
* interval) by default when using the global cookie manager set this value to
Expand Down Expand Up @@ -245,6 +274,7 @@ public CefSettings clone() {
tmp.windowless_rendering_enabled = windowless_rendering_enabled;
tmp.command_line_args_disabled = command_line_args_disabled;
tmp.cache_path = cache_path;
tmp.root_cache_path = root_cache_path;
tmp.persist_session_cookies = persist_session_cookies;
tmp.user_agent = user_agent;
tmp.user_agent_product = user_agent_product;
Expand Down
4 changes: 3 additions & 1 deletion java/org/cef/SystemBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class SystemBootstrap {
/**
* Simple interface for how a library by name should be loaded.
*/
static public interface Loader { public void loadLibrary(String libname); }
static public interface Loader {
public void loadLibrary(String libname);
}

/**
* Default implementation is to call System.loadLibrary
Expand Down
42 changes: 37 additions & 5 deletions java/org/cef/browser/CefBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,20 @@ public interface CefBrowser {
* @param identifier The unique frame identifier
* @return The frame or NULL if not found
*/
public CefFrame getFrame(long identifier);
public CefFrame getFrameByIdentifier(String identifier);

/**
* Returns the frame with the specified name, or NULL if not found.
* @param name The specified name
* @return The frame or NULL if not found
*/
public CefFrame getFrame(String name);
public CefFrame getFrameByName(String name);

/**
* Returns the identifiers of all existing frames.
* @return All identifiers of existing frames.
*/
public Vector<Long> getFrameIdentifiers();
public Vector<String> getFrameIdentifiers();

/**
* Returns the names of all existing frames.
Expand Down Expand Up @@ -331,19 +331,29 @@ public void runFileDialog(FileDialogMode mode, String title, String defaultFileP
public void stopFinding(boolean clearSelection);

/**
* Get an instance of the dev tools to be displayed in its own window or to be
* 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.
*/
public CefBrowser getDevTools();

/**
* Get an instance of the dev tools to be displayed in its own window or to be
* 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.
*
* @param inspectAt a position in the UI which should be inspected.
*/
public CefBrowser getDevTools(Point inspectAt);

/**
* Get an instance of a client that can be used to leverage the DevTools
* protocol. Only one instance per browser is available.
*
* @see {@link CefDevToolsClient}
* @return DevTools client, or null if this browser is not yet created
* or if it is closed or closing
*/
public CefDevToolsClient getDevToolsClient();

/**
* If a misspelled word is currently selected in an editable node calling
* this method will replace it with the specified |word|.
Expand Down Expand Up @@ -374,4 +384,26 @@ public void runFileDialog(FileDialogMode mode, String title, String defaultFileP
* @throws UnsupportedOperationException if not supported
*/
public CompletableFuture<BufferedImage> createScreenshot(boolean nativeResolution);

/**
* Set the maximum rate in frames per second (fps) that {@code CefRenderHandler::onPaint}
* will be called for a windowless browser. The actual fps may be
* lower if the browser cannot generate frames at the requested rate. The
* minimum value is 1, and the maximum value is 60 (default 30).
*
* @param frameRate the maximum frame rate
* @throws UnsupportedOperationException if not supported
*/
public void setWindowlessFrameRate(int frameRate);

/**
* Returns the maximum rate in frames per second (fps) that {@code CefRenderHandler::onPaint}
* will be called for a windowless browser. The actual fps may be lower if the browser cannot
* generate frames at the requested rate. The minimum value is 1, and the maximum value is 60
* (default 30).
*
* @return the framerate, 0 if an error occurs
* @throws UnsupportedOperationException if not supported
*/
public CompletableFuture<Integer> getWindowlessFrameRate();
}
9 changes: 6 additions & 3 deletions java/org/cef/browser/CefBrowserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@

package org.cef.browser;

import org.cef.CefBrowserSettings;
import org.cef.CefClient;

/**
* Creates a new instance of CefBrowser according the passed values
*/
public class CefBrowserFactory {
public static CefBrowser create(CefClient client, String url,
boolean isTransparent, CefRequestContext context) {
return new CefBrowserOsr(client, url, isTransparent, context);
public static CefBrowser create(CefClient client, String url, boolean isOffscreenRendered,
boolean isTransparent, CefRequestContext context, CefBrowserSettings settings) {
if (isOffscreenRendered)
return new CefBrowserOsr(client, url, isTransparent, context, settings);
return new CefBrowserWr(client, url, context, settings);
}
}
Loading

0 comments on commit 5b2d278

Please sign in to comment.