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/string_util.h" | 9 #include "base/string_util.h" |
9 #include "base/string_tokenizer.h" | 10 #include "base/string_tokenizer.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 13 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/extensions/extension_io_event_router.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/common/extensions/extension_error_utils.h" | 17 #include "chrome/common/extensions/extension_error_utils.h" |
16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "net/base/net_errors.h" |
17 #include "net/proxy/proxy_config.h" | 20 #include "net/proxy/proxy_config.h" |
18 | 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 // The scheme for which to use a manually specified proxy, not of the proxy URI | 24 // The scheme for which to use a manually specified proxy, not of the proxy URI |
22 // itself. | 25 // itself. |
23 enum { | 26 enum { |
24 SCHEME_ALL = 0, | 27 SCHEME_ALL = 0, |
25 SCHEME_HTTP, | 28 SCHEME_HTTP, |
26 SCHEME_HTTPS, | 29 SCHEME_HTTPS, |
(...skipping 23 matching lines...) Expand all Loading... |
50 const char kProxyCfgMode[] = "mode"; | 53 const char kProxyCfgMode[] = "mode"; |
51 const char kProxyCfgPacScript[] = "pacScript"; | 54 const char kProxyCfgPacScript[] = "pacScript"; |
52 const char kProxyCfgPacScriptUrl[] = "url"; | 55 const char kProxyCfgPacScriptUrl[] = "url"; |
53 const char kProxyCfgPacScriptData[] = "data"; | 56 const char kProxyCfgPacScriptData[] = "data"; |
54 const char kProxyCfgRules[] = "rules"; | 57 const char kProxyCfgRules[] = "rules"; |
55 const char kProxyCfgRuleHost[] = "host"; | 58 const char kProxyCfgRuleHost[] = "host"; |
56 const char kProxyCfgRulePort[] = "port"; | 59 const char kProxyCfgRulePort[] = "port"; |
57 const char kProxyCfgBypassList[] = "bypassList"; | 60 const char kProxyCfgBypassList[] = "bypassList"; |
58 const char kProxyCfgScheme[] = "scheme"; | 61 const char kProxyCfgScheme[] = "scheme"; |
59 | 62 |
| 63 const char kProxyEventFatal[] = "fatal"; |
| 64 const char kProxyEventError[] = "error"; |
| 65 const char kProxyEventDetails[] = "details"; |
| 66 const char kProxyEventOnProxyError[] = "experimental.proxy.onProxyError"; |
| 67 |
| 68 |
60 const char kPACDataUrlPrefix[] = | 69 const char kPACDataUrlPrefix[] = |
61 "data:application/x-ns-proxy-autoconfig;base64,"; | 70 "data:application/x-ns-proxy-autoconfig;base64,"; |
62 | 71 |
63 COMPILE_ASSERT(SCHEME_MAX == SCHEME_FALLBACK, | 72 COMPILE_ASSERT(SCHEME_MAX == SCHEME_FALLBACK, |
64 SCHEME_MAX_must_equal_SCHEME_FALLBACK); | 73 SCHEME_MAX_must_equal_SCHEME_FALLBACK); |
65 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, | 74 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, |
66 field_name_array_is_wrong_size); | 75 field_name_array_is_wrong_size); |
67 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, | 76 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, |
68 scheme_name_array_is_wrong_size); | 77 scheme_name_array_is_wrong_size); |
69 COMPILE_ASSERT(SCHEME_ALL == 0, singleProxy_must_be_first_option); | 78 COMPILE_ASSERT(SCHEME_ALL == 0, singleProxy_must_be_first_option); |
(...skipping 24 matching lines...) Expand all Loading... |
94 if (pac_script_url_base64_encoded.find(kPACDataUrlPrefix) != 0) { | 103 if (pac_script_url_base64_encoded.find(kPACDataUrlPrefix) != 0) { |
95 return false; | 104 return false; |
96 } | 105 } |
97 std::string pac_script_base64_encoded = | 106 std::string pac_script_base64_encoded = |
98 pac_script_url_base64_encoded.substr(strlen(kPACDataUrlPrefix)); | 107 pac_script_url_base64_encoded.substr(strlen(kPACDataUrlPrefix)); |
99 return base::Base64Decode(pac_script_base64_encoded, pac_script); | 108 return base::Base64Decode(pac_script_base64_encoded, pac_script); |
100 } | 109 } |
101 | 110 |
102 } // namespace | 111 } // namespace |
103 | 112 |
| 113 // static |
| 114 ExtensionProxyEventRouter* ExtensionProxyEventRouter::GetInstance() { |
| 115 return Singleton<ExtensionProxyEventRouter>::get(); |
| 116 } |
| 117 |
| 118 ExtensionProxyEventRouter::ExtensionProxyEventRouter() { |
| 119 } |
| 120 |
| 121 ExtensionProxyEventRouter::~ExtensionProxyEventRouter() { |
| 122 } |
| 123 |
| 124 void ExtensionProxyEventRouter::OnProxyError( |
| 125 const ExtensionIOEventRouter* event_router, |
| 126 int error_code) { |
| 127 ListValue args; |
| 128 DictionaryValue* dict = new DictionaryValue(); |
| 129 dict->SetBoolean(kProxyEventFatal, true); |
| 130 dict->SetString(kProxyEventError, net::ErrorToString(error_code)); |
| 131 dict->SetString(kProxyEventDetails, ""); |
| 132 args.Append(dict); |
| 133 |
| 134 std::string json_args; |
| 135 base::JSONWriter::Write(&args, false, &json_args); |
| 136 event_router->DispatchEventToRenderers( |
| 137 kProxyEventOnProxyError, json_args, GURL()); |
| 138 } |
| 139 |
104 bool UseCustomProxySettingsFunction::GetProxyServer( | 140 bool UseCustomProxySettingsFunction::GetProxyServer( |
105 const DictionaryValue* dict, | 141 const DictionaryValue* dict, |
106 net::ProxyServer::Scheme default_scheme, | 142 net::ProxyServer::Scheme default_scheme, |
107 net::ProxyServer* proxy_server) { | 143 net::ProxyServer* proxy_server) { |
108 std::string scheme_string; // optional. | 144 std::string scheme_string; // optional. |
109 // We can safely assume that this is ASCII due to the allowed enumeration | 145 // We can safely assume that this is ASCII due to the allowed enumeration |
110 // values specified in extension_api.json. | 146 // values specified in extension_api.json. |
111 dict->GetStringASCII(kProxyCfgScheme, &scheme_string); | 147 dict->GetStringASCII(kProxyCfgScheme, &scheme_string); |
112 | 148 |
113 net::ProxyServer::Scheme scheme = | 149 net::ProxyServer::Scheme scheme = |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 break; | 581 break; |
546 case net::ProxyServer::SCHEME_DIRECT: | 582 case net::ProxyServer::SCHEME_DIRECT: |
547 case net::ProxyServer::SCHEME_INVALID: | 583 case net::ProxyServer::SCHEME_INVALID: |
548 NOTREACHED(); | 584 NOTREACHED(); |
549 return out; | 585 return out; |
550 } | 586 } |
551 out->SetString(kProxyCfgRuleHost, proxy.host_port_pair().host()); | 587 out->SetString(kProxyCfgRuleHost, proxy.host_port_pair().host()); |
552 out->SetInteger(kProxyCfgRulePort, proxy.host_port_pair().port()); | 588 out->SetInteger(kProxyCfgRulePort, proxy.host_port_pair().port()); |
553 return out; | 589 return out; |
554 } | 590 } |
OLD | NEW |