| 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 #include "chrome/browser/extensions/extension_proxy_api.h" | 5 #include "chrome/browser/extensions/extension_proxy_api.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/string_tokenizer.h" | 10 #include "base/string_tokenizer.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/prefs/proxy_config_dictionary.h" | 13 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
| 15 #include "chrome/browser/extensions/extension_io_event_router.h" | |
| 16 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/common/extensions/extension_error_utils.h" | 16 #include "chrome/common/extensions/extension_error_utils.h" |
| 18 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 19 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 20 #include "net/proxy/proxy_config.h" | 19 #include "net/proxy/proxy_config.h" |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 // The scheme for which to use a manually specified proxy, not of the proxy URI | 23 // The scheme for which to use a manually specified proxy, not of the proxy URI |
| 25 // itself. | 24 // itself. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 return Singleton<ExtensionProxyEventRouter>::get(); | 115 return Singleton<ExtensionProxyEventRouter>::get(); |
| 117 } | 116 } |
| 118 | 117 |
| 119 ExtensionProxyEventRouter::ExtensionProxyEventRouter() { | 118 ExtensionProxyEventRouter::ExtensionProxyEventRouter() { |
| 120 } | 119 } |
| 121 | 120 |
| 122 ExtensionProxyEventRouter::~ExtensionProxyEventRouter() { | 121 ExtensionProxyEventRouter::~ExtensionProxyEventRouter() { |
| 123 } | 122 } |
| 124 | 123 |
| 125 void ExtensionProxyEventRouter::OnProxyError( | 124 void ExtensionProxyEventRouter::OnProxyError( |
| 126 const ExtensionIOEventRouter* event_router, | 125 ExtensionEventRouterForwarder* event_router, |
| 126 ProfileId profile_id, |
| 127 int error_code) { | 127 int error_code) { |
| 128 ListValue args; | 128 ListValue args; |
| 129 DictionaryValue* dict = new DictionaryValue(); | 129 DictionaryValue* dict = new DictionaryValue(); |
| 130 dict->SetBoolean(kProxyEventFatal, true); | 130 dict->SetBoolean(kProxyEventFatal, true); |
| 131 dict->SetString(kProxyEventError, net::ErrorToString(error_code)); | 131 dict->SetString(kProxyEventError, net::ErrorToString(error_code)); |
| 132 dict->SetString(kProxyEventDetails, ""); | 132 dict->SetString(kProxyEventDetails, ""); |
| 133 args.Append(dict); | 133 args.Append(dict); |
| 134 | 134 |
| 135 std::string json_args; | 135 std::string json_args; |
| 136 base::JSONWriter::Write(&args, false, &json_args); | 136 base::JSONWriter::Write(&args, false, &json_args); |
| 137 event_router->DispatchEventToRenderers( | 137 |
| 138 kProxyEventOnProxyError, json_args, GURL()); | 138 if (profile_id != Profile::InvalidProfileId) { |
| 139 event_router->DispatchEventToRenderers( |
| 140 kProxyEventOnProxyError, json_args, profile_id, true, GURL()); |
| 141 } else { |
| 142 event_router->BroadcastEventToRenderers( |
| 143 kProxyEventOnProxyError, json_args, GURL()); |
| 144 } |
| 139 } | 145 } |
| 140 | 146 |
| 141 bool SetProxySettingsFunction::GetProxyServer( | 147 bool SetProxySettingsFunction::GetProxyServer( |
| 142 const DictionaryValue* dict, | 148 const DictionaryValue* dict, |
| 143 net::ProxyServer::Scheme default_scheme, | 149 net::ProxyServer::Scheme default_scheme, |
| 144 net::ProxyServer* proxy_server) { | 150 net::ProxyServer* proxy_server) { |
| 145 std::string scheme_string; // optional. | 151 std::string scheme_string; // optional. |
| 146 // We can safely assume that this is ASCII due to the allowed enumeration | 152 // We can safely assume that this is ASCII due to the allowed enumeration |
| 147 // values specified in extension_api.json. | 153 // values specified in extension_api.json. |
| 148 dict->GetStringASCII(kProxyCfgScheme, &scheme_string); | 154 dict->GetStringASCII(kProxyCfgScheme, &scheme_string); |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 break; | 553 break; |
| 548 case net::ProxyServer::SCHEME_DIRECT: | 554 case net::ProxyServer::SCHEME_DIRECT: |
| 549 case net::ProxyServer::SCHEME_INVALID: | 555 case net::ProxyServer::SCHEME_INVALID: |
| 550 NOTREACHED(); | 556 NOTREACHED(); |
| 551 return out; | 557 return out; |
| 552 } | 558 } |
| 553 out->SetString(kProxyCfgRuleHost, proxy.host_port_pair().host()); | 559 out->SetString(kProxyCfgRuleHost, proxy.host_port_pair().host()); |
| 554 out->SetInteger(kProxyCfgRulePort, proxy.host_port_pair().port()); | 560 out->SetInteger(kProxyCfgRulePort, proxy.host_port_pair().port()); |
| 555 return out; | 561 return out; |
| 556 } | 562 } |
| OLD | NEW |