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) { |
349 TaskIdToAppWindow::iterator previous_active_app_it = | 337 TaskIdToAppWindow::iterator previous_active_app_it = |
350 task_id_to_app_window_.find(active_task_id_); | 338 task_id_to_app_window_.find(active_task_id_); |
351 if (previous_active_app_it != task_id_to_app_window_.end()) { | 339 if (previous_active_app_it != task_id_to_app_window_.end()) { |
352 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), | 340 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), |
353 ash::STATUS_RUNNING); | 341 ash::STATUS_RUNNING); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) | 379 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) |
392 return it.second->controller(); | 380 return it.second->controller(); |
393 } | 381 } |
394 | 382 |
395 return nullptr; | 383 return nullptr; |
396 } | 384 } |
397 | 385 |
398 void ArcAppWindowLauncherController::OnWindowActivated( | 386 void ArcAppWindowLauncherController::OnWindowActivated( |
399 aura::client::ActivationChangeObserver::ActivationReason reason, | 387 aura::client::ActivationChangeObserver::ActivationReason reason, |
400 aura::Window* gained_active, | 388 aura::Window* gained_active, |
401 aura::Window* lost_active) { | 389 aura::Window* lost_active) { |
reveman
2016/06/03 21:51:47
can you explain what the changes to this function
xdai1
2016/06/03 22:14:46
This change is necessary because otherwise OnTaskS
reveman
2016/06/03 22:49:35
Ok, I think that might be a bit easier to understa
| |
402 OnTaskSetActive(active_task_id_); | 390 AppWindow* app_window = GetAppWindowForTask(active_task_id_); |
391 if (app_window && | |
392 ((gained_active && | |
393 app_window->widget() == | |
394 views::Widget::GetWidgetForNativeWindow(gained_active)) || | |
395 (lost_active && | |
396 app_window->widget() == | |
397 views::Widget::GetWidgetForNativeWindow(lost_active)))) { | |
398 OnTaskSetActive(active_task_id_); | |
399 } | |
403 } | 400 } |
404 | 401 |
405 void ArcAppWindowLauncherController::StartObserving(Profile* profile) { | 402 void ArcAppWindowLauncherController::StartObserving(Profile* profile) { |
406 aura::Env* env = aura::Env::GetInstanceDontCreate(); | 403 aura::Env* env = aura::Env::GetInstanceDontCreate(); |
407 if (env) | 404 if (env) |
408 env->AddObserver(this); | 405 env->AddObserver(this); |
409 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); | 406 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); |
410 DCHECK(prefs); | 407 DCHECK(prefs); |
411 prefs->AddObserver(this); | 408 prefs->AddObserver(this); |
412 } | 409 } |
413 | 410 |
414 void ArcAppWindowLauncherController::StopObserving(Profile* profile) { | 411 void ArcAppWindowLauncherController::StopObserving(Profile* profile) { |
415 for (auto window : observed_windows_) | 412 for (auto window : observed_windows_) |
416 window->RemoveObserver(this); | 413 window->RemoveObserver(this); |
417 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); | 414 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(profile); |
418 prefs->RemoveObserver(this); | 415 prefs->RemoveObserver(this); |
419 aura::Env* env = aura::Env::GetInstanceDontCreate(); | 416 aura::Env* env = aura::Env::GetInstanceDontCreate(); |
420 if (env) | 417 if (env) |
421 env->RemoveObserver(this); | 418 env->RemoveObserver(this); |
422 } | 419 } |
420 | |
421 void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) { | |
422 const std::string app_id = app_window->app_id(); | |
423 DCHECK(!app_id.empty()); | |
424 | |
425 ArcAppWindowLauncherItemController* controller; | |
426 AppControllerMap::iterator it = app_controller_map_.find(app_id); | |
427 ash::ShelfID shelf_id = 0; | |
428 if (it != app_controller_map_.end()) { | |
429 controller = it->second; | |
430 DCHECK_EQ(controller->app_id(), app_id); | |
431 shelf_id = controller->shelf_id(); | |
432 } else { | |
433 controller = new ArcAppWindowLauncherItemController(app_id, owner()); | |
434 shelf_id = owner()->GetShelfIDForAppID(app_id); | |
435 if (shelf_id == 0) { | |
436 // Map Play Store shelf icon to Arc Support host, to share one entry. | |
437 shelf_id = owner()->CreateAppLauncherItem(controller, app_id, | |
438 ash::STATUS_RUNNING); | |
439 } else { | |
440 owner()->SetItemController(shelf_id, controller); | |
441 } | |
442 app_controller_map_[app_id] = controller; | |
443 } | |
444 controller->AddWindow(app_window); | |
445 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); | |
446 app_window->SetController(controller); | |
447 app_window->set_shelf_id(shelf_id); | |
448 } | |
449 | |
450 void ArcAppWindowLauncherController::UnRegisterApp(AppWindow* app_window) { | |
451 const std::string app_id = app_window->app_id(); | |
452 DCHECK(!app_id.empty()); | |
453 AppControllerMap::iterator it = app_controller_map_.find(app_id); | |
454 DCHECK(it != app_controller_map_.end()); | |
455 | |
456 ArcAppWindowLauncherItemController* controller = it->second; | |
457 controller->RemoveWindow(app_window); | |
458 if (!controller->window_count()) { | |
459 ash::ShelfID shelf_id = app_window->shelf_id(); | |
460 owner()->CloseLauncherItem(shelf_id); | |
461 app_controller_map_.erase(it); | |
462 } | |
463 } | |
OLD | NEW |