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 3 // found in the LICENSE file. 4 5 // Defines the Chrome Extensions Proxy Settings API relevant classes to realize 6 // the API as specified in the extension API JSON. 7 8 #ifndef CHROME_BROWSER_EXTENSIONS_API_PROXY_PROXY_API_H_ 9 #define CHROME_BROWSER_EXTENSIONS_API_PROXY_PROXY_API_H_ 10 11 #include <string> 12 13 #include "base/macros.h" 14 #include "base/memory/singleton.h" 15 #include "base/strings/string16.h" 16 #include "chrome/browser/extensions/api/preference/preference_api.h" 17 #include "components/proxy_config/proxy_prefs.h" 18 19 namespace base { 20 class Value; 21 } 22 23 namespace extensions { 24 class EventRouterForwarder; 25 26 // Class to convert between the representation of proxy settings used 27 // in the Proxy Settings API and the representation used in the PrefStores. 28 // This plugs into the ExtensionPreferenceAPI to get and set proxy settings. 29 class ProxyPrefTransformer : public PrefTransformerInterface { 30 public: 31 ProxyPrefTransformer(); 32 ~ProxyPrefTransformer() override; 33 34 // Implementation of PrefTransformerInterface. 35 std::unique_ptr<base::Value> ExtensionToBrowserPref( 36 const base::Value* extension_pref, 37 std::string* error, 38 bool* bad_message) override; 39 std::unique_ptr<base::Value> BrowserToExtensionPref( 40 const base::Value* browser_pref, 41 bool is_incognito_profile) override; 42 43 private: 44 DISALLOW_COPY_AND_ASSIGN(ProxyPrefTransformer); 45 }; 46 47 // This class observes proxy error events and routes them to the appropriate 48 // extensions listening to those events. All methods must be called on the IO 49 // thread unless otherwise specified. 50 class ProxyEventRouter { 51 public: 52 static ProxyEventRouter* GetInstance(); 53 54 void OnProxyError(EventRouterForwarder* event_router, 55 void* profile, 56 int error_code); 57 58 void OnPACScriptError(EventRouterForwarder* event_router, 59 void* profile, 60 int line_number, 61 const base::string16& error); 62 63 private: 64 friend struct base::DefaultSingletonTraits<ProxyEventRouter>; 65 66 ProxyEventRouter(); 67 ~ProxyEventRouter(); 68 69 DISALLOW_COPY_AND_ASSIGN(ProxyEventRouter); 70 }; 71 72 } // namespace extensions 73 74 #endif // CHROME_BROWSER_EXTENSIONS_API_PROXY_PROXY_API_H_ 75