| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_CHANGE_PICTURE_OPTIONS_HANDLER
_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_CHANGE_PICTURE_OPTIONS_HANDLER
_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "chrome/browser/chromeos/options/take_photo_dialog.h" | |
| 10 #include "chrome/browser/image_decoder.h" | |
| 11 #include "chrome/browser/ui/webui/options2/options_ui.h" | |
| 12 #include "content/public/browser/notification_registrar.h" | |
| 13 #include "ui/base/dialogs/select_file_dialog.h" | |
| 14 #include "ui/gfx/image/image_skia.h" | |
| 15 #include "ui/gfx/native_widget_types.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 class ListValue; | |
| 20 } | |
| 21 | |
| 22 namespace chromeos { | |
| 23 namespace options { | |
| 24 | |
| 25 // ChromeOS user image options page UI handler. | |
| 26 class ChangePictureOptionsHandler : public ::options::OptionsPageUIHandler, | |
| 27 public ui::SelectFileDialog::Listener, | |
| 28 public TakePhotoDialog::Delegate, | |
| 29 public ImageDecoder::Delegate { | |
| 30 public: | |
| 31 ChangePictureOptionsHandler(); | |
| 32 virtual ~ChangePictureOptionsHandler(); | |
| 33 | |
| 34 // OptionsPageUIHandler implementation. | |
| 35 virtual void GetLocalizedValues( | |
| 36 base::DictionaryValue* localized_strings) OVERRIDE; | |
| 37 | |
| 38 // WebUIMessageHandler implementation. | |
| 39 virtual void RegisterMessages() OVERRIDE; | |
| 40 | |
| 41 private: | |
| 42 // Sends list of available default images to the page. | |
| 43 void SendDefaultImages(); | |
| 44 | |
| 45 // Sends current selection to the page. | |
| 46 void SendSelectedImage(); | |
| 47 | |
| 48 // Sends the profile image to the page. If |should_select| is true then | |
| 49 // the profile image element is selected. | |
| 50 void SendProfileImage(const gfx::ImageSkia& image, bool should_select); | |
| 51 | |
| 52 // Starts profile image update and shows the last downloaded profile image, | |
| 53 // if any, on the page. Shouldn't be called before |SendProfileImage|. | |
| 54 void UpdateProfileImage(); | |
| 55 | |
| 56 // Starts camera presence check. | |
| 57 void CheckCameraPresence(); | |
| 58 | |
| 59 // Updates UI with camera presence state. | |
| 60 void SetCameraPresent(bool present); | |
| 61 | |
| 62 // Opens a file selection dialog to choose user image from file. | |
| 63 void HandleChooseFile(const base::ListValue* args); | |
| 64 | |
| 65 // Opens the camera capture dialog. | |
| 66 void HandleTakePhoto(const base::ListValue* args); | |
| 67 | |
| 68 // Handles photo taken with WebRTC UI. | |
| 69 void HandlePhotoTaken(const base::ListValue* args); | |
| 70 | |
| 71 // Gets the list of available user images and sends it to the page. | |
| 72 void HandleGetAvailableImages(const base::ListValue* args); | |
| 73 | |
| 74 // Handles page initialized event. | |
| 75 void HandlePageInitialized(const base::ListValue* args); | |
| 76 | |
| 77 // Handles page shown event. | |
| 78 void HandlePageShown(const base::ListValue* args); | |
| 79 | |
| 80 // Selects one of the available images as user's. | |
| 81 void HandleSelectImage(const base::ListValue* args); | |
| 82 | |
| 83 // SelectFileDialog::Delegate implementation. | |
| 84 virtual void FileSelected( | |
| 85 const FilePath& path, | |
| 86 int index, void* params) OVERRIDE; | |
| 87 | |
| 88 // TakePhotoDialog::Delegate implementation. | |
| 89 virtual void OnPhotoAccepted(const gfx::ImageSkia& photo) OVERRIDE; | |
| 90 | |
| 91 // content::NotificationObserver implementation. | |
| 92 virtual void Observe(int type, | |
| 93 const content::NotificationSource& source, | |
| 94 const content::NotificationDetails& details) OVERRIDE; | |
| 95 | |
| 96 // Called when the camera presence check has been completed. | |
| 97 void OnCameraPresenceCheckDone(); | |
| 98 | |
| 99 // Returns handle to browser window or NULL if it can't be found. | |
| 100 gfx::NativeWindow GetBrowserWindow() const; | |
| 101 | |
| 102 // Overriden from ImageDecoder::Delegate: | |
| 103 virtual void OnImageDecoded(const ImageDecoder* decoder, | |
| 104 const SkBitmap& decoded_image) OVERRIDE; | |
| 105 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | |
| 106 | |
| 107 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | |
| 108 | |
| 109 // Previous user image from camera/file and its data URL. | |
| 110 gfx::ImageSkia previous_image_; | |
| 111 std::string previous_image_data_url_; | |
| 112 | |
| 113 // Index of the previous user image. | |
| 114 int previous_image_index_; | |
| 115 | |
| 116 // Last user photo, if taken. | |
| 117 gfx::ImageSkia user_photo_; | |
| 118 | |
| 119 // Data URL for |user_photo_|. | |
| 120 std::string user_photo_data_url_; | |
| 121 | |
| 122 content::NotificationRegistrar registrar_; | |
| 123 | |
| 124 base::WeakPtrFactory<ChangePictureOptionsHandler> weak_factory_; | |
| 125 | |
| 126 // Last ImageDecoder instance used to decode an image blob received by | |
| 127 // HandlePhotoTaken. | |
| 128 scoped_refptr<ImageDecoder> image_decoder_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(ChangePictureOptionsHandler); | |
| 131 }; | |
| 132 | |
| 133 } // namespace options | |
| 134 } // namespace chromeos | |
| 135 | |
| 136 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_CHANGE_PICTURE_OPTIONS_HAND
LER_H_ | |
| OLD | NEW |