| 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/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 11 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 11 #include "chrome/browser/extensions/launch_util.h" | 12 #include "chrome/browser/extensions/launch_util.h" |
| 12 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 13 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 13 #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" |
| 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 18 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | 19 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
| 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 20 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return true; | 60 return true; |
| 60 return multi_user_util::IsProfileFromActiveUser(browser->profile()); | 61 return multi_user_util::IsProfileFromActiveUser(browser->profile()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 65 // static | 66 // static |
| 66 AppShortcutLauncherItemController* AppShortcutLauncherItemController::Create( | 67 AppShortcutLauncherItemController* AppShortcutLauncherItemController::Create( |
| 67 const std::string& app_id, | 68 const std::string& app_id, |
| 68 const std::string& launch_id, | 69 const std::string& launch_id, |
| 70 const std::string& title, |
| 69 ChromeLauncherController* controller) { | 71 ChromeLauncherController* controller) { |
| 70 if (app_id == ArcSupportHost::kHostAppId || app_id == arc::kPlayStoreAppId) | 72 if (app_id == ArcSupportHost::kHostAppId || app_id == arc::kPlayStoreAppId) |
| 71 return new ArcPlaystoreShortcutLauncherItemController(controller); | 73 return new ArcPlaystoreShortcutLauncherItemController(controller); |
| 72 return new AppShortcutLauncherItemController(app_id, launch_id, controller); | 74 return new AppShortcutLauncherItemController(app_id, launch_id, title, |
| 75 controller); |
| 73 } | 76 } |
| 74 | 77 |
| 75 // Item controller for an app shortcut. Shortcuts track app and launcher ids, | 78 // Item controller for an app shortcut. Shortcuts track app and launcher ids, |
| 76 // but do not have any associated windows (opening a shortcut will replace the | 79 // but do not have any associated windows (opening a shortcut will replace the |
| 77 // item with the appropriate LauncherItemController type). | 80 // item with the appropriate LauncherItemController type). |
| 78 AppShortcutLauncherItemController::AppShortcutLauncherItemController( | 81 AppShortcutLauncherItemController::AppShortcutLauncherItemController( |
| 79 const std::string& app_id, | 82 const std::string& app_id, |
| 80 const std::string& launch_id, | 83 const std::string& launch_id, |
| 84 const std::string& title, |
| 81 ChromeLauncherController* controller) | 85 ChromeLauncherController* controller) |
| 82 : LauncherItemController(TYPE_SHORTCUT, app_id, launch_id, controller), | 86 : LauncherItemController(TYPE_SHORTCUT, |
| 87 app_id, |
| 88 launch_id, |
| 89 title, |
| 90 controller), |
| 83 chrome_launcher_controller_(controller) { | 91 chrome_launcher_controller_(controller) { |
| 84 // To detect V1 applications we use their domain and match them against the | 92 // To detect V1 applications we use their domain and match them against the |
| 85 // used URL. This will also work with applications like Google Drive. | 93 // used URL. This will also work with applications like Google Drive. |
| 86 const Extension* extension = | 94 const Extension* extension = |
| 87 GetExtensionForAppID(app_id, controller->profile()); | 95 GetExtensionForAppID(app_id, controller->profile()); |
| 88 // Some unit tests have no real extension. | 96 // Some unit tests have no real extension. |
| 89 if (extension) { | 97 if (extension) { |
| 90 set_refocus_url(GURL( | 98 set_refocus_url(GURL( |
| 91 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); | 99 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); |
| 92 } | 100 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 // In case of a keyboard event, we were called by a hotkey. In that case we | 212 // In case of a keyboard event, we were called by a hotkey. In that case we |
| 205 // activate the next item in line if an item of our list is already active. | 213 // activate the next item in line if an item of our list is already active. |
| 206 if (event.type() == ui::ET_KEY_RELEASED) { | 214 if (event.type() == ui::ET_KEY_RELEASED) { |
| 207 if (AdvanceToNextApp()) | 215 if (AdvanceToNextApp()) |
| 208 return kExistingWindowActivated; | 216 return kExistingWindowActivated; |
| 209 } | 217 } |
| 210 return Activate(ash::LAUNCH_FROM_UNKNOWN); | 218 return Activate(ash::LAUNCH_FROM_UNKNOWN); |
| 211 } | 219 } |
| 212 | 220 |
| 213 base::string16 AppShortcutLauncherItemController::GetTitle() { | 221 base::string16 AppShortcutLauncherItemController::GetTitle() { |
| 214 return LauncherControllerHelper::GetAppTitle(launcher_controller()->profile(), | 222 if (!title().empty()) |
| 215 app_id()); | 223 return base::UTF8ToUTF16(title()); |
| 224 else |
| 225 return LauncherControllerHelper::GetAppTitle( |
| 226 launcher_controller()->profile(), app_id()); |
| 216 } | 227 } |
| 217 | 228 |
| 218 ash::ShelfMenuModel* AppShortcutLauncherItemController::CreateApplicationMenu( | 229 ash::ShelfMenuModel* AppShortcutLauncherItemController::CreateApplicationMenu( |
| 219 int event_flags) { | 230 int event_flags) { |
| 220 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); | 231 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); |
| 221 } | 232 } |
| 222 | 233 |
| 223 bool AppShortcutLauncherItemController::IsDraggable() { | 234 bool AppShortcutLauncherItemController::IsDraggable() { |
| 224 return true; | 235 return true; |
| 225 } | 236 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 383 |
| 373 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 384 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
| 374 if (last_launch_attempt_.is_null() || | 385 if (last_launch_attempt_.is_null() || |
| 375 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 386 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
| 376 kClickSuppressionInMS) < base::Time::Now()) { | 387 kClickSuppressionInMS) < base::Time::Now()) { |
| 377 last_launch_attempt_ = base::Time::Now(); | 388 last_launch_attempt_ = base::Time::Now(); |
| 378 return true; | 389 return true; |
| 379 } | 390 } |
| 380 return false; | 391 return false; |
| 381 } | 392 } |
| OLD | NEW |