Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: chrome/browser/extensions/active_script_controller.cc

Issue 396033002: Support "always allow" for runtime script execution (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Discriminate between explicit and scriptable hosts, other minor changes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Allow current tab to run injection.
111 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.
112
113 GURL url = web_contents()->GetVisibleURL();
114 URLPattern pattern(extensions::UserScript::ValidUserScriptSchemes());
115 pattern.SetScheme(url.scheme());
116 pattern.SetHost(url.host());
117 pattern.SetPath("/*");
118
119 extensions::URLPatternSet new_explicit_hosts;
120 extensions::URLPatternSet new_scriptable_hosts;
121
122 scoped_refptr<const PermissionSet> permissions(
123 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
124 if (permissions->explicit_hosts().MatchesURL(url))
125 new_explicit_hosts.AddPattern(pattern);
126 if (permissions->scriptable_hosts().MatchesURL(url))
127 new_scriptable_hosts.AddPattern(pattern);
128
129 scoped_refptr<extensions::PermissionSet> new_permissions =
130 new extensions::PermissionSet(extensions::APIPermissionSet(),
131 extensions::ManifestPermissionSet(),
132 new_explicit_hosts,
133 new_scriptable_hosts);
134
135 // Update active permissions for the session.
136 extensions::PermissionsUpdater updater(
137 Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
138 updater.AddPermissions(extension, new_permissions.get());
139
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
140 // 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
141 extensions::ExtensionPrefs* prefs =
142 extensions::ExtensionPrefs::Get(web_contents()->GetBrowserContext());
143 prefs->ClearPersistedPermissions(extension->id());
144 prefs->AddPersistedPermission(extension->id(), new_permissions.get());
145 }
146
147 bool ActiveScriptController::HasActiveScriptAction(
148 const Extension* extension) {
149 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
150 return false; // No action for this extension.
151
152 ActiveScriptMap::iterator existing =
153 active_script_actions_.find(extension->id());
154 return existing != active_script_actions_.end();
155 }
156
103 ExtensionAction* ActiveScriptController::GetActionForExtension( 157 ExtensionAction* ActiveScriptController::GetActionForExtension(
104 const Extension* extension) { 158 const Extension* extension) {
105 if (!enabled_ || pending_requests_.count(extension->id()) == 0) 159 if (!enabled_ || pending_requests_.count(extension->id()) == 0)
106 return NULL; // No action for this extension. 160 return NULL; // No action for this extension.
107 161
108 ActiveScriptMap::iterator existing = 162 ActiveScriptMap::iterator existing =
109 active_script_actions_.find(extension->id()); 163 active_script_actions_.find(extension->id());
110 if (existing != active_script_actions_.end()) 164 if (existing != active_script_actions_.end())
111 return existing->second.get(); 165 return existing->second.get();
112 166
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 UMA_HISTOGRAM_COUNTS_100( 367 UMA_HISTOGRAM_COUNTS_100(
314 "Extensions.ActiveScriptController.PermittedExtensions", 368 "Extensions.ActiveScriptController.PermittedExtensions",
315 permitted_extensions_.size()); 369 permitted_extensions_.size());
316 UMA_HISTOGRAM_COUNTS_100( 370 UMA_HISTOGRAM_COUNTS_100(
317 "Extensions.ActiveScriptController.DeniedExtensions", 371 "Extensions.ActiveScriptController.DeniedExtensions",
318 pending_requests_.size()); 372 pending_requests_.size());
319 } 373 }
320 } 374 }
321 375
322 } // namespace extensions 376 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698