| OLD | NEW |
| 1 // Copyright (c) 2011 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/extension_proxy_api.h" | 7 #include "chrome/browser/extensions/api/proxy/proxy_api.h" |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/proxy/proxy_api_constants.h" |
| 14 #include "chrome/browser/extensions/api/proxy/proxy_api_helpers.h" |
| 13 #include "chrome/browser/extensions/extension_event_router_forwarder.h" | 15 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
| 14 #include "chrome/browser/extensions/extension_proxy_api_constants.h" | |
| 15 #include "chrome/browser/extensions/extension_proxy_api_helpers.h" | |
| 16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 17 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 | 19 |
| 20 namespace helpers = extension_proxy_api_helpers; | 20 namespace extensions { |
| 21 namespace keys = extension_proxy_api_constants; | 21 |
| 22 namespace helpers = proxy_api_helpers; |
| 23 namespace keys = proxy_api_constants; |
| 22 | 24 |
| 23 // static | 25 // static |
| 24 ExtensionProxyEventRouter* ExtensionProxyEventRouter::GetInstance() { | 26 ProxyEventRouter* ProxyEventRouter::GetInstance() { |
| 25 return Singleton<ExtensionProxyEventRouter>::get(); | 27 return Singleton<ProxyEventRouter>::get(); |
| 26 } | 28 } |
| 27 | 29 |
| 28 ExtensionProxyEventRouter::ExtensionProxyEventRouter() { | 30 ProxyEventRouter::ProxyEventRouter() { |
| 29 } | 31 } |
| 30 | 32 |
| 31 ExtensionProxyEventRouter::~ExtensionProxyEventRouter() { | 33 ProxyEventRouter::~ProxyEventRouter() { |
| 32 } | 34 } |
| 33 | 35 |
| 34 void ExtensionProxyEventRouter::OnProxyError( | 36 void ProxyEventRouter::OnProxyError( |
| 35 ExtensionEventRouterForwarder* event_router, | 37 ExtensionEventRouterForwarder* event_router, |
| 36 void* profile, | 38 void* profile, |
| 37 int error_code) { | 39 int error_code) { |
| 38 ListValue args; | 40 ListValue args; |
| 39 DictionaryValue* dict = new DictionaryValue(); | 41 DictionaryValue* dict = new DictionaryValue(); |
| 40 dict->SetBoolean(keys::kProxyEventFatal, true); | 42 dict->SetBoolean(keys::kProxyEventFatal, true); |
| 41 dict->SetString(keys::kProxyEventError, net::ErrorToString(error_code)); | 43 dict->SetString(keys::kProxyEventError, net::ErrorToString(error_code)); |
| 42 dict->SetString(keys::kProxyEventDetails, ""); | 44 dict->SetString(keys::kProxyEventDetails, ""); |
| 43 args.Append(dict); | 45 args.Append(dict); |
| 44 | 46 |
| 45 std::string json_args; | 47 std::string json_args; |
| 46 base::JSONWriter::Write(&args, false, &json_args); | 48 base::JSONWriter::Write(&args, false, &json_args); |
| 47 | 49 |
| 48 if (profile) { | 50 if (profile) { |
| 49 event_router->DispatchEventToRenderers( | 51 event_router->DispatchEventToRenderers( |
| 50 keys::kProxyEventOnProxyError, json_args, profile, true, GURL()); | 52 keys::kProxyEventOnProxyError, json_args, profile, true, GURL()); |
| 51 } else { | 53 } else { |
| 52 event_router->BroadcastEventToRenderers( | 54 event_router->BroadcastEventToRenderers( |
| 53 keys::kProxyEventOnProxyError, json_args, GURL()); | 55 keys::kProxyEventOnProxyError, json_args, GURL()); |
| 54 } | 56 } |
| 55 } | 57 } |
| 56 | 58 |
| 57 void ExtensionProxyEventRouter::OnPACScriptError( | 59 void ProxyEventRouter::OnPACScriptError( |
| 58 ExtensionEventRouterForwarder* event_router, | 60 ExtensionEventRouterForwarder* event_router, |
| 59 void* profile, | 61 void* profile, |
| 60 int line_number, | 62 int line_number, |
| 61 const string16& error) { | 63 const string16& error) { |
| 62 ListValue args; | 64 ListValue args; |
| 63 DictionaryValue* dict = new DictionaryValue(); | 65 DictionaryValue* dict = new DictionaryValue(); |
| 64 dict->SetBoolean(keys::kProxyEventFatal, false); | 66 dict->SetBoolean(keys::kProxyEventFatal, false); |
| 65 dict->SetString(keys::kProxyEventError, | 67 dict->SetString(keys::kProxyEventError, |
| 66 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); | 68 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); |
| 67 std::string error_msg; | 69 std::string error_msg; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 if (!proxy_rules_dict) | 177 if (!proxy_rules_dict) |
| 176 return NULL; | 178 return NULL; |
| 177 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); | 179 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); |
| 178 break; | 180 break; |
| 179 } | 181 } |
| 180 case ProxyPrefs::kModeCount: | 182 case ProxyPrefs::kModeCount: |
| 181 NOTREACHED(); | 183 NOTREACHED(); |
| 182 } | 184 } |
| 183 return extension_pref.release(); | 185 return extension_pref.release(); |
| 184 } | 186 } |
| 187 |
| 188 } // namespace extensions |
| OLD | NEW |