Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 187315 - [Browser] session cookie access needed
Summary: [Browser] session cookie access needed
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Grant Gayed CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 83420 (view as bug list)
Depends on:
Blocks: 163120
  Show dependency tree
 
Reported: 2007-05-16 13:00 EDT by Andreas Goetz CLA
Modified: 2009-05-13 10:33 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Goetz CLA 2007-05-16 13:00:26 EDT
For use by Mylar web connector we'd need access to the org.eclipse.swt.browser.Browser's session information- namely cookies. Also interesting might be DOM access via api. While the execute() method allows javascript execution, it does not return any data.

Thanks,
Andreas
Comment 1 Grant Gayed CLA 2007-05-16 13:10:12 EDT
There is an existing request for Browser DOM access via Browser api, see bug 57477.  There are currently two other ways to accomplish this:

1. execute() can be used as demonstrated in (yes they're hacky):
-> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java
-> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java

2. Use a SWT.MOZILLA-style Browser instead and do it via JavaXPCOM.

Removing DOM from the title since bug 57477 already exists for this.
Comment 2 Eugene Kuleshov CLA 2007-05-16 15:16:33 EDT
Grant, can you please elaborate how can we set cookies into the browser instance before opening some external url?
Comment 3 Grant Gayed CLA 2007-05-16 15:56:08 EDT
Comment 1 discusses accessing the browser's DOM.  I don't think there's currently a way to set cookies in the Browser, except:

1. If javascript can do this then execute() may be your friend here (may need to set url to about:blank first).
2. The Silver Bullet, a SWT.MOZILLA-style Browser + JavaXPCOM could probably do this.
Comment 4 Eugene Kuleshov CLA 2007-05-16 17:15:39 EDT
I am not a javascript expert, but the problem with setting cookies from javascript before loading page is the browser's own security restrictions, so it won't allow to set cookies from the code loaded from some foreign domain. I also been told that SWT.MOZILLA browser is not reliable yet comparing to the old browser.
Comment 5 Andreas Goetz CLA 2007-05-17 05:01:12 EDT
The ugly (but sofar only?) way working around this would be to navigate to the target repository, set cookie information and reload page. 
Similarly, when browser widget is closed, last action should be to read the cookie information- if URL is still within the original starting domain and/or path.
Comment 6 Eugene Kuleshov CLA 2007-05-17 13:37:05 EDT
Wau! I didn't think of such multistep process. Though it is still unclear how would we know that page need to be reloaded? Seems like it would require to track all pages that don't have cookies set.
Comment 7 Andreas Goetz CLA 2007-05-17 16:01:07 EDT
Mhhm. I was imagining this process (for editing the bug):
1) open browser at web repository url; use addProgressListener(ProgressListener) to get notified about load finished. Widget might be invisble at that time
2) use execute() to set the cookies using javascript setCookie(), check http://techpatterns.com/downloads/javascript_cookies.php
3) repeat step 1), widget is visible now
4) user does whatever- we'll need to listen for widget destruction or navigation events through ProgressListener
5) if widget is closed or navigated, we use execute() again to get the current cookies and associate them with the repository
This should be enough for a 90% solution of handling simple login?
Comment 8 Andreas Goetz CLA 2007-05-17 16:08:01 EDT
Btw this is not only needed for web connector, but for all connectors- e.g. bugzilla when voting.
Comment 9 Mik Kersten CLA 2007-05-17 21:00:24 EDT
The Mylar connector specific stuff should probably be discussed on bug 163120.
Comment 10 Grant Gayed CLA 2007-11-22 11:17:18 EST
*** Bug 83420 has been marked as a duplicate of this bug. ***
Comment 11 Grant Gayed CLA 2009-05-13 10:33:45 EDT
Cookie API was added in 3.5M6 (Browser.get/setCookie()).

Also note that new API Browser.evaluate() will evaluate a JS string and return the result.