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, MenuItemList()); |
104 return; | |
105 } | |
105 | 106 |
106 content::WebContents* content = GetLRUApplication(); | 107 content::WebContents* content = GetLRUApplication(); |
108 MenuItemList items = GetAppMenuItems(event ? event->flags() : ui::EF_NONE); | |
James Cook
2017/03/09 01:09:47
optional: maybe just do this in the two cases belo
msw
2017/03/10 06:17:57
Done.
| |
107 if (!content) { | 109 if (!content) { |
108 // Ideally we come here only once. After that ShellLauncherItemController | 110 // Ideally we come here only once. After that ShellLauncherItemController |
109 // will take over when the shell window gets opened. However there are apps | 111 // 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 | 112 // 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 | 113 // 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. | 114 // app was started we suppress any further clicks within a special time out. |
113 if (IsV2App() && !AllowNextLaunchAttempt()) | 115 if (IsV2App() && !AllowNextLaunchAttempt()) { |
114 return ash::SHELF_ACTION_NONE; | 116 callback.Run(ash::SHELF_ACTION_NONE, std::move(items)); |
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, MenuItemList()); |
125 return; | |
121 } | 126 } |
122 return ActivateContent(content); | 127 |
128 callback.Run(ActivateContent(content), std::move(items)); | |
James Cook
2017/03/09 01:09:47
optional nit: maybe put the result of ActivateCont
msw
2017/03/10 06:17:57
Done.
| |
123 } | 129 } |
124 | 130 |
125 ash::ShelfAppMenuItemList AppShortcutLauncherItemController::GetAppMenuItems( | 131 ash::ShelfItemDelegate::MenuItemList |
126 int event_flags) { | 132 AppShortcutLauncherItemController::GetAppMenuItems(int event_flags) { |
127 ash::ShelfAppMenuItemList items; | 133 MenuItemList items; |
128 app_menu_items_ = GetRunningApplications(); | 134 app_menu_items_ = GetRunningApplications(); |
129 for (size_t i = 0; i < app_menu_items_.size(); i++) { | 135 for (size_t i = 0; i < app_menu_items_.size(); i++) { |
130 content::WebContents* web_contents = app_menu_items_[i]; | 136 content::WebContents* tab = app_menu_items_[i]; |
131 gfx::Image icon = launcher_controller()->GetAppListIcon(web_contents); | 137 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New()); |
132 base::string16 title = launcher_controller()->GetAppListTitle(web_contents); | 138 item->command_id = base::checked_cast<uint32_t>(i); |
133 items.push_back(base::MakeUnique<ash::ShelfApplicationMenuItem>( | 139 item->label = launcher_controller()->GetAppListTitle(tab); |
134 base::checked_cast<uint32_t>(i), title, &icon)); | 140 item->image = *launcher_controller()->GetAppListIcon(tab).ToSkBitmap(); |
141 items.push_back(std::move(item)); | |
135 } | 142 } |
136 return items; | 143 return items; |
137 } | 144 } |
138 | 145 |
139 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id, | 146 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id, |
140 int event_flags) { | 147 int32_t event_flags) { |
141 if (static_cast<size_t>(command_id) >= app_menu_items_.size()) { | 148 if (static_cast<size_t>(command_id) >= app_menu_items_.size()) { |
142 app_menu_items_.clear(); | 149 app_menu_items_.clear(); |
143 return; | 150 return; |
144 } | 151 } |
145 | 152 |
146 // If the web contents was destroyed while the menu was open, then the invalid | 153 // 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. | 154 // pointer cached in |app_menu_items_| should yield a null browser or kNoTab. |
148 content::WebContents* web_contents = app_menu_items_[command_id]; | 155 content::WebContents* web_contents = app_menu_items_[command_id]; |
149 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 156 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
150 TabStripModel* tab_strip = browser ? browser->tab_strip_model() : nullptr; | 157 TabStripModel* tab_strip = browser ? browser->tab_strip_model() : nullptr; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 | 358 |
352 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 359 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
353 if (last_launch_attempt_.is_null() || | 360 if (last_launch_attempt_.is_null() || |
354 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 361 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
355 kClickSuppressionInMS) < base::Time::Now()) { | 362 kClickSuppressionInMS) < base::Time::Now()) { |
356 last_launch_attempt_ = base::Time::Now(); | 363 last_launch_attempt_ = base::Time::Now(); |
357 return true; | 364 return true; |
358 } | 365 } |
359 return false; | 366 return false; |
360 } | 367 } |
OLD | NEW |