Commit 6f385b64 authored by khmel's avatar khmel Committed by Commit bot

arc: Support Arc window showing/hiding on a user's profile switch.

This fixes several cases when multi-user manager and shelf controller
is unable to restore Arc window correctly when the user changes his
profile.

BUG=b/31493349
TEST=Manually on a device. Arc app windows automatically restored when
     the user switch backs to main profile.

Review-Url: https://codereview.chromium.org/2339313002
Cr-Commit-Position: refs/heads/master@{#418905}
parent 16e5f602
...@@ -93,8 +93,9 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { ...@@ -93,8 +93,9 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
public: public:
AppWindow(int task_id, AppWindow(int task_id,
const std::string app_id, const std::string app_id,
views::Widget* widget,
ArcAppWindowLauncherController* owner) ArcAppWindowLauncherController* owner)
: task_id_(task_id), app_id_(app_id), owner_(owner) {} : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {}
~AppWindow() {} ~AppWindow() {}
void SetController(ArcAppWindowLauncherItemController* controller) { void SetController(ArcAppWindowLauncherItemController* controller) {
...@@ -119,16 +120,13 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { ...@@ -119,16 +120,13 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
views::Widget* widget() const { return widget_; } views::Widget* widget() const { return widget_; }
void set_widget(views::Widget* widget) { widget_ = widget; }
ArcAppWindowLauncherItemController* controller() { return controller_; } ArcAppWindowLauncherItemController* controller() { return controller_; }
const std::string app_id() { return app_id_; } const std::string app_id() { return app_id_; }
// ui::BaseWindow: // ui::BaseWindow:
bool IsActive() const override { bool IsActive() const override {
return widget_ && widget_->IsActive() && return widget_->IsActive() && owner_->active_task_id_ == task_id_;
owner_->active_task_id_ == task_id_;
} }
bool IsMaximized() const override { bool IsMaximized() const override {
...@@ -147,7 +145,7 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { ...@@ -147,7 +145,7 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
} }
gfx::NativeWindow GetNativeWindow() const override { gfx::NativeWindow GetNativeWindow() const override {
return widget_ ? widget_->GetNativeWindow() : nullptr; return widget_->GetNativeWindow();
} }
gfx::Rect GetRestoredBounds() const override { gfx::Rect GetRestoredBounds() const override {
...@@ -165,9 +163,7 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { ...@@ -165,9 +163,7 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
return gfx::Rect(); return gfx::Rect();
} }
void Show() override { void Show() override { widget_->Show(); }
// TODO(khmel): support window minimizing.
}
void ShowInactive() override { NOTREACHED(); } void ShowInactive() override { NOTREACHED(); }
...@@ -175,16 +171,13 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { ...@@ -175,16 +171,13 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
void Close() override { arc::CloseTask(task_id_); } void Close() override { arc::CloseTask(task_id_); }
void Activate() override { arc::SetTaskActive(task_id_); } void Activate() override { widget_->Activate(); }
void Deactivate() override { NOTREACHED(); } void Deactivate() override { NOTREACHED(); }
void Maximize() override { NOTREACHED(); } void Maximize() override { NOTREACHED(); }
void Minimize() override { void Minimize() override { widget_->Minimize(); }
if (widget_)
widget_->Minimize();
}
void Restore() override { NOTREACHED(); } void Restore() override { NOTREACHED(); }
...@@ -218,10 +211,10 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { ...@@ -218,10 +211,10 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
std::string app_id_; std::string app_id_;
FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
// Unowned pointers // Unowned pointers
views::Widget* const widget_;
ArcAppWindowLauncherController* owner_; ArcAppWindowLauncherController* owner_;
ArcAppWindowLauncherItemController* controller_ = nullptr; ArcAppWindowLauncherItemController* controller_ = nullptr;
// Unowned pointer, represents host Arc window. // Unowned pointer, represents host Arc window.
views::Widget* widget_ = nullptr;
arc::mojom::OrientationLock requested_orientation_lock_ = arc::mojom::OrientationLock requested_orientation_lock_ =
arc::mojom::OrientationLock::NONE; arc::mojom::OrientationLock::NONE;
...@@ -296,10 +289,14 @@ void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { ...@@ -296,10 +289,14 @@ void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) {
window->AddObserver(this); window->AddObserver(this);
} }
void ArcAppWindowLauncherController::OnWindowVisibilityChanging( void ArcAppWindowLauncherController::OnWindowVisibilityChanged(
aura::Window* window, aura::Window* window,
bool visible) { bool visible) {
// The application id property should be set at this time. // The application id property should be set at this time. It is important to
// have window->IsVisible set to true before attaching to a controller because
// the window is registered in multi-user manager and this manager may
// consider this new window as hidden for current profile. Multi-user manager
// uses OnWindowVisibilityChanging event to update window state.
if (visible && observed_profile_ == owner()->GetProfile()) if (visible && observed_profile_ == owner()->GetProfile())
AttachControllerToWindowIfNeeded(window); AttachControllerToWindowIfNeeded(window);
} }
...@@ -370,8 +367,10 @@ void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( ...@@ -370,8 +367,10 @@ void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
const std::string& app_id = it->second; const std::string& app_id = it->second;
std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); DCHECK(widget);
std::unique_ptr<AppWindow> app_window(
new AppWindow(task_id, app_id, widget, this));
RegisterApp(app_window.get()); RegisterApp(app_window.get());
DCHECK(app_window->controller()); DCHECK(app_window->controller());
ash::WmWindowAura::Get(window)->SetIntProperty( ash::WmWindowAura::Get(window)->SetIntProperty(
......
...@@ -58,7 +58,7 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController, ...@@ -58,7 +58,7 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController,
void OnWindowInitialized(aura::Window* window) override; void OnWindowInitialized(aura::Window* window) override;
// aura::WindowObserver: // aura::WindowObserver:
void OnWindowVisibilityChanging(aura::Window* window, bool visible) override; void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
void OnWindowDestroying(aura::Window* window) override; void OnWindowDestroying(aura::Window* window) override;
// aura::client::ActivationChangeObserver: // aura::client::ActivationChangeObserver:
......
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