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

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

Issue 1336823003: Move chrome::HostDesktopType to ui::HostDesktopType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@base_session_service_delegate_impl
Patch Set: Fix build on Mac and CrOS Created 5 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
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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* ash_browser_list =
106 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 106 BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_ASH);
107 for (BrowserList::const_reverse_iterator it = 107 for (BrowserList::const_reverse_iterator it =
108 ash_browser_list->begin_last_active(); 108 ash_browser_list->begin_last_active();
109 it != ash_browser_list->end_last_active() && 109 it != ash_browser_list->end_last_active() &&
110 browser_status == ash::STATUS_CLOSED; ++it) { 110 browser_status == ash::STATUS_CLOSED; ++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 || !launcher_controller()->IsBrowserFromActiveUser(browser) ||
128 !launcher_controller()->IsBrowserFromActiveUser(browser) || 128 browser->host_desktop_type() != ui::HOST_DESKTOP_TYPE_ASH ||
129 browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH ||
130 IsSettingsBrowser(browser)) 129 IsSettingsBrowser(browser))
131 return; 130 return;
132 131
133 ash::SetShelfIDForWindow( 132 ash::SetShelfIDForWindow(
134 launcher_controller()->GetShelfIDForWebContents(web_contents), 133 launcher_controller()->GetShelfIDForWebContents(web_contents),
135 browser->window()->GetNativeWindow()); 134 browser->window()->GetNativeWindow());
136 } 135 }
137 136
138 bool BrowserShortcutLauncherItemController::IsOpen() const { 137 bool BrowserShortcutLauncherItemController::IsOpen() const {
139 const BrowserList* ash_browser_list = 138 const BrowserList* ash_browser_list =
140 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 139 BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_ASH);
141 for (BrowserList::const_iterator it = ash_browser_list->begin(); 140 for (BrowserList::const_iterator it = ash_browser_list->begin();
142 it != ash_browser_list->end(); ++it) { 141 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(), true, ui::HOST_DESKTOP_TYPE_ASH);
152 true,
153 chrome::HOST_DESKTOP_TYPE_ASH);
154 151
155 if (!last_browser) { 152 if (!last_browser) {
156 return false; 153 return false;
157 } 154 }
158 155
159 aura::Window* window = last_browser->window()->GetNativeWindow(); 156 aura::Window* window = last_browser->window()->GetNativeWindow();
160 return ash::wm::IsActiveWindow(window); 157 return ash::wm::IsActiveWindow(window);
161 } 158 }
162 159
163 void BrowserShortcutLauncherItemController::Launch(ash::LaunchSource source, 160 void BrowserShortcutLauncherItemController::Launch(ash::LaunchSource source,
164 int event_flags) { 161 int event_flags) {
165 } 162 }
166 163
167 ash::ShelfItemDelegate::PerformedAction 164 ash::ShelfItemDelegate::PerformedAction
168 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { 165 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) {
169 Browser* last_browser = chrome::FindTabbedBrowser( 166 Browser* last_browser = chrome::FindTabbedBrowser(
170 launcher_controller()->profile(), 167 launcher_controller()->profile(), true, ui::HOST_DESKTOP_TYPE_ASH);
171 true,
172 chrome::HOST_DESKTOP_TYPE_ASH);
173 168
174 if (!last_browser) { 169 if (!last_browser) {
175 launcher_controller()->CreateNewWindow(); 170 launcher_controller()->CreateNewWindow();
176 return kNewWindowCreated; 171 return kNewWindowCreated;
177 } 172 }
178 173
179 return launcher_controller()->ActivateWindowOrMinimizeIfActive( 174 return launcher_controller()->ActivateWindowOrMinimizeIfActive(
180 last_browser->window(), GetApplicationList(0).size() == 2); 175 last_browser->window(), GetApplicationList(0).size() == 2);
181 } 176 }
182 177
183 void BrowserShortcutLauncherItemController::Close() { 178 void BrowserShortcutLauncherItemController::Close() {
184 } 179 }
185 180
186 ChromeLauncherAppMenuItems 181 ChromeLauncherAppMenuItems
187 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { 182 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) {
188 ChromeLauncherAppMenuItems items; 183 ChromeLauncherAppMenuItems items;
189 bool found_tabbed_browser = false; 184 bool found_tabbed_browser = false;
190 // Add the application name to the menu. 185 // Add the application name to the menu.
191 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); 186 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false));
192 const BrowserList* ash_browser_list = 187 const BrowserList* ash_browser_list =
193 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 188 BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_ASH);
194 for (BrowserList::const_iterator it = ash_browser_list->begin(); 189 for (BrowserList::const_iterator it = ash_browser_list->begin();
195 it != ash_browser_list->end(); ++it) { 190 it != ash_browser_list->end(); ++it) {
196 Browser* browser = *it; 191 Browser* browser = *it;
197 // Make sure that the browser is from the current user, has a proper window, 192 // Make sure that the browser is from the current user, has a proper window,
198 // and the window was already shown. 193 // and the window was already shown.
199 if (!launcher_controller()->IsBrowserFromActiveUser(browser)) 194 if (!launcher_controller()->IsBrowserFromActiveUser(browser))
200 continue; 195 continue;
201 if (!(browser->window() && browser->window()->GetNativeWindow())) 196 if (!(browser->window() && browser->window()->GetNativeWindow()))
202 continue; 197 continue;
203 if (!(browser->window()->GetNativeWindow()->IsVisible() || 198 if (!(browser->window()->GetNativeWindow()->IsVisible() ||
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 return profile->IsOffTheRecord() && !profile->IsGuestSession(); 298 return profile->IsOffTheRecord() && !profile->IsGuestSession();
304 } 299 }
305 300
306 ash::ShelfItemDelegate::PerformedAction 301 ash::ShelfItemDelegate::PerformedAction
307 BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { 302 BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() {
308 // Create a list of all suitable running browsers. 303 // Create a list of all suitable running browsers.
309 std::vector<Browser*> items; 304 std::vector<Browser*> items;
310 // We use the list in the order of how the browsers got created - not the LRU 305 // We use the list in the order of how the browsers got created - not the LRU
311 // order. 306 // order.
312 const BrowserList* ash_browser_list = 307 const BrowserList* ash_browser_list =
313 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 308 BrowserList::GetInstance(ui::HOST_DESKTOP_TYPE_ASH);
314 for (BrowserList::const_iterator it = 309 for (BrowserList::const_iterator it =
315 ash_browser_list->begin(); 310 ash_browser_list->begin();
316 it != ash_browser_list->end(); ++it) { 311 it != ash_browser_list->end(); ++it) {
317 if (IsBrowserRepresentedInBrowserList(*it)) 312 if (IsBrowserRepresentedInBrowserList(*it))
318 items.push_back(*it); 313 items.push_back(*it);
319 } 314 }
320 // If there are no suitable browsers we create a new one. 315 // If there are no suitable browsers we create a new one.
321 if (items.empty()) { 316 if (items.empty()) {
322 launcher_controller()->CreateNewWindow(); 317 launcher_controller()->CreateNewWindow();
323 return kNewWindowCreated; 318 return kNewWindowCreated;
(...skipping 11 matching lines...) Expand all
335 } else { 330 } else {
336 // If there is more then one suitable browser, we advance to the next if 331 // If there is more then one suitable browser, we advance to the next if
337 // |browser| is already active - or - check the last used browser if it can 332 // |browser| is already active - or - check the last used browser if it can
338 // be used. 333 // be used.
339 std::vector<Browser*>::iterator i = 334 std::vector<Browser*>::iterator i =
340 std::find(items.begin(), items.end(), browser); 335 std::find(items.begin(), items.end(), browser);
341 if (i != items.end()) { 336 if (i != items.end()) {
342 browser = (++i == items.end()) ? items[0] : *i; 337 browser = (++i == items.end()) ? items[0] : *i;
343 } else { 338 } else {
344 browser = chrome::FindTabbedBrowser(launcher_controller()->profile(), 339 browser = chrome::FindTabbedBrowser(launcher_controller()->profile(),
345 true, 340 true, ui::HOST_DESKTOP_TYPE_ASH);
346 chrome::HOST_DESKTOP_TYPE_ASH);
347 if (!browser || 341 if (!browser ||
348 !IsBrowserRepresentedInBrowserList(browser)) 342 !IsBrowserRepresentedInBrowserList(browser))
349 browser = items[0]; 343 browser = items[0];
350 } 344 }
351 } 345 }
352 DCHECK(browser); 346 DCHECK(browser);
353 browser->window()->Show(); 347 browser->window()->Show();
354 browser->window()->Activate(); 348 browser->window()->Activate();
355 return kExistingWindowActivated; 349 return kExistingWindowActivated;
356 } 350 }
357 351
358 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( 352 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList(
359 Browser* browser) { 353 Browser* browser) {
360 // Only Ash desktop browser windows for the active user are represented. 354 // Only Ash desktop browser windows for the active user are represented.
361 if (!browser || 355 if (!browser || !launcher_controller()->IsBrowserFromActiveUser(browser) ||
362 !launcher_controller()->IsBrowserFromActiveUser(browser) || 356 browser->host_desktop_type() != ui::HOST_DESKTOP_TYPE_ASH)
363 browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH)
364 return false; 357 return false;
365 358
366 // v1 App popup windows with a valid app id have their own icon. 359 // v1 App popup windows with a valid app id have their own icon.
367 if (browser->is_app() && 360 if (browser->is_app() &&
368 browser->is_type_popup() && 361 browser->is_type_popup() &&
369 launcher_controller()->GetShelfIDForAppID( 362 launcher_controller()->GetShelfIDForAppID(
370 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) 363 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0)
371 return false; 364 return false;
372 365
373 // Settings browsers have their own icon. 366 // Settings browsers have their own icon.
374 if (IsSettingsBrowser(browser)) 367 if (IsSettingsBrowser(browser))
375 return false; 368 return false;
376 369
377 // Tabbed browser and other popup windows are all represented. 370 // Tabbed browser and other popup windows are all represented.
378 return true; 371 return true;
379 } 372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698