Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / host_dispatcher_wrapper.h
1 // Copyright (c) 2013 The Chromium Authors. 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 CONTENT_RENDERER_PEPPER_HOST_DISPATCHER_WRAPPER_H_
6 #define CONTENT_RENDERER_PEPPER_HOST_DISPATCHER_WRAPPER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/process/process_handle.h"
10 #include "content/renderer/pepper/pepper_hung_plugin_filter.h"
11 #include "ppapi/c/pp_instance.h"
12 #include "ppapi/c/ppp.h"
13 #include "ppapi/proxy/host_dispatcher.h"
14 #include "ppapi/shared_impl/ppapi_permissions.h"
15
16 namespace IPC {
17 struct ChannelHandle;
18 }
19
20 namespace content {
21 class PepperHungPluginFilter;
22 class PluginModule;
23
24 // This class wraps a dispatcher and has the same lifetime. A dispatcher has
25 // the same lifetime as a plugin module, which is longer than any particular
26 // RenderView or plugin instance.
27 class HostDispatcherWrapper {
28  public:
29   HostDispatcherWrapper(PluginModule* module,
30                         base::ProcessId peer_pid,
31                         int plugin_child_id,
32                         const ppapi::PpapiPermissions& perms,
33                         bool is_external);
34   virtual ~HostDispatcherWrapper();
35
36   bool Init(const IPC::ChannelHandle& channel_handle,
37             PP_GetInterface_Func local_get_interface,
38             const ppapi::Preferences& preferences,
39             scoped_refptr<PepperHungPluginFilter> filter);
40
41   // Implements GetInterface for the proxied plugin.
42   const void* GetProxiedInterface(const char* name);
43
44   // Notification to the out-of-process layer that the given plugin instance
45   // has been created. This will happen before the normal PPB_Instance method
46   // calls so the out-of-process code can set up the tracking information for
47   // the new instance.
48   void AddInstance(PP_Instance instance);
49
50   // Like AddInstance but removes the given instance. This is called after
51   // regular instance shutdown so the out-of-process code can clean up its
52   // tracking information.
53   void RemoveInstance(PP_Instance instance);
54
55   base::ProcessId peer_pid() { return peer_pid_; }
56   int plugin_child_id() { return plugin_child_id_; }
57   ppapi::proxy::HostDispatcher* dispatcher() { return dispatcher_.get(); }
58
59  private:
60   PluginModule* module_;
61
62   base::ProcessId peer_pid_;
63
64   // ID that the browser process uses to idetify the child process for the
65   // plugin. This isn't directly useful from our process (the renderer) except
66   // in messages to the browser to disambiguate plugins.
67   int plugin_child_id_;
68
69   ppapi::PpapiPermissions permissions_;
70   bool is_external_;
71
72   scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_;
73   scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_;
74   // We hold the hung_plugin_filter_ to guarantee it outlives |dispatcher_|,
75   // since it is an observer of |dispatcher_| for sync calls.
76   scoped_refptr<PepperHungPluginFilter> hung_plugin_filter_;
77 };
78
79 }  // namespace content
80
81 #endif  // CONTENT_RENDERER_PEPPER_HOST_DISPATCHER_WRAPPER_H_