Package org.cef.browser
Interface CefBrowser
-
public interface CefBrowserInterface representing a browser.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancanGoBack()Tests if the browser can navigate backwards.booleancanGoForward()Tests if the browser can navigate forwards.voidclose(boolean force)Request that the browser close.voidcreateImmediately()Call to immediately create the underlying browser object.java.util.concurrent.CompletableFuture<java.awt.image.BufferedImage>createScreenshot(boolean nativeResolution)Captures a screenshot-like image of the currently displayed content and returns it.booleandoClose()Called from CefClient.doClose.voidexecuteJavaScript(java.lang.String code, java.lang.String url, int line)Execute a string of JavaScript code in this frame.voidfind(int identifier, java.lang.String searchText, boolean forward, boolean matchCase, boolean findNext)Search for some kind of text on the page.CefClientgetClient()Get the client associated with this browser.CefBrowsergetDevTools()Get an instance of the dev tools to be displayed in its own window or to be embedded within your UI.CefBrowsergetDevTools(java.awt.Point inspectAt)Get an instance of the dev tools to be displayed in its own window or to be embedded within your UI.CefFramegetFocusedFrame()Returns the focused frame for the browser window.CefFramegetFrame(long identifier)Returns the frame with the specified identifier, or NULL if not found.CefFramegetFrame(java.lang.String name)Returns the frame with the specified name, or NULL if not found.intgetFrameCount()Returns the number of frames that currently exist.java.util.Vector<java.lang.Long>getFrameIdentifiers()Returns the identifiers of all existing frames.java.util.Vector<java.lang.String>getFrameNames()Returns the names of all existing frames.intgetIdentifier()Returns the unique browser identifier.CefFramegetMainFrame()Returns the main (top-level) frame for the browser window.CefRenderHandlergetRenderHandler()Get an implementation of CefRenderHandler if any.voidgetSource(CefStringVisitor visitor)Retrieve this frame's HTML source as a string sent to the specified visitor.voidgetText(CefStringVisitor visitor)Retrieve this frame's display text as a string sent to the specified visitor.java.awt.ComponentgetUIComponent()Get the underlying UI component (e.g.java.lang.StringgetURL()Emits the URL currently loaded in this frame.CefWindowHandlergetWindowHandler()Get an implementation of CefWindowHandler if any.doublegetZoomLevel()Get the current zoom level.voidgoBack()Go back.voidgoForward()Go forward.booleanhasDocument()Tests if a document has been loaded in the browser.booleanisLoading()Tests if the browser is currently loading.booleanisPopup()Tests if the window is a popup window.voidloadRequest(CefRequest request)Load the request represented by the request object.voidloadURL(java.lang.String url)Load the specified URL in the main frame.voidonBeforeClose()Called from CefClient.onBeforeClose.voidprint()Print the current browser contents.voidprintToPDF(java.lang.String path, CefPdfPrintSettings settings, CefPdfPrintCallback callback)Print the current browser contents to a PDF.voidreload()Reload the current page.voidreloadIgnoreCache()Reload the current page ignoring any cached data.voidreplaceMisspelling(java.lang.String word)If a misspelled word is currently selected in an editable node calling this method will replace it with the specified |word|.voidrunFileDialog(CefDialogHandler.FileDialogMode mode, java.lang.String title, java.lang.String defaultFilePath, java.util.Vector<java.lang.String> acceptFilters, int selectedAcceptFilter, CefRunFileDialogCallback callback)Call to run a file chooser dialog.voidsetCloseAllowed()Allow the browser to close.voidsetFocus(boolean enable)Set or remove keyboard focus to/from the browser window.voidsetWindowVisibility(boolean visible)Set whether the window containing the browser is visible (minimized/unminimized, app hidden/unhidden, etc).voidsetZoomLevel(double zoomLevel)Change the zoom level to the specified value.voidstartDownload(java.lang.String url)Download the file at url using CefDownloadHandler.voidstopFinding(boolean clearSelection)Cancel all searches that are currently going on.voidstopLoad()Stop loading the page.voidviewSource()Save this frame's HTML source to a temporary file and open it in the default text viewing application.
-
-
-
Method Detail
-
createImmediately
void createImmediately()
Call to immediately create the underlying browser object. By default the browser object will be created when the parent container is displayed for the first time.
-
getUIComponent
java.awt.Component getUIComponent()
Get the underlying UI component (e.g. java.awt.Canvas).- Returns:
- The underlying UI component.
-
getClient
CefClient getClient()
Get the client associated with this browser.- Returns:
- The browser client.
-
getRenderHandler
CefRenderHandler getRenderHandler()
Get an implementation of CefRenderHandler if any.- Returns:
- An instance of CefRenderHandler or null.
-
getWindowHandler
CefWindowHandler getWindowHandler()
Get an implementation of CefWindowHandler if any.- Returns:
- An instance of CefWindowHandler or null.
-
canGoBack
boolean canGoBack()
Tests if the browser can navigate backwards.- Returns:
- true if the browser can navigate backwards.
-
goBack
void goBack()
Go back.
-
canGoForward
boolean canGoForward()
Tests if the browser can navigate forwards.- Returns:
- true if the browser can navigate forwards.
-
goForward
void goForward()
Go forward.
-
isLoading
boolean isLoading()
Tests if the browser is currently loading.- Returns:
- true if the browser is currently loading.
-
reload
void reload()
Reload the current page.
-
reloadIgnoreCache
void reloadIgnoreCache()
Reload the current page ignoring any cached data.
-
stopLoad
void stopLoad()
Stop loading the page.
-
getIdentifier
int getIdentifier()
Returns the unique browser identifier.- Returns:
- The browser identifier
-
getMainFrame
CefFrame getMainFrame()
Returns the main (top-level) frame for the browser window.- Returns:
- The main frame
-
getFocusedFrame
CefFrame getFocusedFrame()
Returns the focused frame for the browser window.- Returns:
- The focused frame
-
getFrame
CefFrame getFrame(long identifier)
Returns the frame with the specified identifier, or NULL if not found.- Parameters:
identifier- The unique frame identifier- Returns:
- The frame or NULL if not found
-
getFrame
CefFrame getFrame(java.lang.String name)
Returns the frame with the specified name, or NULL if not found.- Parameters:
name- The specified name- Returns:
- The frame or NULL if not found
-
getFrameIdentifiers
java.util.Vector<java.lang.Long> getFrameIdentifiers()
Returns the identifiers of all existing frames.- Returns:
- All identifiers of existing frames.
-
getFrameNames
java.util.Vector<java.lang.String> getFrameNames()
Returns the names of all existing frames.- Returns:
- The names of all existing frames.
-
getFrameCount
int getFrameCount()
Returns the number of frames that currently exist.- Returns:
- The number of frames
-
isPopup
boolean isPopup()
Tests if the window is a popup window.- Returns:
- true if the window is a popup window.
-
hasDocument
boolean hasDocument()
Tests if a document has been loaded in the browser.- Returns:
- true if a document has been loaded in the browser.
-
viewSource
void viewSource()
Save this frame's HTML source to a temporary file and open it in the default text viewing application. This method can only be called from the browser process.
-
getSource
void getSource(CefStringVisitor visitor)
Retrieve this frame's HTML source as a string sent to the specified visitor.- Parameters:
visitor-
-
getText
void getText(CefStringVisitor visitor)
Retrieve this frame's display text as a string sent to the specified visitor.- Parameters:
visitor-
-
loadRequest
void loadRequest(CefRequest request)
Load the request represented by the request object.- Parameters:
request- The request object.
-
loadURL
void loadURL(java.lang.String url)
Load the specified URL in the main frame.- Parameters:
url- The URL to load.
-
executeJavaScript
void executeJavaScript(java.lang.String code, java.lang.String url, int line)Execute a string of JavaScript code in this frame. The url parameter is the URL where the script in question can be found, if any. The renderer may request this URL to show the developer the source of the error. The line parameter is the base line number to use for error reporting.- Parameters:
code- The code to be executed.url- The URL where the script in question can be found.line- The base line number to use for error reporting.
-
getURL
java.lang.String getURL()
Emits the URL currently loaded in this frame.- Returns:
- the URL currently loaded in this frame.
-
close
void close(boolean force)
Request that the browser close.- Parameters:
force- force the close.
-
setCloseAllowed
void setCloseAllowed()
Allow the browser to close.
-
doClose
boolean doClose()
Called from CefClient.doClose.
-
onBeforeClose
void onBeforeClose()
Called from CefClient.onBeforeClose.
-
setFocus
void setFocus(boolean enable)
Set or remove keyboard focus to/from the browser window.- Parameters:
enable- set to true to give the focus to the browser
-
setWindowVisibility
void setWindowVisibility(boolean visible)
Set whether the window containing the browser is visible (minimized/unminimized, app hidden/unhidden, etc). Only used on Mac OS X.- Parameters:
visible-
-
getZoomLevel
double getZoomLevel()
Get the current zoom level. The default zoom level is 0.0.- Returns:
- The current zoom level.
-
setZoomLevel
void setZoomLevel(double zoomLevel)
Change the zoom level to the specified value. Specify 0.0 to reset the zoom level.- Parameters:
zoomLevel- The zoom level to be set.
-
runFileDialog
void runFileDialog(CefDialogHandler.FileDialogMode mode, java.lang.String title, java.lang.String defaultFilePath, java.util.Vector<java.lang.String> acceptFilters, int selectedAcceptFilter, CefRunFileDialogCallback callback)
Call to run a file chooser dialog. Only a single file chooser dialog may be pending at any given time.The dialog will be initiated asynchronously on the UI thread.- Parameters:
mode- represents the type of dialog to display.title- to be used for the dialog and may be empty to show the default title ("Open" or "Save" depending on the mode).defaultFilePath- is the path with optional directory and/or file name component that should be initially selected in the dialog.acceptFilters- are used to restrict the selectable file types and may any combination of (a) valid lower-cased MIME types (e.g. "text/*" or "image/*"), (b) individual file extensions (e.g. ".txt" or ".png"), or (c) combined description and file extension delimited using "|" and ";" (e.g. "Image Types|.png;.gif;.jpg").selectedAcceptFilter- is the 0-based index of the filter that should be selected by default.callback- will be executed after the dialog is dismissed or immediately if another dialog is already pending.
-
startDownload
void startDownload(java.lang.String url)
Download the file at url using CefDownloadHandler.- Parameters:
url- URL to download that file.
-
print
void print()
Print the current browser contents.
-
printToPDF
void printToPDF(java.lang.String path, CefPdfPrintSettings settings, CefPdfPrintCallback callback)Print the current browser contents to a PDF.- Parameters:
path- The path of the file to write to (will be overwritten if it already exists). Cannot be null.settings- The pdf print settings to use. If null then defaults will be used.callback- Called when the pdf print job has completed.
-
find
void find(int identifier, java.lang.String searchText, boolean forward, boolean matchCase, boolean findNext)Search for some kind of text on the page.- Parameters:
identifier- can be used to have multiple searches running simultaniously.searchText- to be searched for.forward- indicates whether to search forward or backward within the page.matchCase- indicates whether the search should be case-sensitive.findNext- indicates whether this is the first request or a follow-up.
-
stopFinding
void stopFinding(boolean clearSelection)
Cancel all searches that are currently going on.- Parameters:
clearSelection- Set to true to reset selection.
-
getDevTools
CefBrowser getDevTools()
Get an instance of the dev tools to be displayed in its own window or to be embedded within your UI. Only one instance per browser is available.
-
getDevTools
CefBrowser getDevTools(java.awt.Point inspectAt)
Get an instance of the dev tools to be displayed in its own window or to be embedded within your UI. Only one instance per browser is available.- Parameters:
inspectAt- a position in the UI which should be inspected.
-
replaceMisspelling
void replaceMisspelling(java.lang.String word)
If a misspelled word is currently selected in an editable node calling this method will replace it with the specified |word|.- Parameters:
word- replace selected word with this word.
-
createScreenshot
java.util.concurrent.CompletableFuture<java.awt.image.BufferedImage> createScreenshot(boolean nativeResolution)
Captures a screenshot-like image of the currently displayed content and returns it.If executed on the AWT Event Thread, this returns an immediately resolved
CompletableFuture. If executed from another thread, theCompletableFuturereturned is resolved as soon as the screenshot has been taken (which must happen on the event thread).The generated screenshot can either be returned as-is, containing all natively-rendered pixels, or it can be scaled to match the logical width and height of the window. This distinction is only relevant in case of differing logical and physical resolutions (for example with HiDPI/Retina displays, which have a scaling factor of for example 2 between the logical width of a window (ex. 400px) and the actual number of pixels in each row (ex. 800px with a scaling factor of 2)).
- Parameters:
nativeResolution- whether to return an image at full native resolution (true) or a scaled-down version whose width and height are equal to the logical size of the screenshotted browser window- Returns:
- the screenshot image
- Throws:
java.lang.UnsupportedOperationException- if not supported
-
-