summaryrefslogtreecommitdiffstats
path: root/chrome/plugin/npobject_stub.h
blob: 98be7dacb62fe2e4b234e5b25e174cd6125ea334 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// A class that receives IPC messages from an NPObjectProxy and calls the real
// NPObject.

#ifndef CHROME_PLUGIN_NPOBJECT_STUB_H_
#define CHROME_PLUGIN_NPOBJECT_STUB_H_

#include <vector>

#include "base/ref_counted.h"
#include "ipc/ipc_channel.h"

namespace base {
class WaitableEvent;
}

class PluginChannelBase;
class WebPluginDelegateProxy;
struct NPIdentifier_Param;
struct NPObject;
struct NPVariant_Param;

// This wraps an NPObject and converts IPC messages from NPObjectProxy to calls
// to the object.  The results are marshalled back.  See npobject_proxy.h for
// more information.
class NPObjectStub : public IPC::Channel::Listener,
                     public IPC::Message::Sender {
 public:
  NPObjectStub(NPObject* npobject,
               PluginChannelBase* channel,
               int route_id,
               base::WaitableEvent* modal_dialog_event);
  ~NPObjectStub();

  // IPC::Message::Sender implementation:
  bool Send(IPC::Message* msg);

  // Called when the plugin widget that this NPObject came from is destroyed.
  // This is needed because the renderer calls NPN_DeallocateObject on the
  // window script object on destruction to avoid leaks.
  void set_invalid() { valid_ = false; }
  void set_proxy(WebPluginDelegateProxy* proxy) {
    web_plugin_delegate_proxy_ = proxy;
  }

 private:
  // IPC::Channel::Listener implementation:
  void OnMessageReceived(const IPC::Message& message);
  void OnChannelError();

  // message handlers
  void OnRelease(IPC::Message* reply_msg);
  void OnHasMethod(const NPIdentifier_Param& name,
                   bool* result);
  void OnInvoke(bool is_default,
                const NPIdentifier_Param& method,
                const std::vector<NPVariant_Param>& args,
                IPC::Message* reply_msg);
  void OnHasProperty(const NPIdentifier_Param& name,
                     bool* result);
  void OnGetProperty(const NPIdentifier_Param& name,
                     NPVariant_Param* property,
                     bool* result);
  void OnSetProperty(const NPIdentifier_Param& name,
                     const NPVariant_Param& property,
                     bool* result);
  void OnRemoveProperty(const NPIdentifier_Param& name,
                        bool* result);
  void OnInvalidate();
  void OnEnumeration(std::vector<NPIdentifier_Param>* value,
                     bool* result);
  void OnEvaluate(const std::string& script, bool popups_allowed,
                  IPC::Message* reply_msg);
  void OnSetException(const std::string& message);

 private:
  NPObject* npobject_;
  int route_id_;
  scoped_refptr<PluginChannelBase> channel_;

  base::WaitableEvent* modal_dialog_event_;

  // These variables are used to ensure that the window script object is not
  // called after the plugin widget has gone away, as the frame manually
  // deallocates it and ignores the refcount to avoid leaks.
  bool valid_;
  WebPluginDelegateProxy* web_plugin_delegate_proxy_;
};

#endif  // CHROME_PLUGIN_NPOBJECT_STUB_H_