Chromium Code Reviews| 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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/active_script_controller.h" | |
| 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 10 #include "chrome/browser/extensions/extension_action.h" | 11 #include "chrome/browser/extensions/extension_action.h" |
| 11 #include "chrome/browser/extensions/extension_action_manager.h" | 12 #include "chrome/browser/extensions/extension_action_manager.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_tab_util.h" | 14 #include "chrome/browser/extensions/extension_tab_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 20 #include "chrome/common/extensions/manifest_url_handler.h" | 21 #include "chrome/common/extensions/manifest_url_handler.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 "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 25 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 26 #include "extensions/browser/management_policy.h" | 27 #include "extensions/browser/management_policy.h" |
| 27 #include "extensions/browser/uninstall_reason.h" | 28 #include "extensions/browser/uninstall_reason.h" |
| 28 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/manifest_constants.h" | |
| 29 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 32 | 34 |
| 33 using content::OpenURLParams; | 35 using content::OpenURLParams; |
| 34 using content::Referrer; | 36 using content::Referrer; |
| 35 using content::WebContents; | 37 using content::WebContents; |
| 36 using extensions::Extension; | 38 using extensions::Extension; |
| 37 | 39 |
| 38 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension, | 40 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 return false; | 74 return false; |
| 73 | 75 |
| 74 if (command_id == CONFIGURE) { | 76 if (command_id == CONFIGURE) { |
| 75 return | 77 return |
| 76 extensions::ManifestURL::GetOptionsPage(extension).spec().length() > 0; | 78 extensions::ManifestURL::GetOptionsPage(extension).spec().length() > 0; |
| 77 } else if (command_id == NAME) { | 79 } else if (command_id == NAME) { |
| 78 // The NAME links to the Homepage URL. If the extension doesn't have a | 80 // The NAME links to the Homepage URL. If the extension doesn't have a |
| 79 // homepage, we just disable this menu item. | 81 // homepage, we just disable this menu item. |
| 80 return extensions::ManifestURL::GetHomepageURL(extension).is_valid(); | 82 return extensions::ManifestURL::GetHomepageURL(extension).is_valid(); |
| 81 } else if (command_id == INSPECT_POPUP) { | 83 } else if (command_id == INSPECT_POPUP) { |
| 82 WebContents* web_contents = | 84 WebContents* web_contents = GetActiveWebContents(); |
| 83 browser_->tab_strip_model()->GetActiveWebContents(); | |
| 84 if (!web_contents) | 85 if (!web_contents) |
| 85 return false; | 86 return false; |
| 86 | 87 |
| 87 return extension_action_ && | 88 return extension_action_ && |
| 88 extension_action_->HasPopup(SessionID::IdForTab(web_contents)); | 89 extension_action_->HasPopup(SessionID::IdForTab(web_contents)); |
| 89 } else if (command_id == UNINSTALL) { | 90 } else if (command_id == UNINSTALL) { |
| 90 // Some extension types can not be uninstalled. | 91 // Some extension types can not be uninstalled. |
| 91 return extensions::ExtensionSystem::Get( | 92 return extensions::ExtensionSystem::Get( |
| 92 profile_)->management_policy()->UserMayModifySettings(extension, NULL); | 93 profile_)->management_policy()->UserMayModifySettings(extension, NULL); |
| 93 } | 94 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 106 return; | 107 return; |
| 107 | 108 |
| 108 switch (command_id) { | 109 switch (command_id) { |
| 109 case NAME: { | 110 case NAME: { |
| 110 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), | 111 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), |
| 111 Referrer(), NEW_FOREGROUND_TAB, | 112 Referrer(), NEW_FOREGROUND_TAB, |
| 112 content::PAGE_TRANSITION_LINK, false); | 113 content::PAGE_TRANSITION_LINK, false); |
| 113 browser_->OpenURL(params); | 114 browser_->OpenURL(params); |
| 114 break; | 115 break; |
| 115 } | 116 } |
| 117 case ALWAYS_RUN: { | |
| 118 WebContents* web_contents = GetActiveWebContents(); | |
| 119 if (!web_contents) | |
|
not at google - send to devlin
2014/08/11 22:59:30
please phrase this
if (web_contents) {
extensio
gpdavis
2014/08/12 00:52:05
Solid. I think I'm starting to get used to where
not at google - send to devlin
2014/08/12 19:49:26
I admit that a lot of it is aesthetic, but here, r
| |
| 120 return; | |
| 121 | |
| 122 extensions::ActiveScriptController::GetForWebContents(web_contents) | |
| 123 ->AlwaysRunOnVisibleHost(extension); | |
| 124 break; | |
| 125 } | |
| 116 case CONFIGURE: | 126 case CONFIGURE: |
| 117 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); | 127 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); |
| 118 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); | 128 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); |
| 119 break; | 129 break; |
| 120 case HIDE: { | 130 case HIDE: { |
| 121 extensions::ExtensionActionAPI::SetBrowserActionVisibility( | 131 extensions::ExtensionActionAPI::SetBrowserActionVisibility( |
| 122 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); | 132 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); |
| 123 break; | 133 break; |
| 124 } | 134 } |
| 125 case UNINSTALL: { | 135 case UNINSTALL: { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 extension_action_ = extension_action_manager->GetBrowserAction(*extension); | 180 extension_action_ = extension_action_manager->GetBrowserAction(*extension); |
| 171 if (!extension_action_) | 181 if (!extension_action_) |
| 172 extension_action_ = extension_action_manager->GetPageAction(*extension); | 182 extension_action_ = extension_action_manager->GetPageAction(*extension); |
| 173 | 183 |
| 174 std::string extension_name = extension->name(); | 184 std::string extension_name = extension->name(); |
| 175 // Ampersands need to be escaped to avoid being treated like | 185 // Ampersands need to be escaped to avoid being treated like |
| 176 // mnemonics in the menu. | 186 // mnemonics in the menu. |
| 177 base::ReplaceChars(extension_name, "&", "&&", &extension_name); | 187 base::ReplaceChars(extension_name, "&", "&&", &extension_name); |
| 178 AddItem(NAME, base::UTF8ToUTF16(extension_name)); | 188 AddItem(NAME, base::UTF8ToUTF16(extension_name)); |
| 179 AddSeparator(ui::NORMAL_SEPARATOR); | 189 AddSeparator(ui::NORMAL_SEPARATOR); |
| 190 | |
| 191 // Add the "Always Allow" item for adding persisted permissions for script | |
| 192 // injections if there is an active action for this extension (this action). | |
| 193 WebContents* web_contents = GetActiveWebContents(); | |
| 194 if (web_contents && extensions::ActiveScriptController::GetForWebContents( | |
| 195 web_contents)->HasActiveScriptAction(extension)) { | |
| 196 AddItemWithStringId(ALWAYS_RUN, IDS_EXTENSIONS_ALWAYS_RUN); | |
|
not at google - send to devlin
2014/08/11 22:59:30
This is actually really subtle. The way it's writt
gpdavis
2014/08/12 00:52:05
Wow, that is subtle. Nice catch. I added the com
| |
| 197 } | |
| 198 | |
| 180 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); | 199 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); |
| 181 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | 200 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
| 182 if (extension_action_manager->GetBrowserAction(*extension)) | 201 if (extension_action_manager->GetBrowserAction(*extension)) |
| 183 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); | 202 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); |
| 184 AddSeparator(ui::NORMAL_SEPARATOR); | 203 AddSeparator(ui::NORMAL_SEPARATOR); |
| 185 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); | 204 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); |
| 186 } | 205 } |
| 187 | 206 |
| 188 const Extension* ExtensionContextMenuModel::GetExtension() const { | 207 const Extension* ExtensionContextMenuModel::GetExtension() const { |
| 189 ExtensionService* extension_service = | 208 ExtensionService* extension_service = |
| 190 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 209 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 191 return extension_service->GetExtensionById(extension_id_, false); | 210 return extension_service->GetExtensionById(extension_id_, false); |
| 192 } | 211 } |
| 212 | |
| 213 content::WebContents* ExtensionContextMenuModel::GetActiveWebContents() const { | |
| 214 return browser_->tab_strip_model()->GetActiveWebContents(); | |
| 215 } | |
| OLD | NEW |