Home | History | Annotate | Download | only in permissions
      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.
      4 
      5 #include "chrome/common/extensions/permissions/settings_override_permission.h"
      6 
      7 #include "base/strings/utf_string_conversions.h"
      8 #include "grit/generated_resources.h"
      9 #include "ui/base/l10n/l10n_util.h"
     10 
     11 
     12 namespace extensions {
     13 
     14 SettingsOverrideAPIPermission::SettingsOverrideAPIPermission(
     15     const APIPermissionInfo* permission, const std::string& setting_value)
     16     : APIPermission(permission),
     17       setting_value_(setting_value) {
     18 }
     19 
     20 SettingsOverrideAPIPermission::~SettingsOverrideAPIPermission() {
     21 }
     22 
     23 bool SettingsOverrideAPIPermission::HasMessages() const {
     24   return info()->message_id() > PermissionMessage::kNone;
     25 }
     26 
     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;
     34     }
     35     case kStartupPages: {
     36       string_id = IDS_EXTENSION_PROMPT_WARNING_START_PAGE_SETTING_OVERRIDE;
     37       break;
     38     }
     39     case kSearchProvider: {
     40       string_id = IDS_EXTENSION_PROMPT_WARNING_SEARCH_SETTINGS_OVERRIDE;
     41       break;
     42     }
     43     default:
     44       NOTREACHED();
     45   }
     46   PermissionMessages result;
     47   result.push_back(PermissionMessage(
     48       info()->message_id(),
     49       l10n_util::GetStringFUTF16(string_id, UTF8ToUTF16(setting_value_))));
     50   return result;
     51 }
     52 
     53 bool SettingsOverrideAPIPermission::Check(
     54     const APIPermission::CheckParam* param) const {
     55   return !param;
     56 }
     57 
     58 bool SettingsOverrideAPIPermission::Contains(const APIPermission* rhs) const {
     59   CHECK(info() == rhs->info());
     60   return true;
     61 }
     62 
     63 bool SettingsOverrideAPIPermission::Equal(const APIPermission* rhs) const {
     64   if (this == rhs)
     65     return true;
     66   CHECK(info() == rhs->info());
     67   return true;
     68 }
     69 
     70 bool SettingsOverrideAPIPermission::FromValue(const base::Value* value) {
     71   if (value)
     72     return false;
     73   return true;
     74 }
     75 
     76 scoped_ptr<base::Value> SettingsOverrideAPIPermission::ToValue() const {
     77   return scoped_ptr<base::Value>();
     78 }
     79 
     80 APIPermission* SettingsOverrideAPIPermission::Clone() const {
     81   return new SettingsOverrideAPIPermission(info(), setting_value_);
     82 }
     83 
     84 APIPermission* SettingsOverrideAPIPermission::Diff(
     85     const APIPermission* rhs) const {
     86   CHECK(info() == rhs->info());
     87   return NULL;
     88 }
     89 
     90 APIPermission* SettingsOverrideAPIPermission::Union(
     91     const APIPermission* rhs) const {
     92   CHECK(info() == rhs->info());
     93   return new SettingsOverrideAPIPermission(info(), setting_value_);
     94 }
     95 
     96 APIPermission* SettingsOverrideAPIPermission::Intersect(
     97     const APIPermission* rhs) const {
     98   CHECK(info() == rhs->info());
     99   return new SettingsOverrideAPIPermission(info(), setting_value_);
    100 }
    101 
    102 void SettingsOverrideAPIPermission::Write(IPC::Message* m) const {
    103 }
    104 
    105 bool SettingsOverrideAPIPermission::Read(
    106     const IPC::Message* m, PickleIterator* iter) {
    107   return true;
    108 }
    109 
    110 void SettingsOverrideAPIPermission::Log(std::string* log) const {
    111 }
    112 
    113 }  // namespace extensions
    114