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 <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/shelf/shelf_delegate.h" | 10 #include "ash/common/shelf/shelf_delegate.h" |
11 #include "ash/common/shelf/shelf_model.h" | 11 #include "ash/common/shelf/shelf_model.h" |
12 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
13 #include "ash/resources/grit/ash_resources.h" | 13 #include "ash/resources/grit/ash_resources.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/wm/window_properties.h" | 15 #include "ash/wm/window_properties.h" |
16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "chrome/browser/chrome_notification_types.h" | |
19 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
21 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
22 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 21 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
23 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 22 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
24 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
28 #include "chrome/browser/ui/chrome_pages.h" | 27 #include "chrome/browser/ui/chrome_pages.h" |
29 #include "chrome/browser/ui/settings_window_manager.h" | 28 #include "chrome/browser/ui/settings_window_manager.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/browser/web_applications/web_app.h" | 30 #include "chrome/browser/web_applications/web_app.h" |
32 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
33 #include "chrome/grit/chromium_strings.h" | 32 #include "chrome/grit/chromium_strings.h" |
34 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
35 #include "components/strings/grit/components_strings.h" | 34 #include "components/strings/grit/components_strings.h" |
36 #include "content/public/browser/notification_service.h" | |
37 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
38 #include "content/public/common/url_constants.h" | 36 #include "content/public/common/url_constants.h" |
39 #include "ui/aura/window.h" | 37 #include "ui/aura/window.h" |
40 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
42 #include "ui/events/event.h" | 40 #include "ui/events/event.h" |
43 #include "ui/events/event_constants.h" | 41 #include "ui/events/event_constants.h" |
44 #include "ui/gfx/image/image.h" | 42 #include "ui/gfx/image/image.h" |
45 #include "ui/wm/core/window_animations.h" | 43 #include "ui/wm/core/window_animations.h" |
46 | 44 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 210 |
213 ash::ShelfAction action = | 211 ash::ShelfAction action = |
214 launcher_controller()->ActivateWindowOrMinimizeIfActive( | 212 launcher_controller()->ActivateWindowOrMinimizeIfActive( |
215 last_browser->window(), items.size() == 1); | 213 last_browser->window(), items.size() == 1); |
216 callback.Run(action, std::move(items)); | 214 callback.Run(action, std::move(items)); |
217 } | 215 } |
218 | 216 |
219 MenuItemList BrowserShortcutLauncherItemController::GetAppMenuItems( | 217 MenuItemList BrowserShortcutLauncherItemController::GetAppMenuItems( |
220 int event_flags) { | 218 int event_flags) { |
221 browser_menu_items_.clear(); | 219 browser_menu_items_.clear(); |
222 registrar_.RemoveAll(); | 220 BrowserList::RemoveObserver(this); |
223 | 221 |
224 MenuItemList items; | 222 MenuItemList items; |
225 bool found_tabbed_browser = false; | 223 bool found_tabbed_browser = false; |
226 for (auto* browser : GetListOfActiveBrowsers()) { | 224 for (auto* browser : GetListOfActiveBrowsers()) { |
227 if (browser_menu_items_.size() >= kMaxItems) | 225 if (browser_menu_items_.size() >= kMaxItems) |
228 break; | 226 break; |
229 TabStripModel* tab_strip = browser->tab_strip_model(); | 227 TabStripModel* tab_strip = browser->tab_strip_model(); |
230 const int tab_index = tab_strip->active_index(); | 228 const int tab_index = tab_strip->active_index(); |
231 if (tab_index < 0 || tab_index >= kMaxItems) | 229 if (tab_index < 0 || tab_index >= kMaxItems) |
232 continue; | 230 continue; |
(...skipping 10 matching lines...) Expand all Loading... |
243 for (uint16_t i = 0; i < tab_strip->count() && i < kMaxItems; ++i) { | 241 for (uint16_t i = 0; i < tab_strip->count() && i < kMaxItems; ++i) { |
244 content::WebContents* tab = tab_strip->GetWebContentsAt(i); | 242 content::WebContents* tab = tab_strip->GetWebContentsAt(i); |
245 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New()); | 243 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New()); |
246 item->command_id = GetCommandId(browser_menu_items_.size(), i); | 244 item->command_id = GetCommandId(browser_menu_items_.size(), i); |
247 item->label = launcher_controller()->GetAppListTitle(tab); | 245 item->label = launcher_controller()->GetAppListTitle(tab); |
248 item->image = *launcher_controller()->GetAppListIcon(tab).ToSkBitmap(); | 246 item->image = *launcher_controller()->GetAppListIcon(tab).ToSkBitmap(); |
249 items.push_back(std::move(item)); | 247 items.push_back(std::move(item)); |
250 } | 248 } |
251 } | 249 } |
252 browser_menu_items_.push_back(browser); | 250 browser_menu_items_.push_back(browser); |
253 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 251 BrowserList::AddObserver(this); |
254 content::Source<Browser>(browser)); | |
255 } | 252 } |
256 // If only windowed applications are open, we return an empty list to | 253 // If only windowed applications are open, we return an empty list to |
257 // enforce the creation of a new browser. | 254 // enforce the creation of a new browser. |
258 if (!found_tabbed_browser) { | 255 if (!found_tabbed_browser) { |
259 items.clear(); | 256 items.clear(); |
260 browser_menu_items_.clear(); | 257 browser_menu_items_.clear(); |
261 registrar_.RemoveAll(); | 258 BrowserList::RemoveObserver(this); |
262 } | 259 } |
263 return items; | 260 return items; |
264 } | 261 } |
265 | 262 |
266 void BrowserShortcutLauncherItemController::ExecuteCommand( | 263 void BrowserShortcutLauncherItemController::ExecuteCommand( |
267 uint32_t command_id, | 264 uint32_t command_id, |
268 int32_t event_flags) { | 265 int32_t event_flags) { |
269 const uint16_t browser_index = GetBrowserIndex(command_id); | 266 const uint16_t browser_index = GetBrowserIndex(command_id); |
270 // Check that the index is valid and the browser has not been closed. | 267 // Check that the index is valid and the browser has not been closed. |
271 if (browser_index < browser_menu_items_.size() && | 268 if (browser_index < browser_menu_items_.size() && |
(...skipping 12 matching lines...) Expand all Loading... |
284 multi_user_util::MoveWindowToCurrentDesktop( | 281 multi_user_util::MoveWindowToCurrentDesktop( |
285 browser->window()->GetNativeWindow()); | 282 browser->window()->GetNativeWindow()); |
286 if (tab_index != kNoTab && tab_strip->ContainsIndex(tab_index)) | 283 if (tab_index != kNoTab && tab_strip->ContainsIndex(tab_index)) |
287 tab_strip->ActivateTabAt(tab_index, false); | 284 tab_strip->ActivateTabAt(tab_index, false); |
288 browser->window()->Show(); | 285 browser->window()->Show(); |
289 browser->window()->Activate(); | 286 browser->window()->Activate(); |
290 } | 287 } |
291 } | 288 } |
292 | 289 |
293 browser_menu_items_.clear(); | 290 browser_menu_items_.clear(); |
294 registrar_.RemoveAll(); | 291 BrowserList::RemoveObserver(this); |
295 } | 292 } |
296 | 293 |
297 void BrowserShortcutLauncherItemController::Close() { | 294 void BrowserShortcutLauncherItemController::Close() { |
298 for (auto* browser : GetListOfActiveBrowsers()) | 295 for (auto* browser : GetListOfActiveBrowsers()) |
299 browser->window()->Close(); | 296 browser->window()->Close(); |
300 } | 297 } |
301 | 298 |
302 bool BrowserShortcutLauncherItemController::IsListOfActiveBrowserEmpty() { | 299 bool BrowserShortcutLauncherItemController::IsListOfActiveBrowserEmpty() { |
303 return GetListOfActiveBrowsers().empty(); | 300 return GetListOfActiveBrowsers().empty(); |
304 } | 301 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 continue; | 383 continue; |
387 } | 384 } |
388 if (!IsBrowserRepresentedInBrowserList(browser) && | 385 if (!IsBrowserRepresentedInBrowserList(browser) && |
389 !browser->is_type_tabbed()) | 386 !browser->is_type_tabbed()) |
390 continue; | 387 continue; |
391 active_browsers.push_back(browser); | 388 active_browsers.push_back(browser); |
392 } | 389 } |
393 return active_browsers; | 390 return active_browsers; |
394 } | 391 } |
395 | 392 |
396 void BrowserShortcutLauncherItemController::Observe( | 393 void BrowserShortcutLauncherItemController::OnBrowserCloseStarted( |
397 int type, | 394 Browser* browser) { |
398 const content::NotificationSource& source, | |
399 const content::NotificationDetails& details) { | |
400 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type); | |
401 Browser* browser = content::Source<Browser>(source).ptr(); | |
402 DCHECK(browser); | 395 DCHECK(browser); |
403 BrowserList::BrowserVector::iterator item = std::find( | 396 BrowserList::BrowserVector::iterator item = std::find( |
404 browser_menu_items_.begin(), browser_menu_items_.end(), browser); | 397 browser_menu_items_.begin(), browser_menu_items_.end(), browser); |
405 DCHECK(item != browser_menu_items_.end()); | 398 DCHECK(item != browser_menu_items_.end()); |
406 // Clear the entry for the closed browser and leave other indices intact. | 399 // Clear the entry for the closed browser and leave other indices intact. |
407 *item = nullptr; | 400 *item = nullptr; |
408 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, | |
409 content::Source<Browser>(browser)); | |
410 } | 401 } |
OLD | NEW |