File: management_ui_handler.h

package info (click to toggle)
chromium 140.0.7339.185-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,193,740 kB
  • sloc: cpp: 35,093,945; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,797; asm: 949,904; xml: 747,515; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,114; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (183 lines) | stat: -rw-r--r-- 6,850 bytes parent folder | download | duplicates (5)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright 2018 The Chromium Authors
// 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_MANAGEMENT_MANAGEMENT_UI_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_MANAGEMENT_MANAGEMENT_UI_HANDLER_H_

#include <memory>
#include <set>
#include <string>

#include "base/gtest_prod_util.h"
#include "base/values.h"
#include "chrome/common/url_constants.h"
#include "components/enterprise/browser/promotion/promotion_eligibility_checker.h"
#include "components/policy/core/common/policy_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/extension_id.h"

namespace extensions {
class Extension;
}  // namespace extensions

namespace policy {
class PolicyService;
}  // namespace policy

namespace enterprise_management {
class GetUserEligiblePromotionsResponse;
}  // namespace enterprise_management

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
namespace device_signals {
class UserPermissionService;
}  // namespace device_signals
#endif  // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)

// Interface for observing promotion eligibility fetching events.
class ManagementPromotionObserver : public base::CheckedObserver {
 public:
  virtual void OnPromotionEligibilityFetched(
      const std::string& callback_id,
      enterprise_management::GetUserEligiblePromotionsResponse response) = 0;
};

class Profile;

// The JavaScript message handler for the chrome://management page.
class ManagementUIHandler : public content::WebUIMessageHandler,
                            public extensions::ExtensionRegistryObserver,
                            public policy::PolicyService::Observer {
 public:
  explicit ManagementUIHandler(Profile* profile);

  ManagementUIHandler(const ManagementUIHandler&) = delete;
  ManagementUIHandler& operator=(const ManagementUIHandler&) = delete;

  ~ManagementUIHandler() override;

  static std::unique_ptr<ManagementUIHandler> Create(Profile* profile);

  // content::WebUIMessageHandler implementation.
  void RegisterMessages() override;

  void SetAccountManagedForTesting(bool managed) { account_managed_ = managed; }
#if !BUILDFLAG(IS_CHROMEOS)
  void SetBrowserManagedForTesting(bool managed) { browser_managed_ = managed; }
#endif

  void OnJavascriptAllowed() override;
  void OnJavascriptDisallowed() override;

  // Observer management for OnPromotionEligibilityFetched.
  void AddManagementPromotionObserver(ManagementPromotionObserver* observer);
  void RemoveManagementPromotionObserver(ManagementPromotionObserver* observer);

  bool HasPromotionBeenChecked() const {
    return has_checked_promotion_eligibility_;
  }

 protected:
  void AddReportingInfo(base::Value::List* report_sources, bool is_browser);

  virtual base::Value::Dict GetContextualManagedData(Profile* profile);
  base::Value::Dict GetThreatProtectionInfo(Profile* profile);
  base::Value::List GetManagedWebsitesInfo(Profile* profile) const;
  base::Value::List GetApplicationsInfo(Profile* profile) const;
  virtual policy::PolicyService* GetPolicyService();
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
  virtual device_signals::UserPermissionService* GetUserPermissionService();
  base::Value::Dict GetDeviceSignalGrantedMessage();
#endif  // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)

  bool account_managed() const { return account_managed_; }
  virtual bool managed() const;

#if BUILDFLAG(IS_CHROMEOS)
  void set_is_get_all_screens_media_allowed_for_any_origin(bool allowed) {
    is_get_all_screens_media_allowed_for_any_origin_ = allowed;
  }
#endif

  virtual void RegisterPrefChange(PrefChangeRegistrar& pref_registrar);
  virtual void UpdateManagedState();

  bool UpdateAccountManagedState(Profile* profile);
#if !BUILDFLAG(IS_CHROMEOS)
  bool UpdateBrowserManagedState();
#endif

  std::string GetAccountManager(Profile* profile) const;

  bool IsProfileManaged(Profile* profile) const;

  void NotifyThreatProtectionInfoUpdated();

 private:
  void HandleGetExtensions(const base::Value::List& args);
  void HandleGetContextualManagedData(const base::Value::List& args);
  void HandleGetThreatProtectionInfo(const base::Value::List& args);
  void HandleGetManagedWebsites(const base::Value::List& args);
  void HandleGetApplications(const base::Value::List& args);
  void HandleInitBrowserReportingInfo(const base::Value::List& args);
  void HandleInitProfileReportingInfo(const base::Value::List& args);
  void HandleShouldShowPromotion(const base::Value::List& args);
  void HandleSetBannerDismissed(const base::Value::List& args);
  void HandleRecordBannerRedirected(const base::Value::List& args);
  void OnPromotionEligibilityFetched(
      const std::string& callback_id,
      enterprise_management::GetUserEligiblePromotionsResponse response);
  std::unique_ptr<enterprise_promotion::PromotionEligibilityChecker>
      promotion_eligibility_checker_;

  void AsyncUpdateLogo();

  void NotifyBrowserReportingInfoUpdated();
  void NotifyProfileReportingInfoUpdated();

  // extensions::ExtensionRegistryObserver implementation.
  void OnExtensionLoaded(content::BrowserContext* browser_context,
                         const extensions::Extension* extension) override;
  void OnExtensionUnloaded(content::BrowserContext* browser_context,
                           const extensions::Extension* extension,
                           extensions::UnloadedExtensionReason reason) override;

  // policy::PolicyService::Observer
  void OnPolicyUpdated(const policy::PolicyNamespace& ns,
                       const policy::PolicyMap& previous,
                       const policy::PolicyMap& current) override;

  void AddObservers();
  void RemoveObservers();

  bool account_managed_ = false;
  bool browser_managed_ = false;
  // To avoid double-removing the observers, which would cause a DCHECK()
  // failure.
  bool has_observers_ = false;
  std::string web_ui_data_source_name_;

  PrefChangeRegistrar pref_registrar_;

  std::set<extensions::ExtensionId> reporting_extension_ids_;

  // List of observers for promotion eligibility.
  base::ObserverList<ManagementPromotionObserver>
      promotion_eligibility_observers_;

  bool has_checked_promotion_eligibility_ = false;

#if BUILDFLAG(IS_CHROMEOS)
  bool is_get_all_screens_media_allowed_for_any_origin_ = false;
#endif  // BUILDFLAG(IS_CHROMEOS)

  base::WeakPtrFactory<ManagementUIHandler> weak_factory_{this};
};

#endif  // CHROME_BROWSER_UI_WEBUI_MANAGEMENT_MANAGEMENT_UI_HANDLER_H_