1717
1818package org .openqa .selenium .firefox ;
1919
20- import com .google .common .io .Resources ;
21-
22- import org .openqa .selenium .Beta ;
2320import org .openqa .selenium .WebDriverException ;
2421import org .openqa .selenium .io .FileHandler ;
2522import org .openqa .selenium .io .TemporaryFilesystem ;
2926import java .io .File ;
3027import java .io .FileOutputStream ;
3128import java .io .IOException ;
32- import java .io .InputStreamReader ;
3329import java .io .OutputStreamWriter ;
34- import java .io .Reader ;
3530import java .io .StringReader ;
3631import java .io .Writer ;
37- import java .net .URL ;
3832import java .nio .charset .Charset ;
3933import java .util .HashMap ;
4034import java .util .Map ;
4135
4236public class FirefoxProfile {
43- public static final String PORT_PREFERENCE = "webdriver_firefox_port" ;
44- public static final String ALLOWED_HOSTS_PREFERENCE = "webdriver_firefox_allowed_hosts" ;
45-
46- private static final String defaultPrefs = "/org/openqa/selenium/firefox/webdriver_prefs.json" ;
47-
48- private Preferences additionalPrefs ;
4937
50- private Map <String , Extension > extensions = new HashMap <>();
38+ private static final String ACCEPT_UNTRUSTED_CERTS_PREF = "webdriver_accept_untrusted_certs" ;
39+ private static final String ASSUME_UNTRUSTED_ISSUER_PREF = "webdriver_assume_untrusted_issuer" ;
40+ private final Preferences additionalPrefs ;
41+ private final Map <String , Extension > extensions = new HashMap <>();
42+ private final File model ;
5143 private boolean loadNoFocusLib ;
5244 private boolean acceptUntrustedCerts ;
5345 private boolean untrustedCertIssuer ;
54- private File model ;
55- private static final String ACCEPT_UNTRUSTED_CERTS_PREF = "webdriver_accept_untrusted_certs" ;
56- private static final String ASSUME_UNTRUSTED_ISSUER_PREF = "webdriver_assume_untrusted_issuer" ;
5746
5847 public FirefoxProfile () {
5948 this (null );
@@ -67,17 +56,7 @@ public FirefoxProfile() {
6756 * @param profileDir The profile directory to use as a model.
6857 */
6958 public FirefoxProfile (File profileDir ) {
70- this (null , profileDir );
71- }
72-
73- @ Beta
74- protected FirefoxProfile (Reader defaultsReader , File profileDir ) {
75- if (defaultsReader == null ) {
76- defaultsReader = onlyOverrideThisIfYouKnowWhatYouAreDoing ();
77- }
78-
79- additionalPrefs = new Preferences (defaultsReader );
80-
59+ additionalPrefs = new Preferences ();
8160 model = profileDir ;
8261 verifyModel (model );
8362
@@ -87,7 +66,6 @@ protected FirefoxProfile(Reader defaultsReader, File profileDir) {
8766 Preferences existingPrefs = new Preferences (reader , prefsInModel );
8867 acceptUntrustedCerts = getBooleanPreference (existingPrefs , ACCEPT_UNTRUSTED_CERTS_PREF , true );
8968 untrustedCertIssuer = getBooleanPreference (existingPrefs , ASSUME_UNTRUSTED_ISSUER_PREF , true );
90- existingPrefs .addTo (additionalPrefs );
9169 } else {
9270 acceptUntrustedCerts = true ;
9371 untrustedCertIssuer = true ;
@@ -96,27 +74,20 @@ protected FirefoxProfile(Reader defaultsReader, File profileDir) {
9674 // This is not entirely correct but this is not stored in the profile
9775 // so for now will always be set to false.
9876 loadNoFocusLib = false ;
99-
100- try {
101- defaultsReader .close ();
102- } catch (IOException e ) {
103- throw new WebDriverException (e );
104- }
10577 }
10678
107- /**
108- * <strong>Internal method. This is liable to change at a moment's notice.</strong>
109- *
110- * @return InputStreamReader of the default firefox profile preferences
111- */
112- @ Beta
113- protected Reader onlyOverrideThisIfYouKnowWhatYouAreDoing () {
114- URL resource = Resources .getResource (FirefoxProfile .class , defaultPrefs );
115- try {
116- return new InputStreamReader (resource .openStream (), Charset .defaultCharset ());
117- } catch (IOException e ) {
118- throw new WebDriverException (e );
79+ public static FirefoxProfile fromJson (String json ) throws IOException {
80+ // We used to just pass in the entire string without quotes. If we see that, we're good.
81+ // Otherwise, parse the json.
82+
83+ if (json .trim ().startsWith ("\" " )) {
84+ json = new Json ().toType (json , String .class );
11985 }
86+
87+ return new FirefoxProfile (Zip .unzipToTempDir (
88+ json ,
89+ "webdriver" ,
90+ "duplicated" ));
12091 }
12192
12293 private boolean getBooleanPreference (Preferences prefs , String key , boolean defaultValue ) {
@@ -218,7 +189,7 @@ protected Preferences getAdditionalPreferences() {
218189 }
219190
220191 public void updateUserPrefs (File userPrefs ) {
221- Preferences prefs = new Preferences (onlyOverrideThisIfYouKnowWhatYouAreDoing () );
192+ Preferences prefs = new Preferences ();
222193
223194 // Allow users to override these settings
224195 prefs .setPreference ("browser.startup.homepage" , "about:blank" );
@@ -227,7 +198,7 @@ public void updateUserPrefs(File userPrefs) {
227198 prefs .setPreference ("browser.startup.page" , 0 );
228199
229200 if (userPrefs .exists ()) {
230- prefs = new Preferences (onlyOverrideThisIfYouKnowWhatYouAreDoing (), userPrefs );
201+ prefs = new Preferences (userPrefs );
231202 if (!userPrefs .delete ()) {
232203 throw new WebDriverException ("Cannot delete existing user preferences" );
233204 }
@@ -334,24 +305,13 @@ String toJson() throws IOException {
334305 }
335306 }
336307
337- public static FirefoxProfile fromJson (String json ) throws IOException {
338- // We used to just pass in the entire string without quotes. If we see that, we're good.
339- // Otherwise, parse the json.
340-
341- if (json .trim ().startsWith ("\" " )) {
342- json = new Json ().toType (json , String .class );
343- }
344-
345- return new FirefoxProfile (Zip .unzipToTempDir (
346- json ,
347- "webdriver" ,
348- "duplicated" ));
349- }
350-
351308 public void cleanTemporaryModel () {
352309 clean (model );
353310 }
354311
312+ /**
313+ * @deprecated This method will not be replaced as no default preferences are loaded anymore.
314+ */
355315 public void checkForChangesInFrozenPreferences () {
356316 additionalPrefs .checkForChangesInFrozenPreferences ();
357317 }
0 commit comments