Class WebKit
java.lang.Object
org.eclipse.swt.browser.WebBrowser
org.eclipse.swt.browser.WebKit
VERSIONS:
Versioning for webkit is somewhat confusing because it's trying to incorporate webkit, gtk and (various linux distribution) versions.
The way they version webkitGTK is different from webkit.
WebkitGTK:
2.5 is webkit2. [2.4-..) is Gtk3.
Further, linux distributions might refer to webkit2 bindings linked against gtk3 differently.
E.g on Fedora:
webkitgtk4 = webkit2 / Gtk3
webkit2gtk3 = WebKit2/ Gtk3
Webkit2 loading:
- Dynamic bindings are auto generated and linked when the @dynamic keyword is used in WebKitGTK.java
Unlike in OS.java, you don't have to add any code saying what lib the dynamic method is linked to. It's auto-linked to webkit lib by default.
- At no point should you have hard-compiled code, because this will cause crashes on older machines without webkit2.
(the exception is the webextension, because it runs as a separate process and is only loaded dynamically).
- Try to keep all of your logic in Java and avoid writing custom C-code. (I went down this pit). Because if you
use native code, then you have to write dynamic native code (get function pointers, cast types etc.. big pain in the ass).
- Don't try to add webkit2 include flags to pkg-config, as this will tie the swt-glue code to specific webkit versions. Thou shall not do this.
EVENT_HANDLING_DOC:
- On webkit2, signals are implemented via regular gtk mechanism, hook events and pass them along as we receive them.
I haven't found a need to use the dom events, because webkitgtk seems to adequately meet the requirements via regular gtk
events, but maybe I missed something? Who knows.
setUrl(..) with 'post data' was implemented in a very hacky way, via native Java due to missing webkit2gtk api.
It's the best that could be done at the time, but it could result in strange behavior like some webpages loading in funky ways if post-data is used.
Some good resources that I found are as following:
- Webkit2 reference: https://webkitgtk.org/reference/webkit2gtk/stable/
- To understand GDBus, consider reading this guide:
http://www.cs.grinnell.edu/~rebelsky/Courses/CSC195/2013S/Outlines/
And then see the relevant reference I made in WebkitGDBus.java.
Note, DBus is not the same as GDBus. GDBus is an implementation of the DBus protocol (with it's own quirks).
- This is a good starting point for webkit2 extension reading:
https://blogs.igalia.com/carlosgc/2013/09/10/webkit2gtk-web-process-extensions/
[April 2018]
Note on WebKitContext:
We only use a single webcontext, so WebKitGTK.webkit_web_context_get_default() works well for getting this when
needed.
~May the force be with you.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classWebkit2 introduces async api.Nested classes/interfaces inherited from class WebBrowser
WebBrowser.EvaluateFunction -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final String(package private) static final intTimeout used for javascript execution / deadlock detection.(package private) static final intprivate final ControlListener(package private) static booleanWorkaround for bug 522733(package private) static final String(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final booleanFlag that disables browser searching added on top of the WebKit browser.(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final int(package private) boolean(package private) static final int(package private) int(package private) static final int(package private) static boolean(package private) boolean(package private) static final String(package private) static final String(package private) boolean(package private) static final booleanFlag indicating whether TLS errors (like self-signed certificates) are to be ignored.(package private) static Callback(package private) static final byte[](package private) static final String(package private) int(package private) int(package private) static final int(package private) static final int(package private) static final int(package private) static final int(package private) static final String(package private) static final int[](package private) static final intprivate static intWebkit2: In a few situations, evaluate() should not wait for it's asynchronous callback to finish.(package private) static final int(package private) static final int(package private) static final String(package private) longprivate static BrowserStores the browser which is opening a new browser window, during a WebKitcreatesignal.(package private) static Callback(package private) static Callback(package private) static Callback(package private) static Callback(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static final String(package private) static Callbackprivate Shellprivate Pointprivate String(package private) static final int(package private) static final char(package private) static final int(package private) static final byte[](package private) static final String(package private) boolean(package private) long(package private) String(package private) URI(package private) String(package private) static final String(package private) static final String(package private) static AtomicIntegerPart of workaround in Bug 527738.(package private) static final int(package private) long(package private) static final intFields inherited from class WebBrowser
authenticationListeners, browser, closeWindowListeners, CookieName, CookieResult, CookieUrl, CookieValue, ERROR_ID, evaluateResult, EXECUTE_ID, functions, jsEnabled, jsEnabledOnNextPage, KeyTable, locationListeners, NativeClearSessions, NativeGetCookie, NativePendingCookies, NativeSetCookie, nextFunctionIndex, openWindowListeners, progressListeners, statusTextListeners, titleListeners, visibilityWindowListeners -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddRequestHeaders(long requestHeaders, String[] headers) booleanback()private voidbooleanclose()(package private) booleanclose(boolean showPrompters) private void(package private) voidconvertUri(long webkitUri) Converts a WebKit URI into a Java URI object.voidvoidcreateFunction(BrowserFunction function) voiddestroyFunction(BrowserFunction function) boolean(package private) static BrowserFindBrowser(long webView) private voidThis method is reached by: Webkit2: WebKitWebView load-changed signal - void user_function (WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer user_data) - https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView-load-changed - Note: As there is no return value, safe to fire asynchronously.booleanforward()private static String(package private) StringDesigned to be overridden.private static String(package private) static StringgetString(long strPtr) getText()getUrl()(package private) static Objectgtk3_convertToJava(long ctx, long value) (package private) static Objectgtk4_convertToJava(long jsc_value) (package private) booleanhandleDOMEvent(long event, int type) (package private) booleanhandleEventFromFunction(Object[] arguments) (package private) booleanhandleKeyEvent(String type, int keyCode, int charCode, boolean altKey, boolean ctrlKey, boolean shiftKey, boolean metaKey) (package private) longhandleLoadCommitted(long uri, boolean top) (package private) booleanhandleMouseEvent(String type, int screenX, int screenY, int detail, int button, boolean altKey, boolean ctrlKey, boolean shiftKey, boolean metaKey, boolean hasRelatedTarget) private static int[]Gets the webkit version, within anint[3]array with{major, minor, micro}versionprivate static Stringbooleanboolean(package private) static booleanprivate boolean(package private) static longJSDOMEventProc(long arg0, long event, long user_data) (package private) voidnonBlockingExecute(String script) (package private) void(package private) void(package private) voidopenDownloadWindow(long webkitDownload, String suggested_filename) private void(package private) static longProc(long handle, long user_data) (package private) static longProc(long handle, long arg0, long user_data) (package private) static longProc(long handle, long arg0, long arg1, long user_data) (package private) static longProc(long handle, long arg0, long arg1, long arg2, long user_data) voidrefresh()(package private) static longRequestProc(long request, long user_data) private voidbooleanbooleanvoidstop()(package private) void(package private) longwebkit_authenticate(long web_view, long request) gboolean user_function (WebKitWebView *web_view, WebKitAuthenticationRequest *request, gpointer user_data) - https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView-authenticate(package private) longwebkit_close_web_view(long web_view) WebKitWebView 'close' signal void user_function (WebKitWebView *web_view, gpointer user_data); // observe *no* return value.(package private) longwebkit_context_menu(long web_view, long context_menu, long eventXXX, long hit_test_result) (package private) longwebkit_create_web_view(long web_view, long frame) (package private) longwebkit_decide_policy(long web_view, long decision, int decision_type, long user_data) (package private) static longwebkit_download_decide_destination(long webKitDownload, long suggested_filename) (package private) static longwebkit_download_failed(long download) (package private) static longwebkit_download_finished(long download) (package private) static longwebkit_download_started(long webKitDownload) (package private) longwebkit_hovering_over_link(long web_view, long title, long uri) Webkit2: WebkitWebView mouse-target-change - Normally this signal is called for many different events, e.g hoveing over an image.(package private) longwebkit_load_changed(long web_view, int status, long user_data) (package private) longwebkit_load_failed_tls(long web_view, long failing_uri, long certificate, long error) Called in cases where a web page failed to load due to TLS errors (self-signed certificates, as an example).(package private) longwebkit_mouse_target_changed(long web_view, long hit_test_result, long modifiers) WebkitWebView mouse-target-changed - void user_function (WebKitWebView *web_view, WebKitHitTestResult *hit_test_result, guint modifiers, gpointer user_data) - https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView-mouse-target-changed(package private) longwebkit_notify_progress(long web_view, long pspec) Triggered by a change in property.(package private) longwebkit_notify_title(long web_view, long pspec) Triggerd by webkit's 'notify::title' signal and forwarded to this function.private intwebkit_settings_get(byte[] property) private intwebkit_settings_get(long settings, byte[] property) private voidwebkit_settings_set(byte[] property, int value) (package private) longwebkit_web_view_ready(long web_view) Emitted after "create" on the newly created WebKitWebView when it should be displayed to the user.(package private) longwebViewProc(long handle, long user_data) (package private) longwebViewProc(long handle, long arg0, long user_data) (package private) longwebViewProc(long handle, long arg0, long arg1, long user_data) (package private) longwebViewProc(long handle, long arg0, long arg1, long arg2, long user_data) Methods inherited from class WebBrowser
addAuthenticationListener, addCloseWindowListener, addLocationListener, addOpenWindowListener, addProgressListener, addStatusTextListener, addTitleListener, addVisibilityWindowListener, clearSessions, CreateErrorString, deregisterFunction, evaluate, ExtractError, GetCookie, getDeleteFunctionString, getNextFunctionIndex, getWebBrowser, isFocusControl, registerFunction, removeAuthenticationListener, removeCloseWindowListener, removeLocationListener, removeOpenWindowListener, removeProgressListener, removeStatusTextListener, removeTitleListener, removeVisibilityWindowListener, sendKeyEvent, setBrowser, SetCookie, SetPendingCookies, translateKey, translateMnemonics
-
Field Details
-
webView
long webView -
pageId
long pageId -
failureCount
int failureCount -
lastKeyCode
int lastKeyCode -
lastCharCode
int lastCharCode -
ignoreDispose
boolean ignoreDispose -
tlsError
boolean tlsError -
tlsErrorCertificate
long tlsErrorCertificate -
tlsErrorUriString
String tlsErrorUriString -
tlsErrorUri
URI tlsErrorUri -
tlsErrorType
String tlsErrorType -
browserMoveListener
-
searchShellLocation
-
searchShell
-
searchText
-
enableSearch
boolean enableSearch -
firstLoad
boolean firstLoad -
FirstCreate
static boolean FirstCreate -
parentBrowser
Stores the browser which is opening a new browser window, during a WebKitcreatesignal. This browser must be passed to a newly created browser as "related". See bug 579257. -
ASYNC_EXEC_TIMEOUT_MS
static final int ASYNC_EXEC_TIMEOUT_MSTimeout used for javascript execution / deadlock detection. Loosely based on the 10s limit commonly found in browsers. (Except for SWT browser we use 3s as chunks of the UI is blocked). https://www.nczonline.net/blog/2009/01/05/what-determines-that-a-script-is-long-running/ https://stackoverflow.com/questions/3030024/maximum-execution-time-for-javascript- See Also:
-
bug522733FirstInstanceCreated
static boolean bug522733FirstInstanceCreatedWorkaround for bug 522733 -
w2_bug527738LastRequestCounter
Part of workaround in Bug 527738. Prevent old request overring newer request -
nonBlockingEvaluate
private static int nonBlockingEvaluateWebkit2: In a few situations, evaluate() should not wait for it's asynchronous callback to finish. This is to avoid deadlocks, see Bug 512001.
0 means evaluate should wait for callback.
>0 means evaluate should not block. In this case 'null' is returned. This condition is rare.
Note: This has to be *static*. Webkit2 seems to share one event queue, as such two webkit2 instances can interfere with each other. An example of this interfering is when you open a link in a javadoc hover. The new webkit2 in the new tab interferes with the old instance in the hoverbox. As such, any locks should apply to all webkit2 instances.
-
webKitDownloadStatus
-
ABOUT_BLANK
- See Also:
-
CLASSNAME_EXTERNAL
- See Also:
-
FUNCTIONNAME_CALLJAVA
- See Also:
-
HEADER_CONTENTTYPE
- See Also:
-
MIMETYPE_FORMURLENCODED
- See Also:
-
OBJECTNAME_EXTERNAL
- See Also:
-
PROPERTY_LENGTH
- See Also:
-
PROPERTY_PROXYHOST
- See Also:
-
PROPERTY_PROXYPORT
- See Also:
-
PROTOCOL_FILE
- See Also:
-
PROTOCOL_HTTP
- See Also:
-
URI_FILEROOT
- See Also:
-
USER_AGENT
- See Also:
-
MAX_PORT
static final int MAX_PORT- See Also:
-
MAX_PROGRESS
static final int MAX_PROGRESS- See Also:
-
MIN_VERSION
static final int[] MIN_VERSION -
SENTINEL_KEYPRESS
static final int SENTINEL_KEYPRESS- See Also:
-
SEPARATOR_FILE
static final char SEPARATOR_FILE -
STOP_PROPOGATE
static final int STOP_PROPOGATE- See Also:
-
DOMEVENT_DRAGSTART
- See Also:
-
DOMEVENT_KEYDOWN
- See Also:
-
DOMEVENT_KEYPRESS
- See Also:
-
DOMEVENT_KEYUP
- See Also:
-
DOMEVENT_MOUSEDOWN
- See Also:
-
DOMEVENT_MOUSEUP
- See Also:
-
DOMEVENT_MOUSEMOVE
- See Also:
-
DOMEVENT_MOUSEOUT
- See Also:
-
DOMEVENT_MOUSEOVER
- See Also:
-
DOMEVENT_MOUSEWHEEL
- See Also:
-
SWT_PROTOCOL
static final byte[] SWT_PROTOCOL -
JSON_MIME_TYPE
static final byte[] JSON_MIME_TYPE -
NOTIFY_PROGRESS
static final int NOTIFY_PROGRESS- See Also:
-
NOTIFY_TITLE
static final int NOTIFY_TITLE- See Also:
-
CREATE_WEB_VIEW
static final int CREATE_WEB_VIEW- See Also:
-
WEB_VIEW_READY
static final int WEB_VIEW_READY- See Also:
-
CLOSE_WEB_VIEW
static final int CLOSE_WEB_VIEW- See Also:
-
LOAD_CHANGED
static final int LOAD_CHANGED- See Also:
-
DECIDE_POLICY
static final int DECIDE_POLICY- See Also:
-
MOUSE_TARGET_CHANGED
static final int MOUSE_TARGET_CHANGED- See Also:
-
CONTEXT_MENU
static final int CONTEXT_MENU- See Also:
-
AUTHENTICATE
static final int AUTHENTICATE- See Also:
-
DECIDE_DESTINATION
static final int DECIDE_DESTINATION- See Also:
-
FAILED
static final int FAILED- See Also:
-
FINISHED
static final int FINISHED- See Also:
-
DOWNLOAD_STARTED
static final int DOWNLOAD_STARTED- See Also:
-
WIDGET_EVENT
static final int WIDGET_EVENT- See Also:
-
LOAD_FAILED_TLS
static final int LOAD_FAILED_TLS- See Also:
-
KEY_CHECK_SUBWINDOW
- See Also:
-
SWT_WEBKITGTK_VERSION
- See Also:
-
Proc2
-
Proc3
-
Proc4
-
Proc5
-
JSDOMEventProc
-
RequestProc
-
ignoreTls
static final boolean ignoreTlsFlag indicating whether TLS errors (like self-signed certificates) are to be ignored. -
disableBrowserSearchGlobally
static final boolean disableBrowserSearchGloballyFlag that disables browser searching added on top of the WebKit browser.
-
-
Constructor Details
-
WebKit
WebKit()
-
-
Method Details
-
createFunction
- Overrides:
createFunctionin classWebBrowser
-
destroyFunction
- Overrides:
destroyFunctionin classWebBrowser
-
updateUserScript
void updateUserScript() -
getInternalErrorMsg
-
getStackTrace
-
getJavaCallDeclaration
String getJavaCallDeclaration()Description copied from class:WebBrowserDesigned to be overridden.- Overrides:
getJavaCallDeclarationin classWebBrowser- Returns:
- javaScript code that defines the 'callJava' syntax for javascript.
-
internalGetWebkitVersion
private static int[] internalGetWebkitVersion()Gets the webkit version, within anint[3]array with{major, minor, micro}version -
internalGetWebKitVersionStr
-
getString
-
FindBrowser
-
IsInstalled
static boolean IsInstalled() -
JSDOMEventProc
static long JSDOMEventProc(long arg0, long event, long user_data) -
RequestProc
static long RequestProc(long request, long user_data) -
Proc
static long Proc(long handle, long user_data) -
Proc
static long Proc(long handle, long arg0, long user_data) -
Proc
static long Proc(long handle, long arg0, long arg1, long user_data) -
Proc
static long Proc(long handle, long arg0, long arg1, long arg2, long user_data) -
webkit_authenticate
long webkit_authenticate(long web_view, long request) gboolean user_function (WebKitWebView *web_view, WebKitAuthenticationRequest *request, gpointer user_data) - https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView-authenticate -
webViewProc
long webViewProc(long handle, long user_data) -
webViewProc
long webViewProc(long handle, long arg0, long user_data) -
webViewProc
long webViewProc(long handle, long arg0, long arg1, long user_data) -
webViewProc
long webViewProc(long handle, long arg0, long arg1, long arg2, long user_data) -
create
- Specified by:
createin classWebBrowser
-
back
public boolean back()- Specified by:
backin classWebBrowser
-
close
public boolean close()- Overrides:
closein classWebBrowser
-
close
boolean close(boolean showPrompters) -
isJavascriptEnabled
private boolean isJavascriptEnabled() -
nonBlockingExecute
- Overrides:
nonBlockingExecutein classWebBrowser
-
execute
- Specified by:
executein classWebBrowser
-
evaluate
- Overrides:
evaluatein classWebBrowser- Throws:
SWTException
-
forward
public boolean forward()- Specified by:
forwardin classWebBrowser
-
getBrowserType
- Specified by:
getBrowserTypein classWebBrowser
-
getText
- Specified by:
getTextin classWebBrowser
-
getUrl
- Specified by:
getUrlin classWebBrowser
-
handleDOMEvent
boolean handleDOMEvent(long event, int type) -
handleEventFromFunction
-
handleKeyEvent
boolean handleKeyEvent(String type, int keyCode, int charCode, boolean altKey, boolean ctrlKey, boolean shiftKey, boolean metaKey) -
handleMouseEvent
boolean handleMouseEvent(String type, int screenX, int screenY, int detail, int button, boolean altKey, boolean ctrlKey, boolean shiftKey, boolean metaKey, boolean hasRelatedTarget) -
handleLoadCommitted
long handleLoadCommitted(long uri, boolean top) -
fireProgressCompletedEvent
private void fireProgressCompletedEvent()This method is reached by: Webkit2: WebKitWebView load-changed signal - void user_function (WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer user_data) - https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView-load-changed - Note: As there is no return value, safe to fire asynchronously. -
isBackEnabled
public boolean isBackEnabled()- Specified by:
isBackEnabledin classWebBrowser
-
isForwardEnabled
public boolean isForwardEnabled()- Specified by:
isForwardEnabledin classWebBrowser
-
onDispose
-
onResize
-
openDownloadWindow
-
refresh
public void refresh()- Specified by:
refreshin classWebBrowser
-
setText
- Specified by:
setTextin classWebBrowser
-
setUrl
- Specified by:
setUrlin classWebBrowser
-
stop
public void stop()- Specified by:
stopin classWebBrowser
-
webkit_close_web_view
long webkit_close_web_view(long web_view) WebKitWebView 'close' signal void user_function (WebKitWebView *web_view, gpointer user_data); // observe *no* return value. https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView-close -
webkit_create_web_view
long webkit_create_web_view(long web_view, long frame) -
webkit_download_started
static long webkit_download_started(long webKitDownload) -
webkit_download_decide_destination
static long webkit_download_decide_destination(long webKitDownload, long suggested_filename) -
webkit_download_finished
static long webkit_download_finished(long download) -
webkit_download_failed
static long webkit_download_failed(long download) -
webkit_mouse_target_changed
long webkit_mouse_target_changed(long web_view, long hit_test_result, long modifiers) WebkitWebView mouse-target-changed - void user_function (WebKitWebView *web_view, WebKitHitTestResult *hit_test_result, guint modifiers, gpointer user_data) - https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView-mouse-target-changed -
webkit_hovering_over_link
long webkit_hovering_over_link(long web_view, long title, long uri) Webkit2: WebkitWebView mouse-target-change - Normally this signal is called for many different events, e.g hoveing over an image. But in our case, in webkit_mouse_target_changed() we filter out everything except mouse_over_link events. Since there is no return value, it is safe to run asynchronously. -
webkit_decide_policy
long webkit_decide_policy(long web_view, long decision, int decision_type, long user_data) -
webkit_load_changed
long webkit_load_changed(long web_view, int status, long user_data) -
webkit_load_failed_tls
long webkit_load_failed_tls(long web_view, long failing_uri, long certificate, long error) Called in cases where a web page failed to load due to TLS errors (self-signed certificates, as an example). -
convertUri
void convertUri(long webkitUri) Converts a WebKit URI into a Java URI object.- Parameters:
webkitUri- a long pointing to the URI in C string form (gchar *)- Throws:
URISyntaxException- if the string violates RFC 2396, or is otherwise malformed
-
webkit_notify_progress
long webkit_notify_progress(long web_view, long pspec) Triggered by a change in property. (both gdouble[0,1]) Webkit2: WebkitWebview notify::estimated-load-progress https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitWebView--estimated-load-progress No return value required. Thus safe to run asynchronously. -
webkit_notify_title
long webkit_notify_title(long web_view, long pspec) Triggerd by webkit's 'notify::title' signal and forwarded to this function. The signal doesn't have documentation (2.15.4), but is mentioned here: https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-title It doesn't look it would require a return value, so running in asyncExec should be fine. -
addRequestHeaders
-
webkit_web_view_ready
long webkit_web_view_ready(long web_view) Emitted after "create" on the newly created WebKitWebView when it should be displayed to the user. Webkit2 signal: ready-to-show https://webkitgtk.org/reference/webkitgtk/unstable/webkitgtk-webkitwebview.html#WebKitWebView-web-view-ready Note in webkit2, no return value has to be provided in callback. -
webkit_settings_get
private int webkit_settings_get(byte[] property) - Returns:
- An integer value for the property is returned. For boolean settings, 0 indicates false, 1 indicates true. -1= is error.
-
webkit_settings_get
private int webkit_settings_get(long settings, byte[] property) - Returns:
- An integer value for the property is returned. For boolean settings, 0 indicates false, 1 indicates true
-
webkit_settings_set
private void webkit_settings_set(byte[] property, int value) -
browserShellMoved
-
closeSearchDialog
private void closeSearchDialog() -
openSearchDialog
private void openSearchDialog() -
search
-
gtk4_convertToJava
-
gtk3_convertToJava
-