[Extensions Toolbar Mac] Fix actions bar min size, spacing
[chromium-blink-merge.git] / chrome / browser / ui / website_settings / permission_menu_model.cc
blob7c6b450fc8bfb288405ddd78d6781be5c7c7b0d9
1 // Copyright (c) 2012 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 "chrome/browser/ui/website_settings/permission_menu_model.h"
7 #include "chrome/grit/generated_resources.h"
8 #include "ui/base/l10n/l10n_util.h"
10 PermissionMenuModel::PermissionMenuModel(
11 const GURL& url,
12 const WebsiteSettingsUI::PermissionInfo& info,
13 const ChangeCallback& callback)
14 : ui::SimpleMenuModel(this), permission_(info), callback_(callback) {
15 DCHECK(!callback_.is_null());
16 base::string16 label;
17 switch (permission_.default_setting) {
18 case CONTENT_SETTING_ALLOW:
19 label = l10n_util::GetStringUTF16(
20 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW);
21 break;
22 case CONTENT_SETTING_BLOCK:
23 label = l10n_util::GetStringUTF16(
24 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK);
25 break;
26 case CONTENT_SETTING_ASK:
27 // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior.
28 label = l10n_util::GetStringUTF16(
29 permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS
30 ? IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK
31 : IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK);
32 break;
33 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT:
34 label = l10n_util::GetStringUTF16(
35 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_DETECT_IMPORTANT_CONTENT);
36 break;
37 case CONTENT_SETTING_NUM_SETTINGS:
38 NOTREACHED();
39 default:
40 break;
42 AddCheckItem(CONTENT_SETTING_DEFAULT, label);
44 // Media only support CONTENTE_SETTTING_ALLOW for https.
45 if (permission_.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM ||
46 url.SchemeIsSecure()) {
47 label = l10n_util::GetStringUTF16(
48 IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW);
49 AddCheckItem(CONTENT_SETTING_ALLOW, label);
52 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS) {
53 label = l10n_util::GetStringUTF16(
54 IDS_WEBSITE_SETTINGS_MENU_ITEM_DETECT_IMPORTANT_CONTENT);
55 AddCheckItem(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, label);
58 if (permission_.type != CONTENT_SETTINGS_TYPE_FULLSCREEN) {
59 label = l10n_util::GetStringUTF16(
60 IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK);
61 AddCheckItem(CONTENT_SETTING_BLOCK, label);
65 PermissionMenuModel::PermissionMenuModel(const GURL& url,
66 ContentSetting setting,
67 const ChangeCallback& callback)
68 : ui::SimpleMenuModel(this), callback_(callback) {
69 DCHECK(setting == CONTENT_SETTING_ALLOW || setting == CONTENT_SETTING_BLOCK);
70 permission_.type = CONTENT_SETTINGS_TYPE_DEFAULT;
71 permission_.setting = setting;
72 permission_.default_setting = CONTENT_SETTING_NUM_SETTINGS;
73 AddCheckItem(CONTENT_SETTING_ALLOW,
74 l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW));
75 AddCheckItem(CONTENT_SETTING_BLOCK,
76 l10n_util::GetStringUTF16(IDS_PERMISSION_DENY));
79 PermissionMenuModel::~PermissionMenuModel() {}
81 bool PermissionMenuModel::IsCommandIdChecked(int command_id) const {
82 // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior.
83 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS &&
84 permission_.setting == CONTENT_SETTING_ASK &&
85 command_id == CONTENT_SETTING_BLOCK) {
86 return true;
88 return permission_.setting == command_id;
91 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const {
92 return true;
95 bool PermissionMenuModel::GetAcceleratorForCommandId(
96 int command_id,
97 ui::Accelerator* accelerator) {
98 // Accelerators are not supported.
99 return false;
102 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) {
103 permission_.setting = static_cast<ContentSetting>(command_id);
104 callback_.Run(permission_);