Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_controller.cc

Issue 494033002: Move AppWindow to extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unneeded include in chrome_shell_delegate.cc Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/multi_profile_app_window_launcher_contr oller.h" 5 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr oller.h"
6 6
7 #include "apps/app_window.h"
8 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
11 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 10 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
12 #include "chrome/browser/ui/host_desktop.h" 11 #include "chrome/browser/ui/host_desktop.h"
12 #include "extensions/browser/app_window/app_window.h"
13 #include "extensions/browser/app_window/native_app_window.h" 13 #include "extensions/browser/app_window/native_app_window.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 15
16 namespace { 16 namespace {
17 17
18 bool ControlsWindow(aura::Window* window) { 18 bool ControlsWindow(aura::Window* window) {
19 return chrome::GetHostDesktopTypeForNativeWindow(window) == 19 return chrome::GetHostDesktopTypeForNativeWindow(window) ==
20 chrome::HOST_DESKTOP_TYPE_ASH; 20 chrome::HOST_DESKTOP_TYPE_ASH;
21 } 21 }
22 22
(...skipping 14 matching lines...) Expand all
37 37
38 void MultiProfileAppWindowLauncherController::ActiveUserChanged( 38 void MultiProfileAppWindowLauncherController::ActiveUserChanged(
39 const std::string& user_email) { 39 const std::string& user_email) {
40 // The active user has changed and we need to traverse our list of items to 40 // The active user has changed and we need to traverse our list of items to
41 // show / hide them one by one. To avoid that a user dependent state 41 // show / hide them one by one. To avoid that a user dependent state
42 // "survives" in a launcher item, we first delete all items making sure that 42 // "survives" in a launcher item, we first delete all items making sure that
43 // nothing remains and then re-create them again. 43 // nothing remains and then re-create them again.
44 for (AppWindowList::iterator it = app_window_list_.begin(); 44 for (AppWindowList::iterator it = app_window_list_.begin();
45 it != app_window_list_.end(); 45 it != app_window_list_.end();
46 ++it) { 46 ++it) {
47 apps::AppWindow* app_window = *it; 47 extensions::AppWindow* app_window = *it;
48 Profile* profile = 48 Profile* profile =
49 Profile::FromBrowserContext(app_window->browser_context()); 49 Profile::FromBrowserContext(app_window->browser_context());
50 if (!multi_user_util::IsProfileFromActiveUser(profile) && 50 if (!multi_user_util::IsProfileFromActiveUser(profile) &&
51 IsRegisteredApp(app_window->GetNativeWindow())) 51 IsRegisteredApp(app_window->GetNativeWindow()))
52 UnregisterApp(app_window->GetNativeWindow()); 52 UnregisterApp(app_window->GetNativeWindow());
53 } 53 }
54 for (AppWindowList::iterator it = app_window_list_.begin(); 54 for (AppWindowList::iterator it = app_window_list_.begin();
55 it != app_window_list_.end(); 55 it != app_window_list_.end();
56 ++it) { 56 ++it) {
57 apps::AppWindow* app_window = *it; 57 extensions::AppWindow* app_window = *it;
58 Profile* profile = 58 Profile* profile =
59 Profile::FromBrowserContext(app_window->browser_context()); 59 Profile::FromBrowserContext(app_window->browser_context());
60 if (multi_user_util::IsProfileFromActiveUser(profile) && 60 if (multi_user_util::IsProfileFromActiveUser(profile) &&
61 !IsRegisteredApp(app_window->GetNativeWindow()) && 61 !IsRegisteredApp(app_window->GetNativeWindow()) &&
62 (app_window->GetBaseWindow()->IsMinimized() || 62 (app_window->GetBaseWindow()->IsMinimized() ||
63 app_window->GetNativeWindow()->IsVisible())) 63 app_window->GetNativeWindow()->IsVisible()))
64 RegisterApp(*it); 64 RegisterApp(*it);
65 } 65 }
66 } 66 }
67 67
68 void MultiProfileAppWindowLauncherController::AdditionalUserAddedToSession( 68 void MultiProfileAppWindowLauncherController::AdditionalUserAddedToSession(
69 Profile* profile) { 69 Profile* profile) {
70 // Each users AppWindowRegistry needs to be observed. 70 // Each users AppWindowRegistry needs to be observed.
71 apps::AppWindowRegistry* registry = apps::AppWindowRegistry::Get(profile); 71 extensions::AppWindowRegistry* registry =
72 extensions::AppWindowRegistry::Get(profile);
72 multi_user_registry_.push_back(registry); 73 multi_user_registry_.push_back(registry);
73 registry->AddObserver(this); 74 registry->AddObserver(this);
74 } 75 }
75 76
76 void MultiProfileAppWindowLauncherController::OnAppWindowAdded( 77 void MultiProfileAppWindowLauncherController::OnAppWindowAdded(
77 apps::AppWindow* app_window) { 78 extensions::AppWindow* app_window) {
78 if (!ControlsWindow(app_window->GetNativeWindow())) 79 if (!ControlsWindow(app_window->GetNativeWindow()))
79 return; 80 return;
80 81
81 app_window_list_.push_back(app_window); 82 app_window_list_.push_back(app_window);
82 Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); 83 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
83 // If the window got created for a non active user but the user allowed to 84 // If the window got created for a non active user but the user allowed to
84 // teleport to the current user's desktop, we teleport it now. 85 // teleport to the current user's desktop, we teleport it now.
85 if (!multi_user_util::IsProfileFromActiveUser(profile) && 86 if (!multi_user_util::IsProfileFromActiveUser(profile) &&
86 UserHasAppOnActiveDesktop(app_window)) { 87 UserHasAppOnActiveDesktop(app_window)) {
87 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser( 88 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
88 app_window->GetNativeWindow(), multi_user_util::GetCurrentUserId()); 89 app_window->GetNativeWindow(), multi_user_util::GetCurrentUserId());
89 } 90 }
90 } 91 }
91 92
92 void MultiProfileAppWindowLauncherController::OnAppWindowShown( 93 void MultiProfileAppWindowLauncherController::OnAppWindowShown(
93 apps::AppWindow* app_window) { 94 extensions::AppWindow* app_window) {
94 if (!ControlsWindow(app_window->GetNativeWindow())) 95 if (!ControlsWindow(app_window->GetNativeWindow()))
95 return; 96 return;
96 97
97 Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); 98 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
98 99
99 if (multi_user_util::IsProfileFromActiveUser(profile) && 100 if (multi_user_util::IsProfileFromActiveUser(profile) &&
100 !IsRegisteredApp(app_window->GetNativeWindow())) { 101 !IsRegisteredApp(app_window->GetNativeWindow())) {
101 RegisterApp(app_window); 102 RegisterApp(app_window);
102 return; 103 return;
103 } 104 }
104 105
105 // The panel layout manager only manages windows which are anchored. 106 // The panel layout manager only manages windows which are anchored.
106 // Since this window did never had an anchor, it would stay hidden. We 107 // Since this window did never had an anchor, it would stay hidden. We
107 // therefore make it visible now. 108 // therefore make it visible now.
108 if (UserHasAppOnActiveDesktop(app_window) && 109 if (UserHasAppOnActiveDesktop(app_window) &&
109 app_window->GetNativeWindow()->type() == ui::wm::WINDOW_TYPE_PANEL && 110 app_window->GetNativeWindow()->type() == ui::wm::WINDOW_TYPE_PANEL &&
110 !app_window->GetNativeWindow()->layer()->GetTargetOpacity()) { 111 !app_window->GetNativeWindow()->layer()->GetTargetOpacity()) {
111 app_window->GetNativeWindow()->layer()->SetOpacity(1.0f); 112 app_window->GetNativeWindow()->layer()->SetOpacity(1.0f);
112 } 113 }
113 } 114 }
114 115
115 void MultiProfileAppWindowLauncherController::OnAppWindowHidden( 116 void MultiProfileAppWindowLauncherController::OnAppWindowHidden(
116 apps::AppWindow* app_window) { 117 extensions::AppWindow* app_window) {
117 if (!ControlsWindow(app_window->GetNativeWindow())) 118 if (!ControlsWindow(app_window->GetNativeWindow()))
118 return; 119 return;
119 120
120 Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); 121 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
121 if (multi_user_util::IsProfileFromActiveUser(profile) && 122 if (multi_user_util::IsProfileFromActiveUser(profile) &&
122 IsRegisteredApp(app_window->GetNativeWindow())) { 123 IsRegisteredApp(app_window->GetNativeWindow())) {
123 UnregisterApp(app_window->GetNativeWindow()); 124 UnregisterApp(app_window->GetNativeWindow());
124 } 125 }
125 } 126 }
126 127
127 void MultiProfileAppWindowLauncherController::OnAppWindowRemoved( 128 void MultiProfileAppWindowLauncherController::OnAppWindowRemoved(
128 apps::AppWindow* app_window) { 129 extensions::AppWindow* app_window) {
129 if (!ControlsWindow(app_window->GetNativeWindow())) 130 if (!ControlsWindow(app_window->GetNativeWindow()))
130 return; 131 return;
131 132
132 // If the application is registered with AppWindowLauncher (because the user 133 // If the application is registered with AppWindowLauncher (because the user
133 // is currently active), the OnWindowDestroying observer has already (or will 134 // is currently active), the OnWindowDestroying observer has already (or will
134 // soon) unregister it independently from the shelf. If it was not registered 135 // soon) unregister it independently from the shelf. If it was not registered
135 // we don't need to do anything anyways. As such, all which is left to do here 136 // we don't need to do anything anyways. As such, all which is left to do here
136 // is to get rid of our own reference. 137 // is to get rid of our own reference.
137 AppWindowList::iterator it = 138 AppWindowList::iterator it =
138 std::find(app_window_list_.begin(), app_window_list_.end(), app_window); 139 std::find(app_window_list_.begin(), app_window_list_.end(), app_window);
139 DCHECK(it != app_window_list_.end()); 140 DCHECK(it != app_window_list_.end());
140 app_window_list_.erase(it); 141 app_window_list_.erase(it);
141 } 142 }
142 143
143 bool MultiProfileAppWindowLauncherController::UserHasAppOnActiveDesktop( 144 bool MultiProfileAppWindowLauncherController::UserHasAppOnActiveDesktop(
144 apps::AppWindow* app_window) { 145 extensions::AppWindow* app_window) {
145 const std::string& app_id = app_window->extension_id(); 146 const std::string& app_id = app_window->extension_id();
146 content::BrowserContext* app_context = app_window->browser_context(); 147 content::BrowserContext* app_context = app_window->browser_context();
147 DCHECK(!app_context->IsOffTheRecord()); 148 DCHECK(!app_context->IsOffTheRecord());
148 const std::string& current_user = multi_user_util::GetCurrentUserId(); 149 const std::string& current_user = multi_user_util::GetCurrentUserId();
149 chrome::MultiUserWindowManager* manager = 150 chrome::MultiUserWindowManager* manager =
150 chrome::MultiUserWindowManager::GetInstance(); 151 chrome::MultiUserWindowManager::GetInstance();
151 for (AppWindowList::iterator it = app_window_list_.begin(); 152 for (AppWindowList::iterator it = app_window_list_.begin();
152 it != app_window_list_.end(); 153 it != app_window_list_.end();
153 ++it) { 154 ++it) {
154 apps::AppWindow* other_window = *it; 155 extensions::AppWindow* other_window = *it;
155 DCHECK(!other_window->browser_context()->IsOffTheRecord()); 156 DCHECK(!other_window->browser_context()->IsOffTheRecord());
156 if (manager->IsWindowOnDesktopOfUser(other_window->GetNativeWindow(), 157 if (manager->IsWindowOnDesktopOfUser(other_window->GetNativeWindow(),
157 current_user) && 158 current_user) &&
158 app_id == other_window->extension_id() && 159 app_id == other_window->extension_id() &&
159 app_context == other_window->browser_context()) { 160 app_context == other_window->browser_context()) {
160 return true; 161 return true;
161 } 162 }
162 } 163 }
163 return false; 164 return false;
164 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698