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