Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 content::NotificationService::AllSources()); | 66 content::NotificationService::AllSources()); |
| 67 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | 67 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, |
| 68 content::NotificationService::AllSources()); | 68 content::NotificationService::AllSources()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 ChangePictureOptionsHandler::~ChangePictureOptionsHandler() { | 71 ChangePictureOptionsHandler::~ChangePictureOptionsHandler() { |
| 72 if (select_file_dialog_.get()) | 72 if (select_file_dialog_.get()) |
| 73 select_file_dialog_->ListenerDestroyed(); | 73 select_file_dialog_->ListenerDestroyed(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ChangePictureOptionsHandler::Initialize() { | |
| 77 // If no camera presence check has been performed in this session, | |
| 78 // start one now. | |
| 79 if (CameraDetector::camera_presence() == | |
| 80 CameraDetector::kCameraPresenceUnknown) | |
| 81 CheckCameraPresence(); | |
| 82 | |
| 83 // While the check is in progress, use previous camera presence state and | |
| 84 // presume it is present if no check has been performed yet. | |
| 85 SetCameraPresent(CameraDetector::camera_presence() != | |
| 86 CameraDetector::kCameraAbsent); | |
| 87 | |
| 88 SendAvailableImages(); | |
| 89 } | |
| 90 | |
| 91 void ChangePictureOptionsHandler::GetLocalizedValues( | 76 void ChangePictureOptionsHandler::GetLocalizedValues( |
| 92 DictionaryValue* localized_strings) { | 77 DictionaryValue* localized_strings) { |
| 93 DCHECK(localized_strings); | 78 DCHECK(localized_strings); |
| 94 localized_strings->SetString("changePicturePage", | 79 localized_strings->SetString("changePicturePage", |
| 95 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TITLE)); | 80 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TITLE)); |
| 96 localized_strings->SetString("changePicturePageDescription", | 81 localized_strings->SetString("changePicturePageDescription", |
| 97 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TEXT)); | 82 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TEXT)); |
| 98 localized_strings->SetString("takePhoto", | 83 localized_strings->SetString("takePhoto", |
| 99 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_TAKE_PHOTO)); | 84 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_TAKE_PHOTO)); |
| 100 localized_strings->SetString("chooseFile", | 85 localized_strings->SetString("chooseFile", |
| 101 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_CHOOSE_FILE)); | 86 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_CHOOSE_FILE)); |
| 102 localized_strings->SetString("profilePhoto", | 87 localized_strings->SetString("profilePhoto", |
| 103 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_PROFILE_PHOTO)); | 88 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_PROFILE_PHOTO)); |
| 104 localized_strings->SetString("profilePhotoLoading", | 89 localized_strings->SetString("profilePhotoLoading", |
| 105 l10n_util::GetStringUTF16( | 90 l10n_util::GetStringUTF16( |
| 106 IDS_OPTIONS_CHANGE_PICTURE_PROFILE_LOADING_PHOTO)); | 91 IDS_OPTIONS_CHANGE_PICTURE_PROFILE_LOADING_PHOTO)); |
| 107 } | 92 } |
| 108 | 93 |
| 109 void ChangePictureOptionsHandler::RegisterMessages() { | 94 void ChangePictureOptionsHandler::RegisterMessages() { |
| 110 DCHECK(web_ui_); | 95 DCHECK(web_ui_); |
| 111 web_ui_->RegisterMessageCallback("chooseFile", | 96 web_ui_->RegisterMessageCallback("chooseFile", |
| 112 base::Bind(&ChangePictureOptionsHandler::HandleChooseFile, | 97 base::Bind(&ChangePictureOptionsHandler::HandleChooseFile, |
| 113 base::Unretained(this))); | 98 base::Unretained(this))); |
| 114 web_ui_->RegisterMessageCallback("takePhoto", | 99 web_ui_->RegisterMessageCallback("takePhoto", |
| 115 base::Bind(&ChangePictureOptionsHandler::HandleTakePhoto, | 100 base::Bind(&ChangePictureOptionsHandler::HandleTakePhoto, |
| 116 base::Unretained(this))); | 101 base::Unretained(this))); |
| 117 web_ui_->RegisterMessageCallback("onPageShown", | 102 web_ui_->RegisterMessageCallback("onChangePicturePageShown", |
| 118 base::Bind(&ChangePictureOptionsHandler::HandleOnPageShown, | 103 base::Bind(&ChangePictureOptionsHandler::HandlePageShown, |
| 104 base::Unretained(this))); | |
| 105 web_ui_->RegisterMessageCallback("onChangePicturePageInitialized", | |
| 106 base::Bind(&ChangePictureOptionsHandler::HandlePageInitialized, | |
| 119 base::Unretained(this))); | 107 base::Unretained(this))); |
| 120 web_ui_->RegisterMessageCallback("selectImage", | 108 web_ui_->RegisterMessageCallback("selectImage", |
| 121 base::Bind(&ChangePictureOptionsHandler::HandleSelectImage, | 109 base::Bind(&ChangePictureOptionsHandler::HandleSelectImage, |
| 122 base::Unretained(this))); | 110 base::Unretained(this))); |
| 123 } | 111 } |
| 124 | 112 |
| 125 void ChangePictureOptionsHandler::SendAvailableImages() { | 113 void ChangePictureOptionsHandler::SendDefaultImages() { |
| 126 ListValue image_urls; | 114 ListValue image_urls; |
| 127 for (int i = 0; i < kDefaultImagesCount; ++i) { | 115 for (int i = 0; i < kDefaultImagesCount; ++i) { |
| 128 image_urls.Append(new StringValue(GetDefaultImageUrl(i))); | 116 image_urls.Append(new StringValue(GetDefaultImageUrl(i))); |
| 129 } | 117 } |
| 130 web_ui_->CallJavascriptFunction("ChangePictureOptions.setUserImages", | 118 web_ui_->CallJavascriptFunction("ChangePictureOptions.setDefaultImages", |
| 131 image_urls); | 119 image_urls); |
| 132 } | 120 } |
| 133 | 121 |
| 134 void ChangePictureOptionsHandler::HandleChooseFile(const ListValue* args) { | 122 void ChangePictureOptionsHandler::HandleChooseFile(const ListValue* args) { |
| 135 DCHECK(args && args->empty()); | 123 DCHECK(args && args->empty()); |
| 136 if (!select_file_dialog_.get()) | 124 if (!select_file_dialog_.get()) |
| 137 select_file_dialog_ = SelectFileDialog::Create(this); | 125 select_file_dialog_ = SelectFileDialog::Create(this); |
| 138 | 126 |
| 139 FilePath downloads_path; | 127 FilePath downloads_path; |
| 140 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) { | 128 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 161 void ChangePictureOptionsHandler::HandleTakePhoto(const ListValue* args) { | 149 void ChangePictureOptionsHandler::HandleTakePhoto(const ListValue* args) { |
| 162 DCHECK(args && args->empty()); | 150 DCHECK(args && args->empty()); |
| 163 views::Widget* window = browser::CreateViewsWindow( | 151 views::Widget* window = browser::CreateViewsWindow( |
| 164 GetBrowserWindow(), | 152 GetBrowserWindow(), |
| 165 new TakePhotoDialog(this), | 153 new TakePhotoDialog(this), |
| 166 STYLE_GENERIC); | 154 STYLE_GENERIC); |
| 167 window->SetAlwaysOnTop(true); | 155 window->SetAlwaysOnTop(true); |
| 168 window->Show(); | 156 window->Show(); |
| 169 } | 157 } |
| 170 | 158 |
| 171 void ChangePictureOptionsHandler::HandleOnPageShown( | 159 void ChangePictureOptionsHandler::HandlePageInitialized( |
| 172 const base::ListValue* args) { | 160 const base::ListValue* args) { |
| 161 VLOG(1) << "ChangePictureOptionsHandler::HandlePageInitialized"; | |
|
James Hawkins
2011/12/10 04:21:38
Remove log spam.
Ivan Korotkov
2011/12/12 13:47:14
Done.
| |
| 173 DCHECK(args && args->empty()); | 162 DCHECK(args && args->empty()); |
| 163 // If no camera presence check has been performed in this session, | |
| 164 // start one now. | |
| 165 if (CameraDetector::camera_presence() == | |
| 166 CameraDetector::kCameraPresenceUnknown) | |
|
James Hawkins
2011/12/10 04:21:38
Braces required.
Ivan Korotkov
2011/12/12 13:47:14
Done.
| |
| 167 CheckCameraPresence(); | |
| 168 | |
| 169 // While the check is in progress, use previous camera presence state and | |
| 170 // presume it is present if no check has been performed yet. | |
| 171 SetCameraPresent(CameraDetector::camera_presence() != | |
| 172 CameraDetector::kCameraAbsent); | |
| 173 | |
| 174 SendDefaultImages(); | |
| 175 } | |
| 176 | |
| 177 void ChangePictureOptionsHandler::HandlePageShown(const base::ListValue* args) { | |
| 178 VLOG(1) << "ChangePictureOptionsHandler::HandlePageShown"; | |
|
James Hawkins
2011/12/10 04:21:38
Remove log spam.
Ivan Korotkov
2011/12/12 13:47:14
Done.
| |
| 179 DCHECK(args && args->empty()); | |
| 180 // TODO(ivankr): if user opens settings and goes to Change Picture page right | |
|
James Hawkins
2011/12/10 04:21:38
nit: Capitalize sentence.
Ivan Korotkov
2011/12/12 13:47:14
Done.
| |
| 181 // after the check started |HandlePageInitialized| has been completed, we'll | |
|
James Hawkins
2011/12/10 04:21:38
nit: Don't use 'we' in comments; it's ambiguous.
Ivan Korotkov
2011/12/12 13:47:14
Done.
| |
| 182 // call |CheckCameraPresence| twice. Throttle it to prevent excess checks. | |
| 174 CheckCameraPresence(); | 183 CheckCameraPresence(); |
| 175 SendSelectedImage(); | 184 SendSelectedImage(); |
| 176 UpdateProfileImage(); | 185 UpdateProfileImage(); |
| 177 } | 186 } |
| 178 | 187 |
| 179 void ChangePictureOptionsHandler::SendSelectedImage() { | 188 void ChangePictureOptionsHandler::SendSelectedImage() { |
| 180 const User& user = UserManager::Get()->logged_in_user(); | 189 const User& user = UserManager::Get()->logged_in_user(); |
| 181 DCHECK(!user.email().empty()); | 190 DCHECK(!user.email().empty()); |
| 182 | 191 |
| 183 previous_image_index_ = user.image_index(); | 192 previous_image_index_ = user.image_index(); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 | 337 |
| 329 gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const { | 338 gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const { |
| 330 Browser* browser = | 339 Browser* browser = |
| 331 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui_)); | 340 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui_)); |
| 332 if (!browser) | 341 if (!browser) |
| 333 return NULL; | 342 return NULL; |
| 334 return browser->window()->GetNativeHandle(); | 343 return browser->window()->GetNativeHandle(); |
| 335 } | 344 } |
| 336 | 345 |
| 337 } // namespace chromeos | 346 } // namespace chromeos |
| OLD | NEW |