Commit 321ff30d authored by Jit Yao Yap's avatar Jit Yao Yap Committed by Commit Bot

Fix login screen UI window not closing when extension is unloaded

Currently, |login_screen_ui::UiHandler| only closes the login screen UI
window when the extension is uninstalled, and not when it is unloaded.
When an extension is updated, the old instance is unloaded and not
uninstalled. This means when an update occurs when the old instance has
a window open, this window will not be closed, and the new instance
will not be able to open another window.

This CL updates |UiHandler| to also close the window when the extension
is unloaded.

Bug: 957573
Change-Id: If586fa5cc83fca20d971e85080389d013b854e66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002610
Commit-Queue: Jit Yao Yap <jityao@google.com>
Reviewed-by: default avatarAlexander Hendrich <hendrich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732849}
parent 8a985066
...@@ -181,6 +181,18 @@ void UiHandler::OnSessionStateChanged() { ...@@ -181,6 +181,18 @@ void UiHandler::OnSessionStateChanged() {
void UiHandler::OnExtensionUninstalled(content::BrowserContext* browser_context, void UiHandler::OnExtensionUninstalled(content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UninstallReason reason) { extensions::UninstallReason reason) {
HandleExtensionUnloadOrUinstall(extension);
}
void UiHandler::OnExtensionUnloaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) {
HandleExtensionUnloadOrUinstall(extension);
}
void UiHandler::HandleExtensionUnloadOrUinstall(
const extensions::Extension* extension) {
RemoveWindowForExtension(extension->id()); RemoveWindowForExtension(extension->id());
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/session_manager/core/session_manager_observer.h" #include "components/session_manager/core/session_manager_observer.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/unloaded_extension_reason.h"
namespace extensions { namespace extensions {
class Extension; class Extension;
...@@ -82,6 +83,13 @@ class UiHandler : public session_manager::SessionManagerObserver, ...@@ -82,6 +83,13 @@ class UiHandler : public session_manager::SessionManagerObserver,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UninstallReason reason) override; extensions::UninstallReason reason) override;
// extensions::ExtensionRegistryObserver
void OnExtensionUnloaded(content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) override;
void HandleExtensionUnloadOrUinstall(const extensions::Extension* extension);
std::unique_ptr<WindowFactory> window_factory_; std::unique_ptr<WindowFactory> window_factory_;
bool login_or_lock_screen_active_ = false; bool login_or_lock_screen_active_ = false;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/unloaded_extension_reason.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h" #include "extensions/common/extension_builder.h"
#include "extensions/common/features/feature_channel.h" #include "extensions/common/features/feature_channel.h"
...@@ -337,6 +338,18 @@ TEST_F(LoginScreenExtensionUiHandlerUnittest, WindowClosedOnUninstall) { ...@@ -337,6 +338,18 @@ TEST_F(LoginScreenExtensionUiHandlerUnittest, WindowClosedOnUninstall) {
EXPECT_FALSE(ui_handler_->HasOpenWindow(extension_->id())); EXPECT_FALSE(ui_handler_->HasOpenWindow(extension_->id()));
} }
TEST_F(LoginScreenExtensionUiHandlerUnittest, WindowClosedOnUnloaded) {
// Open window.
CheckCanOpenWindow(extension_.get());
EXPECT_TRUE(ui_handler_->HasOpenWindow(extension_->id()));
// Simulate extension unload.
extension_registry_->RemoveEnabled(extension_->id());
extension_registry_->TriggerOnUnloaded(
extension_.get(), extensions::UnloadedExtensionReason::BLACKLIST);
EXPECT_FALSE(ui_handler_->HasOpenWindow(extension_->id()));
}
TEST_F(LoginScreenExtensionUiHandlerUnittest, TEST_F(LoginScreenExtensionUiHandlerUnittest,
OpenWindowWithDifferentArguments) { OpenWindowWithDifferentArguments) {
// Open window. // Open window.
......
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