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 "apps/native_app_window.h" | 7 #include "apps/native_app_window.h" |
| 8 #include "ash/launcher/launcher_model.h" |
8 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
9 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
10 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 12 #include "chrome/browser/favicon/favicon_tab_helper.h" |
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 16 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
| 17 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
15 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 18 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
16 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
18 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/browser/ui/host_desktop.h" | 23 #include "chrome/browser/ui/host_desktop.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 25 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
23 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
24 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
25 #include "ui/base/events/event.h" | 28 #include "ui/base/events/event.h" |
26 #include "ui/views/corewm/window_animations.h" | 29 #include "ui/views/corewm/window_animations.h" |
27 | 30 |
| 31 #if defined(OS_CHROMEOS) |
| 32 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
| 33 #endif |
| 34 |
28 using extensions::Extension; | 35 using extensions::Extension; |
29 | 36 |
30 namespace { | 37 namespace { |
31 | 38 |
32 // The time delta between clicks in which clicks to launch V2 apps are ignored. | 39 // The time delta between clicks in which clicks to launch V2 apps are ignored. |
33 const int kClickSuppressionInMS = 1000; | 40 const int kClickSuppressionInMS = 1000; |
34 | 41 |
35 } // namespace | 42 } // namespace |
36 | 43 |
37 // Item controller for an app shortcut. Shortcuts track app and launcher ids, | 44 // Item controller for an app shortcut. Shortcuts track app and launcher ids, |
(...skipping 11 matching lines...) Expand all Loading... |
49 // Some unit tests have no real extension. | 56 // Some unit tests have no real extension. |
50 if (extension) { | 57 if (extension) { |
51 set_refocus_url(GURL( | 58 set_refocus_url(GURL( |
52 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); | 59 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); |
53 } | 60 } |
54 } | 61 } |
55 | 62 |
56 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() { | 63 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() { |
57 } | 64 } |
58 | 65 |
59 string16 AppShortcutLauncherItemController::GetTitle() { | |
60 return GetAppTitle(); | |
61 } | |
62 | |
63 bool AppShortcutLauncherItemController::IsCurrentlyShownInWindow( | 66 bool AppShortcutLauncherItemController::IsCurrentlyShownInWindow( |
64 aura::Window* window) const { | 67 aura::Window* window) const { |
65 Browser* browser = chrome::FindBrowserWithWindow(window); | 68 Browser* browser = chrome::FindBrowserWithWindow(window); |
66 content::WebContents* active_content_of_window = | 69 content::WebContents* active_content_of_window = |
67 browser ? browser->tab_strip_model()->GetActiveWebContents() : NULL; | 70 browser ? browser->tab_strip_model()->GetActiveWebContents() : NULL; |
68 | 71 |
69 std::vector<content::WebContents*> content = | 72 std::vector<content::WebContents*> content = |
70 chrome_launcher_controller_->GetV1ApplicationsFromAppId(app_id()); | 73 chrome_launcher_controller_->GetV1ApplicationsFromAppId(app_id()); |
71 | 74 |
72 std::vector<content::WebContents*>::const_iterator iter = | 75 std::vector<content::WebContents*>::const_iterator iter = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); | 126 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); |
124 if (!browser) | 127 if (!browser) |
125 continue; | 128 continue; |
126 TabStripModel* tab_strip = browser->tab_strip_model(); | 129 TabStripModel* tab_strip = browser->tab_strip_model(); |
127 int index = tab_strip->GetIndexOfWebContents(content[i]); | 130 int index = tab_strip->GetIndexOfWebContents(content[i]); |
128 DCHECK(index != TabStripModel::kNoTab); | 131 DCHECK(index != TabStripModel::kNoTab); |
129 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE); | 132 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE); |
130 } | 133 } |
131 } | 134 } |
132 | 135 |
133 void AppShortcutLauncherItemController::Clicked(const ui::Event& event) { | |
134 // In case of a keyboard event, we were called by a hotkey. In that case we | |
135 // activate the next item in line if an item of our list is already active. | |
136 if (event.type() == ui::ET_KEY_RELEASED) { | |
137 if (AdvanceToNextApp()) | |
138 return; | |
139 } | |
140 Activate(); | |
141 } | |
142 | |
143 void AppShortcutLauncherItemController::OnRemoved() { | 136 void AppShortcutLauncherItemController::OnRemoved() { |
144 // AppShortcutLauncherItemController is unowned; delete on removal. | 137 // AppShortcutLauncherItemController is unowned; delete on removal. |
145 delete this; | 138 delete this; |
146 } | 139 } |
147 | 140 |
148 ChromeLauncherAppMenuItems | 141 ChromeLauncherAppMenuItems |
149 AppShortcutLauncherItemController::GetApplicationList(int event_flags) { | 142 AppShortcutLauncherItemController::GetApplicationList(int event_flags) { |
150 ChromeLauncherAppMenuItems items; | 143 ChromeLauncherAppMenuItems items; |
151 // Add the application name to the menu. | 144 // Add the application name to the menu. |
152 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); | 145 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 TabStripModel* tab_strip = browser->tab_strip_model(); | 184 TabStripModel* tab_strip = browser->tab_strip_model(); |
192 for (int index = 0; index < tab_strip->count(); index++) { | 185 for (int index = 0; index < tab_strip->count(); index++) { |
193 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); | 186 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); |
194 if (WebContentMatchesApp(extension, refocus_pattern, web_contents)) | 187 if (WebContentMatchesApp(extension, refocus_pattern, web_contents)) |
195 items.push_back(web_contents); | 188 items.push_back(web_contents); |
196 } | 189 } |
197 } | 190 } |
198 return items; | 191 return items; |
199 } | 192 } |
200 | 193 |
| 194 void AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) { |
| 195 #if defined(OS_CHROMEOS) |
| 196 if (!app_id().empty()) |
| 197 chromeos::default_pinned_apps_field_trial::RecordShelfAppClick(app_id()); |
| 198 #endif |
| 199 // In case of a keyboard event, we were called by a hotkey. In that case we |
| 200 // activate the next item in line if an item of our list is already active. |
| 201 if (event.type() == ui::ET_KEY_RELEASED) { |
| 202 if (AdvanceToNextApp()) |
| 203 return; |
| 204 } |
| 205 Activate(); |
| 206 } |
| 207 |
| 208 base::string16 AppShortcutLauncherItemController::GetTitle() { |
| 209 return GetAppTitle(); |
| 210 } |
| 211 |
| 212 ui::MenuModel* AppShortcutLauncherItemController::CreateContextMenu( |
| 213 aura::RootWindow* root_window) { |
| 214 ash::LauncherItem item = |
| 215 *(launcher_controller()->model()->ItemByID(launcher_id())); |
| 216 return new LauncherContextMenu(launcher_controller(), &item, root_window); |
| 217 } |
| 218 |
| 219 ash::LauncherMenuModel* |
| 220 AppShortcutLauncherItemController::CreateApplicationMenu(int event_flags) { |
| 221 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); |
| 222 } |
| 223 |
| 224 bool AppShortcutLauncherItemController::IsDraggable() { |
| 225 return true; |
| 226 } |
| 227 |
| 228 bool AppShortcutLauncherItemController::ShouldShowTooltip() { |
| 229 return true; |
| 230 } |
| 231 |
201 content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() { | 232 content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() { |
202 URLPattern refocus_pattern(URLPattern::SCHEME_ALL); | 233 URLPattern refocus_pattern(URLPattern::SCHEME_ALL); |
203 refocus_pattern.SetMatchAllURLs(true); | 234 refocus_pattern.SetMatchAllURLs(true); |
204 | 235 |
205 if (!refocus_url_.is_empty()) { | 236 if (!refocus_url_.is_empty()) { |
206 refocus_pattern.SetMatchAllURLs(false); | 237 refocus_pattern.SetMatchAllURLs(false); |
207 refocus_pattern.Parse(refocus_url_.spec()); | 238 refocus_pattern.Parse(refocus_url_.spec()); |
208 } | 239 } |
209 | 240 |
210 const Extension* extension = | 241 const Extension* extension = |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 346 |
316 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 347 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
317 if (last_launch_attempt_.is_null() || | 348 if (last_launch_attempt_.is_null() || |
318 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 349 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
319 kClickSuppressionInMS) < base::Time::Now()) { | 350 kClickSuppressionInMS) < base::Time::Now()) { |
320 last_launch_attempt_ = base::Time::Now(); | 351 last_launch_attempt_ = base::Time::Now(); |
321 return true; | 352 return true; |
322 } | 353 } |
323 return false; | 354 return false; |
324 } | 355 } |
OLD | NEW |