1 // Copyright 2013 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 APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_H_
6 #define APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_H_
12 #include "apps/app_lifetime_monitor.h"
13 #include "apps/app_shim/app_shim_handler_mac.h"
14 #include "apps/shell_window_registry.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
30 namespace extensions
{
38 // This app shim handler that handles events for app shims that correspond to an
40 class ExtensionAppShimHandler
: public AppShimHandler
,
41 public content::NotificationObserver
,
42 public AppLifetimeMonitor::Observer
{
46 virtual ~Delegate() {}
48 virtual bool ProfileExistsForPath(const base::FilePath
& path
);
49 virtual Profile
* ProfileForPath(const base::FilePath
& path
);
50 virtual void LoadProfileAsync(const base::FilePath
& path
,
51 base::Callback
<void(Profile
*)> callback
);
53 virtual ShellWindowRegistry::ShellWindowList
GetWindows(
54 Profile
* profile
, const std::string
& extension_id
);
56 virtual const extensions::Extension
* GetAppExtension(
57 Profile
* profile
, const std::string
& extension_id
);
58 virtual void LaunchApp(Profile
* profile
,
59 const extensions::Extension
* extension
,
60 const std::vector
<base::FilePath
>& files
);
61 virtual void LaunchShim(Profile
* profile
,
62 const extensions::Extension
* extension
);
64 virtual void MaybeTerminate();
67 ExtensionAppShimHandler();
68 virtual ~ExtensionAppShimHandler();
70 AppShimHandler::Host
* FindHost(Profile
* profile
, const std::string
& app_id
);
72 static void QuitAppForWindow(ShellWindow
* shell_window
);
74 static void HideAppForWindow(ShellWindow
* shell_window
);
76 static void FocusAppForWindow(ShellWindow
* shell_window
);
78 // Brings the window to the front without showing it and instructs the shim to
79 // request user attention. Returns false if there is no shim for this window.
80 static bool RequestUserAttentionForWindow(ShellWindow
* shell_window
);
82 // AppShimHandler overrides:
83 virtual void OnShimLaunch(Host
* host
,
84 AppShimLaunchType launch_type
,
85 const std::vector
<base::FilePath
>& files
) OVERRIDE
;
86 virtual void OnShimClose(Host
* host
) OVERRIDE
;
87 virtual void OnShimFocus(Host
* host
,
88 AppShimFocusType focus_type
,
89 const std::vector
<base::FilePath
>& files
) OVERRIDE
;
90 virtual void OnShimSetHidden(Host
* host
, bool hidden
) OVERRIDE
;
91 virtual void OnShimQuit(Host
* host
) OVERRIDE
;
93 // AppLifetimeMonitor::Observer overrides:
94 virtual void OnAppStart(Profile
* profile
, const std::string
& app_id
) OVERRIDE
;
95 virtual void OnAppActivated(Profile
* profile
,
96 const std::string
& app_id
) OVERRIDE
;
97 virtual void OnAppDeactivated(Profile
* profile
,
98 const std::string
& app_id
) OVERRIDE
;
99 virtual void OnAppStop(Profile
* profile
, const std::string
& app_id
) OVERRIDE
;
100 virtual void OnChromeTerminating() OVERRIDE
;
102 // content::NotificationObserver overrides:
103 virtual void Observe(int type
,
104 const content::NotificationSource
& source
,
105 const content::NotificationDetails
& details
) OVERRIDE
;
108 typedef std::map
<std::pair
<Profile
*, std::string
>, AppShimHandler::Host
*>
111 // Exposed for testing.
112 void set_delegate(Delegate
* delegate
);
113 HostMap
& hosts() { return hosts_
; }
114 content::NotificationRegistrar
& registrar() { return registrar_
; }
117 // This is passed to Delegate::LoadProfileAsync for shim-initiated launches
118 // where the profile was not yet loaded.
119 void OnProfileLoaded(Host
* host
,
120 AppShimLaunchType launch_type
,
121 const std::vector
<base::FilePath
>& files
,
124 scoped_ptr
<Delegate
> delegate_
;
128 content::NotificationRegistrar registrar_
;
130 base::WeakPtrFactory
<ExtensionAppShimHandler
> weak_factory_
;
132 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandler
);
137 #endif // APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_H_