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.
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_
10 #include "base/time/time.h"
11 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
21 namespace extensions
{
25 class ChromeLauncherController
;
27 // Item controller for an app shortcut. Shortcuts track app and launcher ids,
28 // but do not have any associated windows (opening a shortcut will replace the
29 // item with the appropriate LauncherItemController type).
30 class AppShortcutLauncherItemController
: public LauncherItemController
{
32 AppShortcutLauncherItemController(const std::string
& app_id
,
33 ChromeLauncherController
* controller
);
35 ~AppShortcutLauncherItemController() override
;
37 std::vector
<content::WebContents
*> GetRunningApplications();
39 // LauncherItemController overrides:
40 bool IsOpen() const override
;
41 bool IsVisible() const override
;
42 void Launch(ash::LaunchSource source
, int event_flags
) override
;
43 bool Activate(ash::LaunchSource source
) override
;
44 ChromeLauncherAppMenuItems
GetApplicationList(int event_flags
) override
;
45 bool ItemSelected(const ui::Event
& event
) override
;
46 base::string16
GetTitle() override
;
47 ui::MenuModel
* CreateContextMenu(aura::Window
* root_window
) override
;
48 ash::ShelfMenuModel
* CreateApplicationMenu(int event_flags
) override
;
49 bool IsDraggable() override
;
50 bool ShouldShowTooltip() override
;
51 void Close() override
;
53 // Get the refocus url pattern, which can be used to identify this application
55 const GURL
& refocus_url() const { return refocus_url_
; }
56 // Set the refocus url pattern. Used by unit tests.
57 void set_refocus_url(const GURL
& refocus_url
) { refocus_url_
= refocus_url
; }
60 // Get the last running application.
61 content::WebContents
* GetLRUApplication();
63 // Returns true if this app matches the given |web_contents|. To accelerate
64 // the matching, the app managing |extension| as well as the parsed
65 // |refocus_pattern| get passed. If |is_app| is true, the application gets
66 // first checked against its original URL since a windowed app might have
67 // navigated away from its app domain.
68 bool WebContentMatchesApp(const extensions::Extension
* extension
,
69 const URLPattern
& refocus_pattern
,
70 content::WebContents
* web_contents
,
73 // Activate the browser with the given |content| and show the associated tab.
74 void ActivateContent(content::WebContents
* content
);
76 // Advance to the next item if an owned item is already active. The function
77 // will return true if it has sucessfully advanced.
78 bool AdvanceToNextApp();
80 // Returns true if the application is a V2 app.
83 // Returns true if it is allowed to try starting a V2 app again.
84 bool AllowNextLaunchAttempt();
88 // Since V2 applications can be undetectable after launching, this timer is
89 // keeping track of the last launch attempt.
90 base::Time last_launch_attempt_
;
92 ChromeLauncherController
* chrome_launcher_controller_
;
94 DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController
);
97 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_APP_SHORTCUT_LAUNCHER_ITEM_CONTROLLER_H_