1 // Copyright (c) 2011 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 class that receives IPC messages from an NPObjectProxy and calls the real
8 #ifndef CONTENT_COMMON_NPOBJECT_STUB_H_
9 #define CONTENT_COMMON_NPOBJECT_STUB_H_
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/common/npobject_base.h"
17 #include "googleurl/src/gurl.h"
18 #include "ipc/ipc_channel.h"
19 #include "ui/gfx/native_widget_types.h"
22 struct NPIdentifier_Param
;
24 struct NPVariant_Param
;
26 // This wraps an NPObject and converts IPC messages from NPObjectProxy to calls
27 // to the object. The results are marshalled back. See npobject_proxy.h for
29 class NPObjectStub
: public IPC::Channel::Listener
,
30 public IPC::Message::Sender
,
31 public base::SupportsWeakPtr
<NPObjectStub
>,
34 NPObjectStub(NPObject
* npobject
,
35 NPChannelBase
* channel
,
37 gfx::NativeViewId containing_window
,
38 const GURL
& page_url
);
39 virtual ~NPObjectStub();
41 // Schedules tear-down of this stub. The underlying NPObject reference is
42 // released, and further invokations form the IPC channel will fail once this
43 // call has returned. Deletion of the stub is deferred to the main loop, in
44 // case it is touched as the stack unwinds.
47 // IPC::Message::Sender implementation:
48 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
50 // NPObjectBase implementation.
51 virtual NPObject
* GetUnderlyingNPObject() OVERRIDE
;
52 virtual IPC::Channel::Listener
* GetChannelListener() OVERRIDE
;
55 // IPC::Channel::Listener implementation:
56 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
57 virtual void OnChannelError() OVERRIDE
;
60 void OnRelease(IPC::Message
* reply_msg
);
61 void OnHasMethod(const NPIdentifier_Param
& name
,
63 void OnInvoke(bool is_default
,
64 const NPIdentifier_Param
& method
,
65 const std::vector
<NPVariant_Param
>& args
,
66 IPC::Message
* reply_msg
);
67 void OnHasProperty(const NPIdentifier_Param
& name
,
69 void OnGetProperty(const NPIdentifier_Param
& name
,
70 NPVariant_Param
* property
,
72 void OnSetProperty(const NPIdentifier_Param
& name
,
73 const NPVariant_Param
& property
,
74 IPC::Message
* reply_msg
);
75 void OnRemoveProperty(const NPIdentifier_Param
& name
,
78 void OnEnumeration(std::vector
<NPIdentifier_Param
>* value
,
80 void OnConstruct(const std::vector
<NPVariant_Param
>& args
,
81 IPC::Message
* reply_msg
);
82 void OnEvaluate(const std::string
& script
, bool popups_allowed
,
83 IPC::Message
* reply_msg
);
87 scoped_refptr
<NPChannelBase
> channel_
;
89 gfx::NativeViewId containing_window_
;
91 // The url of the main frame hosting the plugin.
95 #endif // CONTENT_COMMON_NPOBJECT_STUB_H_