| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ | 5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ |
| 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ | 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ |
| 7 | 7 |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "ppapi/shared_impl/resource.h" | 10 #include "ppapi/shared_impl/resource.h" |
| 11 #include "third_party/npapi/bindings/npruntime.h" | 11 #include "third_party/npapi/bindings/npruntime.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class BrowserPlugin; | 15 class BrowserPluginImpl; |
| 16 class BrowserPluginMethodBinding; | 16 class BrowserPluginMethodBinding; |
| 17 class BrowserPluginPropertyBinding; | 17 class BrowserPluginPropertyBinding; |
| 18 | 18 |
| 19 class BrowserPluginBindings { | 19 class BrowserPluginBindings { |
| 20 public: | 20 public: |
| 21 // BrowserPluginNPObject is a simple struct that adds a pointer back to a | 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 | 22 // BrowserPluginBindings instance. This way, we can use an NPObject to allow |
| 23 // JavaScript interactions without forcing BrowserPluginBindings to inherit | 23 // JavaScript interactions without forcing BrowserPluginBindings to inherit |
| 24 // from NPObject. | 24 // from NPObject. |
| 25 struct BrowserPluginNPObject : public NPObject { | 25 struct BrowserPluginNPObject : public NPObject { |
| 26 BrowserPluginNPObject(); | 26 BrowserPluginNPObject(); |
| 27 ~BrowserPluginNPObject(); | 27 ~BrowserPluginNPObject(); |
| 28 | 28 |
| 29 base::WeakPtr<BrowserPluginBindings> message_channel; | 29 base::WeakPtr<BrowserPluginBindings> message_channel; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 explicit BrowserPluginBindings(BrowserPlugin* instance); | 32 explicit BrowserPluginBindings(BrowserPluginImpl* instance); |
| 33 ~BrowserPluginBindings(); | 33 ~BrowserPluginBindings(); |
| 34 | 34 |
| 35 NPObject* np_object() const { return np_object_; } | 35 NPObject* np_object() const { return np_object_; } |
| 36 | 36 |
| 37 BrowserPlugin* instance() const { return instance_; } | 37 BrowserPluginImpl* instance() const { return instance_; } |
| 38 | 38 |
| 39 bool HasMethod(NPIdentifier name) const; | 39 bool HasMethod(NPIdentifier name) const; |
| 40 | 40 |
| 41 bool InvokeMethod(NPIdentifier name, | 41 bool InvokeMethod(NPIdentifier name, |
| 42 const NPVariant* args, | 42 const NPVariant* args, |
| 43 uint32 arg_count, | 43 uint32 arg_count, |
| 44 NPVariant* result); | 44 NPVariant* result); |
| 45 | 45 |
| 46 bool HasProperty(NPIdentifier name) const; | 46 bool HasProperty(NPIdentifier name) const; |
| 47 bool SetProperty(NPObject* np_obj, | 47 bool SetProperty(NPObject* np_obj, |
| 48 NPIdentifier name, | 48 NPIdentifier name, |
| 49 const NPVariant* variant); | 49 const NPVariant* variant); |
| 50 bool GetProperty(NPIdentifier name, NPVariant* result); | 50 bool GetProperty(NPIdentifier name, NPVariant* result); |
| 51 bool RemoveProperty(NPObject *np_obj, NPIdentifier name); | 51 bool RemoveProperty(NPObject *np_obj, NPIdentifier name); |
| 52 |
| 53 // Adds a method/property binding. The binding's lifetime is managed by |
| 54 // BrowserPluginBindings. BrowserPluginBindings is destroyed prior to |
| 55 // cleaning up BrowserPluginObservers. |
| 56 void AddMethodBinding(BrowserPluginMethodBinding* method_binding); |
| 57 void AddPropertyBinding(BrowserPluginPropertyBinding* property_binding); |
| 58 |
| 52 private: | 59 private: |
| 53 BrowserPlugin* instance_; | 60 BrowserPluginImpl* instance_; |
| 54 // The NPObject we use to expose postMessage to JavaScript. | 61 // The NPObject we use to expose postMessage to JavaScript. |
| 55 BrowserPluginNPObject* np_object_; | 62 BrowserPluginNPObject* np_object_; |
| 56 | 63 |
| 57 typedef ScopedVector<BrowserPluginMethodBinding> BindingList; | 64 typedef ScopedVector<BrowserPluginMethodBinding> BindingList; |
| 58 BindingList method_bindings_; | 65 BindingList method_bindings_; |
| 59 typedef ScopedVector<BrowserPluginPropertyBinding> PropertyBindingList; | 66 typedef ScopedVector<BrowserPluginPropertyBinding> PropertyBindingList; |
| 60 PropertyBindingList property_bindings_; | 67 PropertyBindingList property_bindings_; |
| 61 | 68 |
| 62 // This is used to ensure pending tasks will not fire after this object is | 69 // This is used to ensure pending tasks will not fire after this object is |
| 63 // destroyed. | 70 // destroyed. |
| 64 base::WeakPtrFactory<BrowserPluginBindings> weak_ptr_factory_; | 71 base::WeakPtrFactory<BrowserPluginBindings> weak_ptr_factory_; |
| 65 | 72 |
| 66 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindings); | 73 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindings); |
| 67 }; | 74 }; |
| 68 | 75 |
| 69 } // namespace content | 76 } // namespace content |
| 70 | 77 |
| 71 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ | 78 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BINDINGS_H__ |
| OLD | NEW |