| 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/chrome_pages.h" | 17 #include "chrome/browser/ui/chrome_pages.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
| 20 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
| 19 #include "chrome/common/extensions/manifest_url_handler.h" | 21 #include "chrome/common/extensions/manifest_url_handler.h" |
| 20 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 23 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 24 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 25 #include "extensions/browser/management_policy.h" | 27 #include "extensions/browser/management_policy.h" |
| 26 #include "extensions/browser/uninstall_reason.h" | 28 #include "extensions/browser/uninstall_reason.h" |
| 27 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/manifest_constants.h" |
| 28 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
| 29 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 31 | 34 |
| 32 using content::OpenURLParams; | 35 using content::OpenURLParams; |
| 33 using content::Referrer; | 36 using content::Referrer; |
| 34 using content::WebContents; | 37 using content::WebContents; |
| 35 using extensions::Extension; | 38 using extensions::Extension; |
| 36 | 39 |
| 37 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension, | 40 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return; | 108 return; |
| 106 | 109 |
| 107 switch (command_id) { | 110 switch (command_id) { |
| 108 case NAME: { | 111 case NAME: { |
| 109 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), | 112 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), |
| 110 Referrer(), NEW_FOREGROUND_TAB, | 113 Referrer(), NEW_FOREGROUND_TAB, |
| 111 content::PAGE_TRANSITION_LINK, false); | 114 content::PAGE_TRANSITION_LINK, false); |
| 112 browser_->OpenURL(params); | 115 browser_->OpenURL(params); |
| 113 break; | 116 break; |
| 114 } | 117 } |
| 118 case ALWAYS_ALLOW: { |
| 119 content::WebContents* web_contents = |
| 120 browser_->tab_strip_model()->GetActiveWebContents(); |
| 121 extensions::ActiveScriptController::GetForWebContents(web_contents) |
| 122 ->AddPersistedPermission(extension); |
| 123 break; |
| 124 } |
| 115 case CONFIGURE: | 125 case CONFIGURE: |
| 116 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); | 126 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); |
| 117 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); | 127 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); |
| 118 break; | 128 break; |
| 119 case HIDE: { | 129 case HIDE: { |
| 120 extensions::ExtensionActionAPI::SetBrowserActionVisibility( | 130 extensions::ExtensionActionAPI::SetBrowserActionVisibility( |
| 121 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); | 131 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); |
| 122 break; | 132 break; |
| 123 } | 133 } |
| 124 case UNINSTALL: { | 134 case UNINSTALL: { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 extension_action_ = extension_action_manager->GetBrowserAction(*extension); | 177 extension_action_ = extension_action_manager->GetBrowserAction(*extension); |
| 168 if (!extension_action_) | 178 if (!extension_action_) |
| 169 extension_action_ = extension_action_manager->GetPageAction(*extension); | 179 extension_action_ = extension_action_manager->GetPageAction(*extension); |
| 170 | 180 |
| 171 std::string extension_name = extension->name(); | 181 std::string extension_name = extension->name(); |
| 172 // Ampersands need to be escaped to avoid being treated like | 182 // Ampersands need to be escaped to avoid being treated like |
| 173 // mnemonics in the menu. | 183 // mnemonics in the menu. |
| 174 base::ReplaceChars(extension_name, "&", "&&", &extension_name); | 184 base::ReplaceChars(extension_name, "&", "&&", &extension_name); |
| 175 AddItem(NAME, base::UTF8ToUTF16(extension_name)); | 185 AddItem(NAME, base::UTF8ToUTF16(extension_name)); |
| 176 AddSeparator(ui::NORMAL_SEPARATOR); | 186 AddSeparator(ui::NORMAL_SEPARATOR); |
| 187 |
| 188 // Add the "Always Allow" item for adding persisted permissions for script |
| 189 // injections. |
| 190 // TODO: Only add this item if the current page does not match any |
| 191 // persisted permissions. |
| 192 if (!extension_action_manager->GetBrowserAction(*extension) && |
| 193 extension->GetManifestData(extensions::manifest_keys::kContentScripts)) |
| 194 AddItemWithStringId(ALWAYS_ALLOW, IDS_EXTENSIONS_ALWAYS_ALLOW); |
| 195 |
| 177 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); | 196 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); |
| 178 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | 197 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
| 179 if (extension_action_manager->GetBrowserAction(*extension)) | 198 if (extension_action_manager->GetBrowserAction(*extension)) |
| 180 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); | 199 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); |
| 181 AddSeparator(ui::NORMAL_SEPARATOR); | 200 AddSeparator(ui::NORMAL_SEPARATOR); |
| 182 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); | 201 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); |
| 183 } | 202 } |
| 184 | 203 |
| 185 const Extension* ExtensionContextMenuModel::GetExtension() const { | 204 const Extension* ExtensionContextMenuModel::GetExtension() const { |
| 186 ExtensionService* extension_service = | 205 ExtensionService* extension_service = |
| 187 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 206 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 188 return extension_service->GetExtensionById(extension_id_, false); | 207 return extension_service->GetExtensionById(extension_id_, false); |
| 189 } | 208 } |
| OLD | NEW |