Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / app_shortcut_launcher_item_controller.h
blob2e375cd3bf58311dc99603d485277dcd4a2eb91b
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_
8 #include <string>
9 #include <vector>
11 #include "base/time/time.h"
12 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
13 #include "url/gurl.h"
15 class Browser;
16 class URLPattern;
18 namespace aura {
19 class Window;
22 namespace extensions {
23 class Extension;
26 class ChromeLauncherController;
28 // Item controller for an app shortcut. Shortcuts track app and launcher ids,
29 // but do not have any associated windows (opening a shortcut will replace the
30 // item with the appropriate LauncherItemController type).
31 class AppShortcutLauncherItemController : public LauncherItemController {
32 public:
33 AppShortcutLauncherItemController(const std::string& app_id,
34 ChromeLauncherController* controller);
36 ~AppShortcutLauncherItemController() override;
38 std::vector<content::WebContents*> GetRunningApplications();
40 // LauncherItemController overrides:
41 bool IsOpen() const override;
42 bool IsVisible() const override;
43 void Launch(ash::LaunchSource source, int event_flags) override;
44 ash::ShelfItemDelegate::PerformedAction Activate(
45 ash::LaunchSource source) override;
46 ChromeLauncherAppMenuItems GetApplicationList(int event_flags) override;
47 ash::ShelfItemDelegate::PerformedAction ItemSelected(
48 const ui::Event& event) override;
49 base::string16 GetTitle() override;
50 ui::MenuModel* CreateContextMenu(aura::Window* root_window) override;
51 ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) override;
52 bool IsDraggable() override;
53 bool ShouldShowTooltip() override;
54 void Close() override;
56 // Get the refocus url pattern, which can be used to identify this application
57 // from a URL link.
58 const GURL& refocus_url() const { return refocus_url_; }
59 // Set the refocus url pattern. Used by unit tests.
60 void set_refocus_url(const GURL& refocus_url) { refocus_url_ = refocus_url; }
62 private:
63 // Get the last running application.
64 content::WebContents* GetLRUApplication();
66 // Returns true if this app matches the given |web_contents|. To accelerate
67 // the matching, the app managing |extension| as well as the parsed
68 // |refocus_pattern| get passed. If |is_app| is true, the application gets
69 // first checked against its original URL since a windowed app might have
70 // navigated away from its app domain.
71 bool WebContentMatchesApp(const extensions::Extension* extension,
72 const URLPattern& refocus_pattern,
73 content::WebContents* web_contents,
74 Browser* browser);
76 // Activate the browser with the given |content| and show the associated tab.
77 // Returns the action performed by activating the content.
78 ash::ShelfItemDelegate::PerformedAction ActivateContent(
79 content::WebContents* content);
81 // Advance to the next item if an owned item is already active. The function
82 // will return true if it has sucessfully advanced.
83 bool AdvanceToNextApp();
85 // Returns true if the application is a V2 app.
86 bool IsV2App();
88 // Returns true if it is allowed to try starting a V2 app again.
89 bool AllowNextLaunchAttempt();
91 GURL refocus_url_;
93 // Since V2 applications can be undetectable after launching, this timer is
94 // keeping track of the last launch attempt.
95 base::Time last_launch_attempt_;
97 ChromeLauncherController* chrome_launcher_controller_;
99 DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController);
102 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_APP_SHORTCUT_LAUNCHER_ITEM_CONTROLLER_H_