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