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

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: Latest master for CQ 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
« no previous file with comments | « no previous file | chrome/browser/extensions/active_script_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 int page_id = visible_entry->GetPageID(); 164 int page_id = visible_entry->GetPageID();
159 165
160 // We add this to the list of permitted extensions and erase pending entries 166 // We add this to the list of permitted extensions and erase pending entries
161 // *before* running them to guard against the crazy case where running the 167 // *before* running them to guard against the crazy case where running the
162 // callbacks adds more entries. 168 // callbacks adds more entries.
163 permitted_extensions_.insert(extension->id()); 169 permitted_extensions_.insert(extension->id());
164 PendingRequestList requests; 170 PendingRequestList requests;
165 iter->second.swap(requests); 171 iter->second.swap(requests);
166 pending_requests_.erase(extension->id()); 172 pending_requests_.erase(extension->id());
167 173
174 // Clicking to run the extension counts as granting it permission to run on
175 // the given tab.
176 TabHelper::FromWebContents(web_contents())->
177 active_tab_permission_granter()->GrantIfRequested(extension);
178
168 // Run all pending injections for the given extension. 179 // Run all pending injections for the given extension.
169 for (PendingRequestList::iterator request = requests.begin(); 180 for (PendingRequestList::iterator request = requests.begin();
170 request != requests.end(); 181 request != requests.end();
171 ++request) { 182 ++request) {
172 // Only run if it's on the proper page. 183 // Only run if it's on the proper page.
173 if (request->page_id == page_id) 184 if (request->page_id == page_id)
174 request->closure.Run(); 185 request->closure.Run();
175 } 186 }
176 187
177 // Inform the location bar that the action is now gone. 188 // Inform the location bar that the action is now gone.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 UMA_HISTOGRAM_COUNTS_100( 241 UMA_HISTOGRAM_COUNTS_100(
231 "Extensions.ActiveScriptController.PermittedExtensions", 242 "Extensions.ActiveScriptController.PermittedExtensions",
232 permitted_extensions_.size()); 243 permitted_extensions_.size());
233 UMA_HISTOGRAM_COUNTS_100( 244 UMA_HISTOGRAM_COUNTS_100(
234 "Extensions.ActiveScriptController.DeniedExtensions", 245 "Extensions.ActiveScriptController.DeniedExtensions",
235 pending_requests_.size()); 246 pending_requests_.size());
236 } 247 }
237 } 248 }
238 249
239 } // namespace extensions 250 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/active_script_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698