| 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" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 ++request) { | 212 ++request) { |
| 213 // Only run if it's on the proper page. | 213 // Only run if it's on the proper page. |
| 214 if (request->page_id == page_id) | 214 if (request->page_id == page_id) |
| 215 request->closure.Run(); | 215 request->closure.Run(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Inform the location bar that the action is now gone. | 218 // Inform the location bar that the action is now gone. |
| 219 LocationBarController::NotifyChange(web_contents()); | 219 LocationBarController::NotifyChange(web_contents()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void ActiveScriptController::OnRequestContentScriptPermission( | 222 void ActiveScriptController::OnRequestScriptInjectionPermission( |
| 223 const std::string& extension_id, | 223 const std::string& extension_id, |
| 224 int page_id, | 224 int page_id, |
| 225 int request_id) { | 225 int request_id) { |
| 226 if (!Extension::IdIsValid(extension_id)) { | 226 if (!Extension::IdIsValid(extension_id)) { |
| 227 NOTREACHED() << "'" << extension_id << "' is not a valid id."; | 227 NOTREACHED() << "'" << extension_id << "' is not a valid id."; |
| 228 return; | 228 return; |
| 229 } | 229 } |
| 230 | 230 |
| 231 const Extension* extension = | 231 const Extension* extension = |
| 232 ExtensionRegistry::Get(web_contents()->GetBrowserContext()) | 232 ExtensionRegistry::Get(web_contents()->GetBrowserContext()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 244 permitted_extensions_.insert(extension->id()); | 244 permitted_extensions_.insert(extension->id()); |
| 245 return; | 245 return; |
| 246 } | 246 } |
| 247 | 247 |
| 248 if (RequiresUserConsentForScriptInjection(extension)) { | 248 if (RequiresUserConsentForScriptInjection(extension)) { |
| 249 // This base::Unretained() is safe, because the callback is only invoked by | 249 // This base::Unretained() is safe, because the callback is only invoked by |
| 250 // this object. | 250 // this object. |
| 251 RequestScriptInjection( | 251 RequestScriptInjection( |
| 252 extension, | 252 extension, |
| 253 page_id, | 253 page_id, |
| 254 base::Bind(&ActiveScriptController::GrantContentScriptPermission, | 254 base::Bind(&ActiveScriptController::PermitScriptInjection, |
| 255 base::Unretained(this), | 255 base::Unretained(this), |
| 256 request_id)); | 256 request_id)); |
| 257 } else { | 257 } else { |
| 258 GrantContentScriptPermission(request_id); | 258 PermitScriptInjection(request_id); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 void ActiveScriptController::GrantContentScriptPermission(int request_id) { | 262 void ActiveScriptController::PermitScriptInjection(int request_id) { |
| 263 content::RenderViewHost* render_view_host = | 263 content::RenderViewHost* render_view_host = |
| 264 web_contents()->GetRenderViewHost(); | 264 web_contents()->GetRenderViewHost(); |
| 265 if (render_view_host) { | 265 if (render_view_host) { |
| 266 render_view_host->Send(new ExtensionMsg_GrantContentScriptPermission( | 266 render_view_host->Send(new ExtensionMsg_PermitScriptInjection( |
| 267 render_view_host->GetRoutingID(), | 267 render_view_host->GetRoutingID(), request_id)); |
| 268 request_id)); | |
| 269 } | 268 } |
| 270 } | 269 } |
| 271 | 270 |
| 272 bool ActiveScriptController::OnMessageReceived(const IPC::Message& message) { | 271 bool ActiveScriptController::OnMessageReceived(const IPC::Message& message) { |
| 273 bool handled = true; | 272 bool handled = true; |
| 274 IPC_BEGIN_MESSAGE_MAP(ActiveScriptController, message) | 273 IPC_BEGIN_MESSAGE_MAP(ActiveScriptController, message) |
| 275 IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestContentScriptPermission, | 274 IPC_MESSAGE_HANDLER(ExtensionHostMsg_RequestScriptInjectionPermission, |
| 276 OnRequestContentScriptPermission) | 275 OnRequestScriptInjectionPermission) |
| 277 IPC_MESSAGE_UNHANDLED(handled = false) | 276 IPC_MESSAGE_UNHANDLED(handled = false) |
| 278 IPC_END_MESSAGE_MAP() | 277 IPC_END_MESSAGE_MAP() |
| 279 return handled; | 278 return handled; |
| 280 } | 279 } |
| 281 | 280 |
| 282 void ActiveScriptController::LogUMA() const { | 281 void ActiveScriptController::LogUMA() const { |
| 283 UMA_HISTOGRAM_COUNTS_100( | 282 UMA_HISTOGRAM_COUNTS_100( |
| 284 "Extensions.ActiveScriptController.ShownActiveScriptsOnPage", | 283 "Extensions.ActiveScriptController.ShownActiveScriptsOnPage", |
| 285 pending_requests_.size()); | 284 pending_requests_.size()); |
| 286 | 285 |
| 287 // We only log the permitted extensions metric if the feature is enabled, | 286 // We only log the permitted extensions metric if the feature is enabled, |
| 288 // because otherwise the data will be boring (100% allowed). | 287 // because otherwise the data will be boring (100% allowed). |
| 289 if (enabled_) { | 288 if (enabled_) { |
| 290 UMA_HISTOGRAM_COUNTS_100( | 289 UMA_HISTOGRAM_COUNTS_100( |
| 291 "Extensions.ActiveScriptController.PermittedExtensions", | 290 "Extensions.ActiveScriptController.PermittedExtensions", |
| 292 permitted_extensions_.size()); | 291 permitted_extensions_.size()); |
| 293 UMA_HISTOGRAM_COUNTS_100( | 292 UMA_HISTOGRAM_COUNTS_100( |
| 294 "Extensions.ActiveScriptController.DeniedExtensions", | 293 "Extensions.ActiveScriptController.DeniedExtensions", |
| 295 pending_requests_.size()); | 294 pending_requests_.size()); |
| 296 } | 295 } |
| 297 } | 296 } |
| 298 | 297 |
| 299 } // namespace extensions | 298 } // namespace extensions |
| OLD | NEW |