summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/ui/webui/ntp/cookie_controls_handler.h
blob: a0fd7bfa7a96b3c31ab9324f892f590fe28ce2b4 (plain)
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
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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_NTP_COOKIE_CONTROLS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_NTP_COOKIE_CONTROLS_HANDLER_H_

#include <memory>

#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/web_ui_message_handler.h"

class CookieControlsHandlerTest;
class Profile;

namespace base {
class ListValue;
class Value;
}  // namespace base

namespace policy {
class PolicyChangeRegistrar;
}

// Handles requests for prefs::kCookieControlsMode retrival/update.
class CookieControlsHandler : public content::WebUIMessageHandler {
 public:
  CookieControlsHandler();
  ~CookieControlsHandler() override;

  // WebUIMessageHandler
  void RegisterMessages() override;
  void OnJavascriptAllowed() override;
  void OnJavascriptDisallowed() override;

  void HandleCookieControlsToggleChanged(const base::ListValue* args);

  void HandleObserveCookieControlsSettingsChanges(const base::ListValue* args);

  // Whether cookie controls UI should be hidden in incognito ntp.
  static bool ShouldHideCookieControlsUI(const Profile* profile);

  static bool GetToggleCheckedValue(const Profile* profile);

 private:
  friend class CookieControlsHandlerTest;

  // Updates cookie controls UI when underlying setting has changed.
  void OnCookieControlsChanged();

  // Updates cookie controls UI when third-party cookie blocking setting has
  // changed.
  void OnThirdPartyCookieBlockingChanged();

  void OnThirdPartyCookieBlockingPolicyChanged(const base::Value* previous,
                                               const base::Value* current);

  PrefChangeRegistrar pref_change_registrar_;

  std::unique_ptr<policy::PolicyChangeRegistrar> policy_registrar_;

  DISALLOW_COPY_AND_ASSIGN(CookieControlsHandler);
};

#endif  // CHROME_BROWSER_UI_WEBUI_NTP_COOKIE_CONTROLS_HANDLER_H_