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_action_manager.h" | 14 #include "chrome/browser/extensions/extension_action_manager.h" |
| 15 #include "chrome/browser/extensions/extension_util.h" | 15 #include "chrome/browser/extensions/extension_util.h" |
| 16 #include "chrome/browser/extensions/location_bar_controller.h" | 16 #include "chrome/browser/extensions/location_bar_controller.h" |
| 17 #include "chrome/browser/extensions/permissions_updater.h" | |
| 17 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/sessions/session_id.h" | 20 #include "chrome/browser/sessions/session_id.h" |
| 20 #include "chrome/common/extensions/api/extension_action/action_info.h" | 21 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 21 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 22 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
| 23 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 25 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
| 26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/extension_messages.h" | 28 #include "extensions/common/extension_messages.h" |
| 28 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
| 29 #include "extensions/common/feature_switch.h" | 30 #include "extensions/common/feature_switch.h" |
| 30 #include "extensions/common/manifest.h" | 31 #include "extensions/common/manifest.h" |
| 32 #include "extensions/common/manifest_handlers/permissions_parser.h" | |
|
Devlin
2014/08/14 01:20:18
Why?
gpdavis
2014/08/14 20:05:43
Oops; leftover from patchset 13. Done.
| |
| 33 #include "extensions/common/permissions/permission_set.h" | |
| 31 #include "extensions/common/permissions/permissions_data.h" | 34 #include "extensions/common/permissions/permissions_data.h" |
| 32 #include "ipc/ipc_message_macros.h" | 35 #include "ipc/ipc_message_macros.h" |
| 33 | 36 |
| 34 namespace extensions { | 37 namespace extensions { |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| 37 | 40 |
| 38 // 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 |
| 39 // 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 |
| 40 // 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... | |
| 95 ad_injectors, permitted_extensions_).size(); | 98 ad_injectors, permitted_extensions_).size(); |
| 96 | 99 |
| 97 UMA_HISTOGRAM_COUNTS_100( | 100 UMA_HISTOGRAM_COUNTS_100( |
| 98 "Extensions.ActiveScriptController.PreventableAdInjectors", | 101 "Extensions.ActiveScriptController.PreventableAdInjectors", |
| 99 num_preventable_ad_injectors); | 102 num_preventable_ad_injectors); |
| 100 UMA_HISTOGRAM_COUNTS_100( | 103 UMA_HISTOGRAM_COUNTS_100( |
| 101 "Extensions.ActiveScriptController.UnpreventableAdInjectors", | 104 "Extensions.ActiveScriptController.UnpreventableAdInjectors", |
| 102 ad_injectors.size() - num_preventable_ad_injectors); | 105 ad_injectors.size() - num_preventable_ad_injectors); |
| 103 } | 106 } |
| 104 | 107 |
| 108 void ActiveScriptController::AlwaysRunOnVisibleHost( | |
| 109 const Extension* extension) { | |
| 110 GURL url = web_contents()->GetVisibleURL(); | |
|
Devlin
2014/08/14 01:20:18
const &
gpdavis
2014/08/14 20:05:42
Done.
| |
| 111 URLPatternSet new_explicit_hosts; | |
| 112 URLPatternSet new_scriptable_hosts; | |
| 113 | |
| 114 scoped_refptr<const PermissionSet> withheld_permissions = | |
| 115 extension->permissions_data()->withheld_permissions(); | |
| 116 if (withheld_permissions->explicit_hosts().MatchesURL(url)) { | |
| 117 new_explicit_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), | |
| 118 url.GetOrigin()); | |
| 119 } | |
| 120 if (withheld_permissions->scriptable_hosts().MatchesURL(url)) { | |
| 121 new_scriptable_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), | |
| 122 url.GetOrigin()); | |
| 123 } | |
| 124 | |
| 125 scoped_refptr<extensions::PermissionSet> new_permissions = | |
| 126 new PermissionSet(extensions::APIPermissionSet(), | |
|
Devlin
2014/08/14 01:20:18
no extensions::
gpdavis
2014/08/14 20:05:42
Done.
| |
| 127 extensions::ManifestPermissionSet(), | |
|
Devlin
2014/08/14 01:20:18
no extensions::
gpdavis
2014/08/14 20:05:42
Done.
| |
| 128 new_explicit_hosts, | |
| 129 new_scriptable_hosts); | |
| 130 | |
| 131 // Update permissions for the session. This adds |new_permissions| to active | |
| 132 // permissions and granted permissions. | |
| 133 PermissionsUpdater(web_contents()->GetBrowserContext()) | |
| 134 .AddPermissions(extension, new_permissions.get()); | |
| 135 | |
| 136 // Allow current tab to run injection. | |
| 137 OnClicked(extension); | |
| 138 } | |
| 139 | |
| 140 bool ActiveScriptController::HasActiveScriptAction(const Extension* extension) { | |
| 141 return enabled_ && active_script_actions_.count(extension->id()) > 0; | |
| 142 } | |
| 143 | |
| 105 ExtensionAction* ActiveScriptController::GetActionForExtension( | 144 ExtensionAction* ActiveScriptController::GetActionForExtension( |
| 106 const Extension* extension) { | 145 const Extension* extension) { |
| 107 if (!enabled_ || pending_requests_.count(extension->id()) == 0) | 146 if (!enabled_ || pending_requests_.count(extension->id()) == 0) |
| 108 return NULL; // No action for this extension. | 147 return NULL; // No action for this extension. |
| 109 | 148 |
| 110 ActiveScriptMap::iterator existing = | 149 ActiveScriptMap::iterator existing = |
| 111 active_script_actions_.find(extension->id()); | 150 active_script_actions_.find(extension->id()); |
| 112 if (existing != active_script_actions_.end()) | 151 if (existing != active_script_actions_.end()) |
| 113 return existing->second.get(); | 152 return existing->second.get(); |
| 114 | 153 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 UMA_HISTOGRAM_COUNTS_100( | 345 UMA_HISTOGRAM_COUNTS_100( |
| 307 "Extensions.ActiveScriptController.PermittedExtensions", | 346 "Extensions.ActiveScriptController.PermittedExtensions", |
| 308 permitted_extensions_.size()); | 347 permitted_extensions_.size()); |
| 309 UMA_HISTOGRAM_COUNTS_100( | 348 UMA_HISTOGRAM_COUNTS_100( |
| 310 "Extensions.ActiveScriptController.DeniedExtensions", | 349 "Extensions.ActiveScriptController.DeniedExtensions", |
| 311 pending_requests_.size()); | 350 pending_requests_.size()); |
| 312 } | 351 } |
| 313 } | 352 } |
| 314 | 353 |
| 315 } // namespace extensions | 354 } // namespace extensions |
| OLD | NEW |