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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == | 54 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == |
55 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) | 55 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) |
56 return true; | 56 return true; |
57 return multi_user_util::IsProfileFromActiveUser(browser->profile()); | 57 return multi_user_util::IsProfileFromActiveUser(browser->profile()); |
58 } | 58 } |
59 | 59 |
60 } // namespace | 60 } // namespace |
61 | 61 |
62 // static | 62 // static |
63 std::unique_ptr<AppShortcutLauncherItemController> | 63 std::unique_ptr<AppShortcutLauncherItemController> |
64 AppShortcutLauncherItemController::Create( | 64 AppShortcutLauncherItemController::Create(const ash::ShelfID& shelf_id) { |
65 const ash::AppLaunchId& app_launch_id) { | 65 if (shelf_id.app_id() == ArcSupportHost::kHostAppId || |
66 if (app_launch_id.app_id() == ArcSupportHost::kHostAppId || | 66 shelf_id.app_id() == arc::kPlayStoreAppId) { |
67 app_launch_id.app_id() == arc::kPlayStoreAppId) { | |
68 return base::MakeUnique<ArcPlaystoreShortcutLauncherItemController>(); | 67 return base::MakeUnique<ArcPlaystoreShortcutLauncherItemController>(); |
69 } | 68 } |
70 return base::WrapUnique<AppShortcutLauncherItemController>( | 69 return base::WrapUnique<AppShortcutLauncherItemController>( |
71 new AppShortcutLauncherItemController(app_launch_id)); | 70 new AppShortcutLauncherItemController(shelf_id)); |
72 } | 71 } |
73 | 72 |
74 // Item controller for an app shortcut. Shortcuts track app and launcher ids, | 73 // Item controller for an app shortcut. Shortcuts track app and launcher ids, |
75 // but do not have any associated windows (opening a shortcut will replace the | 74 // but do not have any associated windows (opening a shortcut will replace the |
76 // item with the appropriate ash::ShelfItemDelegate type). | 75 // item with the appropriate ash::ShelfItemDelegate type). |
77 AppShortcutLauncherItemController::AppShortcutLauncherItemController( | 76 AppShortcutLauncherItemController::AppShortcutLauncherItemController( |
78 const ash::AppLaunchId& app_launch_id) | 77 const ash::ShelfID& shelf_id) |
79 : ash::ShelfItemDelegate(app_launch_id) { | 78 : ash::ShelfItemDelegate(shelf_id) { |
80 // To detect V1 applications we use their domain and match them against the | 79 // To detect V1 applications we use their domain and match them against the |
81 // used URL. This will also work with applications like Google Drive. | 80 // used URL. This will also work with applications like Google Drive. |
82 const Extension* extension = GetExtensionForAppID( | 81 const Extension* extension = GetExtensionForAppID( |
83 app_launch_id.app_id(), ChromeLauncherController::instance()->profile()); | 82 shelf_id.app_id(), ChromeLauncherController::instance()->profile()); |
84 // Some unit tests have no real extension. | 83 // Some unit tests have no real extension. |
85 if (extension) { | 84 if (extension) { |
86 set_refocus_url(GURL( | 85 set_refocus_url(GURL( |
87 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); | 86 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); |
88 } | 87 } |
89 } | 88 } |
90 | 89 |
91 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {} | 90 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {} |
92 | 91 |
93 void AppShortcutLauncherItemController::ItemSelected( | 92 void AppShortcutLauncherItemController::ItemSelected( |
(...skipping 15 matching lines...) Expand all Loading... |
109 // which take a lot of time for pre-processing (like the files app) before | 108 // which take a lot of time for pre-processing (like the files app) before |
110 // they open a window. Since there is currently no other way to detect if an | 109 // they open a window. Since there is currently no other way to detect if an |
111 // app was started we suppress any further clicks within a special time out. | 110 // app was started we suppress any further clicks within a special time out. |
112 if (IsV2App() && !AllowNextLaunchAttempt()) { | 111 if (IsV2App() && !AllowNextLaunchAttempt()) { |
113 callback.Run(ash::SHELF_ACTION_NONE, | 112 callback.Run(ash::SHELF_ACTION_NONE, |
114 GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); | 113 GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); |
115 return; | 114 return; |
116 } | 115 } |
117 | 116 |
118 // Launching some items replaces this item controller instance, which | 117 // Launching some items replaces this item controller instance, which |
119 // destroys its AppLaunchId string pair; making copies avoid crashes. | 118 // destroys its ShelfID string pair; making copies avoid crashes. |
120 ChromeLauncherController::instance()->LaunchApp( | 119 ChromeLauncherController::instance()->LaunchApp(ash::ShelfID(shelf_id()), |
121 ash::AppLaunchId(app_launch_id()), source, ui::EF_NONE); | 120 source, ui::EF_NONE); |
122 callback.Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, base::nullopt); | 121 callback.Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, base::nullopt); |
123 return; | 122 return; |
124 } | 123 } |
125 | 124 |
126 const ash::ShelfAction action = ActivateContent(content); | 125 const ash::ShelfAction action = ActivateContent(content); |
127 callback.Run(action, GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); | 126 callback.Run(action, GetAppMenuItems(event ? event->flags() : ui::EF_NONE)); |
128 } | 127 } |
129 | 128 |
130 ash::MenuItemList AppShortcutLauncherItemController::GetAppMenuItems( | 129 ash::MenuItemList AppShortcutLauncherItemController::GetAppMenuItems( |
131 int event_flags) { | 130 int event_flags) { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 361 |
363 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 362 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
364 if (last_launch_attempt_.is_null() || | 363 if (last_launch_attempt_.is_null() || |
365 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 364 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
366 kClickSuppressionInMS) < base::Time::Now()) { | 365 kClickSuppressionInMS) < base::Time::Now()) { |
367 last_launch_attempt_ = base::Time::Now(); | 366 last_launch_attempt_ = base::Time::Now(); |
368 return true; | 367 return true; |
369 } | 368 } |
370 return false; | 369 return false; |
371 } | 370 } |
OLD | NEW |