OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 // A proxy for NPObject that sends all calls to the object to an NPObjectStub | |
6 // running in a different process. | |
7 | |
8 #ifndef CONTENT_COMMON_NPOBJECT_PROXY_H_ | |
9 #define CONTENT_COMMON_NPOBJECT_PROXY_H_ | |
10 | |
11 #include "base/memory/ref_counted.h" | |
12 #include "content/common/npobject_base.h" | |
13 #include "googleurl/src/gurl.h" | |
14 #include "ipc/ipc_listener.h" | |
15 #include "ipc/ipc_sender.h" | |
16 #include "third_party/npapi/bindings/npruntime.h" | |
17 #include "ui/gfx/native_widget_types.h" | |
18 | |
19 struct NPObject; | |
20 | |
21 namespace content { | |
22 class NPChannelBase; | |
23 | |
24 // When running a plugin in a different process from the renderer, we need to | |
25 // proxy calls to NPObjects across process boundaries. This happens both ways, | |
26 // as a plugin can get an NPObject for the window, and a page can get an | |
27 // NPObject for the plugin. In the process that interacts with the NPobject we | |
28 // give it an NPObjectProxy instead. All calls to it are sent across an IPC | |
29 // channel (specifically, a NPChannelBase). The NPObjectStub on the other | |
30 // side translates the IPC messages into calls to the actual NPObject, and | |
31 // returns the marshalled result. | |
32 class NPObjectProxy : public IPC::Listener, | |
33 public IPC::Sender, | |
34 public NPObjectBase { | |
35 public: | |
36 virtual ~NPObjectProxy(); | |
37 | |
38 static NPObject* Create(NPChannelBase* channel, | |
39 int route_id, | |
40 int render_view_id, | |
41 const GURL& page_url); | |
42 | |
43 // IPC::Sender implementation: | |
44 virtual bool Send(IPC::Message* msg) OVERRIDE; | |
45 int route_id() { return route_id_; } | |
46 NPChannelBase* channel() { return channel_; } | |
47 | |
48 // The next 9 functions are called on NPObjects from the plugin and browser. | |
49 static bool NPHasMethod(NPObject *obj, | |
50 NPIdentifier name); | |
51 static bool NPInvoke(NPObject *obj, | |
52 NPIdentifier name, | |
53 const NPVariant *args, | |
54 uint32_t arg_count, | |
55 NPVariant *result); | |
56 static bool NPInvokeDefault(NPObject *npobj, | |
57 const NPVariant *args, | |
58 uint32_t arg_count, | |
59 NPVariant *result); | |
60 static bool NPHasProperty(NPObject *obj, | |
61 NPIdentifier name); | |
62 static bool NPGetProperty(NPObject *obj, | |
63 NPIdentifier name, | |
64 NPVariant *result); | |
65 static bool NPSetProperty(NPObject *obj, | |
66 NPIdentifier name, | |
67 const NPVariant *value); | |
68 static bool NPRemoveProperty(NPObject *obj, | |
69 NPIdentifier name); | |
70 static bool NPNEnumerate(NPObject *obj, | |
71 NPIdentifier **value, | |
72 uint32_t *count); | |
73 static bool NPNConstruct(NPObject *npobj, | |
74 const NPVariant *args, | |
75 uint32_t arg_count, | |
76 NPVariant *result); | |
77 | |
78 // The next two functions are only called on NPObjects from the browser. | |
79 static bool NPNEvaluate(NPP npp, | |
80 NPObject *obj, | |
81 NPString *script, | |
82 NPVariant *result); | |
83 | |
84 static bool NPInvokePrivate(NPP npp, | |
85 NPObject *obj, | |
86 bool is_default, | |
87 NPIdentifier name, | |
88 const NPVariant *args, | |
89 uint32_t arg_count, | |
90 NPVariant *result); | |
91 | |
92 static NPObjectProxy* GetProxy(NPObject* object); | |
93 static const NPClass* npclass() { return &npclass_proxy_; } | |
94 | |
95 // NPObjectBase implementation. | |
96 virtual NPObject* GetUnderlyingNPObject() OVERRIDE; | |
97 | |
98 virtual IPC::Listener* GetChannelListener() OVERRIDE; | |
99 | |
100 private: | |
101 NPObjectProxy(NPChannelBase* channel, | |
102 int route_id, | |
103 int render_view_id, | |
104 const GURL& page_url); | |
105 | |
106 // IPC::Listener implementation: | |
107 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | |
108 virtual void OnChannelError() OVERRIDE; | |
109 | |
110 static NPObject* NPAllocate(NPP, NPClass*); | |
111 static void NPDeallocate(NPObject* npObj); | |
112 | |
113 // This function is only caled on NPObjects from the plugin. | |
114 static void NPPInvalidate(NPObject *obj); | |
115 static NPClass npclass_proxy_; | |
116 | |
117 scoped_refptr<NPChannelBase> channel_; | |
118 int route_id_; | |
119 int render_view_id_; | |
120 | |
121 // The url of the main frame hosting the plugin. | |
122 GURL page_url_; | |
123 }; | |
124 | |
125 } // namespace content | |
126 | |
127 #endif // CONTENT_COMMON_NPOBJECT_PROXY_H_ | |
OLD | NEW |