OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_thread.h" | 13 #include "chrome/browser/chrome_thread.h" |
14 #include "chrome/browser/extensions/convert_user_script.h" | 14 #include "chrome/browser/extensions/convert_user_script.h" |
15 #include "chrome/browser/extensions/extension_file_util.h" | 15 #include "chrome/browser/extensions/extension_file_util.h" |
16 #include "chrome/common/extensions/extension_error_reporter.h" | 16 #include "chrome/common/extensions/extension_error_reporter.h" |
17 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
18 #include "chrome/common/notification_type.h" | 18 #include "chrome/common/notification_type.h" |
19 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "webkit/glue/image_decoder.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 // Helper function to delete files. This is used to avoid ugly casts which | 24 // Helper function to delete files. This is used to avoid ugly casts which |
24 // would be necessary with PostMessage since file_util::Delete is overloaded. | 25 // would be necessary with PostMessage since file_util::Delete is overloaded. |
25 static void DeleteFileHelper(const FilePath& path, bool recursive) { | 26 static void DeleteFileHelper(const FilePath& path, bool recursive) { |
26 file_util::Delete(path, recursive); | 27 file_util::Delete(path, recursive); |
27 } | 28 } |
28 } | 29 } |
29 | 30 |
30 void CrxInstaller::Start(const FilePath& crx_path, | 31 void CrxInstaller::Start(const FilePath& crx_path, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // TODO(aa): Also support expected version? | 143 // TODO(aa): Also support expected version? |
143 if (!expected_id_.empty() && expected_id_ != extension->id()) { | 144 if (!expected_id_.empty() && expected_id_ != extension->id()) { |
144 ReportFailureFromFileThread(StringPrintf( | 145 ReportFailureFromFileThread(StringPrintf( |
145 "ID in new extension manifest (%s) does not match expected id (%s)", | 146 "ID in new extension manifest (%s) does not match expected id (%s)", |
146 extension->id().c_str(), | 147 extension->id().c_str(), |
147 expected_id_.c_str())); | 148 expected_id_.c_str())); |
148 return; | 149 return; |
149 } | 150 } |
150 | 151 |
151 if (client_.get()) { | 152 if (client_.get()) { |
152 Extension::DecodeIcon(extension_.get(), Extension::EXTENSION_ICON_LARGE, | 153 FilePath icon_path = |
153 &install_icon_); | 154 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE).GetFilePath(); |
| 155 DecodeInstallIcon(icon_path, &install_icon_); |
154 } | 156 } |
155 ChromeThread::PostTask( | 157 ChromeThread::PostTask( |
156 ChromeThread::UI, FROM_HERE, | 158 ChromeThread::UI, FROM_HERE, |
157 NewRunnableMethod(this, &CrxInstaller::ConfirmInstall)); | 159 NewRunnableMethod(this, &CrxInstaller::ConfirmInstall)); |
158 } | 160 } |
159 | 161 |
| 162 // static |
| 163 void CrxInstaller::DecodeInstallIcon(const FilePath& large_icon_path, |
| 164 scoped_ptr<SkBitmap>* result) { |
| 165 if (large_icon_path.empty()) |
| 166 return; |
| 167 |
| 168 std::string file_contents; |
| 169 if (!file_util::ReadFileToString(large_icon_path, &file_contents)) { |
| 170 LOG(ERROR) << "Could not read icon file: " |
| 171 << WideToUTF8(large_icon_path.ToWStringHack()); |
| 172 return; |
| 173 } |
| 174 |
| 175 // Decode the image using WebKit's image decoder. |
| 176 const unsigned char* data = |
| 177 reinterpret_cast<const unsigned char*>(file_contents.data()); |
| 178 webkit_glue::ImageDecoder decoder; |
| 179 scoped_ptr<SkBitmap> decoded(new SkBitmap()); |
| 180 *decoded = decoder.Decode(data, file_contents.length()); |
| 181 if (decoded->empty()) { |
| 182 LOG(ERROR) << "Could not decode icon file: " |
| 183 << WideToUTF8(large_icon_path.ToWStringHack()); |
| 184 return; |
| 185 } |
| 186 |
| 187 if (decoded->width() != 128 || decoded->height() != 128) { |
| 188 LOG(ERROR) << "Icon file has unexpected size: " |
| 189 << IntToString(decoded->width()) << "x" |
| 190 << IntToString(decoded->height()); |
| 191 return; |
| 192 } |
| 193 |
| 194 result->swap(decoded); |
| 195 } |
| 196 |
160 void CrxInstaller::ConfirmInstall() { | 197 void CrxInstaller::ConfirmInstall() { |
161 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 198 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
162 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) { | 199 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) { |
163 LOG(INFO) << "This extension: " << extension_->id() | 200 LOG(INFO) << "This extension: " << extension_->id() |
164 << " is blacklisted. Install failed."; | 201 << " is blacklisted. Install failed."; |
165 ReportFailureFromUIThread("This extension is blacklisted."); | 202 ReportFailureFromUIThread("This extension is blacklisted."); |
166 return; | 203 return; |
167 } | 204 } |
168 | 205 |
169 current_version_ = | 206 current_version_ = |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 client_->OnInstallSuccess(extension_.get()); | 340 client_->OnInstallSuccess(extension_.get()); |
304 | 341 |
305 // Tell the frontend about the installation and hand off ownership of | 342 // Tell the frontend about the installation and hand off ownership of |
306 // extension_ to it. | 343 // extension_ to it. |
307 frontend_->OnExtensionInstalled(extension_.release(), | 344 frontend_->OnExtensionInstalled(extension_.release(), |
308 allow_privilege_increase_); | 345 allow_privilege_increase_); |
309 | 346 |
310 // We're done. We don't post any more tasks to ourselves so we are deleted | 347 // We're done. We don't post any more tasks to ourselves so we are deleted |
311 // soon. | 348 // soon. |
312 } | 349 } |
OLD | NEW |