Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / extensions / common / permissions / settings_override_permission.cc
blob4514a3fd93b32dc31f8e7c174fccd8b3898d127b
1 // Copyright 2014 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.
5 #include "extensions/common/permissions/settings_override_permission.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "extensions/common/permissions/api_permission_set.h"
9 #include "grit/extensions_strings.h"
10 #include "ui/base/l10n/l10n_util.h"
12 namespace extensions {
14 SettingsOverrideAPIPermission::SettingsOverrideAPIPermission(
15 const APIPermissionInfo* permission,
16 const std::string& setting_value)
17 : APIPermission(permission), setting_value_(setting_value) {}
19 SettingsOverrideAPIPermission::~SettingsOverrideAPIPermission() {}
21 PermissionIDSet SettingsOverrideAPIPermission::GetPermissions() const {
22 PermissionIDSet permissions;
23 permissions.insert(info()->id(), base::UTF8ToUTF16(setting_value_));
24 return permissions;
27 bool SettingsOverrideAPIPermission::HasMessages() const {
28 return info()->message_id() > PermissionMessage::kNone;
31 PermissionMessages SettingsOverrideAPIPermission::GetMessages() const {
32 DCHECK(HasMessages());
33 int string_id = -1;
34 // Warning: when modifying this function, be sure to modify the correct rule
35 // in ChromePermissionMessageProvider.
36 switch (id()) {
37 case kHomepage: {
38 string_id = IDS_EXTENSION_PROMPT_WARNING_HOME_PAGE_SETTING_OVERRIDE;
39 break;
41 case kStartupPages: {
42 string_id = IDS_EXTENSION_PROMPT_WARNING_START_PAGE_SETTING_OVERRIDE;
43 break;
45 case kSearchProvider: {
46 string_id = IDS_EXTENSION_PROMPT_WARNING_SEARCH_SETTINGS_OVERRIDE;
47 break;
49 default:
50 NOTREACHED();
52 PermissionMessages result;
53 result.push_back(
54 PermissionMessage(info()->message_id(),
55 l10n_util::GetStringFUTF16(
56 string_id, base::UTF8ToUTF16(setting_value_))));
57 return result;
60 bool SettingsOverrideAPIPermission::Check(
61 const APIPermission::CheckParam* param) const {
62 return (param == NULL);
65 bool SettingsOverrideAPIPermission::Contains(const APIPermission* rhs) const {
66 CHECK_EQ(info(), rhs->info());
67 return true;
70 bool SettingsOverrideAPIPermission::Equal(const APIPermission* rhs) const {
71 if (this != rhs)
72 CHECK_EQ(info(), rhs->info());
73 return true;
76 bool SettingsOverrideAPIPermission::FromValue(
77 const base::Value* value,
78 std::string* /*error*/,
79 std::vector<std::string>* unhandled_permissions) {
80 return (value == NULL);
83 scoped_ptr<base::Value> SettingsOverrideAPIPermission::ToValue() const {
84 return scoped_ptr<base::Value>();
87 APIPermission* SettingsOverrideAPIPermission::Clone() const {
88 return new SettingsOverrideAPIPermission(info(), setting_value_);
91 APIPermission* SettingsOverrideAPIPermission::Diff(
92 const APIPermission* rhs) const {
93 CHECK_EQ(info(), rhs->info());
94 return NULL;
97 APIPermission* SettingsOverrideAPIPermission::Union(
98 const APIPermission* rhs) const {
99 CHECK_EQ(info(), rhs->info());
100 return new SettingsOverrideAPIPermission(info(), setting_value_);
103 APIPermission* SettingsOverrideAPIPermission::Intersect(
104 const APIPermission* rhs) const {
105 CHECK_EQ(info(), rhs->info());
106 return new SettingsOverrideAPIPermission(info(), setting_value_);
109 void SettingsOverrideAPIPermission::Write(IPC::Message* m) const {}
111 bool SettingsOverrideAPIPermission::Read(const IPC::Message* m,
112 PickleIterator* iter) {
113 return true;
116 void SettingsOverrideAPIPermission::Log(std::string* log) const {}
118 } // namespace extensions