1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.selenium.browsers.firefox;
18
19 import org.openqa.selenium.Capabilities;
20 import org.openqa.selenium.browserlaunchers.BrowserLauncher;
21 import org.openqa.selenium.browserlaunchers.locators.*;
22 import org.openqa.selenium.remote.BrowserType;
23 import org.openqa.selenium.remote.CapabilityType;
24 import org.openqa.selenium.server.ApplicationRegistry;
25 import org.openqa.selenium.server.RemoteControlConfiguration;
26 import org.openqa.selenium.server.browserlaunchers.FirefoxCustomProfileLauncher;
27 import org.openqa.selenium.server.browserlaunchers.InvalidBrowserExecutableException;
28 import org.openqa.selenium.server.browserlaunchers.ProxyInjectionFirefoxCustomProfileLauncher;
29
30
31
32
33
34
35 public class DisplayAwareFirefoxLauncher implements BrowserLauncher {
36
37 final BrowserLauncher realLauncher;
38
39 public DisplayAwareFirefoxLauncher(Capabilities browserOptions, RemoteControlConfiguration configuration,
40 String sessionId, String browserLaunchLocation)
41 throws InvalidBrowserExecutableException {
42 String browserName = BrowserType.FIREFOX;
43 BrowserLocator locator = new CombinedFirefoxLocator();
44 String version = (String) browserOptions.getCapability(CapabilityType.VERSION);
45 if ("2".equals(version)) {
46 browserName = BrowserType.FIREFOX_2;
47 locator = new Firefox2Locator();
48 }
49 if ("3".equals(version)) {
50 browserName = BrowserType.FIREFOX_3;
51 locator = new Firefox3Locator();
52 }
53 String mode = (String) browserOptions.getCapability("mode");
54 if (mode == null) {
55 mode = "chrome";
56 }
57 if ("default".equals(mode)) {
58 mode = "chrome";
59 }
60
61 BrowserInstallation installation =
62 ApplicationRegistry.instance().browserInstallationCache().locateBrowserInstallation(
63 browserName, browserLaunchLocation, locator);
64
65 if (installation == null) {
66 throw new InvalidBrowserExecutableException(
67 "The specified path to the browser executable is invalid.");
68 }
69
70 if ("chrome".equals(mode)) {
71 realLauncher =
72 new DisplayAwareFirefoxChromeLauncher(browserOptions, configuration, sessionId, installation);
73 return;
74 }
75
76 boolean proxyInjectionMode =
77 browserOptions.is("proxyInjectionMode") || "proxyInjection".equals(mode);
78
79
80
81 boolean globalProxyInjectionMode = configuration.getProxyInjectionModeArg();
82 if (proxyInjectionMode && !globalProxyInjectionMode) {
83 if (proxyInjectionMode) {
84 throw new RuntimeException(
85 "You requested proxy injection mode, but this server wasn't configured with -proxyInjectionMode on the command line");
86 }
87 }
88
89
90 proxyInjectionMode = globalProxyInjectionMode;
91 if (proxyInjectionMode) {
92 realLauncher =
93 new ProxyInjectionFirefoxCustomProfileLauncher(browserOptions, configuration, sessionId,
94 installation);
95 return;
96 }
97
98
99
100 if (!CapabilityType.PROXY.equals(mode)) {
101 throw new RuntimeException("Unrecognized browser mode: " + mode);
102 }
103
104 realLauncher =
105 new FirefoxCustomProfileLauncher(browserOptions, configuration, sessionId, installation);
106
107 }
108
109 public void close() {
110 realLauncher.close();
111 }
112
113 public void launchHTMLSuite(String suiteUrl, String baseUrl) {
114 realLauncher.launchHTMLSuite(suiteUrl, baseUrl);
115 }
116
117 public void launchRemoteSession(String url) {
118 realLauncher.launchRemoteSession(url);
119 }
120
121 }