OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser_shortcut_launcher_item_controll
er.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_model.h" | 10 #include "ash/shelf/shelf_model.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 content::WebContents* contents = | 95 content::WebContents* contents = |
96 browser->tab_strip_model()->GetActiveWebContents(); | 96 browser->tab_strip_model()->GetActiveWebContents(); |
97 if (contents && | 97 if (contents && |
98 (launcher_controller()->GetShelfIDForWebContents(contents) != | 98 (launcher_controller()->GetShelfIDForWebContents(contents) != |
99 browser_item.id)) | 99 browser_item.id)) |
100 browser_status = ash::STATUS_RUNNING; | 100 browser_status = ash::STATUS_RUNNING; |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 if (browser_status == ash::STATUS_CLOSED) { | 104 if (browser_status == ash::STATUS_CLOSED) { |
105 const BrowserList* ash_browser_list = | 105 const BrowserList* browser_list = BrowserList::GetInstance(); |
106 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
107 for (BrowserList::const_reverse_iterator it = | 106 for (BrowserList::const_reverse_iterator it = |
108 ash_browser_list->begin_last_active(); | 107 browser_list->begin_last_active(); |
109 it != ash_browser_list->end_last_active() && | 108 it != browser_list->end_last_active() && |
110 browser_status == ash::STATUS_CLOSED; ++it) { | 109 browser_status == ash::STATUS_CLOSED; |
| 110 ++it) { |
111 if (IsBrowserRepresentedInBrowserList(*it)) | 111 if (IsBrowserRepresentedInBrowserList(*it)) |
112 browser_status = ash::STATUS_RUNNING; | 112 browser_status = ash::STATUS_RUNNING; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 if (browser_status != browser_item.status) { | 116 if (browser_status != browser_item.status) { |
117 browser_item.status = browser_status; | 117 browser_item.status = browser_status; |
118 model->Set(browser_index, browser_item); | 118 model->Set(browser_index, browser_item); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void BrowserShortcutLauncherItemController::SetShelfIDForBrowserWindowContents( | 122 void BrowserShortcutLauncherItemController::SetShelfIDForBrowserWindowContents( |
123 Browser* browser, | 123 Browser* browser, |
124 content::WebContents* web_contents) { | 124 content::WebContents* web_contents) { |
125 // We need to call SetShelfIDForWindow for V1 applications since they are | 125 // We need to call SetShelfIDForWindow for V1 applications since they are |
126 // content which might change and as such change the application type. | 126 // content which might change and as such change the application type. |
127 if (!browser || | 127 if (!browser || |
128 !launcher_controller()->IsBrowserFromActiveUser(browser) || | 128 !launcher_controller()->IsBrowserFromActiveUser(browser) || |
129 browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH || | 129 browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH || |
130 IsSettingsBrowser(browser)) | 130 IsSettingsBrowser(browser)) |
131 return; | 131 return; |
132 | 132 |
133 ash::SetShelfIDForWindow( | 133 ash::SetShelfIDForWindow( |
134 launcher_controller()->GetShelfIDForWebContents(web_contents), | 134 launcher_controller()->GetShelfIDForWebContents(web_contents), |
135 browser->window()->GetNativeWindow()); | 135 browser->window()->GetNativeWindow()); |
136 } | 136 } |
137 | 137 |
138 bool BrowserShortcutLauncherItemController::IsOpen() const { | 138 bool BrowserShortcutLauncherItemController::IsOpen() const { |
139 const BrowserList* ash_browser_list = | 139 const BrowserList* browser_list = BrowserList::GetInstance(); |
140 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 140 for (BrowserList::const_iterator it = browser_list->begin(); |
141 for (BrowserList::const_iterator it = ash_browser_list->begin(); | 141 it != browser_list->end(); ++it) { |
142 it != ash_browser_list->end(); ++it) { | |
143 if (launcher_controller()->IsBrowserFromActiveUser(*it)) | 142 if (launcher_controller()->IsBrowserFromActiveUser(*it)) |
144 return true; | 143 return true; |
145 } | 144 } |
146 return false; | 145 return false; |
147 } | 146 } |
148 | 147 |
149 bool BrowserShortcutLauncherItemController::IsVisible() const { | 148 bool BrowserShortcutLauncherItemController::IsVisible() const { |
150 Browser* last_browser = chrome::FindTabbedBrowser( | 149 Browser* last_browser = chrome::FindTabbedBrowser( |
151 launcher_controller()->profile(), | 150 launcher_controller()->profile(), |
152 true, | 151 true, |
(...skipping 29 matching lines...) Expand all Loading... |
182 | 181 |
183 void BrowserShortcutLauncherItemController::Close() { | 182 void BrowserShortcutLauncherItemController::Close() { |
184 } | 183 } |
185 | 184 |
186 ChromeLauncherAppMenuItems | 185 ChromeLauncherAppMenuItems |
187 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { | 186 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { |
188 ChromeLauncherAppMenuItems items; | 187 ChromeLauncherAppMenuItems items; |
189 bool found_tabbed_browser = false; | 188 bool found_tabbed_browser = false; |
190 // Add the application name to the menu. | 189 // Add the application name to the menu. |
191 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); | 190 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); |
192 const BrowserList* ash_browser_list = | 191 const BrowserList* browser_list = BrowserList::GetInstance(); |
193 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 192 for (BrowserList::const_iterator it = browser_list->begin(); |
194 for (BrowserList::const_iterator it = ash_browser_list->begin(); | 193 it != browser_list->end(); ++it) { |
195 it != ash_browser_list->end(); ++it) { | |
196 Browser* browser = *it; | 194 Browser* browser = *it; |
197 // Make sure that the browser is from the current user, has a proper window, | 195 // Make sure that the browser is from the current user, has a proper window, |
198 // and the window was already shown. | 196 // and the window was already shown. |
199 if (!launcher_controller()->IsBrowserFromActiveUser(browser)) | 197 if (!launcher_controller()->IsBrowserFromActiveUser(browser)) |
200 continue; | 198 continue; |
201 if (!(browser->window() && browser->window()->GetNativeWindow())) | 199 if (!(browser->window() && browser->window()->GetNativeWindow())) |
202 continue; | 200 continue; |
203 if (!(browser->window()->GetNativeWindow()->IsVisible() || | 201 if (!(browser->window()->GetNativeWindow()->IsVisible() || |
204 browser->window()->IsMinimized())) { | 202 browser->window()->IsMinimized())) { |
205 continue; | 203 continue; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 304 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
307 return profile->IsOffTheRecord() && !profile->IsGuestSession(); | 305 return profile->IsOffTheRecord() && !profile->IsGuestSession(); |
308 } | 306 } |
309 | 307 |
310 ash::ShelfItemDelegate::PerformedAction | 308 ash::ShelfItemDelegate::PerformedAction |
311 BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { | 309 BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { |
312 // Create a list of all suitable running browsers. | 310 // Create a list of all suitable running browsers. |
313 std::vector<Browser*> items; | 311 std::vector<Browser*> items; |
314 // We use the list in the order of how the browsers got created - not the LRU | 312 // We use the list in the order of how the browsers got created - not the LRU |
315 // order. | 313 // order. |
316 const BrowserList* ash_browser_list = | 314 const BrowserList* browser_list = BrowserList::GetInstance(); |
317 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 315 for (BrowserList::const_iterator it = browser_list->begin(); |
318 for (BrowserList::const_iterator it = | 316 it != browser_list->end(); ++it) { |
319 ash_browser_list->begin(); | |
320 it != ash_browser_list->end(); ++it) { | |
321 if (IsBrowserRepresentedInBrowserList(*it)) | 317 if (IsBrowserRepresentedInBrowserList(*it)) |
322 items.push_back(*it); | 318 items.push_back(*it); |
323 } | 319 } |
324 // If there are no suitable browsers we create a new one. | 320 // If there are no suitable browsers we create a new one. |
325 if (items.empty()) { | 321 if (items.empty()) { |
326 launcher_controller()->CreateNewWindow(); | 322 launcher_controller()->CreateNewWindow(); |
327 return kNewWindowCreated; | 323 return kNewWindowCreated; |
328 } | 324 } |
329 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | 325 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); |
330 if (items.size() == 1) { | 326 if (items.size() == 1) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) | 370 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) |
375 return false; | 371 return false; |
376 | 372 |
377 // Settings browsers have their own icon. | 373 // Settings browsers have their own icon. |
378 if (IsSettingsBrowser(browser)) | 374 if (IsSettingsBrowser(browser)) |
379 return false; | 375 return false; |
380 | 376 |
381 // Tabbed browser and other popup windows are all represented. | 377 // Tabbed browser and other popup windows are all represented. |
382 return true; | 378 return true; |
383 } | 379 } |
OLD | NEW |