1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_ 7 8 #include <string> 9 10 #include "chrome/browser/extensions/chrome_extension_function.h" 11 #include "chrome/browser/signin/screenlock_bridge.h" 12 #include "extensions/browser/browser_context_keyed_api_factory.h" 13 14 namespace gfx { 15 class Image; 16 } 17 18 namespace extensions { 19 20 class ScreenlockPrivateGetLockedFunction : public ChromeAsyncExtensionFunction { 21 public: 22 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getLocked", 23 SCREENLOCKPRIVATE_GETLOCKED) 24 ScreenlockPrivateGetLockedFunction(); 25 virtual bool RunAsync() OVERRIDE; 26 27 private: 28 virtual ~ScreenlockPrivateGetLockedFunction(); 29 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetLockedFunction); 30 }; 31 32 class ScreenlockPrivateSetLockedFunction : public ChromeAsyncExtensionFunction { 33 public: 34 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setLocked", 35 SCREENLOCKPRIVATE_SETLOCKED) 36 ScreenlockPrivateSetLockedFunction(); 37 virtual bool RunAsync() OVERRIDE; 38 39 private: 40 virtual ~ScreenlockPrivateSetLockedFunction(); 41 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetLockedFunction); 42 }; 43 44 class ScreenlockPrivateShowMessageFunction 45 : public ChromeAsyncExtensionFunction { 46 public: 47 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showMessage", 48 SCREENLOCKPRIVATE_SHOWMESSAGE) 49 ScreenlockPrivateShowMessageFunction(); 50 virtual bool RunAsync() OVERRIDE; 51 52 private: 53 virtual ~ScreenlockPrivateShowMessageFunction(); 54 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowMessageFunction); 55 }; 56 57 class ScreenlockPrivateShowCustomIconFunction 58 : public ChromeAsyncExtensionFunction { 59 public: 60 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showCustomIcon", 61 SCREENLOCKPRIVATE_SHOWCUSTOMICON) 62 ScreenlockPrivateShowCustomIconFunction(); 63 virtual bool RunAsync() OVERRIDE; 64 65 private: 66 virtual ~ScreenlockPrivateShowCustomIconFunction(); 67 void OnImageLoaded(const gfx::Image& image); 68 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowCustomIconFunction); 69 }; 70 71 class ScreenlockPrivateHideCustomIconFunction 72 : public ChromeAsyncExtensionFunction { 73 public: 74 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.hideCustomIcon", 75 SCREENLOCKPRIVATE_HIDECUSTOMICON) 76 ScreenlockPrivateHideCustomIconFunction(); 77 virtual bool RunAsync() OVERRIDE; 78 79 private: 80 virtual ~ScreenlockPrivateHideCustomIconFunction(); 81 void OnImageLoaded(const gfx::Image& image); 82 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateHideCustomIconFunction); 83 }; 84 85 class ScreenlockPrivateSetAuthTypeFunction 86 : public ChromeAsyncExtensionFunction { 87 public: 88 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setAuthType", 89 SCREENLOCKPRIVATE_SETAUTHTYPE) 90 ScreenlockPrivateSetAuthTypeFunction(); 91 virtual bool RunAsync() OVERRIDE; 92 93 private: 94 virtual ~ScreenlockPrivateSetAuthTypeFunction(); 95 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetAuthTypeFunction); 96 }; 97 98 class ScreenlockPrivateGetAuthTypeFunction 99 : public ChromeAsyncExtensionFunction { 100 public: 101 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getAuthType", 102 SCREENLOCKPRIVATE_GETAUTHTYPE) 103 ScreenlockPrivateGetAuthTypeFunction(); 104 virtual bool RunAsync() OVERRIDE; 105 106 private: 107 virtual ~ScreenlockPrivateGetAuthTypeFunction(); 108 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetAuthTypeFunction); 109 }; 110 111 class ScreenlockPrivateAcceptAuthAttemptFunction 112 : public ChromeAsyncExtensionFunction { 113 public: 114 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.acceptAuthAttempt", 115 SCREENLOCKPRIVATE_ACCEPTAUTHATTEMPT) 116 ScreenlockPrivateAcceptAuthAttemptFunction(); 117 virtual bool RunAsync() OVERRIDE; 118 119 private: 120 virtual ~ScreenlockPrivateAcceptAuthAttemptFunction(); 121 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateAcceptAuthAttemptFunction); 122 }; 123 124 class ScreenlockPrivateEventRouter : public extensions::BrowserContextKeyedAPI, 125 public ScreenlockBridge::Observer { 126 public: 127 explicit ScreenlockPrivateEventRouter(content::BrowserContext* context); 128 virtual ~ScreenlockPrivateEventRouter(); 129 130 void OnAuthAttempted(ScreenlockBridge::LockHandler::AuthType auth_type, 131 const std::string& value); 132 133 // BrowserContextKeyedAPI 134 static extensions::BrowserContextKeyedAPIFactory< 135 ScreenlockPrivateEventRouter>* 136 GetFactoryInstance(); 137 virtual void Shutdown() OVERRIDE; 138 139 // ScreenlockBridge::Observer 140 virtual void OnScreenDidLock() OVERRIDE; 141 virtual void OnScreenDidUnlock() OVERRIDE; 142 143 private: 144 friend class extensions::BrowserContextKeyedAPIFactory< 145 ScreenlockPrivateEventRouter>; 146 147 // BrowserContextKeyedAPI service_name()148 static const char* service_name() { 149 return "ScreenlockPrivateEventRouter"; 150 } 151 static const bool kServiceIsNULLWhileTesting = true; 152 static const bool kServiceRedirectedInIncognito = true; 153 154 void DispatchEvent(const std::string& event_name, base::Value* arg); 155 156 content::BrowserContext* browser_context_; 157 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateEventRouter); 158 }; 159 160 } // namespace extensions 161 162 #endif // CHROME_BROWSER_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_ 163