| 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_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
| 9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/extensions/extension_tab_util.h" | 12 #include "chrome/browser/extensions/extension_tab_util.h" |
| 13 #include "chrome/browser/extensions/management_policy.h" | 13 #include "chrome/browser/extensions/management_policy.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_tabstrip.h" | 17 #include "chrome/browser/ui/browser_tabstrip.h" |
| 18 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/extensions/manifest_url_info.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 23 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 24 #include "grit/chromium_strings.h" | 25 #include "grit/chromium_strings.h" |
| 25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 | 28 |
| 28 using content::OpenURLParams; | 29 using content::OpenURLParams; |
| 29 using content::Referrer; | 30 using content::Referrer; |
| 30 using content::WebContents; | 31 using content::WebContents; |
| 31 using extensions::Extension; | 32 using extensions::Extension; |
| 33 using extensions::ManifestURLInfo; |
| 32 | 34 |
| 33 ExtensionContextMenuModel::ExtensionContextMenuModel( | 35 ExtensionContextMenuModel::ExtensionContextMenuModel( |
| 34 const Extension* extension, | 36 const Extension* extension, |
| 35 Browser* browser, | 37 Browser* browser, |
| 36 PopupDelegate* delegate) | 38 PopupDelegate* delegate) |
| 37 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), | 39 : ALLOW_THIS_IN_INITIALIZER_LIST(SimpleMenuModel(this)), |
| 38 extension_id_(extension->id()), | 40 extension_id_(extension->id()), |
| 39 browser_(browser), | 41 browser_(browser), |
| 40 profile_(browser->profile()), | 42 profile_(browser->profile()), |
| 41 delegate_(delegate) { | 43 delegate_(delegate) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 66 bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const { | 68 bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const { |
| 67 const Extension* extension = this->GetExtension(); | 69 const Extension* extension = this->GetExtension(); |
| 68 if (!extension) | 70 if (!extension) |
| 69 return false; | 71 return false; |
| 70 | 72 |
| 71 if (command_id == CONFIGURE) { | 73 if (command_id == CONFIGURE) { |
| 72 return extension->options_url().spec().length() > 0; | 74 return extension->options_url().spec().length() > 0; |
| 73 } else if (command_id == NAME) { | 75 } else if (command_id == NAME) { |
| 74 // The NAME links to the Homepage URL. If the extension doesn't have a | 76 // The NAME links to the Homepage URL. If the extension doesn't have a |
| 75 // homepage, we just disable this menu item. | 77 // homepage, we just disable this menu item. |
| 76 return extension->GetHomepageURL().is_valid(); | 78 return ManifestURLInfo::GetHomepageURL(extension).is_valid(); |
| 77 } else if (command_id == INSPECT_POPUP) { | 79 } else if (command_id == INSPECT_POPUP) { |
| 78 WebContents* web_contents = chrome::GetActiveWebContents(browser_); | 80 WebContents* web_contents = chrome::GetActiveWebContents(browser_); |
| 79 if (!web_contents) | 81 if (!web_contents) |
| 80 return false; | 82 return false; |
| 81 | 83 |
| 82 return extension_action_ && | 84 return extension_action_ && |
| 83 extension_action_->HasPopup(SessionID::IdForTab(web_contents)); | 85 extension_action_->HasPopup(SessionID::IdForTab(web_contents)); |
| 84 } else if (command_id == UNINSTALL) { | 86 } else if (command_id == UNINSTALL) { |
| 85 // Some extension types can not be uninstalled. | 87 // Some extension types can not be uninstalled. |
| 86 return extensions::ExtensionSystem::Get( | 88 return extensions::ExtensionSystem::Get( |
| 87 profile_)->management_policy()->UserMayModifySettings(extension, NULL); | 89 profile_)->management_policy()->UserMayModifySettings(extension, NULL); |
| 88 } | 90 } |
| 89 return true; | 91 return true; |
| 90 } | 92 } |
| 91 | 93 |
| 92 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( | 94 bool ExtensionContextMenuModel::GetAcceleratorForCommandId( |
| 93 int command_id, ui::Accelerator* accelerator) { | 95 int command_id, ui::Accelerator* accelerator) { |
| 94 return false; | 96 return false; |
| 95 } | 97 } |
| 96 | 98 |
| 97 void ExtensionContextMenuModel::ExecuteCommand(int command_id) { | 99 void ExtensionContextMenuModel::ExecuteCommand(int command_id) { |
| 98 const Extension* extension = GetExtension(); | 100 const Extension* extension = GetExtension(); |
| 99 if (!extension) | 101 if (!extension) |
| 100 return; | 102 return; |
| 101 | 103 |
| 102 switch (command_id) { | 104 switch (command_id) { |
| 103 case NAME: { | 105 case NAME: { |
| 104 OpenURLParams params(extension->GetHomepageURL(), Referrer(), | 106 OpenURLParams params(ManifestURLInfo::GetHomepageURL(extension), |
| 105 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, | 107 Referrer(), NEW_FOREGROUND_TAB, |
| 106 false); | 108 content::PAGE_TRANSITION_LINK, false); |
| 107 browser_->OpenURL(params); | 109 browser_->OpenURL(params); |
| 108 break; | 110 break; |
| 109 } | 111 } |
| 110 case CONFIGURE: | 112 case CONFIGURE: |
| 111 DCHECK(!extension->options_url().is_empty()); | 113 DCHECK(!extension->options_url().is_empty()); |
| 112 extensions::ExtensionSystem::Get(profile_)->process_manager()-> | 114 extensions::ExtensionSystem::Get(profile_)->process_manager()-> |
| 113 OpenOptionsPage(extension, browser_); | 115 OpenOptionsPage(extension, browser_); |
| 114 break; | 116 break; |
| 115 case HIDE: { | 117 case HIDE: { |
| 116 ExtensionService* extension_service = | 118 ExtensionService* extension_service = |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); | 178 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); |
| 177 AddSeparator(ui::NORMAL_SEPARATOR); | 179 AddSeparator(ui::NORMAL_SEPARATOR); |
| 178 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); | 180 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSIONS); |
| 179 } | 181 } |
| 180 | 182 |
| 181 const Extension* ExtensionContextMenuModel::GetExtension() const { | 183 const Extension* ExtensionContextMenuModel::GetExtension() const { |
| 182 ExtensionService* extension_service = | 184 ExtensionService* extension_service = |
| 183 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 185 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 184 return extension_service->GetExtensionById(extension_id_, false); | 186 return extension_service->GetExtensionById(extension_id_, false); |
| 185 } | 187 } |
| OLD | NEW |