diff options
| author | Leo Ufimtsev | 2017-12-07 18:04:45 +0000 |
|---|---|---|
| committer | Leo Ufimtsev | 2017-12-08 17:21:24 +0000 |
| commit | 9c55d07591d154b42f50854c7654c7e856ae1587 (patch) | |
| tree | b5bdcb8febb877136dfeed9b7df733ee1b2c88cc | |
| parent | 030ee71ec27f982f9ba71e0d0dea2d156f592939 (diff) | |
| download | eclipse.platform.swt-9c55d07591d154b42f50854c7654c7e856ae1587.tar.gz eclipse.platform.swt-9c55d07591d154b42f50854c7654c7e856ae1587.tar.xz eclipse.platform.swt-9c55d07591d154b42f50854c7654c7e856ae1587.zip | |
Bug 510905 [GTK3][Webkit2] Implement webkit2 support for browser
function (Part 2: Java return a value from callback.)
OSGI Logic:
Adding logic to allow webextension & it's directory to be extracted
via OSGI mechanism.
Tested by building swt.jar and injecting it into a local eclipse.
Need to verify after new eclipse is build.
Change-Id: I492b8d8f787e7752faf91d02a69d6b518fa77cc6
Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
3 files changed, 41 insertions, 10 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java b/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java index e7303b0b1c..cec17b15bf 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common_j2se/org/eclipse/swt/internal/Library.java @@ -11,6 +11,7 @@ package org.eclipse.swt.internal; import java.io.*; +import java.lang.reflect.*; import java.net.*; import java.util.function.*; import java.util.jar.*; @@ -366,12 +367,16 @@ private static boolean SWT_WEBKIT_DEBUG_MSGS = System.getenv("SWT_WEBKIT_DEBUG_M * Locates a resource located either in java library path, swt library path, or attempts to extract it from inside swt.jar file. * This function supports a single level subfolder, e.g SubFolder/resource. * + * Dev note: (17·12·07) This has been developed and throughly tested on GTK. Designed to work on Cocoa/Win as well, but not tested. + * * @param subDir 'null' or a folder name without slashes. E.g Correct: 'mysubdir', incorrect: '/subdir/'. * Platform specific Slashes will be added automatically. * @param resourceName e.g swt-webkitgtk * @param mapResourceName true if you like platform specific mapping applied to resource name. e.g MyLib -> libMyLib-gtk-4826.so */ public static File findResource(String subDir, String resourceName, boolean mapResourceName){ + + //We construct a 'maybe' subdirectory path. 'Maybe' because if no subDir given, then it's an empty string "". // subdir e.g: subdir String maybeSubDirPath = subDir != null ? subDir + SEPARATOR : ""; // e.g: subdir/ or "" String maybeSubDirPathWithPrefix = subDir != null ? SEPARATOR + maybeSubDirPath : ""; // e.g: /subdir/ or "" @@ -383,7 +388,6 @@ public static File findResource(String subDir, String resourceName, boolean mapR // This code commonly finds the resource if the swt project is a required project and the swt binary (for your platform) // project is open in your workplace (found in the JAVA_LIBRARY_PATH) or if you're explicitly specified SWT_LIBRARY_PATH. { - Function<String, File> lookForFileInPath = searchPath -> { String classpath = System.getProperty(searchPath); if (classpath != null){ @@ -406,9 +410,32 @@ public static File findResource(String subDir, String resourceName, boolean mapR } } + // 2) If SWT is ran as OSGI bundle (e.g inside Eclipse), then local resources are extracted to + // eclipse/configuration/org.eclipse.osgi/NN/N/.cp/<resource> and we're given a pointer to the file. + { + if (SWT_WEBKIT_DEBUG_MSGS) System.out.println("SWT_WEBKIT: findResource is attempting to find resource from OSGI Bundle."); // Temp, will be removed. Bug 510905 + + // If this is an OSGI bundle look for the resource using getResource + URL url = Library.class.getClassLoader().getResource(maybeSubDirPathWithPrefix + finalResourceName); + URLConnection connection; + try { + connection = url.openConnection(); + Method getFileURLMethod = connection.getClass().getMethod("getFileURL"); + if (getFileURLMethod != null){ + // This method does the actual extraction of file to: ../eclipse/configuration/org.eclipse.osgi/NN/N/.cp/<SubDir>/resource.ext + URL result = (URL) getFileURLMethod.invoke(connection); + File returnedFile = new File(result.toURI()); + if (SWT_WEBKIT_DEBUG_MSGS) System.out.println("SWT_WEBKIT: OSGI found resource in: " + returnedFile.getAbsolutePath()); + return returnedFile; + } + } catch (Exception e) { + // If any exceptions are thrown the resource cannot be located this way. + } + } + if (SWT_WEBKIT_DEBUG_MSGS) System.out.println("SWT_WEBKIT: findResource didn't find file in paths. Will attempt to extract."); // Temp, will be removed. Bug 510905 - // 2) Need to try to pull the resource out of the swt.jar. + // 3) Need to try to pull the resource out of the swt.jar. // Look for the resource in the user's home directory, (if already extracted in the temp swt folder. (~/.swt/lib...) // Extract from the swt.jar if not there already. { diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java index 755c797d71..11a3a1d326 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java +++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java @@ -62,7 +62,7 @@ class WebKit extends WebBrowser { + "&data=&defined_groups=1&dependson=&description=&flag_type-1=X&flag_type-11=X&flag_type-12=X&flag_type-13=X&flag_type-14=X" + "&flag_type-15=X&flag_type-16=X&flag_type-2=X&flag_type-4=X&flag_type-6=X&flag_type-7=X&flag_type-8=X&form_name=enter_bug" + "&keywords=&maketemplate=Remember%20values%20as%20bookmarkable%20template&op_sys=Linux&product=Platform&qa_contact=" - + "&rep_platform=PC&requestee_type-1=&requestee_type-2=&short_desc=[webkit2]BrowserProblem"; + + "&rep_platform=PC&requestee_type-1=&requestee_type-2=&short_desc=webkit2_BrowserProblem"; static boolean bug522733FirstInstanceCreated = false; //Webkit2 workaround for Bug 522733 @@ -397,19 +397,24 @@ class WebKit extends WebBrowser { // Webkit extensions should be in their own directory. String swtVersion = Library.getVersionString(); if (WebKitGTK.SWT_WEBKIT_DEBUG_MSGS) System.out.println("SWT_WEBKIT: Webkit dir is:" + "webkitextensions" + swtVersion); - File extension = Library.findResource("webkitextensions" + swtVersion ,"swt-webkit2extension", true); - if (extension == null){ + File extension; + try { + extension = Library.findResource("webkitextensions" + swtVersion ,"swt-webkit2extension", true); + if (extension == null){ + throw new UnsatisfiedLinkError("SWT Webkit could not find it's webextension"); + } + } catch (UnsatisfiedLinkError e) { System.err.println("SWT Webkit.java Error: Could not find webkit extension. BrowserFunction functionality will not be available. \n" - + "(swt version: " + swtVersion + ")"); + + "(swt version: " + swtVersion + ")" + WebKitGTK.swtWebkitGlueCodeVersion + WebKitGTK.swtWebkitGlueCodeVersionInfo); int [] vers = internalGetWebkitVersion(); System.err.println(String.format("WebKit2Gtk version %s.%s.%s", vers[0], vers[1], vers[2])); System.err.println(reportErrMsg); loadFailed = true; return; } + if (WebKitGTK.SWT_WEBKIT_DEBUG_MSGS && extension != null) System.out.println(" SWT_WEBKIT: Found extension in: " + extension.getAbsolutePath()); String extensionsFolder = extension.getParent(); - /* Dev note: * As per * - WebkitSrc: WebKitExtensionManager.cpp, @@ -421,7 +426,6 @@ class WebKit extends WebBrowser { WebKitGTK.webkit_web_context_set_web_extensions_directory(WebKitGTK.webkit_web_context_get_default(), Converter.wcsToMbcs (extensionsFolder, true)); long /*int*/ gvariantUserData = WebKitGTK.g_variant_new_int32(uniqueID); WebKitGTK.webkit_web_context_set_web_extensions_initialization_user_data(WebKitGTK.webkit_web_context_get_default(), gvariantUserData); - } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java index a7bb1ad384..f297f68d52 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java +++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java @@ -29,8 +29,8 @@ public class WebKitGTK extends C { * Internal version of "Webkit glue code", used mainly during webkit2 port. * Used to make it easier to support users on bugzilla. Updated by hand. */ - private static final String swtWebkitGlueCodeVersion = " SWT Glue code version: 50.0"; - private static final String swtWebkitGlueCodeVersionInfo = " info: +BrowserFunction/GDBus, +WebkitExtension Folder versioning, -setUrl(..postData..), -setCookie(), -getCookie"; + public static final String swtWebkitGlueCodeVersion = " SWT Glue code version: 51.0"; + public static final String swtWebkitGlueCodeVersionInfo = " info: +BrowserFunction/GDBus, +WebkitExtension Folder versioning, +WebKitExtension OSGI support, -setUrl(..postData..), -setCookie(), -getCookie"; /** |
