Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation of the Chrome Extensions Proxy Settings API. | 5 // Implementation of the Chrome Extensions Proxy Settings API. |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/proxy/proxy_api.h" | 7 #include "chrome/browser/extensions/api/proxy/proxy_api.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 std::move(args), GURL()); | 89 std::move(args), GURL()); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 ProxyPrefTransformer::ProxyPrefTransformer() { | 93 ProxyPrefTransformer::ProxyPrefTransformer() { |
| 94 } | 94 } |
| 95 | 95 |
| 96 ProxyPrefTransformer::~ProxyPrefTransformer() { | 96 ProxyPrefTransformer::~ProxyPrefTransformer() { |
| 97 } | 97 } |
| 98 | 98 |
| 99 base::Value* ProxyPrefTransformer::ExtensionToBrowserPref( | 99 std::unique_ptr<base::Value> ProxyPrefTransformer::ExtensionToBrowserPref( |
| 100 const base::Value* extension_pref, | 100 const base::Value* extension_pref, |
| 101 std::string* error, | 101 std::string* error, |
| 102 bool* bad_message) { | 102 bool* bad_message) { |
| 103 // When ExtensionToBrowserPref is called, the format of |extension_pref| | 103 // When ExtensionToBrowserPref is called, the format of |extension_pref| |
| 104 // has been verified already by the extension API to match the schema | 104 // has been verified already by the extension API to match the schema |
| 105 // defined in the extension API JSON. | 105 // defined in the extension API JSON. |
| 106 CHECK(extension_pref->IsType(base::Value::Type::DICTIONARY)); | 106 CHECK(extension_pref->IsType(base::Value::Type::DICTIONARY)); |
| 107 const base::DictionaryValue* config = | 107 const base::DictionaryValue* config = |
| 108 static_cast<const base::DictionaryValue*>(extension_pref); | 108 static_cast<const base::DictionaryValue*>(extension_pref); |
| 109 | 109 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 123 !helpers::GetPacMandatoryFromExtensionPref( | 123 !helpers::GetPacMandatoryFromExtensionPref( |
| 124 config, &pac_mandatory, error, bad_message) || | 124 config, &pac_mandatory, error, bad_message) || |
| 125 !helpers::GetPacUrlFromExtensionPref( | 125 !helpers::GetPacUrlFromExtensionPref( |
| 126 config, &pac_url, error, bad_message) || | 126 config, &pac_url, error, bad_message) || |
| 127 !helpers::GetPacDataFromExtensionPref( | 127 !helpers::GetPacDataFromExtensionPref( |
| 128 config, &pac_data, error, bad_message) || | 128 config, &pac_data, error, bad_message) || |
| 129 !helpers::GetProxyRulesStringFromExtensionPref( | 129 !helpers::GetProxyRulesStringFromExtensionPref( |
| 130 config, &proxy_rules_string, error, bad_message) || | 130 config, &proxy_rules_string, error, bad_message) || |
| 131 !helpers::GetBypassListFromExtensionPref( | 131 !helpers::GetBypassListFromExtensionPref( |
| 132 config, &bypass_list, error, bad_message)) { | 132 config, &bypass_list, error, bad_message)) { |
| 133 return NULL; | 133 return nullptr; |
| 134 } | 134 } |
| 135 | 135 |
| 136 return helpers::CreateProxyConfigDict(mode_enum, pac_mandatory, pac_url, | 136 return helpers::CreateProxyConfigDict(mode_enum, pac_mandatory, pac_url, |
| 137 pac_data, proxy_rules_string, | 137 pac_data, proxy_rules_string, |
| 138 bypass_list, error) | 138 bypass_list, error); |
| 139 .release(); | |
| 140 } | 139 } |
| 141 | 140 |
| 142 base::Value* ProxyPrefTransformer::BrowserToExtensionPref( | 141 std::unique_ptr<base::Value> ProxyPrefTransformer::BrowserToExtensionPref( |
| 143 const base::Value* browser_pref) { | 142 const base::Value* browser_pref) { |
| 144 CHECK(browser_pref->IsType(base::Value::Type::DICTIONARY)); | 143 CHECK(browser_pref->IsType(base::Value::Type::DICTIONARY)); |
| 145 | 144 |
| 146 // This is a dictionary wrapper that exposes the proxy configuration stored in | 145 // This is a dictionary wrapper that exposes the proxy configuration stored in |
| 147 // the browser preferences. | 146 // the browser preferences. |
| 148 ProxyConfigDictionary config( | 147 ProxyConfigDictionary config( |
| 149 static_cast<const base::DictionaryValue*>(browser_pref) | 148 static_cast<const base::DictionaryValue*>(browser_pref) |
| 150 ->CreateDeepCopy()); | 149 ->CreateDeepCopy()); |
| 151 | 150 |
| 152 ProxyPrefs::ProxyMode mode; | 151 ProxyPrefs::ProxyMode mode; |
| 153 if (!config.GetMode(&mode)) { | 152 if (!config.GetMode(&mode)) { |
| 154 LOG(ERROR) << "Cannot determine proxy mode."; | 153 LOG(ERROR) << "Cannot determine proxy mode."; |
| 155 return NULL; | 154 return nullptr; |
| 156 } | 155 } |
| 157 | 156 |
| 158 // Build a new ProxyConfig instance as defined in the extension API. | 157 // Build a new ProxyConfig instance as defined in the extension API. |
| 159 std::unique_ptr<base::DictionaryValue> extension_pref( | 158 std::unique_ptr<base::DictionaryValue> extension_pref( |
| 160 new base::DictionaryValue); | 159 new base::DictionaryValue); |
| 161 | 160 |
| 162 extension_pref->SetString(keys::kProxyConfigMode, | 161 extension_pref->SetString(keys::kProxyConfigMode, |
| 163 ProxyPrefs::ProxyModeToString(mode)); | 162 ProxyPrefs::ProxyModeToString(mode)); |
| 164 | 163 |
| 165 switch (mode) { | 164 switch (mode) { |
| 166 case ProxyPrefs::MODE_DIRECT: | 165 case ProxyPrefs::MODE_DIRECT: |
| 167 case ProxyPrefs::MODE_AUTO_DETECT: | 166 case ProxyPrefs::MODE_AUTO_DETECT: |
| 168 case ProxyPrefs::MODE_SYSTEM: | 167 case ProxyPrefs::MODE_SYSTEM: |
| 169 // These modes have no further parameters. | 168 // These modes have no further parameters. |
| 170 break; | 169 break; |
| 171 case ProxyPrefs::MODE_PAC_SCRIPT: { | 170 case ProxyPrefs::MODE_PAC_SCRIPT: { |
| 172 // A PAC URL either point to a PAC script or contain a base64 encoded | 171 // A PAC URL either point to a PAC script or contain a base64 encoded |
| 173 // PAC script. In either case we build a PacScript dictionary as defined | 172 // PAC script. In either case we build a PacScript dictionary as defined |
| 174 // in the extension API. | 173 // in the extension API. |
| 175 base::DictionaryValue* pac_dict = helpers::CreatePacScriptDict(config); | 174 base::DictionaryValue* pac_dict = helpers::CreatePacScriptDict(config); |
| 176 if (!pac_dict) | 175 if (!pac_dict) |
| 177 return NULL; | 176 return nullptr; |
| 178 extension_pref->Set(keys::kProxyConfigPacScript, pac_dict); | 177 extension_pref->Set(keys::kProxyConfigPacScript, pac_dict); |
| 179 break; | 178 break; |
| 180 } | 179 } |
| 181 case ProxyPrefs::MODE_FIXED_SERVERS: { | 180 case ProxyPrefs::MODE_FIXED_SERVERS: { |
| 182 // Build ProxyRules dictionary according to the extension API. | 181 // Build ProxyRules dictionary according to the extension API. |
| 183 base::DictionaryValue* proxy_rules_dict = | 182 base::DictionaryValue* proxy_rules_dict = |
| 184 helpers::CreateProxyRulesDict(config); | 183 helpers::CreateProxyRulesDict(config); |
| 185 if (!proxy_rules_dict) | 184 if (!proxy_rules_dict) |
| 186 return NULL; | 185 return nullptr; |
| 187 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); | 186 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); |
| 188 break; | 187 break; |
| 189 } | 188 } |
| 190 case ProxyPrefs::kModeCount: | 189 case ProxyPrefs::kModeCount: |
| 191 NOTREACHED(); | 190 NOTREACHED(); |
| 192 } | 191 } |
| 193 return extension_pref.release(); | 192 return extension_pref; |
|
jdoerrie
2017/04/10 10:39:23
return std::move(extension_pref); should fix the c
| |
| 194 } | 193 } |
| 195 | 194 |
| 196 } // namespace extensions | 195 } // namespace extensions |
| OLD | NEW |