Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / common / permissions / settings_override_permission.cc
blobe23bc2eecc5c2e4fed369d9fc02ccadbba87001e
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 "grit/extensions_strings.h"
9 #include "ui/base/l10n/l10n_util.h"
11 namespace extensions {
13 SettingsOverrideAPIPermission::SettingsOverrideAPIPermission(
14 const APIPermissionInfo* permission,
15 const std::string& setting_value)
16 : APIPermission(permission), setting_value_(setting_value) {}
18 SettingsOverrideAPIPermission::~SettingsOverrideAPIPermission() {}
20 bool SettingsOverrideAPIPermission::HasMessages() const {
21 return info()->message_id() > PermissionMessage::kNone;
24 PermissionMessages SettingsOverrideAPIPermission::GetMessages() const {
25 DCHECK(HasMessages());
26 int string_id = -1;
27 switch (id()) {
28 case kHomepage: {
29 string_id = IDS_EXTENSION_PROMPT_WARNING_HOME_PAGE_SETTING_OVERRIDE;
30 break;
32 case kStartupPages: {
33 string_id = IDS_EXTENSION_PROMPT_WARNING_START_PAGE_SETTING_OVERRIDE;
34 break;
36 case kSearchProvider: {
37 string_id = IDS_EXTENSION_PROMPT_WARNING_SEARCH_SETTINGS_OVERRIDE;
38 break;
40 default:
41 NOTREACHED();
43 PermissionMessages result;
44 result.push_back(
45 PermissionMessage(info()->message_id(),
46 l10n_util::GetStringFUTF16(
47 string_id, base::UTF8ToUTF16(setting_value_))));
48 return result;
51 bool SettingsOverrideAPIPermission::Check(
52 const APIPermission::CheckParam* param) const {
53 return (param == NULL);
56 bool SettingsOverrideAPIPermission::Contains(const APIPermission* rhs) const {
57 CHECK_EQ(info(), rhs->info());
58 return true;
61 bool SettingsOverrideAPIPermission::Equal(const APIPermission* rhs) const {
62 if (this != rhs)
63 CHECK_EQ(info(), rhs->info());
64 return true;
67 bool SettingsOverrideAPIPermission::FromValue(
68 const base::Value* value,
69 std::string* /*error*/,
70 std::vector<std::string>* unhandled_permissions) {
71 return (value == NULL);
74 scoped_ptr<base::Value> SettingsOverrideAPIPermission::ToValue() const {
75 return scoped_ptr<base::Value>();
78 APIPermission* SettingsOverrideAPIPermission::Clone() const {
79 return new SettingsOverrideAPIPermission(info(), setting_value_);
82 APIPermission* SettingsOverrideAPIPermission::Diff(
83 const APIPermission* rhs) const {
84 CHECK_EQ(info(), rhs->info());
85 return NULL;
88 APIPermission* SettingsOverrideAPIPermission::Union(
89 const APIPermission* rhs) const {
90 CHECK_EQ(info(), rhs->info());
91 return new SettingsOverrideAPIPermission(info(), setting_value_);
94 APIPermission* SettingsOverrideAPIPermission::Intersect(
95 const APIPermission* rhs) const {
96 CHECK_EQ(info(), rhs->info());
97 return new SettingsOverrideAPIPermission(info(), setting_value_);
100 void SettingsOverrideAPIPermission::Write(IPC::Message* m) const {}
102 bool SettingsOverrideAPIPermission::Read(const IPC::Message* m,
103 PickleIterator* iter) {
104 return true;
107 void SettingsOverrideAPIPermission::Log(std::string* log) const {}
109 } // namespace extensions