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 "extensions/renderer/script_injection_manager.h" | 5 #include "extensions/renderer/script_injection_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 if (!active_injection_frames_.count(frame)) | 400 if (!active_injection_frames_.count(frame)) |
401 break; | 401 break; |
402 std::unique_ptr<ScriptInjection> injection(std::move(*iter)); | 402 std::unique_ptr<ScriptInjection> injection(std::move(*iter)); |
403 iter = frame_injections.erase(iter); | 403 iter = frame_injections.erase(iter); |
404 TryToInject(std::move(injection), run_location, &scripts_run_info); | 404 TryToInject(std::move(injection), run_location, &scripts_run_info); |
405 } | 405 } |
406 | 406 |
407 // We are done running in the frame. | 407 // We are done running in the frame. |
408 active_injection_frames_.erase(frame); | 408 active_injection_frames_.erase(frame); |
409 | 409 |
410 scripts_run_info.LogRun(); | 410 scripts_run_info.LogRun(activity_logging_enabled_); |
411 } | 411 } |
412 | 412 |
413 void ScriptInjectionManager::TryToInject( | 413 void ScriptInjectionManager::TryToInject( |
414 std::unique_ptr<ScriptInjection> injection, | 414 std::unique_ptr<ScriptInjection> injection, |
415 UserScript::RunLocation run_location, | 415 UserScript::RunLocation run_location, |
416 ScriptsRunInfo* scripts_run_info) { | 416 ScriptsRunInfo* scripts_run_info) { |
417 // Try to inject the script. If the injection is waiting (i.e., for | 417 // Try to inject the script. If the injection is waiting (i.e., for |
418 // permission), add it to the list of pending injections. If the injection | 418 // permission), add it to the list of pending injections. If the injection |
419 // has blocked, add it to the list of running injections. | 419 // has blocked, add it to the list of running injections. |
420 // The Unretained below is safe because this object owns all the | 420 // The Unretained below is safe because this object owns all the |
(...skipping 24 matching lines...) Expand all Loading... |
445 return; | 445 return; |
446 } else if (params.host_id.type() == HostID::WEBUI) { | 446 } else if (params.host_id.type() == HostID::WEBUI) { |
447 injection_host.reset( | 447 injection_host.reset( |
448 new WebUIInjectionHost(params.host_id)); | 448 new WebUIInjectionHost(params.host_id)); |
449 } | 449 } |
450 | 450 |
451 std::unique_ptr<ScriptInjection> injection(new ScriptInjection( | 451 std::unique_ptr<ScriptInjection> injection(new ScriptInjection( |
452 std::unique_ptr<ScriptInjector>( | 452 std::unique_ptr<ScriptInjector>( |
453 new ProgrammaticScriptInjector(params, render_frame)), | 453 new ProgrammaticScriptInjector(params, render_frame)), |
454 render_frame, std::move(injection_host), | 454 render_frame, std::move(injection_host), |
455 static_cast<UserScript::RunLocation>(params.run_at))); | 455 static_cast<UserScript::RunLocation>(params.run_at), |
| 456 activity_logging_enabled_)); |
456 | 457 |
457 FrameStatusMap::const_iterator iter = frame_statuses_.find(render_frame); | 458 FrameStatusMap::const_iterator iter = frame_statuses_.find(render_frame); |
458 UserScript::RunLocation run_location = | 459 UserScript::RunLocation run_location = |
459 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second; | 460 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second; |
460 | 461 |
461 ScriptsRunInfo scripts_run_info(render_frame, run_location); | 462 ScriptsRunInfo scripts_run_info(render_frame, run_location); |
462 TryToInject(std::move(injection), run_location, &scripts_run_info); | 463 TryToInject(std::move(injection), run_location, &scripts_run_info); |
463 } | 464 } |
464 | 465 |
465 void ScriptInjectionManager::HandleExecuteDeclarativeScript( | 466 void ScriptInjectionManager::HandleExecuteDeclarativeScript( |
466 content::RenderFrame* render_frame, | 467 content::RenderFrame* render_frame, |
467 int tab_id, | 468 int tab_id, |
468 const ExtensionId& extension_id, | 469 const ExtensionId& extension_id, |
469 int script_id, | 470 int script_id, |
470 const GURL& url) { | 471 const GURL& url) { |
471 std::unique_ptr<ScriptInjection> injection = | 472 std::unique_ptr<ScriptInjection> injection = |
472 user_script_set_manager_->GetInjectionForDeclarativeScript( | 473 user_script_set_manager_->GetInjectionForDeclarativeScript( |
473 script_id, render_frame, tab_id, url, extension_id); | 474 script_id, render_frame, tab_id, url, extension_id); |
474 if (injection.get()) { | 475 if (injection.get()) { |
475 ScriptsRunInfo scripts_run_info(render_frame, UserScript::BROWSER_DRIVEN); | 476 ScriptsRunInfo scripts_run_info(render_frame, UserScript::BROWSER_DRIVEN); |
476 // TODO(markdittmer): Use return value of TryToInject for error handling. | 477 // TODO(markdittmer): Use return value of TryToInject for error handling. |
477 TryToInject(std::move(injection), UserScript::BROWSER_DRIVEN, | 478 TryToInject(std::move(injection), UserScript::BROWSER_DRIVEN, |
478 &scripts_run_info); | 479 &scripts_run_info); |
479 | 480 |
480 scripts_run_info.LogRun(); | 481 scripts_run_info.LogRun(activity_logging_enabled_); |
481 } | 482 } |
482 } | 483 } |
483 | 484 |
484 void ScriptInjectionManager::HandlePermitScriptInjection(int64_t request_id) { | 485 void ScriptInjectionManager::HandlePermitScriptInjection(int64_t request_id) { |
485 auto iter = pending_injections_.begin(); | 486 auto iter = pending_injections_.begin(); |
486 for (; iter != pending_injections_.end(); ++iter) { | 487 for (; iter != pending_injections_.end(); ++iter) { |
487 if ((*iter)->request_id() == request_id) { | 488 if ((*iter)->request_id() == request_id) { |
488 DCHECK((*iter)->host_id().type() == HostID::EXTENSIONS); | 489 DCHECK((*iter)->host_id().type() == HostID::EXTENSIONS); |
489 break; | 490 break; |
490 } | 491 } |
491 } | 492 } |
492 if (iter == pending_injections_.end()) | 493 if (iter == pending_injections_.end()) |
493 return; | 494 return; |
494 | 495 |
495 // At this point, because the request is present in pending_injections_, we | 496 // At this point, because the request is present in pending_injections_, we |
496 // know that this is the same page that issued the request (otherwise, | 497 // know that this is the same page that issued the request (otherwise, |
497 // RFOHelper::InvalidateAndResetFrame would have caused it to be cleared out). | 498 // RFOHelper::InvalidateAndResetFrame would have caused it to be cleared out). |
498 | 499 |
499 std::unique_ptr<ScriptInjection> injection(std::move(*iter)); | 500 std::unique_ptr<ScriptInjection> injection(std::move(*iter)); |
500 pending_injections_.erase(iter); | 501 pending_injections_.erase(iter); |
501 | 502 |
502 ScriptsRunInfo scripts_run_info(injection->render_frame(), | 503 ScriptsRunInfo scripts_run_info(injection->render_frame(), |
503 UserScript::RUN_DEFERRED); | 504 UserScript::RUN_DEFERRED); |
504 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( | 505 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( |
505 &scripts_run_info); | 506 &scripts_run_info); |
506 if (res == ScriptInjection::INJECTION_BLOCKED) | 507 if (res == ScriptInjection::INJECTION_BLOCKED) |
507 running_injections_.push_back(std::move(injection)); | 508 running_injections_.push_back(std::move(injection)); |
508 scripts_run_info.LogRun(); | 509 scripts_run_info.LogRun(activity_logging_enabled_); |
509 } | 510 } |
510 | 511 |
511 } // namespace extensions | 512 } // namespace extensions |
OLD | NEW |