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

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

Issue 2793443003: Removed NOTIFICATION_BROWSER_CLOSING notification (Closed)
Patch Set: Update CL basing on review comments (rebase) Created 3 years, 7 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 <limits> 7 #include <limits>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/public/cpp/window_properties.h" 11 #include "ash/public/cpp/window_properties.h"
12 #include "ash/resources/grit/ash_resources.h" 12 #include "ash/resources/grit/ash_resources.h"
13 #include "ash/shelf/shelf_model.h" 13 #include "ash/shelf/shelf_model.h"
14 #include "ash/wm_window.h" 14 #include "ash/wm_window.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
20 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
21 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 20 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
22 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h" 22 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_finder.h" 23 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/chrome_pages.h" 26 #include "chrome/browser/ui/chrome_pages.h"
28 #include "chrome/browser/ui/settings_window_manager.h" 27 #include "chrome/browser/ui/settings_window_manager.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/browser/web_applications/web_app.h" 29 #include "chrome/browser/web_applications/web_app.h"
31 #include "chrome/common/extensions/extension_constants.h" 30 #include "chrome/common/extensions/extension_constants.h"
32 #include "chrome/grit/chromium_strings.h" 31 #include "chrome/grit/chromium_strings.h"
33 #include "chrome/grit/generated_resources.h" 32 #include "chrome/grit/generated_resources.h"
34 #include "components/strings/grit/components_strings.h" 33 #include "components/strings/grit/components_strings.h"
35 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
37 #include "content/public/common/url_constants.h" 35 #include "content/public/common/url_constants.h"
38 #include "ui/aura/window.h" 36 #include "ui/aura/window.h"
39 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/events/event.h" 39 #include "ui/events/event.h"
42 #include "ui/events/event_constants.h" 40 #include "ui/events/event_constants.h"
43 #include "ui/gfx/image/image.h" 41 #include "ui/gfx/image/image.h"
44 #include "ui/wm/core/window_animations.h" 42 #include "ui/wm/core/window_animations.h"
45 43
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 base::string16 GetBrowserListTitle(content::WebContents* web_contents) { 98 base::string16 GetBrowserListTitle(content::WebContents* web_contents) {
101 const base::string16& title = web_contents->GetTitle(); 99 const base::string16& title = web_contents->GetTitle();
102 return title.empty() ? l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE) : title; 100 return title.empty() ? l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE) : title;
103 } 101 }
104 102
105 } // namespace 103 } // namespace
106 104
107 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( 105 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController(
108 ash::ShelfModel* shelf_model) 106 ash::ShelfModel* shelf_model)
109 : ash::ShelfItemDelegate(ash::ShelfID(extension_misc::kChromeAppId)), 107 : ash::ShelfItemDelegate(ash::ShelfID(extension_misc::kChromeAppId)),
110 shelf_model_(shelf_model) { 108 shelf_model_(shelf_model),
109 browser_list_observer_(this) {
111 // Tag all open browser windows with the appropriate shelf id property. This 110 // Tag all open browser windows with the appropriate shelf id property. This
112 // associates each window with the shelf item for the active web contents. 111 // associates each window with the shelf item for the active web contents.
113 for (auto* browser : *BrowserList::GetInstance()) { 112 for (auto* browser : *BrowserList::GetInstance()) {
114 if (IsBrowserRepresentedInBrowserList(browser) && 113 if (IsBrowserRepresentedInBrowserList(browser) &&
115 browser->tab_strip_model()->GetActiveWebContents()) { 114 browser->tab_strip_model()->GetActiveWebContents()) {
116 SetShelfIDForBrowserWindowContents( 115 SetShelfIDForBrowserWindowContents(
117 browser, browser->tab_strip_model()->GetActiveWebContents()); 116 browser, browser->tab_strip_model()->GetActiveWebContents());
118 } 117 }
119 } 118 }
120 } 119 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 213
215 ash::ShelfAction action = 214 ash::ShelfAction action =
216 ChromeLauncherController::instance()->ActivateWindowOrMinimizeIfActive( 215 ChromeLauncherController::instance()->ActivateWindowOrMinimizeIfActive(
217 last_browser->window(), items.size() == 1); 216 last_browser->window(), items.size() == 1);
218 std::move(callback).Run(action, std::move(items)); 217 std::move(callback).Run(action, std::move(items));
219 } 218 }
220 219
221 ash::MenuItemList BrowserShortcutLauncherItemController::GetAppMenuItems( 220 ash::MenuItemList BrowserShortcutLauncherItemController::GetAppMenuItems(
222 int event_flags) { 221 int event_flags) {
223 browser_menu_items_.clear(); 222 browser_menu_items_.clear();
224 registrar_.RemoveAll(); 223 browser_list_observer_.RemoveAll();
225 224
226 ash::MenuItemList items; 225 ash::MenuItemList items;
227 bool found_tabbed_browser = false; 226 bool found_tabbed_browser = false;
228 ChromeLauncherController* controller = ChromeLauncherController::instance(); 227 ChromeLauncherController* controller = ChromeLauncherController::instance();
229 for (auto* browser : GetListOfActiveBrowsers()) { 228 for (auto* browser : GetListOfActiveBrowsers()) {
230 if (browser_menu_items_.size() >= kMaxItems) 229 if (browser_menu_items_.size() >= kMaxItems)
231 break; 230 break;
232 TabStripModel* tab_strip = browser->tab_strip_model(); 231 TabStripModel* tab_strip = browser->tab_strip_model();
233 const int tab_index = tab_strip->active_index(); 232 const int tab_index = tab_strip->active_index();
234 if (tab_index < 0 || tab_index >= kMaxItems) 233 if (tab_index < 0 || tab_index >= kMaxItems)
(...skipping 11 matching lines...) Expand all
246 for (uint16_t i = 0; i < tab_strip->count() && i < kMaxItems; ++i) { 245 for (uint16_t i = 0; i < tab_strip->count() && i < kMaxItems; ++i) {
247 content::WebContents* tab = tab_strip->GetWebContentsAt(i); 246 content::WebContents* tab = tab_strip->GetWebContentsAt(i);
248 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New()); 247 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New());
249 item->command_id = GetCommandId(browser_menu_items_.size(), i); 248 item->command_id = GetCommandId(browser_menu_items_.size(), i);
250 item->label = controller->GetAppListTitle(tab); 249 item->label = controller->GetAppListTitle(tab);
251 item->image = *controller->GetAppListIcon(tab).ToSkBitmap(); 250 item->image = *controller->GetAppListIcon(tab).ToSkBitmap();
252 items.push_back(std::move(item)); 251 items.push_back(std::move(item));
253 } 252 }
254 } 253 }
255 browser_menu_items_.push_back(browser); 254 browser_menu_items_.push_back(browser);
256 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, 255 if (!browser_list_observer_.IsObservingSources())
257 content::Source<Browser>(browser)); 256 browser_list_observer_.Add(BrowserList::GetInstance());
258 } 257 }
259 // If only windowed applications are open, we return an empty list to 258 // If only windowed applications are open, we return an empty list to
260 // enforce the creation of a new browser. 259 // enforce the creation of a new browser.
261 if (!found_tabbed_browser) { 260 if (!found_tabbed_browser) {
262 items.clear(); 261 items.clear();
263 browser_menu_items_.clear(); 262 browser_menu_items_.clear();
264 registrar_.RemoveAll(); 263 browser_list_observer_.RemoveAll();
265 } 264 }
266 return items; 265 return items;
267 } 266 }
268 267
269 void BrowserShortcutLauncherItemController::ExecuteCommand( 268 void BrowserShortcutLauncherItemController::ExecuteCommand(
270 uint32_t command_id, 269 uint32_t command_id,
271 int32_t event_flags) { 270 int32_t event_flags) {
272 const uint16_t browser_index = GetBrowserIndex(command_id); 271 const uint16_t browser_index = GetBrowserIndex(command_id);
273 // Check that the index is valid and the browser has not been closed. 272 // Check that the index is valid and the browser has not been closed.
274 if (browser_index < browser_menu_items_.size() && 273 if (browser_index < browser_menu_items_.size() &&
(...skipping 12 matching lines...) Expand all
287 multi_user_util::MoveWindowToCurrentDesktop( 286 multi_user_util::MoveWindowToCurrentDesktop(
288 browser->window()->GetNativeWindow()); 287 browser->window()->GetNativeWindow());
289 if (tab_index != kNoTab && tab_strip->ContainsIndex(tab_index)) 288 if (tab_index != kNoTab && tab_strip->ContainsIndex(tab_index))
290 tab_strip->ActivateTabAt(tab_index, false); 289 tab_strip->ActivateTabAt(tab_index, false);
291 browser->window()->Show(); 290 browser->window()->Show();
292 browser->window()->Activate(); 291 browser->window()->Activate();
293 } 292 }
294 } 293 }
295 294
296 browser_menu_items_.clear(); 295 browser_menu_items_.clear();
297 registrar_.RemoveAll(); 296 browser_list_observer_.RemoveAll();
298 } 297 }
299 298
300 void BrowserShortcutLauncherItemController::Close() { 299 void BrowserShortcutLauncherItemController::Close() {
301 for (auto* browser : GetListOfActiveBrowsers()) 300 for (auto* browser : GetListOfActiveBrowsers())
302 browser->window()->Close(); 301 browser->window()->Close();
303 } 302 }
304 303
305 bool BrowserShortcutLauncherItemController::IsListOfActiveBrowserEmpty() { 304 bool BrowserShortcutLauncherItemController::IsListOfActiveBrowserEmpty() {
306 return GetListOfActiveBrowsers().empty(); 305 return GetListOfActiveBrowsers().empty();
307 } 306 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 continue; 385 continue;
387 } 386 }
388 if (!IsBrowserRepresentedInBrowserList(browser) && 387 if (!IsBrowserRepresentedInBrowserList(browser) &&
389 !browser->is_type_tabbed()) 388 !browser->is_type_tabbed())
390 continue; 389 continue;
391 active_browsers.push_back(browser); 390 active_browsers.push_back(browser);
392 } 391 }
393 return active_browsers; 392 return active_browsers;
394 } 393 }
395 394
396 void BrowserShortcutLauncherItemController::Observe( 395 void BrowserShortcutLauncherItemController::OnBrowserClosing(Browser* browser) {
397 int type,
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); 396 DCHECK(browser);
403 BrowserList::BrowserVector::iterator item = std::find( 397 BrowserList::BrowserVector::iterator item = std::find(
404 browser_menu_items_.begin(), browser_menu_items_.end(), browser); 398 browser_menu_items_.begin(), browser_menu_items_.end(), browser);
405 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 if (item != browser_menu_items_.end())
408 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, 401 *item = nullptr;
409 content::Source<Browser>(browser));
410 } 402 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698