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/ui/native_app_window.h" | 7 #include "apps/ui/native_app_window.h" |
8 #include "ash/shelf/shelf_model.h" | 8 #include "ash/shelf/shelf_model.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
11 #include "chrome/browser/favicon/favicon_tab_helper.h" | 11 #include "chrome/browser/extensions/extension_service.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/launcher_application_menu_item_model.h" | 15 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
16 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 16 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
17 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
18 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 18 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/host_desktop.h" | 24 #include "chrome/browser/ui/host_desktop.h" |
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
26 #include "chrome/browser/web_applications/web_app.h" | |
26 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 27 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
27 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
30 #include "extensions/browser/process_manager.h" | 31 #include "extensions/browser/process_manager.h" |
31 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
32 #include "ui/events/event.h" | 33 #include "ui/events/event.h" |
33 #include "ui/views/corewm/window_animations.h" | 34 #include "ui/views/corewm/window_animations.h" |
34 | 35 |
35 using extensions::Extension; | 36 using extensions::Extension; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 178 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
178 for (BrowserList::const_iterator it = ash_browser_list->begin(); | 179 for (BrowserList::const_iterator it = ash_browser_list->begin(); |
179 it != ash_browser_list->end(); ++it) { | 180 it != ash_browser_list->end(); ++it) { |
180 Browser* browser = *it; | 181 Browser* browser = *it; |
181 if (!launcher_controller()->IsBrowserFromActiveUser(browser)) | 182 if (!launcher_controller()->IsBrowserFromActiveUser(browser)) |
182 continue; | 183 continue; |
183 TabStripModel* tab_strip = browser->tab_strip_model(); | 184 TabStripModel* tab_strip = browser->tab_strip_model(); |
184 for (int index = 0; index < tab_strip->count(); index++) { | 185 for (int index = 0; index < tab_strip->count(); index++) { |
185 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); | 186 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); |
186 if (WebContentMatchesApp( | 187 if (WebContentMatchesApp( |
187 extension, refocus_pattern, web_contents, browser->is_app())) | 188 extension, refocus_pattern, web_contents, browser)) |
188 items.push_back(web_contents); | 189 items.push_back(web_contents); |
189 } | 190 } |
190 } | 191 } |
191 return items; | 192 return items; |
192 } | 193 } |
193 | 194 |
194 bool AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) { | 195 bool AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) { |
195 // In case of a keyboard event, we were called by a hotkey. In that case we | 196 // In case of a keyboard event, we were called by a hotkey. In that case we |
196 // activate the next item in line if an item of our list is already active. | 197 // activate the next item in line if an item of our list is already active. |
197 if (event.type() == ui::ET_KEY_RELEASED) { | 198 if (event.type() == ui::ET_KEY_RELEASED) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 Browser* browser = *it; | 250 Browser* browser = *it; |
250 if (!CanBrowserBeUsedForDirectActivation(browser, launcher_controller())) | 251 if (!CanBrowserBeUsedForDirectActivation(browser, launcher_controller())) |
251 continue; | 252 continue; |
252 TabStripModel* tab_strip = browser->tab_strip_model(); | 253 TabStripModel* tab_strip = browser->tab_strip_model(); |
253 // We start to enumerate from the active index. | 254 // We start to enumerate from the active index. |
254 int active_index = tab_strip->active_index(); | 255 int active_index = tab_strip->active_index(); |
255 for (int index = 0; index < tab_strip->count(); index++) { | 256 for (int index = 0; index < tab_strip->count(); index++) { |
256 content::WebContents* web_contents = tab_strip->GetWebContentsAt( | 257 content::WebContents* web_contents = tab_strip->GetWebContentsAt( |
257 (index + active_index) % tab_strip->count()); | 258 (index + active_index) % tab_strip->count()); |
258 if (WebContentMatchesApp( | 259 if (WebContentMatchesApp( |
259 extension, refocus_pattern, web_contents, browser->is_app())) | 260 extension, refocus_pattern, web_contents, browser)) |
260 return web_contents; | 261 return web_contents; |
261 } | 262 } |
262 } | 263 } |
263 // Coming here our application was not in the LRU list. This could have | 264 // Coming here our application was not in the LRU list. This could have |
264 // happened because it did never get activated yet. So check the browser list | 265 // happened because it did never get activated yet. So check the browser list |
265 // as well. | 266 // as well. |
266 for (BrowserList::const_iterator it = ash_browser_list->begin(); | 267 for (BrowserList::const_iterator it = ash_browser_list->begin(); |
267 it != ash_browser_list->end(); ++it) { | 268 it != ash_browser_list->end(); ++it) { |
268 Browser* browser = *it; | 269 Browser* browser = *it; |
269 if (!CanBrowserBeUsedForDirectActivation(browser, launcher_controller())) | 270 if (!CanBrowserBeUsedForDirectActivation(browser, launcher_controller())) |
270 continue; | 271 continue; |
271 TabStripModel* tab_strip = browser->tab_strip_model(); | 272 TabStripModel* tab_strip = browser->tab_strip_model(); |
272 for (int index = 0; index < tab_strip->count(); index++) { | 273 for (int index = 0; index < tab_strip->count(); index++) { |
273 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); | 274 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); |
274 if (WebContentMatchesApp( | 275 if (WebContentMatchesApp( |
275 extension, refocus_pattern, web_contents, browser->is_app())) | 276 extension, refocus_pattern, web_contents, browser)) |
276 return web_contents; | 277 return web_contents; |
277 } | 278 } |
278 } | 279 } |
279 return NULL; | 280 return NULL; |
280 } | 281 } |
281 | 282 |
282 bool AppShortcutLauncherItemController::WebContentMatchesApp( | 283 bool AppShortcutLauncherItemController::WebContentMatchesApp( |
283 const extensions::Extension* extension, | 284 const extensions::Extension* extension, |
284 const URLPattern& refocus_pattern, | 285 const URLPattern& refocus_pattern, |
285 content::WebContents* web_contents, | 286 content::WebContents* web_contents, |
286 bool is_app) { | 287 Browser* browser) { |
287 // Note: We can come here when the initial navigation isn't completed and | 288 const extensions::Extension* browser_extension = NULL; |
288 // no entry was yet created. | 289 if (browser->is_app()) { |
289 const GURL tab_url = is_app && web_contents->GetController().GetEntryCount() ? | 290 const ExtensionService* extension_service = |
290 web_contents->GetController().GetEntryAtIndex(0)->GetURL() : | 291 browser->profile()->GetExtensionService(); |
291 web_contents->GetURL(); | 292 if (extension_service) { |
293 browser_extension = extension_service->GetInstalledExtension( | |
294 web_app::GetExtensionIdFromApplicationName(browser->app_name())); | |
295 } | |
296 } | |
292 // There are three ways to identify the association of a URL with this | 297 // There are three ways to identify the association of a URL with this |
293 // extension: | 298 // extension: |
294 // - The refocus pattern is matched (needed for apps like drive). | 299 // - The refocus pattern is matched (needed for apps like drive). |
295 // - The extension's origin + extent gets matched. | 300 // - The browser is an app window and the app name matches the extension. |
296 // - The launcher controller knows that the tab got created for this app. | 301 // - The launcher controller knows that the tab got created for this app. |
297 return ((!refocus_pattern.match_all_urls() && | 302 return ((!refocus_pattern.match_all_urls() && |
298 refocus_pattern.MatchesURL(tab_url)) || | 303 refocus_pattern.MatchesURL(web_contents->GetURL())) || |
Mr4D (OOO till 08-26)
2014/02/07 17:44:03
You cannot remove the line 299&300 since this matc
calamity
2014/02/17 02:03:17
Done.
| |
299 (extension->OverlapsWithOrigin(tab_url) && | 304 extension == browser_extension || |
300 extension->web_extent().MatchesURL(tab_url)) || | |
301 launcher_controller()->IsWebContentHandledByApplication(web_contents, | 305 launcher_controller()->IsWebContentHandledByApplication(web_contents, |
302 app_id())); | 306 app_id())); |
303 } | 307 } |
304 | 308 |
305 void AppShortcutLauncherItemController::ActivateContent( | 309 void AppShortcutLauncherItemController::ActivateContent( |
306 content::WebContents* content) { | 310 content::WebContents* content) { |
307 Browser* browser = chrome::FindBrowserWithWebContents(content); | 311 Browser* browser = chrome::FindBrowserWithWebContents(content); |
308 TabStripModel* tab_strip = browser->tab_strip_model(); | 312 TabStripModel* tab_strip = browser->tab_strip_model(); |
309 int index = tab_strip->GetIndexOfWebContents(content); | 313 int index = tab_strip->GetIndexOfWebContents(content); |
310 DCHECK_NE(TabStripModel::kNoTab, index); | 314 DCHECK_NE(TabStripModel::kNoTab, index); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 | 357 |
354 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 358 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
355 if (last_launch_attempt_.is_null() || | 359 if (last_launch_attempt_.is_null() || |
356 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 360 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
357 kClickSuppressionInMS) < base::Time::Now()) { | 361 kClickSuppressionInMS) < base::Time::Now()) { |
358 last_launch_attempt_ = base::Time::Now(); | 362 last_launch_attempt_ = base::Time::Now(); |
359 return true; | 363 return true; |
360 } | 364 } |
361 return false; | 365 return false; |
362 } | 366 } |
OLD | NEW |