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_CHROMEOS_LOGIN_USER_IMAGE_SCREEN_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_USER_IMAGE_SCREEN_HANDLER_H_ 7 8 #include <string> 9 10 #include "base/memory/weak_ptr.h" 11 #include "base/time/time.h" 12 #include "chrome/browser/chromeos/login/screens/user_image_screen_actor.h" 13 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" 14 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 15 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/native_widget_types.h" 17 18 namespace chromeos { 19 20 // WebUI implementation of UserImageScreenActor. It is used to interact 21 // with JS page part allowing user to select avatar. 22 class UserImageScreenHandler : public UserImageScreenActor, 23 public BaseScreenHandler { 24 public: 25 UserImageScreenHandler(); 26 virtual ~UserImageScreenHandler(); 27 28 // BaseScreenHandler implementation: 29 virtual void Initialize() OVERRIDE; 30 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE; 31 32 // WebUIMessageHandler implementation: 33 virtual void RegisterMessages() OVERRIDE; 34 35 // UserImageScreenActor implementation: 36 virtual void SetDelegate( 37 UserImageScreenActor::Delegate* screen) OVERRIDE; 38 virtual void Show() OVERRIDE; 39 virtual void Hide() OVERRIDE; 40 virtual void PrepareToShow() OVERRIDE; 41 42 virtual void SelectImage(int index) OVERRIDE; 43 virtual void SendProfileImage(const std::string& data_url) OVERRIDE; 44 virtual void OnProfileImageAbsent() OVERRIDE; 45 46 virtual void SetCameraPresent(bool enabled) OVERRIDE; 47 48 virtual void HideCurtain() OVERRIDE; 49 50 private: 51 52 // Sends image data to the page. 53 void HandleGetImages(); 54 55 // Screen ready to be shown. 56 void HandleScreenReady(); 57 58 // Handles photo taken with WebRTC UI. 59 void HandlePhotoTaken(const std::string& image_url); 60 61 // Handles 'take-photo' button click. 62 void HandleTakePhoto(); 63 64 // Handles 'discard-photo' button click. 65 void HandleDiscardPhoto(); 66 67 // Handles clicking on default user image. 68 void HandleSelectImage(const std::string& image_url, 69 const std::string& image_type, 70 bool is_user_selection); 71 72 // Called when user accept the image closing the screen. 73 void HandleImageAccepted(); 74 75 // Called when the user image screen has been loaded and shown. 76 void HandleScreenShown(); 77 78 UserImageScreenActor::Delegate* screen_; 79 80 // Keeps whether screen should be shown right after initialization. 81 bool show_on_init_; 82 83 // Keeps whether screen has loaded all default images and redy to be shown. 84 bool is_ready_; 85 86 base::Time screen_show_time_; 87 88 DISALLOW_COPY_AND_ASSIGN(UserImageScreenHandler); 89 }; 90 91 } // namespace chromeos 92 93 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_USER_IMAGE_SCREEN_HANDLER_H_ 94