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

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

Issue 557953005: Allow the user to "repair" a corrupted extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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
OLDNEW
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/webstore_standalone_installer.h" 5 #include "chrome/browser/extensions/webstore_standalone_installer.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "base/version.h" 8 #include "base/version.h"
9 #include "chrome/browser/extensions/crx_installer.h" 9 #include "chrome/browser/extensions/crx_installer.h"
10 #include "chrome/browser/extensions/extension_install_prompt.h" 10 #include "chrome/browser/extensions/extension_install_prompt.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 webstore_data_fetcher_->Start(); 79 webstore_data_fetcher_->Start();
80 } 80 }
81 81
82 // 82 //
83 // Private interface implementation. 83 // Private interface implementation.
84 // 84 //
85 85
86 WebstoreStandaloneInstaller::~WebstoreStandaloneInstaller() { 86 WebstoreStandaloneInstaller::~WebstoreStandaloneInstaller() {
87 } 87 }
88 88
89 void WebstoreStandaloneInstaller::RunCallback(bool success,
90 const std::string& error,
91 webstore_install::Result result) {
92 callback_.Run(success, error, result);
93 }
94
89 void WebstoreStandaloneInstaller::AbortInstall() { 95 void WebstoreStandaloneInstaller::AbortInstall() {
90 callback_.Reset(); 96 callback_.Reset();
91 // Abort any in-progress fetches. 97 // Abort any in-progress fetches.
92 if (webstore_data_fetcher_) { 98 if (webstore_data_fetcher_) {
93 webstore_data_fetcher_.reset(); 99 webstore_data_fetcher_.reset();
94 scoped_active_install_.reset(); 100 scoped_active_install_.reset();
95 Release(); // Matches the AddRef in BeginInstall. 101 Release(); // Matches the AddRef in BeginInstall.
96 } 102 }
97 } 103 }
98 104
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 profile_, 187 profile_,
182 id_, 188 id_,
183 scoped_ptr<base::DictionaryValue>(manifest_.get()->DeepCopy()), 189 scoped_ptr<base::DictionaryValue>(manifest_.get()->DeepCopy()),
184 true)); 190 true));
185 approval->skip_post_install_ui = !ShouldShowPostInstallUI(); 191 approval->skip_post_install_ui = !ShouldShowPostInstallUI();
186 approval->use_app_installed_bubble = ShouldShowAppInstalledBubble(); 192 approval->use_app_installed_bubble = ShouldShowAppInstalledBubble();
187 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); 193 approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_);
188 return approval.Pass(); 194 return approval.Pass();
189 } 195 }
190 196
197 void WebstoreStandaloneInstaller::InstallUIProceed() {
198 if (!CheckRequestorAlive()) {
199 CompleteInstall(webstore_install::ABORTED, std::string());
200 return;
201 }
202
203 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval();
204
205 ExtensionService* extension_service =
206 ExtensionSystem::Get(profile_)->extension_service();
207 const Extension* installed_extension =
208 extension_service->GetExtensionById(id_, true /* include disabled */);
209 if (installed_extension) {
210 std::string install_message;
211 webstore_install::Result install_result = webstore_install::SUCCESS;
212 bool done = true;
213
214 if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) {
215 // Don't install a blacklisted extension.
216 install_result = webstore_install::BLACKLISTED;
217 install_message = kExtensionIsBlacklisted;
218 } else if (util::IsEphemeralApp(installed_extension->id(), profile_) &&
219 !approval->is_ephemeral) {
220 // If the target extension has already been installed ephemerally and is
221 // up to date, it can be promoted to a regular installed extension and
222 // downloading from the Web Store is not necessary.
223 scoped_refptr<const Extension> extension_to_install =
224 GetLocalizedExtensionForDisplay();
225 if (!extension_to_install.get()) {
226 CompleteInstall(webstore_install::INVALID_MANIFEST,
227 kInvalidManifestError);
228 return;
229 }
230
231 if (installed_extension->version()->CompareTo(
232 *extension_to_install->version()) < 0) {
233 // If the existing extension is out of date, proceed with the install
234 // to update the extension.
235 done = false;
236 } else {
237 install_ui::ShowPostInstallUIForApproval(
238 profile_, *approval, installed_extension);
239 extension_service->PromoteEphemeralApp(installed_extension, false);
240 }
241 } else if (!extension_service->IsExtensionEnabled(id_)) {
242 // If the extension is installed but disabled, and not blacklisted,
243 // enable it.
244 extension_service->EnableExtension(id_);
245 } // else extension is installed and enabled; no work to be done.
246
247 if (done) {
248 CompleteInstall(install_result, install_message);
249 return;
250 }
251 }
252
253 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller(
254 profile_,
255 this,
256 GetWebContents(),
257 id_,
258 approval.Pass(),
259 install_source_);
260 installer->Start();
261 }
262
263 void WebstoreStandaloneInstaller::InstallUIAbort(bool user_initiated) {
264 CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError);
265 }
266
191 void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() { 267 void WebstoreStandaloneInstaller::OnWebstoreRequestFailure() {
192 OnWebStoreDataFetcherDone(); 268 OnWebStoreDataFetcherDone();
193 CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR, 269 CompleteInstall(webstore_install::WEBSTORE_REQUEST_ERROR,
194 kWebstoreRequestError); 270 kWebstoreRequestError);
195 } 271 }
196 272
197 void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess( 273 void WebstoreStandaloneInstaller::OnWebstoreResponseParseSuccess(
198 scoped_ptr<base::DictionaryValue> webstore_data) { 274 scoped_ptr<base::DictionaryValue> webstore_data) {
199 OnWebStoreDataFetcherDone(); 275 OnWebStoreDataFetcherDone();
200 276
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 case WebstoreInstallHelper::Delegate::ICON_ERROR: 392 case WebstoreInstallHelper::Delegate::ICON_ERROR:
317 install_result = webstore_install::ICON_ERROR; 393 install_result = webstore_install::ICON_ERROR;
318 break; 394 break;
319 default: 395 default:
320 break; 396 break;
321 } 397 }
322 398
323 CompleteInstall(install_result, error_message); 399 CompleteInstall(install_result, error_message);
324 } 400 }
325 401
326 void WebstoreStandaloneInstaller::InstallUIProceed() {
327 if (!CheckRequestorAlive()) {
328 CompleteInstall(webstore_install::ABORTED, std::string());
329 return;
330 }
331
332 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval();
333
334 ExtensionService* extension_service =
335 ExtensionSystem::Get(profile_)->extension_service();
336 const Extension* installed_extension =
337 extension_service->GetExtensionById(id_, true /* include disabled */);
338 if (installed_extension) {
339 std::string install_message;
340 webstore_install::Result install_result = webstore_install::SUCCESS;
341 bool done = true;
342
343 if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) {
344 // Don't install a blacklisted extension.
345 install_result = webstore_install::BLACKLISTED;
346 install_message = kExtensionIsBlacklisted;
347 } else if (util::IsEphemeralApp(installed_extension->id(), profile_) &&
348 !approval->is_ephemeral) {
349 // If the target extension has already been installed ephemerally and is
350 // up to date, it can be promoted to a regular installed extension and
351 // downloading from the Web Store is not necessary.
352 scoped_refptr<const Extension> extension_to_install =
353 GetLocalizedExtensionForDisplay();
354 if (!extension_to_install.get()) {
355 CompleteInstall(webstore_install::INVALID_MANIFEST,
356 kInvalidManifestError);
357 return;
358 }
359
360 if (installed_extension->version()->CompareTo(
361 *extension_to_install->version()) < 0) {
362 // If the existing extension is out of date, proceed with the install
363 // to update the extension.
364 done = false;
365 } else {
366 install_ui::ShowPostInstallUIForApproval(
367 profile_, *approval, installed_extension);
368 extension_service->PromoteEphemeralApp(installed_extension, false);
369 }
370 } else if (!extension_service->IsExtensionEnabled(id_)) {
371 // If the extension is installed but disabled, and not blacklisted,
372 // enable it.
373 extension_service->EnableExtension(id_);
374 } // else extension is installed and enabled; no work to be done.
375
376 if (done) {
377 CompleteInstall(install_result, install_message);
378 return;
379 }
380 }
381
382 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller(
383 profile_,
384 this,
385 GetWebContents(),
386 id_,
387 approval.Pass(),
388 install_source_);
389 installer->Start();
390 }
391
392 void WebstoreStandaloneInstaller::InstallUIAbort(bool user_initiated) {
393 CompleteInstall(webstore_install::USER_CANCELLED, kUserCancelledError);
394 }
395
396 void WebstoreStandaloneInstaller::OnExtensionInstallSuccess( 402 void WebstoreStandaloneInstaller::OnExtensionInstallSuccess(
397 const std::string& id) { 403 const std::string& id) {
398 CHECK_EQ(id_, id); 404 CHECK_EQ(id_, id);
399 CompleteInstall(webstore_install::SUCCESS, std::string()); 405 CompleteInstall(webstore_install::SUCCESS, std::string());
400 } 406 }
401 407
402 void WebstoreStandaloneInstaller::OnExtensionInstallFailure( 408 void WebstoreStandaloneInstaller::OnExtensionInstallFailure(
403 const std::string& id, 409 const std::string& id,
404 const std::string& error, 410 const std::string& error,
405 WebstoreInstaller::FailureReason reason) { 411 WebstoreInstaller::FailureReason reason) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() { 443 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() {
438 // An instance of this class is passed in as a delegate for the 444 // An instance of this class is passed in as a delegate for the
439 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and 445 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and
440 // therefore needs to remain alive until they are done. Clear the webstore 446 // therefore needs to remain alive until they are done. Clear the webstore
441 // data fetcher to avoid calling Release in AbortInstall while any of these 447 // data fetcher to avoid calling Release in AbortInstall while any of these
442 // operations are in progress. 448 // operations are in progress.
443 webstore_data_fetcher_.reset(); 449 webstore_data_fetcher_.reset();
444 } 450 }
445 451
446 } // namespace extensions 452 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698