1a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file. 4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef CHROME_BROWSER_APPS_APP_SHIM_APP_SHIM_HANDLER_MAC_H_ 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define CHROME_BROWSER_APPS_APP_SHIM_APP_SHIM_HANDLER_MAC_H_ 7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include <string> 958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include <vector> 10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/files/file_path.h" 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/common/mac/app_shim_launch.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 14a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace apps { 15a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Registrar, and interface for services that can handle interactions with OSX 17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// shim processes. 18a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class AppShimHandler { 19a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public: 20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) class Host { 21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public: 227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Invoked when the app is successfully launched. 237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void OnAppLaunchComplete(AppShimLaunchResult result) = 0; 24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Invoked when the app is closed in the browser process. 25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void OnAppClosed() = 0; 2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Invoked when the app should be hidden. 2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void OnAppHide() = 0; 28424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Invoked when the app is requesting user attention. 2903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void OnAppRequestUserAttention(AppShimAttentionType type) = 0; 30a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Allows the handler to determine which app this host corresponds to. 32eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual base::FilePath GetProfilePath() const = 0; 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual std::string GetAppId() const = 0; 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 35a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected: 36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual ~Host() {} 37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) }; 38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Register a handler for an |app_mode_id|. 40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) static void RegisterHandler(const std::string& app_mode_id, 41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) AppShimHandler* handler); 42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Remove a handler for an |app_mode_id|. 44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) static void RemoveHandler(const std::string& app_mode_id); 45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the handler registered for the given |app_mode_id|. If there is 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // none registered, it returns the default handler or NULL if there is no 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // default handler. 49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) static AppShimHandler* GetForAppMode(const std::string& app_mode_id); 50a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Sets the default handler to return when there is no app-specific handler. 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Setting this to NULL removes the default handler. 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static void SetDefaultHandler(AppShimHandler* handler); 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Terminate Chrome if a browser window has never been opened, there are no 564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // shell windows, and the app list is not visible. 574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) static void MaybeTerminate(); 584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Whether browser sessions should be restored right now. This is true if 60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // the browser has been quit but kept alive because Chrome Apps are still 61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // running. 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) static bool ShouldRestoreSession(); 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Invoked by the shim host when the shim process is launched. The handler 657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // must call OnAppLaunchComplete to inform the shim of the result. 6658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // |launch_type| indicates the type of launch. 6758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // |files|, if non-empty, holds an array of files paths given as arguments, or 6858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // dragged onto the app bundle or dock icon. 6958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void OnShimLaunch(Host* host, 7058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) AppShimLaunchType launch_type, 7158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const std::vector<base::FilePath>& files) = 0; 72a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 73a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Invoked by the shim host when the connection to the shim process is closed. 74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void OnShimClose(Host* host) = 0; 75a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 76a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) // Invoked by the shim host when the shim process receives a focus event. 7758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // |files|, if non-empty, holds an array of files dragged onto the app bundle 7858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // or dock icon. 7958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void OnShimFocus(Host* host, 8058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) AppShimFocusType focus_type, 8158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const std::vector<base::FilePath>& files) = 0; 82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Invoked by the shim host when the shim process is hidden or shown. 84eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void OnShimSetHidden(Host* host, bool hidden) = 0; 85a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Invoked by the shim host when the shim process receives a quit event. 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void OnShimQuit(Host* host) = 0; 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 89a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected: 90a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) AppShimHandler() {} 91a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual ~AppShimHandler() {} 92a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}; 93a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 94a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)} // namespace apps 95a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif // CHROME_BROWSER_APPS_APP_SHIM_APP_SHIM_HANDLER_MAC_H_ 97