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

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: Address comments. 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 for (size_t i = 0; i < app_menu_items_.size(); i++) {
131 content::WebContents* web_contents = content_list[i]; 130 content::WebContents* web_contents = app_menu_items_[i];
132 gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents); 131 gfx::Image icon = launcher_controller()->GetAppListIcon(web_contents);
133 base::string16 title = launcher_controller()->GetAppListTitle(web_contents); 132 base::string16 title = launcher_controller()->GetAppListTitle(web_contents);
134 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>( 133 items.push_back(base::MakeUnique<ash::ShelfApplicationMenuItem>(
135 title, &app_icon, web_contents)); 134 base::checked_cast<uint32_t>(i), title, &icon));
136 } 135 }
137 return items; 136 return items;
138 } 137 }
139 138
139 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id,
140 int event_flags) {
141 if (static_cast<size_t>(command_id) >= app_menu_items_.size()) {
142 app_menu_items_.clear();
143 return;
144 }
145
146 // If the web contents was destroyed while the menu was open, then the invalid
147 // pointer cached in |app_menu_items_| should yield a null browser or kNoTab.
148 content::WebContents* web_contents = app_menu_items_[command_id];
149 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
150 TabStripModel* tab_strip = browser ? browser->tab_strip_model() : nullptr;
151 const int index = tab_strip ? tab_strip->GetIndexOfWebContents(web_contents)
152 : TabStripModel::kNoTab;
153 if (index != TabStripModel::kNoTab) {
154 if (event_flags & (ui::EF_SHIFT_DOWN | ui::EF_MIDDLE_MOUSE_BUTTON)) {
155 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_USER_GESTURE);
156 } else {
157 multi_user_util::MoveWindowToCurrentDesktop(
158 browser->window()->GetNativeWindow());
159 tab_strip->ActivateTabAt(index, false);
160 browser->window()->Show();
161 browser->window()->Activate();
162 }
163 }
164
165 app_menu_items_.clear();
166 }
167
140 void AppShortcutLauncherItemController::Close() { 168 void AppShortcutLauncherItemController::Close() {
141 // Close all running 'programs' of this type. 169 // Close all running 'programs' of this type.
142 std::vector<content::WebContents*> content = 170 std::vector<content::WebContents*> content =
143 launcher_controller()->GetV1ApplicationsFromAppId(app_id()); 171 launcher_controller()->GetV1ApplicationsFromAppId(app_id());
144 for (size_t i = 0; i < content.size(); i++) { 172 for (size_t i = 0; i < content.size(); i++) {
145 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); 173 Browser* browser = chrome::FindBrowserWithWebContents(content[i]);
146 if (!browser || !IsBrowserFromActiveUser(browser)) 174 if (!browser || !IsBrowserFromActiveUser(browser))
147 continue; 175 continue;
148 TabStripModel* tab_strip = browser->tab_strip_model(); 176 TabStripModel* tab_strip = browser->tab_strip_model();
149 int index = tab_strip->GetIndexOfWebContents(content[i]); 177 int index = tab_strip->GetIndexOfWebContents(content[i]);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 351
324 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 352 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
325 if (last_launch_attempt_.is_null() || 353 if (last_launch_attempt_.is_null() ||
326 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 354 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
327 kClickSuppressionInMS) < base::Time::Now()) { 355 kClickSuppressionInMS) < base::Time::Now()) {
328 last_launch_attempt_ = base::Time::Now(); 356 last_launch_attempt_ = base::Time::Now();
329 return true; 357 return true;
330 } 358 }
331 return false; 359 return false;
332 } 360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698