[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/active_script_controller.h" |
| 6 | |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 7 | #include "base/bind.h" |
| 8 | #include "base/bind_helpers.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 10 | #include "base/metrics/histogram.h" |
| 11 | #include "base/stl_util.h" |
[email protected] | 78cd68e | 2014-05-22 20:33:52 | [diff] [blame] | 12 | #include "chrome/browser/extensions/active_tab_permission_granter.h" |
rdevlin.cronin | aeffd18 | 2014-08-26 17:04:00 | [diff] [blame] | 13 | #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_action.h" |
[email protected] | 6a24a039 | 2014-08-12 21:31:33 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_action_manager.h" |
[email protected] | b33c8c2 | 2014-05-29 19:51:08 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | e167058 | 2014-08-15 23:05:41 | [diff] [blame] | 17 | #include "chrome/browser/extensions/location_bar_controller.h" |
| 18 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | eac223a | 2014-05-13 17:39:57 | [diff] [blame] | 19 | #include "chrome/browser/extensions/tab_helper.h" |
[email protected] | 6a24a039 | 2014-08-12 21:31:33 | [diff] [blame] | 20 | #include "chrome/browser/profiles/profile.h" |
[email protected] | e3f90c60 | 2014-08-18 12:41:59 | [diff] [blame] | 21 | #include "chrome/browser/sessions/session_tab_helper.h" |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 22 | #include "chrome/common/extensions/api/extension_action/action_info.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 23 | #include "components/crx_file/id_util.h" |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 24 | #include "content/public/browser/navigation_controller.h" |
rdevlin.cronin | 5094223 | 2014-08-27 17:40:56 | [diff] [blame^] | 25 | #include "content/public/browser/navigation_details.h" |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 26 | #include "content/public/browser/navigation_entry.h" |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 27 | #include "content/public/browser/render_view_host.h" |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 28 | #include "content/public/browser/web_contents.h" |
| 29 | #include "extensions/browser/extension_registry.h" |
| 30 | #include "extensions/common/extension.h" |
| 31 | #include "extensions/common/extension_messages.h" |
| 32 | #include "extensions/common/extension_set.h" |
| 33 | #include "extensions/common/feature_switch.h" |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 34 | #include "extensions/common/manifest.h" |
[email protected] | e167058 | 2014-08-15 23:05:41 | [diff] [blame] | 35 | #include "extensions/common/permissions/permission_set.h" |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 36 | #include "extensions/common/permissions/permissions_data.h" |
| 37 | #include "ipc/ipc_message_macros.h" |
| 38 | |
| 39 | namespace extensions { |
| 40 | |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 41 | namespace { |
| 42 | |
| 43 | // Returns true if the extension should be regarded as a "permitted" extension |
| 44 | // for the case of metrics. We need this because we only actually withhold |
| 45 | // permissions if the switch is enabled, but want to record metrics in all |
| 46 | // cases. |
| 47 | // "ExtensionWouldHaveHadHostPermissionsWithheldIfSwitchWasOn()" would be |
| 48 | // more accurate, but too long. |
| 49 | bool ShouldRecordExtension(const Extension* extension) { |
| 50 | return extension->ShouldDisplayInExtensionSettings() && |
| 51 | !Manifest::IsPolicyLocation(extension->location()) && |
| 52 | !Manifest::IsComponentLocation(extension->location()) && |
| 53 | !PermissionsData::CanExecuteScriptEverywhere(extension) && |
| 54 | extension->permissions_data() |
| 55 | ->active_permissions() |
| 56 | ->ShouldWarnAllHosts(); |
| 57 | } |
| 58 | |
| 59 | } // namespace |
| 60 | |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 61 | ActiveScriptController::ActiveScriptController( |
| 62 | content::WebContents* web_contents) |
| 63 | : content::WebContentsObserver(web_contents), |
| 64 | enabled_(FeatureSwitch::scripts_require_action()->IsEnabled()) { |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 65 | CHECK(web_contents); |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | ActiveScriptController::~ActiveScriptController() { |
| 69 | LogUMA(); |
| 70 | } |
| 71 | |
[email protected] | eac223a | 2014-05-13 17:39:57 | [diff] [blame] | 72 | // static |
| 73 | ActiveScriptController* ActiveScriptController::GetForWebContents( |
| 74 | content::WebContents* web_contents) { |
| 75 | if (!web_contents) |
| 76 | return NULL; |
| 77 | TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); |
| 78 | if (!tab_helper) |
| 79 | return NULL; |
| 80 | LocationBarController* location_bar_controller = |
| 81 | tab_helper->location_bar_controller(); |
| 82 | // This should never be NULL. |
| 83 | DCHECK(location_bar_controller); |
| 84 | return location_bar_controller->active_script_controller(); |
| 85 | } |
| 86 | |
[email protected] | 11814f5 | 2014-05-23 06:50:35 | [diff] [blame] | 87 | void ActiveScriptController::OnActiveTabPermissionGranted( |
| 88 | const Extension* extension) { |
| 89 | RunPendingForExtension(extension); |
| 90 | } |
| 91 | |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 92 | void ActiveScriptController::OnAdInjectionDetected( |
[email protected] | 0d8d697 | 2014-06-03 22:41:02 | [diff] [blame] | 93 | const std::set<std::string>& ad_injectors) { |
[email protected] | c0a3cd9 | 2014-05-22 12:23:42 | [diff] [blame] | 94 | // We're only interested in data if there are ad injectors detected. |
| 95 | if (ad_injectors.empty()) |
| 96 | return; |
| 97 | |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 98 | size_t num_preventable_ad_injectors = |
| 99 | base::STLSetIntersection<std::set<std::string> >( |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 100 | ad_injectors, permitted_extensions_).size(); |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 101 | |
| 102 | UMA_HISTOGRAM_COUNTS_100( |
| 103 | "Extensions.ActiveScriptController.PreventableAdInjectors", |
| 104 | num_preventable_ad_injectors); |
| 105 | UMA_HISTOGRAM_COUNTS_100( |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 106 | "Extensions.ActiveScriptController.UnpreventableAdInjectors", |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 107 | ad_injectors.size() - num_preventable_ad_injectors); |
| 108 | } |
| 109 | |
[email protected] | e167058 | 2014-08-15 23:05:41 | [diff] [blame] | 110 | void ActiveScriptController::AlwaysRunOnVisibleOrigin( |
| 111 | const Extension* extension) { |
| 112 | const GURL& url = web_contents()->GetVisibleURL(); |
| 113 | URLPatternSet new_explicit_hosts; |
| 114 | URLPatternSet new_scriptable_hosts; |
| 115 | |
| 116 | scoped_refptr<const PermissionSet> withheld_permissions = |
| 117 | extension->permissions_data()->withheld_permissions(); |
| 118 | if (withheld_permissions->explicit_hosts().MatchesURL(url)) { |
| 119 | new_explicit_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), |
| 120 | url.GetOrigin()); |
| 121 | } |
| 122 | if (withheld_permissions->scriptable_hosts().MatchesURL(url)) { |
| 123 | new_scriptable_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), |
| 124 | url.GetOrigin()); |
| 125 | } |
| 126 | |
| 127 | scoped_refptr<PermissionSet> new_permissions = |
| 128 | new PermissionSet(APIPermissionSet(), |
| 129 | ManifestPermissionSet(), |
| 130 | new_explicit_hosts, |
| 131 | new_scriptable_hosts); |
| 132 | |
| 133 | // Update permissions for the session. This adds |new_permissions| to active |
| 134 | // permissions and granted permissions. |
| 135 | // TODO(devlin): Make sure that the permission is removed from |
| 136 | // withheld_permissions if appropriate. |
| 137 | PermissionsUpdater(web_contents()->GetBrowserContext()) |
| 138 | .AddPermissions(extension, new_permissions.get()); |
| 139 | |
| 140 | // Allow current tab to run injection. |
| 141 | OnClicked(extension); |
| 142 | } |
| 143 | |
rdevlin.cronin | e9c7112 | 2014-08-25 23:47:21 | [diff] [blame] | 144 | void ActiveScriptController::OnClicked(const Extension* extension) { |
| 145 | DCHECK(ContainsKey(pending_requests_, extension->id())); |
| 146 | RunPendingForExtension(extension); |
| 147 | } |
| 148 | |
[email protected] | e167058 | 2014-08-15 23:05:41 | [diff] [blame] | 149 | bool ActiveScriptController::HasActiveScriptAction(const Extension* extension) { |
[email protected] | 903cf84 | 2014-08-22 01:15:28 | [diff] [blame] | 150 | return enabled_ && pending_requests_.count(extension->id()) > 0; |
[email protected] | e167058 | 2014-08-15 23:05:41 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 153 | ExtensionAction* ActiveScriptController::GetActionForExtension( |
| 154 | const Extension* extension) { |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 155 | if (!enabled_ || pending_requests_.count(extension->id()) == 0) |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 156 | return NULL; // No action for this extension. |
| 157 | |
| 158 | ActiveScriptMap::iterator existing = |
| 159 | active_script_actions_.find(extension->id()); |
| 160 | if (existing != active_script_actions_.end()) |
| 161 | return existing->second.get(); |
| 162 | |
[email protected] | 6a24a039 | 2014-08-12 21:31:33 | [diff] [blame] | 163 | linked_ptr<ExtensionAction> action(ExtensionActionManager::Get( |
| 164 | Profile::FromBrowserContext(web_contents()->GetBrowserContext())) |
| 165 | ->GetBestFitAction(*extension, ActionInfo::TYPE_PAGE).release()); |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 166 | action->SetIsVisible(ExtensionAction::kDefaultTabId, true); |
| 167 | |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 168 | active_script_actions_[extension->id()] = action; |
| 169 | return action.get(); |
| 170 | } |
| 171 | |
[email protected] | 0d8d697 | 2014-06-03 22:41:02 | [diff] [blame] | 172 | void ActiveScriptController::OnExtensionUnloaded(const Extension* extension) { |
| 173 | PendingRequestMap::iterator iter = pending_requests_.find(extension->id()); |
| 174 | if (iter != pending_requests_.end()) |
| 175 | pending_requests_.erase(iter); |
| 176 | } |
| 177 | |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 178 | PermissionsData::AccessType |
| 179 | ActiveScriptController::RequiresUserConsentForScriptInjection( |
| 180 | const Extension* extension, |
| 181 | UserScript::InjectionType type) { |
| 182 | CHECK(extension); |
| 183 | |
| 184 | // If the feature is not enabled, we automatically allow all extensions to |
| 185 | // run scripts. |
| 186 | if (!enabled_) |
| 187 | permitted_extensions_.insert(extension->id()); |
| 188 | |
| 189 | // Allow the extension if it's been explicitly granted permission. |
| 190 | if (permitted_extensions_.count(extension->id()) > 0) |
| 191 | return PermissionsData::ACCESS_ALLOWED; |
| 192 | |
| 193 | GURL url = web_contents()->GetVisibleURL(); |
[email protected] | e3f90c60 | 2014-08-18 12:41:59 | [diff] [blame] | 194 | int tab_id = SessionTabHelper::IdForTab(web_contents()); |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 195 | switch (type) { |
| 196 | case UserScript::CONTENT_SCRIPT: |
| 197 | return extension->permissions_data()->GetContentScriptAccess( |
| 198 | extension, url, url, tab_id, -1, NULL); |
| 199 | case UserScript::PROGRAMMATIC_SCRIPT: |
| 200 | return extension->permissions_data()->GetPageAccess( |
| 201 | extension, url, url, tab_id, -1, NULL); |
| 202 | } |
| 203 | |
| 204 | NOTREACHED(); |
| 205 | return PermissionsData::ACCESS_DENIED; |
| 206 | } |
| 207 | |
| 208 | void ActiveScriptController::RequestScriptInjection( |
| 209 | const Extension* extension, |
| 210 | const base::Closure& callback) { |
| 211 | CHECK(extension); |
| 212 | PendingRequestList& list = pending_requests_[extension->id()]; |
| 213 | list.push_back(callback); |
| 214 | |
| 215 | // If this was the first entry, notify the location bar that there's a new |
| 216 | // icon. |
rdevlin.cronin | aeffd18 | 2014-08-26 17:04:00 | [diff] [blame] | 217 | if (list.size() == 1u) { |
| 218 | ExtensionActionAPI::Get(web_contents()->GetBrowserContext())-> |
| 219 | NotifyPageActionsChanged(web_contents()); |
| 220 | } |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | 11814f5 | 2014-05-23 06:50:35 | [diff] [blame] | 223 | void ActiveScriptController::RunPendingForExtension( |
| 224 | const Extension* extension) { |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 225 | DCHECK(extension); |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 226 | |
| 227 | content::NavigationEntry* visible_entry = |
| 228 | web_contents()->GetController().GetVisibleEntry(); |
| 229 | // Refuse to run if there's no visible entry, because we have no idea of |
| 230 | // determining if it's the proper page. This should rarely, if ever, happen. |
| 231 | if (!visible_entry) |
[email protected] | 11814f5 | 2014-05-23 06:50:35 | [diff] [blame] | 232 | return; |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 233 | |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 234 | // We add this to the list of permitted extensions and erase pending entries |
| 235 | // *before* running them to guard against the crazy case where running the |
| 236 | // callbacks adds more entries. |
| 237 | permitted_extensions_.insert(extension->id()); |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 238 | |
| 239 | PendingRequestMap::iterator iter = pending_requests_.find(extension->id()); |
| 240 | if (iter == pending_requests_.end()) |
| 241 | return; |
| 242 | |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 243 | PendingRequestList requests; |
| 244 | iter->second.swap(requests); |
| 245 | pending_requests_.erase(extension->id()); |
| 246 | |
[email protected] | 78cd68e | 2014-05-22 20:33:52 | [diff] [blame] | 247 | // Clicking to run the extension counts as granting it permission to run on |
| 248 | // the given tab. |
[email protected] | 11814f5 | 2014-05-23 06:50:35 | [diff] [blame] | 249 | // The extension may already have active tab at this point, but granting |
| 250 | // it twice is essentially a no-op. |
[email protected] | 78cd68e | 2014-05-22 20:33:52 | [diff] [blame] | 251 | TabHelper::FromWebContents(web_contents())-> |
| 252 | active_tab_permission_granter()->GrantIfRequested(extension); |
| 253 | |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 254 | // Run all pending injections for the given extension. |
| 255 | for (PendingRequestList::iterator request = requests.begin(); |
| 256 | request != requests.end(); |
| 257 | ++request) { |
[email protected] | d205600 | 2014-07-03 06:18:06 | [diff] [blame] | 258 | request->Run(); |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // Inform the location bar that the action is now gone. |
rdevlin.cronin | aeffd18 | 2014-08-26 17:04:00 | [diff] [blame] | 262 | ExtensionActionAPI::Get(web_contents()->GetBrowserContext())-> |
| 263 | NotifyPageActionsChanged(web_contents()); |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 264 | } |
| 265 | |
[email protected] | ac2f8937 | 2014-06-23 21:44:25 | [diff] [blame] | 266 | void ActiveScriptController::OnRequestScriptInjectionPermission( |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 267 | const std::string& extension_id, |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 268 | UserScript::InjectionType script_type, |
[email protected] | d205600 | 2014-07-03 06:18:06 | [diff] [blame] | 269 | int64 request_id) { |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 270 | if (!crx_file::id_util::IdIsValid(extension_id)) { |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 271 | NOTREACHED() << "'" << extension_id << "' is not a valid id."; |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | const Extension* extension = |
| 276 | ExtensionRegistry::Get(web_contents()->GetBrowserContext()) |
| 277 | ->enabled_extensions().GetByID(extension_id); |
| 278 | // We shouldn't allow extensions which are no longer enabled to run any |
| 279 | // scripts. Ignore the request. |
| 280 | if (!extension) |
| 281 | return; |
| 282 | |
[email protected] | 0d8d697 | 2014-06-03 22:41:02 | [diff] [blame] | 283 | // If the request id is -1, that signals that the content script has already |
| 284 | // ran (because this feature is not enabled). Add the extension to the list of |
| 285 | // permitted extensions (for metrics), and return immediately. |
| 286 | if (request_id == -1) { |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 287 | if (ShouldRecordExtension(extension)) { |
| 288 | DCHECK(!enabled_); |
| 289 | permitted_extensions_.insert(extension->id()); |
| 290 | } |
[email protected] | 0d8d697 | 2014-06-03 22:41:02 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 294 | switch (RequiresUserConsentForScriptInjection(extension, script_type)) { |
| 295 | case PermissionsData::ACCESS_ALLOWED: |
| 296 | PermitScriptInjection(request_id); |
| 297 | break; |
| 298 | case PermissionsData::ACCESS_WITHHELD: |
| 299 | // This base::Unretained() is safe, because the callback is only invoked |
| 300 | // by this object. |
| 301 | RequestScriptInjection( |
| 302 | extension, |
| 303 | base::Bind(&ActiveScriptController::PermitScriptInjection, |
| 304 | base::Unretained(this), |
| 305 | request_id)); |
| 306 | break; |
| 307 | case PermissionsData::ACCESS_DENIED: |
| 308 | // We should usually only get a "deny access" if the page changed (as the |
| 309 | // renderer wouldn't have requested permission if the answer was always |
| 310 | // "no"). Just let the request fizzle and die. |
| 311 | break; |
[email protected] | 0d8d697 | 2014-06-03 22:41:02 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
[email protected] | d205600 | 2014-07-03 06:18:06 | [diff] [blame] | 315 | void ActiveScriptController::PermitScriptInjection(int64 request_id) { |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 316 | // This only sends the response to the renderer - the process of adding the |
| 317 | // extension to the list of |permitted_extensions_| is done elsewhere. |
[email protected] | 0d8d697 | 2014-06-03 22:41:02 | [diff] [blame] | 318 | content::RenderViewHost* render_view_host = |
| 319 | web_contents()->GetRenderViewHost(); |
| 320 | if (render_view_host) { |
[email protected] | ac2f8937 | 2014-06-23 21:44:25 | [diff] [blame] | 321 | render_view_host->Send(new ExtensionMsg_PermitScriptInjection( |
| 322 | render_view_host->GetRoutingID(), request_id)); |
[email protected] | 0d8d697 | 2014-06-03 22:41:02 | [diff] [blame] | 323 | } |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | bool ActiveScriptController::OnMessageReceived(const IPC::Message& message) { |
| 327 | bool handled = true; |
| 328 | IPC_BEGIN_MESSAGE_MAP(ActiveScriptController, message) |
[email protected] | ac2f8937 | 2014-06-23 21:44:25 | [diff] [blame] | 329 | IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestScriptInjectionPermission, |
| 330 | OnRequestScriptInjectionPermission) |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 331 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 332 | IPC_END_MESSAGE_MAP() |
| 333 | return handled; |
| 334 | } |
| 335 | |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 336 | void ActiveScriptController::LogUMA() const { |
| 337 | UMA_HISTOGRAM_COUNTS_100( |
| 338 | "Extensions.ActiveScriptController.ShownActiveScriptsOnPage", |
[email protected] | ac02ac5 | 2014-05-20 01:11:26 | [diff] [blame] | 339 | pending_requests_.size()); |
| 340 | |
| 341 | // We only log the permitted extensions metric if the feature is enabled, |
| 342 | // because otherwise the data will be boring (100% allowed). |
| 343 | if (enabled_) { |
| 344 | UMA_HISTOGRAM_COUNTS_100( |
| 345 | "Extensions.ActiveScriptController.PermittedExtensions", |
| 346 | permitted_extensions_.size()); |
| 347 | UMA_HISTOGRAM_COUNTS_100( |
| 348 | "Extensions.ActiveScriptController.DeniedExtensions", |
| 349 | pending_requests_.size()); |
| 350 | } |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 351 | } |
| 352 | |
rdevlin.cronin | 5094223 | 2014-08-27 17:40:56 | [diff] [blame^] | 353 | void ActiveScriptController::DidNavigateMainFrame( |
| 354 | const content::LoadCommittedDetails& details, |
| 355 | const content::FrameNavigateParams& params) { |
| 356 | if (details.is_in_page) |
| 357 | return; |
| 358 | |
| 359 | LogUMA(); |
| 360 | permitted_extensions_.clear(); |
| 361 | pending_requests_.clear(); |
| 362 | } |
| 363 | |
[email protected] | 39ef0a7c5 | 2014-05-11 01:40:00 | [diff] [blame] | 364 | } // namespace extensions |