Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 238277 - [Browser] Unable to use getdata("query") to obtain cookies
Summary: [Browser] Unable to use getdata("query") to obtain cookies
Status: RESOLVED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 163120
  Show dependency tree
 
Reported: 2008-06-24 11:59 EDT by Andreas Goetz CLA
Modified: 2008-06-28 09:59 EDT (History)
3 users (show)

See Also:


Attachments
mylyn/context/zip (29.27 KB, application/octet-stream)
2008-06-24 14:02 EDT, Andreas Goetz CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Goetz CLA 2008-06-24 11:59:03 EDT
Playing with org.eclipse.ui.examples.rcp.browser while trying to develop some code for accessing browser cookies using DOM, I've realized that  

  if (browser.execute("window.status=document.cookie;")) {
    String value = (String) browser.getData("query");
  }
  
doesn't return any data, regardless if the site contains cookies or not. Adding alert statement verifies that cookies indeed do exist.
Since the code also had a StatusTextListener attached, I've realized though that the updates to window.status end up in the status listener instead which correctly shows the cookies.
This behaviour could be reproduced with both Mozilla 3.0 and IE 7.0 browsers.

Not sure if I'm doing something entirely stupid here or this is an issue of the browser widget?
Comment 1 Andreas Goetz CLA 2008-06-24 14:02:37 EDT
Created attachment 105734 [details]
mylyn/context/zip

browser example mylyn context
Comment 2 Grant Gayed CLA 2008-06-27 16:30:15 EDT
I think the snippet below is what you want (derived from http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java ).  If I'm wrong then please follow up.

public static void main(String [] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.addStatusTextListener(new StatusTextListener() {
        public void changed(StatusTextEvent event) {
            browser.setData("query", event.text);
        }
    });
    browser.addProgressListener(new ProgressAdapter() {
        public void completed(ProgressEvent event) {
            browser.execute("window.status=document.cookie;");
            String value = (String)browser.getData("query");
            System.out.println("document.cookie: " + value);
        }
    });
    browser.setUrl("google.com");
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}
Comment 3 Andreas Goetz CLA 2008-06-28 09:59:11 EDT
True- I had totally overlooked the connection between the status listener and the getData...