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 "ash/common/wm/window_state.h" | 6 #include "ash/common/wm/window_state.h" |
7 #include "ash/shelf/shelf_util.h" | 7 #include "ash/shelf/shelf_util.h" |
8 #include "ash/wm/window_state_aura.h" | 8 #include "ash/wm/window_state_aura.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 11 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
12 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 12 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 14 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
15 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller
.h" | 15 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller
.h" |
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
17 #include "components/arc/arc_bridge_service.h" | 18 #include "components/arc/arc_bridge_service.h" |
18 #include "components/exo/shell_surface.h" | 19 #include "components/exo/shell_surface.h" |
| 20 #include "components/signin/core/account_id/account_id.h" |
| 21 #include "components/user_manager/user_manager.h" |
19 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
20 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
21 #include "ui/base/base_window.h" | 24 #include "ui/base/base_window.h" |
22 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
23 | 26 |
24 namespace { | 27 namespace { |
25 | 28 |
26 enum class FullScreenMode { | 29 enum class FullScreenMode { |
27 NOT_DEFINED, // Fullscreen mode was not defined. | 30 NOT_DEFINED, // Fullscreen mode was not defined. |
28 ACTIVE, // Fullscreen is activated for an app. | 31 ACTIVE, // Fullscreen is activated for an app. |
29 NON_ACTIVE, // Fullscreen was not activated for an app. | 32 NON_ACTIVE, // Fullscreen was not activated for an app. |
30 }; | 33 }; |
31 | 34 |
32 std::string GetShelfAppId(const std::string& app_id) { | 35 std::string GetShelfAppId(const std::string& app_id) { |
33 return app_id == arc::kPlayStoreAppId ? ArcSupportHost::kHostAppId : app_id; | 36 return app_id == arc::kPlayStoreAppId ? ArcSupportHost::kHostAppId : app_id; |
34 } | 37 } |
35 } // namespace | 38 } // namespace |
36 | 39 |
37 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { | 40 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { |
38 public: | 41 public: |
39 AppWindow(int task_id, ArcAppWindowLauncherController* owner) | 42 AppWindow(int task_id, |
40 : task_id_(task_id), owner_(owner) {} | 43 const std::string app_id, |
| 44 ArcAppWindowLauncherController* owner) |
| 45 : task_id_(task_id), app_id_(app_id), owner_(owner) {} |
41 ~AppWindow() {} | 46 ~AppWindow() {} |
42 | 47 |
43 void SetController(ArcAppWindowLauncherItemController* controller) { | 48 void SetController(ArcAppWindowLauncherItemController* controller) { |
44 DCHECK(!controller_ && controller); | 49 DCHECK(!controller_ && controller); |
45 controller_ = controller; | 50 controller_ = controller; |
46 } | 51 } |
47 | 52 |
48 void SetFullscreenMode(FullScreenMode mode) { | 53 void SetFullscreenMode(FullScreenMode mode) { |
49 DCHECK(mode != FullScreenMode::NOT_DEFINED); | 54 DCHECK(mode != FullScreenMode::NOT_DEFINED); |
50 fullscreen_mode_ = mode; | 55 fullscreen_mode_ = mode; |
51 } | 56 } |
52 | 57 |
53 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } | 58 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } |
54 | 59 |
55 int task_id() const { return task_id_; } | 60 int task_id() const { return task_id_; } |
56 | 61 |
57 ash::ShelfID shelf_id() const { return shelf_id_; } | 62 ash::ShelfID shelf_id() const { return shelf_id_; } |
58 | 63 |
59 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } | 64 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } |
60 | 65 |
61 views::Widget* widget() const { return widget_; } | 66 views::Widget* widget() const { return widget_; } |
62 | 67 |
63 void set_widget(views::Widget* widget) { widget_ = widget; } | 68 void set_widget(views::Widget* widget) { widget_ = widget; } |
64 | 69 |
65 ArcAppWindowLauncherItemController* controller() { return controller_; } | 70 ArcAppWindowLauncherItemController* controller() { return controller_; } |
66 | 71 |
| 72 const std::string app_id() { return app_id_; } |
| 73 |
67 // ui::BaseWindow: | 74 // ui::BaseWindow: |
68 bool IsActive() const override { | 75 bool IsActive() const override { |
69 return widget_ && widget_->IsActive() && | 76 return widget_ && widget_->IsActive() && |
70 owner_->active_task_id_ == task_id_; | 77 owner_->active_task_id_ == task_id_; |
71 } | 78 } |
72 | 79 |
73 bool IsMaximized() const override { | 80 bool IsMaximized() const override { |
74 NOTREACHED(); | 81 NOTREACHED(); |
75 return false; | 82 return false; |
76 } | 83 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 if (bridge_service->app_version() < 3) { | 167 if (bridge_service->app_version() < 3) { |
161 VLOG(2) << "Arc Bridge has old version for apps." | 168 VLOG(2) << "Arc Bridge has old version for apps." |
162 << bridge_service->app_version(); | 169 << bridge_service->app_version(); |
163 return nullptr; | 170 return nullptr; |
164 } | 171 } |
165 return app_instance; | 172 return app_instance; |
166 } | 173 } |
167 | 174 |
168 int task_id_; | 175 int task_id_; |
169 ash::ShelfID shelf_id_ = 0; | 176 ash::ShelfID shelf_id_ = 0; |
| 177 std::string app_id_; |
170 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; | 178 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; |
171 // Unowned pointers | 179 // Unowned pointers |
172 ArcAppWindowLauncherController* owner_; | 180 ArcAppWindowLauncherController* owner_; |
173 ArcAppWindowLauncherItemController* controller_ = nullptr; | 181 ArcAppWindowLauncherItemController* controller_ = nullptr; |
174 // Unowned pointer, represents host Arc window. | 182 // Unowned pointer, represents host Arc window. |
175 views::Widget* widget_ = nullptr; | 183 views::Widget* widget_ = nullptr; |
176 | 184 |
177 DISALLOW_COPY_AND_ASSIGN(AppWindow); | 185 DISALLOW_COPY_AND_ASSIGN(AppWindow); |
178 }; | 186 }; |
179 | 187 |
180 ArcAppWindowLauncherController::ArcAppWindowLauncherController( | 188 ArcAppWindowLauncherController::ArcAppWindowLauncherController( |
181 ChromeLauncherController* owner) | 189 ChromeLauncherController* owner) |
182 : AppWindowLauncherController(owner) { | 190 : AppWindowLauncherController(owner) { |
183 if (arc::ArcAuthService::IsAllowedForProfile(owner->profile())) { | 191 if (arc::ArcAuthService::IsAllowedForProfile(owner->profile())) { |
184 observed_profile_ = owner->profile(); | 192 observed_profile_ = owner->profile(); |
185 StartObserving(observed_profile_); | 193 StartObserving(observed_profile_); |
186 } | 194 } |
187 } | 195 } |
188 | 196 |
189 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { | 197 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { |
190 if (observed_profile_) | 198 if (observed_profile_) |
191 StopObserving(observed_profile_); | 199 StopObserving(observed_profile_); |
192 } | 200 } |
193 | 201 |
194 void ArcAppWindowLauncherController::ActiveUserChanged( | 202 void ArcAppWindowLauncherController::ActiveUserChanged( |
195 const std::string& user_email) { | 203 const std::string& user_email) { |
196 // TODO(xdai): Traverse the Arc App list to show / hide the apps one by one | 204 for (auto& it : task_id_to_app_window_) { |
197 // if there are Arc Apps running. | 205 AppWindow* app_window = it.second.get(); |
| 206 if (user_email == |
| 207 user_manager::UserManager::Get() |
| 208 ->GetPrimaryUser() |
| 209 ->GetAccountId() |
| 210 .GetUserEmail()) { |
| 211 RegisterApp(app_window); |
| 212 } else { |
| 213 UnregisterApp(app_window); |
| 214 } |
| 215 } |
198 } | 216 } |
199 | 217 |
200 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( | 218 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( |
201 Profile* profile) { | 219 Profile* profile) { |
202 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); | 220 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); |
203 } | 221 } |
204 | 222 |
205 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { | 223 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { |
206 // Arc windows has type WINDOW_TYPE_NORMAL. | 224 // Arc windows has type WINDOW_TYPE_NORMAL. |
207 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) | 225 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 const std::string app_id = exo::ShellSurface::GetApplicationId(window); | 262 const std::string app_id = exo::ShellSurface::GetApplicationId(window); |
245 if (app_id.empty()) | 263 if (app_id.empty()) |
246 return; | 264 return; |
247 | 265 |
248 int task_id = -1; | 266 int task_id = -1; |
249 if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) | 267 if (sscanf(app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) |
250 return; | 268 return; |
251 | 269 |
252 if (task_id) { | 270 if (task_id) { |
253 AppWindow* app_window = GetAppWindowForTask(task_id); | 271 AppWindow* app_window = GetAppWindowForTask(task_id); |
254 if (app_window) | 272 if (app_window) { |
255 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); | 273 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); |
| 274 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( |
| 275 window, |
| 276 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); |
| 277 } |
256 } | 278 } |
257 } | 279 } |
258 | 280 |
259 void ArcAppWindowLauncherController::OnAppReadyChanged( | 281 void ArcAppWindowLauncherController::OnAppReadyChanged( |
260 const std::string& app_id, | 282 const std::string& app_id, |
261 bool ready) { | 283 bool ready) { |
262 if (!ready) | 284 if (!ready) |
263 OnAppRemoved(app_id); | 285 OnAppRemoved(app_id); |
264 } | 286 } |
265 | 287 |
(...skipping 15 matching lines...) Expand all Loading... |
281 | 303 |
282 DCHECK(app_controller_map_.find(app_id) == app_controller_map_.end()); | 304 DCHECK(app_controller_map_.find(app_id) == app_controller_map_.end()); |
283 } | 305 } |
284 | 306 |
285 void ArcAppWindowLauncherController::OnTaskCreated( | 307 void ArcAppWindowLauncherController::OnTaskCreated( |
286 int task_id, | 308 int task_id, |
287 const std::string& package_name, | 309 const std::string& package_name, |
288 const std::string& activity_name) { | 310 const std::string& activity_name) { |
289 DCHECK(!GetAppWindowForTask(task_id)); | 311 DCHECK(!GetAppWindowForTask(task_id)); |
290 | 312 |
291 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, this)); | |
292 | |
293 const std::string app_id = | 313 const std::string app_id = |
294 GetShelfAppId(ArcAppListPrefs::GetAppId(package_name, activity_name)); | 314 GetShelfAppId(ArcAppListPrefs::GetAppId(package_name, activity_name)); |
295 | 315 |
296 ArcAppWindowLauncherItemController* controller; | 316 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); |
297 AppControllerMap::iterator it = app_controller_map_.find(app_id); | 317 RegisterApp(app_window.get()); |
298 ash::ShelfID shelf_id = 0; | |
299 if (it != app_controller_map_.end()) { | |
300 controller = it->second; | |
301 DCHECK_EQ(controller->app_id(), app_id); | |
302 shelf_id = controller->shelf_id(); | |
303 } else { | |
304 controller = new ArcAppWindowLauncherItemController(app_id, owner()); | |
305 shelf_id = owner()->GetShelfIDForAppID(app_id); | |
306 if (shelf_id == 0) { | |
307 // Map Play Store shelf icon to Arc Support host, to share one entry. | |
308 shelf_id = owner()->CreateAppLauncherItem(controller, app_id, | |
309 ash::STATUS_RUNNING); | |
310 } else { | |
311 owner()->SetItemController(shelf_id, controller); | |
312 } | |
313 app_controller_map_[app_id] = controller; | |
314 } | |
315 controller->AddWindow(app_window.get()); | |
316 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | |
317 app_window->SetController(controller); | |
318 app_window->set_shelf_id(shelf_id); | |
319 | 318 |
320 task_id_to_app_window_[task_id] = std::move(app_window); | 319 task_id_to_app_window_[task_id] = std::move(app_window); |
321 | 320 |
322 for (auto window : observed_windows_) | 321 for (auto window : observed_windows_) |
323 CheckForAppWindowWidget(window); | 322 CheckForAppWindowWidget(window); |
324 } | 323 } |
325 | 324 |
326 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { | 325 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { |
327 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); | 326 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); |
328 if (it == task_id_to_app_window_.end()) | 327 if (it == task_id_to_app_window_.end()) |
329 return; | 328 return; |
330 | 329 |
331 AppWindow* app_window = it->second.get(); | 330 AppWindow* app_window = it->second.get(); |
332 ArcAppWindowLauncherItemController* controller = app_window->controller(); | 331 UnregisterApp(app_window); |
333 DCHECK(controller); | |
334 const std::string app_id = controller->app_id(); | |
335 controller->RemoveWindow(app_window); | |
336 if (!controller->window_count()) { | |
337 ash::ShelfID shelf_id = app_window->shelf_id(); | |
338 DCHECK(shelf_id); | |
339 owner()->CloseLauncherItem(shelf_id); | |
340 AppControllerMap::iterator it2 = app_controller_map_.find(app_id); | |
341 DCHECK(it2 != app_controller_map_.end()); | |
342 app_controller_map_.erase(it2); | |
343 } | |
344 | 332 |
345 task_id_to_app_window_.erase(it); | 333 task_id_to_app_window_.erase(it); |
346 } | 334 } |
347 | 335 |
348 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { | 336 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { |
| 337 if (observed_profile_ != owner()->profile()) |
| 338 return; |
| 339 |
349 TaskIdToAppWindow::iterator previous_active_app_it = | 340 TaskIdToAppWindow::iterator previous_active_app_it = |
350 task_id_to_app_window_.find(active_task_id_); | 341 task_id_to_app_window_.find(active_task_id_); |
351 if (previous_active_app_it != task_id_to_app_window_.end()) { | 342 if (previous_active_app_it != task_id_to_app_window_.end()) { |
352 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), | 343 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), |
353 ash::STATUS_RUNNING); | 344 ash::STATUS_RUNNING); |
354 previous_active_app_it->second->SetFullscreenMode( | 345 previous_active_app_it->second->SetFullscreenMode( |
355 previous_active_app_it->second->widget() && | 346 previous_active_app_it->second->widget() && |
356 previous_active_app_it->second->widget()->IsFullscreen() | 347 previous_active_app_it->second->widget()->IsFullscreen() |
357 ? FullScreenMode::ACTIVE | 348 ? FullScreenMode::ACTIVE |
358 : FullScreenMode::NON_ACTIVE); | 349 : FullScreenMode::NON_ACTIVE); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 404 |
414 void ArcAppWindowLauncherController::StopObserving(Profile* profile) { | 405 void ArcAppWindowLauncherController::StopObserving(Profile* profile) { |
415 for (auto window : observed_windows_) | 406 for (auto window : observed_windows_) |
416 window->RemoveObserver(this); | 407 window->RemoveObserver(this); |
417 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); | 408 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); |
418 prefs->RemoveObserver(this); | 409 prefs->RemoveObserver(this); |
419 aura::Env* env = aura::Env::GetInstanceDontCreate(); | 410 aura::Env* env = aura::Env::GetInstanceDontCreate(); |
420 if (env) | 411 if (env) |
421 env->RemoveObserver(this); | 412 env->RemoveObserver(this); |
422 } | 413 } |
| 414 |
| 415 void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) { |
| 416 const std::string app_id = app_window->app_id(); |
| 417 DCHECK(!app_id.empty()); |
| 418 |
| 419 ArcAppWindowLauncherItemController* controller; |
| 420 AppControllerMap::iterator it = app_controller_map_.find(app_id); |
| 421 ash::ShelfID shelf_id = 0; |
| 422 if (it != app_controller_map_.end()) { |
| 423 controller = it->second; |
| 424 DCHECK_EQ(controller->app_id(), app_id); |
| 425 shelf_id = controller->shelf_id(); |
| 426 } else { |
| 427 controller = new ArcAppWindowLauncherItemController(app_id, owner()); |
| 428 shelf_id = owner()->GetShelfIDForAppID(app_id); |
| 429 if (shelf_id == 0) { |
| 430 // Map Play Store shelf icon to Arc Support host, to share one entry. |
| 431 shelf_id = owner()->CreateAppLauncherItem(controller, app_id, |
| 432 ash::STATUS_RUNNING); |
| 433 } else { |
| 434 owner()->SetItemController(shelf_id, controller); |
| 435 } |
| 436 app_controller_map_[app_id] = controller; |
| 437 } |
| 438 controller->AddWindow(app_window); |
| 439 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); |
| 440 app_window->SetController(controller); |
| 441 app_window->set_shelf_id(shelf_id); |
| 442 } |
| 443 |
| 444 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window) { |
| 445 const std::string app_id = app_window->app_id(); |
| 446 DCHECK(!app_id.empty()); |
| 447 AppControllerMap::iterator it = app_controller_map_.find(app_id); |
| 448 DCHECK(it != app_controller_map_.end()); |
| 449 |
| 450 ArcAppWindowLauncherItemController* controller = it->second; |
| 451 controller->RemoveWindow(app_window); |
| 452 if (!controller->window_count()) { |
| 453 ash::ShelfID shelf_id = app_window->shelf_id(); |
| 454 owner()->CloseLauncherItem(shelf_id); |
| 455 app_controller_map_.erase(it); |
| 456 } |
| 457 } |
OLD | NEW |