| OLD | NEW |
| 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/api/webstore_private/webstore_private_api.h" | 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
| 25 #include "chrome/browser/ui/app_list/app_list_service.h" | 25 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 26 #include "chrome/browser/ui/app_list/app_list_util.h" | 26 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 27 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "components/crx_file/id_util.h" | 29 #include "components/crx_file/id_util.h" |
| 30 #include "components/signin/core/browser/signin_manager.h" | 30 #include "components/signin/core/browser/signin_manager.h" |
| 31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 32 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" |
| 33 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
| 34 #include "extensions/browser/extension_util.h" | |
| 35 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
| 36 #include "net/base/load_flags.h" | 35 #include "net/base/load_flags.h" |
| 37 #include "net/url_request/url_request.h" | 36 #include "net/url_request/url_request.h" |
| 38 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 39 | 38 |
| 40 namespace extensions { | 39 namespace extensions { |
| 41 | 40 |
| 42 namespace BeginInstallWithManifest3 = | 41 namespace BeginInstallWithManifest3 = |
| 43 api::webstore_private::BeginInstallWithManifest3; | 42 api::webstore_private::BeginInstallWithManifest3; |
| 44 namespace CompleteInstall = api::webstore_private::CompleteInstall; | 43 namespace CompleteInstall = api::webstore_private::CompleteInstall; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 icon_url = source_url().Resolve(*details().icon_url); | 199 icon_url = source_url().Resolve(*details().icon_url); |
| 201 if (!icon_url.is_valid()) { | 200 if (!icon_url.is_valid()) { |
| 202 return RespondNow(BuildResponse( | 201 return RespondNow(BuildResponse( |
| 203 api::webstore_private::RESULT_INVALID_ICON_URL, | 202 api::webstore_private::RESULT_INVALID_ICON_URL, |
| 204 kInvalidIconUrlError)); | 203 kInvalidIconUrlError)); |
| 205 } | 204 } |
| 206 } | 205 } |
| 207 | 206 |
| 208 InstallTracker* tracker = InstallTracker::Get(browser_context()); | 207 InstallTracker* tracker = InstallTracker::Get(browser_context()); |
| 209 DCHECK(tracker); | 208 DCHECK(tracker); |
| 210 if (util::IsExtensionInstalledPermanently(details().id, browser_context()) || | 209 bool is_installed = |
| 211 tracker->GetActiveInstall(details().id)) { | 210 extensions::ExtensionRegistry::Get(browser_context())->GetExtensionById( |
| 211 details().id, extensions::ExtensionRegistry::EVERYTHING) != nullptr; |
| 212 if (is_installed || tracker->GetActiveInstall(details().id)) { |
| 212 return RespondNow(BuildResponse( | 213 return RespondNow(BuildResponse( |
| 213 api::webstore_private::RESULT_ALREADY_INSTALLED, | 214 api::webstore_private::RESULT_ALREADY_INSTALLED, |
| 214 kAlreadyInstalledError)); | 215 kAlreadyInstalledError)); |
| 215 } | 216 } |
| 216 ActiveInstallData install_data(details().id); | 217 ActiveInstallData install_data(details().id); |
| 217 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); | 218 scoped_active_install_.reset(new ScopedActiveInstall(tracker, install_data)); |
| 218 | 219 |
| 219 net::URLRequestContextGetter* context_getter = nullptr; | 220 net::URLRequestContextGetter* context_getter = nullptr; |
| 220 if (!icon_url.is_empty()) | 221 if (!icon_url.is_empty()) |
| 221 context_getter = browser_context()->GetRequestContext(); | 222 context_getter = browser_context()->GetRequestContext(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 420 |
| 420 if (IsAppLauncherEnabled() && approval_->manifest->is_app()) { | 421 if (IsAppLauncherEnabled() && approval_->manifest->is_app()) { |
| 421 // Show the app list to show download is progressing. Don't show the app | 422 // Show the app list to show download is progressing. Don't show the app |
| 422 // list on first app install so users can be trained to open it themselves. | 423 // list on first app install so users can be trained to open it themselves. |
| 423 app_list_service->ShowForAppInstall( | 424 app_list_service->ShowForAppInstall( |
| 424 chrome_details_.GetProfile(), | 425 chrome_details_.GetProfile(), |
| 425 params->expected_id, | 426 params->expected_id, |
| 426 approval_->enable_launcher); | 427 approval_->enable_launcher); |
| 427 } | 428 } |
| 428 | 429 |
| 429 // If the target extension has already been installed ephemerally and is | |
| 430 // up to date, it can be promoted to a regular installed extension and | |
| 431 // downloading from the Web Store is not necessary. | |
| 432 const Extension* extension = ExtensionRegistry::Get(browser_context())-> | |
| 433 GetExtensionById(params->expected_id, ExtensionRegistry::EVERYTHING); | |
| 434 if (extension && approval_->dummy_extension.get() && | |
| 435 util::IsEphemeralApp(extension->id(), browser_context()) && | |
| 436 extension->version()->CompareTo(*approval_->dummy_extension->version()) >= | |
| 437 0) { | |
| 438 install_ui::ShowPostInstallUIForApproval( | |
| 439 browser_context(), *approval_, extension); | |
| 440 | |
| 441 ExtensionService* extension_service = | |
| 442 ExtensionSystem::Get(browser_context())->extension_service(); | |
| 443 extension_service->PromoteEphemeralApp(extension, false); | |
| 444 OnInstallSuccess(extension->id()); | |
| 445 VLOG(1) << "Install success, sending response"; | |
| 446 return RespondNow(NoArguments()); | |
| 447 } | |
| 448 | |
| 449 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). | 430 // Balanced in OnExtensionInstallSuccess() or OnExtensionInstallFailure(). |
| 450 AddRef(); | 431 AddRef(); |
| 451 | 432 |
| 452 // The extension will install through the normal extension install flow, but | 433 // The extension will install through the normal extension install flow, but |
| 453 // the whitelist entry will bypass the normal permissions install dialog. | 434 // the whitelist entry will bypass the normal permissions install dialog. |
| 454 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 435 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
| 455 chrome_details_.GetProfile(), | 436 chrome_details_.GetProfile(), |
| 456 this, | 437 this, |
| 457 chrome_details_.GetAssociatedWebContents(), | 438 chrome_details_.GetAssociatedWebContents(), |
| 458 params->expected_id, | 439 params->expected_id, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 // The response is sent asynchronously in OnFetchComplete, OnInstallApproval, | 518 // The response is sent asynchronously in OnFetchComplete, OnInstallApproval, |
| 538 // or OnInstallComplete. | 519 // or OnInstallComplete. |
| 539 return RespondLater(); | 520 return RespondLater(); |
| 540 } | 521 } |
| 541 | 522 |
| 542 void WebstorePrivateInstallBundleFunction::OnFetchComplete( | 523 void WebstorePrivateInstallBundleFunction::OnFetchComplete( |
| 543 const GURL& url, const SkBitmap* bitmap) { | 524 const GURL& url, const SkBitmap* bitmap) { |
| 544 BundleInstaller::ItemList items; | 525 BundleInstaller::ItemList items; |
| 545 for (const auto& entry : params_->contents) { | 526 for (const auto& entry : params_->contents) { |
| 546 // Skip already-installed items. | 527 // Skip already-installed items. |
| 547 if (util::IsExtensionInstalledPermanently(entry->id, browser_context()) || | 528 bool is_installed = |
| 529 extensions::ExtensionRegistry::Get(browser_context())->GetExtensionById( |
| 530 entry->id, extensions::ExtensionRegistry::EVERYTHING) != nullptr; |
| 531 if (is_installed || |
| 548 InstallTracker::Get(browser_context())->GetActiveInstall(entry->id)) { | 532 InstallTracker::Get(browser_context())->GetActiveInstall(entry->id)) { |
| 549 continue; | 533 continue; |
| 550 } | 534 } |
| 551 BundleInstaller::Item item; | 535 BundleInstaller::Item item; |
| 552 item.id = entry->id; | 536 item.id = entry->id; |
| 553 item.manifest = entry->manifest; | 537 item.manifest = entry->manifest; |
| 554 item.localized_name = entry->localized_name; | 538 item.localized_name = entry->localized_name; |
| 555 if (entry->icon_url) | 539 if (entry->icon_url) |
| 556 item.icon_url = source_url().Resolve(*entry->icon_url); | 540 item.icon_url = source_url().Resolve(*entry->icon_url); |
| 557 items.push_back(item); | 541 items.push_back(item); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 WebstorePrivateGetEphemeralAppsEnabledFunction:: | 701 WebstorePrivateGetEphemeralAppsEnabledFunction:: |
| 718 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} | 702 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} |
| 719 | 703 |
| 720 ExtensionFunction::ResponseAction | 704 ExtensionFunction::ResponseAction |
| 721 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { | 705 WebstorePrivateGetEphemeralAppsEnabledFunction::Run() { |
| 722 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( | 706 return RespondNow(ArgumentList(GetEphemeralAppsEnabled::Results::Create( |
| 723 false))); | 707 false))); |
| 724 } | 708 } |
| 725 | 709 |
| 726 } // namespace extensions | 710 } // namespace extensions |
| OLD | NEW |