| 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 // If the browser is an app window and the app name matches the extension. |
| 288 // no entry was yet created. | 289 if (browser->is_app()) { |
| 289 const GURL tab_url = is_app && web_contents->GetController().GetEntryCount() ? | 290 const extensions::Extension* browser_extension = NULL; |
| 290 web_contents->GetController().GetEntryAtIndex(0)->GetURL() : | 291 const ExtensionService* extension_service = |
| 291 web_contents->GetURL(); | 292 browser->profile()->GetExtensionService(); |
| 293 if (extension_service) { |
| 294 browser_extension = extension_service->GetInstalledExtension( |
| 295 web_app::GetExtensionIdFromApplicationName(browser->app_name())); |
| 296 } |
| 297 return browser_extension == extension; |
| 298 } |
| 299 |
| 292 // There are three ways to identify the association of a URL with this | 300 // There are three ways to identify the association of a URL with this |
| 293 // extension: | 301 // extension: |
| 294 // - The refocus pattern is matched (needed for apps like drive). | 302 // - The refocus pattern is matched (needed for apps like drive). |
| 295 // - The extension's origin + extent gets matched. | 303 // - The extension's origin + extent gets matched. |
| 296 // - The launcher controller knows that the tab got created for this app. | 304 // - The launcher controller knows that the tab got created for this app. |
| 305 const GURL tab_url = web_contents->GetURL(); |
| 297 return ((!refocus_pattern.match_all_urls() && | 306 return ((!refocus_pattern.match_all_urls() && |
| 298 refocus_pattern.MatchesURL(tab_url)) || | 307 refocus_pattern.MatchesURL(tab_url)) || |
| 299 (extension->OverlapsWithOrigin(tab_url) && | 308 (extension->OverlapsWithOrigin(tab_url) && |
| 300 extension->web_extent().MatchesURL(tab_url)) || | 309 extension->web_extent().MatchesURL(tab_url)) || |
| 301 launcher_controller()->IsWebContentHandledByApplication(web_contents, | 310 launcher_controller()->IsWebContentHandledByApplication(web_contents, |
| 302 app_id())); | 311 app_id())); |
| 303 } | 312 } |
| 304 | 313 |
| 305 void AppShortcutLauncherItemController::ActivateContent( | 314 void AppShortcutLauncherItemController::ActivateContent( |
| 306 content::WebContents* content) { | 315 content::WebContents* content) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 362 |
| 354 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { | 363 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { |
| 355 if (last_launch_attempt_.is_null() || | 364 if (last_launch_attempt_.is_null() || |
| 356 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( | 365 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( |
| 357 kClickSuppressionInMS) < base::Time::Now()) { | 366 kClickSuppressionInMS) < base::Time::Now()) { |
| 358 last_launch_attempt_ = base::Time::Now(); | 367 last_launch_attempt_ = base::Time::Now(); |
| 359 return true; | 368 return true; |
| 360 } | 369 } |
| 361 return false; | 370 return false; |
| 362 } | 371 } |
| OLD | NEW |