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

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

Issue 486022: Implement context menu for page and browser actions (Closed) Base URL: svn://chrome-svn/chrome/trunk/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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // TODO(aa): Also support expected version? 147 // TODO(aa): Also support expected version?
149 if (!expected_id_.empty() && expected_id_ != extension->id()) { 148 if (!expected_id_.empty() && expected_id_ != extension->id()) {
150 ReportFailureFromFileThread(StringPrintf( 149 ReportFailureFromFileThread(StringPrintf(
151 "ID in new extension manifest (%s) does not match expected id (%s)", 150 "ID in new extension manifest (%s) does not match expected id (%s)",
152 extension->id().c_str(), 151 extension->id().c_str(),
153 expected_id_.c_str())); 152 expected_id_.c_str()));
154 return; 153 return;
155 } 154 }
156 155
157 if (client_.get()) { 156 if (client_.get()) {
158 FilePath icon_path = 157 Extension::DecodeIcon(extension_.get(), Extension::EXTENSION_ICON_LARGE,
159 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE).GetFilePath(); 158 &install_icon_);
160 DecodeInstallIcon(icon_path, &install_icon_);
161 } 159 }
162 ChromeThread::PostTask( 160 ChromeThread::PostTask(
163 ChromeThread::UI, FROM_HERE, 161 ChromeThread::UI, FROM_HERE,
164 NewRunnableMethod(this, &CrxInstaller::ConfirmInstall)); 162 NewRunnableMethod(this, &CrxInstaller::ConfirmInstall));
165 } 163 }
166 164
167 // static
168 void CrxInstaller::DecodeInstallIcon(const FilePath& large_icon_path,
169 scoped_ptr<SkBitmap>* result) {
170 if (large_icon_path.empty())
171 return;
172
173 std::string file_contents;
174 if (!file_util::ReadFileToString(large_icon_path, &file_contents)) {
175 LOG(ERROR) << "Could not read icon file: "
176 << WideToUTF8(large_icon_path.ToWStringHack());
177 return;
178 }
179
180 // Decode the image using WebKit's image decoder.
181 const unsigned char* data =
182 reinterpret_cast<const unsigned char*>(file_contents.data());
183 webkit_glue::ImageDecoder decoder;
184 scoped_ptr<SkBitmap> decoded(new SkBitmap());
185 *decoded = decoder.Decode(data, file_contents.length());
186 if (decoded->empty()) {
187 LOG(ERROR) << "Could not decode icon file: "
188 << WideToUTF8(large_icon_path.ToWStringHack());
189 return;
190 }
191
192 if (decoded->width() != 128 || decoded->height() != 128) {
193 LOG(ERROR) << "Icon file has unexpected size: "
194 << IntToString(decoded->width()) << "x"
195 << IntToString(decoded->height());
196 return;
197 }
198
199 result->swap(decoded);
200 }
201
202 void CrxInstaller::ConfirmInstall() { 165 void CrxInstaller::ConfirmInstall() {
203 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 166 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
204 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) { 167 if (frontend_->extension_prefs()->IsExtensionBlacklisted(extension_->id())) {
205 LOG(INFO) << "This extension: " << extension_->id() 168 LOG(INFO) << "This extension: " << extension_->id()
206 << " is blacklisted. Install failed."; 169 << " is blacklisted. Install failed.";
207 ReportFailureFromUIThread("This extension is blacklisted."); 170 ReportFailureFromUIThread("This extension is blacklisted.");
208 return; 171 return;
209 } 172 }
210 173
211 current_version_ = 174 current_version_ =
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 client_->OnInstallSuccess(extension_.get()); 308 client_->OnInstallSuccess(extension_.get());
346 309
347 // Tell the frontend about the installation and hand off ownership of 310 // Tell the frontend about the installation and hand off ownership of
348 // extension_ to it. 311 // extension_ to it.
349 frontend_->OnExtensionInstalled(extension_.release(), 312 frontend_->OnExtensionInstalled(extension_.release(),
350 allow_privilege_increase_); 313 allow_privilege_increase_);
351 314
352 // We're done. We don't post any more tasks to ourselves so we are deleted 315 // We're done. We don't post any more tasks to ourselves so we are deleted
353 // soon. 316 // soon.
354 } 317 }
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