Home | History | Annotate | Download | only in browser_plugin
      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.
      4 
      5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__
      6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__
      7 
      8 #include "base/memory/scoped_vector.h"
      9 #include "base/memory/weak_ptr.h"
     10 #include "ppapi/shared_impl/resource.h"
     11 #include "third_party/npapi/bindings/npruntime.h"
     12 
     13 namespace content {
     14 
     15 class BrowserPlugin;
     16 class BrowserPluginMethodBinding;
     17 class BrowserPluginPropertyBinding;
     18 
     19 class BrowserPluginBindings {
     20  public:
     21   // BrowserPluginNPObject is a simple struct that adds a pointer back to a
     22   // BrowserPluginBindings instance.  This way, we can use an NPObject to allow
     23   // JavaScript interactions without forcing BrowserPluginBindings to inherit
     24   // from NPObject.
     25   struct BrowserPluginNPObject : public NPObject {
     26     BrowserPluginNPObject();
     27     ~BrowserPluginNPObject();
     28 
     29     base::WeakPtr<BrowserPluginBindings> message_channel;
     30   };
     31 
     32   explicit BrowserPluginBindings(BrowserPlugin* instance);
     33   ~BrowserPluginBindings();
     34 
     35   NPObject* np_object() const { return np_object_; }
     36 
     37   BrowserPlugin* instance() const { return instance_; }
     38 
     39   bool HasMethod(NPIdentifier name) const;
     40 
     41   bool InvokeMethod(NPIdentifier name,
     42                     const NPVariant* args,
     43                     uint32 arg_count,
     44                     NPVariant* result);
     45 
     46   bool HasProperty(NPIdentifier name) const;
     47   bool SetProperty(NPObject* np_obj,
     48                    NPIdentifier name,
     49                    const NPVariant* variant);
     50   bool GetProperty(NPIdentifier name, NPVariant* result);
     51   bool RemoveProperty(NPObject *np_obj, NPIdentifier name);
     52  private:
     53   BrowserPlugin* instance_;
     54   // The NPObject we use to expose postMessage to JavaScript.
     55   BrowserPluginNPObject* np_object_;
     56 
     57   typedef ScopedVector<BrowserPluginMethodBinding> BindingList;
     58   BindingList method_bindings_;
     59   typedef ScopedVector<BrowserPluginPropertyBinding> PropertyBindingList;
     60   PropertyBindingList property_bindings_;
     61 
     62   // This is used to ensure pending tasks will not fire after this object is
     63   // destroyed.
     64   base::WeakPtrFactory<BrowserPluginBindings> weak_ptr_factory_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindings);
     67 };
     68 
     69 }  // namespace content
     70 
     71 #endif  //  CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__
     72