blob: e7b031625ec23ccaec1656c73fc49327c4fda5ce [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2019 The Chromium Authors
Huanzhong Huang8c0fbfa62019-10-07 10:49:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/webui/ntp/cookie_controls_handler.h"
6
Huanzhong Huang4e2d8a72019-10-20 19:13:077#include <utility>
8
Christian Dullwebercce1b27b2020-04-01 00:15:399#include "base/feature_list.h"
Avi Drissman9269d4ed2023-01-07 01:38:0610#include "base/functional/bind.h"
Huanzhong Huang8c0fbfa62019-10-07 10:49:0511#include "base/values.h"
12#include "chrome/browser/profiles/profile.h"
Ehimare Okoyomon3fc4c3c2020-02-03 21:50:3713#include "chrome/browser/ui/cookie_controls/cookie_controls_service.h"
14#include "chrome/browser/ui/cookie_controls/cookie_controls_service_factory.h"
Christian Dullwebercce1b27b2020-04-01 00:15:3915#include "chrome/common/chrome_features.h"
Sean Harrisonc69688472021-02-19 17:08:2016#include "chrome/common/webui_url_constants.h"
Mugdha Lakhani47e07fe2020-04-17 19:06:0117#include "components/content_settings/core/common/cookie_controls_enforcement.h"
Huanzhong Huang8c0fbfa62019-10-07 10:49:0518
Christian Dullweberd16bc1a02019-12-13 12:06:3519namespace {
Christian Dullweberd16bc1a02019-12-13 12:06:3520static const char* kPolicyIcon = "cr20:domain";
Christian Dullwebercce1b27b2020-04-01 00:15:3921static const char* kExtensionIcon = "cr:extension";
22static const char* kSettingsIcon = "cr:settings_icon";
Christian Dullweberd16bc1a02019-12-13 12:06:3523} // namespace
24
Ehimare Okoyomonb57d396b2020-03-06 14:51:1025CookieControlsHandler::CookieControlsHandler(Profile* profile)
26 : service_(CookieControlsServiceFactory::GetForProfile(profile)) {}
Huanzhong Huang8c0fbfa62019-10-07 10:49:0527
Ehimare Okoyomonb57d396b2020-03-06 14:51:1028CookieControlsHandler::~CookieControlsHandler() {
29 service_->RemoveObserver(this);
30}
Huanzhong Huang8c0fbfa62019-10-07 10:49:0531
32void CookieControlsHandler::RegisterMessages() {
Michael Wilsonf16cccf2022-03-28 15:29:1033 web_ui()->RegisterMessageCallback(
Huanzhong Huang8c0fbfa62019-10-07 10:49:0534 "cookieControlsToggleChanged",
35 base::BindRepeating(
36 &CookieControlsHandler::HandleCookieControlsToggleChanged,
37 base::Unretained(this)));
Michael Wilsonf16cccf2022-03-28 15:29:10