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