summaryrefslogtreecommitdiff
path: root/apps/app_shim/extension_app_shim_handler_mac.h
blob: f5a7d668eb8f197a0a3f65402a0766d427e7199a (plain)
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
// Copyright 2013 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 APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_H_
#define APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_H_

#include <map>
#include <string>

#include "apps/app_shim/app_shim_handler_mac.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"

class Profile;

namespace extensions {
class Extension;
}

namespace apps {

// This app shim handler that handles events for app shims that correspond to an
// extension.
class ExtensionAppShimHandler : public AppShimHandler,
                                public content::NotificationObserver {
 public:
  ExtensionAppShimHandler();
  virtual ~ExtensionAppShimHandler();

  // AppShimHandler overrides:
  virtual bool OnShimLaunch(Host* host, AppShimLaunchType launch_type) OVERRIDE;
  virtual void OnShimClose(Host* host) OVERRIDE;
  virtual void OnShimFocus(Host* host) OVERRIDE;
  virtual void OnShimQuit(Host* host) OVERRIDE;

 protected:
  typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*>
      HostMap;

  // Exposed for testing.
  HostMap& hosts() { return hosts_; }
  content::NotificationRegistrar& registrar() { return registrar_; }

 private:
  virtual bool LaunchApp(Profile* profile,
                         const std::string& app_id,
                         AppShimLaunchType launch_type);

  // Listen to the NOTIFICATION_EXTENSION_HOST_DESTROYED message to detect when
  // an app closes. When that happens, call OnAppClosed on the relevant
  // AppShimHandler::Host which causes the app shim process to quit.
  // The host will call OnShimClose on this.
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE;

  void StartShim(Profile* profile, const extensions::Extension* extension);

  void CloseShim(Profile* profile, const std::string& app_id);

  HostMap hosts_;

  content::NotificationRegistrar registrar_;
};

}  // namespace apps

#endif  // APPS_APP_SHIM_EXTENSION_APP_SHIM_HANDLER_H_