public class Browser
extends java.awt.Canvas
dispose()
method to free allocated memory and
terminate appropriate native process. Before you dispose it, it's recommended that you remove component
from Swing container where it was embedded.Constructor and Description |
---|
Browser()
Constructs a new
Browser instance with new BrowserContext . |
Browser(BrowserContext context)
Constructs a new
Browser instance with specific context . |
Modifier and Type | Method and Description |
---|---|
void |
addDisposeListener(DisposeListener listener) |
void |
addMouseEventListener(MouseEventListener listener) |
void |
addNavigationListener(NavigationListener listener) |
void |
addNotify() |
void |
addPrintEventListener(PrintEventListener listener) |
void |
addScriptErrorListener(ScriptErrorListener listener) |
void |
addStatusListener(StatusListener listener) |
void |
addWindowListener(WindowListener listener) |
void |
clearCache(InternetCacheEntry cacheEntry)
Clears the Internet Explorer cache.
|
void |
dispose()
Disposes web browser engine associated with the current Browser instance, clears allocated memory and
terminates corresponding native process if it's necessary.
|
JSValue |
executeScript(java.lang.String javaScript)
Executes
javaScript code in the main frame of the currently loaded document. |
AuthenticationHandler |
getAuthenticationHandler()
Returns authentication handler or
null if handler isn't installed. |
java.lang.String |
getContent()
Returns the string that represents HTML content of a currently
loaded document in WebBrowser.
|
java.lang.String |
getContent(boolean original)
Returns the string that represents HTML content of a currently
loaded document in WebBrowser.
|
BrowserContext |
getContext()
Returns context associated with the current Browser instance.
|
ContextMenuProvider |
getContextMenuProvider() |
java.util.List<Cookie> |
getCookies(java.lang.String url)
Returns cookies associated with the
url or empty collection is no cookies available for this URL. |
java.lang.String |
getDefaultUserAgent()
Returns default user-agent string.
|
DialogHandler |
getDialogHandler() |
java.util.List<DisposeListener> |
getDisposeListeners() |
DOMDocument |
getDocument()
Returns DOM document of the currently loaded web page or
null if web page isn't loaded completely or
it's not HTML document. |
java.lang.String |
getDocumentType()
Returns string that represents type of the currently loaded document.
|
EventsHandler |
getEventsHandler() |
HTMLDialogListener |
getHTMLDialogListener()
Returns the current HTML Dialog listener or
null if it's not
registered. |
HttpSecurityHandler |
getHttpSecurityHandler()
Returns http security handler that allows processing any security
problems or
null if it's not present. |
KeyFilter |
getKeyFilter() |
java.lang.String |
getLocationURL()
Returns location of the currently loaded HTML document.
|
java.awt.Dimension |
getMinimumSize() |
java.util.List<NavigationListener> |
getNavigationListeners() |
PopupHandler |
getPopupHandler() |
java.util.List<PrintEventListener> |
getPrintEventListeners() |
ProxyConfiguration |
getProxy()
Returns proxy settings for the current Browser instance.
|
java.awt.Image |
getScreenShot(boolean wholePage)
Returns an image that represent screen shot of the page.
|
java.awt.Image |
getScreenShot(java.awt.Dimension dimension)
Returns an image that represent screen shot of the page.
|
java.util.List<ScriptErrorListener> |
getScriptErrorListeners() |
SecurityPolicyHandler |
getSecurityPolicyHandler() |
java.util.List<StatusListener> |
getStatusListeners() |
java.lang.String |
getTitle()
Returns string that represents title of the currently loaded document.
|
java.lang.String |
getUserAgent()
Returns user-agent string of the current Browser instance that was set using the
setUserAgent(String) method. |
java.util.List<WindowListener> |
getWindowListeners() |
int |
getZoomLevel()
Returns zoom level for the current Browser instance.
|
void |
goBack()
Navigates backward one item in the history list.
|
void |
goForward()
Navigates forward one item in the history list.
|
void |
goHome()
Navigates to the current home or start page.
|
static void |
invokeAndWaitLoadMainFrame(Browser browser,
Callback<Browser> callback)
Invokes
callback and waits until main frame is loaded completely blocking current thread execution. |
static void |
invokeAndWaitLoadMainFrame(Browser browser,
Callback<Browser> callback,
int timeoutInSeconds)
Invokes
callback and waits until main frame is loaded completely blocking current thread execution. |
boolean |
isDisposed()
Returns
true if current Browser instance is disposed. |
boolean |
isInternetFeatureEnabled(InternetFeature feature)
Indicates whether MS Internet Explorer feature is enabled or not.
|
boolean |
isSilent()
Indicates whether silent mode is enabled or not.
|
void |
navigate(java.lang.String url)
Navigates to an entire web resource specified by
url . |
void |
navigate(java.lang.String url,
java.lang.String postData)
Navigates to an entire web resource specified by
url . |
void |
navigate(java.lang.String url,
java.lang.String target,
java.lang.String postData)
Navigates to an entire web resource specified by
url . |
void |
navigate(java.lang.String url,
java.lang.String target,
java.lang.String postData,
java.lang.String headers)
Navigates to an entire web resource specified by
url . |
void |
navigate(java.lang.String url,
java.lang.String target,
java.lang.String postData,
java.lang.String headers,
int flags)
Navigates to an entire web resource specified by
url with HTTP
postData and additional custom headers into a specified window defined by target . |
void |
print()
Prints currently loaded web page silently with empty header and footer.
|
void |
print(boolean prompt,
java.lang.String header,
java.lang.String footer)
Prints currently loaded web page.
|
void |
refresh()
Reloads the file that is currently displayed in the object.
|
void |
registerFunction(java.lang.String functionName,
BrowserFunction function)
Registers a browser function on the currently loaded document.
|
void |
removeDisposeListener(DisposeListener listener) |
void |
removeMouseEventListener(MouseEventListener listener) |
void |
removeNavigationListener(NavigationListener listener) |
void |
removeNotify() |
void |
removePrintEventListener(PrintEventListener listener) |
void |
removeScriptErrorListener(ScriptErrorListener listener) |
void |
removeStatusListener(StatusListener listener) |
void |
removeWindowListener(WindowListener listener) |
void |
requestFocus()
Request browser focus
|
void |
setAuthenticationHandler(AuthenticationHandler authenticationHandler)
Sets a new handler for basic, digest and NTLM authentication.
|
void |
setBrowserProperties(BrowserProperties properties) |
void |
setContent(java.lang.String htmlContent)
Sets the specified HTML content to the current WebBrowser document.
|
void |
setContextMenuProvider(ContextMenuProvider contextMenuProvider) |
void |
setCookie(java.lang.String url,
Cookie... cookie)
Sets/updates cookie associated with specified
url . |
void |
setCookies(java.lang.String url,
java.util.Collection<Cookie> cookies)
Sets/updates list of cookies associated with specified
url . |
void |
setDialogHandler(DialogHandler handler) |
void |
setEventsHandler(EventsHandler handler) |
void |
setHTMLDialogListener(HTMLDialogListener listener)
Sets the specified HTML Dialog listener that allows receiving event
when the HTML Dialog is shown and its document is loaded completely.
|
void |
setHttpSecurityHandler(HttpSecurityHandler securityHandler)
Sets the specified HTTP security handler that allows processing
any security problems such as Invalid Certificate error, Invalid
Certificate Name, Invalid Certificate Date, Moving from a non-SSL
to an SSL connection because of a redirect or The redirection
requires user confirmation problems.
|
void |
setInternetFeatureEnabled(InternetFeature feature,
boolean enable)
Enables/disables MS Internet Explorer feature.
|
void |
setKeyFilter(KeyFilter keyFilter) |
void |
setPopupHandler(PopupHandler handler) |
void |
setProxy(ProxyConfiguration conf)
Updates proxy configuration for the current Browser instance.
|
void |
setSecurityPolicyHandler(SecurityPolicyHandler handler) |
void |
setSilent(boolean silent)
Enables or disables silent mode.
|
void |
setUserAgent(java.lang.String userAgent)
Configures Browser instance to use a custom
userAgent string. |
void |
setZoomLevel(int zoomLevel)
Updates zoom level for all web pages in the current Browser instance.
|
void |
stop()
Cancels any pending navigation or download operation and stops any
dynamic page elements, such as background sounds and animations.
|
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, paint, update
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
public Browser()
Browser
instance with new BrowserContext
.public Browser(BrowserContext context)
Browser
instance with specific context
.context
- associated with the Browser instance. Cannot be null
.java.lang.IllegalArgumentException
- when context
is null
.public DOMDocument getDocument()
null
if web page isn't loaded completely or
it's not HTML document.public void setAuthenticationHandler(AuthenticationHandler authenticationHandler)
authenticationHandler
- a new authentication handler. Can be null
.public HttpSecurityHandler getHttpSecurityHandler()
null
if it's not present. By default this
method always returns null
and all security problems are
processing by default Internet Explorer security handler.null
if it's not presentpublic void setHttpSecurityHandler(HttpSecurityHandler securityHandler)
securityHandler
- the specified HTTP security handler.public AuthenticationHandler getAuthenticationHandler()
null
if handler isn't installed.null
if handler isn't installed.public void addNotify()
addNotify
in class java.awt.Canvas
public void removeNotify()
removeNotify
in class java.awt.Component
public java.awt.Dimension getMinimumSize()
getMinimumSize
in class java.awt.Component
public BrowserContext getContext()
public void setProxy(ProxyConfiguration conf)
conf
- new proxy configuration.public ProxyConfiguration getProxy()
public void setInternetFeatureEnabled(InternetFeature feature, boolean enable)
feature
- to enable/disable.enable
- true
to enable feature, false
to disable.public boolean isInternetFeatureEnabled(InternetFeature feature)
feature
- MS IE feature.true
when feature is enabled, otherwise - false
.public JSValue executeScript(java.lang.String javaScript)
javaScript
code in the main frame of the currently loaded document.javaScript
- JavaScript code to execute. Cannot be null
or empty string.java.lang.IllegalArgumentException
- when javaScript
is null
or empty.public void setHTMLDialogListener(HTMLDialogListener listener)
window.showModalDialog
and window.showModelessDialog
JavaScript functions.listener
- the specified HTML Dialog listener.getHTMLDialogListener()
public HTMLDialogListener getHTMLDialogListener()
null
if it's not
registered.null
if it's not
registered.public void addPrintEventListener(PrintEventListener listener)
public void removePrintEventListener(PrintEventListener listener)
public void addMouseEventListener(MouseEventListener listener)
public void removeMouseEventListener(MouseEventListener listener)
public java.util.List<PrintEventListener> getPrintEventListeners()
public void print()
public void print(boolean prompt, java.lang.String header, java.lang.String footer)
prompt
- indicates whether printing should be silent or Print dialog should be displayed.header
- page header text.footer
- page footer text.public void navigate(java.lang.String url)
url
.
This method is executed asynchronously. To make sure that required URL is loaded completely use the
NavigationListener.mainDocumentCompleted(Browser, String)
event.url
- the URL of the resource to load and display. Cannot be null
or empty string.public void navigate(java.lang.String url, java.lang.String postData)
url
.
This method is executed asynchronously. To make sure that required URL is loaded completely use the
NavigationListener.mainDocumentCompleted(Browser, String)
event.url
- the URL of the resource to load and display. Cannot be null
or empty string.postData
- HTTP post data (for example, "name=Alex&product=Pizza").public void navigate(java.lang.String url, java.lang.String target, java.lang.String postData)
url
.
This method is executed asynchronously. To make sure that required URL is loaded completely use the
NavigationListener.mainDocumentCompleted(Browser, String)
event.url
- the URL of the resource to load and display. Cannot be null
or empty string.target
- the string that contains the name of the
frame in which to display the resource.
The possible values for this parameter are.
postData
- HTTP post data (for example, "name=Alex&product=Pizza").public void navigate(java.lang.String url, java.lang.String target, java.lang.String postData, java.lang.String headers)
url
.
This method is executed asynchronously. To make sure that required URL is loaded completely use the
NavigationListener.mainDocumentCompleted(Browser, String)
event.url
- the URL of the resource to load and display. Cannot be null
or empty string.target
- the string that contains the name of the
frame in which to display the resource.
The possible values for this parameter are.
postData
- HTTP post data (for example, "name=Alex&product=Pizza").headers
- the string that contains additional HTTP headers to send
to the server. These headers are added to the default
Windows Internet Explorer headers. For example, headers
can specify the action required of the server, the type
of data being passed to the server, or a status code.
This parameter is ignored if the URL is not an HTTP
(or HTTPS) URL.public void navigate(java.lang.String url, java.lang.String target, java.lang.String postData, java.lang.String headers, int flags)
url
with HTTP
postData
and additional custom headers
into a specified window defined by target
.
This method is executed asynchronously. To make sure that required URL is loaded completely use the
NavigationListener.mainDocumentCompleted(Browser, String)
event.url
- the URL of the resource to load and display. Cannot be null
or empty string.target
- the string that contains the name of the
frame in which to display the resource.
The possible values for this parameter are.
postData
- HTTP post data (for example, "name=Alex&product=Pizza").headers
- the string that contains additional HTTP headers to send
to the server. These headers are added to the default
Windows Internet Explorer headers. For example, headers
can specify the action required of the server, the type
of data being passed to the server, or a status code.
This parameter is ignored if the URL is not an HTTP
(or HTTPS) URL.flags
- browser navigation flag. Description of every flag can be found at
http://msdn.microsoft.com/en-us/library/aa768360(v=vs.85).aspxjava.lang.IllegalArgumentException
- when url
is null
or empty.public java.lang.String getLocationURL()
public java.lang.String getTitle()
public java.awt.Image getScreenShot(boolean wholePage)
wholePage
- if true
returns the whole page not just what is visiblepublic java.awt.Image getScreenShot(java.awt.Dimension dimension)
dimension
- - dimension of area to renderpublic void goForward()
public void goBack()
public void goHome()
public void refresh()
public void stop()
public void setContent(java.lang.String htmlContent)
htmlContent
- a string that represents HTML content
to set to the current document. Cannot be null
or empty.public java.lang.String getContent()
public java.lang.String getContent(boolean original)
original
- if true
then returns the original
HTML content (like View Source command in context
menu of Internet Explorer browser), otherwise this method
returns the actual content of a document according to its DOM.public java.util.List<ScriptErrorListener> getScriptErrorListeners()
public void addScriptErrorListener(ScriptErrorListener listener)
public void removeScriptErrorListener(ScriptErrorListener listener)
public void addWindowListener(WindowListener listener)
public void removeWindowListener(WindowListener listener)
public java.util.List<WindowListener> getWindowListeners()
public void addNavigationListener(NavigationListener listener)
public void removeNavigationListener(NavigationListener listener)
public java.util.List<NavigationListener> getNavigationListeners()
public void addStatusListener(StatusListener listener)
public java.util.List<StatusListener> getStatusListeners()
public void removeStatusListener(StatusListener listener)
public EventsHandler getEventsHandler()
public void setEventsHandler(EventsHandler handler)
public void setPopupHandler(PopupHandler handler)
public PopupHandler getPopupHandler()
public void dispose()
isDisposed()
method.public boolean isDisposed()
true
if current Browser instance is disposed. Otherwise false
.public void addDisposeListener(DisposeListener listener)
public void removeDisposeListener(DisposeListener listener)
public java.util.List<DisposeListener> getDisposeListeners()
public void setDialogHandler(DialogHandler handler)
public DialogHandler getDialogHandler()
public void setUserAgent(java.lang.String userAgent)
userAgent
string.userAgent
- the string that represents a new user-agent. Cannot be null
or empty.java.lang.IllegalArgumentException
- when userAgent
is null
or empty.public java.lang.String getUserAgent()
setUserAgent(String)
method. Returns empty string if no customer user-agent string was set.public java.lang.String getDefaultUserAgent()
public int getZoomLevel()
public void setZoomLevel(int zoomLevel)
public void requestFocus()
requestFocus
in class java.awt.Component
public void setSilent(boolean silent)
silent
- true
to enable silent mode, otherwise false
.public boolean isSilent()
true
when silent mode is enabled.public void setCookies(java.lang.String url, java.util.Collection<Cookie> cookies)
url
.url
- URL address associated with the cookies
. Cannot be null
or empty.cookies
- list of new cookies.java.lang.IllegalArgumentException
- when url
or cookies
is null
.public void setCookie(java.lang.String url, Cookie... cookie)
url
.url
- URL address associated with the cookie
. Cannot be null
or empty.cookie
- a new cookie.java.lang.IllegalArgumentException
- when url
or cookie
is null
.public java.util.List<Cookie> getCookies(java.lang.String url)
url
or empty collection is no cookies available for this URL.url
- URL address for cookies. Cannot be null
or empty.url
.public void registerFunction(java.lang.String functionName, BrowserFunction function)
functionName
. The browser
function is not available anymore if document is reloaded or other web page
is loaded.public java.lang.String getDocumentType()
public void setSecurityPolicyHandler(SecurityPolicyHandler handler)
public SecurityPolicyHandler getSecurityPolicyHandler()
public void setKeyFilter(KeyFilter keyFilter)
public KeyFilter getKeyFilter()
public ContextMenuProvider getContextMenuProvider()
public void setContextMenuProvider(ContextMenuProvider contextMenuProvider)
public static void invokeAndWaitLoadMainFrame(Browser browser, Callback<Browser> callback) throws java.util.concurrent.TimeoutException
callback
and waits until main frame is loaded completely blocking current thread execution.
If main frame document wasn't loaded within LatchUtil.WAIT_SECONDS
seconds, method throws TimeoutException
. You can
change default timeout via "jexplorer.ipc.timeout.seconds"
System Property.browser
- instance that will wait for main frame loading completion. Cannot be null
.callback
- contains task that initiates web page loading. Cannot be null
.java.lang.IllegalArgumentException
- when browser
or callback
is null
.java.util.concurrent.TimeoutException
- when main document hasn't been loaded completely by the time when operation times out.public static void invokeAndWaitLoadMainFrame(Browser browser, Callback<Browser> callback, int timeoutInSeconds) throws java.util.concurrent.TimeoutException
callback
and waits until main frame is loaded completely blocking current thread execution.
If main frame document wasn't loaded completely within timeoutInSeconds
, method throws TimeoutException
.browser
- instance that will wait for main frame loading completion. Cannot be null
.callback
- contains task that initiates web page loading. Cannot be null
.timeoutInSeconds
- contains task that initiates web page loading. Cannot be null
.java.lang.IllegalArgumentException
- when browser
or callback
is null
, or timeoutInSeconds
<= 0;java.util.concurrent.TimeoutException
- when main document hasn't been loaded completely by the time when operation times out.public void clearCache(InternetCacheEntry cacheEntry)
To clear:
InternetCacheEntry.NORMAL_CACHE_ENTRY
value.InternetCacheEntry.COOKIE_CACHE_ENTRY
value.InternetCacheEntry.URLHISTORY_CACHE_ENTRY
value.cacheEntry
- Internet cache entry type that will be cleared.public void setBrowserProperties(BrowserProperties properties)