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
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/ash/settings/pages/kerberos/kerberos_section.h"
#include <array>
#include "base/containers/span.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ash/settings/pages/kerberos/kerberos_accounts_handler.h"
#include "chrome/browser/ui/webui/ash/settings/search/search_tag_registry.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
namespace ash::settings {
namespace mojom {
using ::chromeos::settings::mojom::kKerberosAccountsV2SubpagePath;
using ::chromeos::settings::mojom::kKerberosSectionPath;
using ::chromeos::settings::mojom::Section;
using ::chromeos::settings::mojom::Setting;
using ::chromeos::settings::mojom::Subpage;
} // namespace mojom
namespace {
// Provides search tags that are always available when the feature is enabled by
// policy/flag.
base::span<const SearchConcept> GetFixedKerberosSearchConcepts() {
static constexpr auto tags = std::to_array<SearchConcept>({
{IDS_OS_SETTINGS_TAG_KERBEROS_SECTION,
mojom::kKerberosSectionPath,
mojom::SearchResultIcon::kAuthKey,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSection,
{.section = mojom::Section::kKerberos}},
{IDS_OS_SETTINGS_TAG_KERBEROS,
mojom::kKerberosAccountsV2SubpagePath,
mojom::SearchResultIcon::kAuthKey,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSubpage,
{.subpage = mojom::Subpage::kKerberosAccountsV2}},
{IDS_OS_SETTINGS_TAG_KERBEROS_ADD,
mojom::kKerberosAccountsV2SubpagePath,
mojom::SearchResultIcon::kAuthKey,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kAddKerberosTicketV2}},
});
return tags;
}
// Provides search tags that are only available when the feature is enabled by
// policy/flag and there is at least one Kerberos ticket.
base::span<const SearchConcept> GetDynamicKerberosSearchConcepts() {
static constexpr auto tags = std::to_array<SearchConcept>({
{IDS_OS_SETTINGS_TAG_KERBEROS_REMOVE,
mojom::kKerberosAccountsV2SubpagePath,
mojom::SearchResultIcon::kAuthKey,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kRemoveKerberosTicketV2}},
{IDS_OS_SETTINGS_TAG_KERBEROS_ACTIVE,
mojom::kKerberosAccountsV2SubpagePath,
mojom::SearchResultIcon::kAuthKey,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kSetActiveKerberosTicketV2}},
});
return tags;
}
} // namespace
KerberosSection::KerberosSection(
Profile* profile,
SearchTagRegistry* search_tag_registry,
KerberosCredentialsManager* kerberos_credentials_manager)
: OsSettingsSection(profile, search_tag_registry),
kerberos_credentials_manager_(kerberos_credentials_manager) {
if (kerberos_credentials_manager_) {
// Kerberos search tags are added/removed dynamically.
kerberos_credentials_manager_->AddObserver(this);
UpdateKerberosSearchConcepts();
}
}
KerberosSection::~KerberosSection() {
if (kerberos_credentials_manager_) {
kerberos_credentials_manager_->RemoveObserver(this);
}
}
void KerberosSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
html_source->AddLocalizedString("kerberosPageTitle",
IDS_OS_SETTINGS_KERBEROS);
KerberosAccountsHandler::AddLoadTimeKerberosStrings(
html_source, kerberos_credentials_manager_);
}
void KerberosSection::AddHandlers(content::WebUI* web_ui) {
std::unique_ptr<KerberosAccountsHandler> kerberos_accounts_handler =
KerberosAccountsHandler::CreateIfKerberosEnabled(profile());
if (kerberos_accounts_handler) {
// Note that the UI is enabled only if Kerberos is enabled.
web_ui->AddMessageHandler(std::move(kerberos_accounts_handler));
}
}
int KerberosSection::GetSectionNameMessageId() const {
return IDS_OS_SETTINGS_KERBEROS;
}
mojom::Section KerberosSection::GetSection() const {
return mojom::Section::kKerberos;
}
mojom::SearchResultIcon KerberosSection::GetSectionIcon() const {
return mojom::SearchResultIcon::kAuthKey;
}
const char* KerberosSection::GetSectionPath() const {
return mojom::kKerberosSectionPath;
}
bool KerberosSection::LogMetric(mojom::Setting setting,
base::Value& value) const {
// Unimplemented.
return false;
}
void KerberosSection::RegisterHierarchy(HierarchyGenerator* generator) const {
generator->RegisterTopLevelSubpage(IDS_SETTINGS_KERBEROS_ACCOUNTS_PAGE_TITLE,
mojom::Subpage::kKerberosAccountsV2,
mojom::SearchResultIcon::kAuthKey,
mojom::SearchResultDefaultRank::kMedium,
mojom::kKerberosAccountsV2SubpagePath);
static constexpr mojom::Setting kKerberosAccountsV2Settings[] = {
mojom::Setting::kAddKerberosTicketV2,
mojom::Setting::kRemoveKerberosTicketV2,
mojom::Setting::kSetActiveKerberosTicketV2,
};
RegisterNestedSettingBulk(mojom::Subpage::kKerberosAccountsV2,
kKerberosAccountsV2Settings, generator);
}
void KerberosSection::OnAccountsChanged() {
UpdateKerberosSearchConcepts();
}
void KerberosSection::OnKerberosEnabledStateChanged() {
UpdateKerberosSearchConcepts();
}
// Updates search tags according to the KerberosEnabled state and the presence
// of Kerberos tickets in the system.
void KerberosSection::UpdateKerberosSearchConcepts() {
CHECK(kerberos_credentials_manager_);
SearchTagRegistry::ScopedTagUpdater updater = registry()->StartUpdate();
// Removes all search tags first. They will be added conditionally later.
updater.RemoveSearchTags(GetFixedKerberosSearchConcepts());
updater.RemoveSearchTags(GetDynamicKerberosSearchConcepts());
if (kerberos_credentials_manager_->IsKerberosEnabled()) {
updater.AddSearchTags(GetFixedKerberosSearchConcepts());
const std::string account_name =
kerberos_credentials_manager_->GetActiveAccount();
if (!account_name.empty()) {
updater.AddSearchTags(GetDynamicKerberosSearchConcepts());
}
}
}
} // namespace ash::settings
|