Chromium Code Reviews| Index: chrome/browser/extensions/active_script_controller.cc |
| diff --git a/chrome/browser/extensions/active_script_controller.cc b/chrome/browser/extensions/active_script_controller.cc |
| index 1b35b2872c9415706f9bd7585315856576cdc57b..e79e1a551779d72a52936c3dfc0843e9052306ad 100644 |
| --- a/chrome/browser/extensions/active_script_controller.cc |
| +++ b/chrome/browser/extensions/active_script_controller.cc |
| @@ -13,19 +13,24 @@ |
| #include "chrome/browser/extensions/extension_action.h" |
| #include "chrome/browser/extensions/extension_util.h" |
| #include "chrome/browser/extensions/location_bar_controller.h" |
| +#include "chrome/browser/extensions/permissions_updater.h" |
| #include "chrome/browser/extensions/tab_helper.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sessions/session_id.h" |
| #include "chrome/common/extensions/api/extension_action/action_info.h" |
| #include "content/public/browser/navigation_controller.h" |
| #include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "extensions/browser/extension_prefs.h" |
| #include "extensions/browser/extension_registry.h" |
| #include "extensions/common/extension.h" |
| #include "extensions/common/extension_messages.h" |
| #include "extensions/common/extension_set.h" |
| #include "extensions/common/feature_switch.h" |
| #include "extensions/common/manifest.h" |
| +#include "extensions/common/manifest_handlers/permissions_parser.h" |
| +#include "extensions/common/permissions/permission_set.h" |
| #include "extensions/common/permissions/permissions_data.h" |
| #include "ipc/ipc_message_macros.h" |
| @@ -100,6 +105,55 @@ void ActiveScriptController::OnAdInjectionDetected( |
| ad_injectors.size() - num_preventable_ad_injectors); |
| } |
| +void ActiveScriptController::AddPersistedPermission( |
| + const Extension* extension) { |
| + // Allow current tab to run injection. |
| + OnClicked(extension); |
|
not at google - send to devlin
2014/08/01 18:15:12
it might be safer to do this at the end in case so
gpdavis
2014/08/01 20:06:06
Sure thing.
|
| + |
| + GURL url = web_contents()->GetVisibleURL(); |
| + URLPattern pattern(extensions::UserScript::ValidUserScriptSchemes()); |
| + pattern.SetScheme(url.scheme()); |
| + pattern.SetHost(url.host()); |
| + pattern.SetPath("/*"); |
| + |
| + extensions::URLPatternSet new_explicit_hosts; |
| + extensions::URLPatternSet new_scriptable_hosts; |
| + |
| + scoped_refptr<const PermissionSet> permissions( |
| + PermissionsParser::GetRequiredPermissions(extension)); |
|
not at google - send to devlin
2014/08/01 18:15:11
shouldn't this be querying the withheld permission
gpdavis
2014/08/01 20:06:06
That seems reasonable. I chose RequiredPermission
|
| + if (permissions->explicit_hosts().MatchesURL(url)) |
| + new_explicit_hosts.AddPattern(pattern); |
| + if (permissions->scriptable_hosts().MatchesURL(url)) |
| + new_scriptable_hosts.AddPattern(pattern); |
| + |
| + scoped_refptr<extensions::PermissionSet> new_permissions = |
| + new extensions::PermissionSet(extensions::APIPermissionSet(), |
| + extensions::ManifestPermissionSet(), |
| + new_explicit_hosts, |
| + new_scriptable_hosts); |
| + |
| + // Update active permissions for the session. |
| + extensions::PermissionsUpdater updater( |
| + Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
| + updater.AddPermissions(extension, new_permissions.get()); |
| + |
|
not at google - send to devlin
2014/08/01 18:15:11
we should add UMA for this. I think a useful metri
gpdavis
2014/08/01 20:06:06
Okay, sure. Should I add both you and devlin as o
not at google - send to devlin
2014/08/04 23:53:13
no, histograms.xml has its own owners. git-cl uplo
gpdavis
2014/08/07 20:50:39
Oh, no, I meant for the <owner></owner> tags in th
not at google - send to devlin
2014/08/08 14:31:28
I thought I replied to this question. yes, <owner>
gpdavis
2014/08/08 18:07:34
I added this comment right before I added the one
|
| + // Update persisted permissions for extension. |
|
not at google - send to devlin
2014/08/01 18:15:12
PermissionsUpdater should already do this?
gpdavis
2014/08/01 20:06:06
Update Persisted Permissions?
The updater adds to
not at google - send to devlin
2014/08/04 23:53:13
I mean PermissionsUpdater::AddPermissions:
https:
gpdavis
2014/08/07 20:50:39
Ahh, I see what you're saying. AddPermissions alr
not at google - send to devlin
2014/08/07 22:03:45
It looks like GetBoundedActivePermissions reads in
gpdavis
2014/08/07 23:23:36
I believe this is the line that's causing problems
not at google - send to devlin
2014/08/08 00:24:29
ah I see. so that condition needs to take into acc
gpdavis
2014/08/08 00:51:43
You mean as a part of the bound, meaning that acti
not at google - send to devlin
2014/08/08 14:31:28
ah I see the confusion here, on both our parts. in
gpdavis
2014/08/08 18:07:34
Ah! That does make a lot of sense. I wonder why
|
| + extensions::ExtensionPrefs* prefs = |
| + extensions::ExtensionPrefs::Get(web_contents()->GetBrowserContext()); |
| + prefs->ClearPersistedPermissions(extension->id()); |
| + prefs->AddPersistedPermission(extension->id(), new_permissions.get()); |
| +} |
| + |
| +bool ActiveScriptController::HasActiveScriptAction( |
| + const Extension* extension) { |
| + if (!enabled_ || pending_requests_.count(extension->id()) == 0) |
|
not at google - send to devlin
2014/08/01 18:15:12
why this second check? again while it seems like c
gpdavis
2014/08/01 20:06:06
Ah, I see. That makes sense. I guess I was going
|
| + return false; // No action for this extension. |
| + |
| + ActiveScriptMap::iterator existing = |
| + active_script_actions_.find(extension->id()); |
| + return existing != active_script_actions_.end(); |
| +} |
| + |
| ExtensionAction* ActiveScriptController::GetActionForExtension( |
| const Extension* extension) { |
| if (!enabled_ || pending_requests_.count(extension->id()) == 0) |