| 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 26 matching lines...) Expand all Loading... |
| 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, |
| 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 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 47 scoped_refptr<ContentVerifyJob> job( | 48 scoped_refptr<ContentVerifyJob> job( |
| 48 verifier->CreateJobFor(extension_id, extension_root, relative_path)); | 49 verifier->CreateJobFor(extension_id, extension_root, relative_path)); |
| 49 if (job.get()) { | 50 if (job.get()) { |
| 50 job->Start(); | 51 job->Start(); |
| 51 job->BytesRead(content.size(), content.data()); | 52 job->BytesRead(content.size(), content.data()); |
| 52 job->DoneReading(); | 53 job->DoneReading(); |
| 53 } | 54 } |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool LoadScriptContent(const std::string& extension_id, | 57 bool LoadScriptContent(const std::string& extension_id, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 74 << script_file->relative_path().value() << " from " | 75 << script_file->relative_path().value() << " from " |
| 75 << script_file->extension_root().value(); | 76 << script_file->extension_root().value(); |
| 76 return false; | 77 return false; |
| 77 } | 78 } |
| 78 } else { | 79 } else { |
| 79 if (!base::ReadFileToString(path, &content)) { | 80 if (!base::ReadFileToString(path, &content)) { |
| 80 LOG(WARNING) << "Failed to load user script file: " << path.value(); | 81 LOG(WARNING) << "Failed to load user script file: " << path.value(); |
| 81 return false; | 82 return false; |
| 82 } | 83 } |
| 83 if (verifier) { | 84 if (verifier) { |
| 84 VerifyContent(verifier, | 85 content::BrowserThread::PostTask(content::BrowserThread::IO, |
| 85 extension_id, | 86 FROM_HERE, |
| 86 script_file->extension_root(), | 87 base::Bind(&VerifyContent, |
| 87 script_file->relative_path(), | 88 verifier, |
| 88 content); | 89 extension_id, |
| 90 script_file->extension_root(), |
| 91 script_file->relative_path(), |
| 92 content)); |
| 89 } | 93 } |
| 90 } | 94 } |
| 91 | 95 |
| 92 // Localize the content. | 96 // Localize the content. |
| 93 if (localization_messages) { | 97 if (localization_messages) { |
| 94 std::string error; | 98 std::string error; |
| 95 MessageBundle::ReplaceMessagesWithExternalDictionary( | 99 MessageBundle::ReplaceMessagesWithExternalDictionary( |
| 96 *localization_messages, &content, &error); | 100 *localization_messages, &content, &error); |
| 97 if (!error.empty()) { | 101 if (!error.empty()) { |
| 98 LOG(WARNING) << "Failed to replace messages in script: " << error; | 102 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)) | 543 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) |
| 540 return; // This can legitimately fail if the renderer asserts at startup. | 544 return; // This can legitimately fail if the renderer asserts at startup. |
| 541 | 545 |
| 542 if (base::SharedMemory::IsHandleValid(handle_for_process)) { | 546 if (base::SharedMemory::IsHandleValid(handle_for_process)) { |
| 543 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process, | 547 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process, |
| 544 changed_extensions)); | 548 changed_extensions)); |
| 545 } | 549 } |
| 546 } | 550 } |
| 547 | 551 |
| 548 } // namespace extensions | 552 } // namespace extensions |
| OLD | NEW |