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