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