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 "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"
17 class DictionaryValue;
24 // ChromeOS user image options page UI handler.
25 class ChangePictureOptionsHandler : public ::options::OptionsPageUIHandler,
26 public ui::SelectFileDialog::Listener,
27 public ImageDecoder::Delegate {
29 ChangePictureOptionsHandler();
30 virtual ~ChangePictureOptionsHandler();
32 // OptionsPageUIHandler implementation.
33 virtual void GetLocalizedValues(
34 base::DictionaryValue* localized_strings) OVERRIDE;
36 // WebUIMessageHandler implementation.
37 virtual void RegisterMessages() OVERRIDE;
40 // Sends list of available default images to the page.
41 void SendDefaultImages();
43 // Sends current selection to the page.
44 void SendSelectedImage();
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);
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();
54 // Sends previous user image to the page.
55 void SendOldImage(const std::string& image_url);
57 // Starts camera presence check.
58 void CheckCameraPresence();
60 // Updates UI with camera presence state.
61 void SetCameraPresent(bool present);
63 // Opens a file selection dialog to choose user image from file.
64 void HandleChooseFile(const base::ListValue* args);
66 // Handles photo taken with WebRTC UI.
67 void HandlePhotoTaken(const base::ListValue* args);
69 // Handles camera presence check request.
70 void HandleCheckCameraPresence(const base::ListValue* args);
72 // Gets the list of available user images and sends it to the page.
73 void HandleGetAvailableImages(const base::ListValue* args);
75 // Handles page initialized event.
76 void HandlePageInitialized(const base::ListValue* args);
78 // Handles page shown event.
79 void HandlePageShown(const base::ListValue* args);
81 // Selects one of the available images as user's.
82 void HandleSelectImage(const base::ListValue* args);
84 // SelectFileDialog::Delegate implementation.
85 virtual void FileSelected(
86 const base::FilePath& path,
87 int index, void* params) OVERRIDE;
89 // content::NotificationObserver implementation.
90 virtual void Observe(int type,
91 const content::NotificationSource& source,
92 const content::NotificationDetails& details) OVERRIDE;
94 // Called when the camera presence check has been completed.
95 void OnCameraPresenceCheckDone();
97 // Sets user image to photo taken from camera.
98 void SetImageFromCamera(const gfx::ImageSkia& photo);
100 // Returns handle to browser window or NULL if it can't be found.
101 gfx::NativeWindow GetBrowserWindow() const;
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;
108 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
110 // Previous user image from camera/file and its data URL.
111 gfx::ImageSkia previous_image_;
112 std::string previous_image_url_;
114 // Index of the previous user image.
115 int previous_image_index_;
117 // Last user photo, if taken.
118 gfx::ImageSkia user_photo_;
120 // Data URL for |user_photo_|.
121 std::string user_photo_data_url_;
123 content::NotificationRegistrar registrar_;
125 base::WeakPtrFactory<ChangePictureOptionsHandler> weak_factory_;
127 // Last ImageDecoder instance used to decode an image blob received by
129 scoped_refptr<ImageDecoder> image_decoder_;
131 DISALLOW_COPY_AND_ASSIGN(ChangePictureOptionsHandler);
134 } // namespace options
135 } // namespace chromeos
137 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_CHANGE_PICTURE_OPTIONS_HANDLER_H_