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 "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 ProxyEventRouter::ProxyEventRouter() { | 30 ProxyEventRouter::ProxyEventRouter() { |
31 } | 31 } |
32 | 32 |
33 ProxyEventRouter::~ProxyEventRouter() { | 33 ProxyEventRouter::~ProxyEventRouter() { |
34 } | 34 } |
35 | 35 |
36 void ProxyEventRouter::OnProxyError( | 36 void ProxyEventRouter::OnProxyError( |
37 EventRouterForwarder* event_router, | 37 EventRouterForwarder* event_router, |
38 void* profile, | 38 void* profile, |
39 int error_code) { | 39 int error_code) { |
40 scoped_ptr<ListValue> args(new ListValue()); | 40 scoped_ptr<base::ListValue> args(new base::ListValue()); |
41 DictionaryValue* dict = new DictionaryValue(); | 41 base::DictionaryValue* dict = new base::DictionaryValue(); |
42 dict->SetBoolean(keys::kProxyEventFatal, true); | 42 dict->SetBoolean(keys::kProxyEventFatal, true); |
43 dict->SetString(keys::kProxyEventError, net::ErrorToString(error_code)); | 43 dict->SetString(keys::kProxyEventError, net::ErrorToString(error_code)); |
44 dict->SetString(keys::kProxyEventDetails, std::string()); | 44 dict->SetString(keys::kProxyEventDetails, std::string()); |
45 args->Append(dict); | 45 args->Append(dict); |
46 | 46 |
47 if (profile) { | 47 if (profile) { |
48 event_router->DispatchEventToRenderers( | 48 event_router->DispatchEventToRenderers( |
49 keys::kProxyEventOnProxyError, args.Pass(), profile, true, GURL()); | 49 keys::kProxyEventOnProxyError, args.Pass(), profile, true, GURL()); |
50 } else { | 50 } else { |
51 event_router->BroadcastEventToRenderers( | 51 event_router->BroadcastEventToRenderers( |
52 keys::kProxyEventOnProxyError, args.Pass(), GURL()); | 52 keys::kProxyEventOnProxyError, args.Pass(), GURL()); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 void ProxyEventRouter::OnPACScriptError( | 56 void ProxyEventRouter::OnPACScriptError( |
57 EventRouterForwarder* event_router, | 57 EventRouterForwarder* event_router, |
58 void* profile, | 58 void* profile, |
59 int line_number, | 59 int line_number, |
60 const string16& error) { | 60 const string16& error) { |
61 scoped_ptr<ListValue> args(new ListValue()); | 61 scoped_ptr<base::ListValue> args(new base::ListValue()); |
62 DictionaryValue* dict = new DictionaryValue(); | 62 base::DictionaryValue* dict = new base::DictionaryValue(); |
63 dict->SetBoolean(keys::kProxyEventFatal, false); | 63 dict->SetBoolean(keys::kProxyEventFatal, false); |
64 dict->SetString(keys::kProxyEventError, | 64 dict->SetString(keys::kProxyEventError, |
65 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); | 65 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); |
66 std::string error_msg; | 66 std::string error_msg; |
67 if (line_number != -1) { | 67 if (line_number != -1) { |
68 base::SStringPrintf( | 68 base::SStringPrintf( |
69 &error_msg, "line: %d: %s", line_number, UTF16ToUTF8(error).c_str()); | 69 &error_msg, "line: %d: %s", line_number, UTF16ToUTF8(error).c_str()); |
70 } else { | 70 } else { |
71 error_msg = UTF16ToUTF8(error); | 71 error_msg = UTF16ToUTF8(error); |
72 } | 72 } |
(...skipping 15 matching lines...) Expand all Loading... |
88 ProxyPrefTransformer::~ProxyPrefTransformer() { | 88 ProxyPrefTransformer::~ProxyPrefTransformer() { |
89 } | 89 } |
90 | 90 |
91 Value* ProxyPrefTransformer::ExtensionToBrowserPref(const Value* extension_pref, | 91 Value* ProxyPrefTransformer::ExtensionToBrowserPref(const Value* extension_pref, |
92 std::string* error, | 92 std::string* error, |
93 bool* bad_message) { | 93 bool* bad_message) { |
94 // When ExtensionToBrowserPref is called, the format of |extension_pref| | 94 // When ExtensionToBrowserPref is called, the format of |extension_pref| |
95 // has been verified already by the extension API to match the schema | 95 // has been verified already by the extension API to match the schema |
96 // defined in the extension API JSON. | 96 // defined in the extension API JSON. |
97 CHECK(extension_pref->IsType(Value::TYPE_DICTIONARY)); | 97 CHECK(extension_pref->IsType(Value::TYPE_DICTIONARY)); |
98 const DictionaryValue* config = | 98 const base::DictionaryValue* config = |
99 static_cast<const DictionaryValue*>(extension_pref); | 99 static_cast<const base::DictionaryValue*>(extension_pref); |
100 | 100 |
101 // Extract the various pieces of information passed to | 101 // Extract the various pieces of information passed to |
102 // chrome.proxy.settings.set(). Several of these strings will | 102 // chrome.proxy.settings.set(). Several of these strings will |
103 // remain blank no respective values have been passed to set(). | 103 // remain blank no respective values have been passed to set(). |
104 // If a values has been passed to set but could not be parsed, we bail | 104 // If a values has been passed to set but could not be parsed, we bail |
105 // out and return NULL. | 105 // out and return NULL. |
106 ProxyPrefs::ProxyMode mode_enum; | 106 ProxyPrefs::ProxyMode mode_enum; |
107 bool pac_mandatory; | 107 bool pac_mandatory; |
108 std::string pac_url; | 108 std::string pac_url; |
109 std::string pac_data; | 109 std::string pac_data; |
(...skipping 18 matching lines...) Expand all Loading... |
128 mode_enum, pac_mandatory, pac_url, pac_data, proxy_rules_string, | 128 mode_enum, pac_mandatory, pac_url, pac_data, proxy_rules_string, |
129 bypass_list, error); | 129 bypass_list, error); |
130 } | 130 } |
131 | 131 |
132 Value* ProxyPrefTransformer::BrowserToExtensionPref(const Value* browser_pref) { | 132 Value* ProxyPrefTransformer::BrowserToExtensionPref(const Value* browser_pref) { |
133 CHECK(browser_pref->IsType(Value::TYPE_DICTIONARY)); | 133 CHECK(browser_pref->IsType(Value::TYPE_DICTIONARY)); |
134 | 134 |
135 // This is a dictionary wrapper that exposes the proxy configuration stored in | 135 // This is a dictionary wrapper that exposes the proxy configuration stored in |
136 // the browser preferences. | 136 // the browser preferences. |
137 ProxyConfigDictionary config( | 137 ProxyConfigDictionary config( |
138 static_cast<const DictionaryValue*>(browser_pref)); | 138 static_cast<const base::DictionaryValue*>(browser_pref)); |
139 | 139 |
140 ProxyPrefs::ProxyMode mode; | 140 ProxyPrefs::ProxyMode mode; |
141 if (!config.GetMode(&mode)) { | 141 if (!config.GetMode(&mode)) { |
142 LOG(ERROR) << "Cannot determine proxy mode."; | 142 LOG(ERROR) << "Cannot determine proxy mode."; |
143 return NULL; | 143 return NULL; |
144 } | 144 } |
145 | 145 |
146 // Build a new ProxyConfig instance as defined in the extension API. | 146 // Build a new ProxyConfig instance as defined in the extension API. |
147 scoped_ptr<DictionaryValue> extension_pref(new DictionaryValue); | 147 scoped_ptr<base::DictionaryValue> extension_pref(new base::DictionaryValue); |
148 | 148 |
149 extension_pref->SetString(keys::kProxyConfigMode, | 149 extension_pref->SetString(keys::kProxyConfigMode, |
150 ProxyPrefs::ProxyModeToString(mode)); | 150 ProxyPrefs::ProxyModeToString(mode)); |
151 | 151 |
152 switch (mode) { | 152 switch (mode) { |
153 case ProxyPrefs::MODE_DIRECT: | 153 case ProxyPrefs::MODE_DIRECT: |
154 case ProxyPrefs::MODE_AUTO_DETECT: | 154 case ProxyPrefs::MODE_AUTO_DETECT: |
155 case ProxyPrefs::MODE_SYSTEM: | 155 case ProxyPrefs::MODE_SYSTEM: |
156 // These modes have no further parameters. | 156 // These modes have no further parameters. |
157 break; | 157 break; |
158 case ProxyPrefs::MODE_PAC_SCRIPT: { | 158 case ProxyPrefs::MODE_PAC_SCRIPT: { |
159 // A PAC URL either point to a PAC script or contain a base64 encoded | 159 // A PAC URL either point to a PAC script or contain a base64 encoded |
160 // PAC script. In either case we build a PacScript dictionary as defined | 160 // PAC script. In either case we build a PacScript dictionary as defined |
161 // in the extension API. | 161 // in the extension API. |
162 DictionaryValue* pac_dict = helpers::CreatePacScriptDict(config); | 162 base::DictionaryValue* pac_dict = helpers::CreatePacScriptDict(config); |
163 if (!pac_dict) | 163 if (!pac_dict) |
164 return NULL; | 164 return NULL; |
165 extension_pref->Set(keys::kProxyConfigPacScript, pac_dict); | 165 extension_pref->Set(keys::kProxyConfigPacScript, pac_dict); |
166 break; | 166 break; |
167 } | 167 } |
168 case ProxyPrefs::MODE_FIXED_SERVERS: { | 168 case ProxyPrefs::MODE_FIXED_SERVERS: { |
169 // Build ProxyRules dictionary according to the extension API. | 169 // Build ProxyRules dictionary according to the extension API. |
170 DictionaryValue* proxy_rules_dict = helpers::CreateProxyRulesDict(config); | 170 base::DictionaryValue* proxy_rules_dict = |
| 171 helpers::CreateProxyRulesDict(config); |
171 if (!proxy_rules_dict) | 172 if (!proxy_rules_dict) |
172 return NULL; | 173 return NULL; |
173 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); | 174 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); |
174 break; | 175 break; |
175 } | 176 } |
176 case ProxyPrefs::kModeCount: | 177 case ProxyPrefs::kModeCount: |
177 NOTREACHED(); | 178 NOTREACHED(); |
178 } | 179 } |
179 return extension_pref.release(); | 180 return extension_pref.release(); |
180 } | 181 } |
181 | 182 |
182 } // namespace extensions | 183 } // namespace extensions |
OLD | NEW |