| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/strings/string_util.h" |
| 16 #include "base/version.h" | 17 #include "base/version.h" |
| 17 #include "content/public/browser/browser_context.h" | 18 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/render_process_host.h" | 21 #include "content/public/browser/render_process_host.h" |
| 21 #include "extensions/browser/component_extension_resource_manager.h" | 22 #include "extensions/browser/component_extension_resource_manager.h" |
| 22 #include "extensions/browser/content_verifier.h" | 23 #include "extensions/browser/content_verifier.h" |
| 23 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/browser/extension_system.h" | 25 #include "extensions/browser/extension_system.h" |
| 25 #include "extensions/browser/extensions_browser_client.h" | 26 #include "extensions/browser/extensions_browser_client.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Localize the content. | 96 // Localize the content. |
| 96 if (localization_messages) { | 97 if (localization_messages) { |
| 97 std::string error; | 98 std::string error; |
| 98 MessageBundle::ReplaceMessagesWithExternalDictionary(*localization_messages, | 99 MessageBundle::ReplaceMessagesWithExternalDictionary(*localization_messages, |
| 99 &content, &error); | 100 &content, &error); |
| 100 if (!error.empty()) | 101 if (!error.empty()) |
| 101 LOG(WARNING) << "Failed to replace messages in script: " << error; | 102 LOG(WARNING) << "Failed to replace messages in script: " << error; |
| 102 } | 103 } |
| 103 | 104 |
| 104 // Remove BOM from the content. | 105 // Remove BOM from the content. |
| 105 std::string::size_type index = content.find(base::kUtf8ByteOrderMark); | 106 if (base::StartsWith(content, base::kUtf8ByteOrderMark, |
| 106 if (index == 0) | 107 base::CompareCase::SENSITIVE)) { |
| 107 script_file->set_content(content.substr(strlen(base::kUtf8ByteOrderMark))); | 108 script_file->set_content(content.substr(strlen(base::kUtf8ByteOrderMark))); |
| 108 else | 109 } else { |
| 109 script_file->set_content(content); | 110 script_file->set_content(content); |
| 111 } |
| 110 | 112 |
| 111 return true; | 113 return true; |
| 112 } | 114 } |
| 113 | 115 |
| 114 SubstitutionMap* GetLocalizationMessages( | 116 SubstitutionMap* GetLocalizationMessages( |
| 115 const ExtensionUserScriptLoader::HostsInfo& hosts_info, | 117 const ExtensionUserScriptLoader::HostsInfo& hosts_info, |
| 116 const HostID& host_id) { | 118 const HostID& host_id) { |
| 117 ExtensionUserScriptLoader::HostsInfo::const_iterator iter = | 119 ExtensionUserScriptLoader::HostsInfo::const_iterator iter = |
| 118 hosts_info.find(host_id); | 120 hosts_info.find(host_id); |
| 119 if (iter == hosts_info.end()) | 121 if (iter == hosts_info.end()) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 const Extension* extension, | 232 const Extension* extension, |
| 231 UnloadedExtensionInfo::Reason reason) { | 233 UnloadedExtensionInfo::Reason reason) { |
| 232 hosts_info_.erase(HostID(HostID::EXTENSIONS, extension->id())); | 234 hosts_info_.erase(HostID(HostID::EXTENSIONS, extension->id())); |
| 233 } | 235 } |
| 234 | 236 |
| 235 void ExtensionUserScriptLoader::OnExtensionSystemReady() { | 237 void ExtensionUserScriptLoader::OnExtensionSystemReady() { |
| 236 SetReady(true); | 238 SetReady(true); |
| 237 } | 239 } |
| 238 | 240 |
| 239 } // namespace extensions | 241 } // namespace extensions |
| OLD | NEW |