Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2017-12-01 20:01:17 +0000
committerLeo Ufimtsev2017-12-12 19:23:53 +0000
commitd8fca1df5fd4712c60aca821d48bec6f9359f1a4 (patch)
treecd628bab93072665a9e8b4c2f496b9fe9623d621 /examples
parente4ea137643762dd3e38d38276d52c49d8a5b8aec (diff)
downloadeclipse.platform.swt-d8fca1df5fd4712c60aca821d48bec6f9359f1a4.tar.gz
eclipse.platform.swt-d8fca1df5fd4712c60aca821d48bec6f9359f1a4.tar.xz
eclipse.platform.swt-d8fca1df5fd4712c60aca821d48bec6f9359f1a4.zip
Bug 527738 [Webkit2] implement setUrl(...POST..) support. (snippet 330)
When setURL contains POST data, bypass the Webkit2 API and use the Java API (HttpURLConnection) to perform the request. Set the URL globally so that when calling setText with the response string, any relative paths can be resolved using the base URL. This implementation does not currently support Webkit configured proxies and there may be issues with detecting various signals/listeners that operate on request/response objects given that these are handled by the Java side. Tested against Snippet330. --- Leo's modifications: Patchest 9 notes: - Added g_bytes_unref() to prevent memory leakage. - Making g_bytes_* dynamic otherwise we'll get jvm crash on gtk2. (g_byte* introduced in glib 2.32, but gtk2 only has glib 2.26(ish)). - Move data type conversion logic into one place. (html converted where it's used) - Reduced size of if statment, it was scary. - Add scope to code for clarity. - Don't touch this.postData & this.headers, they're only used by webkit1. Webkit2 shouldn't touch what it doesn't use. - Added if (Webkit1) guards around variables only used by webkit1. - Refactoring. - Avoid passing null value to webkit_web_view_load_bytes(.) if connection is not HTML. - Instead of passing empty array to encoding type, pass array with only a single 0. - Modified Snippet330.java to include some more examples for better testing and learning. - Verified: - against (modified) Snippet330 - jUnit tests. (w1/w2) ... Patchset 15: - Added counter support to setText(..) as a long setURI() could override a setText() call. Change-Id: Ic93747083af6af9933af3ca52149a1fb6e894d2c Signed-off-by: Roland Grunberg <rgrunber@redhat.com> Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet330.java110
1 files changed, 71 insertions, 39 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet330.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet330.java
index 0084cb602b..5cca50fef0 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet330.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet330.java
@@ -25,48 +25,80 @@ import org.eclipse.swt.widgets.*;
public class Snippet330 {
-public static void main(String [] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new GridLayout(2, true));
+ static int BUTTONS_PER_ROW = 1;
- final Browser browser;
- try {
- browser = new Browser(shell, SWT.NONE);
- } catch (SWTError e) {
- System.out.println("Could not instantiate Browser: " + e.getMessage());
- display.dispose();
- return;
- }
- GridData data = new GridData(GridData.FILL_BOTH);
- data.horizontalSpan = 2;
- browser.setLayoutData(data);
+ public static void main(String[] args) {
+
+ Display display = new Display();
+ Shell shell = new Shell(display);
+ shell.setLayout(new GridLayout(BUTTONS_PER_ROW, true));
+
+ final Browser browser;
+ try {
+ browser = new Browser(shell, SWT.NONE);
+ } catch (SWTError e) {
+ System.out.println("Could not instantiate Browser: " + e.getMessage());
+ display.dispose();
+ return;
+ }
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.horizontalSpan = BUTTONS_PER_ROW;
+ browser.setLayoutData(data);
+
+ {
+ Button setHeaders = new Button(shell, SWT.PUSH);
+ setHeaders.setText("Send custom headers");
+ setHeaders.addListener(SWT.Selection,event ->
+ browser.setUrl("http://www.ericgiguere.com/tools/http-header-viewer.html", null,
+ new String[] { "User-agent: SWT Browser", "Custom-header: this is just a demo" }));
+ }
- Button headersButton = new Button(shell, SWT.PUSH);
- headersButton.setText("Send custom headers");
- data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- headersButton.setLayoutData(data);
- headersButton.addListener(SWT.Selection, event -> browser.setUrl(
- "http://www.ericgiguere.com/tools/http-header-viewer.html",
- null,
- new String[] {"User-agent: SWT Browser","Custom-header: this is just a demo"}));
- Button postDataButton = new Button(shell, SWT.PUSH);
- postDataButton.setText("Send post data");
- data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- postDataButton.setLayoutData(data);
- postDataButton.addListener(SWT.Selection, event -> browser.setUrl(
- "https://bugs.eclipse.org/bugs/buglist.cgi",
- "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW&email1=platform-swt-inbox&emailtype1=substring",
- null));
+ {
+ Button postTextPlain = new Button(shell, SWT.PUSH);
+ postTextPlain.setText("Post data as 'text/plain'");
+ postTextPlain.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post",
+ "Plain text passed as postData", new String[] { "content-type: text/plain" }));
+ }
- shell.setBounds(10,10,600,600);
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) display.sleep();
+ {
+ Button postTextPlainUtf8 = new Button(shell, SWT.PUSH);
+ postTextPlainUtf8.setText("Post data as 'text/plain' and specify encoding.");
+ postTextPlainUtf8.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post",
+ "Plain text passed as postData", new String[] { "content-type: text/plain; charset=UTF-8" }));
+ }
+
+ {
+ Button postUrlEncoded = new Button(shell, SWT.PUSH);
+ postUrlEncoded.setText("Post data with url encoding key=value");
+ postUrlEncoded.addListener(SWT.Selection, event -> browser.setUrl("http://httpbin.org/post", "MyKey1=MyValue1&MyKey2=MyValue2",
+ new String[] { "content-type: application/x-www-form-urlencoded" }));
+ }
+
+ {
+ Button postDataBugzilla = new Button(shell, SWT.PUSH);
+ postDataBugzilla.setText("Send post data to bugzilla. url encoding is used as default");
+ postDataBugzilla.addListener(SWT.Selection, event -> browser.setUrl(
+ "https://bugs.eclipse.org/bugs/buglist.cgi",
+ "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW&email1=platform-swt-inbox&emailtype1=substring",
+ null));
+ }
+
+ {
+ Button postDataBugzillaLongQuery = new Button(shell, SWT.PUSH);
+ postDataBugzillaLongQuery.setText("Send post data to bugzilla. Very slow response");
+ postDataBugzillaLongQuery.addListener(SWT.Selection, event -> browser.setUrl(
+ "https://bugs.eclipse.org/bugs/buglist.cgi",
+ "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW",
+ null));
+ }
+
+ shell.setSize(1000, 1000);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
}
- display.dispose();
-}
} \ No newline at end of file

Back to the top