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

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

Issue 2716403005: mash: Remove shelf app menu item objects. (Closed)
Patch Set: Fix ash_shell compile Created 3 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/app_shortcut_launcher_item_controller.h " 5 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/public/cpp/shelf_application_menu_item.h" 9 #include "ash/public/cpp/shelf_application_menu_item.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/chromeos/arc/arc_support_host.h" 12 #include "chrome/browser/chromeos/arc/arc_support_host.h"
13 #include "chrome/browser/extensions/launch_util.h" 13 #include "chrome/browser/extensions/launch_util.h"
14 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 14 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
15 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h" 15 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 18 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
20 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" 19 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
21 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 20 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
22 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 21 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
23 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 22 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
24 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_finder.h" 24 #include "chrome/browser/ui/browser_finder.h"
26 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()), 118 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()),
120 source, ui::EF_NONE); 119 source, ui::EF_NONE);
121 return ash::SHELF_ACTION_NEW_WINDOW_CREATED; 120 return ash::SHELF_ACTION_NEW_WINDOW_CREATED;
122 } 121 }
123 return ActivateContent(content); 122 return ActivateContent(content);
124 } 123 }
125 124
126 ash::ShelfAppMenuItemList AppShortcutLauncherItemController::GetAppMenuItems( 125 ash::ShelfAppMenuItemList AppShortcutLauncherItemController::GetAppMenuItems(
127 int event_flags) { 126 int event_flags) {
128 ash::ShelfAppMenuItemList items; 127 ash::ShelfAppMenuItemList items;
129 std::vector<content::WebContents*> content_list = GetRunningApplications(); 128 app_menu_items_ = GetRunningApplications();
130 for (size_t i = 0; i < content_list.size(); i++) { 129 CHECK_LT(app_menu_items_.size(), std::numeric_limits<uint32_t>::max());
James Cook 2017/03/01 19:50:48 Is this useful? It looks like GetRunningApplicatio
msw 2017/03/02 02:59:20 These checks are indeed a bit paranoid... I doubt
James Cook 2017/03/02 15:43:00 This check implies GetRunningApplications() can lo
msw 2017/03/02 18:37:47 I was checking against uint32_t, because that's th
131 content::WebContents* web_contents = content_list[i]; 130 for (size_t i = 0; i < app_menu_items_.size(); i++) {
132 gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents); 131 content::WebContents* web_contents = app_menu_items_[i];
132 gfx::Image icon = launcher_controller()->GetAppListIcon(web_contents);
133 base::string16 title = launcher_controller()->GetAppListTitle(web_contents); 133 base::string16 title = launcher_controller()->GetAppListTitle(web_contents);
134 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>( 134 items.push_back(base::MakeUnique<ash::ShelfApplicationMenuItem>(
135 title, &app_icon, web_contents)); 135 base::checked_cast<uint32_t>(i), title, &icon));
136 } 136 }
137 return items; 137 return items;
138 } 138 }
139 139
140 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id,
141 int32_t event_flags) {
142 if (static_cast<size_t>(command_id) >= app_menu_items_.size())
143 return;
144
145 content::WebContents* web_contents = app_menu_items_[command_id];
146 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
147 if (!browser)
148 return;
149
150 TabStripModel* tab_strip = browser->tab_strip_model();
151 int index = tab_strip->GetIndexOfWebContents(web_contents);
152 DCHECK_NE(index, TabStripModel::kNoTab);
James Cook 2017/03/01 19:50:48 Should this early-exit? Is it possible a tab could
msw 2017/03/02 02:59:20 Done.
153 if (event_flags & (ui::EF_SHIFT_DOWN | ui::EF_MIDDLE_MOUSE_BUTTON)) {
154 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_USER_GESTURE);
155 } else {
156 multi_user_util::MoveWindowToCurrentDesktop(
157 browser->window()->GetNativeWindow());
158 tab_strip->ActivateTabAt(index, false);
159 browser->window()->Show();
160 browser->window()->Activate();
161 }
162 }
163
140 void AppShortcutLauncherItemController::Close() { 164 void AppShortcutLauncherItemController::Close() {
141 // Close all running 'programs' of this type. 165 // Close all running 'programs' of this type.
142 std::vector<content::WebContents*> content = 166 std::vector<content::WebContents*> content =
143 launcher_controller()->GetV1ApplicationsFromAppId(app_id()); 167 launcher_controller()->GetV1ApplicationsFromAppId(app_id());
144 for (size_t i = 0; i < content.size(); i++) { 168 for (size_t i = 0; i < content.size(); i++) {
145 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); 169 Browser* browser = chrome::FindBrowserWithWebContents(content[i]);
146 if (!browser || !IsBrowserFromActiveUser(browser)) 170 if (!browser || !IsBrowserFromActiveUser(browser))
147 continue; 171 continue;
148 TabStripModel* tab_strip = browser->tab_strip_model(); 172 TabStripModel* tab_strip = browser->tab_strip_model();
149 int index = tab_strip->GetIndexOfWebContents(content[i]); 173 int index = tab_strip->GetIndexOfWebContents(content[i]);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 347
324 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 348 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
325 if (last_launch_attempt_.is_null() || 349 if (last_launch_attempt_.is_null() ||
326 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 350 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
327 kClickSuppressionInMS) < base::Time::Now()) { 351 kClickSuppressionInMS) < base::Time::Now()) {
328 last_launch_attempt_ = base::Time::Now(); 352 last_launch_attempt_ = base::Time::Now();
329 return true; 353 return true;
330 } 354 }
331 return false; 355 return false;
332 } 356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698