/** * Constructs an anonymous profile. If a template profile has not been created * for this anonymous type, it will create one. * * @param port the port number to assign to the new profile * @return an anonymous FirefoxProfile, ready for use. */ FirefoxProfile createProfile(FirefoxBinary binary, int port) { // Lazily instantiate the anonymous profile. FirefoxProfile anonymous = cachedProfiles.get(ANONYMOUS_PROFILE_NAME); if (!isValidProfile(anonymous)) { synchronized (this) { anonymous = cachedProfiles.get(ANONYMOUS_PROFILE_NAME); if (!isValidProfile(anonymous)) { anonymous = new FirefoxProfile() { @Override public void clean() { throw new WebDriverException("Cached profiles must not be cleaed."); } }; initCachedProfile(binary, anonymous, port); cachedProfiles.put(ANONYMOUS_PROFILE_NAME, anonymous); } } } return anonymous.createCopy(port); }
public FirefoxBinary startProfile(FirefoxProfile profile, int port) throws IOException { FirefoxBinary binaryToUse = binary; if (binary == null) { binaryToUse = new FirefoxBinary(); } FirefoxProfile profileToUse = profile.createCopy(port); binaryToUse.clean(profileToUse); binaryToUse.startProfile(profileToUse); return binaryToUse; }
/** * Constructs a named profile. If the template profile has not been created * for this profile, it will create one. * * @param profileName the profile, ready for use * @param port the port number to assign to the new profile * @return a fresh clone of the requested named profile */ FirefoxProfile createProfile(FirefoxBinary binary, String profileName, int port) { FirefoxProfile named = cachedProfiles.get(profileName); if (!isValidProfile(named)) { synchronized (this) { named = cachedProfiles.get(profileName); if (!isValidProfile(named)) { ProfilesIni profileDirectory = new ProfilesIni(); named = profileDirectory.getProfile(profileName); if (!isValidProfile(named)) { throw new WebDriverException(String.format("Unable to locate profile \"%s\"", profileName)); } initCachedProfile(binary, named, port); cachedProfiles.put(profileName, named); } } } return named.createCopy(port); }