1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.eclipse.swtbot.swt.finder.widgets; |
12 | |
|
13 | |
import java.lang.reflect.Method; |
14 | |
|
15 | |
import org.apache.log4j.Logger; |
16 | |
import org.eclipse.swt.SWT; |
17 | |
import org.eclipse.swt.browser.Browser; |
18 | |
import org.eclipse.swtbot.swt.finder.utils.Credentials; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
class BrowserAuthenticationListenerDelegate { |
28 | |
|
29 | |
private Object delegate; |
30 | |
|
31 | 0 | BrowserAuthenticationListenerDelegate() { |
32 | 0 | if (SWT.getVersion() >= 3500) { |
33 | |
try { |
34 | 0 | this.delegate = Class.forName("org.eclipse.swtbot.swt.finder.widgets.BrowserAuthenticationListener").newInstance(); |
35 | 0 | } catch (ClassNotFoundException e) { |
36 | 0 | throw new RuntimeException(e); |
37 | 0 | } catch (InstantiationException e) { |
38 | 0 | throw new RuntimeException(e); |
39 | 0 | } catch (IllegalAccessException e) { |
40 | 0 | throw new RuntimeException(e); |
41 | |
} |
42 | |
} else { |
43 | 0 | Logger log = Logger.getLogger(BrowserAuthenticationListenerDelegate.class); |
44 | 0 | log.warn("You are running a version of SWT lower than v3.5. Browser authentication may not be available."); |
45 | |
} |
46 | 0 | } |
47 | |
|
48 | |
Credentials getCredentials() { |
49 | 0 | if (this.delegate == null) { |
50 | 0 | return null; |
51 | |
} |
52 | |
try { |
53 | 0 | Method method = delegate.getClass().getMethod("getCredentials"); |
54 | 0 | return (Credentials) method.invoke(this.delegate); |
55 | 0 | } catch (Exception e) { |
56 | 0 | throw new RuntimeException(e); |
57 | |
} |
58 | |
} |
59 | |
|
60 | |
void setCredentials(Credentials credentials) { |
61 | 0 | if (this.delegate == null) { |
62 | 0 | return; |
63 | |
} |
64 | |
try { |
65 | 0 | Method method = delegate.getClass().getMethod("setCredentials", Credentials.class); |
66 | 0 | method.invoke(this.delegate, credentials); |
67 | 0 | } catch (Exception e) { |
68 | 0 | throw new RuntimeException(e); |
69 | |
} |
70 | 0 | } |
71 | |
|
72 | |
void init(Browser widget) { |
73 | 0 | if (this.delegate == null) { |
74 | 0 | return; |
75 | |
} |
76 | |
try { |
77 | 0 | Method method = delegate.getClass().getMethod("init", Browser.class); |
78 | 0 | method.invoke(this.delegate, widget); |
79 | 0 | } catch (Exception e) { |
80 | 0 | throw new RuntimeException(e); |
81 | |
} |
82 | 0 | } |
83 | |
|
84 | |
} |