Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/extensions/api/screenlock_private/screenlock_private_api.cc

Issue 562393002: Remove unused chrome.screenlockPrivate methods (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector>
8
9 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 8 #include "base/values.h"
12 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/api/screenlock_private.h" 10 #include "chrome/common/extensions/api/screenlock_private.h"
14 #include "extensions/browser/event_router.h" 11 #include "extensions/browser/event_router.h"
15 #include "extensions/browser/image_loader.h"
16 #include "ui/gfx/image/image.h"
17 12
18 namespace screenlock = extensions::api::screenlock_private; 13 namespace screenlock = extensions::api::screenlock_private;
19 14
20 namespace extensions { 15 namespace extensions {
21 16
22 namespace { 17 namespace {
23 18
24 const char kNotLockedError[] = "Screen is not currently locked."; 19 const char kNotLockedError[] = "Screen is not currently locked.";
25 const char kInvalidIconError[] = "Invalid custom icon data.";
26
27 ScreenlockBridge::LockHandler::AuthType ToLockHandlerAuthType(
28 screenlock::AuthType auth_type) {
29 switch (auth_type) {
30 case screenlock::AUTH_TYPE_OFFLINEPASSWORD:
31 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
32 case screenlock::AUTH_TYPE_NUMERICPIN:
33 return ScreenlockBridge::LockHandler::NUMERIC_PIN;
34 case screenlock::AUTH_TYPE_USERCLICK:
35 return ScreenlockBridge::LockHandler::USER_CLICK;
36 case screenlock::AUTH_TYPE_NONE:
37 break;
38 }
39 NOTREACHED();
40 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD;
41 }
42 20
43 screenlock::AuthType FromLockHandlerAuthType( 21 screenlock::AuthType FromLockHandlerAuthType(
44 ScreenlockBridge::LockHandler::AuthType auth_type) { 22 ScreenlockBridge::LockHandler::AuthType auth_type) {
45 switch (auth_type) { 23 switch (auth_type) {
46 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD: 24 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD:
47 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; 25 return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
48 case ScreenlockBridge::LockHandler::NUMERIC_PIN: 26 case ScreenlockBridge::LockHandler::NUMERIC_PIN:
49 return screenlock::AUTH_TYPE_NUMERICPIN; 27 return screenlock::AUTH_TYPE_NUMERICPIN;
50 case ScreenlockBridge::LockHandler::USER_CLICK: 28 case ScreenlockBridge::LockHandler::USER_CLICK:
51 return screenlock::AUTH_TYPE_USERCLICK; 29 return screenlock::AUTH_TYPE_USERCLICK;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 screenlock::SetLocked::Params::Create(*args_)); 63 screenlock::SetLocked::Params::Create(*args_));
86 EXTENSION_FUNCTION_VALIDATE(params.get()); 64 EXTENSION_FUNCTION_VALIDATE(params.get());
87 if (params->locked) 65 if (params->locked)
88 ScreenlockBridge::Get()->Lock(GetProfile()); 66 ScreenlockBridge::Get()->Lock(GetProfile());
89 else 67 else
90 ScreenlockBridge::Get()->Unlock(GetProfile()); 68 ScreenlockBridge::Get()->Unlock(GetProfile());
91 SendResponse(error_.empty()); 69 SendResponse(error_.empty());
92 return true; 70 return true;
93 } 71 }
94 72
95 ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {}
96
97 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {}
98
99 bool ScreenlockPrivateShowMessageFunction::RunAsync() {
100 scoped_ptr<screenlock::ShowMessage::Params> params(
101 screenlock::ShowMessage::Params::Create(*args_));
102 EXTENSION_FUNCTION_VALIDATE(params.get());
103 ScreenlockBridge::LockHandler* locker =
104 ScreenlockBridge::Get()->lock_handler();
105 if (locker)
106 locker->ShowBannerMessage(base::UTF8ToUTF16(params->message));
107 SendResponse(error_.empty());
108 return true;
109 }
110
111 ScreenlockPrivateShowCustomIconFunction::
112 ScreenlockPrivateShowCustomIconFunction() {}
113
114 ScreenlockPrivateShowCustomIconFunction::
115 ~ScreenlockPrivateShowCustomIconFunction() {}
116
117 bool ScreenlockPrivateShowCustomIconFunction::RunAsync() {
118 scoped_ptr<screenlock::ShowCustomIcon::Params> params(
119 screenlock::ShowCustomIcon::Params::Create(*args_));
120 EXTENSION_FUNCTION_VALIDATE(params.get());
121 ScreenlockBridge::LockHandler* locker =
122 ScreenlockBridge::Get()->lock_handler();
123 if (!locker) {
124 SetError(kNotLockedError);
125 return false;
126 }
127
128 const int kMaxButtonIconSize = 40;
129 bool has_scale_100P = false;
130 std::vector<extensions::ImageLoader::ImageRepresentation> icon_info;
131 for (size_t i = 0; i < params->icon.size(); ++i) {
132 ui::ScaleFactor scale_factor;
133 if (params->icon[i]->scale_factor == 1.) {
134 scale_factor = ui::SCALE_FACTOR_100P;
135 } else if (params->icon[i]->scale_factor == 2.) {
136 scale_factor = ui::SCALE_FACTOR_200P;
137 } else {
138 continue;
139 }
140
141 ExtensionResource resource = extension()->GetResource(params->icon[i]->url);
142 if (resource.empty())
143 continue;
144
145 icon_info.push_back(
146 ImageLoader::ImageRepresentation(
147 resource,
148 ImageLoader::ImageRepresentation::RESIZE_WHEN_LARGER,
149 gfx::Size(kMaxButtonIconSize * params->icon[i]->scale_factor,
150 kMaxButtonIconSize * params->icon[i]->scale_factor),
151 scale_factor));
152 if (scale_factor == ui::SCALE_FACTOR_100P)
153 has_scale_100P = true;
154 }
155
156 if (!has_scale_100P) {
157 SetError(kInvalidIconError);
158 return false;
159 }
160
161 extensions::ImageLoader* loader = extensions::ImageLoader::Get(GetProfile());
162 loader->LoadImagesAsync(
163 extension(),
164 icon_info,
165 base::Bind(&ScreenlockPrivateShowCustomIconFunction::OnImageLoaded,
166 this));
167 return true;
168 }
169
170 void ScreenlockPrivateShowCustomIconFunction::OnImageLoaded(
171 const gfx::Image& image) {
172 ScreenlockBridge::LockHandler* locker =
173 ScreenlockBridge::Get()->lock_handler();
174 if (!locker) {
175 SetError(kNotLockedError);
176 SendResponse(false);
177 return;
178 }
179
180 ScreenlockBridge::UserPodCustomIconOptions icon;
181 icon.SetIconAsImage(image);
182 locker->ShowUserPodCustomIcon(
183 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()),
184 icon);
185 SendResponse(error_.empty());
186 }
187
188 ScreenlockPrivateHideCustomIconFunction::
189 ScreenlockPrivateHideCustomIconFunction() {
190 }
191
192 ScreenlockPrivateHideCustomIconFunction::
193 ~ScreenlockPrivateHideCustomIconFunction() {
194 }
195
196 bool ScreenlockPrivateHideCustomIconFunction::RunAsync() {
197 ScreenlockBridge::LockHandler* locker =
198 ScreenlockBridge::Get()->lock_handler();
199 if (locker) {
200 locker->HideUserPodCustomIcon(
201 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()));
202 } else {
203 SetError(kNotLockedError);
204 }
205 SendResponse(error_.empty());
206 return true;
207 }
208
209 ScreenlockPrivateSetAuthTypeFunction::ScreenlockPrivateSetAuthTypeFunction() {}
210
211 ScreenlockPrivateSetAuthTypeFunction::~ScreenlockPrivateSetAuthTypeFunction() {}
212
213 bool ScreenlockPrivateSetAuthTypeFunction::RunAsync() {
214 scoped_ptr<screenlock::SetAuthType::Params> params(
215 screenlock::SetAuthType::Params::Create(*args_));
216 EXTENSION_FUNCTION_VALIDATE(params.get());
217
218 ScreenlockBridge::LockHandler* locker =
219 ScreenlockBridge::Get()->lock_handler();
220 if (locker) {
221 std::string initial_value =
222 params->initial_value.get() ? *(params->initial_value.get()) : "";
223 locker->SetAuthType(
224 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()),
225 ToLockHandlerAuthType(params->auth_type),
226 base::UTF8ToUTF16(initial_value));
227 } else {
228 SetError(kNotLockedError);
229 }
230 SendResponse(error_.empty());
231 return true;
232 }
233
234 ScreenlockPrivateGetAuthTypeFunction::ScreenlockPrivateGetAuthTypeFunction() {}
235
236 ScreenlockPrivateGetAuthTypeFunction::~ScreenlockPrivateGetAuthTypeFunction() {}
237
238 bool ScreenlockPrivateGetAuthTypeFunction::RunAsync() {
239 ScreenlockBridge::LockHandler* locker =
240 ScreenlockBridge::Get()->lock_handler();
241 if (locker) {
242 ScreenlockBridge::LockHandler::AuthType auth_type = locker->GetAuthType(
243 ScreenlockBridge::GetAuthenticatedUserEmail(GetProfile()));
244 std::string auth_type_name =
245 screenlock::ToString(FromLockHandlerAuthType(auth_type));
246 SetResult(new base::StringValue(auth_type_name));
247 } else {
248 SetError(kNotLockedError);
249 }
250 SendResponse(error_.empty());
251 return true;
252 }
253
254 ScreenlockPrivateAcceptAuthAttemptFunction:: 73 ScreenlockPrivateAcceptAuthAttemptFunction::
255 ScreenlockPrivateAcceptAuthAttemptFunction() {} 74 ScreenlockPrivateAcceptAuthAttemptFunction() {}
256 75
257 ScreenlockPrivateAcceptAuthAttemptFunction:: 76 ScreenlockPrivateAcceptAuthAttemptFunction::
258 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} 77 ~ScreenlockPrivateAcceptAuthAttemptFunction() {}
259 78
260 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunAsync() { 79 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunAsync() {
261 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( 80 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params(
262 screenlock::AcceptAuthAttempt::Params::Create(*args_)); 81 screenlock::AcceptAuthAttempt::Params::Create(*args_));
263 EXTENSION_FUNCTION_VALIDATE(params.get()); 82 EXTENSION_FUNCTION_VALIDATE(params.get());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 scoped_ptr<base::ListValue> args(new base::ListValue()); 144 scoped_ptr<base::ListValue> args(new base::ListValue());
326 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); 145 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type)));
327 args->AppendString(value); 146 args->AppendString(value);
328 147
329 scoped_ptr<extensions::Event> event(new extensions::Event( 148 scoped_ptr<extensions::Event> event(new extensions::Event(
330 screenlock::OnAuthAttempted::kEventName, args.Pass())); 149 screenlock::OnAuthAttempted::kEventName, args.Pass()));
331 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); 150 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
332 } 151 }
333 152
334 } // namespace extensions 153 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698