summaryrefslogtreecommitdiffstats
path: root/apps/app_shim/app_shim_handler_mac.h
blob: 2cc3425b9fb61a05b90eb67b13cb99021beb61ef (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
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
// 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_APP_SHIM_HANDLER_MAC_H_
#define APPS_APP_SHIM_APP_SHIM_HANDLER_MAC_H_

#include <string>
#include <vector>

#include "apps/app_shim/app_shim_launch.h"
#include "base/files/file_path.h"

namespace apps {

// Registrar, and interface for services that can handle interactions with OSX
// shim processes.
class AppShimHandler {
 public:
  class Host {
   public:
    // Invoked when the app is successfully launched.
    virtual void OnAppLaunchComplete(AppShimLaunchResult result) = 0;
    // Invoked when the app is closed in the browser process.
    virtual void OnAppClosed() = 0;
    // Invoked when the app should be hidden.
    virtual void OnAppHide() = 0;
    // Invoked when the app is requesting user attention.
    virtual void OnAppRequestUserAttention(AppShimAttentionType type) = 0;

    // Allows the handler to determine which app this host corresponds to.
    virtual base::FilePath GetProfilePath() const = 0;
    virtual std::string GetAppId() const = 0;

   protected:
    virtual ~Host() {}
  };

  // Register a handler for an |app_mode_id|.
  static void RegisterHandler(const std::string& app_mode_id,
                              AppShimHandler* handler);

  // Remove a handler for an |app_mode_id|.
  static void RemoveHandler(const std::string& app_mode_id);

  // Returns the handler registered for the given |app_mode_id|. If there is
  // none registered, it returns the default handler or NULL if there is no
  // default handler.
  static AppShimHandler* GetForAppMode(const std::string& app_mode_id);

  // Sets the default handler to return when there is no app-specific handler.
  // Setting this to NULL removes the default handler.
  static void SetDefaultHandler(AppShimHandler* handler);

  // Terminate Chrome if a browser window has never been opened, there are no
  // shell windows, and the app list is not visible.
  static void MaybeTerminate();

  // Whether browser sessions should be restored right now. This is true if
  // the browser has been quit but kept alive because Chrome Apps are still
  // running.
  static bool ShouldRestoreSession();

  // Invoked by the shim host when the shim process is launched. The handler
  // must call OnAppLaunchComplete to inform the shim of the result.
  // |launch_type| indicates the type of launch.
  // |files|, if non-empty, holds an array of files paths given as arguments, or
  // dragged onto the app bundle or dock icon.
  virtual void OnShimLaunch(Host* host,
                            AppShimLaunchType launch_type,
                            const std::vector<base::FilePath>& files) = 0;

  // Invoked by the shim host when the connection to the shim process is closed.
  virtual void OnShimClose(Host* host) = 0;

  // Invoked by the shim host when the shim process receives a focus event.
  // |files|, if non-empty, holds an array of files dragged onto the app bundle
  // or dock icon.
  virtual void OnShimFocus(Host* host,
                           AppShimFocusType focus_type,
                           const std::vector<base::FilePath>& files) = 0;

  // Invoked by the shim host when the shim process is hidden or shown.
  virtual void OnShimSetHidden(Host* host, bool hidden) = 0;

  // Invoked by the shim host when the shim process receives a quit event.
  virtual void OnShimQuit(Host* host) = 0;

 protected:
  AppShimHandler() {}
  virtual ~AppShimHandler() {}
};

}  // namespace apps

#endif  // APPS_APP_SHIM_APP_SHIM_HANDLER_MAC_H_