Commit dabd5140 authored by Aya ElAttar's avatar Aya ElAttar Committed by Commit Bot

Fixed ExtensionApps to publish apps disabled by policy

-Fixed ExtensionApps::Connect to check the app disable reason before
publishing instead of publishing as always disabled by user.
-Fixed ExtensionApps::OnSystemWebAppsInstalled to check the app status
before publishing instead of always publishing as ready.
-Added ExtensionApps::OnExtensionStateChanged to publish the app in case
it got disabled by a policy.

Bug: 1063404
Change-Id: Ia09d4dee1600e268d118d05000e53a905482bc30
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127211
Commit-Queue: Aya Elsayed <ayaelattar@google.com>
Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756224}
parent 5dd4977b
......@@ -159,6 +159,22 @@ std::string GetLaunchId(extensions::AppWindow* app_window) {
return launch_id;
}
// Get the |apps::mojom::Readiness| for the |app_id|. If the extension is
// enabled, it returns |kReady|. If the extension is
// |DISABLE_BLOCKED_BY_POLICY|, it returns |kDisabledByPolicy|. Otherwise it
// returns |kDisabledByUser|.
apps::mojom::Readiness GetReadiness(const std::string& app_id,
extensions::ExtensionPrefs* prefs) {
DCHECK(prefs);
if (prefs->IsExtensionDisabled(app_id)) {
return prefs->HasDisableReason(
app_id, extensions::disable_reason::DISABLE_BLOCKED_BY_POLICY)
? apps::mojom::Readiness::kDisabledByPolicy
: apps::mojom::Readiness::kDisabledByUser;
}
return apps::mojom::Readiness::kReady;
}
} // namespace
namespace apps {
......@@ -352,7 +368,9 @@ void ExtensionApps::OnSystemWebAppsInstalled() {
continue;
}
Publish(Convert(extension, apps::mojom::Readiness::kReady));
Publish(Convert(
extension,
GetReadiness(app_id, extensions::ExtensionPrefs::Get(profile_))));
}
}
......@@ -367,7 +385,23 @@ void ExtensionApps::Connect(
extensions::ExtensionRegistry::Get(profile_);
ConvertVector(registry->enabled_extensions(),
apps::mojom::Readiness::kReady, &apps);
ConvertVector(registry->disabled_extensions(),
extensions::ExtensionSet extensions_disabled_by_policy,
extensions_disabled_by_user;
const extensions::ExtensionPrefs* prefs =
extensions::ExtensionPrefs::Get(profile_);
for (const auto& extension : registry->disabled_extensions()) {
if (prefs->HasDisableReason(
extension->id(),
extensions::disable_reason::DISABLE_BLOCKED_BY_POLICY)) {
extensions_disabled_by_policy.Insert(extension);
} else {
extensions_disabled_by_user.Insert(extension);
}
}
ConvertVector(extensions_disabled_by_policy,
apps::mojom::Readiness::kDisabledByPolicy, &apps);
ConvertVector(extensions_disabled_by_user,
apps::mojom::Readiness::kDisabledByUser, &apps);
ConvertVector(registry->terminated_extensions(),
apps::mojom::Readiness::kTerminated, &apps);
......@@ -953,7 +987,8 @@ void ExtensionApps::OnExtensionUnloaded(
switch (reason) {
case extensions::UnloadedExtensionReason::DISABLE:
readiness = apps::mojom::Readiness::kDisabledByUser;
readiness = GetReadiness(extension->id(),
extensions::ExtensionPrefs::Get(profile_));
break;
case extensions::UnloadedExtensionReason::BLACKLIST:
readiness = apps::mojom::Readiness::kDisabledByBlacklist;
......
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