| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/chromeos/camera_detector.h" | 13 #include "chrome/browser/chromeos/camera_detector.h" |
| 14 #include "chrome/browser/chromeos/login/default_user_images.h" | 14 #include "chrome/browser/chromeos/login/default_user_images.h" |
| 15 #include "chrome/browser/chromeos/login/user.h" | 15 #include "chrome/browser/chromeos/login/user.h" |
| 16 #include "chrome/browser/chromeos/login/webui_login_display.h" | 16 #include "chrome/browser/chromeos/login/webui_login_display.h" |
| 17 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 17 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 22 #include "net/base/data_url.h" | 23 #include "net/base/data_url.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 25 #include "ui/webui/web_ui_util.h" | 26 #include "ui/webui/web_ui_util.h" |
| 26 | 27 |
| 28 using content::BrowserThread; |
| 29 |
| 27 namespace chromeos { | 30 namespace chromeos { |
| 28 | 31 |
| 29 UserImageScreenHandler::UserImageScreenHandler() | 32 UserImageScreenHandler::UserImageScreenHandler() |
| 30 : screen_(NULL), | 33 : screen_(NULL), |
| 31 show_on_init_(false), | 34 show_on_init_(false), |
| 32 selected_image_(User::kInvalidImageIndex), | 35 selected_image_(User::kInvalidImageIndex), |
| 33 accept_photo_after_decoding_(false), | 36 accept_photo_after_decoding_(false), |
| 34 user_photo_data_url_(chrome::kAboutBlankURL), | 37 user_photo_data_url_(chrome::kAboutBlankURL), |
| 35 profile_picture_data_url_(chrome::kAboutBlankURL), | 38 profile_picture_data_url_(chrome::kAboutBlankURL), |
| 36 profile_picture_absent_(false), | 39 profile_picture_absent_(false), |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 if (selected_image_ != User::kInvalidImageIndex) | 186 if (selected_image_ != User::kInvalidImageIndex) |
| 184 SelectImage(selected_image_); | 187 SelectImage(selected_image_); |
| 185 | 188 |
| 186 if (profile_picture_data_url_ != chrome::kAboutBlankURL) | 189 if (profile_picture_data_url_ != chrome::kAboutBlankURL) |
| 187 SendProfileImage(profile_picture_data_url_); | 190 SendProfileImage(profile_picture_data_url_); |
| 188 else if (profile_picture_absent_) | 191 else if (profile_picture_absent_) |
| 189 OnProfileImageAbsent(); | 192 OnProfileImageAbsent(); |
| 190 } | 193 } |
| 191 | 194 |
| 192 void UserImageScreenHandler::HandlePhotoTaken(const base::ListValue* args) { | 195 void UserImageScreenHandler::HandlePhotoTaken(const base::ListValue* args) { |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 193 std::string image_url; | 197 std::string image_url; |
| 194 if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url)) | 198 if (!args || args->GetSize() != 1 || !args->GetString(0, &image_url)) |
| 195 NOTREACHED(); | 199 NOTREACHED(); |
| 196 DCHECK(!image_url.empty()); | 200 DCHECK(!image_url.empty()); |
| 197 | 201 |
| 198 std::string mime_type, charset, raw_data; | 202 std::string mime_type, charset, raw_data; |
| 199 if (!net::DataURL::Parse(GURL(image_url), &mime_type, &charset, &raw_data)) | 203 if (!net::DataURL::Parse(GURL(image_url), &mime_type, &charset, &raw_data)) |
| 200 NOTREACHED(); | 204 NOTREACHED(); |
| 201 DCHECK_EQ("image/png", mime_type); | 205 DCHECK_EQ("image/png", mime_type); |
| 202 | 206 |
| 203 user_photo_ = gfx::ImageSkia(); | 207 user_photo_ = gfx::ImageSkia(); |
| 204 user_photo_data_url_ = image_url; | 208 user_photo_data_url_ = image_url; |
| 205 | 209 |
| 206 if (image_decoder_.get()) | 210 if (image_decoder_.get()) |
| 207 image_decoder_->set_delegate(NULL); | 211 image_decoder_->set_delegate(NULL); |
| 208 image_decoder_ = new ImageDecoder(this, raw_data, | 212 image_decoder_ = new ImageDecoder(this, raw_data, |
| 209 ImageDecoder::DEFAULT_CODEC); | 213 ImageDecoder::DEFAULT_CODEC); |
| 210 image_decoder_->Start(); | 214 scoped_refptr<base::MessageLoopProxy> task_runner = |
| 215 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 216 image_decoder_->Start(task_runner); |
| 211 } | 217 } |
| 212 | 218 |
| 213 void UserImageScreenHandler::HandleCheckCameraPresence( | 219 void UserImageScreenHandler::HandleCheckCameraPresence( |
| 214 const base::ListValue* args) { | 220 const base::ListValue* args) { |
| 215 DCHECK(args->empty()); | 221 DCHECK(args->empty()); |
| 216 CheckCameraPresence(); | 222 CheckCameraPresence(); |
| 217 } | 223 } |
| 218 | 224 |
| 219 void UserImageScreenHandler::HandleSelectImage(const base::ListValue* args) { | 225 void UserImageScreenHandler::HandleSelectImage(const base::ListValue* args) { |
| 220 std::string image_url; | 226 std::string image_url; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 user_photo_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); | 293 user_photo_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); |
| 288 if (screen_ && accept_photo_after_decoding_) | 294 if (screen_ && accept_photo_after_decoding_) |
| 289 screen_->OnPhotoTaken(user_photo_); | 295 screen_->OnPhotoTaken(user_photo_); |
| 290 } | 296 } |
| 291 | 297 |
| 292 void UserImageScreenHandler::OnDecodeImageFailed(const ImageDecoder* decoder) { | 298 void UserImageScreenHandler::OnDecodeImageFailed(const ImageDecoder* decoder) { |
| 293 NOTREACHED() << "Failed to decode PNG image from WebUI"; | 299 NOTREACHED() << "Failed to decode PNG image from WebUI"; |
| 294 } | 300 } |
| 295 | 301 |
| 296 } // namespace chromeos | 302 } // namespace chromeos |
| OLD | NEW |