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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 using extensions::ExtensionsBrowserClient; | 32 using extensions::ExtensionsBrowserClient; |
33 | 33 |
34 namespace extensions { | 34 namespace extensions { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 typedef base::Callback<void(scoped_ptr<UserScriptList>, | 38 typedef base::Callback<void(scoped_ptr<UserScriptList>, |
39 scoped_ptr<base::SharedMemory>)> | 39 scoped_ptr<base::SharedMemory>)> |
40 LoadScriptsCallback; | 40 LoadScriptsCallback; |
41 | 41 |
42 void VerifyContent(scoped_refptr<ContentVerifier> verifier, | 42 void VerifyContent(scoped_refptr<ContentVerifier> verifier, |
Ken Rockot(use gerrit already)
2014/07/22 16:44:22
Could you DCHECK that you're on the IO thread here
asargent_no_longer_on_chrome
2014/07/22 20:27:28
Done.
| |
43 const std::string& extension_id, | 43 const std::string& extension_id, |
44 const base::FilePath& extension_root, | 44 const base::FilePath& extension_root, |
45 const base::FilePath& relative_path, | 45 const base::FilePath& relative_path, |
46 const std::string& content) { | 46 const std::string& content) { |
47 scoped_refptr<ContentVerifyJob> job( | 47 scoped_refptr<ContentVerifyJob> job( |
48 verifier->CreateJobFor(extension_id, extension_root, relative_path)); | 48 verifier->CreateJobFor(extension_id, extension_root, relative_path)); |
49 if (job.get()) { | 49 if (job.get()) { |
50 job->Start(); | 50 job->Start(); |
51 job->BytesRead(content.size(), content.data()); | 51 job->BytesRead(content.size(), content.data()); |
52 job->DoneReading(); | 52 job->DoneReading(); |
(...skipping 21 matching lines...) Expand all Loading... | |
74 << script_file->relative_path().value() << " from " | 74 << script_file->relative_path().value() << " from " |
75 << script_file->extension_root().value(); | 75 << script_file->extension_root().value(); |
76 return false; | 76 return false; |
77 } | 77 } |
78 } else { | 78 } else { |
79 if (!base::ReadFileToString(path, &content)) { | 79 if (!base::ReadFileToString(path, &content)) { |
80 LOG(WARNING) << "Failed to load user script file: " << path.value(); | 80 LOG(WARNING) << "Failed to load user script file: " << path.value(); |
81 return false; | 81 return false; |
82 } | 82 } |
83 if (verifier) { | 83 if (verifier) { |
84 VerifyContent(verifier, | 84 content::BrowserThread::PostTask(content::BrowserThread::IO, |
85 extension_id, | 85 FROM_HERE, |
86 script_file->extension_root(), | 86 base::Bind(&VerifyContent, |
87 script_file->relative_path(), | 87 verifier, |
88 content); | 88 extension_id, |
89 script_file->extension_root(), | |
90 script_file->relative_path(), | |
91 content)); | |
89 } | 92 } |
90 } | 93 } |
91 | 94 |
92 // Localize the content. | 95 // Localize the content. |
93 if (localization_messages) { | 96 if (localization_messages) { |
94 std::string error; | 97 std::string error; |
95 MessageBundle::ReplaceMessagesWithExternalDictionary( | 98 MessageBundle::ReplaceMessagesWithExternalDictionary( |
96 *localization_messages, &content, &error); | 99 *localization_messages, &content, &error); |
97 if (!error.empty()) { | 100 if (!error.empty()) { |
98 LOG(WARNING) << "Failed to replace messages in script: " << error; | 101 LOG(WARNING) << "Failed to replace messages in script: " << error; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) | 542 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) |
540 return; // This can legitimately fail if the renderer asserts at startup. | 543 return; // This can legitimately fail if the renderer asserts at startup. |
541 | 544 |
542 if (base::SharedMemory::IsHandleValid(handle_for_process)) { | 545 if (base::SharedMemory::IsHandleValid(handle_for_process)) { |
543 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process, | 546 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process, |
544 changed_extensions)); | 547 changed_extensions)); |
545 } | 548 } |
546 } | 549 } |
547 | 550 |
548 } // namespace extensions | 551 } // namespace extensions |
OLD | NEW |