summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_setting_combo_model.cc
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 22:06:27 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 22:06:27 +0000
commit77767745f94bb6e2ae267260de97af697fd2af82 (patch)
treefa18692d1ce6a175bb4ce5c7b9481c5c4f87750e /chrome/browser/content_setting_combo_model.cc
parent9d166afe522da91217060a34787b16fa705f15e3 (diff)
downloadchromium_src-77767745f94bb6e2ae267260de97af697fd2af82.zip
chromium_src-77767745f94bb6e2ae267260de97af697fd2af82.tar.gz
chromium_src-77767745f94bb6e2ae267260de97af697fd2af82.tar.bz2
Moves ActionComboboxModel class to its own header so we can share common code between windows and linux.
BUG=None TEST=compiles, and still works as before. Review URL: http://codereview.chromium.org/661225 Patch from thiago.farina@gmail.com. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40446 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/content_setting_combo_model.cc')
-rw-r--r--chrome/browser/content_setting_combo_model.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/chrome/browser/content_setting_combo_model.cc b/chrome/browser/content_setting_combo_model.cc
new file mode 100644
index 0000000..e37c151
--- /dev/null
+++ b/chrome/browser/content_setting_combo_model.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/content_setting_combo_model.h"
+
+#include "app/l10n_util.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+// The settings shown in the combobox if show_ask_ is false;
+const ContentSetting kNoAskSettings[] = { CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_BLOCK };
+
+// The settings shown in the combobox if show_ask_ is true;
+const ContentSetting kAskSettings[] = { CONTENT_SETTING_ALLOW,
+ CONTENT_SETTING_ASK,
+ CONTENT_SETTING_BLOCK };
+
+} // namespace
+
+ContentSettingComboModel::ContentSettingComboModel(bool show_ask)
+ : show_ask_(show_ask) {
+}
+
+ContentSettingComboModel::~ContentSettingComboModel() {
+}
+
+int ContentSettingComboModel::GetItemCount() {
+ return show_ask_ ? arraysize(kAskSettings) : arraysize(kNoAskSettings);
+}
+
+std::wstring ContentSettingComboModel::GetItemAt(int index) {
+ switch (SettingForIndex(index)) {
+ case CONTENT_SETTING_ALLOW:
+ return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON);
+ case CONTENT_SETTING_BLOCK:
+ return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON);
+ case CONTENT_SETTING_ASK:
+ return l10n_util::GetString(IDS_EXCEPTIONS_ASK_BUTTON);
+ default:
+ NOTREACHED();
+ }
+ return std::wstring();
+}
+
+ContentSetting ContentSettingComboModel::SettingForIndex(int index) {
+ return show_ask_ ? kAskSettings[index] : kNoAskSettings[index];
+}
+
+int ContentSettingComboModel::IndexForSetting(ContentSetting setting) {
+ for (int i = 0; i < GetItemCount(); ++i)
+ if (SettingForIndex(i) == setting)
+ return i;
+ NOTREACHED();
+ return 0;
+}
+