Commit b21f5e09 authored by Swapnil's avatar Swapnil Committed by Chromium LUCI CQ

[Extensions] Use policy-enforced update URL in assets manager

This change gives ExtensionManagement control over update URL used when
updating extensions. Previously only first install was affected, all
later updates used update URL from the extension manifest. Now update
URL from the policy can be used if extension management said so.
This change is split into multiple CLs.

Update URL from policy is handled in
https://chromium-review.googlesource.com/c/chromium/src/+/2593260.

Bug: b/175786074
Change-Id: I73580416d039a14abe7b91ecad50f4f8cecc8682
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596259Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Swapnil Gupta <swapnilgupta@google.com>
Cr-Commit-Position: refs/heads/master@{#843457}
parent 4f3db9db
......@@ -23,6 +23,7 @@
#include "chrome/browser/chromeos/note_taking_helper.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/extension_assets_manager.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/pref_names.h"
#include "extensions/browser/extension_file_task_runner.h"
......@@ -32,6 +33,7 @@
#include "extensions/common/api/app_runtime.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/file_util.h"
#include "extensions/common/manifest.h"
......@@ -132,6 +134,7 @@ void InstallExtensionCopy(
const base::FilePath& original_path,
const base::FilePath& target_install_dir,
Profile* profile,
bool updates_from_webstore_or_empty_update_url,
const ExtensionCallback& callback) {
base::FilePath target_dir = target_install_dir.Append(extension->id());
base::FilePath install_temp_dir =
......@@ -159,7 +162,8 @@ void InstallExtensionCopy(
extension.get(), temp_copy, target_install_dir, profile,
base::Bind(&LoadInstalledExtension, extension->id(),
extension->location(), extension->creation_flags(),
base::Passed(std::move(extension_temp_dir)), callback));
base::Passed(std::move(extension_temp_dir)), callback),
updates_from_webstore_or_empty_update_url);
}
} // namespace
......@@ -423,11 +427,19 @@ AppManagerImpl::State AppManagerImpl::AddAppToLockScreenProfile(
extensions::ExtensionSystem::Get(lock_screen_profile_)
->extension_service();
const GURL update_url =
extensions::ExtensionManagementFactory::GetForBrowserContext(
lock_screen_profile_)
->GetEffectiveUpdateURL(*lock_profile_app);
bool updates_from_webstore_or_empty_update_url =
update_url.is_empty() || extension_urls::IsWebstoreUpdateUrl(update_url);
extensions::GetExtensionFileTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&InstallExtensionCopy, lock_profile_app, app->path(),
lock_screen_service->install_directory(), lock_screen_profile_,
updates_from_webstore_or_empty_update_url,
base::Bind(&InvokeCallbackOnTaskRunner,
base::Bind(&AppManagerImpl::CompleteLockScreenAppInstall,
weak_ptr_factory_.GetWeakPtr(), install_count_,
......
......@@ -58,6 +58,7 @@
#include "extensions/browser/preload_check_group.h"
#include "extensions/browser/requirements_checker.h"
#include "extensions/common/extension_icon_set.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/file_util.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_handlers/kiosk_mode_info.h"
......@@ -904,13 +905,22 @@ void CrxInstaller::UpdateCreationFlagsAndCompleteInstall(
if (withholding_behavior == kWithholdPermissions)
creation_flags_ |= Extension::WITHHOLD_PERMISSIONS;
ExtensionManagement* extension_management =
ExtensionManagementFactory::GetForBrowserContext(profile());
const GURL update_url =
extension_management->GetEffectiveUpdateURL(*(extension()));
const bool updates_from_webstore_or_empty_update_url =
update_url.is_empty() || extension_urls::IsWebstoreUpdateUrl(update_url);
if (!shared_file_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&CrxInstaller::CompleteInstall, this))) {
FROM_HERE,
base::BindOnce(&CrxInstaller::CompleteInstall, this,
updates_from_webstore_or_empty_update_url))) {
NOTREACHED();
}
}
void CrxInstaller::CompleteInstall() {
void CrxInstaller::CompleteInstall(
bool updates_from_webstore_or_empty_update_url) {
DCHECK(shared_file_task_runner_->RunsTasksInCurrentSequence());
if (current_version_.IsValid() &&
......@@ -928,7 +938,8 @@ void CrxInstaller::CompleteInstall() {
ExtensionAssetsManager::GetInstance();
assets_manager->InstallExtension(
extension(), unpacked_extension_root_, install_directory_, profile(),
base::BindOnce(&CrxInstaller::ReloadExtensionAfterInstall, this));
base::Bind(&CrxInstaller::ReloadExtensionAfterInstall, this),
updates_from_webstore_or_empty_update_url);
}
void CrxInstaller::ReloadExtensionAfterInstall(
......
......@@ -317,7 +317,7 @@ class CrxInstaller : public SandboxedUnpackerClient {
// Runs on File thread. Install the unpacked extension into the profile and
// notify the frontend.
void CompleteInstall();
void CompleteInstall(bool updates_from_webstore);
// Reloads extension on File thread and reports installation result back
// to UI thread.
......
......@@ -25,11 +25,13 @@ class ExtensionAssetsManagerImpl : public ExtensionAssetsManager {
}
// Override from ExtensionAssetsManager.
void InstallExtension(const Extension* extension,
const base::FilePath& unpacked_extension_root,
const base::FilePath& local_install_dir,
Profile* profile,
InstallExtensionCallback callback) override {
void InstallExtension(
const Extension* extension,
const base::FilePath& unpacked_extension_root,
const base::FilePath& local_install_dir,
Profile* profile,
InstallExtensionCallback callback,
bool updates_from_webstore_or_empty_update_url) override {
std::move(callback).Run(file_util::InstallExtension(
unpacked_extension_root, extension->id(), extension->VersionString(),
local_install_dir));
......
......@@ -32,11 +32,13 @@ class ExtensionAssetsManager {
// Copy extension assets to final location. This location could be under
// |local_install_dir| or some common location shared for multiple users.
virtual void InstallExtension(const Extension* extension,
const base::FilePath& unpacked_extension_root,
const base::FilePath& local_install_dir,
Profile* profile,
InstallExtensionCallback callback) = 0;
virtual void InstallExtension(
const Extension* extension,
const base::FilePath& unpacked_extension_root,
const base::FilePath& local_install_dir,
Profile* profile,
InstallExtensionCallback callback,
bool updates_from_webstore_or_empty_update_url) = 0;
// Remove extension assets if it is not used by anyone else.
virtual void UninstallExtension(const std::string& id,
......
......@@ -21,6 +21,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/constants/chromeos_switches.h"
#include "components/prefs/pref_registry_simple.h"
......@@ -32,7 +33,6 @@
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/file_util.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_url_handlers.h"
......@@ -151,8 +151,10 @@ void ExtensionAssetsManagerChromeOS::InstallExtension(
const base::FilePath& unpacked_extension_root,
const base::FilePath& local_install_dir,
Profile* profile,
InstallExtensionCallback callback) {
if (!CanShareAssets(extension, unpacked_extension_root)) {
InstallExtensionCallback callback,
bool updates_from_webstore_or_empty_update_url) {
if (!CanShareAssets(extension, unpacked_extension_root,
updates_from_webstore_or_empty_update_url)) {
InstallLocalExtension(extension->id(), extension->VersionString(),
unpacked_extension_root, local_install_dir,
std::move(callback));
......@@ -247,17 +249,18 @@ void ExtensionAssetsManagerChromeOS::SetSharedInstallDirForTesting(
// static
bool ExtensionAssetsManagerChromeOS::CanShareAssets(
const Extension* extension,
const base::FilePath& unpacked_extension_root) {
const base::FilePath& unpacked_extension_root,
bool updates_from_webstore_or_empty_update_url) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnableExtensionAssetsSharing)) {
return false;
}
GURL update_url = ManifestURL::GetUpdateURL(extension);
if (!update_url.is_empty() &&
!extension_urls::IsWebstoreUpdateUrl(update_url)) {
// TODO(crbug.com/1166539): Investigate why do we allow sharing assets in case
// of empty update URL and if the empty update URL is not required, update
// this to consider only the updates from webstore.
if (!updates_from_webstore_or_empty_update_url)
return false;
}
// Chrome caches crx files for installed by default apps so sharing assets is
// also possible. User specific apps should be excluded to not expose apps
......
......@@ -41,11 +41,13 @@ class ExtensionAssetsManagerChromeOS : public ExtensionAssetsManager {
static void RegisterPrefs(PrefRegistrySimple* registry);
// Override from ExtensionAssetsManager.
void InstallExtension(const Extension* extension,
const base::FilePath& unpacked_extension_root,
const base::FilePath& local_install_dir,
Profile* profile,
InstallExtensionCallback callback) override;
void InstallExtension(
const Extension* extension,
const base::FilePath& unpacked_extension_root,
const base::FilePath& local_install_dir,
Profile* profile,
InstallExtensionCallback callback,
bool updates_from_webstore_or_empty_update_url) override;
void UninstallExtension(const std::string& id,
Profile* profile,
const base::FilePath& local_install_dir,
......@@ -75,7 +77,8 @@ class ExtensionAssetsManagerChromeOS : public ExtensionAssetsManager {
// Return |true| if |extension| can be installed in a shared place for all
// users on the device.
static bool CanShareAssets(const Extension* extension,
const base::FilePath& unpacked_extension_root);
const base::FilePath& unpacked_extension_root,
bool updates_from_webstore_or_empty_update_url);
// Called on the UI thread to check if a given version of the |extension|
// already exists at the shared location.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment