Chromium Code Reviews| 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/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 22 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 23 #include "chrome/browser/ui/ash/launcher/arc_app_window.h" | |
| 23 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h" | 24 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h" |
| 24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 25 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 25 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 26 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 26 #include "components/arc/arc_bridge_service.h" | 27 #include "components/arc/arc_bridge_service.h" |
| 27 #include "components/exo/shell_surface.h" | 28 #include "components/exo/shell_surface.h" |
| 28 #include "components/signin/core/account_id/account_id.h" | 29 #include "components/signin/core/account_id/account_id.h" |
| 29 #include "components/user_manager/user_manager.h" | 30 #include "components/user_manager/user_manager.h" |
| 30 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" | 31 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" |
| 31 #include "ui/aura/client/aura_constants.h" | 32 #include "ui/aura/client/aura_constants.h" |
| 32 #include "ui/aura/env.h" | 33 #include "ui/aura/env.h" |
| 33 #include "ui/base/base_window.h" | 34 #include "ui/base/base_window.h" |
| 34 #include "ui/display/display.h" | 35 #include "ui/display/display.h" |
| 35 #include "ui/display/manager/display_manager.h" | 36 #include "ui/display/manager/display_manager.h" |
| 36 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 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( | 41 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom( |
| 47 arc::mojom::OrientationLock orientation_lock) { | 42 arc::mojom::OrientationLock orientation_lock) { |
| 48 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock); | 43 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock); |
| 49 switch (orientation_lock) { | 44 switch (orientation_lock) { |
| 50 case arc::mojom::OrientationLock::PORTRAIT: | 45 case arc::mojom::OrientationLock::PORTRAIT: |
| 51 return blink::kWebScreenOrientationLockPortrait; | 46 return blink::kWebScreenOrientationLockPortrait; |
| 52 case arc::mojom::OrientationLock::LANDSCAPE: | 47 case arc::mojom::OrientationLock::LANDSCAPE: |
| 53 return blink::kWebScreenOrientationLockLandscape; | 48 return blink::kWebScreenOrientationLockLandscape; |
| 54 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY: | 49 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY: |
| 55 return blink::kWebScreenOrientationLockPortraitPrimary; | 50 return blink::kWebScreenOrientationLockPortraitPrimary; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 69 using ash::ScreenOrientationController; | 64 using ash::ScreenOrientationController; |
| 70 | 65 |
| 71 // The information about the arc application window which has to be kept | 66 // The information about the arc application window which has to be kept |
| 72 // even when its AppWindow is not present. | 67 // even when its AppWindow is not present. |
| 73 class ArcAppWindowLauncherController::AppWindowInfo { | 68 class ArcAppWindowLauncherController::AppWindowInfo { |
| 74 public: | 69 public: |
| 75 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id) | 70 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id) |
| 76 : app_shelf_id_(app_shelf_id) {} | 71 : app_shelf_id_(app_shelf_id) {} |
| 77 ~AppWindowInfo() = default; | 72 ~AppWindowInfo() = default; |
| 78 | 73 |
| 74 void SetDescription(const std::string& title, | |
| 75 const std::vector<uint8_t>& icon_data_png) { | |
| 76 title_ = title; | |
|
nasko
2017/05/23 05:02:31
This data comes from untrusted process, so some ve
khmel
2017/05/23 15:33:28
Yes, it is expected that this is UTF_8. IIUC UTF8T
nasko
2017/05/23 21:52:29
It is not just a matter whether the conversion fun
khmel
2017/05/24 00:09:52
I tried to find similar but could not (well, name
| |
| 77 // Chrome has custom Play Store icon. Don't overwrite it. | |
| 78 if (app_shelf_id_.app_id() != arc::kPlayStoreAppId) | |
| 79 icon_data_png_ = icon_data_png; | |
|
nasko
2017/05/23 05:02:31
I don't know if there is much to be verified here,
khmel
2017/05/23 15:33:28
I can suggest to limit this by size. Normally this
reveman
2017/05/23 16:46:17
Oh, didn't know we used a sandboxed process for th
khmel
2017/05/23 16:52:49
I know only high level details:
https://cs.chromiu
nasko
2017/05/23 21:52:29
While decoding in sandboxed process is awesome for
khmel
2017/05/24 00:09:51
Acknowledged. Thanks for sharing your knowledge!
| |
| 80 } | |
| 81 | |
| 82 void set_app_window(std::unique_ptr<ArcAppWindow> window) { | |
| 83 app_window_ = std::move(window); | |
| 84 } | |
| 85 | |
| 79 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } | 86 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } |
| 80 | 87 |
| 81 bool has_requested_orientation_lock() const { | 88 bool has_requested_orientation_lock() const { |
| 82 return has_requested_orientation_lock_; | 89 return has_requested_orientation_lock_; |
| 83 } | 90 } |
| 84 | 91 |
| 85 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { | 92 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { |
| 86 has_requested_orientation_lock_ = true; | 93 has_requested_orientation_lock_ = true; |
| 87 requested_orientation_lock_ = lock; | 94 requested_orientation_lock_ = lock; |
| 88 } | 95 } |
| 89 | 96 |
| 90 arc::mojom::OrientationLock requested_orientation_lock() const { | 97 arc::mojom::OrientationLock requested_orientation_lock() const { |
| 91 return requested_orientation_lock_; | 98 return requested_orientation_lock_; |
| 92 } | 99 } |
| 93 | 100 |
| 94 void set_lock_completion_behavior( | 101 void set_lock_completion_behavior( |
| 95 ScreenOrientationController::LockCompletionBehavior lock_behavior) { | 102 ScreenOrientationController::LockCompletionBehavior lock_behavior) { |
| 96 lock_completion_behavior_ = lock_behavior; | 103 lock_completion_behavior_ = lock_behavior; |
| 97 } | 104 } |
| 98 | 105 |
| 99 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior() | 106 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior() |
| 100 const { | 107 const { |
| 101 return lock_completion_behavior_; | 108 return lock_completion_behavior_; |
| 102 } | 109 } |
| 103 | 110 |
| 104 void set_app_window(std::unique_ptr<AppWindow> window) { | 111 ArcAppWindow* app_window() { return app_window_.get(); } |
| 105 app_window_ = std::move(window); | |
| 106 } | |
| 107 | 112 |
| 108 AppWindow* app_window() { return app_window_.get(); } | 113 const std::string& title() const { return title_; } |
| 114 | |
| 115 const std::vector<uint8_t>& icon_data_png() const { return icon_data_png_; } | |
| 109 | 116 |
| 110 private: | 117 private: |
| 111 const arc::ArcAppShelfId app_shelf_id_; | 118 const arc::ArcAppShelfId app_shelf_id_; |
| 112 bool has_requested_orientation_lock_ = false; | 119 bool has_requested_orientation_lock_ = false; |
| 113 | 120 |
| 114 // If true, the orientation should be locked to the specific | 121 // If true, the orientation should be locked to the specific |
| 115 // orientation after the requested_orientation_lock is applied. | 122 // orientation after the requested_orientation_lock is applied. |
| 116 // This is meaningful only if the orientation is one of ::NONE, | 123 // This is meaningful only if the orientation is one of ::NONE, |
| 117 // ::PORTRAIT or ::LANDSCAPE. | 124 // ::PORTRAIT or ::LANDSCAPE. |
| 118 ScreenOrientationController::LockCompletionBehavior | 125 ScreenOrientationController::LockCompletionBehavior |
| 119 lock_completion_behavior_ = | 126 lock_completion_behavior_ = |
| 120 ScreenOrientationController::LockCompletionBehavior::None; | 127 ScreenOrientationController::LockCompletionBehavior::None; |
| 121 arc::mojom::OrientationLock requested_orientation_lock_ = | 128 arc::mojom::OrientationLock requested_orientation_lock_ = |
| 122 arc::mojom::OrientationLock::NONE; | 129 arc::mojom::OrientationLock::NONE; |
| 123 std::unique_ptr<AppWindow> app_window_; | 130 // Keeps overridden window title. |
| 131 std::string title_; | |
| 132 // Keeps overridden window icon. | |
| 133 std::vector<uint8_t> icon_data_png_; | |
| 134 std::unique_ptr<ArcAppWindow> app_window_; | |
| 124 | 135 |
| 125 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); | 136 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); |
| 126 }; | 137 }; |
| 127 | 138 |
| 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( | 139 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
| 250 ChromeLauncherController* owner) | 140 ChromeLauncherController* owner) |
| 251 : AppWindowLauncherController(owner) { | 141 : AppWindowLauncherController(owner) { |
| 252 if (arc::IsArcAllowedForProfile(owner->profile())) { | 142 if (arc::IsArcAllowedForProfile(owner->profile())) { |
| 253 observed_profile_ = owner->profile(); | 143 observed_profile_ = owner->profile(); |
| 254 StartObserving(observed_profile_); | 144 StartObserving(observed_profile_); |
| 255 } | 145 } |
| 256 } | 146 } |
| 257 | 147 |
| 258 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { | 148 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 UnregisterApp(info_it->second.get()); | 240 UnregisterApp(info_it->second.get()); |
| 351 } | 241 } |
| 352 } | 242 } |
| 353 | 243 |
| 354 ArcAppWindowLauncherController::AppWindowInfo* | 244 ArcAppWindowLauncherController::AppWindowInfo* |
| 355 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) { | 245 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) { |
| 356 const auto it = task_id_to_app_window_info_.find(task_id); | 246 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(); | 247 return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get(); |
| 358 } | 248 } |
| 359 | 249 |
| 360 ArcAppWindowLauncherController::AppWindow* | 250 ArcAppWindow* ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { |
| 361 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { | |
| 362 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | 251 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 363 return info ? info->app_window() : nullptr; | 252 return info ? info->app_window() : nullptr; |
| 364 } | 253 } |
| 365 | 254 |
| 366 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { | 255 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { |
| 367 for (auto* window : observed_windows_) | 256 for (auto* window : observed_windows_) |
| 368 AttachControllerToWindowIfNeeded(window); | 257 AttachControllerToWindowIfNeeded(window); |
| 369 } | 258 } |
| 370 | 259 |
| 371 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( | 260 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 392 // Create controller if we have task info. | 281 // Create controller if we have task info. |
| 393 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | 282 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 394 if (!info) { | 283 if (!info) { |
| 395 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id; | 284 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id; |
| 396 return; | 285 return; |
| 397 } | 286 } |
| 398 | 287 |
| 399 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 288 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 400 DCHECK(widget); | 289 DCHECK(widget); |
| 401 DCHECK(!info->app_window()); | 290 DCHECK(!info->app_window()); |
| 402 info->set_app_window( | 291 info->set_app_window(base::MakeUnique<ArcAppWindow>( |
| 403 base::MakeUnique<AppWindow>(task_id, info->app_shelf_id(), widget, this)); | 292 task_id, info->app_shelf_id(), widget, this)); |
| 293 info->app_window()->SetDescription(info->title(), info->icon_data_png()); | |
| 404 RegisterApp(info); | 294 RegisterApp(info); |
| 405 DCHECK(info->app_window()->controller()); | 295 DCHECK(info->app_window()->controller()); |
| 406 const ash::ShelfID shelf_id(info->app_window()->shelf_id()); | 296 const ash::ShelfID shelf_id(info->app_window()->shelf_id()); |
| 407 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize())); | 297 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize())); |
| 408 if (ash::Shell::Get() | 298 if (ash::Shell::Get() |
| 409 ->maximize_mode_controller() | 299 ->maximize_mode_controller() |
| 410 ->IsMaximizeModeWindowManagerEnabled()) { | 300 ->IsMaximizeModeWindowManagerEnabled()) { |
| 411 SetOrientationLockForAppWindow(info->app_window()); | 301 SetOrientationLockForAppWindow(info->app_window()); |
| 412 } | 302 } |
| 413 } | 303 } |
| 414 | 304 |
| 415 void ArcAppWindowLauncherController::OnAppReadyChanged( | 305 void ArcAppWindowLauncherController::OnAppReadyChanged( |
| 416 const std::string& arc_app_id, | 306 const std::string& arc_app_id, |
| 417 bool ready) { | 307 bool ready) { |
| 418 if (!ready) | 308 if (!ready) |
| 419 OnAppRemoved(arc_app_id); | 309 OnAppRemoved(arc_app_id); |
| 420 } | 310 } |
| 421 | 311 |
| 422 std::vector<int> ArcAppWindowLauncherController::GetTaskIdsForApp( | 312 std::vector<int> ArcAppWindowLauncherController::GetTaskIdsForApp( |
| 423 const std::string& arc_app_id) const { | 313 const std::string& arc_app_id) const { |
| 424 // Note, AppWindow is optional part for a task and it may be not created if | 314 // 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 | 315 // another full screen Android app is currently active. Use |
| 426 // |task_id_to_app_window_info_| that keeps currently running tasks info. | 316 // |task_id_to_app_window_info_| that keeps currently running tasks info. |
| 427 std::vector<int> task_ids; | 317 std::vector<int> task_ids; |
| 428 for (const auto& it : task_id_to_app_window_info_) { | 318 for (const auto& it : task_id_to_app_window_info_) { |
| 429 const AppWindowInfo* app_window_info = it.second.get(); | 319 const AppWindowInfo* app_window_info = it.second.get(); |
| 430 if (app_window_info->app_shelf_id().app_id() == arc_app_id) | 320 if (app_window_info->app_shelf_id().app_id() == arc_app_id) |
| 431 task_ids.push_back(it.first); | 321 task_ids.push_back(it.first); |
| 432 } | 322 } |
| 433 | 323 |
| 434 return task_ids; | 324 return task_ids; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 459 return; | 349 return; |
| 460 | 350 |
| 461 AttachControllerToWindowsIfNeeded(); | 351 AttachControllerToWindowsIfNeeded(); |
| 462 | 352 |
| 463 // Some tasks can be started in background and might have no window until | 353 // Some tasks can be started in background and might have no window until |
| 464 // pushed to the front. We need its representation on the shelf to give a user | 354 // pushed to the front. We need its representation on the shelf to give a user |
| 465 // control over it. | 355 // control over it. |
| 466 AttachControllerToTask(task_id, *task_id_to_app_window_info_[task_id]); | 356 AttachControllerToTask(task_id, *task_id_to_app_window_info_[task_id]); |
| 467 } | 357 } |
| 468 | 358 |
| 359 void ArcAppWindowLauncherController::OnTaskDescriptionUpdated( | |
| 360 int32_t task_id, | |
| 361 const std::string& label, | |
| 362 const std::vector<uint8_t>& icon_png_data) { | |
| 363 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | |
| 364 if (info) { | |
| 365 info->SetDescription(label, icon_png_data); | |
| 366 if (info->app_window()) | |
| 367 info->app_window()->SetDescription(label, icon_png_data); | |
| 368 } | |
| 369 } | |
| 370 | |
| 469 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 371 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
| 470 auto it = task_id_to_app_window_info_.find(task_id); | 372 auto it = task_id_to_app_window_info_.find(task_id); |
| 471 if (it == task_id_to_app_window_info_.end()) | 373 if (it == task_id_to_app_window_info_.end()) |
| 472 return; | 374 return; |
| 473 | 375 |
| 474 UnregisterApp(it->second.get()); | 376 UnregisterApp(it->second.get()); |
| 475 | 377 |
| 476 // Check if we may close controller now, at this point we can safely remove | 378 // Check if we may close controller now, at this point we can safely remove |
| 477 // controllers without window. | 379 // controllers without window. |
| 478 auto it_controller = | 380 auto it_controller = |
| 479 app_shelf_group_to_controller_map_.find(it->second->app_shelf_id()); | 381 app_shelf_group_to_controller_map_.find(it->second->app_shelf_id()); |
| 480 if (it_controller != app_shelf_group_to_controller_map_.end()) { | 382 if (it_controller != app_shelf_group_to_controller_map_.end()) { |
| 481 it_controller->second->RemoveTaskId(task_id); | 383 it_controller->second->RemoveTaskId(task_id); |
| 482 if (!it_controller->second->HasAnyTasks()) { | 384 if (!it_controller->second->HasAnyTasks()) { |
| 483 owner()->CloseLauncherItem(it_controller->second->shelf_id()); | 385 owner()->CloseLauncherItem(it_controller->second->shelf_id()); |
| 484 app_shelf_group_to_controller_map_.erase(it_controller); | 386 app_shelf_group_to_controller_map_.erase(it_controller); |
| 485 } | 387 } |
| 486 } | 388 } |
| 487 | 389 |
| 488 task_id_to_app_window_info_.erase(it); | 390 task_id_to_app_window_info_.erase(it); |
| 489 } | 391 } |
| 490 | 392 |
| 491 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { | |
| 492 if (observed_profile_ != owner()->profile()) { | |
| 493 active_task_id_ = task_id; | |
| 494 return; | |
| 495 } | |
| 496 | |
| 497 AppWindow* previous_app_window = GetAppWindowForTask(active_task_id_); | |
| 498 if (previous_app_window) { | |
| 499 owner()->SetItemStatus(previous_app_window->shelf_id(), | |
| 500 ash::STATUS_RUNNING); | |
| 501 previous_app_window->SetFullscreenMode( | |
| 502 previous_app_window->widget() && | |
| 503 previous_app_window->widget()->IsFullscreen() | |
| 504 ? FullScreenMode::ACTIVE | |
| 505 : FullScreenMode::NON_ACTIVE); | |
| 506 } | |
| 507 | |
| 508 active_task_id_ = task_id; | |
| 509 | |
| 510 AppWindow* current_app_window = GetAppWindowForTask(task_id); | |
| 511 if (current_app_window) { | |
| 512 owner()->SetItemStatus( | |
| 513 current_app_window->shelf_id(), | |
| 514 current_app_window->widget() && current_app_window->IsActive() | |
| 515 ? ash::STATUS_ACTIVE | |
| 516 : ash::STATUS_RUNNING); | |
| 517 // TODO(reveman): Figure out how to support fullscreen in interleaved | |
| 518 // window mode. | |
| 519 // if (new_active_app_it->second->widget()) { | |
| 520 // new_active_app_it->second->widget()->SetFullscreen( | |
| 521 // new_active_app_it->second->fullscreen_mode() == | |
| 522 // FullScreenMode::ACTIVE); | |
| 523 // } | |
| 524 } | |
| 525 } | |
| 526 | |
| 527 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( | 393 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( |
| 528 int32_t task_id, | 394 int32_t task_id, |
| 529 const arc::mojom::OrientationLock orientation_lock) { | 395 const arc::mojom::OrientationLock orientation_lock) { |
| 530 // Don't save to AppInfo in prefs because this is requested in runtime. | 396 // Don't save to AppInfo in prefs because this is requested in runtime. |
| 531 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); | 397 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); |
| 532 DCHECK(info); | 398 DCHECK(info); |
| 533 if (!info) | 399 if (!info) |
| 534 return; | 400 return; |
| 535 | 401 |
| 536 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { | 402 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { |
| 537 info->set_lock_completion_behavior( | 403 info->set_lock_completion_behavior( |
| 538 ScreenOrientationController::LockCompletionBehavior::DisableSensor); | 404 ScreenOrientationController::LockCompletionBehavior::DisableSensor); |
| 539 if (!info->has_requested_orientation_lock()) { | 405 if (!info->has_requested_orientation_lock()) { |
| 540 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE); | 406 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE); |
| 541 } | 407 } |
| 542 } else { | 408 } else { |
| 543 info->set_requested_orientation_lock(orientation_lock); | 409 info->set_requested_orientation_lock(orientation_lock); |
| 544 info->set_lock_completion_behavior( | 410 info->set_lock_completion_behavior( |
| 545 ScreenOrientationController::LockCompletionBehavior::None); | 411 ScreenOrientationController::LockCompletionBehavior::None); |
| 546 } | 412 } |
| 547 | 413 |
| 548 if (ash::Shell::Get() | 414 if (ash::Shell::Get() |
| 549 ->maximize_mode_controller() | 415 ->maximize_mode_controller() |
| 550 ->IsMaximizeModeWindowManagerEnabled()) { | 416 ->IsMaximizeModeWindowManagerEnabled()) { |
| 551 AppWindow* app_window = info->app_window(); | 417 ArcAppWindow* app_window = info->app_window(); |
| 552 if (app_window) | 418 if (app_window) |
| 553 SetOrientationLockForAppWindow(app_window); | 419 SetOrientationLockForAppWindow(app_window); |
| 554 } | 420 } |
| 555 } | 421 } |
| 556 | 422 |
| 423 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { | |
| 424 if (observed_profile_ != owner()->profile()) { | |
| 425 active_task_id_ = task_id; | |
| 426 return; | |
| 427 } | |
| 428 | |
| 429 ArcAppWindow* previous_app_window = GetAppWindowForTask(active_task_id_); | |
| 430 if (previous_app_window) { | |
| 431 owner()->SetItemStatus(previous_app_window->shelf_id(), | |
| 432 ash::STATUS_RUNNING); | |
| 433 previous_app_window->SetFullscreenMode( | |
| 434 previous_app_window->widget() && | |
| 435 previous_app_window->widget()->IsFullscreen() | |
| 436 ? ArcAppWindow::FullScreenMode::ACTIVE | |
| 437 : ArcAppWindow::FullScreenMode::NON_ACTIVE); | |
| 438 } | |
| 439 | |
| 440 active_task_id_ = task_id; | |
| 441 | |
| 442 ArcAppWindow* current_app_window = GetAppWindowForTask(task_id); | |
| 443 if (current_app_window) { | |
| 444 if (current_app_window->widget() && current_app_window->IsActive()) { | |
| 445 owner()->SetItemStatus(current_app_window->shelf_id(), | |
| 446 ash::STATUS_ACTIVE); | |
| 447 current_app_window->controller()->SetActiveWindow( | |
| 448 current_app_window->GetNativeWindow()); | |
| 449 } else { | |
| 450 owner()->SetItemStatus(current_app_window->shelf_id(), | |
| 451 ash::STATUS_RUNNING); | |
| 452 } | |
| 453 // TODO(reveman): Figure out how to support fullscreen in interleaved | |
| 454 // window mode. | |
| 455 // if (new_active_app_it->second->widget()) { | |
| 456 // new_active_app_it->second->widget()->SetFullscreen( | |
| 457 // new_active_app_it->second->fullscreen_mode() == | |
| 458 // ArcAppWindow::FullScreenMode::ACTIVE); | |
| 459 // } | |
| 460 } | |
| 461 } | |
| 462 | |
| 557 AppWindowLauncherItemController* | 463 AppWindowLauncherItemController* |
| 558 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { | 464 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { |
| 559 if (!window) | 465 if (!window) |
| 560 return nullptr; | 466 return nullptr; |
| 561 | 467 |
| 562 AppWindow* app_window = GetAppWindowForTask(active_task_id_); | 468 ArcAppWindow* app_window = GetAppWindowForTask(active_task_id_); |
| 563 if (app_window && | 469 if (app_window && |
| 564 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { | 470 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { |
| 565 return app_window->controller(); | 471 return app_window->controller(); |
| 566 } | 472 } |
| 567 | 473 |
| 568 for (auto& it : task_id_to_app_window_info_) { | 474 for (auto& it : task_id_to_app_window_info_) { |
| 569 AppWindow* app_window = it.second->app_window(); | 475 ArcAppWindow* app_window = it.second->app_window(); |
| 570 if (app_window && | 476 if (app_window && |
| 571 app_window->widget() == | 477 app_window->widget() == |
| 572 views::Widget::GetWidgetForNativeWindow(window)) { | 478 views::Widget::GetWidgetForNativeWindow(window)) { |
| 573 return it.second->app_window()->controller(); | 479 return it.second->app_window()->controller(); |
| 574 } | 480 } |
| 575 } | 481 } |
| 576 | 482 |
| 577 return nullptr; | 483 return nullptr; |
| 578 } | 484 } |
| 579 | 485 |
| 580 void ArcAppWindowLauncherController::OnWindowActivated( | 486 void ArcAppWindowLauncherController::OnWindowActivated( |
| 581 aura::client::ActivationChangeObserver::ActivationReason reason, | 487 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 582 aura::Window* gained_active, | 488 aura::Window* gained_active, |
| 583 aura::Window* lost_active) { | 489 aura::Window* lost_active) { |
| 584 AppWindowLauncherController::OnWindowActivated(reason, gained_active, | 490 AppWindowLauncherController::OnWindowActivated(reason, gained_active, |
| 585 lost_active); | 491 lost_active); |
| 586 OnTaskSetActive(active_task_id_); | 492 OnTaskSetActive(active_task_id_); |
| 587 } | 493 } |
| 588 | 494 |
| 589 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { | 495 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { |
| 590 for (auto& it : task_id_to_app_window_info_) { | 496 for (auto& it : task_id_to_app_window_info_) { |
| 591 AppWindow* app_window = it.second->app_window(); | 497 ArcAppWindow* app_window = it.second->app_window(); |
| 592 if (app_window) | 498 if (app_window) |
| 593 SetOrientationLockForAppWindow(app_window); | 499 SetOrientationLockForAppWindow(app_window); |
| 594 } | 500 } |
| 595 } | 501 } |
| 596 | 502 |
| 597 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { | 503 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { |
| 598 ash::ScreenOrientationController* orientation_controller = | 504 ash::ScreenOrientationController* orientation_controller = |
| 599 ash::Shell::Get()->screen_orientation_controller(); | 505 ash::Shell::Get()->screen_orientation_controller(); |
| 600 // Don't unlock one by one because it'll switch to next rotation. | 506 // Don't unlock one by one because it'll switch to next rotation. |
| 601 orientation_controller->UnlockAll(); | 507 orientation_controller->UnlockAll(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 627 const arc::ArcAppShelfId& app_shelf_id = app_window_info.app_shelf_id(); | 533 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); | 534 const auto it = app_shelf_group_to_controller_map_.find(app_shelf_id); |
| 629 if (it != app_shelf_group_to_controller_map_.end()) { | 535 if (it != app_shelf_group_to_controller_map_.end()) { |
| 630 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString()); | 536 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString()); |
| 631 it->second->AddTaskId(task_id); | 537 it->second->AddTaskId(task_id); |
| 632 return it->second; | 538 return it->second; |
| 633 } | 539 } |
| 634 | 540 |
| 635 std::unique_ptr<ArcAppWindowLauncherItemController> controller = | 541 std::unique_ptr<ArcAppWindowLauncherItemController> controller = |
| 636 base::MakeUnique<ArcAppWindowLauncherItemController>( | 542 base::MakeUnique<ArcAppWindowLauncherItemController>( |
| 637 app_shelf_id.ToString()); | 543 app_shelf_id.ToString(), owner()); |
| 638 ArcAppWindowLauncherItemController* item_controller = controller.get(); | 544 ArcAppWindowLauncherItemController* item_controller = controller.get(); |
| 639 const ash::ShelfID shelf_id(app_shelf_id.ToString()); | 545 const ash::ShelfID shelf_id(app_shelf_id.ToString()); |
| 640 if (!owner()->GetItem(shelf_id)) { | 546 if (!owner()->GetItem(shelf_id)) { |
| 641 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING); | 547 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING); |
| 642 } else { | 548 } else { |
| 643 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, | 549 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, |
| 644 std::move(controller)); | 550 std::move(controller)); |
| 645 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 551 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 646 } | 552 } |
| 647 item_controller->AddTaskId(task_id); | 553 item_controller->AddTaskId(task_id); |
| 648 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller; | 554 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller; |
| 649 return item_controller; | 555 return item_controller; |
| 650 } | 556 } |
| 651 | 557 |
| 652 void ArcAppWindowLauncherController::RegisterApp( | 558 void ArcAppWindowLauncherController::RegisterApp( |
| 653 AppWindowInfo* app_window_info) { | 559 AppWindowInfo* app_window_info) { |
| 654 AppWindow* app_window = app_window_info->app_window(); | 560 ArcAppWindow* app_window = app_window_info->app_window(); |
| 655 ArcAppWindowLauncherItemController* controller = | 561 ArcAppWindowLauncherItemController* controller = |
| 656 AttachControllerToTask(app_window->task_id(), *app_window_info); | 562 AttachControllerToTask(app_window->task_id(), *app_window_info); |
| 657 DCHECK(!controller->app_id().empty()); | 563 DCHECK(!controller->app_id().empty()); |
| 658 const ash::ShelfID shelf_id(controller->app_id()); | 564 const ash::ShelfID shelf_id(controller->app_id()); |
| 659 DCHECK(owner()->GetItem(shelf_id)); | 565 DCHECK(owner()->GetItem(shelf_id)); |
| 660 | 566 |
| 661 controller->AddWindow(app_window); | 567 controller->AddWindow(app_window); |
| 662 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | 568 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 663 app_window->SetController(controller); | 569 app_window->SetController(controller); |
| 664 app_window->set_shelf_id(shelf_id); | 570 app_window->set_shelf_id(shelf_id); |
| 665 } | 571 } |
| 666 | 572 |
| 667 void ArcAppWindowLauncherController::UnregisterApp( | 573 void ArcAppWindowLauncherController::UnregisterApp( |
| 668 AppWindowInfo* app_window_info) { | 574 AppWindowInfo* app_window_info) { |
| 669 AppWindow* app_window = app_window_info->app_window(); | 575 ArcAppWindow* app_window = app_window_info->app_window(); |
| 670 if (!app_window) | 576 if (!app_window) |
| 671 return; | 577 return; |
| 672 | 578 |
| 673 ArcAppWindowLauncherItemController* controller = app_window->controller(); | 579 ArcAppWindowLauncherItemController* controller = app_window->controller(); |
| 674 if (controller) | 580 if (controller) |
| 675 controller->RemoveWindow(app_window); | 581 controller->RemoveWindow(app_window); |
| 676 app_window->ResetController(); | 582 app_window->SetController(nullptr); |
| 677 app_window_info->set_app_window(nullptr); | 583 app_window_info->set_app_window(nullptr); |
| 678 } | 584 } |
| 679 | 585 |
| 680 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( | 586 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( |
| 681 AppWindow* app_window) { | 587 ArcAppWindow* app_window) { |
| 682 ash::WmWindow* window = | 588 ash::WmWindow* window = |
| 683 ash::WmWindow::Get(app_window->widget()->GetNativeWindow()); | 589 ash::WmWindow::Get(app_window->widget()->GetNativeWindow()); |
| 684 if (!window) | 590 if (!window) |
| 685 return; | 591 return; |
| 686 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); | 592 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); |
| 687 arc::mojom::OrientationLock orientation_lock; | 593 arc::mojom::OrientationLock orientation_lock; |
| 688 | 594 |
| 689 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior = | 595 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior = |
| 690 ScreenOrientationController::LockCompletionBehavior::None; | 596 ScreenOrientationController::LockCompletionBehavior::None; |
| 691 if (info->has_requested_orientation_lock()) { | 597 if (info->has_requested_orientation_lock()) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 715 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); | 621 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); |
| 716 if (arc_app_id.empty()) | 622 if (arc_app_id.empty()) |
| 717 return -1; | 623 return -1; |
| 718 | 624 |
| 719 int task_id = -1; | 625 int task_id = -1; |
| 720 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 626 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
| 721 return -1; | 627 return -1; |
| 722 | 628 |
| 723 return task_id; | 629 return task_id; |
| 724 } | 630 } |
| OLD | NEW |