| OLD | NEW |
| 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/api/extension_action/extension_action_api.h" |
| 13 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
| 14 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
| 15 #include "chrome/browser/extensions/extension_util.h" | 16 #include "chrome/browser/extensions/extension_util.h" |
| 16 #include "chrome/browser/extensions/location_bar_controller.h" | 17 #include "chrome/browser/extensions/location_bar_controller.h" |
| 17 #include "chrome/browser/extensions/permissions_updater.h" | 18 #include "chrome/browser/extensions/permissions_updater.h" |
| 18 #include "chrome/browser/extensions/tab_helper.h" | 19 #include "chrome/browser/extensions/tab_helper.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/sessions/session_tab_helper.h" | 21 #include "chrome/browser/sessions/session_tab_helper.h" |
| 21 #include "chrome/common/extensions/api/extension_action/action_info.h" | 22 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 22 #include "components/crx_file/id_util.h" | 23 #include "components/crx_file/id_util.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 214 |
| 214 void ActiveScriptController::RequestScriptInjection( | 215 void ActiveScriptController::RequestScriptInjection( |
| 215 const Extension* extension, | 216 const Extension* extension, |
| 216 const base::Closure& callback) { | 217 const base::Closure& callback) { |
| 217 CHECK(extension); | 218 CHECK(extension); |
| 218 PendingRequestList& list = pending_requests_[extension->id()]; | 219 PendingRequestList& list = pending_requests_[extension->id()]; |
| 219 list.push_back(callback); | 220 list.push_back(callback); |
| 220 | 221 |
| 221 // If this was the first entry, notify the location bar that there's a new | 222 // If this was the first entry, notify the location bar that there's a new |
| 222 // icon. | 223 // icon. |
| 223 if (list.size() == 1u) | 224 if (list.size() == 1u) { |
| 224 LocationBarController::NotifyChange(web_contents()); | 225 ExtensionActionAPI::Get(web_contents()->GetBrowserContext())-> |
| 226 NotifyPageActionsChanged(web_contents()); |
| 227 } |
| 225 } | 228 } |
| 226 | 229 |
| 227 void ActiveScriptController::RunPendingForExtension( | 230 void ActiveScriptController::RunPendingForExtension( |
| 228 const Extension* extension) { | 231 const Extension* extension) { |
| 229 DCHECK(extension); | 232 DCHECK(extension); |
| 230 | 233 |
| 231 content::NavigationEntry* visible_entry = | 234 content::NavigationEntry* visible_entry = |
| 232 web_contents()->GetController().GetVisibleEntry(); | 235 web_contents()->GetController().GetVisibleEntry(); |
| 233 // Refuse to run if there's no visible entry, because we have no idea of | 236 // Refuse to run if there's no visible entry, because we have no idea of |
| 234 // determining if it's the proper page. This should rarely, if ever, happen. | 237 // determining if it's the proper page. This should rarely, if ever, happen. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 256 active_tab_permission_granter()->GrantIfRequested(extension); | 259 active_tab_permission_granter()->GrantIfRequested(extension); |
| 257 | 260 |
| 258 // Run all pending injections for the given extension. | 261 // Run all pending injections for the given extension. |
| 259 for (PendingRequestList::iterator request = requests.begin(); | 262 for (PendingRequestList::iterator request = requests.begin(); |
| 260 request != requests.end(); | 263 request != requests.end(); |
| 261 ++request) { | 264 ++request) { |
| 262 request->Run(); | 265 request->Run(); |
| 263 } | 266 } |
| 264 | 267 |
| 265 // Inform the location bar that the action is now gone. | 268 // Inform the location bar that the action is now gone. |
| 266 LocationBarController::NotifyChange(web_contents()); | 269 ExtensionActionAPI::Get(web_contents()->GetBrowserContext())-> |
| 270 NotifyPageActionsChanged(web_contents()); |
| 267 } | 271 } |
| 268 | 272 |
| 269 void ActiveScriptController::OnRequestScriptInjectionPermission( | 273 void ActiveScriptController::OnRequestScriptInjectionPermission( |
| 270 const std::string& extension_id, | 274 const std::string& extension_id, |
| 271 UserScript::InjectionType script_type, | 275 UserScript::InjectionType script_type, |
| 272 int64 request_id) { | 276 int64 request_id) { |
| 273 if (!crx_file::id_util::IdIsValid(extension_id)) { | 277 if (!crx_file::id_util::IdIsValid(extension_id)) { |
| 274 NOTREACHED() << "'" << extension_id << "' is not a valid id."; | 278 NOTREACHED() << "'" << extension_id << "' is not a valid id."; |
| 275 return; | 279 return; |
| 276 } | 280 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 UMA_HISTOGRAM_COUNTS_100( | 351 UMA_HISTOGRAM_COUNTS_100( |
| 348 "Extensions.ActiveScriptController.PermittedExtensions", | 352 "Extensions.ActiveScriptController.PermittedExtensions", |
| 349 permitted_extensions_.size()); | 353 permitted_extensions_.size()); |
| 350 UMA_HISTOGRAM_COUNTS_100( | 354 UMA_HISTOGRAM_COUNTS_100( |
| 351 "Extensions.ActiveScriptController.DeniedExtensions", | 355 "Extensions.ActiveScriptController.DeniedExtensions", |
| 352 pending_requests_.size()); | 356 pending_requests_.size()); |
| 353 } | 357 } |
| 354 } | 358 } |
| 355 | 359 |
| 356 } // namespace extensions | 360 } // namespace extensions |
| OLD | NEW |