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