| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/extensions/extension_context_menu_model.h" | 5 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_tab_util.h" | 9 #include "chrome/browser/extensions/extension_tab_util.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_action.h" | 14 #include "chrome/common/extensions/extension_action.h" |
| 15 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 | 22 |
| 23 using content::OpenURLParams; | 23 using content::OpenURLParams; |
| 24 using content::Referrer; | 24 using content::Referrer; |
| 25 using content::WebContents; | 25 using content::WebContents; |
| 26 | 26 |
| 27 enum MenuEntries { | |
| 28 NAME = 0, | |
| 29 CONFIGURE, | |
| 30 HIDE, | |
| 31 DISABLE, | |
| 32 UNINSTALL, | |
| 33 MANAGE | |
| 34 }; | |
| 35 | |
| 36 ExtensionContextMenuModel::ExtensionContextMenuModel( | 27 ExtensionContextMenuModel::ExtensionContextMenuModel( |
| 37 const Extension* extension, | 28 const Extension* extension, |
| 38 Browser* browser) | 29 Browser* browser) |
| 39 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), | 30 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), |
| 40 extension_id_(extension->id()), | 31 extension_id_(extension->id()), |
| 41 browser_(browser), | 32 browser_(browser), |
| 42 profile_(browser->profile()) { | 33 profile_(browser->profile()) { |
| 43 extension_action_ = extension->browser_action(); | 34 extension_action_ = extension->browser_action(); |
| 44 if (!extension_action_) | 35 if (!extension_action_) |
| 45 extension_action_ = extension->page_action(); | 36 extension_action_ = extension->page_action(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 57 return false; | 48 return false; |
| 58 | 49 |
| 59 if (command_id == CONFIGURE) { | 50 if (command_id == CONFIGURE) { |
| 60 return extension->options_url().spec().length() > 0; | 51 return extension->options_url().spec().length() > 0; |
| 61 } else if (command_id == NAME) { | 52 } else if (command_id == NAME) { |
| 62 // The NAME links to the Homepage URL. If the extension doesn't have a | 53 // The NAME links to the Homepage URL. If the extension doesn't have a |
| 63 // homepage, we just disable this menu item. | 54 // homepage, we just disable this menu item. |
| 64 return extension->GetHomepageURL().is_valid(); | 55 return extension->GetHomepageURL().is_valid(); |
| 65 } else if (command_id == DISABLE || command_id == UNINSTALL) { | 56 } else if (command_id == DISABLE || command_id == UNINSTALL) { |
| 66 // Some extension types can not be disabled or uninstalled. | 57 // Some extension types can not be disabled or uninstalled. |
| 67 return Extension::UserMayDisable(extension->location()); | 58 return profile_->GetExtensionService()->extension_management_policy()-> |
| 59 UserMayModifyStatus(extension, NULL); |
| 68 } | 60 } |
| 69 return true; | 61 return true; |
| 70 } | 62 } |
| 71 | 63 |
| 72 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( | 64 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( |
| 73 int command_id, ui::Accelerator* accelerator) { | 65 int command_id, ui::Accelerator* accelerator) { |
| 74 return false; | 66 return false; |
| 75 } | 67 } |
| 76 | 68 |
| 77 void ExtensionContextMenuModel::ExecuteCommand(int command_id) { | 69 void ExtensionContextMenuModel::ExecuteCommand(int command_id) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (extension->browser_action()) | 141 if (extension->browser_action()) |
| 150 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); | 142 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); |
| 151 AddSeparator(); | 143 AddSeparator(); |
| 152 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); | 144 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); |
| 153 } | 145 } |
| 154 | 146 |
| 155 const Extension* ExtensionContextMenuModel::GetExtension() const { | 147 const Extension* ExtensionContextMenuModel::GetExtension() const { |
| 156 ExtensionService* extension_service = profile_->GetExtensionService(); | 148 ExtensionService* extension_service = profile_->GetExtensionService(); |
| 157 return extension_service->GetExtensionById(extension_id_, false); | 149 return extension_service->GetExtensionById(extension_id_, false); |
| 158 } | 150 } |
| OLD | NEW |