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

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

Issue 939803002: [Extensions] Update renderers when all-urls is granted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test Created 5 years, 10 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 21 matching lines...) Expand all
32 #include "extensions/common/manifest.h" 32 #include "extensions/common/manifest.h"
33 #include "extensions/common/permissions/permission_set.h" 33 #include "extensions/common/permissions/permission_set.h"
34 #include "extensions/common/permissions/permissions_data.h" 34 #include "extensions/common/permissions/permissions_data.h"
35 #include "ipc/ipc_message_macros.h" 35 #include "ipc/ipc_message_macros.h"
36 36
37 namespace extensions { 37 namespace extensions {
38 38
39 ActiveScriptController::ActiveScriptController( 39 ActiveScriptController::ActiveScriptController(
40 content::WebContents* web_contents) 40 content::WebContents* web_contents)
41 : content::WebContentsObserver(web_contents), 41 : content::WebContentsObserver(web_contents),
42 num_page_requests_(0),
42 browser_context_(web_contents->GetBrowserContext()), 43 browser_context_(web_contents->GetBrowserContext()),
43 was_used_on_page_(false), 44 was_used_on_page_(false),
44 extension_registry_observer_(this) { 45 extension_registry_observer_(this) {
45 CHECK(web_contents); 46 CHECK(web_contents);
46 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); 47 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
47 } 48 }
48 49
49 ActiveScriptController::~ActiveScriptController() { 50 ActiveScriptController::~ActiveScriptController() {
50 LogUMA(); 51 LogUMA();
51 } 52 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // permitted extensions (for metrics), and return immediately. 231 // permitted extensions (for metrics), and return immediately.
231 if (request_id == -1) { 232 if (request_id == -1) {
232 if (PermissionsData::ScriptsMayRequireActionForExtension( 233 if (PermissionsData::ScriptsMayRequireActionForExtension(
233 extension, 234 extension,
234 extension->permissions_data()->active_permissions().get())) { 235 extension->permissions_data()->active_permissions().get())) {
235 permitted_extensions_.insert(extension->id()); 236 permitted_extensions_.insert(extension->id());
236 } 237 }
237 return; 238 return;
238 } 239 }
239 240
241 ++num_page_requests_;
242
240 switch (RequiresUserConsentForScriptInjection(extension, script_type)) { 243 switch (RequiresUserConsentForScriptInjection(extension, script_type)) {
241 case PermissionsData::ACCESS_ALLOWED: 244 case PermissionsData::ACCESS_ALLOWED:
242 PermitScriptInjection(request_id); 245 PermitScriptInjection(request_id);
243 break; 246 break;
244 case PermissionsData::ACCESS_WITHHELD: 247 case PermissionsData::ACCESS_WITHHELD:
245 // This base::Unretained() is safe, because the callback is only invoked 248 // This base::Unretained() is safe, because the callback is only invoked
246 // by this object. 249 // by this object.
247 RequestScriptInjection( 250 RequestScriptInjection(
248 extension, 251 extension,
249 base::Bind(&ActiveScriptController::PermitScriptInjection, 252 base::Bind(&ActiveScriptController::PermitScriptInjection,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return handled; 311 return handled;
309 } 312 }
310 313
311 void ActiveScriptController::DidNavigateMainFrame( 314 void ActiveScriptController::DidNavigateMainFrame(
312 const content::LoadCommittedDetails& details, 315 const content::LoadCommittedDetails& details,
313 const content::FrameNavigateParams& params) { 316 const content::FrameNavigateParams& params) {
314 if (details.is_in_page) 317 if (details.is_in_page)
315 return; 318 return;
316 319
317 LogUMA(); 320 LogUMA();
321 num_page_requests_ = 0;
318 permitted_extensions_.clear(); 322 permitted_extensions_.clear();
319 pending_requests_.clear(); 323 pending_requests_.clear();
320 was_used_on_page_ = false; 324 was_used_on_page_ = false;
321 } 325 }
322 326
323 void ActiveScriptController::OnExtensionUnloaded( 327 void ActiveScriptController::OnExtensionUnloaded(
324 content::BrowserContext* browser_context, 328 content::BrowserContext* browser_context,
325 const Extension* extension, 329 const Extension* extension,
326 UnloadedExtensionInfo::Reason reason) { 330 UnloadedExtensionInfo::Reason reason) {
327 PendingRequestMap::iterator iter = pending_requests_.find(extension->id()); 331 PendingRequestMap::iterator iter = pending_requests_.find(extension->id());
328 if (iter != pending_requests_.end()) { 332 if (iter != pending_requests_.end()) {
329 pending_requests_.erase(iter); 333 pending_requests_.erase(iter);
330 ExtensionActionAPI::Get(browser_context_)-> 334 ExtensionActionAPI::Get(browser_context_)->
331 NotifyPageActionsChanged(web_contents()); 335 NotifyPageActionsChanged(web_contents());
332 } 336 }
333 } 337 }
334 338
335 } // namespace extensions 339 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698