| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browser/extension_user_script_loader.h" | 5 #include "extensions/browser/extension_user_script_loader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 iter->second.first, host_id.id(), iter->second.second); | 122 iter->second.first, host_id.id(), iter->second.second); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void LoadUserScripts(UserScriptList* user_scripts, | 125 void LoadUserScripts(UserScriptList* user_scripts, |
| 126 const ExtensionUserScriptLoader::HostsInfo& hosts_info, | 126 const ExtensionUserScriptLoader::HostsInfo& hosts_info, |
| 127 const std::set<int>& added_script_ids, | 127 const std::set<int>& added_script_ids, |
| 128 const scoped_refptr<ContentVerifier>& verifier) { | 128 const scoped_refptr<ContentVerifier>& verifier) { |
| 129 for (UserScript& script : *user_scripts) { | 129 for (UserScript& script : *user_scripts) { |
| 130 if (added_script_ids.count(script.id()) == 0) | 130 if (added_script_ids.count(script.id()) == 0) |
| 131 continue; | 131 continue; |
| 132 scoped_ptr<SubstitutionMap> localization_messages( | 132 std::unique_ptr<SubstitutionMap> localization_messages( |
| 133 GetLocalizationMessages(hosts_info, script.host_id())); | 133 GetLocalizationMessages(hosts_info, script.host_id())); |
| 134 for (UserScript::File& script_file : script.js_scripts()) { | 134 for (UserScript::File& script_file : script.js_scripts()) { |
| 135 if (script_file.GetContent().empty()) | 135 if (script_file.GetContent().empty()) |
| 136 LoadScriptContent(script.host_id(), &script_file, nullptr, verifier); | 136 LoadScriptContent(script.host_id(), &script_file, nullptr, verifier); |
| 137 } | 137 } |
| 138 for (UserScript::File& script_file : script.css_scripts()) { | 138 for (UserScript::File& script_file : script.css_scripts()) { |
| 139 if (script_file.GetContent().empty()) | 139 if (script_file.GetContent().empty()) |
| 140 LoadScriptContent(script.host_id(), &script_file, | 140 LoadScriptContent(script.host_id(), &script_file, |
| 141 localization_messages.get(), verifier); | 141 localization_messages.get(), verifier); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 void LoadScriptsOnFileThread( | 146 void LoadScriptsOnFileThread( |
| 147 scoped_ptr<UserScriptList> user_scripts, | 147 std::unique_ptr<UserScriptList> user_scripts, |
| 148 const ExtensionUserScriptLoader::HostsInfo& hosts_info, | 148 const ExtensionUserScriptLoader::HostsInfo& hosts_info, |
| 149 const std::set<int>& added_script_ids, | 149 const std::set<int>& added_script_ids, |
| 150 const scoped_refptr<ContentVerifier>& verifier, | 150 const scoped_refptr<ContentVerifier>& verifier, |
| 151 UserScriptLoader::LoadScriptsCallback callback) { | 151 UserScriptLoader::LoadScriptsCallback callback) { |
| 152 DCHECK(user_scripts.get()); | 152 DCHECK(user_scripts.get()); |
| 153 LoadUserScripts(user_scripts.get(), hosts_info, added_script_ids, verifier); | 153 LoadUserScripts(user_scripts.get(), hosts_info, added_script_ids, verifier); |
| 154 scoped_ptr<base::SharedMemory> memory = | 154 std::unique_ptr<base::SharedMemory> memory = |
| 155 UserScriptLoader::Serialize(*user_scripts); | 155 UserScriptLoader::Serialize(*user_scripts); |
| 156 content::BrowserThread::PostTask( | 156 content::BrowserThread::PostTask( |
| 157 content::BrowserThread::UI, FROM_HERE, | 157 content::BrowserThread::UI, FROM_HERE, |
| 158 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory))); | 158 base::Bind(callback, base::Passed(&user_scripts), base::Passed(&memory))); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace | 161 } // namespace |
| 162 | 162 |
| 163 ExtensionUserScriptLoader::ExtensionUserScriptLoader( | 163 ExtensionUserScriptLoader::ExtensionUserScriptLoader( |
| 164 BrowserContext* browser_context, | 164 BrowserContext* browser_context, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 189 HostsInfo info; | 189 HostsInfo info; |
| 190 std::set<int> added_script_ids; | 190 std::set<int> added_script_ids; |
| 191 for (UserScript& script : *user_scripts) | 191 for (UserScript& script : *user_scripts) |
| 192 added_script_ids.insert(script.id()); | 192 added_script_ids.insert(script.id()); |
| 193 | 193 |
| 194 LoadUserScripts(user_scripts, info, added_script_ids, | 194 LoadUserScripts(user_scripts, info, added_script_ids, |
| 195 nullptr /* no verifier for testing */); | 195 nullptr /* no verifier for testing */); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void ExtensionUserScriptLoader::LoadScripts( | 198 void ExtensionUserScriptLoader::LoadScripts( |
| 199 scoped_ptr<UserScriptList> user_scripts, | 199 std::unique_ptr<UserScriptList> user_scripts, |
| 200 const std::set<HostID>& changed_hosts, | 200 const std::set<HostID>& changed_hosts, |
| 201 const std::set<int>& added_script_ids, | 201 const std::set<int>& added_script_ids, |
| 202 LoadScriptsCallback callback) { | 202 LoadScriptsCallback callback) { |
| 203 UpdateHostsInfo(changed_hosts); | 203 UpdateHostsInfo(changed_hosts); |
| 204 | 204 |
| 205 content::BrowserThread::PostTask( | 205 content::BrowserThread::PostTask( |
| 206 content::BrowserThread::FILE, FROM_HERE, | 206 content::BrowserThread::FILE, FROM_HERE, |
| 207 base::Bind(&LoadScriptsOnFileThread, base::Passed(&user_scripts), | 207 base::Bind(&LoadScriptsOnFileThread, base::Passed(&user_scripts), |
| 208 hosts_info_, added_script_ids, content_verifier_, callback)); | 208 hosts_info_, added_script_ids, content_verifier_, callback)); |
| 209 } | 209 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 230 const Extension* extension, | 230 const Extension* extension, |
| 231 UnloadedExtensionInfo::Reason reason) { | 231 UnloadedExtensionInfo::Reason reason) { |
| 232 hosts_info_.erase(HostID(HostID::EXTENSIONS, extension->id())); | 232 hosts_info_.erase(HostID(HostID::EXTENSIONS, extension->id())); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void ExtensionUserScriptLoader::OnExtensionSystemReady() { | 235 void ExtensionUserScriptLoader::OnExtensionSystemReady() { |
| 236 SetReady(true); | 236 SetReady(true); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace extensions | 239 } // namespace extensions |
| OLD | NEW |