| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/content_setting_combo_model.h" | 5 #include "chrome/browser/content_setting_combo_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // The settings shown in the combobox if show_session_ is false; | 15 // The settings shown in the combobox if show_session_ is false; |
| 16 const ContentSetting kNoSessionSettings[] = { CONTENT_SETTING_ALLOW, | 16 const ContentSetting kNoSessionSettings[] = { CONTENT_SETTING_ALLOW, |
| 17 CONTENT_SETTING_BLOCK }; | 17 CONTENT_SETTING_BLOCK }; |
| 18 | 18 |
| 19 // The settings shown in the combobox if show_session_ is true; | 19 // The settings shown in the combobox if show_session_ is true; |
| 20 const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW, | 20 const ContentSetting kSessionSettings[] = { CONTENT_SETTING_ALLOW, |
| 21 CONTENT_SETTING_SESSION_ONLY, | 21 CONTENT_SETTING_SESSION_ONLY, |
| 22 CONTENT_SETTING_BLOCK }; | 22 CONTENT_SETTING_BLOCK }; |
| 23 | 23 |
| 24 // The settings shown in the combobox if show_session_ is true, and we still | |
| 25 // offer the cookie prompt mode. | |
| 26 const ContentSetting kSessionAskSettings[] = { CONTENT_SETTING_ALLOW, | |
| 27 CONTENT_SETTING_ASK, | |
| 28 CONTENT_SETTING_SESSION_ONLY, | |
| 29 CONTENT_SETTING_BLOCK }; | |
| 30 | |
| 31 } // namespace | 24 } // namespace |
| 32 | 25 |
| 33 ContentSettingComboModel::ContentSettingComboModel(bool show_session) | 26 ContentSettingComboModel::ContentSettingComboModel(bool show_session) |
| 34 : show_session_(show_session), | 27 : show_session_(show_session) { |
| 35 disable_cookie_prompt_(!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 36 switches::kEnableCookiePrompt)) { | |
| 37 } | 28 } |
| 38 | 29 |
| 39 ContentSettingComboModel::~ContentSettingComboModel() { | 30 ContentSettingComboModel::~ContentSettingComboModel() { |
| 40 } | 31 } |
| 41 | 32 |
| 42 int ContentSettingComboModel::GetItemCount() { | 33 int ContentSettingComboModel::GetItemCount() { |
| 43 if (show_session_) { | 34 return show_session_ ? arraysize(kSessionSettings) |
| 44 return disable_cookie_prompt_ ? | 35 : arraysize(kNoSessionSettings); |
| 45 arraysize(kSessionSettings) : arraysize(kSessionAskSettings); | |
| 46 } else { | |
| 47 return arraysize(kNoSessionSettings); | |
| 48 } | |
| 49 } | 36 } |
| 50 | 37 |
| 51 string16 ContentSettingComboModel::GetItemAt(int index) { | 38 string16 ContentSettingComboModel::GetItemAt(int index) { |
| 52 switch (SettingForIndex(index)) { | 39 switch (SettingForIndex(index)) { |
| 53 case CONTENT_SETTING_ALLOW: | 40 case CONTENT_SETTING_ALLOW: |
| 54 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON); | 41 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON); |
| 55 case CONTENT_SETTING_BLOCK: | 42 case CONTENT_SETTING_BLOCK: |
| 56 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON); | 43 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON); |
| 57 case CONTENT_SETTING_ASK: | |
| 58 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ASK_BUTTON); | |
| 59 case CONTENT_SETTING_SESSION_ONLY: | 44 case CONTENT_SETTING_SESSION_ONLY: |
| 60 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_SESSION_ONLY_BUTTON); | 45 return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_SESSION_ONLY_BUTTON); |
| 61 default: | 46 default: |
| 62 NOTREACHED(); | 47 NOTREACHED(); |
| 63 } | 48 } |
| 64 return string16(); | 49 return string16(); |
| 65 } | 50 } |
| 66 | 51 |
| 67 ContentSetting ContentSettingComboModel::SettingForIndex(int index) { | 52 ContentSetting ContentSettingComboModel::SettingForIndex(int index) { |
| 68 if (show_session_) { | 53 return show_session_ ? kSessionSettings[index] : kNoSessionSettings[index]; |
| 69 return disable_cookie_prompt_ ? | |
| 70 kSessionSettings[index] : kSessionAskSettings[index]; | |
| 71 } else { | |
| 72 return kNoSessionSettings[index]; | |
| 73 } | |
| 74 } | 54 } |
| 75 | 55 |
| 76 int ContentSettingComboModel::IndexForSetting(ContentSetting setting) { | 56 int ContentSettingComboModel::IndexForSetting(ContentSetting setting) { |
| 77 for (int i = 0; i < GetItemCount(); ++i) | 57 for (int i = 0; i < GetItemCount(); ++i) |
| 78 if (SettingForIndex(i) == setting) | 58 if (SettingForIndex(i) == setting) |
| 79 return i; | 59 return i; |
| 80 NOTREACHED(); | 60 NOTREACHED(); |
| 81 return 0; | 61 return 0; |
| 82 } | 62 } |
| 83 | 63 |
| OLD | NEW |