Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/active_script_controller.h" | 5 #include "chrome/browser/extensions/active_script_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 12 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| 13 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
| 14 #include "chrome/browser/extensions/extension_util.h" | 14 #include "chrome/browser/extensions/extension_util.h" |
| 15 #include "chrome/browser/extensions/location_bar_controller.h" | 15 #include "chrome/browser/extensions/location_bar_controller.h" |
| 16 #include "chrome/browser/extensions/permissions_updater.h" | |
| 16 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 17 #include "chrome/browser/sessions/session_id.h" | 19 #include "chrome/browser/sessions/session_id.h" |
| 18 #include "chrome/common/extensions/api/extension_action/action_info.h" | 20 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 19 #include "content/public/browser/navigation_controller.h" | 21 #include "content/public/browser/navigation_controller.h" |
| 20 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 21 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "extensions/browser/extension_prefs.h" | |
| 23 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/extension_messages.h" | 28 #include "extensions/common/extension_messages.h" |
| 26 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
| 27 #include "extensions/common/feature_switch.h" | 30 #include "extensions/common/feature_switch.h" |
| 28 #include "extensions/common/manifest.h" | 31 #include "extensions/common/manifest.h" |
| 32 #include "extensions/common/manifest_handlers/permissions_parser.h" | |
| 33 #include "extensions/common/permissions/permission_set.h" | |
| 29 #include "extensions/common/permissions/permissions_data.h" | 34 #include "extensions/common/permissions/permissions_data.h" |
| 30 #include "ipc/ipc_message_macros.h" | 35 #include "ipc/ipc_message_macros.h" |
| 31 | 36 |
| 32 namespace extensions { | 37 namespace extensions { |
| 33 | 38 |
| 34 namespace { | 39 namespace { |
| 35 | 40 |
| 36 // Returns true if the extension should be regarded as a "permitted" extension | 41 // Returns true if the extension should be regarded as a "permitted" extension |
| 37 // for the case of metrics. We need this because we only actually withhold | 42 // for the case of metrics. We need this because we only actually withhold |
| 38 // permissions if the switch is enabled, but want to record metrics in all | 43 // permissions if the switch is enabled, but want to record metrics in all |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 ad_injectors, permitted_extensions_).size(); | 98 ad_injectors, permitted_extensions_).size(); |
| 94 | 99 |
| 95 UMA_HISTOGRAM_COUNTS_100( | 100 UMA_HISTOGRAM_COUNTS_100( |
| 96 "Extensions.ActiveScriptController.PreventableAdInjectors", | 101 "Extensions.ActiveScriptController.PreventableAdInjectors", |
| 97 num_preventable_ad_injectors); | 102 num_preventable_ad_injectors); |
| 98 UMA_HISTOGRAM_COUNTS_100( | 103 UMA_HISTOGRAM_COUNTS_100( |
| 99 "Extensions.ActiveScriptController.UnpreventableAdInjectors", | 104 "Extensions.ActiveScriptController.UnpreventableAdInjectors", |
| 100 ad_injectors.size() - num_preventable_ad_injectors); | 105 ad_injectors.size() - num_preventable_ad_injectors); |
| 101 } | 106 } |
| 102 | 107 |
| 108 void ActiveScriptController::AddPersistedPermission( | |
| 109 const Extension* extension) { | |
| 110 GURL url = web_contents()->GetVisibleURL(); | |
| 111 URLPattern pattern(extensions::UserScript::ValidUserScriptSchemes()); | |
| 112 pattern.SetScheme(url.scheme()); | |
| 113 pattern.SetHost(url.host()); | |
|
not at google - send to devlin
2014/08/07 22:03:45
should probably also set port here.
gpdavis
2014/08/08 00:51:43
Done.
| |
| 114 pattern.SetPath("/*"); | |
| 115 | |
| 116 extensions::URLPatternSet new_explicit_hosts; | |
| 117 extensions::URLPatternSet new_scriptable_hosts; | |
| 118 | |
| 119 scoped_refptr<const PermissionSet> withheld_permissions = | |
| 120 extension->permissions_data()->withheld_permissions(); | |
| 121 if (withheld_permissions->explicit_hosts().MatchesURL(url)) | |
| 122 new_explicit_hosts.AddPattern(pattern); | |
| 123 if (withheld_permissions->scriptable_hosts().MatchesURL(url)) | |
| 124 new_scriptable_hosts.AddPattern(pattern); | |
| 125 | |
| 126 scoped_refptr<extensions::PermissionSet> new_permissions = | |
| 127 new extensions::PermissionSet(extensions::APIPermissionSet(), | |
| 128 extensions::ManifestPermissionSet(), | |
| 129 new_explicit_hosts, | |
| 130 new_scriptable_hosts); | |
| 131 | |
| 132 // Update permissions for the session. This adds |new_permissions| to active | |
| 133 // permissions and granted permissions. | |
| 134 extensions::PermissionsUpdater updater( | |
| 135 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); | |
|
not at google - send to devlin
2014/08/07 22:03:45
you don't need to cast this to a Profile*, it take
gpdavis
2014/08/08 00:51:43
Done.
| |
| 136 updater.AddPermissions(extension, new_permissions.get()); | |
|
gpdavis
2014/08/07 20:50:39
So here we AddPermissions, which will immediately
| |
| 137 | |
| 138 UMA_HISTOGRAM_COUNTS_100( | |
|
not at google - send to devlin
2014/08/07 22:03:45
hmmmmm so I don't think this actually is right, so
gpdavis
2014/08/08 00:51:43
Which permissions are you talking about here? Wit
not at google - send to devlin
2014/08/08 14:31:28
ah. oh man, optional permissions do complicate thi
gpdavis
2014/08/08 18:07:35
So then, the size of withheld_permissions->scripta
| |
| 139 "Extensions.ActiveScriptController.PersistedPermissionCount", | |
|
not at google - send to devlin
2014/08/07 22:03:45
AlwaysRunCount would be better.
gpdavis
2014/08/08 00:51:43
Done.
| |
| 140 extension->permissions_data()->GetEffectiveHostPermissions().size()); | |
| 141 | |
| 142 // Allow current tab to run injection. | |
| 143 OnClicked(extension); | |
| 144 } | |
| 145 | |
| 146 bool ActiveScriptController::HasActiveScriptAction( | |
| 147 const Extension* extension) { | |
| 148 return enabled_ && active_script_actions_.count(extension->id()) > 0; | |
| 149 } | |
| 150 | |
| 103 ExtensionAction* ActiveScriptController::GetActionForExtension( | 151 ExtensionAction* ActiveScriptController::GetActionForExtension( |
| 104 const Extension* extension) { | 152 const Extension* extension) { |
| 105 if (!enabled_ || pending_requests_.count(extension->id()) == 0) | 153 if (!enabled_ || pending_requests_.count(extension->id()) == 0) |
| 106 return NULL; // No action for this extension. | 154 return NULL; // No action for this extension. |
| 107 | 155 |
| 108 ActiveScriptMap::iterator existing = | 156 ActiveScriptMap::iterator existing = |
| 109 active_script_actions_.find(extension->id()); | 157 active_script_actions_.find(extension->id()); |
| 110 if (existing != active_script_actions_.end()) | 158 if (existing != active_script_actions_.end()) |
| 111 return existing->second.get(); | 159 return existing->second.get(); |
| 112 | 160 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 UMA_HISTOGRAM_COUNTS_100( | 361 UMA_HISTOGRAM_COUNTS_100( |
| 314 "Extensions.ActiveScriptController.PermittedExtensions", | 362 "Extensions.ActiveScriptController.PermittedExtensions", |
| 315 permitted_extensions_.size()); | 363 permitted_extensions_.size()); |
| 316 UMA_HISTOGRAM_COUNTS_100( | 364 UMA_HISTOGRAM_COUNTS_100( |
| 317 "Extensions.ActiveScriptController.DeniedExtensions", | 365 "Extensions.ActiveScriptController.DeniedExtensions", |
| 318 pending_requests_.size()); | 366 pending_requests_.size()); |
| 319 } | 367 } |
| 320 } | 368 } |
| 321 | 369 |
| 322 } // namespace extensions | 370 } // namespace extensions |
| OLD | NEW |