OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/api/screenlock_private/screenlock_private_ap
i.h" | 5 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/image_loader.h" | 9 #include "chrome/browser/extensions/image_loader.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 screenlock::ShowMessage::Params::Create(*args_)); | 90 screenlock::ShowMessage::Params::Create(*args_)); |
91 EXTENSION_FUNCTION_VALIDATE(params.get()); | 91 EXTENSION_FUNCTION_VALIDATE(params.get()); |
92 ScreenlockBridge::LockHandler* locker = | 92 ScreenlockBridge::LockHandler* locker = |
93 ScreenlockBridge::Get()->lock_handler(); | 93 ScreenlockBridge::Get()->lock_handler(); |
94 if (locker) | 94 if (locker) |
95 locker->ShowBannerMessage(params->message); | 95 locker->ShowBannerMessage(params->message); |
96 SendResponse(error_.empty()); | 96 SendResponse(error_.empty()); |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 static const int kMaxButtonIconSize = 40; | 100 ScreenlockPrivateShowCustomIconFunction:: |
| 101 ScreenlockPrivateShowCustomIconFunction() {} |
101 | 102 |
102 ScreenlockPrivateShowButtonFunction:: | 103 ScreenlockPrivateShowCustomIconFunction:: |
103 ScreenlockPrivateShowButtonFunction() {} | 104 ~ScreenlockPrivateShowCustomIconFunction() {} |
104 | 105 |
105 ScreenlockPrivateShowButtonFunction:: | 106 bool ScreenlockPrivateShowCustomIconFunction::RunAsync() { |
106 ~ScreenlockPrivateShowButtonFunction() {} | 107 scoped_ptr<screenlock::ShowCustomIcon::Params> params( |
107 | 108 screenlock::ShowCustomIcon::Params::Create(*args_)); |
108 bool ScreenlockPrivateShowButtonFunction::RunAsync() { | |
109 scoped_ptr<screenlock::ShowButton::Params> params( | |
110 screenlock::ShowButton::Params::Create(*args_)); | |
111 EXTENSION_FUNCTION_VALIDATE(params.get()); | 109 EXTENSION_FUNCTION_VALIDATE(params.get()); |
112 ScreenlockBridge::LockHandler* locker = | 110 ScreenlockBridge::LockHandler* locker = |
113 ScreenlockBridge::Get()->lock_handler(); | 111 ScreenlockBridge::Get()->lock_handler(); |
114 if (!locker) { | 112 if (!locker) { |
115 SetError(kNotLockedError); | 113 SetError(kNotLockedError); |
116 SendResponse(false); | 114 SendResponse(false); |
117 return true; | 115 return true; |
118 } | 116 } |
| 117 |
| 118 const int kMaxButtonIconSize = 40; |
119 extensions::ImageLoader* loader = extensions::ImageLoader::Get(GetProfile()); | 119 extensions::ImageLoader* loader = extensions::ImageLoader::Get(GetProfile()); |
120 loader->LoadImageAsync( | 120 loader->LoadImageAsync( |
121 GetExtension(), GetExtension()->GetResource(params->icon), | 121 GetExtension(), |
| 122 GetExtension()->GetResource(params->icon), |
122 gfx::Size(kMaxButtonIconSize, kMaxButtonIconSize), | 123 gfx::Size(kMaxButtonIconSize, kMaxButtonIconSize), |
123 base::Bind(&ScreenlockPrivateShowButtonFunction::OnImageLoaded, this)); | 124 base::Bind(&ScreenlockPrivateShowCustomIconFunction::OnImageLoaded, |
| 125 this)); |
124 return true; | 126 return true; |
125 } | 127 } |
126 | 128 |
127 void ScreenlockPrivateShowButtonFunction::OnImageLoaded( | 129 void ScreenlockPrivateShowCustomIconFunction::OnImageLoaded( |
128 const gfx::Image& image) { | 130 const gfx::Image& image) { |
129 ScreenlockBridge::LockHandler* locker = | 131 ScreenlockBridge::LockHandler* locker = |
130 ScreenlockBridge::Get()->lock_handler(); | 132 ScreenlockBridge::Get()->lock_handler(); |
131 ScreenlockPrivateEventRouter* router = | 133 locker->ShowUserPodCustomIcon( |
132 ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(GetProfile()); | |
133 locker->ShowUserPodButton( | |
134 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()), | 134 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()), |
135 image, | 135 image); |
136 base::Bind(&ScreenlockPrivateEventRouter::OnButtonClicked, | |
137 base::Unretained(router))); | |
138 SendResponse(error_.empty()); | 136 SendResponse(error_.empty()); |
139 } | 137 } |
140 | 138 |
141 ScreenlockPrivateHideButtonFunction::ScreenlockPrivateHideButtonFunction() {} | 139 ScreenlockPrivateHideCustomIconFunction:: |
| 140 ScreenlockPrivateHideCustomIconFunction() { |
| 141 } |
142 | 142 |
143 ScreenlockPrivateHideButtonFunction::~ScreenlockPrivateHideButtonFunction() {} | 143 ScreenlockPrivateHideCustomIconFunction:: |
| 144 ~ScreenlockPrivateHideCustomIconFunction() { |
| 145 } |
144 | 146 |
145 bool ScreenlockPrivateHideButtonFunction::RunAsync() { | 147 bool ScreenlockPrivateHideCustomIconFunction::RunAsync() { |
146 ScreenlockBridge::LockHandler* locker = | 148 ScreenlockBridge::LockHandler* locker = |
147 ScreenlockBridge::Get()->lock_handler(); | 149 ScreenlockBridge::Get()->lock_handler(); |
148 if (locker) { | 150 if (locker) { |
149 locker->HideUserPodButton( | 151 locker->HideUserPodCustomIcon( |
150 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile())); | 152 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile())); |
151 } else { | 153 } else { |
152 SetError(kNotLockedError); | 154 SetError(kNotLockedError); |
153 } | 155 } |
154 SendResponse(error_.empty()); | 156 SendResponse(error_.empty()); |
155 return true; | 157 return true; |
156 } | 158 } |
157 | 159 |
158 ScreenlockPrivateSetAuthTypeFunction::ScreenlockPrivateSetAuthTypeFunction() {} | 160 ScreenlockPrivateSetAuthTypeFunction::ScreenlockPrivateSetAuthTypeFunction() {} |
159 | 161 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // static | 263 // static |
262 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* | 264 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* |
263 ScreenlockPrivateEventRouter::GetFactoryInstance() { | 265 ScreenlockPrivateEventRouter::GetFactoryInstance() { |
264 return g_factory.Pointer(); | 266 return g_factory.Pointer(); |
265 } | 267 } |
266 | 268 |
267 void ScreenlockPrivateEventRouter::Shutdown() { | 269 void ScreenlockPrivateEventRouter::Shutdown() { |
268 ScreenlockBridge::Get()->RemoveObserver(this); | 270 ScreenlockBridge::Get()->RemoveObserver(this); |
269 } | 271 } |
270 | 272 |
271 void ScreenlockPrivateEventRouter::OnButtonClicked() { | |
272 DispatchEvent(screenlock::OnButtonClicked::kEventName, NULL); | |
273 } | |
274 | |
275 void ScreenlockPrivateEventRouter::OnAuthAttempted( | 273 void ScreenlockPrivateEventRouter::OnAuthAttempted( |
276 ScreenlockBridge::LockHandler::AuthType auth_type, | 274 ScreenlockBridge::LockHandler::AuthType auth_type, |
277 const std::string& value) { | 275 const std::string& value) { |
278 scoped_ptr<base::ListValue> args(new base::ListValue()); | 276 scoped_ptr<base::ListValue> args(new base::ListValue()); |
279 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); | 277 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); |
280 args->AppendString(value); | 278 args->AppendString(value); |
281 | 279 |
282 scoped_ptr<extensions::Event> event(new extensions::Event( | 280 scoped_ptr<extensions::Event> event(new extensions::Event( |
283 screenlock::OnAuthAttempted::kEventName, args.Pass())); | 281 screenlock::OnAuthAttempted::kEventName, args.Pass())); |
284 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 282 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
285 } | 283 } |
286 | 284 |
287 } // namespace extensions | 285 } // namespace extensions |
OLD | NEW |