12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "apps/app_shim/app_shim_handler_mac.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/files/file_path.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/threading/non_thread_safe.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ipc/ipc_listener.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ipc/ipc_sender.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace IPC { 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct ChannelHandle; 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ChannelProxy; 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class Message; 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace IPC 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This is the counterpart to AppShimController in 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// destroyed when the app it corresponds to is closed or when the channel 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// connected to the app shim is closed. 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AppShimHost : public IPC::Listener, 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public IPC::Sender, 29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public apps::AppShimHandler::Host, 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public base::NonThreadSafe { 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AppShimHost(); 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~AppShimHost(); 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Creates a new server-side IPC channel at |handle|, which should contain a 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // file descriptor of a channel created by an IPC::ChannelFactory, and begins 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // listening for messages on it. 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ServeChannel(const IPC::ChannelHandle& handle); 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected: 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // IPC::Listener implementation. 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void OnChannelError() OVERRIDE; 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // IPC::Sender implementation. 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool Send(IPC::Message* message) OVERRIDE; 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The app shim process is requesting to be associated with the given profile 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // and app_id. Once the profile and app_id are stored, and all future 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // messages from the app shim relate to this app. The app is launched 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // immediately if |launch_now| is true. 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void OnLaunchApp(base::FilePath profile_dir, 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::string app_id, 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) apps::AppShimLaunchType launch_type); 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Called when the app shim process notifies that the app was focused. 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void OnFocus(apps::AppShimFocusType focus_type); 59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void OnSetHidden(bool hidden); 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Called when the app shim process notifies that the app should quit. 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void OnQuit(); 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // apps::AppShimHandler::Host overrides: 667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void OnAppLaunchComplete(apps::AppShimLaunchResult result) OVERRIDE; 67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) virtual void OnAppClosed() OVERRIDE; 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual base::FilePath GetProfilePath() const OVERRIDE; 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual std::string GetAppId() const OVERRIDE; 70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Closes the channel and destroys the AppShimHost. 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Close(); 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<IPC::ChannelProxy> channel_; 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string app_id_; 76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::FilePath profile_path_; 777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch bool initial_launch_finished_; 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_ 81