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 #include "chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.h" |
6 | 6 |
7 #include "base/command_line.h" | |
Nikita (slow)
2012/06/07 15:26:55
nit: sort
Ivan Korotkov
2012/06/09 14:19:01
Done.
| |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/chromeos/login/camera_detector.h" | 13 #include "chrome/browser/chromeos/login/camera_detector.h" |
13 #include "chrome/browser/chromeos/login/default_user_images.h" | 14 #include "chrome/browser/chromeos/login/default_user_images.h" |
14 #include "chrome/browser/chromeos/login/user.h" | 15 #include "chrome/browser/chromeos/login/user.h" |
15 #include "chrome/browser/chromeos/login/webui_login_display.h" | 16 #include "chrome/browser/chromeos/login/webui_login_display.h" |
16 #include "chrome/browser/chromeos/options/take_photo_dialog.h" | 17 #include "chrome/browser/chromeos/options/take_photo_dialog.h" |
17 #include "chrome/browser/ui/webui/web_ui_util.h" | 18 #include "chrome/browser/ui/webui/web_ui_util.h" |
19 #include "chrome/common/chrome_switches.h" | |
18 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
19 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // UserImage screen ID. | 27 // UserImage screen ID. |
26 const char kUserImageScreen[] = "user-image"; | 28 const char kUserImageScreen[] = "user-image"; |
27 | 29 |
(...skipping 25 matching lines...) Expand all Loading... | |
53 localized_strings->SetString("userImageScreenDescription", | 55 localized_strings->SetString("userImageScreenDescription", |
54 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TEXT)); | 56 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TEXT)); |
55 localized_strings->SetString("takePhoto", | 57 localized_strings->SetString("takePhoto", |
56 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_TAKE_PHOTO)); | 58 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_TAKE_PHOTO)); |
57 localized_strings->SetString("profilePhoto", | 59 localized_strings->SetString("profilePhoto", |
58 l10n_util::GetStringUTF16(IDS_IMAGE_SCREEN_PROFILE_PHOTO)); | 60 l10n_util::GetStringUTF16(IDS_IMAGE_SCREEN_PROFILE_PHOTO)); |
59 localized_strings->SetString("profilePhotoLoading", | 61 localized_strings->SetString("profilePhotoLoading", |
60 l10n_util::GetStringUTF16(IDS_IMAGE_SCREEN_PROFILE_LOADING_PHOTO)); | 62 l10n_util::GetStringUTF16(IDS_IMAGE_SCREEN_PROFILE_LOADING_PHOTO)); |
61 localized_strings->SetString("okButtonText", | 63 localized_strings->SetString("okButtonText", |
62 l10n_util::GetStringUTF16(IDS_OK)); | 64 l10n_util::GetStringUTF16(IDS_OK)); |
65 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHtml5Camera)) | |
66 localized_strings->SetString("cameraType", "webrtc"); | |
67 else | |
68 localized_strings->SetString("cameraType", "old"); | |
69 localized_strings->SetString("userImagesGridSrc", "../user_images_grid.js"); | |
Nikita (slow)
2012/06/07 15:26:55
Is this somekind of hack till code is refactored i
Ivan Korotkov
2012/06/09 14:19:01
Obsolete hack, removed.
| |
63 } | 70 } |
64 | 71 |
65 void UserImageScreenHandler::Initialize() { | 72 void UserImageScreenHandler::Initialize() { |
66 ListValue image_urls; | 73 ListValue image_urls; |
67 for (int i = 0; i < kDefaultImagesCount; ++i) { | 74 for (int i = 0; i < kDefaultImagesCount; ++i) { |
68 image_urls.Append(new StringValue(GetDefaultImageUrl(i))); | 75 image_urls.Append(new StringValue(GetDefaultImageUrl(i))); |
69 } | 76 } |
70 web_ui()->CallJavascriptFunction("oobe.UserImageScreen.setUserImages", | 77 web_ui()->CallJavascriptFunction("oobe.UserImageScreen.setUserImages", |
71 image_urls); | 78 image_urls); |
72 | 79 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 void UserImageScreenHandler::UpdateVideoFrame(const SkBitmap& frame) { | 127 void UserImageScreenHandler::UpdateVideoFrame(const SkBitmap& frame) { |
121 } | 128 } |
122 | 129 |
123 void UserImageScreenHandler::ShowCameraError() { | 130 void UserImageScreenHandler::ShowCameraError() { |
124 } | 131 } |
125 | 132 |
126 void UserImageScreenHandler::ShowCameraInitializing() { | 133 void UserImageScreenHandler::ShowCameraInitializing() { |
127 } | 134 } |
128 | 135 |
129 void UserImageScreenHandler::CheckCameraPresence() { | 136 void UserImageScreenHandler::CheckCameraPresence() { |
137 // For WebRTC, camera presence checked is done on JS side. | |
138 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHtml5Camera)) | |
139 return; | |
130 CameraDetector::StartPresenceCheck( | 140 CameraDetector::StartPresenceCheck( |
131 base::Bind(&UserImageScreenHandler::OnCameraPresenceCheckDone, | 141 base::Bind(&UserImageScreenHandler::OnCameraPresenceCheckDone, |
132 weak_factory_.GetWeakPtr())); | 142 weak_factory_.GetWeakPtr())); |
133 } | 143 } |
134 | 144 |
135 bool UserImageScreenHandler::IsCapturing() const { | 145 bool UserImageScreenHandler::IsCapturing() const { |
136 return false; | 146 return false; |
137 } | 147 } |
138 | 148 |
139 void UserImageScreenHandler::RegisterMessages() { | 149 void UserImageScreenHandler::RegisterMessages() { |
140 web_ui()->RegisterMessageCallback("takePhoto", | 150 web_ui()->RegisterMessageCallback("takePhoto", |
141 base::Bind(&UserImageScreenHandler::HandleTakePhoto, | 151 base::Bind(&UserImageScreenHandler::HandleTakePhoto, |
142 base::Unretained(this))); | 152 base::Unretained(this))); |
153 web_ui()->RegisterMessageCallback("photoTaken", | |
154 base::Bind(&UserImageScreenHandler::HandlePhotoTaken, | |
155 base::Unretained(this))); | |
143 web_ui()->RegisterMessageCallback("selectImage", | 156 web_ui()->RegisterMessageCallback("selectImage", |
144 base::Bind(&UserImageScreenHandler::HandleSelectImage, | 157 base::Bind(&UserImageScreenHandler::HandleSelectImage, |
145 base::Unretained(this))); | 158 base::Unretained(this))); |
146 web_ui()->RegisterMessageCallback("onUserImageAccepted", | 159 web_ui()->RegisterMessageCallback("onUserImageAccepted", |
147 base::Bind(&UserImageScreenHandler::HandleImageAccepted, | 160 base::Bind(&UserImageScreenHandler::HandleImageAccepted, |
148 base::Unretained(this))); | 161 base::Unretained(this))); |
149 web_ui()->RegisterMessageCallback("onUserImageScreenShown", | 162 web_ui()->RegisterMessageCallback("onUserImageScreenShown", |
150 base::Bind(&UserImageScreenHandler::HandleScreenShown, | 163 base::Bind(&UserImageScreenHandler::HandleScreenShown, |
151 base::Unretained(this))); | 164 base::Unretained(this))); |
152 } | 165 } |
(...skipping 22 matching lines...) Expand all Loading... | |
175 | 188 |
176 void UserImageScreenHandler::OnPhotoAccepted(const gfx::ImageSkia& photo) { | 189 void UserImageScreenHandler::OnPhotoAccepted(const gfx::ImageSkia& photo) { |
177 user_photo_ = photo; | 190 user_photo_ = photo; |
178 user_photo_data_url_ = web_ui_util::GetImageDataUrl(user_photo_); | 191 user_photo_data_url_ = web_ui_util::GetImageDataUrl(user_photo_); |
179 selected_image_ = User::kExternalImageIndex; | 192 selected_image_ = User::kExternalImageIndex; |
180 base::StringValue data_url(user_photo_data_url_); | 193 base::StringValue data_url(user_photo_data_url_); |
181 web_ui()->CallJavascriptFunction("oobe.UserImageScreen.setUserPhoto", | 194 web_ui()->CallJavascriptFunction("oobe.UserImageScreen.setUserPhoto", |
182 data_url); | 195 data_url); |
183 } | 196 } |
184 | 197 |
198 void UserImageScreenHandler::HandlePhotoTaken(const base::ListValue* args) { | |
199 std::string image_url; | |
200 if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url)) | |
201 NOTREACHED(); | |
202 DCHECK(!image_url.empty()); | |
203 user_photo_data_url_ = image_url; | |
204 user_photo_ = web_ui_util::GetImageFromDataUrl(image_url); | |
205 } | |
206 | |
185 void UserImageScreenHandler::HandleTakePhoto(const base::ListValue* args) { | 207 void UserImageScreenHandler::HandleTakePhoto(const base::ListValue* args) { |
186 DCHECK(args && args->empty()); | 208 DCHECK(args && args->empty()); |
187 views::Widget* window = views::Widget::CreateWindowWithParent( | 209 views::Widget* window = views::Widget::CreateWindowWithParent( |
188 new TakePhotoDialog(this), GetNativeWindow()); | 210 new TakePhotoDialog(this), GetNativeWindow()); |
189 window->SetAlwaysOnTop(true); | 211 window->SetAlwaysOnTop(true); |
190 window->Show(); | 212 window->Show(); |
191 } | 213 } |
192 | 214 |
193 void UserImageScreenHandler::HandleSelectImage(const base::ListValue* args) { | 215 void UserImageScreenHandler::HandleSelectImage(const base::ListValue* args) { |
194 std::string image_url; | 216 std::string image_url; |
195 if (!args || | 217 if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url)) |
196 args->GetSize() != 1 || | |
197 !args->GetString(0, &image_url)) { | |
198 NOTREACHED(); | 218 NOTREACHED(); |
199 return; | |
200 } | |
201 if (image_url.empty()) | 219 if (image_url.empty()) |
202 return; | 220 return; |
203 | 221 |
204 int user_image_index = User::kInvalidImageIndex; | 222 int user_image_index = User::kInvalidImageIndex; |
205 if (IsDefaultImageUrl(image_url, &user_image_index)) { | 223 if (IsDefaultImageUrl(image_url, &user_image_index)) { |
206 selected_image_ = user_image_index; | 224 selected_image_ = user_image_index; |
207 } else if (image_url == user_photo_data_url_) { | 225 } else if (image_url == user_photo_data_url_) { |
208 selected_image_ = User::kExternalImageIndex; | 226 selected_image_ = User::kExternalImageIndex; |
209 } else { | 227 } else { |
210 selected_image_ = User::kProfileImageIndex; | 228 selected_image_ = User::kProfileImageIndex; |
(...skipping 13 matching lines...) Expand all Loading... | |
224 screen_->OnProfileImageSelected(); | 242 screen_->OnProfileImageSelected(); |
225 break; | 243 break; |
226 | 244 |
227 default: | 245 default: |
228 DCHECK(selected_image_ >= 0 && selected_image_ < kDefaultImagesCount); | 246 DCHECK(selected_image_ >= 0 && selected_image_ < kDefaultImagesCount); |
229 screen_->OnDefaultImageSelected(selected_image_); | 247 screen_->OnDefaultImageSelected(selected_image_); |
230 } | 248 } |
231 } | 249 } |
232 | 250 |
233 void UserImageScreenHandler::HandleScreenShown(const base::ListValue* args) { | 251 void UserImageScreenHandler::HandleScreenShown(const base::ListValue* args) { |
252 CheckCameraPresence(); | |
Nikita (slow)
2012/06/07 15:26:55
Remove?
Ivan Korotkov
2012/06/09 14:19:01
Done.
| |
253 return; | |
234 DCHECK(args && args->empty()); | 254 DCHECK(args && args->empty()); |
235 DCHECK(!screen_show_time_.is_null()); | 255 DCHECK(!screen_show_time_.is_null()); |
236 | 256 |
237 base::TimeDelta delta = base::Time::Now() - screen_show_time_; | 257 base::TimeDelta delta = base::Time::Now() - screen_show_time_; |
238 VLOG(1) << "Screen load time: " << delta.InSecondsF(); | 258 VLOG(1) << "Screen load time: " << delta.InSecondsF(); |
239 UMA_HISTOGRAM_TIMES("UserImage.ScreenIsShownTime", delta); | 259 UMA_HISTOGRAM_TIMES("UserImage.ScreenIsShownTime", delta); |
240 } | 260 } |
241 | 261 |
242 void UserImageScreenHandler::OnCameraPresenceCheckDone() { | 262 void UserImageScreenHandler::OnCameraPresenceCheckDone() { |
263 // For WebRTC, camera presence checked is done on JS side. | |
Nikita (slow)
2012/06/07 15:26:55
You don't need this check here as you CamerDetecto
Ivan Korotkov
2012/06/09 14:19:01
Done.
| |
264 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHtml5Camera)) | |
265 return; | |
243 base::FundamentalValue present_value( | 266 base::FundamentalValue present_value( |
244 CameraDetector::camera_presence() == CameraDetector::kCameraPresent); | 267 CameraDetector::camera_presence() == CameraDetector::kCameraPresent); |
245 web_ui()->CallJavascriptFunction("oobe.UserImageScreen.setCameraPresent", | 268 web_ui()->CallJavascriptFunction("oobe.UserImageScreen.setCameraPresent", |
246 present_value); | 269 present_value); |
247 } | 270 } |
248 | 271 |
249 } // namespace chromeos | 272 } // namespace chromeos |
OLD | NEW |