| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Definition of helper functions for the Chrome Extensions Proxy Settings API. | 5 // Definition of helper functions for the Chrome Extensions Proxy Settings API. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROXY_API_HELPERS_H_ | 7 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PROXY_API_HELPERS_H_ |
| 8 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROXY_API_HELPERS_H_ | 8 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PROXY_API_HELPERS_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "chrome/browser/prefs/proxy_prefs.h" | 13 #include "chrome/browser/prefs/proxy_prefs.h" |
| 14 #include "net/proxy/proxy_config.h" | 14 #include "net/proxy/proxy_config.h" |
| 15 | 15 |
| 16 class ProxyConfigDictionary; |
| 17 |
| 18 namespace base { |
| 16 class DictionaryValue; | 19 class DictionaryValue; |
| 17 class ListValue; | 20 class ListValue; |
| 18 class ProxyConfigDictionary; | 21 } |
| 19 | 22 |
| 20 namespace extension_proxy_api_helpers { | 23 namespace extension_proxy_api_helpers { |
| 21 | 24 |
| 22 // Conversion between PAC scripts and data-encoding URLs containing these | 25 // Conversion between PAC scripts and data-encoding URLs containing these |
| 23 // PAC scripts. Data-encoding URLs consist of a data:// prefix, a mime-type and | 26 // PAC scripts. Data-encoding URLs consist of a data:// prefix, a mime-type and |
| 24 // base64 encoded text. The functions return true in case of success. | 27 // base64 encoded text. The functions return true in case of success. |
| 25 // CreatePACScriptFromDataURL should only be called on data-encoding urls | 28 // CreatePACScriptFromDataURL should only be called on data-encoding urls |
| 26 // created with CreateDataURLFromPACScript. | 29 // created with CreateDataURLFromPACScript. |
| 27 bool CreateDataURLFromPACScript(const std::string& pac_script, | 30 bool CreateDataURLFromPACScript(const std::string& pac_script, |
| 28 std::string* pac_script_url_base64_encoded); | 31 std::string* pac_script_url_base64_encoded); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 // | 42 // |
| 40 // - If there are NO entries for the respective pieces of data, the functions | 43 // - If there are NO entries for the respective pieces of data, the functions |
| 41 // return true. | 44 // return true. |
| 42 // - If there ARE entries and they could be parsed, the functions set |out| | 45 // - If there ARE entries and they could be parsed, the functions set |out| |
| 43 // and return true. | 46 // and return true. |
| 44 // - If there are entries that could not be parsed, the functions set |error| | 47 // - If there are entries that could not be parsed, the functions set |error| |
| 45 // and return false. | 48 // and return false. |
| 46 // | 49 // |
| 47 // The parameter |bad_message| is passed to simulate the behavior of | 50 // The parameter |bad_message| is passed to simulate the behavior of |
| 48 // EXTENSION_FUNCTION_VALIDATE. It is never NULL. | 51 // EXTENSION_FUNCTION_VALIDATE. It is never NULL. |
| 49 bool GetProxyModeFromExtensionPref(const DictionaryValue* proxy_config, | 52 bool GetProxyModeFromExtensionPref(const base::DictionaryValue* proxy_config, |
| 50 ProxyPrefs::ProxyMode* out, | 53 ProxyPrefs::ProxyMode* out, |
| 51 std::string* error, | 54 std::string* error, |
| 52 bool* bad_message); | 55 bool* bad_message); |
| 53 bool GetPacMandatoryFromExtensionPref(const DictionaryValue* proxy_config, | 56 bool GetPacMandatoryFromExtensionPref(const base::DictionaryValue* proxy_config, |
| 54 bool* out, | 57 bool* out, |
| 55 std::string* error, | 58 std::string* error, |
| 56 bool* bad_message); | 59 bool* bad_message); |
| 57 bool GetPacUrlFromExtensionPref(const DictionaryValue* proxy_config, | 60 bool GetPacUrlFromExtensionPref(const base::DictionaryValue* proxy_config, |
| 58 std::string* out, | 61 std::string* out, |
| 59 std::string* error, | 62 std::string* error, |
| 60 bool* bad_message); | 63 bool* bad_message); |
| 61 bool GetPacDataFromExtensionPref(const DictionaryValue* proxy_config, | 64 bool GetPacDataFromExtensionPref(const base::DictionaryValue* proxy_config, |
| 62 std::string* out, | 65 std::string* out, |
| 63 std::string* error, | 66 std::string* error, |
| 64 bool* bad_message); | 67 bool* bad_message); |
| 65 bool GetProxyRulesStringFromExtensionPref(const DictionaryValue* proxy_config, | 68 bool GetProxyRulesStringFromExtensionPref( |
| 66 std::string* out, | 69 const base::DictionaryValue* proxy_config, |
| 67 std::string* error, | 70 std::string* out, |
| 68 bool* bad_message); | 71 std::string* error, |
| 69 bool GetBypassListFromExtensionPref(const DictionaryValue* proxy_config, | 72 bool* bad_message); |
| 73 bool GetBypassListFromExtensionPref(const base::DictionaryValue* proxy_config, |
| 70 std::string* out, | 74 std::string* out, |
| 71 std::string* error, | 75 std::string* error, |
| 72 bool* bad_message); | 76 bool* bad_message); |
| 73 | 77 |
| 74 // Creates and returns a ProxyConfig dictionary (as defined in the extension | 78 // Creates and returns a ProxyConfig dictionary (as defined in the extension |
| 75 // API) from the given parameters. Ownership is passed to the caller. | 79 // API) from the given parameters. Ownership is passed to the caller. |
| 76 // Depending on the value of |mode_enum|, several of the strings may be empty. | 80 // Depending on the value of |mode_enum|, several of the strings may be empty. |
| 77 DictionaryValue* CreateProxyConfigDict(ProxyPrefs::ProxyMode mode_enum, | 81 base::DictionaryValue* CreateProxyConfigDict( |
| 78 bool pac_mandatory, | 82 ProxyPrefs::ProxyMode mode_enum, |
| 79 const std::string& pac_url, | 83 bool pac_mandatory, |
| 80 const std::string& pac_data, | 84 const std::string& pac_url, |
| 81 const std::string& proxy_rules_string, | 85 const std::string& pac_data, |
| 82 const std::string& bypass_list, | 86 const std::string& proxy_rules_string, |
| 83 std::string* error); | 87 const std::string& bypass_list, |
| 88 std::string* error); |
| 84 | 89 |
| 85 // Converts a ProxyServer dictionary instance (as defined in the extension API) | 90 // Converts a ProxyServer dictionary instance (as defined in the extension API) |
| 86 // |proxy_server| to a net::ProxyServer. | 91 // |proxy_server| to a net::ProxyServer. |
| 87 // |default_scheme| is the default scheme that is filled in, in case the | 92 // |default_scheme| is the default scheme that is filled in, in case the |
| 88 // caller did not pass one. | 93 // caller did not pass one. |
| 89 // Returns true if successful and sets |error| otherwise. | 94 // Returns true if successful and sets |error| otherwise. |
| 90 bool GetProxyServer(const DictionaryValue* proxy_server, | 95 bool GetProxyServer(const base::DictionaryValue* proxy_server, |
| 91 net::ProxyServer::Scheme default_scheme, | 96 net::ProxyServer::Scheme default_scheme, |
| 92 net::ProxyServer* out, | 97 net::ProxyServer* out, |
| 93 std::string* error, | 98 std::string* error, |
| 94 bool* bad_message); | 99 bool* bad_message); |
| 95 | 100 |
| 96 // Joins a list of URLs (stored as StringValues) in |list| with |joiner| | 101 // Joins a list of URLs (stored as StringValues) in |list| with |joiner| |
| 97 // to |out|. Returns true if successful and sets |error| otherwise. | 102 // to |out|. Returns true if successful and sets |error| otherwise. |
| 98 bool JoinUrlList(ListValue* list, | 103 bool JoinUrlList(base::ListValue* list, |
| 99 const std::string& joiner, | 104 const std::string& joiner, |
| 100 std::string* out, | 105 std::string* out, |
| 101 std::string* error, | 106 std::string* error, |
| 102 bool* bad_message); | 107 bool* bad_message); |
| 103 | 108 |
| 104 | 109 |
| 105 // Helper functions for browser->extension pref transformation: | 110 // Helper functions for browser->extension pref transformation: |
| 106 | 111 |
| 107 // Creates and returns a ProxyRules dictionary as defined in the extension API | 112 // Creates and returns a ProxyRules dictionary as defined in the extension API |
| 108 // with the values of a ProxyConfigDictionary configured for fixed proxy | 113 // with the values of a ProxyConfigDictionary configured for fixed proxy |
| 109 // servers. Returns NULL in case of failures. Ownership is passed to the caller. | 114 // servers. Returns NULL in case of failures. Ownership is passed to the caller. |
| 110 DictionaryValue* CreateProxyRulesDict( | 115 base::DictionaryValue* CreateProxyRulesDict( |
| 111 const ProxyConfigDictionary& proxy_config); | 116 const ProxyConfigDictionary& proxy_config); |
| 112 | 117 |
| 113 // Creates and returns a ProxyServer dictionary as defined in the extension API | 118 // Creates and returns a ProxyServer dictionary as defined in the extension API |
| 114 // with values from a net::ProxyServer object. Never returns NULL. Ownership is | 119 // with values from a net::ProxyServer object. Never returns NULL. Ownership is |
| 115 // passed to the caller. | 120 // passed to the caller. |
| 116 DictionaryValue* CreateProxyServerDict(const net::ProxyServer& proxy); | 121 base::DictionaryValue* CreateProxyServerDict(const net::ProxyServer& proxy); |
| 117 | 122 |
| 118 // Creates and returns a PacScript dictionary as defined in the extension API | 123 // Creates and returns a PacScript dictionary as defined in the extension API |
| 119 // with the values of a ProxyconfigDictionary configured for pac scripts. | 124 // with the values of a ProxyconfigDictionary configured for pac scripts. |
| 120 // Returns NULL in case of failures. Ownership is passed to the caller. | 125 // Returns NULL in case of failures. Ownership is passed to the caller. |
| 121 DictionaryValue* CreatePacScriptDict(const ProxyConfigDictionary& proxy_config); | 126 base::DictionaryValue* CreatePacScriptDict( |
| 127 const ProxyConfigDictionary& proxy_config); |
| 122 | 128 |
| 123 // Tokenizes the |in| at delimiters |delims| and returns a new ListValue with | 129 // Tokenizes the |in| at delimiters |delims| and returns a new ListValue with |
| 124 // StringValues created from the tokens. Ownership is passed to the caller. | 130 // StringValues created from the tokens. Ownership is passed to the caller. |
| 125 ListValue* TokenizeToStringList(const std::string& in, | 131 base::ListValue* TokenizeToStringList(const std::string& in, |
| 126 const std::string& delims); | 132 const std::string& delims); |
| 127 | 133 |
| 128 } // namespace extension_proxy_api_helpers | 134 } // namespace extension_proxy_api_helpers |
| 129 | 135 |
| 130 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROXY_API_HELPERS_H_ | 136 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PROXY_API_HELPERS_H_ |
| OLD | NEW |