3900e18d4e7fa4ab16e28365ad53d3183d950b4f
[platform/framework/web/crosswalk.git] / src / xwalk / extensions / extension_process / xwalk_extension_process.h
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef XWALK_EXTENSIONS_EXTENSION_PROCESS_XWALK_EXTENSION_PROCESS_H_
6 #define XWALK_EXTENSIONS_EXTENSION_PROCESS_XWALK_EXTENSION_PROCESS_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/values.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h"
14 #include "ipc/ipc_channel_handle.h"
15 #include "ipc/ipc_listener.h"
16 #include "xwalk/extensions/common/xwalk_extension_permission_types.h"
17 #include "xwalk/extensions/common/xwalk_extension_server.h"
18
19 namespace base {
20 class FilePath;
21 }
22
23 namespace IPC {
24 class SyncChannel;
25 }
26
27 namespace xwalk {
28 namespace extensions {
29
30 class XWalkExtension;
31 class XWalkExtensionRunner;
32
33
34 // This class represents the Extension Process itself.
35 // It not only represents the extension side of the browser <->
36 // extension process communication channel, but also the extension side
37 // of the extension <-> render process channel.
38 // It will be responsible for handling the native side (instances) of
39 // External extensions through its XWalkExtensionServer.
40 class XWalkExtensionProcess : public IPC::Listener,
41                               public XWalkExtension::PermissionsDelegate {
42  public:
43   XWalkExtensionProcess();
44   virtual ~XWalkExtensionProcess();
45   virtual bool CheckAPIAccessControl(const std::string& extension_name,
46       const std::string& api_name) OVERRIDE;
47   virtual bool RegisterPermissions(const std::string& extension_name,
48       const std::string& perm_table) OVERRIDE;
49
50  private:
51   // IPC::Listener implementation.
52   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
53
54   // Handlers for IPC messages from XWalkExtensionProcessHost.
55   void OnRegisterExtensions(const base::FilePath& extension_path,
56                             const base::ListValue& browser_variables);
57
58   void CreateBrowserProcessChannel();
59   void CreateRenderProcessChannel();
60
61   base::WaitableEvent shutdown_event_;
62   base::Thread io_thread_;
63   scoped_ptr<IPC::SyncChannel> browser_process_channel_;
64   XWalkExtensionServer extensions_server_;
65   scoped_ptr<IPC::SyncChannel> render_process_channel_;
66   IPC::ChannelHandle rp_channel_handle_;
67   typedef std::map<std::string, RuntimePermission> PermissionCacheType;
68   PermissionCacheType permission_cache_;
69
70   DISALLOW_COPY_AND_ASSIGN(XWalkExtensionProcess);
71 };
72
73 }  // namespace extensions
74 }  // namespace xwalk
75
76 #endif  // XWALK_EXTENSIONS_EXTENSION_PROCESS_XWALK_EXTENSION_PROCESS_H_