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.
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_
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"
18 class DictionaryValue;
22 namespace user_manager {
30 // ChromeOS user image options page UI handler.
31 class ChangePictureOptionsHandler : public ::options::OptionsPageUIHandler,
32 public ui::SelectFileDialog::Listener,
33 public content::NotificationObserver,
34 public ImageDecoder::Delegate,
35 public CameraPresenceNotifier::Observer {
37 ChangePictureOptionsHandler();
38 virtual ~ChangePictureOptionsHandler();
40 // OptionsPageUIHandler implementation.
41 virtual void GetLocalizedValues(
42 base::DictionaryValue* localized_strings) override;
44 // WebUIMessageHandler implementation.
45 virtual void RegisterMessages() override;
47 // CameraPresenceNotifier::Observer implementation:
48 virtual void OnCameraPresenceCheckDone(bool is_camera_present) override;
51 // Sends list of available default images to the page.
52 void SendDefaultImages();
54 // Sends current selection to the page.
55 void SendSelectedImage();
57 // Sends the profile image to the page. If |should_select| is true then
58 // the profile image element is selected.
59 void SendProfileImage(const gfx::ImageSkia& image, bool should_select);
61 // Starts profile image update and shows the last downloaded profile image,
62 // if any, on the page. Shouldn't be called before |SendProfileImage|.
63 void UpdateProfileImage();
65 // Sends previous user image to the page.
66 void SendOldImage(const std::string& image_url);
68 // Starts camera presence check.
69 void CheckCameraPresence();
71 // Updates UI with camera presence state.
72 void SetCameraPresent(bool present);
74 // Opens a file selection dialog to choose user image from file.
75 void HandleChooseFile(const base::ListValue* args);
77 // Handles 'take-photo' button click.
78 void HandleTakePhoto(const base::ListValue* args);
80 // Handles photo taken with WebRTC UI.
81 void HandlePhotoTaken(const base::ListValue* args);
83 // Handles 'discard-photo' button click.
84 void HandleDiscardPhoto(const base::ListValue* args);
86 // Gets the list of available user images and sends it to the page.
87 void HandleGetAvailableImages(const base::ListValue* args);
89 // Handles page initialized event.
90 void HandlePageInitialized(const base::ListValue* args);
92 // Handles page shown event.
93 void HandlePageShown(const base::ListValue* args);
95 // Handles page hidden event.
96 void HandlePageHidden(const base::ListValue* args);
98 // Selects one of the available images as user's.
99 void HandleSelectImage(const base::ListValue* args);
101 // SelectFileDialog::Delegate implementation.
102 virtual void FileSelected(
103 const base::FilePath& path,
104 int index, void* params) override;
106 // content::NotificationObserver implementation.
107 virtual void Observe(int type,
108 const content::NotificationSource& source,
109 const content::NotificationDetails& details) override;
111 // Sets user image to photo taken from camera.
112 void SetImageFromCamera(const gfx::ImageSkia& photo);
114 // Returns handle to browser window or NULL if it can't be found.
115 gfx::NativeWindow GetBrowserWindow() const;
117 // Overriden from ImageDecoder::Delegate:
118 virtual void OnImageDecoded(const ImageDecoder* decoder,
119 const SkBitmap& decoded_image) override;
120 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) override;
122 // Returns user related to current WebUI. If this user doesn't exist,
123 // returns active user.
124 user_manager::User* GetUser() const;
126 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
128 // Previous user image from camera/file and its data URL.
129 gfx::ImageSkia previous_image_;
130 std::string previous_image_url_;
132 // Index of the previous user image.
133 int previous_image_index_;
135 // Last user photo, if taken.
136 gfx::ImageSkia user_photo_;
138 // Data URL for |user_photo_|.
139 std::string user_photo_data_url_;
141 content::NotificationRegistrar registrar_;
143 // Last ImageDecoder instance used to decode an image blob received by
145 scoped_refptr<ImageDecoder> image_decoder_;
147 DISALLOW_COPY_AND_ASSIGN(ChangePictureOptionsHandler);
150 } // namespace options
151 } // namespace chromeos
153 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_CHANGE_PICTURE_OPTIONS_HANDLER_H_