| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 ProxyEventRouter::ProxyEventRouter() { | 32 ProxyEventRouter::ProxyEventRouter() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 ProxyEventRouter::~ProxyEventRouter() { | 35 ProxyEventRouter::~ProxyEventRouter() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ProxyEventRouter::OnProxyError( | 38 void ProxyEventRouter::OnProxyError( |
| 39 EventRouterForwarder* event_router, | 39 EventRouterForwarder* event_router, |
| 40 void* profile, | 40 void* profile, |
| 41 int error_code) { | 41 int error_code) { |
| 42 scoped_ptr<base::ListValue> args(new base::ListValue()); | 42 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 43 base::DictionaryValue* dict = new base::DictionaryValue(); | 43 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 44 dict->SetBoolean(keys::kProxyEventFatal, true); | 44 dict->SetBoolean(keys::kProxyEventFatal, true); |
| 45 dict->SetString(keys::kProxyEventError, net::ErrorToString(error_code)); | 45 dict->SetString(keys::kProxyEventError, net::ErrorToString(error_code)); |
| 46 dict->SetString(keys::kProxyEventDetails, std::string()); | 46 dict->SetString(keys::kProxyEventDetails, std::string()); |
| 47 args->Append(dict); | 47 args->Append(dict); |
| 48 | 48 |
| 49 if (profile) { | 49 if (profile) { |
| 50 event_router->DispatchEventToRenderers( | 50 event_router->DispatchEventToRenderers( |
| 51 events::PROXY_ON_PROXY_ERROR, keys::kProxyEventOnProxyError, | 51 events::PROXY_ON_PROXY_ERROR, keys::kProxyEventOnProxyError, |
| 52 std::move(args), profile, true, GURL()); | 52 std::move(args), profile, true, GURL()); |
| 53 } else { | 53 } else { |
| 54 event_router->BroadcastEventToRenderers(events::PROXY_ON_PROXY_ERROR, | 54 event_router->BroadcastEventToRenderers(events::PROXY_ON_PROXY_ERROR, |
| 55 keys::kProxyEventOnProxyError, | 55 keys::kProxyEventOnProxyError, |
| 56 std::move(args), GURL()); | 56 std::move(args), GURL()); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ProxyEventRouter::OnPACScriptError( | 60 void ProxyEventRouter::OnPACScriptError( |
| 61 EventRouterForwarder* event_router, | 61 EventRouterForwarder* event_router, |
| 62 void* profile, | 62 void* profile, |
| 63 int line_number, | 63 int line_number, |
| 64 const base::string16& error) { | 64 const base::string16& error) { |
| 65 scoped_ptr<base::ListValue> args(new base::ListValue()); | 65 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 66 base::DictionaryValue* dict = new base::DictionaryValue(); | 66 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 67 dict->SetBoolean(keys::kProxyEventFatal, false); | 67 dict->SetBoolean(keys::kProxyEventFatal, false); |
| 68 dict->SetString(keys::kProxyEventError, | 68 dict->SetString(keys::kProxyEventError, |
| 69 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); | 69 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); |
| 70 std::string error_msg; | 70 std::string error_msg; |
| 71 if (line_number != -1) { | 71 if (line_number != -1) { |
| 72 base::SStringPrintf(&error_msg, | 72 base::SStringPrintf(&error_msg, |
| 73 "line: %d: %s", | 73 "line: %d: %s", |
| 74 line_number, base::UTF16ToUTF8(error).c_str()); | 74 line_number, base::UTF16ToUTF8(error).c_str()); |
| 75 } else { | 75 } else { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 ProxyConfigDictionary config( | 146 ProxyConfigDictionary config( |
| 147 static_cast<const base::DictionaryValue*>(browser_pref)); | 147 static_cast<const base::DictionaryValue*>(browser_pref)); |
| 148 | 148 |
| 149 ProxyPrefs::ProxyMode mode; | 149 ProxyPrefs::ProxyMode mode; |
| 150 if (!config.GetMode(&mode)) { | 150 if (!config.GetMode(&mode)) { |
| 151 LOG(ERROR) << "Cannot determine proxy mode."; | 151 LOG(ERROR) << "Cannot determine proxy mode."; |
| 152 return NULL; | 152 return NULL; |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Build a new ProxyConfig instance as defined in the extension API. | 155 // Build a new ProxyConfig instance as defined in the extension API. |
| 156 scoped_ptr<base::DictionaryValue> extension_pref(new base::DictionaryValue); | 156 std::unique_ptr<base::DictionaryValue> extension_pref( |
| 157 new base::DictionaryValue); |
| 157 | 158 |
| 158 extension_pref->SetString(keys::kProxyConfigMode, | 159 extension_pref->SetString(keys::kProxyConfigMode, |
| 159 ProxyPrefs::ProxyModeToString(mode)); | 160 ProxyPrefs::ProxyModeToString(mode)); |
| 160 | 161 |
| 161 switch (mode) { | 162 switch (mode) { |
| 162 case ProxyPrefs::MODE_DIRECT: | 163 case ProxyPrefs::MODE_DIRECT: |
| 163 case ProxyPrefs::MODE_AUTO_DETECT: | 164 case ProxyPrefs::MODE_AUTO_DETECT: |
| 164 case ProxyPrefs::MODE_SYSTEM: | 165 case ProxyPrefs::MODE_SYSTEM: |
| 165 // These modes have no further parameters. | 166 // These modes have no further parameters. |
| 166 break; | 167 break; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 183 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); | 184 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); |
| 184 break; | 185 break; |
| 185 } | 186 } |
| 186 case ProxyPrefs::kModeCount: | 187 case ProxyPrefs::kModeCount: |
| 187 NOTREACHED(); | 188 NOTREACHED(); |
| 188 } | 189 } |
| 189 return extension_pref.release(); | 190 return extension_pref.release(); |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace extensions | 193 } // namespace extensions |
| OLD | NEW |