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

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

Issue 293003008: Make ActiveScriptController use Active Tab-style permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ben's Created 6 years, 7 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 | Annotate | Revision Log
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/extension_action.h" 13 #include "chrome/browser/extensions/extension_action.h"
13 #include "chrome/browser/extensions/location_bar_controller.h" 14 #include "chrome/browser/extensions/location_bar_controller.h"
14 #include "chrome/browser/extensions/tab_helper.h" 15 #include "chrome/browser/extensions/tab_helper.h"
16 #include "chrome/browser/sessions/session_id.h"
15 #include "chrome/common/extensions/api/extension_action/action_info.h" 17 #include "chrome/common/extensions/api/extension_action/action_info.h"
16 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
17 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
20 #include "extensions/browser/extension_registry.h" 22 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
22 #include "extensions/common/extension_messages.h" 24 #include "extensions/common/extension_messages.h"
23 #include "extensions/common/extension_set.h" 25 #include "extensions/common/extension_set.h"
24 #include "extensions/common/feature_switch.h" 26 #include "extensions/common/feature_switch.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 LocationBarController* location_bar_controller = 65 LocationBarController* location_bar_controller =
64 tab_helper->location_bar_controller(); 66 tab_helper->location_bar_controller();
65 // This should never be NULL. 67 // This should never be NULL.
66 DCHECK(location_bar_controller); 68 DCHECK(location_bar_controller);
67 return location_bar_controller->active_script_controller(); 69 return location_bar_controller->active_script_controller();
68 } 70 }
69 71
70 bool ActiveScriptController::RequiresUserConsentForScriptInjection( 72 bool ActiveScriptController::RequiresUserConsentForScriptInjection(
71 const Extension* extension) { 73 const Extension* extension) {
72 CHECK(extension); 74 CHECK(extension);
73 if (!PermissionsData::RequiresActionForScriptExecution(extension)) 75 if (!PermissionsData::RequiresActionForScriptExecution(
76 extension,
77 SessionID::IdForTab(web_contents()),
78 web_contents()->GetVisibleURL())) {
74 return false; 79 return false;
80 }
75 81
76 // If the feature is not enabled, we automatically allow all extensions to 82 // If the feature is not enabled, we automatically allow all extensions to
77 // run scripts. 83 // run scripts.
78 if (!enabled_) 84 if (!enabled_)
79 permitted_extensions_.insert(extension->id()); 85 permitted_extensions_.insert(extension->id());
80 86
81 return permitted_extensions_.count(extension->id()) == 0; 87 return permitted_extensions_.count(extension->id()) == 0;
82 } 88 }
83 89
84 void ActiveScriptController::RequestScriptInjection( 90 void ActiveScriptController::RequestScriptInjection(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 int page_id = visible_entry->GetPageID(); 160 int page_id = visible_entry->GetPageID();
155 161
156 // We add this to the list of permitted extensions and erase pending entries 162 // We add this to the list of permitted extensions and erase pending entries
157 // *before* running them to guard against the crazy case where running the 163 // *before* running them to guard against the crazy case where running the
158 // callbacks adds more entries. 164 // callbacks adds more entries.
159 permitted_extensions_.insert(extension->id()); 165 permitted_extensions_.insert(extension->id());
160 PendingRequestList requests; 166 PendingRequestList requests;
161 iter->second.swap(requests); 167 iter->second.swap(requests);
162 pending_requests_.erase(extension->id()); 168 pending_requests_.erase(extension->id());
163 169
170 // Clicking to run the extension counts as granting it permission to run on
171 // the given tab.
172 TabHelper::FromWebContents(web_contents())->
173 active_tab_permission_granter()->GrantIfRequested(extension);
174
164 // Run all pending injections for the given extension. 175 // Run all pending injections for the given extension.
165 for (PendingRequestList::iterator request = requests.begin(); 176 for (PendingRequestList::iterator request = requests.begin();
166 request != requests.end(); 177 request != requests.end();
167 ++request) { 178 ++request) {
168 // Only run if it's on the proper page. 179 // Only run if it's on the proper page.
169 if (request->page_id == page_id) 180 if (request->page_id == page_id)
170 request->closure.Run(); 181 request->closure.Run();
171 } 182 }
172 183
173 // Inform the location bar that the action is now gone. 184 // Inform the location bar that the action is now gone.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 UMA_HISTOGRAM_COUNTS_100( 237 UMA_HISTOGRAM_COUNTS_100(
227 "Extensions.ActiveScriptController.PermittedExtensions", 238 "Extensions.ActiveScriptController.PermittedExtensions",
228 permitted_extensions_.size()); 239 permitted_extensions_.size());
229 UMA_HISTOGRAM_COUNTS_100( 240 UMA_HISTOGRAM_COUNTS_100(
230 "Extensions.ActiveScriptController.DeniedExtensions", 241 "Extensions.ActiveScriptController.DeniedExtensions",
231 pending_requests_.size()); 242 pending_requests_.size());
232 } 243 }
233 } 244 }
234 245
235 } // namespace extensions 246 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698