OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 4 |
5 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" |
6 | 6 |
7 #include "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
13 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" | 13 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h
" |
14 #include "chrome/browser/ui/host_desktop.h" | 14 #include "chrome/browser/ui/host_desktop.h" |
15 #include "ui/aura/client/activation_client.h" | 15 #include "ui/aura/client/activation_client.h" |
16 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
17 | 17 |
| 18 #if defined(OS_CHROMEOS) |
| 19 #include "chrome/browser/ui/ash/multi_user_window_manager.h" |
| 20 #endif |
| 21 |
18 using apps::ShellWindow; | 22 using apps::ShellWindow; |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 std::string GetAppLauncherId(ShellWindow* shell_window) { | 26 std::string GetAppLauncherId(ShellWindow* shell_window) { |
23 if (shell_window->window_type_is_panel()) | 27 if (shell_window->window_type_is_panel()) |
24 return base::StringPrintf("panel:%d", shell_window->session_id().id()); | 28 return base::StringPrintf("panel:%d", shell_window->session_id().id()); |
25 return shell_window->extension()->id(); | 29 return shell_window->extension()->id(); |
26 } | 30 } |
27 | 31 |
28 bool ControlsWindow(aura::Window* window) { | 32 bool ControlsWindow(aura::Window* window) { |
29 return chrome::GetHostDesktopTypeForNativeWindow(window) == | 33 return chrome::GetHostDesktopTypeForNativeWindow(window) == |
30 chrome::HOST_DESKTOP_TYPE_ASH; | 34 chrome::HOST_DESKTOP_TYPE_ASH; |
31 } | 35 } |
32 | 36 |
33 } // namespace | 37 } // namespace |
34 | 38 |
35 ShellWindowLauncherController::ShellWindowLauncherController( | 39 ShellWindowLauncherController::ShellWindowLauncherController( |
36 ChromeLauncherController* owner) | 40 ChromeLauncherController* owner) |
37 : owner_(owner), | 41 : owner_(owner), |
38 registry_(apps::ShellWindowRegistry::Get(owner->profile())), | |
39 activation_client_(NULL) { | 42 activation_client_(NULL) { |
40 registry_->AddObserver(this); | 43 apps::ShellWindowRegistry* registry = |
| 44 apps::ShellWindowRegistry::Get(owner->profile()); |
| 45 registry_.insert(registry); |
| 46 registry->AddObserver(this); |
41 if (ash::Shell::HasInstance()) { | 47 if (ash::Shell::HasInstance()) { |
42 if (ash::Shell::GetInstance()->GetPrimaryRootWindow()) { | 48 if (ash::Shell::GetInstance()->GetPrimaryRootWindow()) { |
43 activation_client_ = aura::client::GetActivationClient( | 49 activation_client_ = aura::client::GetActivationClient( |
44 ash::Shell::GetInstance()->GetPrimaryRootWindow()); | 50 ash::Shell::GetInstance()->GetPrimaryRootWindow()); |
45 if (activation_client_) | 51 if (activation_client_) |
46 activation_client_->AddObserver(this); | 52 activation_client_->AddObserver(this); |
47 } | 53 } |
48 } | 54 } |
49 } | 55 } |
50 | 56 |
51 ShellWindowLauncherController::~ShellWindowLauncherController() { | 57 ShellWindowLauncherController::~ShellWindowLauncherController() { |
52 registry_->RemoveObserver(this); | 58 for (std::set<apps::ShellWindowRegistry*>::iterator it = registry_.begin(); |
| 59 it != registry_.end(); ++it) |
| 60 (*it)->RemoveObserver(this); |
| 61 |
53 if (activation_client_) | 62 if (activation_client_) |
54 activation_client_->RemoveObserver(this); | 63 activation_client_->RemoveObserver(this); |
55 for (WindowToAppLauncherIdMap::iterator iter = | 64 for (WindowToAppLauncherIdMap::iterator iter = |
56 window_to_app_launcher_id_map_.begin(); | 65 window_to_app_launcher_id_map_.begin(); |
57 iter != window_to_app_launcher_id_map_.end(); ++iter) { | 66 iter != window_to_app_launcher_id_map_.end(); ++iter) { |
58 iter->first->RemoveObserver(this); | 67 iter->first->RemoveObserver(this); |
59 } | 68 } |
60 } | 69 } |
61 | 70 |
| 71 void ShellWindowLauncherController::AdditionalUserAddedToSession( |
| 72 Profile* profile) { |
| 73 #if defined(OS_CHROMEOS) |
| 74 // TODO(skuhne): This was added for the legacy side by side mode in M32. If |
| 75 // this mode gets no longer pursued this special case can be removed. |
| 76 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != |
| 77 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_MIXED) |
| 78 return; |
| 79 |
| 80 apps::ShellWindowRegistry* registry = apps::ShellWindowRegistry::Get(profile); |
| 81 if (registry_.find(registry) != registry_.end()) |
| 82 return; |
| 83 |
| 84 registry->AddObserver(this); |
| 85 registry_.insert(registry); |
| 86 #endif |
| 87 } |
| 88 |
62 void ShellWindowLauncherController::OnShellWindowAdded( | 89 void ShellWindowLauncherController::OnShellWindowAdded( |
63 ShellWindow* shell_window) { | 90 ShellWindow* shell_window) { |
64 if (!ControlsWindow(shell_window->GetNativeWindow())) | 91 if (!ControlsWindow(shell_window->GetNativeWindow())) |
65 return; | 92 return; |
66 RegisterApp(shell_window); | 93 RegisterApp(shell_window); |
67 } | 94 } |
68 | 95 |
69 void ShellWindowLauncherController::OnShellWindowIconChanged( | 96 void ShellWindowLauncherController::OnShellWindowIconChanged( |
70 ShellWindow* shell_window) { | 97 ShellWindow* shell_window) { |
71 if (!ControlsWindow(shell_window->GetNativeWindow())) | 98 if (!ControlsWindow(shell_window->GetNativeWindow())) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 WindowToAppLauncherIdMap::iterator iter1 = | 217 WindowToAppLauncherIdMap::iterator iter1 = |
191 window_to_app_launcher_id_map_.find(window); | 218 window_to_app_launcher_id_map_.find(window); |
192 if (iter1 == window_to_app_launcher_id_map_.end()) | 219 if (iter1 == window_to_app_launcher_id_map_.end()) |
193 return NULL; | 220 return NULL; |
194 std::string app_launcher_id = iter1->second; | 221 std::string app_launcher_id = iter1->second; |
195 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); | 222 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); |
196 if (iter2 == app_controller_map_.end()) | 223 if (iter2 == app_controller_map_.end()) |
197 return NULL; | 224 return NULL; |
198 return iter2->second; | 225 return iter2->second; |
199 } | 226 } |
OLD | NEW |