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