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_CHROMEOS_LOGIN_SCREENS_BASE_SCREEN_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_BASE_SCREEN_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 12 namespace base { 13 class DictionaryValue; 14 } 15 16 namespace chromeos { 17 18 class ScreenContext; 19 20 // Base class for the all OOBE/login/before-session screens. 21 // Screens are identified by ID, screen and it's JS counterpart must have same 22 // id. 23 // Most of the screens will be re-created for each appearance with Initialize() 24 // method called just once. However if initialization is too expensive, screen 25 // can override result of IsPermanent() method, and do clean-up upon subsequent 26 // Initialize() method calls. 27 class BaseScreen { 28 public: 29 BaseScreen(); 30 virtual ~BaseScreen(); 31 32 // ---- Old implementation ---- 33 34 virtual void PrepareToShow() = 0; 35 36 // Makes wizard screen visible. 37 virtual void Show() = 0; 38 39 // Makes wizard screen invisible. 40 virtual void Hide() = 0; 41 42 // Returns the screen name. 43 virtual std::string GetName() const = 0; 44 45 // ---- New Implementation ---- 46 47 // Called to perform initialization of the screen. UI is guaranteed to exist 48 // at this point. Screen can alter context, resulting context will be passed 49 // to JS. This method will be called once per instance of the Screen object, 50 // unless |IsPermanent()| returns |true|. 51 virtual void Initialize(ScreenContext* context); 52 53 // Called when screen appears. 54 virtual void OnShow(); 55 // Called when screen disappears, either because it finished it's work, or 56 // because some other screen pops up. 57 virtual void OnHide(); 58 59 // Called when we navigate from screen so that we will never return to it. 60 // This is a last chance to call JS counterpart, this object will be deleted 61 // soon. 62 virtual void OnClose(); 63 64 // Indicates whether status area should be displayed while this screen is 65 // displayed. 66 virtual bool IsStatusAreaDisplayed(); 67 68 // If this method returns |true|, screen will not be deleted once we leave it. 69 // However, Initialize() might be called several times in this case. 70 virtual bool IsPermanent(); 71 72 // Returns the identifier of the screen. 73 virtual std::string GetID() const; 74 75 protected: 76 // Screen can call this method to notify framework that it have finished 77 // it's work with |outcome|. 78 void Finish(const std::string& outcome); 79 80 // Called when button with |button_id| was pressed. Notification 81 // about this event comes from the JS counterpart. 82 virtual void OnButtonPressed(const std::string& button_id); 83 84 // Called when context for the currenct screen was 85 // changed. Notification about this event comes from the JS 86 // counterpart. 87 virtual void OnContextChanged(const base::DictionaryValue* diff); 88 89 private: 90 friend class ScreenManager; 91 void SetContext(ScreenContext* context); 92 93 DISALLOW_COPY_AND_ASSIGN(BaseScreen); 94 }; 95 96 } // namespace chromeos 97 98 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_BASE_SCREEN_H_ 99