| 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_set.h" | 5 #include "extensions/renderer/user_script_set.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 void UserScriptSet::AddObserver(Observer* observer) { | 51 void UserScriptSet::AddObserver(Observer* observer) { |
| 52 observers_.AddObserver(observer); | 52 observers_.AddObserver(observer); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void UserScriptSet::RemoveObserver(Observer* observer) { | 55 void UserScriptSet::RemoveObserver(Observer* observer) { |
| 56 observers_.RemoveObserver(observer); | 56 observers_.RemoveObserver(observer); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void UserScriptSet::GetActiveExtensionIds( | 59 void UserScriptSet::GetActiveExtensionIds( |
| 60 std::set<std::string>* ids) const { | 60 std::set<std::string>* ids) const { |
| 61 for (const UserScript* script : scripts_) { | 61 for (const std::unique_ptr<UserScript>& script : scripts_) { |
| 62 if (script->host_id().type() != HostID::EXTENSIONS) | 62 if (script->host_id().type() != HostID::EXTENSIONS) |
| 63 continue; | 63 continue; |
| 64 DCHECK(!script->extension_id().empty()); | 64 DCHECK(!script->extension_id().empty()); |
| 65 ids->insert(script->extension_id()); | 65 ids->insert(script->extension_id()); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 void UserScriptSet::GetInjections( | 69 void UserScriptSet::GetInjections( |
| 70 std::vector<std::unique_ptr<ScriptInjection>>* injections, | 70 std::vector<std::unique_ptr<ScriptInjection>>* injections, |
| 71 content::RenderFrame* render_frame, | 71 content::RenderFrame* render_frame, |
| 72 int tab_id, | 72 int tab_id, |
| 73 UserScript::RunLocation run_location, | 73 UserScript::RunLocation run_location, |
| 74 bool log_activity) { | 74 bool log_activity) { |
| 75 GURL document_url = GetDocumentUrlForFrame(render_frame->GetWebFrame()); | 75 GURL document_url = GetDocumentUrlForFrame(render_frame->GetWebFrame()); |
| 76 for (const UserScript* script : scripts_) { | 76 for (const std::unique_ptr<UserScript>& script : scripts_) { |
| 77 std::unique_ptr<ScriptInjection> injection = GetInjectionForScript( | 77 std::unique_ptr<ScriptInjection> injection = GetInjectionForScript( |
| 78 script, render_frame, tab_id, run_location, document_url, | 78 script.get(), render_frame, tab_id, run_location, document_url, |
| 79 false /* is_declarative */, log_activity); | 79 false /* is_declarative */, log_activity); |
| 80 if (injection.get()) | 80 if (injection.get()) |
| 81 injections->push_back(std::move(injection)); | 81 injections->push_back(std::move(injection)); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool UserScriptSet::UpdateUserScripts(base::SharedMemoryHandle shared_memory, | 85 bool UserScriptSet::UpdateUserScripts(base::SharedMemoryHandle shared_memory, |
| 86 const std::set<HostID>& changed_hosts, | 86 const std::set<HostID>& changed_hosts, |
| 87 bool whitelisted_only) { | 87 bool whitelisted_only) { |
| 88 bool only_inject_incognito = | 88 bool only_inject_incognito = |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 RendererExtensionRegistry::Get()->GetByID(script->extension_id()); | 143 RendererExtensionRegistry::Get()->GetByID(script->extension_id()); |
| 144 if (whitelisted_only && | 144 if (whitelisted_only && |
| 145 (!extension || | 145 (!extension || |
| 146 !PermissionsData::CanExecuteScriptEverywhere(extension))) { | 146 !PermissionsData::CanExecuteScriptEverywhere(extension))) { |
| 147 continue; | 147 continue; |
| 148 } | 148 } |
| 149 | 149 |
| 150 scripts_.push_back(std::move(script)); | 150 scripts_.push_back(std::move(script)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 FOR_EACH_OBSERVER(Observer, | 153 FOR_EACH_OBSERVER(Observer, observers_, |
| 154 observers_, | 154 OnUserScriptsUpdated(changed_hosts, scripts_)); |
| 155 OnUserScriptsUpdated(changed_hosts, scripts_.get())); | |
| 156 return true; | 155 return true; |
| 157 } | 156 } |
| 158 | 157 |
| 159 std::unique_ptr<ScriptInjection> UserScriptSet::GetDeclarativeScriptInjection( | 158 std::unique_ptr<ScriptInjection> UserScriptSet::GetDeclarativeScriptInjection( |
| 160 int script_id, | 159 int script_id, |
| 161 content::RenderFrame* render_frame, | 160 content::RenderFrame* render_frame, |
| 162 int tab_id, | 161 int tab_id, |
| 163 UserScript::RunLocation run_location, | 162 UserScript::RunLocation run_location, |
| 164 const GURL& document_url, | 163 const GURL& document_url, |
| 165 bool log_activity) { | 164 bool log_activity) { |
| 166 for (const UserScript* script : scripts_) { | 165 for (const std::unique_ptr<UserScript>& script : scripts_) { |
| 167 if (script->id() == script_id) { | 166 if (script->id() == script_id) { |
| 168 return GetInjectionForScript(script, render_frame, tab_id, run_location, | 167 return GetInjectionForScript(script.get(), render_frame, tab_id, |
| 169 document_url, true /* is_declarative */, | 168 run_location, document_url, |
| 170 log_activity); | 169 true /* is_declarative */, log_activity); |
| 171 } | 170 } |
| 172 } | 171 } |
| 173 return std::unique_ptr<ScriptInjection>(); | 172 return std::unique_ptr<ScriptInjection>(); |
| 174 } | 173 } |
| 175 | 174 |
| 176 std::unique_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript( | 175 std::unique_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript( |
| 177 const UserScript* script, | 176 const UserScript* script, |
| 178 content::RenderFrame* render_frame, | 177 content::RenderFrame* render_frame, |
| 179 int tab_id, | 178 int tab_id, |
| 180 UserScript::RunLocation run_location, | 179 UserScript::RunLocation run_location, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 !script->js_scripts().empty() && script->run_location() == run_location; | 220 !script->js_scripts().empty() && script->run_location() == run_location; |
| 222 if (inject_css || inject_js) { | 221 if (inject_css || inject_js) { |
| 223 injection.reset(new ScriptInjection(std::move(injector), render_frame, | 222 injection.reset(new ScriptInjection(std::move(injector), render_frame, |
| 224 std::move(injection_host), run_location, | 223 std::move(injection_host), run_location, |
| 225 log_activity)); | 224 log_activity)); |
| 226 } | 225 } |
| 227 return injection; | 226 return injection; |
| 228 } | 227 } |
| 229 | 228 |
| 230 } // namespace extensions | 229 } // namespace extensions |
| OLD | NEW |