Chromium Code Reviews| 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, |
| 104 std::vector<ash::mojom::MenuItemPtr>()); | |
|
James Cook
2017/03/10 16:56:01
optional: Out of curiosity, WDTY of using an optio
msw
2017/03/10 20:44:45
Done; I also added a using statement in launcher_i
| |
| 105 return; | |
| 106 } | |
| 105 | 107 |
| 106 content::WebContents* content = GetLRUApplication(); | 108 content::WebContents* content = GetLRUApplication(); |
| 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, |
| 117 GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); | |
| 118 return; | |
| 119 } | |
| 115 | 120 |
| 116 // Launching some items replaces this item controller instance, which | 121 // Launching some items replaces this item controller instance, which |
| 117 // destroys the app and launch id strings; making copies avoid crashes. | 122 // destroys the app and launch id strings; making copies avoid crashes. |
| 118 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()), | 123 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()), |
| 119 source, ui::EF_NONE); | 124 source, ui::EF_NONE); |
| 120 return ash::SHELF_ACTION_NEW_WINDOW_CREATED; | 125 callback.Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, |
| 126 std::vector<ash::mojom::MenuItemPtr>()); | |
| 127 return; | |
| 121 } | 128 } |
| 122 return ActivateContent(content); | 129 |
| 130 const ash::ShelfAction action = ActivateContent(content); | |
| 131 callback.Run(action, GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); | |
| 123 } | 132 } |
| 124 | 133 |
| 125 ash::ShelfAppMenuItemList AppShortcutLauncherItemController::GetAppMenuItems( | 134 std::vector<ash::mojom::MenuItemPtr> |
| 126 int event_flags) { | 135 AppShortcutLauncherItemController::GetAppMenuItems(int event_flags) { |
| 127 ash::ShelfAppMenuItemList items; | 136 std::vector<ash::mojom::MenuItemPtr> items; |
| 128 app_menu_items_ = GetRunningApplications(); | 137 app_menu_items_ = GetRunningApplications(); |
| 129 for (size_t i = 0; i < app_menu_items_.size(); i++) { | 138 for (size_t i = 0; i < app_menu_items_.size(); i++) { |
| 130 content::WebContents* web_contents = app_menu_items_[i]; | 139 content::WebContents* tab = app_menu_items_[i]; |
| 131 gfx::Image icon = launcher_controller()->GetAppListIcon(web_contents); | 140 ash::mojom::MenuItemPtr item(ash::mojom::MenuItem::New()); |
| 132 base::string16 title = launcher_controller()->GetAppListTitle(web_contents); | 141 item->command_id = base::checked_cast<uint32_t>(i); |
| 133 items.push_back(base::MakeUnique<ash::ShelfApplicationMenuItem>( | 142 item->label = launcher_controller()->GetAppListTitle(tab); |
| 134 base::checked_cast<uint32_t>(i), title, &icon)); | 143 item->image = *launcher_controller()->GetAppListIcon(tab).ToSkBitmap(); |
| 144 items.push_back(std::move(item)); | |
| 135 } | 145 } |
| 136 return items; | 146 return items; |
| 137 } | 147 } |
| 138 | 148 |
| 139 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id, | 149 void AppShortcutLauncherItemController::ExecuteCommand(uint32_t command_id, |
| 140 int event_flags) { | 150 int32_t event_flags) { |
| 141 if (static_cast<size_t>(command_id) >= app_menu_items_.size()) { | 151 if (static_cast<size_t>(command_id) >= app_menu_items_.size()) { |
| 142 app_menu_items_.clear(); | 152 app_menu_items_.clear(); |
| 143 return; | 153 return; |
| 144 } | 154 } |
| 145 | 155 |
| 146 // If the web contents was destroyed while the menu was open, then the invalid | 156 // 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. | 157 // pointer cached in |app_menu_items_| should yield a null browser or kNoTab. |
| 148 content::WebContents* web_contents = app_menu_items_[command_id]; | 158 content::WebContents* web_contents = app_menu_items_[command_id]; |
| 149 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 159 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 150 TabStripModel* tab_strip = browser ? browser->tab_strip_model() : nullptr; | 160 TabStripModel* tab_strip = browser ? browser->tab_strip_model() : nullptr; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 | 361 |
| 352 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 362 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
| 353 if (last_launch_attempt_.is_null() || | 363 if (last_launch_attempt_.is_null() || |
| 354 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 364 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
| 355 kClickSuppressionInMS) < base::Time::Now()) { | 365 kClickSuppressionInMS) < base::Time::Now()) { |
| 356 last_launch_attempt_ = base::Time::Now(); | 366 last_launch_attempt_ = base::Time::Now(); |
| 357 return true; | 367 return true; |
| 358 } | 368 } |
| 359 return false; | 369 return false; |
| 360 } | 370 } |
| OLD | NEW |