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" |
15 #include "chrome/browser/extensions/permissions_updater.h" | |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/chrome_pages.h" | 18 #include "chrome/browser/ui/chrome_pages.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
21 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | |
19 #include "chrome/common/extensions/manifest_url_handler.h" | 22 #include "chrome/common/extensions/manifest_url_handler.h" |
20 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
23 #include "extensions/browser/extension_prefs.h" | 26 #include "extensions/browser/extension_prefs.h" |
24 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
25 #include "extensions/browser/management_policy.h" | 28 #include "extensions/browser/management_policy.h" |
26 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
30 #include "extensions/common/manifest_constants.h" | |
31 #include "extensions/common/permissions/permission_set.h" | |
27 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
28 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
30 | 35 |
31 using content::OpenURLParams; | 36 using content::OpenURLParams; |
32 using content::Referrer; | 37 using content::Referrer; |
33 using content::WebContents; | 38 using content::WebContents; |
34 using extensions::Extension; | 39 using extensions::Extension; |
35 | 40 |
36 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension, | 41 ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 return; | 109 return; |
105 | 110 |
106 switch (command_id) { | 111 switch (command_id) { |
107 case NAME: { | 112 case NAME: { |
108 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), | 113 OpenURLParams params(extensions::ManifestURL::GetHomepageURL(extension), |
109 Referrer(), NEW_FOREGROUND_TAB, | 114 Referrer(), NEW_FOREGROUND_TAB, |
110 content::PAGE_TRANSITION_LINK, false); | 115 content::PAGE_TRANSITION_LINK, false); |
111 browser_->OpenURL(params); | 116 browser_->OpenURL(params); |
112 break; | 117 break; |
113 } | 118 } |
119 case ALWAYS_ALLOW: { | |
120 content::WebContents* web_contents = | |
121 browser_->tab_strip_model()->GetActiveWebContents(); | |
122 | |
123 extensions::ActiveScriptController* script_controller = | |
124 extensions::ActiveScriptController::GetForWebContents(web_contents); | |
125 | |
126 // Allow current tab to run injection. | |
Devlin
2014/07/15 22:11:01
Let's move this logic into ActiveScriptController
| |
127 script_controller->OnActiveTabPermissionGranted(extension); | |
gpdavis
2014/07/15 21:56:38
Grant active tab permission so that the page actio
| |
128 | |
129 GURL url = web_contents->GetLastCommittedURL(); | |
130 extensions::URLPatternSet new_hosts; | |
131 URLPattern pattern(extensions::UserScript::ValidUserScriptSchemes()); | |
132 | |
133 pattern.SetScheme(url.scheme()); | |
134 pattern.SetHost(url.host()); | |
135 pattern.SetPath("/*"); | |
136 LOG(WARNING) << "Adding pattern: " << pattern.GetAsString(); | |
137 new_hosts.AddPattern(pattern); | |
138 | |
139 scoped_refptr<extensions::PermissionSet> new_permissions = | |
140 new extensions::PermissionSet(extensions::APIPermissionSet(), | |
141 extensions::ManifestPermissionSet(), | |
142 extensions::URLPatternSet(), | |
143 new_hosts); | |
144 | |
145 extensions::PermissionsUpdater updater(profile_); | |
146 updater.AddPermissions(extension, new_permissions.get()); | |
gpdavis
2014/07/15 21:56:38
Add current permissions for this session, since pe
| |
147 | |
148 extensions::ExtensionPrefs* prefs = | |
149 extensions::ExtensionPrefs::Get(web_contents->GetBrowserContext()); | |
150 prefs->ClearPersistedPermissions(extension); | |
151 prefs->AddPersistedPermission(extension, &pattern); | |
gpdavis
2014/07/15 21:56:37
Currently, I have this clearing persisted permissi
| |
152 break; | |
153 } | |
gpdavis
2014/07/15 21:56:38
I'm not sure how much of this code belongs in this
| |
114 case CONFIGURE: | 154 case CONFIGURE: |
115 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); | 155 DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty()); |
116 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); | 156 extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_); |
117 break; | 157 break; |
118 case HIDE: { | 158 case HIDE: { |
119 extensions::ExtensionActionAPI::SetBrowserActionVisibility( | 159 extensions::ExtensionActionAPI::SetBrowserActionVisibility( |
120 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); | 160 extensions::ExtensionPrefs::Get(profile_), extension->id(), false); |
121 break; | 161 break; |
122 } | 162 } |
123 case UNINSTALL: { | 163 case UNINSTALL: { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 extension_action_ = extension_action_manager->GetBrowserAction(*extension); | 207 extension_action_ = extension_action_manager->GetBrowserAction(*extension); |
168 if (!extension_action_) | 208 if (!extension_action_) |
169 extension_action_ = extension_action_manager->GetPageAction(*extension); | 209 extension_action_ = extension_action_manager->GetPageAction(*extension); |
170 | 210 |
171 std::string extension_name = extension->name(); | 211 std::string extension_name = extension->name(); |
172 // Ampersands need to be escaped to avoid being treated like | 212 // Ampersands need to be escaped to avoid being treated like |
173 // mnemonics in the menu. | 213 // mnemonics in the menu. |
174 base::ReplaceChars(extension_name, "&", "&&", &extension_name); | 214 base::ReplaceChars(extension_name, "&", "&&", &extension_name); |
175 AddItem(NAME, base::UTF8ToUTF16(extension_name)); | 215 AddItem(NAME, base::UTF8ToUTF16(extension_name)); |
176 AddSeparator(ui::NORMAL_SEPARATOR); | 216 AddSeparator(ui::NORMAL_SEPARATOR); |
217 | |
218 // Add the "Always Allow" item for adding persisted permissions for script | |
219 // injections. | |
220 // TODO: Only add this item if the current page does not match any | |
221 // persisted permissions. | |
222 if (!extension_action_manager->GetBrowserAction(*extension) && | |
223 extension->GetManifestData(extensions::manifest_keys::kContentScripts)) | |
224 AddItemWithStringId(ALWAYS_ALLOW, IDS_EXTENSIONS_ALWAYS_ALLOW); | |
gpdavis
2014/07/15 21:56:38
Any suggestions on a clean way to resolve this TOD
| |
225 | |
177 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); | 226 AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); |
178 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); | 227 AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); |
179 if (extension_action_manager->GetBrowserAction(*extension)) | 228 if (extension_action_manager->GetBrowserAction(*extension)) |
180 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); | 229 AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON); |
181 AddSeparator(ui::NORMAL_SEPARATOR); | 230 AddSeparator(ui::NORMAL_SEPARATOR); |
182 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); | 231 AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION); |
183 } | 232 } |
184 | 233 |
185 const Extension* ExtensionContextMenuModel::GetExtension() const { | 234 const Extension* ExtensionContextMenuModel::GetExtension() const { |
186 ExtensionService* extension_service = | 235 ExtensionService* extension_service = |
187 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 236 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
188 return extension_service->GetExtensionById(extension_id_, false); | 237 return extension_service->GetExtensionById(extension_id_, false); |
189 } | 238 } |
OLD | NEW |