Author: yradtsevich
Date: 2011-10-20 13:55:43 -0400 (Thu, 20 Oct 2011)
New Revision: 35855
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit.gtk.linux.x86/src/org/jboss/tools/browsersim/webkit/WebKitBrowser.java
Log:
https://issues.jboss.org/browse/JBIDE-9539 : Browsersim app for testing mobile/desktop web
apps
- Linux x86 version also works now
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit.gtk.linux.x86/src/org/jboss/tools/browsersim/webkit/WebKitBrowser.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit.gtk.linux.x86/src/org/jboss/tools/browsersim/webkit/WebKitBrowser.java 2011-10-20
17:25:03 UTC (rev 35854)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit.gtk.linux.x86/src/org/jboss/tools/browsersim/webkit/WebKitBrowser.java 2011-10-20
17:55:43 UTC (rev 35855)
@@ -11,17 +11,29 @@
package org.jboss.tools.browsersim.webkit;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.internal.Converter;
import org.eclipse.swt.internal.gtk.OS;
-import org.eclipse.swt.internal.webkit.WebKitGTK;
import org.eclipse.swt.widgets.Composite;
/**
* @author Yahor Radtsevich (yradtsevich)
*/
public class WebKitBrowser extends AbstractWebKitBrowser {
+ private static final byte[] USER_AGENT; // = WebKitGTK.user_agent
+ static {
+ int length = "user-agent".length();
+ char [] chars = new char[length];
+ "user-agent".getChars(0, length, chars, 0);
+ USER_AGENT = new byte[length + 1];
+ for (int i = 0; i < length; i++) {
+ USER_AGENT[i] = (byte) chars [i];
+ }
+ }
+
public WebKitBrowser(Composite parent, int style) {
super(parent, style);
}
@@ -35,12 +47,17 @@
Field webViewField = webKit.getClass().getDeclaredField("webView");
webViewField.setAccessible(true);
int webView = (Integer) webViewField.get(webKit);
- int settings = WebKitGTK.webkit_web_view_get_settings(webView);
+
+// int settings = WebKitGTK.webkit_web_view_get_settings(webView);
+ Class webKitGTKClass =
Browser.class.getClassLoader().loadClass("org.eclipse.swt.internal.webkit.WebKitGTK");
+ Method webkit_web_view_get_settingsMethod =
webKitGTKClass.getDeclaredMethod("webkit_web_view_get_settings", int.class);
+ int settings = (Integer) webkit_web_view_get_settingsMethod.invoke(null, webView);
+
if (userAgent != null) {
byte[] bytes = Converter.wcsToMbcs(null, userAgent, true);
- OS.g_object_set(settings, WebKitGTK.user_agent, bytes, 0);
+ OS.g_object_set(settings, USER_AGENT, bytes, 0);
} else {
- OS.g_object_set(settings, WebKitGTK.user_agent, 0, 0);
+ OS.g_object_set(settings, USER_AGENT, 0, 0);
}
} catch (SecurityException e) {
e.printStackTrace();
@@ -50,6 +67,12 @@
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
}
}
}