| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "ash/display/screen_orientation_controller_chromeos.h" | 8 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 9 #include "ash/public/cpp/window_properties.h" | 9 #include "ash/public/cpp/window_properties.h" |
| 10 #include "ash/shared/app_types.h" | 10 #include "ash/shared/app_types.h" |
| 11 #include "ash/shelf/shelf_model.h" | 11 #include "ash/shelf/shelf_model.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 13 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 16 #include "ash/wm_window.h" | 16 #include "ash/wm_window.h" |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_util.h" | 19 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 21 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 22 #include "chrome/browser/ui/ash/launcher/arc_app_window.h" |
| 22 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller
.h" | 23 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller
.h" |
| 23 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 24 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 25 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 25 #include "components/arc/arc_bridge_service.h" | 26 #include "components/arc/arc_bridge_service.h" |
| 26 #include "components/exo/shell_surface.h" | 27 #include "components/exo/shell_surface.h" |
| 27 #include "components/signin/core/account_id/account_id.h" | 28 #include "components/signin/core/account_id/account_id.h" |
| 28 #include "components/user_manager/user_manager.h" | 29 #include "components/user_manager/user_manager.h" |
| 29 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" | 30 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree
nOrientationLockType.h" |
| 30 #include "ui/aura/client/aura_constants.h" | 31 #include "ui/aura/client/aura_constants.h" |
| 31 #include "ui/aura/env.h" | 32 #include "ui/aura/env.h" |
| 32 #include "ui/base/base_window.h" | 33 #include "ui/base/base_window.h" |
| 33 #include "ui/display/display.h" | 34 #include "ui/display/display.h" |
| 34 #include "ui/display/manager/display_manager.h" | 35 #include "ui/display/manager/display_manager.h" |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 enum class FullScreenMode { | 40 constexpr size_t kMaxIconPngSize = 64 * 1024; // 64 kb |
| 40 NOT_DEFINED, // Fullscreen mode was not defined. | |
| 41 ACTIVE, // Fullscreen is activated for an app. | |
| 42 NON_ACTIVE, // Fullscreen was not activated for an app. | |
| 43 }; | |
| 44 | 41 |
| 45 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom( | 42 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom( |
| 46 arc::mojom::OrientationLock orientation_lock) { | 43 arc::mojom::OrientationLock orientation_lock) { |
| 47 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock); | 44 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock); |
| 48 switch (orientation_lock) { | 45 switch (orientation_lock) { |
| 49 case arc::mojom::OrientationLock::PORTRAIT: | 46 case arc::mojom::OrientationLock::PORTRAIT: |
| 50 return blink::kWebScreenOrientationLockPortrait; | 47 return blink::kWebScreenOrientationLockPortrait; |
| 51 case arc::mojom::OrientationLock::LANDSCAPE: | 48 case arc::mojom::OrientationLock::LANDSCAPE: |
| 52 return blink::kWebScreenOrientationLockLandscape; | 49 return blink::kWebScreenOrientationLockLandscape; |
| 53 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY: | 50 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 68 using ash::ScreenOrientationController; | 65 using ash::ScreenOrientationController; |
| 69 | 66 |
| 70 // The information about the arc application window which has to be kept | 67 // The information about the arc application window which has to be kept |
| 71 // even when its AppWindow is not present. | 68 // even when its AppWindow is not present. |
| 72 class ArcAppWindowLauncherController::AppWindowInfo { | 69 class ArcAppWindowLauncherController::AppWindowInfo { |
| 73 public: | 70 public: |
| 74 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id) | 71 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id) |
| 75 : app_shelf_id_(app_shelf_id) {} | 72 : app_shelf_id_(app_shelf_id) {} |
| 76 ~AppWindowInfo() = default; | 73 ~AppWindowInfo() = default; |
| 77 | 74 |
| 75 void SetDescription(const std::string& title, |
| 76 const std::vector<uint8_t>& icon_data_png) { |
| 77 if (base::IsStringUTF8(title)) |
| 78 title_ = title; |
| 79 else |
| 80 VLOG(1) << "Task label is not UTF-8 string."; |
| 81 // Chrome has custom Play Store icon. Don't overwrite it. |
| 82 if (app_shelf_id_.app_id() != arc::kPlayStoreAppId) { |
| 83 if (icon_data_png.size() < kMaxIconPngSize) |
| 84 icon_data_png_ = icon_data_png; |
| 85 else |
| 86 VLOG(1) << "Task icon size is too big " << icon_data_png.size() << "."; |
| 87 } |
| 88 } |
| 89 |
| 90 void set_app_window(std::unique_ptr<ArcAppWindow> window) { |
| 91 app_window_ = std::move(window); |
| 92 } |
| 93 |
| 78 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } | 94 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } |
| 79 | 95 |
| 80 bool has_requested_orientation_lock() const { | 96 bool has_requested_orientation_lock() const { |
| 81 return has_requested_orientation_lock_; | 97 return has_requested_orientation_lock_; |
| 82 } | 98 } |
| 83 | 99 |
| 84 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { | 100 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { |
| 85 has_requested_orientation_lock_ = true; | 101 has_requested_orientation_lock_ = true; |
| 86 requested_orientation_lock_ = lock; | 102 requested_orientation_lock_ = lock; |
| 87 } | 103 } |
| 88 | 104 |
| 89 arc::mojom::OrientationLock requested_orientation_lock() const { | 105 arc::mojom::OrientationLock requested_orientation_lock() const { |
| 90 return requested_orientation_lock_; | 106 return requested_orientation_lock_; |
| 91 } | 107 } |
| 92 | 108 |
| 93 void set_lock_completion_behavior( | 109 void set_lock_completion_behavior( |
| 94 ScreenOrientationController::LockCompletionBehavior lock_behavior) { | 110 ScreenOrientationController::LockCompletionBehavior lock_behavior) { |
| 95 lock_completion_behavior_ = lock_behavior; | 111 lock_completion_behavior_ = lock_behavior; |
| 96 } | 112 } |
| 97 | 113 |
| 98 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior() | 114 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior() |
| 99 const { | 115 const { |
| 100 return lock_completion_behavior_; | 116 return lock_completion_behavior_; |
| 101 } | 117 } |
| 102 | 118 |
| 103 void set_app_window(std::unique_ptr<AppWindow> window) { | 119 ArcAppWindow* app_window() { return app_window_.get(); } |
| 104 app_window_ = std::move(window); | |
| 105 } | |
| 106 | 120 |
| 107 AppWindow* app_window() { return app_window_.get(); } | 121 const std::string& title() const { return title_; } |
| 122 |
| 123 const std::vector<uint8_t>& icon_data_png() const { return icon_data_png_; } |
| 108 | 124 |
| 109 private: | 125 private: |
| 110 const arc::ArcAppShelfId app_shelf_id_; | 126 const arc::ArcAppShelfId app_shelf_id_; |
| 111 bool has_requested_orientation_lock_ = false; | 127 bool has_requested_orientation_lock_ = false; |
| 112 | 128 |
| 113 // If true, the orientation should be locked to the specific | 129 // If true, the orientation should be locked to the specific |
| 114 // orientation after the requested_orientation_lock is applied. | 130 // orientation after the requested_orientation_lock is applied. |
| 115 // This is meaningful only if the orientation is one of ::NONE, | 131 // This is meaningful only if the orientation is one of ::NONE, |
| 116 // ::PORTRAIT or ::LANDSCAPE. | 132 // ::PORTRAIT or ::LANDSCAPE. |
| 117 ScreenOrientationController::LockCompletionBehavior | 133 ScreenOrientationController::LockCompletionBehavior |
| 118 lock_completion_behavior_ = | 134 lock_completion_behavior_ = |
| 119 ScreenOrientationController::LockCompletionBehavior::None; | 135 ScreenOrientationController::LockCompletionBehavior::None; |
| 120 arc::mojom::OrientationLock requested_orientation_lock_ = | 136 arc::mojom::OrientationLock requested_orientation_lock_ = |
| 121 arc::mojom::OrientationLock::NONE; | 137 arc::mojom::OrientationLock::NONE; |
| 122 std::unique_ptr<AppWindow> app_window_; | 138 // Keeps overridden window title. |
| 139 std::string title_; |
| 140 // Keeps overridden window icon. |
| 141 std::vector<uint8_t> icon_data_png_; |
| 142 std::unique_ptr<ArcAppWindow> app_window_; |
| 123 | 143 |
| 124 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); | 144 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); |
| 125 }; | 145 }; |
| 126 | 146 |
| 127 // A ui::BaseWindow for a chromeos launcher to control ARC applications. | |
| 128 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { | |
| 129 public: | |
| 130 AppWindow(int task_id, | |
| 131 const arc::ArcAppShelfId& app_shelf_id, | |
| 132 views::Widget* widget, | |
| 133 ArcAppWindowLauncherController* owner) | |
| 134 : task_id_(task_id), | |
| 135 app_shelf_id_(app_shelf_id), | |
| 136 widget_(widget), | |
| 137 owner_(owner) {} | |
| 138 ~AppWindow() = default; | |
| 139 | |
| 140 void SetController(ArcAppWindowLauncherItemController* controller) { | |
| 141 DCHECK(!controller_ && controller); | |
| 142 controller_ = controller; | |
| 143 } | |
| 144 | |
| 145 void ResetController() { controller_ = nullptr; } | |
| 146 | |
| 147 void SetFullscreenMode(FullScreenMode mode) { | |
| 148 DCHECK(mode != FullScreenMode::NOT_DEFINED); | |
| 149 fullscreen_mode_ = mode; | |
| 150 } | |
| 151 | |
| 152 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } | |
| 153 | |
| 154 int task_id() const { return task_id_; } | |
| 155 | |
| 156 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } | |
| 157 | |
| 158 const ash::ShelfID& shelf_id() const { return shelf_id_; } | |
| 159 | |
| 160 void set_shelf_id(const ash::ShelfID& shelf_id) { shelf_id_ = shelf_id; } | |
| 161 | |
| 162 views::Widget* widget() const { return widget_; } | |
| 163 | |
| 164 ArcAppWindowLauncherItemController* controller() { return controller_; } | |
| 165 | |
| 166 // ui::BaseWindow: | |
| 167 bool IsActive() const override { | |
| 168 return widget_->IsActive() && owner_->active_task_id_ == task_id_; | |
| 169 } | |
| 170 | |
| 171 bool IsMaximized() const override { | |
| 172 NOTREACHED(); | |
| 173 return false; | |
| 174 } | |
| 175 | |
| 176 bool IsMinimized() const override { | |
| 177 NOTREACHED(); | |
| 178 return false; | |
| 179 } | |
| 180 | |
| 181 bool IsFullscreen() const override { | |
| 182 NOTREACHED(); | |
| 183 return false; | |
| 184 } | |
| 185 | |
| 186 gfx::NativeWindow GetNativeWindow() const override { | |
| 187 return widget_->GetNativeWindow(); | |
| 188 } | |
| 189 | |
| 190 gfx::Rect GetRestoredBounds() const override { | |
| 191 NOTREACHED(); | |
| 192 return gfx::Rect(); | |
| 193 } | |
| 194 | |
| 195 ui::WindowShowState GetRestoredState() const override { | |
| 196 NOTREACHED(); | |
| 197 return ui::SHOW_STATE_NORMAL; | |
| 198 } | |
| 199 | |
| 200 gfx::Rect GetBounds() const override { | |
| 201 NOTREACHED(); | |
| 202 return gfx::Rect(); | |
| 203 } | |
| 204 | |
| 205 void Show() override { widget_->Show(); } | |
| 206 | |
| 207 void ShowInactive() override { NOTREACHED(); } | |
| 208 | |
| 209 void Hide() override { NOTREACHED(); } | |
| 210 | |
| 211 void Close() override { arc::CloseTask(task_id_); } | |
| 212 | |
| 213 void Activate() override { widget_->Activate(); } | |
| 214 | |
| 215 void Deactivate() override { NOTREACHED(); } | |
| 216 | |
| 217 void Maximize() override { NOTREACHED(); } | |
| 218 | |
| 219 void Minimize() override { widget_->Minimize(); } | |
| 220 | |
| 221 void Restore() override { NOTREACHED(); } | |
| 222 | |
| 223 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); } | |
| 224 | |
| 225 void FlashFrame(bool flash) override { NOTREACHED(); } | |
| 226 | |
| 227 bool IsAlwaysOnTop() const override { | |
| 228 NOTREACHED(); | |
| 229 return false; | |
| 230 } | |
| 231 | |
| 232 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); } | |
| 233 | |
| 234 private: | |
| 235 const int task_id_; | |
| 236 const arc::ArcAppShelfId app_shelf_id_; | |
| 237 ash::ShelfID shelf_id_; | |
| 238 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; | |
| 239 // Unowned pointers | |
| 240 views::Widget* const widget_; | |
| 241 ArcAppWindowLauncherController* owner_; | |
| 242 ArcAppWindowLauncherItemController* controller_ = nullptr; | |
| 243 // Unowned pointer, represents host ARC window. | |
| 244 | |
| 245 DISALLOW_COPY_AND_ASSIGN(AppWindow); | |
| 246 }; | |
| 247 | |
| 248 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 147 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 249 ChromeLauncherController* owner) | 148 ChromeLauncherController* owner) |
| 250 : AppWindowLauncherController(owner) { | 149 : AppWindowLauncherController(owner) { |
| 251 if (arc::IsArcAllowedForProfile(owner->profile())) { | 150 if (arc::IsArcAllowedForProfile(owner->profile())) { |
| 252 observed_profile_ = owner->profile(); | 151 observed_profile_ = owner->profile(); |
| 253 StartObserving(observed_profile_); | 152 StartObserving(observed_profile_); |
| 254 } | 153 } |
| 255 } | 154 } |
| 256 | 155 |
| 257 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { | 156 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 UnregisterApp(info_it->second.get()); | 248 UnregisterApp(info_it->second.get()); |
| 350 } | 249 } |
| 351 } | 250 } |
| 352 | 251 |
| 353 ArcAppWindowLauncherController::AppWindowInfo* | 252 ArcAppWindowLauncherController::AppWindowInfo* |
| 354 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) { | 253 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) { |
| 355 const auto it = task_id_to_app_window_info_.find(task_id); | 254 const auto it = task_id_to_app_window_info_.find(task_id); |
| 356 return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get(); | 255 return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get(); |
| 357 } | 256 } |
| 358 | 257 |
| 359 ArcAppWindowLauncherController::AppWindow* | 258 ArcAppWindow* ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
| 360 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { | |
| 361 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | 259 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 362 return info ? info->app_window() : nullptr; | 260 return info ? info->app_window() : nullptr; |
| 363 } | 261 } |
| 364 | 262 |
| 365 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { | 263 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { |
| 366 for (auto* window : observed_windows_) | 264 for (auto* window : observed_windows_) |
| 367 AttachControllerToWindowIfNeeded(window); | 265 AttachControllerToWindowIfNeeded(window); |
| 368 } | 266 } |
| 369 | 267 |
| 370 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( | 268 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 391 // Create controller if we have task info. | 289 // Create controller if we have task info. |
| 392 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | 290 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 393 if (!info) { | 291 if (!info) { |
| 394 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id; | 292 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id; |
| 395 return; | 293 return; |
| 396 } | 294 } |
| 397 | 295 |
| 398 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 296 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 399 DCHECK(widget); | 297 DCHECK(widget); |
| 400 DCHECK(!info->app_window()); | 298 DCHECK(!info->app_window()); |
| 401 info->set_app_window( | 299 info->set_app_window(base::MakeUnique<ArcAppWindow>( |
| 402 base::MakeUnique<AppWindow>(task_id, info->app_shelf_id(), widget, this)); | 300 task_id, info->app_shelf_id(), widget, this)); |
| 301 info->app_window()->SetDescription(info->title(), info->icon_data_png()); |
| 403 RegisterApp(info); | 302 RegisterApp(info); |
| 404 DCHECK(info->app_window()->controller()); | 303 DCHECK(info->app_window()->controller()); |
| 405 const ash::ShelfID shelf_id(info->app_window()->shelf_id()); | 304 const ash::ShelfID shelf_id(info->app_window()->shelf_id()); |
| 406 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize())); | 305 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize())); |
| 407 if (ash::Shell::Get() | 306 if (ash::Shell::Get() |
| 408 ->maximize_mode_controller() | 307 ->maximize_mode_controller() |
| 409 ->IsMaximizeModeWindowManagerEnabled()) { | 308 ->IsMaximizeModeWindowManagerEnabled()) { |
| 410 SetOrientationLockForAppWindow(info->app_window()); | 309 SetOrientationLockForAppWindow(info->app_window()); |
| 411 } | 310 } |
| 412 } | 311 } |
| 413 | 312 |
| 414 void ArcAppWindowLauncherController::OnAppReadyChanged( | 313 void ArcAppWindowLauncherController::OnAppReadyChanged( |
| 415 const std::string& arc_app_id, | 314 const std::string& arc_app_id, |
| 416 bool ready) { | 315 bool ready) { |
| 417 if (!ready) | 316 if (!ready) |
| 418 OnAppRemoved(arc_app_id); | 317 OnAppRemoved(arc_app_id); |
| 419 } | 318 } |
| 420 | 319 |
| 421 std::vector<int> ArcAppWindowLauncherController::GetTaskIdsForApp( | 320 std::vector<int> ArcAppWindowLauncherController::GetTaskIdsForApp( |
| 422 const std::string& arc_app_id) const { | 321 const std::string& arc_app_id) const { |
| 423 // Note, AppWindow is optional part for a task and it may be not created if | 322 // Note, ArcAppWindow is optional part for a task and it may be not created if |
| 424 // another full screen Android app is currently active. Use | 323 // another full screen Android app is currently active. Use |
| 425 // |task_id_to_app_window_info_| that keeps currently running tasks info. | 324 // |task_id_to_app_window_info_| that keeps currently running tasks info. |
| 426 std::vector<int> task_ids; | 325 std::vector<int> task_ids; |
| 427 for (const auto& it : task_id_to_app_window_info_) { | 326 for (const auto& it : task_id_to_app_window_info_) { |
| 428 const AppWindowInfo* app_window_info = it.second.get(); | 327 const AppWindowInfo* app_window_info = it.second.get(); |
| 429 if (app_window_info->app_shelf_id().app_id() == arc_app_id) | 328 if (app_window_info->app_shelf_id().app_id() == arc_app_id) |
| 430 task_ids.push_back(it.first); | 329 task_ids.push_back(it.first); |
| 431 } | 330 } |
| 432 | 331 |
| 433 return task_ids; | 332 return task_ids; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 458 return; | 357 return; |
| 459 | 358 |
| 460 AttachControllerToWindowsIfNeeded(); | 359 AttachControllerToWindowsIfNeeded(); |
| 461 | 360 |
| 462 // Some tasks can be started in background and might have no window until | 361 // Some tasks can be started in background and might have no window until |
| 463 // pushed to the front. We need its representation on the shelf to give a user | 362 // pushed to the front. We need its representation on the shelf to give a user |
| 464 // control over it. | 363 // control over it. |
| 465 AttachControllerToTask(task_id, *task_id_to_app_window_info_[task_id]); | 364 AttachControllerToTask(task_id, *task_id_to_app_window_info_[task_id]); |
| 466 } | 365 } |
| 467 | 366 |
| 367 void ArcAppWindowLauncherController::OnTaskDescriptionUpdated( |
| 368 int32_t task_id, |
| 369 const std::string& label, |
| 370 const std::vector<uint8_t>& icon_png_data) { |
| 371 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 372 if (info) { |
| 373 info->SetDescription(label, icon_png_data); |
| 374 if (info->app_window()) |
| 375 info->app_window()->SetDescription(label, icon_png_data); |
| 376 } |
| 377 } |
| 378 |
| 468 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 379 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| 469 auto it = task_id_to_app_window_info_.find(task_id); | 380 auto it = task_id_to_app_window_info_.find(task_id); |
| 470 if (it == task_id_to_app_window_info_.end()) | 381 if (it == task_id_to_app_window_info_.end()) |
| 471 return; | 382 return; |
| 472 | 383 |
| 473 UnregisterApp(it->second.get()); | 384 UnregisterApp(it->second.get()); |
| 474 | 385 |
| 475 // Check if we may close controller now, at this point we can safely remove | 386 // Check if we may close controller now, at this point we can safely remove |
| 476 // controllers without window. | 387 // controllers without window. |
| 477 auto it_controller = | 388 auto it_controller = |
| 478 app_shelf_group_to_controller_map_.find(it->second->app_shelf_id()); | 389 app_shelf_group_to_controller_map_.find(it->second->app_shelf_id()); |
| 479 if (it_controller != app_shelf_group_to_controller_map_.end()) { | 390 if (it_controller != app_shelf_group_to_controller_map_.end()) { |
| 480 it_controller->second->RemoveTaskId(task_id); | 391 it_controller->second->RemoveTaskId(task_id); |
| 481 if (!it_controller->second->HasAnyTasks()) { | 392 if (!it_controller->second->HasAnyTasks()) { |
| 482 owner()->CloseLauncherItem(it_controller->second->shelf_id()); | 393 owner()->CloseLauncherItem(it_controller->second->shelf_id()); |
| 483 app_shelf_group_to_controller_map_.erase(it_controller); | 394 app_shelf_group_to_controller_map_.erase(it_controller); |
| 484 } | 395 } |
| 485 } | 396 } |
| 486 | 397 |
| 487 task_id_to_app_window_info_.erase(it); | 398 task_id_to_app_window_info_.erase(it); |
| 488 } | 399 } |
| 489 | 400 |
| 490 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { | |
| 491 if (observed_profile_ != owner()->profile()) { | |
| 492 active_task_id_ = task_id; | |
| 493 return; | |
| 494 } | |
| 495 | |
| 496 AppWindow* previous_app_window = GetAppWindowForTask(active_task_id_); | |
| 497 if (previous_app_window) { | |
| 498 owner()->SetItemStatus(previous_app_window->shelf_id(), | |
| 499 ash::STATUS_RUNNING); | |
| 500 previous_app_window->SetFullscreenMode( | |
| 501 previous_app_window->widget() && | |
| 502 previous_app_window->widget()->IsFullscreen() | |
| 503 ? FullScreenMode::ACTIVE | |
| 504 : FullScreenMode::NON_ACTIVE); | |
| 505 } | |
| 506 | |
| 507 active_task_id_ = task_id; | |
| 508 | |
| 509 AppWindow* current_app_window = GetAppWindowForTask(task_id); | |
| 510 if (current_app_window) { | |
| 511 owner()->SetItemStatus( | |
| 512 current_app_window->shelf_id(), | |
| 513 current_app_window->widget() && current_app_window->IsActive() | |
| 514 ? ash::STATUS_ACTIVE | |
| 515 : ash::STATUS_RUNNING); | |
| 516 // TODO(reveman): Figure out how to support fullscreen in interleaved | |
| 517 // window mode. | |
| 518 // if (new_active_app_it->second->widget()) { | |
| 519 // new_active_app_it->second->widget()->SetFullscreen( | |
| 520 // new_active_app_it->second->fullscreen_mode() == | |
| 521 // FullScreenMode::ACTIVE); | |
| 522 // } | |
| 523 } | |
| 524 } | |
| 525 | |
| 526 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( | 401 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( |
| 527 int32_t task_id, | 402 int32_t task_id, |
| 528 const arc::mojom::OrientationLock orientation_lock) { | 403 const arc::mojom::OrientationLock orientation_lock) { |
| 529 // Don't save to AppInfo in prefs because this is requested in runtime. | 404 // Don't save to AppInfo in prefs because this is requested in runtime. |
| 530 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | 405 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 531 DCHECK(info); | 406 DCHECK(info); |
| 532 if (!info) | 407 if (!info) |
| 533 return; | 408 return; |
| 534 | 409 |
| 535 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 410 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 536 info->set_lock_completion_behavior( | 411 info->set_lock_completion_behavior( |
| 537 ScreenOrientationController::LockCompletionBehavior::DisableSensor); | 412 ScreenOrientationController::LockCompletionBehavior::DisableSensor); |
| 538 if (!info->has_requested_orientation_lock()) { | 413 if (!info->has_requested_orientation_lock()) { |
| 539 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE); | 414 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE); |
| 540 } | 415 } |
| 541 } else { | 416 } else { |
| 542 info->set_requested_orientation_lock(orientation_lock); | 417 info->set_requested_orientation_lock(orientation_lock); |
| 543 info->set_lock_completion_behavior( | 418 info->set_lock_completion_behavior( |
| 544 ScreenOrientationController::LockCompletionBehavior::None); | 419 ScreenOrientationController::LockCompletionBehavior::None); |
| 545 } | 420 } |
| 546 | 421 |
| 547 if (ash::Shell::Get() | 422 if (ash::Shell::Get() |
| 548 ->maximize_mode_controller() | 423 ->maximize_mode_controller() |
| 549 ->IsMaximizeModeWindowManagerEnabled()) { | 424 ->IsMaximizeModeWindowManagerEnabled()) { |
| 550 AppWindow* app_window = info->app_window(); | 425 ArcAppWindow* app_window = info->app_window(); |
| 551 if (app_window) | 426 if (app_window) |
| 552 SetOrientationLockForAppWindow(app_window); | 427 SetOrientationLockForAppWindow(app_window); |
| 553 } | 428 } |
| 554 } | 429 } |
| 555 | 430 |
| 431 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { |
| 432 if (observed_profile_ != owner()->profile()) { |
| 433 active_task_id_ = task_id; |
| 434 return; |
| 435 } |
| 436 |
| 437 ArcAppWindow* previous_app_window = GetAppWindowForTask(active_task_id_); |
| 438 if (previous_app_window) { |
| 439 owner()->SetItemStatus(previous_app_window->shelf_id(), |
| 440 ash::STATUS_RUNNING); |
| 441 previous_app_window->SetFullscreenMode( |
| 442 previous_app_window->widget() && |
| 443 previous_app_window->widget()->IsFullscreen() |
| 444 ? ArcAppWindow::FullScreenMode::ACTIVE |
| 445 : ArcAppWindow::FullScreenMode::NON_ACTIVE); |
| 446 } |
| 447 |
| 448 active_task_id_ = task_id; |
| 449 |
| 450 ArcAppWindow* current_app_window = GetAppWindowForTask(task_id); |
| 451 if (current_app_window) { |
| 452 if (current_app_window->widget() && current_app_window->IsActive()) { |
| 453 owner()->SetItemStatus(current_app_window->shelf_id(), |
| 454 ash::STATUS_ACTIVE); |
| 455 current_app_window->controller()->SetActiveWindow( |
| 456 current_app_window->GetNativeWindow()); |
| 457 } else { |
| 458 owner()->SetItemStatus(current_app_window->shelf_id(), |
| 459 ash::STATUS_RUNNING); |
| 460 } |
| 461 // TODO(reveman): Figure out how to support fullscreen in interleaved |
| 462 // window mode. |
| 463 // if (new_active_app_it->second->widget()) { |
| 464 // new_active_app_it->second->widget()->SetFullscreen( |
| 465 // new_active_app_it->second->fullscreen_mode() == |
| 466 // ArcAppWindow::FullScreenMode::ACTIVE); |
| 467 // } |
| 468 } |
| 469 } |
| 470 |
| 556 AppWindowLauncherItemController* | 471 AppWindowLauncherItemController* |
| 557 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { | 472 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { |
| 558 if (!window) | 473 if (!window) |
| 559 return nullptr; | 474 return nullptr; |
| 560 | 475 |
| 561 AppWindow* app_window = GetAppWindowForTask(active_task_id_); | 476 ArcAppWindow* app_window = GetAppWindowForTask(active_task_id_); |
| 562 if (app_window && | 477 if (app_window && |
| 563 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { | 478 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { |
| 564 return app_window->controller(); | 479 return app_window->controller(); |
| 565 } | 480 } |
| 566 | 481 |
| 567 for (auto& it : task_id_to_app_window_info_) { | 482 for (auto& it : task_id_to_app_window_info_) { |
| 568 AppWindow* app_window = it.second->app_window(); | 483 ArcAppWindow* app_window = it.second->app_window(); |
| 569 if (app_window && | 484 if (app_window && |
| 570 app_window->widget() == | 485 app_window->widget() == |
| 571 views::Widget::GetWidgetForNativeWindow(window)) { | 486 views::Widget::GetWidgetForNativeWindow(window)) { |
| 572 return it.second->app_window()->controller(); | 487 return it.second->app_window()->controller(); |
| 573 } | 488 } |
| 574 } | 489 } |
| 575 | 490 |
| 576 return nullptr; | 491 return nullptr; |
| 577 } | 492 } |
| 578 | 493 |
| 579 void ArcAppWindowLauncherController::OnWindowActivated( | 494 void ArcAppWindowLauncherController::OnWindowActivated( |
| 580 aura::client::ActivationChangeObserver::ActivationReason reason, | 495 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 581 aura::Window* gained_active, | 496 aura::Window* gained_active, |
| 582 aura::Window* lost_active) { | 497 aura::Window* lost_active) { |
| 583 AppWindowLauncherController::OnWindowActivated(reason, gained_active, | 498 AppWindowLauncherController::OnWindowActivated(reason, gained_active, |
| 584 lost_active); | 499 lost_active); |
| 585 OnTaskSetActive(active_task_id_); | 500 OnTaskSetActive(active_task_id_); |
| 586 } | 501 } |
| 587 | 502 |
| 588 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { | 503 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { |
| 589 for (auto& it : task_id_to_app_window_info_) { | 504 for (auto& it : task_id_to_app_window_info_) { |
| 590 AppWindow* app_window = it.second->app_window(); | 505 ArcAppWindow* app_window = it.second->app_window(); |
| 591 if (app_window) | 506 if (app_window) |
| 592 SetOrientationLockForAppWindow(app_window); | 507 SetOrientationLockForAppWindow(app_window); |
| 593 } | 508 } |
| 594 } | 509 } |
| 595 | 510 |
| 596 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { | 511 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { |
| 597 ash::ScreenOrientationController* orientation_controller = | 512 ash::ScreenOrientationController* orientation_controller = |
| 598 ash::Shell::Get()->screen_orientation_controller(); | 513 ash::Shell::Get()->screen_orientation_controller(); |
| 599 // Don't unlock one by one because it'll switch to next rotation. | 514 // Don't unlock one by one because it'll switch to next rotation. |
| 600 orientation_controller->UnlockAll(); | 515 orientation_controller->UnlockAll(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 626 const arc::ArcAppShelfId& app_shelf_id = app_window_info.app_shelf_id(); | 541 const arc::ArcAppShelfId& app_shelf_id = app_window_info.app_shelf_id(); |
| 627 const auto it = app_shelf_group_to_controller_map_.find(app_shelf_id); | 542 const auto it = app_shelf_group_to_controller_map_.find(app_shelf_id); |
| 628 if (it != app_shelf_group_to_controller_map_.end()) { | 543 if (it != app_shelf_group_to_controller_map_.end()) { |
| 629 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString()); | 544 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString()); |
| 630 it->second->AddTaskId(task_id); | 545 it->second->AddTaskId(task_id); |
| 631 return it->second; | 546 return it->second; |
| 632 } | 547 } |
| 633 | 548 |
| 634 std::unique_ptr<ArcAppWindowLauncherItemController> controller = | 549 std::unique_ptr<ArcAppWindowLauncherItemController> controller = |
| 635 base::MakeUnique<ArcAppWindowLauncherItemController>( | 550 base::MakeUnique<ArcAppWindowLauncherItemController>( |
| 636 app_shelf_id.ToString()); | 551 app_shelf_id.ToString(), owner()); |
| 637 ArcAppWindowLauncherItemController* item_controller = controller.get(); | 552 ArcAppWindowLauncherItemController* item_controller = controller.get(); |
| 638 const ash::ShelfID shelf_id(app_shelf_id.ToString()); | 553 const ash::ShelfID shelf_id(app_shelf_id.ToString()); |
| 639 if (!owner()->GetItem(shelf_id)) { | 554 if (!owner()->GetItem(shelf_id)) { |
| 640 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING); | 555 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING); |
| 641 } else { | 556 } else { |
| 642 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, | 557 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, |
| 643 std::move(controller)); | 558 std::move(controller)); |
| 644 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 559 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 645 } | 560 } |
| 646 item_controller->AddTaskId(task_id); | 561 item_controller->AddTaskId(task_id); |
| 647 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller; | 562 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller; |
| 648 return item_controller; | 563 return item_controller; |
| 649 } | 564 } |
| 650 | 565 |
| 651 void ArcAppWindowLauncherController::RegisterApp( | 566 void ArcAppWindowLauncherController::RegisterApp( |
| 652 AppWindowInfo* app_window_info) { | 567 AppWindowInfo* app_window_info) { |
| 653 AppWindow* app_window = app_window_info->app_window(); | 568 ArcAppWindow* app_window = app_window_info->app_window(); |
| 654 ArcAppWindowLauncherItemController* controller = | 569 ArcAppWindowLauncherItemController* controller = |
| 655 AttachControllerToTask(app_window->task_id(), *app_window_info); | 570 AttachControllerToTask(app_window->task_id(), *app_window_info); |
| 656 DCHECK(!controller->app_id().empty()); | 571 DCHECK(!controller->app_id().empty()); |
| 657 const ash::ShelfID shelf_id(controller->app_id()); | 572 const ash::ShelfID shelf_id(controller->app_id()); |
| 658 DCHECK(owner()->GetItem(shelf_id)); | 573 DCHECK(owner()->GetItem(shelf_id)); |
| 659 | 574 |
| 660 controller->AddWindow(app_window); | 575 controller->AddWindow(app_window); |
| 661 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 576 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 662 app_window->SetController(controller); | 577 app_window->SetController(controller); |
| 663 app_window->set_shelf_id(shelf_id); | 578 app_window->set_shelf_id(shelf_id); |
| 664 } | 579 } |
| 665 | 580 |
| 666 void ArcAppWindowLauncherController::UnregisterApp( | 581 void ArcAppWindowLauncherController::UnregisterApp( |
| 667 AppWindowInfo* app_window_info) { | 582 AppWindowInfo* app_window_info) { |
| 668 AppWindow* app_window = app_window_info->app_window(); | 583 ArcAppWindow* app_window = app_window_info->app_window(); |
| 669 if (!app_window) | 584 if (!app_window) |
| 670 return; | 585 return; |
| 671 | 586 |
| 672 ArcAppWindowLauncherItemController* controller = app_window->controller(); | 587 ArcAppWindowLauncherItemController* controller = app_window->controller(); |
| 673 if (controller) | 588 if (controller) |
| 674 controller->RemoveWindow(app_window); | 589 controller->RemoveWindow(app_window); |
| 675 app_window->ResetController(); | 590 app_window->SetController(nullptr); |
| 676 app_window_info->set_app_window(nullptr); | 591 app_window_info->set_app_window(nullptr); |
| 677 } | 592 } |
| 678 | 593 |
| 679 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( | 594 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( |
| 680 AppWindow* app_window) { | 595 ArcAppWindow* app_window) { |
| 681 aura::Window* window = app_window->widget()->GetNativeWindow(); | 596 aura::Window* window = app_window->widget()->GetNativeWindow(); |
| 682 if (!window) | 597 if (!window) |
| 683 return; | 598 return; |
| 684 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); | 599 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); |
| 685 arc::mojom::OrientationLock orientation_lock; | 600 arc::mojom::OrientationLock orientation_lock; |
| 686 | 601 |
| 687 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior = | 602 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior = |
| 688 ScreenOrientationController::LockCompletionBehavior::None; | 603 ScreenOrientationController::LockCompletionBehavior::None; |
| 689 if (info->has_requested_orientation_lock()) { | 604 if (info->has_requested_orientation_lock()) { |
| 690 orientation_lock = info->requested_orientation_lock(); | 605 orientation_lock = info->requested_orientation_lock(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 713 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); | 628 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); |
| 714 if (arc_app_id.empty()) | 629 if (arc_app_id.empty()) |
| 715 return -1; | 630 return -1; |
| 716 | 631 |
| 717 int task_id = -1; | 632 int task_id = -1; |
| 718 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 633 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| 719 return -1; | 634 return -1; |
| 720 | 635 |
| 721 return task_id; | 636 return task_id; |
| 722 } | 637 } |
| OLD | NEW |