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_CHROMEOS_LOGIN_SCREENS_BASE_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_BASE_SCREEN_H_
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h"
13 #include "components/login/base_screen_handler_utils.h"
14 #include "components/login/screens/screen_context.h"
17 class DictionaryValue
;
22 class ModelViewChannel
;
24 // Base class for the all OOBE/login/before-session screens.
25 // Screens are identified by ID, screen and it's JS counterpart must have same
27 // Most of the screens will be re-created for each appearance with Initialize()
28 // method called just once. However if initialization is too expensive, screen
29 // can override result of IsPermanent() method, and do clean-up upon subsequent
30 // Initialize() method calls.
33 explicit BaseScreen(BaseScreenDelegate
* base_screen_delegate
);
34 virtual ~BaseScreen();
36 // ---- Old implementation ----
38 virtual void PrepareToShow() = 0;
40 // Makes wizard screen visible.
41 virtual void Show() = 0;
43 // Makes wizard screen invisible.
44 virtual void Hide() = 0;
46 // Returns the screen name.
47 virtual std::string
GetName() const = 0;
49 // ---- New Implementation ----
51 // Called to perform initialization of the screen. UI is guaranteed to exist
52 // at this point. Screen can alter context, resulting context will be passed
53 // to JS. This method will be called once per instance of the Screen object,
54 // unless |IsPermanent()| returns |true|.
55 virtual void Initialize(::login::ScreenContext
* context
);
57 // Called when screen appears.
58 virtual void OnShow();
59 // Called when screen disappears, either because it finished it's work, or
60 // because some other screen pops up.
61 virtual void OnHide();
63 // Called when we navigate from screen so that we will never return to it.
64 // This is a last chance to call JS counterpart, this object will be deleted
66 virtual void OnClose();
68 // Indicates whether status area should be displayed while this screen is
70 virtual bool IsStatusAreaDisplayed();
72 // If this method returns |true|, screen will not be deleted once we leave it.
73 // However, Initialize() might be called several times in this case.
74 virtual bool IsPermanent();
76 // Returns the identifier of the screen.
77 virtual std::string
GetID() const;
79 // Called when user action event with |event_id|
80 // happened. Notification about this event comes from the JS
82 virtual void OnUserAction(const std::string
& action_id
);
84 void set_model_view_channel(ModelViewChannel
* channel
) { channel_
= channel
; }
87 // Scoped context editor, which automatically commits all pending
88 // context changes on destruction.
91 using KeyType
= ::login::ScreenContext::KeyType
;
92 using String16List
= ::login::String16List
;
93 using StringList
= ::login::StringList
;
95 explicit ContextEditor(BaseScreen
& screen
);
98 const ContextEditor
& SetBoolean(const KeyType
& key
, bool value
) const;
99 const ContextEditor
& SetInteger(const KeyType
& key
, int value
) const;
100 const ContextEditor
& SetDouble(const KeyType
& key
, double value
) const;
101 const ContextEditor
& SetString(const KeyType
& key
,
102 const std::string
& value
) const;
103 const ContextEditor
& SetString(const KeyType
& key
,
104 const base::string16
& value
) const;
105 const ContextEditor
& SetStringList(const KeyType
& key
,
106 const StringList
& value
) const;
107 const ContextEditor
& SetString16List(const KeyType
& key
,
108 const String16List
& value
) const;
112 ::login::ScreenContext
& context_
;
115 // Sends all pending context changes to the JS side.
116 void CommitContextChanges();
118 // Screen can call this method to notify framework that it have finished
119 // it's work with |outcome|.
120 void Finish(BaseScreenDelegate::ExitCodes exit_code
);
122 // The method is called each time some key in screen context is
123 // updated by JS side. Default implementation does nothing, so
124 // subclasses should override it in order to observe updates in
126 virtual void OnContextKeyUpdated(const ::login::ScreenContext::KeyType
& key
);
128 // Returns scoped context editor. The editor or it's copies should not outlive
129 // current BaseScreen instance.
130 ContextEditor
GetContextEditor();
132 BaseScreenDelegate
* get_base_screen_delegate() const {
133 return base_screen_delegate_
;
136 ::login::ScreenContext context_
;
139 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest
, TestCancel
);
140 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest
, TestSuccess
);
141 FRIEND_TEST_ALL_PREFIXES(ProvisionedEnrollmentScreenTest
, TestBackButton
);
143 friend class BaseScreenHandler
;
144 friend class NetworkScreenTest
;
145 friend class ScreenEditor
;
146 friend class ScreenManager
;
147 friend class UpdateScreenTest
;
149 void SetContext(::login::ScreenContext
* context
);
151 // Called when context for the current screen was
152 // changed. Notification about this event comes from the JS
154 void OnContextChanged(const base::DictionaryValue
& diff
);
156 ModelViewChannel
* channel_
;
158 BaseScreenDelegate
* base_screen_delegate_
;
160 DISALLOW_COPY_AND_ASSIGN(BaseScreen
);
163 } // namespace chromeos
165 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_BASE_SCREEN_H_