| 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/stringprintf.h" | 10 #include "base/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 ListValue args; | 40 scoped_ptr<ListValue> args(new ListValue()); |
| 41 DictionaryValue* dict = new DictionaryValue(); | 41 DictionaryValue* dict = new 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, ""); | 44 dict->SetString(keys::kProxyEventDetails, ""); |
| 45 args.Append(dict); | 45 args->Append(dict); |
| 46 | |
| 47 std::string json_args; | |
| 48 base::JSONWriter::Write(&args, &json_args); | |
| 49 | 46 |
| 50 if (profile) { | 47 if (profile) { |
| 51 event_router->DispatchEventToRenderers( | 48 event_router->DispatchEventToRenderers( |
| 52 keys::kProxyEventOnProxyError, json_args, profile, true, GURL()); | 49 keys::kProxyEventOnProxyError, args.Pass(), profile, true, GURL()); |
| 53 } else { | 50 } else { |
| 54 event_router->BroadcastEventToRenderers( | 51 event_router->BroadcastEventToRenderers( |
| 55 keys::kProxyEventOnProxyError, json_args, GURL()); | 52 keys::kProxyEventOnProxyError, args.Pass(), GURL()); |
| 56 } | 53 } |
| 57 } | 54 } |
| 58 | 55 |
| 59 void ProxyEventRouter::OnPACScriptError( | 56 void ProxyEventRouter::OnPACScriptError( |
| 60 EventRouterForwarder* event_router, | 57 EventRouterForwarder* event_router, |
| 61 void* profile, | 58 void* profile, |
| 62 int line_number, | 59 int line_number, |
| 63 const string16& error) { | 60 const string16& error) { |
| 64 ListValue args; | 61 scoped_ptr<ListValue> args(new ListValue()); |
| 65 DictionaryValue* dict = new DictionaryValue(); | 62 DictionaryValue* dict = new DictionaryValue(); |
| 66 dict->SetBoolean(keys::kProxyEventFatal, false); | 63 dict->SetBoolean(keys::kProxyEventFatal, false); |
| 67 dict->SetString(keys::kProxyEventError, | 64 dict->SetString(keys::kProxyEventError, |
| 68 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); | 65 net::ErrorToString(net::ERR_PAC_SCRIPT_FAILED)); |
| 69 std::string error_msg; | 66 std::string error_msg; |
| 70 if (line_number != -1) { | 67 if (line_number != -1) { |
| 71 base::SStringPrintf( | 68 base::SStringPrintf( |
| 72 &error_msg, "line: %d: %s", line_number, UTF16ToUTF8(error).c_str()); | 69 &error_msg, "line: %d: %s", line_number, UTF16ToUTF8(error).c_str()); |
| 73 } else { | 70 } else { |
| 74 error_msg = UTF16ToUTF8(error); | 71 error_msg = UTF16ToUTF8(error); |
| 75 } | 72 } |
| 76 dict->SetString(keys::kProxyEventDetails, error_msg); | 73 dict->SetString(keys::kProxyEventDetails, error_msg); |
| 77 args.Append(dict); | 74 args->Append(dict); |
| 78 | |
| 79 std::string json_args; | |
| 80 base::JSONWriter::Write(&args, &json_args); | |
| 81 | 75 |
| 82 if (profile) { | 76 if (profile) { |
| 83 event_router->DispatchEventToRenderers( | 77 event_router->DispatchEventToRenderers( |
| 84 keys::kProxyEventOnProxyError, json_args, profile, true, GURL()); | 78 keys::kProxyEventOnProxyError, args.Pass(), profile, true, GURL()); |
| 85 } else { | 79 } else { |
| 86 event_router->BroadcastEventToRenderers( | 80 event_router->BroadcastEventToRenderers( |
| 87 keys::kProxyEventOnProxyError, json_args, GURL()); | 81 keys::kProxyEventOnProxyError, args.Pass(), GURL()); |
| 88 } | 82 } |
| 89 } | 83 } |
| 90 | 84 |
| 91 ProxyPrefTransformer::ProxyPrefTransformer() { | 85 ProxyPrefTransformer::ProxyPrefTransformer() { |
| 92 } | 86 } |
| 93 | 87 |
| 94 ProxyPrefTransformer::~ProxyPrefTransformer() { | 88 ProxyPrefTransformer::~ProxyPrefTransformer() { |
| 95 } | 89 } |
| 96 | 90 |
| 97 Value* ProxyPrefTransformer::ExtensionToBrowserPref(const Value* extension_pref, | 91 Value* ProxyPrefTransformer::ExtensionToBrowserPref(const Value* extension_pref, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); | 173 extension_pref->Set(keys::kProxyConfigRules, proxy_rules_dict); |
| 180 break; | 174 break; |
| 181 } | 175 } |
| 182 case ProxyPrefs::kModeCount: | 176 case ProxyPrefs::kModeCount: |
| 183 NOTREACHED(); | 177 NOTREACHED(); |
| 184 } | 178 } |
| 185 return extension_pref.release(); | 179 return extension_pref.release(); |
| 186 } | 180 } |
| 187 | 181 |
| 188 } // namespace extensions | 182 } // namespace extensions |
| OLD | NEW |