Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.cc

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

Powered by Google App Engine
This is Rietveld 408576698