Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/extensions/crx_installer.cc

Issue 501136: Merge 34812 - Add the rightclick context menu for Browser actions and Page... (Closed) Base URL: svn://chrome-svn/chrome/branches/249/src/
Patch Set: Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
22 21
23 namespace { 22 namespace {
24 // Helper function to delete files. This is used to avoid ugly casts which 23 // Helper function to delete files. This is used to avoid ugly casts which
25 // would be necessary with PostMessage since file_util::Delete is overloaded. 24 // would be necessary with PostMessage since file_util::Delete is overloaded.
26 static void DeleteFileHelper(const FilePath& path, bool recursive) { 25 static void DeleteFileHelper(const FilePath& path, bool recursive) {
27 file_util::Delete(path, recursive); 26 file_util::Delete(path, recursive);
28 } 27 }
29 } 28 }
30 29
31 void CrxInstaller::Start(const FilePath& crx_path, 30 void CrxInstaller::Start(const FilePath& crx_path,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // TODO(aa): Also support expected version? 142 // TODO(aa): Also support expected version?
144 if (!expected_id_.empty() && expected_id_ != extension->id()) { 143 if (!expected_id_.empty() && expected_id_ != extension->id()) {
145 ReportFailureFromFileThread(StringPrintf( 144 ReportFailureFromFileThread(StringPrintf(
146 "ID in new extension manifest (%s) does not match expected id (%s)", 145 "ID in new extension manifest (%s) does not match expected id (%s)",
147 extension->id().c_str(), 146 extension->id().c_str(),
148 expected_id_.c_str())); 147 expected_id_.c_str()));
149 return; 148 return;
150 } 149 }
151 150
152 if (client_.get()) { 151 if (client_.get()) {
153 FilePath icon_path = 152 Extension::DecodeIcon(extension_.get(), Extension::EXTENSION_ICON_LARGE,
154 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE).GetFilePath(); 153 &install_icon_);
155 DecodeInstallIcon(icon_path, &install_icon_);
156 } 154 }
157 ChromeThread::PostTask( 155 ChromeThread::PostTask(
158 ChromeThread::UI, FROM_HERE, 156 ChromeThread::UI, FROM_HERE,
159 NewRunnableMethod(this, &CrxInstaller::ConfirmInstall)); 157 NewRunnableMethod(this, &CrxInstaller::ConfirmInstall));
160 } 158 }
161 159
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
197 void CrxInstaller::ConfirmInstall() { 160 void CrxInstaller::ConfirmInstall() {
198 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 161 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
199 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) { 162 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) {
200 LOG(INFO) << "This extension: " << extension_->id() 163 LOG(INFO) << "This extension: " << extension_->id()
201 << " is blacklisted. Install failed."; 164 << " is blacklisted. Install failed.";
202 ReportFailureFromUIThread("This extension is blacklisted."); 165 ReportFailureFromUIThread("This extension is blacklisted.");
203 return; 166 return;
204 } 167 }
205 168
206 current_version_ = 169 current_version_ =
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 client_->OnInstallSuccess(extension_.get()); 303 client_->OnInstallSuccess(extension_.get());
341 304
342 // Tell the frontend about the installation and hand off ownership of 305 // Tell the frontend about the installation and hand off ownership of
343 // extension_ to it. 306 // extension_ to it.
344 frontend_->OnExtensionInstalled(extension_.release(), 307 frontend_->OnExtensionInstalled(extension_.release(),
345 allow_privilege_increase_); 308 allow_privilege_increase_);
346 309
347 // We're done. We don't post any more tasks to ourselves so we are deleted 310 // We're done. We don't post any more tasks to ourselves so we are deleted
348 // soon. 311 // soon.
349 } 312 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.h ('k') | chrome/browser/extensions/extension_action_context_menu_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698