| 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/web_ui_user_script_loader.h" | 5 #include "extensions/browser/web_ui_user_script_loader.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 fetchers_.push_back(std::move(fetcher)); | 121 fetchers_.push_back(std::move(fetcher)); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete( | 126 void WebUIUserScriptLoader::OnSingleWebUIURLFetchComplete( |
| 127 extensions::UserScript::File* script_file, | 127 extensions::UserScript::File* script_file, |
| 128 bool success, | 128 bool success, |
| 129 const std::string& data) { | 129 const std::string& data) { |
| 130 if (success) { | 130 if (success) { |
| 131 // Remove BOM from the content. | 131 // Remove BOM from |data|. |
| 132 std::string::size_type index = data.find(base::kUtf8ByteOrderMark); | 132 if (base::StartsWith(data, base::kUtf8ByteOrderMark, |
| 133 if (index == 0) | 133 base::CompareCase::SENSITIVE)) { |
| 134 script_file->set_content(data.substr(strlen(base::kUtf8ByteOrderMark))); | 134 script_file->set_content(data.substr(strlen(base::kUtf8ByteOrderMark))); |
| 135 else | 135 } else { |
| 136 script_file->set_content(data); | 136 script_file->set_content(data); |
| 137 } |
| 137 } | 138 } |
| 138 | 139 |
| 139 ++complete_fetchers_; | 140 ++complete_fetchers_; |
| 140 if (complete_fetchers_ == fetchers_.size()) { | 141 if (complete_fetchers_ == fetchers_.size()) { |
| 141 complete_fetchers_ = 0; | 142 complete_fetchers_ = 0; |
| 142 OnWebUIURLFetchComplete(); | 143 OnWebUIURLFetchComplete(); |
| 143 fetchers_.clear(); | 144 fetchers_.clear(); |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 147 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { | 148 void WebUIUserScriptLoader::OnWebUIURLFetchComplete() { |
| 148 content::BrowserThread::PostTask( | 149 content::BrowserThread::PostTask( |
| 149 content::BrowserThread::FILE, FROM_HERE, | 150 content::BrowserThread::FILE, FROM_HERE, |
| 150 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), | 151 base::Bind(&SerializeOnFileThread, base::Passed(&user_scripts_cache_), |
| 151 scripts_loaded_callback_)); | 152 scripts_loaded_callback_)); |
| 152 scripts_loaded_callback_.Reset(); | 153 scripts_loaded_callback_.Reset(); |
| 153 } | 154 } |
| OLD | NEW |