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 {
public:
AppWindow(int task_id,
const std::string app_id,
views::Widget* widget,
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() {}
void SetController(ArcAppWindowLauncherItemController* controller) {
......@@ -119,16 +120,13 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
views::Widget* widget() const { return widget_; }
void set_widget(views::Widget* widget) { widget_ = widget; }
ArcAppWindowLauncherItemController* controller() { return controller_; }
const std::string app_id() { return app_id_; }
// ui::BaseWindow:
bool IsActive() const override {
return widget_ && widget_->IsActive() &&
owner_->active_task_id_ == task_id_;
return widget_->IsActive() && owner_->active_task_id_ == task_id_;
}
bool IsMaximized() const override {
......@@ -147,7 +145,7 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
}
gfx::NativeWindow GetNativeWindow() const override {
return widget_ ? widget_->GetNativeWindow() : nullptr;
return widget_->GetNativeWindow();
}
gfx::Rect GetRestoredBounds() const override {
......@@ -165,9 +163,7 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
return gfx::Rect();
}
void Show() override {
// TODO(khmel): support window minimizing.
}
void Show() override { widget_->Show(); }
void ShowInactive() override { NOTREACHED(); }
......@@ -175,16 +171,13 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
void Close() override { arc::CloseTask(task_id_); }
void Activate() override { arc::SetTaskActive(task_id_); }
void Activate() override { widget_->Activate(); }
void Deactivate() override { NOTREACHED(); }
void Maximize() override { NOTREACHED(); }
void Minimize() override {
if (widget_)
widget_->Minimize();
}
void Minimize() override { widget_->Minimize(); }
void Restore() override { NOTREACHED(); }
......@@ -218,10 +211,10 @@ class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
std::string app_id_;
FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
// Unowned pointers
views::Widget* const widget_;
ArcAppWindowLauncherController* owner_;
ArcAppWindowLauncherItemController* controller_ = nullptr;
// Unowned pointer, represents host Arc window.
views::Widget* widget_ = nullptr;
arc::mojom::OrientationLock requested_orientation_lock_ =
arc::mojom::OrientationLock::NONE;
......@@ -296,10 +289,14 @@ void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) {
window->AddObserver(this);
}
void ArcAppWindowLauncherController::OnWindowVisibilityChanging(
void ArcAppWindowLauncherController::OnWindowVisibilityChanged(
aura::Window* window,
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())
AttachControllerToWindowIfNeeded(window);
}
......@@ -370,8 +367,10 @@ void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
const std::string& app_id = it->second;
std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this));
app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window));
views::Widget* 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());
DCHECK(app_window->controller());
ash::WmWindowAura::Get(window)->SetIntProperty(
......
......@@ -58,7 +58,7 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController,
void OnWindowInitialized(aura::Window* window) override;
// aura::WindowObserver:
void OnWindowVisibilityChanging(aura::Window* window, bool visible) override;
void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
void OnWindowDestroying(aura::Window* window) override;
// 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