1 // Copyright 2017 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_SYNC_CONSENT_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SYNC_CONSENT_SCREEN_HANDLER_H_
7 
8 #include <unordered_set>
9 
10 #include "base/macros.h"
11 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
12 
13 namespace chromeos {
14 
15 class SyncConsentScreen;
16 
17 // Interface for dependency injection between SyncConsentScreen and its
18 // WebUI representation.
19 class SyncConsentScreenView {
20  public:
21   constexpr static StaticOobeScreenId kScreenId{"sync-consent"};
22 
23   virtual ~SyncConsentScreenView() = default;
24 
25   // Sets screen this view belongs to.
26   virtual void Bind(SyncConsentScreen* screen) = 0;
27 
28   // Shows the contents of the screen.
29   virtual void Show() = 0;
30 
31   // Hides the contents of the screen.
32   virtual void Hide() = 0;
33 
34   // Controls if the loading throbber is visible. This is used when
35   // SyncScreenBehavior is unknown.
36   virtual void SetThrobberVisible(bool visible) = 0;
37 };
38 
39 // The sole implementation of the SyncConsentScreenView, using WebUI.
40 class SyncConsentScreenHandler : public BaseScreenHandler,
41                                  public SyncConsentScreenView {
42  public:
43   using TView = SyncConsentScreenView;
44 
45   // These values are persisted to logs. Entries should not be renumbered and
46   // numeric values should never be reused. Public for testing.
47   enum class UserChoice { kDeclined = 0, kAccepted = 1, kMaxValue = kAccepted };
48 
49   explicit SyncConsentScreenHandler(JSCallsContainer* js_calls_container);
50   ~SyncConsentScreenHandler() override;
51 
52   // BaseScreenHandler:
53   void DeclareLocalizedValues(
54       ::login::LocalizedValuesBuilder* builder) override;
55 
56   // SyncConsentScreenView:
57   void Bind(SyncConsentScreen* screen) override;
58   void Show() override;
59   void Hide() override;
60   void SetThrobberVisible(bool visible) override;
61 
62  private:
63   // BaseScreenHandler:
64   void Initialize() override;
65   void RegisterMessages() override;
66 
67   // WebUI message handlers
68   void HandleContinueAndReview(const ::login::StringList& consent_description,
69                                const std::string& consent_confirmation);
70   void HandleContinueWithDefaults(
71       const ::login::StringList& consent_description,
72       const std::string& consent_confirmation);
73 
74   // WebUI message handlers for SplitSettingsSync.
75   void HandleAcceptAndContinue(const ::login::StringList& consent_description,
76                                const std::string& consent_confirmation);
77   void HandleDeclineAndContinue(const ::login::StringList& consent_description,
78                                 const std::string& consent_confirmation);
79 
80   // Helper for the accept and decline cases.
81   void Continue(const ::login::StringList& consent_description,
82                 const std::string& consent_confirmation,
83                 UserChoice choice);
84 
85   // Adds resource `resource_id` both to `builder` and to `known_string_ids_`.
86   void RememberLocalizedValue(const std::string& name,
87                               const int resource_id,
88                               ::login::LocalizedValuesBuilder* builder);
89 
90   // Resource IDs of the displayed strings.
91   std::unordered_set<int> known_string_ids_;
92 
93   SyncConsentScreen* screen_ = nullptr;
94 
95   DISALLOW_COPY_AND_ASSIGN(SyncConsentScreenHandler);
96 };
97 
98 }  // namespace chromeos
99 
100 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SYNC_CONSENT_SCREEN_HANDLER_H_
101