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

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

Issue 22887015: Remove PerBrowser launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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/wm/window_util.h" 8 #include "ash/wm/window_util.h"
9 #include "chrome/browser/extensions/extension_process_manager.h" 9 #include "chrome/browser/extensions/extension_process_manager.h"
10 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/favicon/favicon_tab_helper.h" 11 #include "chrome/browser/favicon/favicon_tab_helper.h"
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.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_tab.h" 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h"
16 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 15 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
17 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_finder.h" 17 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/host_desktop.h" 20 #include "chrome/browser/ui/host_desktop.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
24 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
25 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
26 #include "ui/base/events/event.h" 25 #include "ui/base/events/event.h"
27 #include "ui/views/corewm/window_animations.h" 26 #include "ui/views/corewm/window_animations.h"
28 27
29 using extensions::Extension; 28 using extensions::Extension;
30 29
31 namespace { 30 namespace {
32 31
33 // The time delta between clicks in which clicks to launch V2 apps are ignored. 32 // The time delta between clicks in which clicks to launch V2 apps are ignored.
34 const int kClickSuppressionInMS = 1000; 33 const int kClickSuppressionInMS = 1000;
35 34
36 } // namespace 35 } // namespace
37 36
38 // Item controller for an app shortcut. Shortcuts track app and launcher ids, 37 // Item controller for an app shortcut. Shortcuts track app and launcher ids,
39 // but do not have any associated windows (opening a shortcut will replace the 38 // but do not have any associated windows (opening a shortcut will replace the
40 // item with the appropriate LauncherItemController type). 39 // item with the appropriate LauncherItemController type).
41 AppShortcutLauncherItemController::AppShortcutLauncherItemController( 40 AppShortcutLauncherItemController::AppShortcutLauncherItemController(
42 const std::string& app_id, 41 const std::string& app_id,
43 ChromeLauncherControllerPerApp* controller) 42 ChromeLauncherController* controller)
44 : LauncherItemController(TYPE_SHORTCUT, app_id, controller), 43 : LauncherItemController(TYPE_SHORTCUT, app_id, controller) {
45 app_controller_(controller) {
46 // To detect V1 applications we use their domain and match them against the 44 // To detect V1 applications we use their domain and match them against the
47 // used URL. This will also work with applications like Google Drive. 45 // used URL. This will also work with applications like Google Drive.
48 const Extension* extension = 46 const Extension* extension =
49 launcher_controller()->GetExtensionForAppID(app_id); 47 launcher_controller()->GetExtensionForAppID(app_id);
50 // Some unit tests have no real extension. 48 // Some unit tests have no real extension.
51 if (extension) { 49 if (extension) {
52 set_refocus_url(GURL( 50 set_refocus_url(GURL(
53 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); 51 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*"));
54 } 52 }
55 } 53 }
56 54
57 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() { 55 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {
58 } 56 }
59 57
60 string16 AppShortcutLauncherItemController::GetTitle() { 58 string16 AppShortcutLauncherItemController::GetTitle() {
61 return GetAppTitle(); 59 return GetAppTitle();
62 } 60 }
63 61
64 bool AppShortcutLauncherItemController::IsCurrentlyShownInWindow( 62 bool AppShortcutLauncherItemController::IsCurrentlyShownInWindow(
65 aura::Window* window) const { 63 aura::Window* window) const {
66 Browser* browser = chrome::FindBrowserWithWindow(window); 64 Browser* browser = chrome::FindBrowserWithWindow(window);
67 content::WebContents* active_content_of_window = 65 content::WebContents* active_content_of_window =
68 browser ? browser->tab_strip_model()->GetActiveWebContents() : NULL; 66 browser ? browser->tab_strip_model()->GetActiveWebContents() : NULL;
69 67
70 std::vector<content::WebContents*> content = 68 std::vector<content::WebContents*> content =
71 app_controller_->GetV1ApplicationsFromAppId(app_id()); 69 launcher_controller()->GetV1ApplicationsFromAppId(app_id());
72 70
73 std::vector<content::WebContents*>::const_iterator iter = 71 std::vector<content::WebContents*>::const_iterator iter =
74 std::find(content.begin(), content.end(), active_content_of_window); 72 std::find(content.begin(), content.end(), active_content_of_window);
75 73
76 return iter != content.end() ? true : false; 74 return iter != content.end() ? true : false;
77 } 75 }
78 76
79 bool AppShortcutLauncherItemController::IsOpen() const { 77 bool AppShortcutLauncherItemController::IsOpen() const {
80 return !app_controller_->GetV1ApplicationsFromAppId(app_id()).empty(); 78 return !launcher_controller()->GetV1ApplicationsFromAppId(app_id()).empty();
81 } 79 }
82 80
83 bool AppShortcutLauncherItemController::IsVisible() const { 81 bool AppShortcutLauncherItemController::IsVisible() const {
84 // Return true if any browser window associated with the app is visible. 82 // Return true if any browser window associated with the app is visible.
85 std::vector<content::WebContents*> content = 83 std::vector<content::WebContents*> content =
86 app_controller_->GetV1ApplicationsFromAppId(app_id()); 84 launcher_controller()->GetV1ApplicationsFromAppId(app_id());
87 for (size_t i = 0; i < content.size(); i++) { 85 for (size_t i = 0; i < content.size(); i++) {
88 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); 86 Browser* browser = chrome::FindBrowserWithWebContents(content[i]);
89 if (browser && browser->window()->GetNativeWindow()->IsVisible()) 87 if (browser && browser->window()->GetNativeWindow()->IsVisible())
90 return true; 88 return true;
91 } 89 }
92 return false; 90 return false;
93 } 91 }
94 92
95 void AppShortcutLauncherItemController::Launch(int event_flags) { 93 void AppShortcutLauncherItemController::Launch(int event_flags) {
96 app_controller_->LaunchApp(app_id(), event_flags); 94 launcher_controller()->LaunchApp(app_id(), event_flags);
97 } 95 }
98 96
99 void AppShortcutLauncherItemController::Activate() { 97 void AppShortcutLauncherItemController::Activate() {
100 content::WebContents* content = GetLRUApplication(); 98 content::WebContents* content = GetLRUApplication();
101 if (!content) { 99 if (!content) {
102 if (IsV2App()) { 100 if (IsV2App()) {
103 // Ideally we come here only once. After that ShellLauncherItemController 101 // Ideally we come here only once. After that ShellLauncherItemController
104 // will take over when the shell window gets opened. However there are 102 // will take over when the shell window gets opened. However there are
105 // apps which take a lot of time for pre-processing (like the files app) 103 // apps which take a lot of time for pre-processing (like the files app)
106 // before they open a window. Since there is currently no other way to 104 // before they open a window. Since there is currently no other way to
107 // detect if an app was started we suppress any further clicks within a 105 // detect if an app was started we suppress any further clicks within a
108 // special time out. 106 // special time out.
109 if (!AllowNextLaunchAttempt()) 107 if (!AllowNextLaunchAttempt())
110 return; 108 return;
111 } 109 }
112 Launch(ui::EF_NONE); 110 Launch(ui::EF_NONE);
113 return; 111 return;
114 } 112 }
115 ActivateContent(content); 113 ActivateContent(content);
116 } 114 }
117 115
118 void AppShortcutLauncherItemController::Close() { 116 void AppShortcutLauncherItemController::Close() {
119 // Close all running 'programs' of this type. 117 // Close all running 'programs' of this type.
120 std::vector<content::WebContents*> content = 118 std::vector<content::WebContents*> content =
121 app_controller_->GetV1ApplicationsFromAppId(app_id()); 119 launcher_controller()->GetV1ApplicationsFromAppId(app_id());
122 for (size_t i = 0; i < content.size(); i++) { 120 for (size_t i = 0; i < content.size(); i++) {
123 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); 121 Browser* browser = chrome::FindBrowserWithWebContents(content[i]);
124 if (!browser) 122 if (!browser)
125 continue; 123 continue;
126 TabStripModel* tab_strip = browser->tab_strip_model(); 124 TabStripModel* tab_strip = browser->tab_strip_model();
127 int index = tab_strip->GetIndexOfWebContents(content[i]); 125 int index = tab_strip->GetIndexOfWebContents(content[i]);
128 DCHECK(index != TabStripModel::kNoTab); 126 DCHECK(index != TabStripModel::kNoTab);
129 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE); 127 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE);
130 } 128 }
131 } 129 }
(...skipping 22 matching lines...) Expand all
154 AppShortcutLauncherItemController::GetApplicationList(int event_flags) { 152 AppShortcutLauncherItemController::GetApplicationList(int event_flags) {
155 ChromeLauncherAppMenuItems items; 153 ChromeLauncherAppMenuItems items;
156 // Add the application name to the menu. 154 // Add the application name to the menu.
157 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); 155 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false));
158 156
159 std::vector<content::WebContents*> content_list = GetRunningApplications(); 157 std::vector<content::WebContents*> content_list = GetRunningApplications();
160 158
161 for (size_t i = 0; i < content_list.size(); i++) { 159 for (size_t i = 0; i < content_list.size(); i++) {
162 content::WebContents* web_contents = content_list[i]; 160 content::WebContents* web_contents = content_list[i];
163 // Get the icon. 161 // Get the icon.
164 gfx::Image app_icon = app_controller_->GetAppListIcon(web_contents); 162 gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents);
165 string16 title = app_controller_->GetAppListTitle(web_contents); 163 string16 title = launcher_controller()->GetAppListTitle(web_contents);
166 items.push_back(new ChromeLauncherAppMenuItemTab( 164 items.push_back(new ChromeLauncherAppMenuItemTab(
167 title, &app_icon, web_contents, i == 0)); 165 title, &app_icon, web_contents, i == 0));
168 } 166 }
169 return items.Pass(); 167 return items.Pass();
170 } 168 }
171 169
172 std::vector<content::WebContents*> 170 std::vector<content::WebContents*>
173 AppShortcutLauncherItemController::GetRunningApplications() { 171 AppShortcutLauncherItemController::GetRunningApplications() {
174 std::vector<content::WebContents*> items; 172 std::vector<content::WebContents*> items;
175 173
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 const GURL tab_url = web_contents->GetURL(); 256 const GURL tab_url = web_contents->GetURL();
259 // There are three ways to identify the association of a URL with this 257 // There are three ways to identify the association of a URL with this
260 // extension: 258 // extension:
261 // - The refocus pattern is matched (needed for apps like drive). 259 // - The refocus pattern is matched (needed for apps like drive).
262 // - The extension's origin + extent gets matched. 260 // - The extension's origin + extent gets matched.
263 // - The launcher controller knows that the tab got created for this app. 261 // - The launcher controller knows that the tab got created for this app.
264 return ((!refocus_pattern.match_all_urls() && 262 return ((!refocus_pattern.match_all_urls() &&
265 refocus_pattern.MatchesURL(tab_url)) || 263 refocus_pattern.MatchesURL(tab_url)) ||
266 (extension->OverlapsWithOrigin(tab_url) && 264 (extension->OverlapsWithOrigin(tab_url) &&
267 extension->web_extent().MatchesURL(tab_url)) || 265 extension->web_extent().MatchesURL(tab_url)) ||
268 launcher_controller()->GetPerAppInterface()-> 266 launcher_controller()->IsWebContentHandledByApplication(web_contents,
269 IsWebContentHandledByApplication(web_contents, app_id())); 267 app_id()));
270 } 268 }
271 269
272 void AppShortcutLauncherItemController::ActivateContent( 270 void AppShortcutLauncherItemController::ActivateContent(
273 content::WebContents* content) { 271 content::WebContents* content) {
274 Browser* browser = chrome::FindBrowserWithWebContents(content); 272 Browser* browser = chrome::FindBrowserWithWebContents(content);
275 TabStripModel* tab_strip = browser->tab_strip_model(); 273 TabStripModel* tab_strip = browser->tab_strip_model();
276 int index = tab_strip->GetIndexOfWebContents(content); 274 int index = tab_strip->GetIndexOfWebContents(content);
277 DCHECK_NE(TabStripModel::kNoTab, index); 275 DCHECK_NE(TabStripModel::kNoTab, index);
278 276
279 int old_index = tab_strip->active_index(); 277 int old_index = tab_strip->active_index();
280 if (index != old_index) 278 if (index != old_index)
281 tab_strip->ActivateTabAt(index, false); 279 tab_strip->ActivateTabAt(index, false);
282 app_controller_->ActivateWindowOrMinimizeIfActive(browser->window(), 280 launcher_controller()->ActivateWindowOrMinimizeIfActive(
281 browser->window(),
283 index == old_index && GetRunningApplications().size() == 1); 282 index == old_index && GetRunningApplications().size() == 1);
284 } 283 }
285 284
286 bool AppShortcutLauncherItemController::AdvanceToNextApp() { 285 bool AppShortcutLauncherItemController::AdvanceToNextApp() {
287 std::vector<content::WebContents*> items = GetRunningApplications(); 286 std::vector<content::WebContents*> items = GetRunningApplications();
288 if (items.size() >= 1) { 287 if (items.size() >= 1) {
289 Browser* browser = chrome::FindBrowserWithWindow( 288 Browser* browser = chrome::FindBrowserWithWindow(
290 ash::wm::GetActiveWindow()); 289 ash::wm::GetActiveWindow());
291 if (browser) { 290 if (browser) {
292 TabStripModel* tab_strip = browser->tab_strip_model(); 291 TabStripModel* tab_strip = browser->tab_strip_model();
(...skipping 12 matching lines...) Expand all
305 ActivateContent(items[index]); 304 ActivateContent(items[index]);
306 } 305 }
307 return true; 306 return true;
308 } 307 }
309 } 308 }
310 } 309 }
311 return false; 310 return false;
312 } 311 }
313 312
314 bool AppShortcutLauncherItemController::IsV2App() { 313 bool AppShortcutLauncherItemController::IsV2App() {
315 const Extension* extension = app_controller_->GetExtensionForAppID(app_id()); 314 const Extension* extension =
315 launcher_controller()->GetExtensionForAppID(app_id());
316 return extension && extension->is_platform_app(); 316 return extension && extension->is_platform_app();
317 } 317 }
318 318
319 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 319 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
320 if (last_launch_attempt_.is_null() || 320 if (last_launch_attempt_.is_null() ||
321 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 321 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
322 kClickSuppressionInMS) < base::Time::Now()) { 322 kClickSuppressionInMS) < base::Time::Now()) {
323 last_launch_attempt_ = base::Time::Now(); 323 last_launch_attempt_ = base::Time::Now();
324 return true; 324 return true;
325 } 325 }
326 return false; 326 return false;
327 } 327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698