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.
5 // A proxy for NPObject that sends all calls to the object to an NPObjectStub
6 // running in a different process.
8 #ifndef CONTENT_COMMON_NPOBJECT_PROXY_H_
9 #define CONTENT_COMMON_NPOBJECT_PROXY_H_
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"
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 virtual ~NPObjectProxy();
38 static NPObject
* Create(NPChannelBase
* channel
,
41 const GURL
& page_url
);
43 // IPC::Sender implementation:
44 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
45 int route_id() { return route_id_
; }
46 NPChannelBase
* channel() { return channel_
; }
48 // The next 9 functions are called on NPObjects from the plugin and browser.
49 static bool NPHasMethod(NPObject
*obj
,
51 static bool NPInvoke(NPObject
*obj
,
53 const NPVariant
*args
,
56 static bool NPInvokeDefault(NPObject
*npobj
,
57 const NPVariant
*args
,
60 static bool NPHasProperty(NPObject
*obj
,
62 static bool NPGetProperty(NPObject
*obj
,
65 static bool NPSetProperty(NPObject
*obj
,
67 const NPVariant
*value
);
68 static bool NPRemoveProperty(NPObject
*obj
,
70 static bool NPNEnumerate(NPObject
*obj
,
73 static bool NPNConstruct(NPObject
*npobj
,
74 const NPVariant
*args
,
78 // The next two functions are only called on NPObjects from the browser.
79 static bool NPNEvaluate(NPP npp
,
84 static bool NPInvokePrivate(NPP npp
,
88 const NPVariant
*args
,
92 static NPObjectProxy
* GetProxy(NPObject
* object
);
93 static const NPClass
* npclass() { return &npclass_proxy_
; }
95 // NPObjectBase implementation.
96 virtual NPObject
* GetUnderlyingNPObject() OVERRIDE
;
98 virtual IPC::Listener
* GetChannelListener() OVERRIDE
;
101 NPObjectProxy(NPChannelBase
* channel
,
104 const GURL
& page_url
);
106 // IPC::Listener implementation:
107 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
108 virtual void OnChannelError() OVERRIDE
;
110 static NPObject
* NPAllocate(NPP
, NPClass
*);
111 static void NPDeallocate(NPObject
* npObj
);
113 // This function is only caled on NPObjects from the plugin.
114 static void NPPInvalidate(NPObject
*obj
);
115 static NPClass npclass_proxy_
;
117 scoped_refptr
<NPChannelBase
> channel_
;
121 // The url of the main frame hosting the plugin.
125 } // namespace content
127 #endif // CONTENT_COMMON_NPOBJECT_PROXY_H_