Search in sources :

Example 1 with ProgressWindow

use of com.biglybt.ui.swt.progress.ProgressWindow in project BiglyBT by BiglySoftware.

the class ExternalLoginWindow method setCaptureMethod.

protected void setCaptureMethod(final BrowserWrapper browser, boolean transparent, boolean show_progress) {
    if (sniffer != null) {
        sniffer.destroy();
        sniffer = null;
    }
    if (show_progress) {
        final ProgressWindow prog_wind = new ProgressWindow(shell, "externalLogin.wait", SWT.DIALOG_TRIM, 500);
        browser.addProgressListener(new ProgressListener() {

            @Override
            public void changed(ProgressEvent arg0) {
            }

            @Override
            public void completed(ProgressEvent arg0) {
                if (browser.isDisposed() || browser.getShell().isDisposed()) {
                    return;
                }
                browser.removeProgressListener(this);
                prog_wind.destroy();
            }
        });
    }
    if (transparent) {
        browser.setUrl(originalLoginUrl);
    } else {
        try {
            final HTTPAuthHelper this_sniffer = sniffer = new HTTPAuthHelper(new URL(originalLoginUrl));
            this_sniffer.addListener(new HTTPAuthHelperListener() {

                @Override
                public void cookieFound(HTTPAuthHelper helper, String cookie_name, String cookie_value) {
                    if (helper == this_sniffer) {
                        foundCookies(cookie_name + "=" + cookie_value, false);
                    }
                }
            });
            this_sniffer.start();
            String str = originalLoginUrl.toString();
            int pos = str.indexOf("://");
            str = str.substring(pos + 3);
            pos = str.indexOf("/");
            if (pos != -1) {
                str = str.substring(pos);
            }
            if (!str.startsWith("/")) {
                str = "/" + str;
            }
            browser.setUrl("http://localhost:" + sniffer.getPort() + str);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
}
Also used : HTTPAuthHelper(com.biglybt.core.util.http.HTTPAuthHelper) ProgressListener(org.eclipse.swt.browser.ProgressListener) ProgressWindow(com.biglybt.ui.swt.progress.ProgressWindow) HTTPAuthHelperListener(com.biglybt.core.util.http.HTTPAuthHelperListener) ProgressEvent(org.eclipse.swt.browser.ProgressEvent) URL(java.net.URL)

Aggregations

HTTPAuthHelper (com.biglybt.core.util.http.HTTPAuthHelper)1 HTTPAuthHelperListener (com.biglybt.core.util.http.HTTPAuthHelperListener)1 ProgressWindow (com.biglybt.ui.swt.progress.ProgressWindow)1 URL (java.net.URL)1 ProgressEvent (org.eclipse.swt.browser.ProgressEvent)1 ProgressListener (org.eclipse.swt.browser.ProgressListener)1