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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_APP_SHORTCUT_LAUNCHER_ITEM_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_APP_SHORTCUT_LAUNCHER_ITEM_CONTROLLER_H_ 7 8 #include <string> 9 10 #include "base/time/time.h" 11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" 12 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 13 14 namespace aura { 15 class Window; 16 } 17 18 namespace extensions { 19 class Extension; 20 } 21 22 class ChromeLauncherController; 23 24 // Item controller for an app shortcut. Shortcuts track app and launcher ids, 25 // but do not have any associated windows (opening a shortcut will replace the 26 // item with the appropriate LauncherItemController type). 27 class AppShortcutLauncherItemController : public LauncherItemController { 28 public: 29 AppShortcutLauncherItemController(const std::string& app_id, 30 ChromeLauncherControllerPerApp* controller); 31 32 virtual ~AppShortcutLauncherItemController(); 33 34 // LauncherItemController overrides: 35 virtual string16 GetTitle() OVERRIDE; 36 virtual bool HasWindow(aura::Window* window) const OVERRIDE; 37 virtual bool IsOpen() const OVERRIDE; 38 virtual bool IsVisible() const OVERRIDE; 39 virtual void Launch(int event_flags) OVERRIDE; 40 virtual void Activate() OVERRIDE; 41 virtual void Close() OVERRIDE; 42 virtual void Clicked(const ui::Event& event) OVERRIDE; 43 virtual void OnRemoved() OVERRIDE; 44 virtual void LauncherItemChanged( 45 int model_index, 46 const ash::LauncherItem& old_item) OVERRIDE; 47 virtual ChromeLauncherAppMenuItems GetApplicationList( 48 int event_flags) OVERRIDE; 49 std::vector<content::WebContents*> GetRunningApplications(); 50 51 // Get the refocus url pattern, which can be used to identify this application 52 // from a URL link. 53 const GURL& refocus_url() const { return refocus_url_; } 54 // Set the refocus url pattern. Used by unit tests. 55 void set_refocus_url(const GURL& refocus_url) { refocus_url_ = refocus_url; } 56 57 private: 58 // Get the last running application. 59 content::WebContents* GetLRUApplication(); 60 61 // Returns true if this app matches the given |web_contents|. To accelerate 62 // the matching, the app managing |extension| as well as the parsed 63 // |refocus_pattern| get passed. 64 bool WebContentMatchesApp(const extensions::Extension* extension, 65 const URLPattern& refocus_pattern, 66 content::WebContents* web_contents); 67 68 // Activate the browser with the given |content| and show the associated tab. 69 void ActivateContent(content::WebContents* content); 70 71 // Advance to the next item if an owned item is already active. The function 72 // will return true if it has sucessfully advanced. 73 bool AdvanceToNextApp(); 74 75 // Returns true if the application is a V2 app. 76 bool IsV2App(); 77 78 // Returns true if it is allowed to try starting a V2 app again. 79 bool AllowNextLaunchAttempt(); 80 81 GURL refocus_url_; 82 ChromeLauncherControllerPerApp* app_controller_; 83 84 // Since V2 applications can be undetectable after launching, this timer is 85 // keeping track of the last launch attempt. 86 base::Time last_launch_attempt_; 87 88 DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController); 89 }; 90 91 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_APP_SHORTCUT_LAUNCHER_ITEM_CONTROLLER_H_ 92