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::ImageRequest
,
35 public CameraPresenceNotifier::Observer
{
37 ChangePictureOptionsHandler();
38 ~ChangePictureOptionsHandler() override
;
40 // OptionsPageUIHandler implementation.
41 void GetLocalizedValues(base::DictionaryValue
* localized_strings
) override
;
43 // WebUIMessageHandler implementation.
44 void RegisterMessages() override
;
46 // CameraPresenceNotifier::Observer implementation:
47 void OnCameraPresenceCheckDone(bool is_camera_present
) override
;
50 // Sends list of available default images to the page.
51 void SendDefaultImages();
53 // Sends current selection to the page.
54 void SendSelectedImage();
56 // Sends the profile image to the page. If |should_select| is true then
57 // the profile image element is selected.
58 void SendProfileImage(const gfx::ImageSkia
& image
, bool should_select
);
60 // Starts profile image update and shows the last downloaded profile image,
61 // if any, on the page. Shouldn't be called before |SendProfileImage|.
62 void UpdateProfileImage();
64 // Sends previous user image to the page.
65 void SendOldImage(const std::string
& image_url
);
67 // Starts camera presence check.
68 void CheckCameraPresence();
70 // Updates UI with camera presence state.
71 void SetCameraPresent(bool present
);
73 // Opens a file selection dialog to choose user image from file.
74 void HandleChooseFile(const base::ListValue
* args
);
76 // Handles 'take-photo' button click.
77 void HandleTakePhoto(const base::ListValue
* args
);
79 // Handles photo taken with WebRTC UI.
80 void HandlePhotoTaken(const base::ListValue
* args
);
82 // Handles 'discard-photo' button click.
83 void HandleDiscardPhoto(const base::ListValue
* args
);
85 // Gets the list of available user images and sends it to the page.
86 void HandleGetAvailableImages(const base::ListValue
* args
);
88 // Handles page initialized event.
89 void HandlePageInitialized(const base::ListValue
* args
);
91 // Handles page shown event.
92 void HandlePageShown(const base::ListValue
* args
);
94 // Handles page hidden event.
95 void HandlePageHidden(const base::ListValue
* args
);
97 // Selects one of the available images as user's.
98 void HandleSelectImage(const base::ListValue
* args
);
100 // SelectFileDialog::Delegate implementation.
101 void FileSelected(const base::FilePath
& path
,
103 void* params
) override
;
105 // content::NotificationObserver implementation.
106 void Observe(int type
,
107 const content::NotificationSource
& source
,
108 const content::NotificationDetails
& details
) override
;
110 // Sets user image to photo taken from camera.
111 void SetImageFromCamera(const gfx::ImageSkia
& photo
);
113 // Returns handle to browser window or NULL if it can't be found.
114 gfx::NativeWindow
GetBrowserWindow() const;
116 // Overriden from ImageDecoder::ImageRequest:
117 void OnImageDecoded(const SkBitmap
& decoded_image
) override
;
118 void OnDecodeImageFailed() override
;
120 // Returns user related to current WebUI. If this user doesn't exist,
121 // returns active user.
122 const user_manager::User
* GetUser() const;
124 scoped_refptr
<ui::SelectFileDialog
> select_file_dialog_
;
126 // Previous user image from camera/file and its data URL.
127 gfx::ImageSkia previous_image_
;
128 std::string previous_image_url_
;
130 // Index of the previous user image.
131 int previous_image_index_
;
133 // Last user photo, if taken.
134 gfx::ImageSkia user_photo_
;
136 // Data URL for |user_photo_|.
137 std::string user_photo_data_url_
;
139 content::NotificationRegistrar registrar_
;
141 DISALLOW_COPY_AND_ASSIGN(ChangePictureOptionsHandler
);
144 } // namespace options
145 } // namespace chromeos
147 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_CHANGE_PICTURE_OPTIONS_HANDLER_H_