Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / browser / linux / running_application_object.h
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #ifndef XWALK_APPLICATION_BROWSER_LINUX_RUNNING_APPLICATION_OBJECT_H_
7 #define XWALK_APPLICATION_BROWSER_LINUX_RUNNING_APPLICATION_OBJECT_H_
8
9 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "dbus/bus.h"
12 #include "ipc/ipc_channel_handle.h"
13 #include "xwalk/application/browser/application.h"
14 #include "xwalk/dbus/object_manager_adaptor.h"
15
16 namespace dbus {
17 class FileDescriptor;
18 }
19
20 namespace xwalk {
21 namespace application {
22
23 // Represents the running application inside D-Bus hierarchy of
24 // RunningApplicationsManager.
25 //
26 // Watches for the D-Bus presence of the launcher, when it disappears (e.g. the
27 // launcher was ended by a task manager) will terminate the corresponding
28 // application in Crosswalk.
29 class RunningApplicationObject : public dbus::ManagedObject {
30  public:
31   RunningApplicationObject(scoped_refptr<dbus::Bus> bus,
32                            const std::string& app_id,
33                            const std::string& launcher_name,
34                            Application* application);
35
36   virtual ~RunningApplicationObject();
37
38   void ExtensionProcessCreated(const IPC::ChannelHandle& handle);
39
40  private:
41   void TerminateApplication();
42
43   void OnExported(const std::string& interface_name,
44                   const std::string& method_name,
45                   bool success);
46
47   void OnTerminate(dbus::MethodCall* method_call,
48                    dbus::ExportedObject::ResponseSender response_sender);
49
50   void OnGetExtensionProcessChannel(
51       dbus::MethodCall* method_call,
52       dbus::ExportedObject::ResponseSender response_sender);
53
54 #if defined(OS_TIZEN)
55   void OnHide(dbus::MethodCall* method_call,
56               dbus::ExportedObject::ResponseSender response_sender);
57
58   void OnSuspend(dbus::MethodCall* method_call,
59                  dbus::ExportedObject::ResponseSender response_sender);
60
61   void OnResume(dbus::MethodCall* method_call,
62                 dbus::ExportedObject::ResponseSender response_sender);
63
64   void OnRemoveAllCookies(dbus::MethodCall* method_call,
65                    dbus::ExportedObject::ResponseSender response_sender);
66
67   void SetUserAgentStringOnIOThread(const std::string& user_agent_string);
68   void OnSetUserAgentString(dbus::MethodCall* method_call,
69                    dbus::ExportedObject::ResponseSender response_sender);
70 #endif
71
72   void ListenForOwnerChange();
73   void UnlistenForOwnerChange();
74   void OnNameOwnerChanged(const std::string& service_owner);
75
76   void OnLauncherDisappeared();
77
78   void SendChannel(dbus::MethodCall* method_call,
79                    dbus::ExportedObject::ResponseSender response_sender);
80
81   scoped_refptr<dbus::Bus> bus_;
82   std::string launcher_name_;
83   dbus::Bus::GetServiceOwnerCallback owner_change_callback_;
84   Application* application_;
85
86   IPC::ChannelHandle ep_bp_channel_;
87 };
88
89 }  // namespace application
90 }  // namespace xwalk
91
92 #endif  // XWALK_APPLICATION_BROWSER_LINUX_RUNNING_APPLICATION_OBJECT_H_