Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / permissions / settings_override_permission.cc
blobf5bf9468610cd074abe5e138c0d9e7373ce7b3ac
1 // Copyright 2013 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 "chrome/common/extensions/permissions/settings_override_permission.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "grit/generated_resources.h"
9 #include "ui/base/l10n/l10n_util.h"
12 namespace extensions {
14 SettingsOverrideAPIPermission::SettingsOverrideAPIPermission(
15 const APIPermissionInfo* permission, const std::string& setting_value)
16 : APIPermission(permission),
17 setting_value_(setting_value) {
20 SettingsOverrideAPIPermission::~SettingsOverrideAPIPermission() {
23 bool SettingsOverrideAPIPermission::HasMessages() const {
24 return info()->message_id() > PermissionMessage::kNone;
27 PermissionMessages SettingsOverrideAPIPermission::GetMessages() const {
28 DCHECK(HasMessages());
29 int string_id = -1;
30 switch (id()) {
31 case kHomepage: {
32 string_id = IDS_EXTENSION_PROMPT_WARNING_HOME_PAGE_SETTING_OVERRIDE;
33 break;
35 case kStartupPages: {
36 string_id = IDS_EXTENSION_PROMPT_WARNING_START_PAGE_SETTING_OVERRIDE;
37 break;
39 case kSearchProvider: {
40 string_id = IDS_EXTENSION_PROMPT_WARNING_SEARCH_SETTINGS_OVERRIDE;
41 break;
43 default:
44 NOTREACHED();
46 PermissionMessages result;
47 result.push_back(PermissionMessage(
48 info()->message_id(),
49 l10n_util::GetStringFUTF16(string_id,
50 base::UTF8ToUTF16(setting_value_))));
51 return result;
54 bool SettingsOverrideAPIPermission::Check(
55 const APIPermission::CheckParam* param) const {
56 return !param;
59 bool SettingsOverrideAPIPermission::Contains(const APIPermission* rhs) const {
60 CHECK(info() == rhs->info());
61 return true;
64 bool SettingsOverrideAPIPermission::Equal(const APIPermission* rhs) const {
65 if (this == rhs)
66 return true;
67 CHECK(info() == rhs->info());
68 return true;
71 bool SettingsOverrideAPIPermission::FromValue(const base::Value* value) {
72 if (value)
73 return false;
74 return true;
77 scoped_ptr<base::Value> SettingsOverrideAPIPermission::ToValue() const {
78 return scoped_ptr<base::Value>();
81 APIPermission* SettingsOverrideAPIPermission::Clone() const {
82 return new SettingsOverrideAPIPermission(info(), setting_value_);
85 APIPermission* SettingsOverrideAPIPermission::Diff(
86 const APIPermission* rhs) const {
87 CHECK(info() == rhs->info());
88 return NULL;
91 APIPermission* SettingsOverrideAPIPermission::Union(
92 const APIPermission* rhs) const {
93 CHECK(info() == rhs->info());
94 return new SettingsOverrideAPIPermission(info(), setting_value_);
97 APIPermission* SettingsOverrideAPIPermission::Intersect(
98 const APIPermission* rhs) const {
99 CHECK(info() == rhs->info());
100 return new SettingsOverrideAPIPermission(info(), setting_value_);
103 void SettingsOverrideAPIPermission::Write(IPC::Message* m) const {
106 bool SettingsOverrideAPIPermission::Read(
107 const IPC::Message* m, PickleIterator* iter) {
108 return true;
111 void SettingsOverrideAPIPermission::Log(std::string* log) const {
114 } // namespace extensions