OLD | NEW |
1 // Copyright (c) 2013 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/options/chromeos/change_picture_options_handle
r.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/change_picture_options_handle
r.h" |
6 | 6 |
7 #include "ash/audio/sounds.h" | 7 #include "ash/audio/sounds.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 image_data->SetString("author", | 173 image_data->SetString("author", |
174 l10n_util::GetStringUTF16( | 174 l10n_util::GetStringUTF16( |
175 default_user_image::kDefaultImageAuthorIDs[i])); | 175 default_user_image::kDefaultImageAuthorIDs[i])); |
176 image_data->SetString("website", | 176 image_data->SetString("website", |
177 l10n_util::GetStringUTF16( | 177 l10n_util::GetStringUTF16( |
178 default_user_image::kDefaultImageWebsiteIDs[i])); | 178 default_user_image::kDefaultImageWebsiteIDs[i])); |
179 image_data->SetString("title", | 179 image_data->SetString("title", |
180 default_user_image::GetDefaultImageDescription(i)); | 180 default_user_image::GetDefaultImageDescription(i)); |
181 image_urls.Append(image_data.release()); | 181 image_urls.Append(image_data.release()); |
182 } | 182 } |
183 web_ui()->CallJavascriptFunction("ChangePictureOptions.setDefaultImages", | 183 web_ui()->CallJavascriptFunctionUnsafe( |
184 image_urls); | 184 "ChangePictureOptions.setDefaultImages", image_urls); |
185 } | 185 } |
186 | 186 |
187 void ChangePictureOptionsHandler::HandleChooseFile( | 187 void ChangePictureOptionsHandler::HandleChooseFile( |
188 const base::ListValue* args) { | 188 const base::ListValue* args) { |
189 DCHECK(args && args->empty()); | 189 DCHECK(args && args->empty()); |
190 select_file_dialog_ = ui::SelectFileDialog::Create( | 190 select_file_dialog_ = ui::SelectFileDialog::Create( |
191 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 191 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
192 | 192 |
193 base::FilePath downloads_path; | 193 base::FilePath downloads_path; |
194 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) { | 194 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 break; | 279 break; |
280 } | 280 } |
281 default: { | 281 default: { |
282 DCHECK(previous_image_index_ >= 0 && | 282 DCHECK(previous_image_index_ >= 0 && |
283 previous_image_index_ < default_user_image::kDefaultImagesCount); | 283 previous_image_index_ < default_user_image::kDefaultImagesCount); |
284 if (previous_image_index_ >= | 284 if (previous_image_index_ >= |
285 default_user_image::kFirstDefaultImageIndex) { | 285 default_user_image::kFirstDefaultImageIndex) { |
286 // User has image from the current set of default images. | 286 // User has image from the current set of default images. |
287 base::StringValue image_url( | 287 base::StringValue image_url( |
288 default_user_image::GetDefaultImageUrl(previous_image_index_)); | 288 default_user_image::GetDefaultImageUrl(previous_image_index_)); |
289 web_ui()->CallJavascriptFunction( | 289 web_ui()->CallJavascriptFunctionUnsafe( |
290 "ChangePictureOptions.setSelectedImage", image_url); | 290 "ChangePictureOptions.setSelectedImage", image_url); |
291 } else { | 291 } else { |
292 // User has an old default image, so present it in the same manner as a | 292 // User has an old default image, so present it in the same manner as a |
293 // previous image from file. | 293 // previous image from file. |
294 SendOldImage( | 294 SendOldImage( |
295 default_user_image::GetDefaultImageUrl(previous_image_index_)); | 295 default_user_image::GetDefaultImageUrl(previous_image_index_)); |
296 } | 296 } |
297 } | 297 } |
298 } | 298 } |
299 } | 299 } |
300 | 300 |
301 void ChangePictureOptionsHandler::SendProfileImage(const gfx::ImageSkia& image, | 301 void ChangePictureOptionsHandler::SendProfileImage(const gfx::ImageSkia& image, |
302 bool should_select) { | 302 bool should_select) { |
303 base::StringValue data_url(webui::GetBitmapDataUrl(*image.bitmap())); | 303 base::StringValue data_url(webui::GetBitmapDataUrl(*image.bitmap())); |
304 base::FundamentalValue select(should_select); | 304 base::FundamentalValue select(should_select); |
305 web_ui()->CallJavascriptFunction("ChangePictureOptions.setProfileImage", | 305 web_ui()->CallJavascriptFunctionUnsafe("ChangePictureOptions.setProfileImage", |
306 data_url, select); | 306 data_url, select); |
307 } | 307 } |
308 | 308 |
309 void ChangePictureOptionsHandler::UpdateProfileImage() { | 309 void ChangePictureOptionsHandler::UpdateProfileImage() { |
310 UserImageManager* user_image_manager = | 310 UserImageManager* user_image_manager = |
311 ChromeUserManager::Get()->GetUserImageManager(GetUser()->GetAccountId()); | 311 ChromeUserManager::Get()->GetUserImageManager(GetUser()->GetAccountId()); |
312 // If we have a downloaded profile image and haven't sent it in | 312 // If we have a downloaded profile image and haven't sent it in |
313 // |SendSelectedImage|, send it now (without selecting). | 313 // |SendSelectedImage|, send it now (without selecting). |
314 if (previous_image_index_ != user_manager::User::USER_IMAGE_PROFILE && | 314 if (previous_image_index_ != user_manager::User::USER_IMAGE_PROFILE && |
315 !user_image_manager->DownloadedProfileImage().isNull()) | 315 !user_image_manager->DownloadedProfileImage().isNull()) |
316 SendProfileImage(user_image_manager->DownloadedProfileImage(), false); | 316 SendProfileImage(user_image_manager->DownloadedProfileImage(), false); |
317 | 317 |
318 user_image_manager->DownloadProfileImage(kProfileDownloadReason); | 318 user_image_manager->DownloadProfileImage(kProfileDownloadReason); |
319 } | 319 } |
320 | 320 |
321 void ChangePictureOptionsHandler::SendOldImage(const std::string& image_url) { | 321 void ChangePictureOptionsHandler::SendOldImage(const std::string& image_url) { |
322 previous_image_url_ = image_url; | 322 previous_image_url_ = image_url; |
323 base::StringValue url(image_url); | 323 base::StringValue url(image_url); |
324 web_ui()->CallJavascriptFunction("ChangePictureOptions.setOldImage", url); | 324 web_ui()->CallJavascriptFunctionUnsafe("ChangePictureOptions.setOldImage", |
| 325 url); |
325 } | 326 } |
326 | 327 |
327 void ChangePictureOptionsHandler::HandleSelectImage( | 328 void ChangePictureOptionsHandler::HandleSelectImage( |
328 const base::ListValue* args) { | 329 const base::ListValue* args) { |
329 std::string image_url; | 330 std::string image_url; |
330 std::string image_type; | 331 std::string image_type; |
331 if (!args || | 332 if (!args || |
332 args->GetSize() != 2 || | 333 args->GetSize() != 2 || |
333 !args->GetString(0, &image_url) || | 334 !args->GetString(0, &image_url) || |
334 !args->GetString(1, &image_type)) { | 335 !args->GetString(1, &image_type)) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 ->SaveUserImage(user_manager::UserImage::CreateAndEncode(photo)); | 415 ->SaveUserImage(user_manager::UserImage::CreateAndEncode(photo)); |
415 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", | 416 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", |
416 default_user_image::kHistogramImageFromCamera, | 417 default_user_image::kHistogramImageFromCamera, |
417 default_user_image::kHistogramImagesCount); | 418 default_user_image::kHistogramImagesCount); |
418 VLOG(1) << "Selected camera photo"; | 419 VLOG(1) << "Selected camera photo"; |
419 } | 420 } |
420 | 421 |
421 void ChangePictureOptionsHandler::SetCameraPresent(bool present) { | 422 void ChangePictureOptionsHandler::SetCameraPresent(bool present) { |
422 base::FundamentalValue present_value(present); | 423 base::FundamentalValue present_value(present); |
423 | 424 |
424 web_ui()->CallJavascriptFunction("ChangePictureOptions.setCameraPresent", | 425 web_ui()->CallJavascriptFunctionUnsafe( |
425 present_value); | 426 "ChangePictureOptions.setCameraPresent", present_value); |
426 } | 427 } |
427 | 428 |
428 void ChangePictureOptionsHandler::OnCameraPresenceCheckDone( | 429 void ChangePictureOptionsHandler::OnCameraPresenceCheckDone( |
429 bool is_camera_present) { | 430 bool is_camera_present) { |
430 SetCameraPresent(is_camera_present); | 431 SetCameraPresent(is_camera_present); |
431 } | 432 } |
432 | 433 |
433 void ChangePictureOptionsHandler::Observe( | 434 void ChangePictureOptionsHandler::Observe( |
434 int type, | 435 int type, |
435 const content::NotificationSource& source, | 436 const content::NotificationSource& source, |
(...skipping 30 matching lines...) Expand all Loading... |
466 Profile* profile = Profile::FromWebUI(web_ui()); | 467 Profile* profile = Profile::FromWebUI(web_ui()); |
467 const user_manager::User* user = | 468 const user_manager::User* user = |
468 ProfileHelper::Get()->GetUserByProfile(profile); | 469 ProfileHelper::Get()->GetUserByProfile(profile); |
469 if (!user) | 470 if (!user) |
470 return user_manager::UserManager::Get()->GetActiveUser(); | 471 return user_manager::UserManager::Get()->GetActiveUser(); |
471 return user; | 472 return user; |
472 } | 473 } |
473 | 474 |
474 } // namespace options | 475 } // namespace options |
475 } // namespace chromeos | 476 } // namespace chromeos |
OLD | NEW |