| 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/user_script_injector.h" | 5 #include "extensions/renderer/user_script_injector.h" |
| 6 | 6 |
| 7 #include <tuple> | 7 #include <tuple> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 is_declarative_(is_declarative), | 94 is_declarative_(is_declarative), |
| 95 user_script_set_observer_(this) { | 95 user_script_set_observer_(this) { |
| 96 user_script_set_observer_.Add(script_list); | 96 user_script_set_observer_.Add(script_list); |
| 97 } | 97 } |
| 98 | 98 |
| 99 UserScriptInjector::~UserScriptInjector() { | 99 UserScriptInjector::~UserScriptInjector() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 void UserScriptInjector::OnUserScriptsUpdated( | 102 void UserScriptInjector::OnUserScriptsUpdated( |
| 103 const std::set<HostID>& changed_hosts, | 103 const std::set<HostID>& changed_hosts, |
| 104 const std::vector<UserScript*>& scripts) { | 104 const std::vector<std::unique_ptr<UserScript>>& scripts) { |
| 105 // If the host causing this injection changed, then this injection | 105 // If the host causing this injection changed, then this injection |
| 106 // will be removed, and there's no guarantee the backing script still exists. | 106 // will be removed, and there's no guarantee the backing script still exists. |
| 107 if (changed_hosts.count(host_id_) > 0) { | 107 if (changed_hosts.count(host_id_) > 0) { |
| 108 script_ = nullptr; | 108 script_ = nullptr; |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 | 111 |
| 112 for (std::vector<UserScript*>::const_iterator iter = scripts.begin(); | 112 for (const std::unique_ptr<UserScript>& script : scripts) { |
| 113 iter != scripts.end(); | |
| 114 ++iter) { | |
| 115 // We need to compare to |script_id_| (and not to script_->id()) because the | 113 // We need to compare to |script_id_| (and not to script_->id()) because the |
| 116 // old |script_| may be deleted by now. | 114 // old |script_| may be deleted by now. |
| 117 if ((*iter)->id() == script_id_) { | 115 if (script->id() == script_id_) { |
| 118 script_ = *iter; | 116 script_ = script.get(); |
| 119 break; | 117 break; |
| 120 } | 118 } |
| 121 } | 119 } |
| 122 } | 120 } |
| 123 | 121 |
| 124 UserScript::InjectionType UserScriptInjector::script_type() const { | 122 UserScript::InjectionType UserScriptInjector::script_type() const { |
| 125 return UserScript::CONTENT_SCRIPT; | 123 return UserScript::CONTENT_SCRIPT; |
| 126 } | 124 } |
| 127 | 125 |
| 128 bool UserScriptInjector::ShouldExecuteInMainWorld() const { | 126 bool UserScriptInjector::ShouldExecuteInMainWorld() const { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 void UserScriptInjector::OnInjectionComplete( | 285 void UserScriptInjector::OnInjectionComplete( |
| 288 std::unique_ptr<base::Value> execution_result, | 286 std::unique_ptr<base::Value> execution_result, |
| 289 UserScript::RunLocation run_location, | 287 UserScript::RunLocation run_location, |
| 290 content::RenderFrame* render_frame) {} | 288 content::RenderFrame* render_frame) {} |
| 291 | 289 |
| 292 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason, | 290 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason, |
| 293 content::RenderFrame* render_frame) { | 291 content::RenderFrame* render_frame) { |
| 294 } | 292 } |
| 295 | 293 |
| 296 } // namespace extensions | 294 } // namespace extensions |
| OLD | NEW |