OLD | NEW |
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" | |
10 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
11 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
12 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 11 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
13 #include "chrome/browser/extensions/launch_util.h" | 12 #include "chrome/browser/extensions/launch_util.h" |
14 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 13 #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" | 14 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co
ntroller.h" |
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
18 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 17 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
19 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 18 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 GetExtensionForAppID(app_id, controller->profile()); | 85 GetExtensionForAppID(app_id, controller->profile()); |
87 // Some unit tests have no real extension. | 86 // Some unit tests have no real extension. |
88 if (extension) { | 87 if (extension) { |
89 set_refocus_url(GURL( | 88 set_refocus_url(GURL( |
90 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); | 89 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); |
91 } | 90 } |
92 } | 91 } |
93 | 92 |
94 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {} | 93 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {} |
95 | 94 |
96 ash::ShelfAction AppShortcutLauncherItemController::ItemSelected( | 95 void AppShortcutLauncherItemController::ItemSelected( |
97 ui::EventType event_type, | 96 std::unique_ptr<ui::Event> event, |
98 int event_flags, | |
99 int64_t display_id, | 97 int64_t display_id, |
100 ash::ShelfLaunchSource source) { | 98 ash::ShelfLaunchSource source, |
| 99 const ItemSelectedCallback& callback) { |
101 // In case of a keyboard event, we were called by a hotkey. In that case we | 100 // In case of a keyboard event, we were called by a hotkey. In that case we |
102 // activate the next item in line if an item of our list is already active. | 101 // activate the next item in line if an item of our list is already active. |
103 if (event_type == ui::ET_KEY_RELEASED && AdvanceToNextApp()) | 102 if (event && event->type() == ui::ET_KEY_RELEASED && AdvanceToNextApp()) { |
104 return ash::SHELF_ACTION_WINDOW_ACTIVATED; | 103 callback.Run(ash::SHELF_ACTION_WINDOW_ACTIVATED, base::nullopt); |
| 104 return; |
| 105 } |
105 | 106 |
106 content::WebContents* content = GetLRUApplication(); | 107 content::WebContents* content = GetLRUApplication(); |
107 if (!content) { | 108 if (!content) { |
108 // Ideally we come here only once. After that ShellLauncherItemController | 109 // Ideally we come here only once. After that ShellLauncherItemController |
109 // will take over when the shell window gets opened. However there are apps | 110 // will take over when the shell window gets opened. However there are apps |
110 // which take a lot of time for pre-processing (like the files app) before | 111 // which take a lot of time for pre-processing (like the files app) before |
111 // they open a window. Since there is currently no other way to detect if an | 112 // they open a window. Since there is currently no other way to detect if an |
112 // app was started we suppress any further clicks within a special time out. | 113 // app was started we suppress any further clicks within a special time out. |
113 if (IsV2App() && !AllowNextLaunchAttempt()) | 114 if (IsV2App() && !AllowNextLaunchAttempt()) { |
114 return ash::SHELF_ACTION_NONE; | 115 callback.Run(ash::SHELF_ACTION_NONE, |
| 116 GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); |
| 117 return; |
| 118 } |
115 | 119 |
116 // Launching some items replaces this item controller instance, which | 120 // Launching some items replaces this item controller instance, which |
117 // destroys the app and launch id strings; making copies avoid crashes. | 121 // destroys the app and launch id strings; making copies avoid crashes. |
118 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()), | 122 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()), |
119 source, ui::EF_NONE); | 123 source, ui::EF_NONE); |
120 return ash::SHELF_ACTION_NEW_WINDOW_CREATED; | 124 callback.Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, base::nullopt); |
| 125 return; |
121 } | 126 } |
122 return ActivateContent(content); | 127 |
| 128 const ash::ShelfAction action = ActivateContent(content); |
| 129 callback.Run(action, GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); |
123 } | 130 } |
124 | 131 |
125 ash::ShelfAppMenuItemList AppShortcutLauncherItemController::GetAppMenuItems( | 132 MenuItemList AppShortcutLauncherItemController::GetAppMenuItems( |
126 int event_flags) { | 133 int event_flags) { |
127 ash::ShelfAppMenuItemList items; | 134 MenuItemList items; |
128 app_menu_items_ = GetRunningApplications(); | 135 app_menu_items_ = GetRunningApplications(); |
129 for (size_t i = 0; i < app_menu_items_.size(); i++) { | 136 for (size_t i = 0; i < app_menu_items_.size(); i++) { |
130 content::WebContents* web_contents = app_menu_items_[i]; | 137 content::WebContents* tab = app_menu_items_[i]; |
131 gfx::Image icon = launcher_controller()->GetAppListIcon(web_contents); | 138 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New()); |
132 base::string16 title = launcher_controller()->GetAppListTitle(web_contents); | 139 item->command_id = base::checked_cast<uint32_t>(i); |
133 items.push_back(base::MakeUnique<ash::ShelfApplicationMenuItem>( | 140 item->label = launcher_controller()->GetAppListTitle(tab); |
134 base::checked_cast<uint32_t>(i), title, &icon)); | 141 item->image = *launcher_controller()->GetAppListIcon(tab).ToSkBitmap(); |
| 142 items.push_back(std::move(item)); |
135 } | 143 } |
136 return items; | 144 return items; |
137 } | 145 } |
138 | 146 |
139 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id, | 147 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id, |
140 int event_flags) { | 148 int32_t event_flags) { |
141 if (static_cast<size_t>(command_id) >= app_menu_items_.size()) { | 149 if (static_cast<size_t>(command_id) >= app_menu_items_.size()) { |
142 app_menu_items_.clear(); | 150 app_menu_items_.clear(); |
143 return; | 151 return; |
144 } | 152 } |
145 | 153 |
146 // If the web contents was destroyed while the menu was open, then the invalid | 154 // 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. | 155 // pointer cached in |app_menu_items_| should yield a null browser or kNoTab. |
148 content::WebContents* web_contents = app_menu_items_[command_id]; | 156 content::WebContents* web_contents = app_menu_items_[command_id]; |
149 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 157 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
150 TabStripModel* tab_strip = browser ? browser->tab_strip_model() : nullptr; | 158 TabStripModel* tab_strip = browser ? browser->tab_strip_model() : nullptr; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 359 |
352 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 360 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
353 if (last_launch_attempt_.is_null() || | 361 if (last_launch_attempt_.is_null() || |
354 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 362 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
355 kClickSuppressionInMS) < base::Time::Now()) { | 363 kClickSuppressionInMS) < base::Time::Now()) { |
356 last_launch_attempt_ = base::Time::Now(); | 364 last_launch_attempt_ = base::Time::Now(); |
357 return true; | 365 return true; |
358 } | 366 } |
359 return false; | 367 return false; |
360 } | 368 } |
OLD | NEW |