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.
5 // A proxy for NPObject that sends all calls to the object to an NPObjectStub
6 // running in a different process.
8 #ifndef CONTENT_CHILD_NPAPI_NPOBJECT_PROXY_H_
9 #define CONTENT_CHILD_NPAPI_NPOBJECT_PROXY_H_
11 #include "base/memory/ref_counted.h"
12 #include "content/child/npapi/npobject_base.h"
13 #include "ipc/ipc_listener.h"
14 #include "ipc/ipc_sender.h"
15 #include "third_party/npapi/bindings/npruntime.h"
16 #include "ui/gfx/native_widget_types.h"
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
,
36 ~NPObjectProxy() override
;
38 static NPObject
* Create(NPChannelBase
* channel
,
44 // IPC::Sender implementation:
45 bool Send(IPC::Message
* msg
) override
;
46 int route_id() { return route_id_
; }
47 NPChannelBase
* channel() { return channel_
.get(); }
49 // The next 9 functions are called on NPObjects from the plugin and browser.
50 static bool NPHasMethod(NPObject
*obj
,
52 static bool NPInvoke(NPObject
*obj
,
54 const NPVariant
*args
,
57 static bool NPInvokeDefault(NPObject
*npobj
,
58 const NPVariant
*args
,
61 static bool NPHasProperty(NPObject
*obj
,
63 static bool NPGetProperty(NPObject
*obj
,
66 static bool NPSetProperty(NPObject
*obj
,
68 const NPVariant
*value
);
69 static bool NPRemoveProperty(NPObject
*obj
,
71 static bool NPNEnumerate(NPObject
*obj
,
74 static bool NPNConstruct(NPObject
*npobj
,
75 const NPVariant
*args
,
79 // The next two functions are only called on NPObjects from the browser.
80 static bool NPNEvaluate(NPP npp
,
85 static bool NPInvokePrivate(NPP npp
,
89 const NPVariant
*args
,
93 static NPObjectProxy
* GetProxy(NPObject
* object
);
94 static const NPClass
* npclass() { return &npclass_proxy_
; }
96 // NPObjectBase implementation.
97 NPObject
* GetUnderlyingNPObject() override
;
99 IPC::Listener
* GetChannelListener() override
;
102 NPObjectProxy(NPChannelBase
* channel
,
105 const GURL
& page_url
);
107 // IPC::Listener implementation:
108 bool OnMessageReceived(const IPC::Message
& msg
) override
;
109 void OnChannelError() override
;
111 static NPObject
* NPAllocate(NPP
, NPClass
*);
112 static void NPDeallocate(NPObject
* npObj
);
114 // This function is only caled on NPObjects from the plugin.
115 static void NPPInvalidate(NPObject
*obj
);
116 static NPClass npclass_proxy_
;
118 scoped_refptr
<NPChannelBase
> channel_
;
122 // The url of the main frame hosting the plugin.
126 } // namespace content
128 #endif // CONTENT_CHILD_NPAPI_NPOBJECT_PROXY_H_