Class WebKit


class WebKit extends WebBrowser
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.
  • 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

      private final ControlListener browserMoveListener
    • searchShellLocation

      private Point searchShellLocation
    • searchShell

      private Shell searchShell
    • searchText

      private String searchText
    • enableSearch

      boolean enableSearch
    • firstLoad

      boolean firstLoad
    • FirstCreate

      static boolean FirstCreate
    • parentBrowser

      private static Browser parentBrowser
      Stores the browser which is opening a new browser window, during a WebKit create signal. 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_MS
      Timeout 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 bug522733FirstInstanceCreated
      Workaround for bug 522733
    • w2_bug527738LastRequestCounter

      static AtomicInteger w2_bug527738LastRequestCounter
      Part of workaround in Bug 527738. Prevent old request overring newer request
    • nonBlockingEvaluate

      private static int nonBlockingEvaluate
      Webkit2: 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

      static Map<LONG,Integer> webKitDownloadStatus
    • ABOUT_BLANK

      static final String ABOUT_BLANK
      See Also:
    • CLASSNAME_EXTERNAL

      static final String CLASSNAME_EXTERNAL
      See Also:
    • FUNCTIONNAME_CALLJAVA

      static final String FUNCTIONNAME_CALLJAVA
      See Also:
    • HEADER_CONTENTTYPE

      static final String HEADER_CONTENTTYPE
      See Also:
    • MIMETYPE_FORMURLENCODED

      static final String MIMETYPE_FORMURLENCODED
      See Also:
    • OBJECTNAME_EXTERNAL

      static final String OBJECTNAME_EXTERNAL
      See Also:
    • PROPERTY_LENGTH

      static final String PROPERTY_LENGTH
      See Also:
    • PROPERTY_PROXYHOST

      static final String PROPERTY_PROXYHOST
      See Also:
    • PROPERTY_PROXYPORT

      static final String PROPERTY_PROXYPORT
      See Also:
    • PROTOCOL_FILE

      static final String PROTOCOL_FILE
      See Also:
    • PROTOCOL_HTTP

      static final String PROTOCOL_HTTP
      See Also:
    • URI_FILEROOT

      static final String URI_FILEROOT
      See Also:
    • USER_AGENT

      static final String 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

      static final String DOMEVENT_DRAGSTART
      See Also:
    • DOMEVENT_KEYDOWN

      static final String DOMEVENT_KEYDOWN
      See Also:
    • DOMEVENT_KEYPRESS

      static final String DOMEVENT_KEYPRESS
      See Also:
    • DOMEVENT_KEYUP

      static final String DOMEVENT_KEYUP
      See Also:
    • DOMEVENT_MOUSEDOWN

      static final String DOMEVENT_MOUSEDOWN
      See Also:
    • DOMEVENT_MOUSEUP

      static final String DOMEVENT_MOUSEUP
      See Also:
    • DOMEVENT_MOUSEMOVE

      static final String DOMEVENT_MOUSEMOVE
      See Also:
    • DOMEVENT_MOUSEOUT

      static final String DOMEVENT_MOUSEOUT
      See Also:
    • DOMEVENT_MOUSEOVER

      static final String DOMEVENT_MOUSEOVER
      See Also:
    • DOMEVENT_MOUSEWHEEL

      static final String 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

      static final String KEY_CHECK_SUBWINDOW
      See Also:
    • SWT_WEBKITGTK_VERSION

      static final String SWT_WEBKITGTK_VERSION
      See Also:
    • Proc2

      static Callback Proc2
    • Proc3

      static Callback Proc3
    • Proc4

      static Callback Proc4
    • Proc5

      static Callback Proc5
    • JSDOMEventProc

      static Callback JSDOMEventProc
    • RequestProc

      static Callback RequestProc
    • ignoreTls

      static final boolean ignoreTls
      Flag indicating whether TLS errors (like self-signed certificates) are to be ignored.
    • disableBrowserSearchGlobally

      static final boolean disableBrowserSearchGlobally
      Flag that disables browser searching added on top of the WebKit browser.
  • Constructor Details

    • WebKit

      WebKit()
  • Method Details

    • createFunction

      public void createFunction(BrowserFunction function)
      Overrides:
      createFunction in class WebBrowser
    • destroyFunction

      public void destroyFunction(BrowserFunction function)
      Overrides:
      destroyFunction in class WebBrowser
    • updateUserScript

      void updateUserScript()
    • getInternalErrorMsg

      private static String getInternalErrorMsg()
    • getStackTrace

      private static String getStackTrace()
    • getJavaCallDeclaration

      String getJavaCallDeclaration()
      Description copied from class: WebBrowser
      Designed to be overridden.
      Overrides:
      getJavaCallDeclaration in class WebBrowser
      Returns:
      javaScript code that defines the 'callJava' syntax for javascript.
    • internalGetWebkitVersion

      private static int[] internalGetWebkitVersion()
      Gets the webkit version, within an int[3] array with {major, minor, micro} version
    • internalGetWebKitVersionStr

      private static String internalGetWebKitVersionStr()
    • getString

      static String getString(long strPtr)
    • FindBrowser

      static Browser FindBrowser(long webView)
    • 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

      public void create(Composite parent, int style)
      Specified by:
      create in class WebBrowser
    • back

      public boolean back()
      Specified by:
      back in class WebBrowser
    • close

      public boolean close()
      Overrides:
      close in class WebBrowser
    • close

      boolean close(boolean showPrompters)
    • isJavascriptEnabled

      private boolean isJavascriptEnabled()
    • nonBlockingExecute

      void nonBlockingExecute(String script)
      Overrides:
      nonBlockingExecute in class WebBrowser
    • execute

      public boolean execute(String script)
      Specified by:
      execute in class WebBrowser
    • evaluate

      public Object evaluate(String script) throws SWTException
      Overrides:
      evaluate in class WebBrowser
      Throws:
      SWTException
    • forward

      public boolean forward()
      Specified by:
      forward in class WebBrowser
    • getBrowserType

      public String getBrowserType()
      Specified by:
      getBrowserType in class WebBrowser
    • getText

      public String getText()
      Specified by:
      getText in class WebBrowser
    • getUrl

      public String getUrl()
      Specified by:
      getUrl in class WebBrowser
    • handleDOMEvent

      boolean handleDOMEvent(long event, int type)
    • handleEventFromFunction

      boolean handleEventFromFunction(Object[] arguments)
    • 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:
      isBackEnabled in class WebBrowser
    • isForwardEnabled

      public boolean isForwardEnabled()
      Specified by:
      isForwardEnabled in class WebBrowser
    • onDispose

      void onDispose(Event e)
    • onResize

      void onResize(Event e)
    • openDownloadWindow

      void openDownloadWindow(long webkitDownload, String suggested_filename)
    • refresh

      public void refresh()
      Specified by:
      refresh in class WebBrowser
    • setText

      public boolean setText(String html, boolean trusted)
      Specified by:
      setText in class WebBrowser
    • setUrl

      public boolean setUrl(String url, String postData, String[] headers)
      Specified by:
      setUrl in class WebBrowser
    • stop

      public void stop()
      Specified by:
      stop in class WebBrowser
    • 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.
    • webkit_context_menu

      long webkit_context_menu(long web_view, long context_menu, long eventXXX, long hit_test_result)
    • addRequestHeaders

      private void addRequestHeaders(long requestHeaders, String[] headers)
    • 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

      private void browserShellMoved(ControlEvent e)
    • closeSearchDialog

      private void closeSearchDialog()
    • openSearchDialog

      private void openSearchDialog()
    • search

      private void search(long findController, Supplier<String> currentText, Consumer<Long> incrementSearch)
    • gtk4_convertToJava

      static Object gtk4_convertToJava(long jsc_value)
    • gtk3_convertToJava

      static Object gtk3_convertToJava(long ctx, long value)