| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/net/firefox_proxy_settings.h" | 5 #include "chrome/browser/net/firefox_proxy_settings.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return FirefoxProxySettings::UNKNONW; | 58 return FirefoxProxySettings::UNKNONW; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Parses the prefs found in the file |pref_file| and puts the key/value pairs | 62 // Parses the prefs found in the file |pref_file| and puts the key/value pairs |
| 63 // in |prefs|. Keys are strings, and values can be strings, booleans or | 63 // in |prefs|. Keys are strings, and values can be strings, booleans or |
| 64 // integers. Returns true if it succeeded, false otherwise (in which case | 64 // integers. Returns true if it succeeded, false otherwise (in which case |
| 65 // |prefs| is not filled). | 65 // |prefs| is not filled). |
| 66 // Note: for strings, only valid UTF-8 string values are supported. If a | 66 // Note: for strings, only valid UTF-8 string values are supported. If a |
| 67 // key/pair is not valid UTF-8, it is ignored and will not appear in |prefs|. | 67 // key/pair is not valid UTF-8, it is ignored and will not appear in |prefs|. |
| 68 bool ParsePrefFile(const base::FilePath& pref_file, DictionaryValue* prefs) { | 68 bool ParsePrefFile(const base::FilePath& pref_file, |
| 69 base::DictionaryValue* prefs) { |
| 69 // The string that is before a pref key. | 70 // The string that is before a pref key. |
| 70 const std::string kUserPrefString = "user_pref(\""; | 71 const std::string kUserPrefString = "user_pref(\""; |
| 71 std::string contents; | 72 std::string contents; |
| 72 if (!base::ReadFileToString(pref_file, &contents)) | 73 if (!base::ReadFileToString(pref_file, &contents)) |
| 73 return false; | 74 return false; |
| 74 | 75 |
| 75 std::vector<std::string> lines; | 76 std::vector<std::string> lines; |
| 76 Tokenize(contents, "\n", &lines); | 77 Tokenize(contents, "\n", &lines); |
| 77 | 78 |
| 78 for (std::vector<std::string>::const_iterator iter = lines.begin(); | 79 for (std::vector<std::string>::const_iterator iter = lines.begin(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 239 |
| 239 config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching( | 240 config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching( |
| 240 JoinString(proxy_bypass_list_, ';')); | 241 JoinString(proxy_bypass_list_, ';')); |
| 241 | 242 |
| 242 return true; | 243 return true; |
| 243 } | 244 } |
| 244 | 245 |
| 245 // static | 246 // static |
| 246 bool FirefoxProxySettings::GetSettingsFromFile(const base::FilePath& pref_file, | 247 bool FirefoxProxySettings::GetSettingsFromFile(const base::FilePath& pref_file, |
| 247 FirefoxProxySettings* settings) { | 248 FirefoxProxySettings* settings) { |
| 248 DictionaryValue dictionary; | 249 base::DictionaryValue dictionary; |
| 249 if (!ParsePrefFile(pref_file, &dictionary)) | 250 if (!ParsePrefFile(pref_file, &dictionary)) |
| 250 return false; | 251 return false; |
| 251 | 252 |
| 252 int proxy_type = 0; | 253 int proxy_type = 0; |
| 253 if (!dictionary.GetInteger(kNetworkProxyTypeKey, &proxy_type)) | 254 if (!dictionary.GetInteger(kNetworkProxyTypeKey, &proxy_type)) |
| 254 return true; // No type means no proxy. | 255 return true; // No type means no proxy. |
| 255 | 256 |
| 256 settings->config_type_ = IntToProxyConfig(proxy_type); | 257 settings->config_type_ = IntToProxyConfig(proxy_type); |
| 257 if (settings->config_type_ == AUTO_FROM_URL) { | 258 if (settings->config_type_ == AUTO_FROM_URL) { |
| 258 if (!dictionary.GetStringASCII(kAutoconfigURL, | 259 if (!dictionary.GetStringASCII(kAutoconfigURL, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 while (string_tok.GetNext()) { | 299 while (string_tok.GetNext()) { |
| 299 std::string token = string_tok.token(); | 300 std::string token = string_tok.token(); |
| 300 TrimWhitespaceASCII(token, TRIM_ALL, &token); | 301 TrimWhitespaceASCII(token, TRIM_ALL, &token); |
| 301 if (!token.empty()) | 302 if (!token.empty()) |
| 302 settings->proxy_bypass_list_.push_back(token); | 303 settings->proxy_bypass_list_.push_back(token); |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 } | 306 } |
| 306 return true; | 307 return true; |
| 307 } | 308 } |
| OLD | NEW |