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

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

Issue 1349613003: [Extensions] Un-refcount PermissionSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 "Extensions.ActiveScriptController.UnpreventableAdInjectors", 82 "Extensions.ActiveScriptController.UnpreventableAdInjectors",
83 ad_injectors.size() - num_preventable_ad_injectors); 83 ad_injectors.size() - num_preventable_ad_injectors);
84 } 84 }
85 85
86 void ActiveScriptController::AlwaysRunOnVisibleOrigin( 86 void ActiveScriptController::AlwaysRunOnVisibleOrigin(
87 const Extension* extension) { 87 const Extension* extension) {
88 const GURL& url = web_contents()->GetVisibleURL(); 88 const GURL& url = web_contents()->GetVisibleURL();
89 URLPatternSet new_explicit_hosts; 89 URLPatternSet new_explicit_hosts;
90 URLPatternSet new_scriptable_hosts; 90 URLPatternSet new_scriptable_hosts;
91 91
92 scoped_refptr<const PermissionSet> withheld_permissions = 92 const PermissionSet* withheld_permissions =
93 extension->permissions_data()->withheld_permissions(); 93 extension->permissions_data()->withheld_permissions();
94 if (withheld_permissions->explicit_hosts().MatchesURL(url)) { 94 if (withheld_permissions->explicit_hosts().MatchesURL(url)) {
95 new_explicit_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), 95 new_explicit_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(),
96 url.GetOrigin()); 96 url.GetOrigin());
97 } 97 }
98 if (withheld_permissions->scriptable_hosts().MatchesURL(url)) { 98 if (withheld_permissions->scriptable_hosts().MatchesURL(url)) {
99 new_scriptable_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(), 99 new_scriptable_hosts.AddOrigin(UserScript::ValidUserScriptSchemes(),
100 url.GetOrigin()); 100 url.GetOrigin());
101 } 101 }
102 102
103 scoped_refptr<PermissionSet> new_permissions = 103 PermissionSet new_permissions(APIPermissionSet(), ManifestPermissionSet(),
104 new PermissionSet(APIPermissionSet(), 104 new_explicit_hosts, new_scriptable_hosts);
105 ManifestPermissionSet(),
106 new_explicit_hosts,
107 new_scriptable_hosts);
108 105
109 // Update permissions for the session. This adds |new_permissions| to active 106 // Update permissions for the session. This adds |new_permissions| to active
110 // permissions and granted permissions. 107 // permissions and granted permissions.
111 // TODO(devlin): Make sure that the permission is removed from 108 // TODO(devlin): Make sure that the permission is removed from
112 // withheld_permissions if appropriate. 109 // withheld_permissions if appropriate.
113 PermissionsUpdater(browser_context_).AddPermissions(extension, 110 PermissionsUpdater(browser_context_)
114 new_permissions.get()); 111 .AddPermissions(extension, &new_permissions);
115 112
116 // Allow current tab to run injection. 113 // Allow current tab to run injection.
117 OnClicked(extension); 114 OnClicked(extension);
118 } 115 }
119 116
120 void ActiveScriptController::OnClicked(const Extension* extension) { 117 void ActiveScriptController::OnClicked(const Extension* extension) {
121 DCHECK(ContainsKey(pending_requests_, extension->id())); 118 DCHECK(ContainsKey(pending_requests_, extension->id()));
122 RunPendingForExtension(extension); 119 RunPendingForExtension(extension);
123 } 120 }
124 121
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // We shouldn't allow extensions which are no longer enabled to run any 221 // We shouldn't allow extensions which are no longer enabled to run any
225 // scripts. Ignore the request. 222 // scripts. Ignore the request.
226 if (!extension) 223 if (!extension)
227 return; 224 return;
228 225
229 // If the request id is -1, that signals that the content script has already 226 // If the request id is -1, that signals that the content script has already
230 // ran (because this feature is not enabled). Add the extension to the list of 227 // ran (because this feature is not enabled). Add the extension to the list of
231 // permitted extensions (for metrics), and return immediately. 228 // permitted extensions (for metrics), and return immediately.
232 if (request_id == -1) { 229 if (request_id == -1) {
233 if (PermissionsData::ScriptsMayRequireActionForExtension( 230 if (PermissionsData::ScriptsMayRequireActionForExtension(
234 extension, 231 extension, extension->permissions_data()->active_permissions())) {
235 extension->permissions_data()->active_permissions().get())) {
236 permitted_extensions_.insert(extension->id()); 232 permitted_extensions_.insert(extension->id());
237 } 233 }
238 return; 234 return;
239 } 235 }
240 236
241 ++num_page_requests_; 237 ++num_page_requests_;
242 238
243 switch (RequiresUserConsentForScriptInjection(extension, script_type)) { 239 switch (RequiresUserConsentForScriptInjection(extension, script_type)) {
244 case PermissionsData::ACCESS_ALLOWED: 240 case PermissionsData::ACCESS_ALLOWED:
245 PermitScriptInjection(request_id); 241 PermitScriptInjection(request_id);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 UnloadedExtensionInfo::Reason reason) { 328 UnloadedExtensionInfo::Reason reason) {
333 PendingRequestMap::iterator iter = pending_requests_.find(extension->id()); 329 PendingRequestMap::iterator iter = pending_requests_.find(extension->id());
334 if (iter != pending_requests_.end()) { 330 if (iter != pending_requests_.end()) {
335 pending_requests_.erase(iter); 331 pending_requests_.erase(iter);
336 ExtensionActionAPI::Get(browser_context_)-> 332 ExtensionActionAPI::Get(browser_context_)->
337 NotifyPageActionsChanged(web_contents()); 333 NotifyPageActionsChanged(web_contents());
338 } 334 }
339 } 335 }
340 336
341 } // namespace extensions 337 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698