Re: Reading and manipulating the DOM of a loaded document with JavaXPCOM and Javier Pedemonte's SWT
"mica" <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <1146248701.544889.51130__29085.2829501548$1146249032$gmane$org@i39g2000cwa.googlegroups.com> |
I am doing the same thing that you say. I have a method named "go" that
blocks util the page is fully loaded. And then, I can access to the
loaded document.
My code is based on MozillaBrowser found in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=79213
Code is like this:
public class SpeciallBrowser extends MozillaBrowser {
private int numStart = 0;
private CountDownLatch latch = new CountDownLatch(1);
private Display display;
public SpeciallBrowser(Composite parent, int style) {
super(parent, style);
display = parent.getDisplay();
}
public void go(final String url) {
latch = new CountDownLatch(1);
display.asyncExec(new Runnable() {
public void run() {
setUrl(url);
}
});
try {
latch.await();
latch = new CountDownLatch(1);
} catch (InterruptedException e) {
throw new Error();
}
}
public void onStateChange(nsIWebProgress aWebProgress, nsIRequest
aRequest, long aStateFlags, long aStatus) {
boolean isDocument =
(aStateFlags &
nsIWebProgressListener.STATE_IS_DOCUMENT) != 0;
boolean start =
(aStateFlags &
nsIWebProgressListener.STATE_START) != 0;
boolean stop =
(aStateFlags &
nsIWebProgressListener.STATE_STOP) != 0;
if (isDocument) {
if (start) {
numStart++;
} else if (stop) {
numStart--;
if (numStart == 0) {
latch.countDown();
}
}
}
}
}
Does somebody think that is better form to do this ????