content_setting_combo_model.cc revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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/browser/content_setting_combo_model.h"
6
7#include "app/l10n_util.h"
8#include "grit/generated_resources.h"
9
10namespace {
11
12// The settings shown in the combobox if show_session_ is false;
13const ContentSetting kNoSessionSettings[] = { CONTENT_SETTING_ALLOW,
14                                              CONTENT_SETTING_BLOCK };
15
16// The settings shown in the combobox if show_session_ is true;
17const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW,
18                                            CONTENT_SETTING_SESSION_ONLY,
19                                            CONTENT_SETTING_BLOCK };
20
21}  // namespace
22
23ContentSettingComboModel::ContentSettingComboModel(bool show_session)
24    : show_session_(show_session) {
25}
26
27ContentSettingComboModel::~ContentSettingComboModel() {
28}
29
30int ContentSettingComboModel::GetItemCount() {
31  return show_session_ ?
32      arraysize(kSessionSettings) : arraysize(kNoSessionSettings);
33}
34
35std::wstring ContentSettingComboModel::GetItemAt(int index) {
36  switch (SettingForIndex(index)) {
37    case CONTENT_SETTING_ALLOW:
38      return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON);
39    case CONTENT_SETTING_BLOCK:
40      return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON);
41    case CONTENT_SETTING_SESSION_ONLY:
42      return l10n_util::GetString(IDS_EXCEPTIONS_SESSION_ONLY_BUTTON);
43    default:
44      NOTREACHED();
45  }
46  return std::wstring();
47}
48
49ContentSetting ContentSettingComboModel::SettingForIndex(int index) {
50  return show_session_ ? kSessionSettings[index] : kNoSessionSettings[index];
51}
52
53int ContentSettingComboModel::IndexForSetting(ContentSetting setting) {
54  for (int i = 0; i < GetItemCount(); ++i)
55    if (SettingForIndex(i) == setting)
56      return i;
57  NOTREACHED();
58  return 0;
59}
60
61