OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/user_script_master.h" | 5 #include "chrome/browser/extensions/user_script_master.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/version.h" | 18 #include "base/version.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
21 #include "chrome/browser/extensions/image_loader.h" | |
21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 24 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
24 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
25 #include "chrome/common/extensions/extension_file_util.h" | 26 #include "chrome/common/extensions/extension_file_util.h" |
26 #include "chrome/common/extensions/extension_set.h" | 27 #include "chrome/common/extensions/extension_set.h" |
27 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | 28 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" |
28 #include "chrome/common/extensions/message_bundle.h" | 29 #include "chrome/common/extensions/message_bundle.h" |
29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
31 #include "extensions/common/extension_resource.h" | 32 #include "extensions/common/extension_resource.h" |
33 #include "ui/base/resource/resource_bundle.h" | |
32 | 34 |
33 using content::BrowserThread; | 35 using content::BrowserThread; |
34 | 36 |
35 namespace extensions { | 37 namespace extensions { |
36 | 38 |
37 // Helper function to parse greasesmonkey headers | 39 // Helper function to parse greasesmonkey headers |
38 static bool GetDeclarationValue(const base::StringPiece& line, | 40 static bool GetDeclarationValue(const base::StringPiece& line, |
39 const base::StringPiece& prefix, | 41 const base::StringPiece& prefix, |
40 std::string* value) { | 42 std::string* value) { |
41 base::StringPiece::size_type index = line.find(prefix); | 43 base::StringPiece::size_type index = line.find(prefix); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 Release(); | 183 Release(); |
182 } | 184 } |
183 | 185 |
184 static bool LoadScriptContent(UserScript::File* script_file, | 186 static bool LoadScriptContent(UserScript::File* script_file, |
185 const SubstitutionMap* localization_messages) { | 187 const SubstitutionMap* localization_messages) { |
186 std::string content; | 188 std::string content; |
187 const base::FilePath& path = ExtensionResource::GetFilePath( | 189 const base::FilePath& path = ExtensionResource::GetFilePath( |
188 script_file->extension_root(), script_file->relative_path(), | 190 script_file->extension_root(), script_file->relative_path(), |
189 ExtensionResource::SYMLINKS_MUST_RESOLVE_WITHIN_ROOT); | 191 ExtensionResource::SYMLINKS_MUST_RESOLVE_WITHIN_ROOT); |
190 if (path.empty()) { | 192 if (path.empty()) { |
191 LOG(WARNING) << "Failed to get file path to " | 193 int resource_id; |
192 << script_file->relative_path().value() << " from " | 194 if (extensions::ImageLoader::IsComponentExtensionResource( |
Matt Perry
2013/04/10 18:52:09
I don't understand this change. IsComponentExtensi
| |
193 << script_file->extension_root().value(); | 195 script_file->extension_root(), script_file->relative_path(), |
194 return false; | 196 &resource_id)) { |
195 } | 197 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
196 if (!file_util::ReadFileToString(path, &content)) { | 198 content = rb.GetRawDataResource(resource_id).as_string(); |
197 LOG(WARNING) << "Failed to load user script file: " << path.value(); | 199 } else { |
198 return false; | 200 LOG(WARNING) << "Failed to get file path to " |
201 << script_file->relative_path().value() << " from " | |
202 << script_file->extension_root().value(); | |
203 return false; | |
204 } | |
205 } else { | |
206 if (!file_util::ReadFileToString(path, &content)) { | |
207 LOG(WARNING) << "Failed to load user script file: " << path.value(); | |
208 return false; | |
209 } | |
199 } | 210 } |
200 | 211 |
201 // Localize the content. | 212 // Localize the content. |
202 if (localization_messages) { | 213 if (localization_messages) { |
203 std::string error; | 214 std::string error; |
204 MessageBundle::ReplaceMessagesWithExternalDictionary( | 215 MessageBundle::ReplaceMessagesWithExternalDictionary( |
205 *localization_messages, &content, &error); | 216 *localization_messages, &content, &error); |
206 if (!error.empty()) { | 217 if (!error.empty()) { |
207 LOG(WARNING) << "Failed to replace messages in script: " << error; | 218 LOG(WARNING) << "Failed to replace messages in script: " << error; |
208 } | 219 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 | 447 |
437 base::SharedMemoryHandle handle_for_process; | 448 base::SharedMemoryHandle handle_for_process; |
438 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) | 449 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) |
439 return; // This can legitimately fail if the renderer asserts at startup. | 450 return; // This can legitimately fail if the renderer asserts at startup. |
440 | 451 |
441 if (base::SharedMemory::IsHandleValid(handle_for_process)) | 452 if (base::SharedMemory::IsHandleValid(handle_for_process)) |
442 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); | 453 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); |
443 } | 454 } |
444 | 455 |
445 } // namespace extensions | 456 } // namespace extensions |
OLD | NEW |