| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // A proxy for NPObject that sends all calls to the object to an NPObjectStub | 5 // A proxy for NPObject that sends all calls to the object to an NPObjectStub |
| 6 // running in a different process. | 6 // running in a different process. |
| 7 | 7 |
| 8 #ifndef CHROME_PLUGIN_NPOBJECT_PROXY_H_ | 8 #ifndef CHROME_PLUGIN_NPOBJECT_PROXY_H_ |
| 9 #define CHROME_PLUGIN_NPOBJECT_PROXY_H_ | 9 #define CHROME_PLUGIN_NPOBJECT_PROXY_H_ |
| 10 | 10 |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "chrome/common/ipc_channel.h" | 12 #include "chrome/common/ipc_channel.h" |
| 13 #include "googleurl/src/gurl.h" |
| 13 #include "third_party/npapi/bindings/npruntime.h" | 14 #include "third_party/npapi/bindings/npruntime.h" |
| 14 | 15 |
| 15 class PluginChannelBase; | 16 class PluginChannelBase; |
| 16 struct NPObject; | 17 struct NPObject; |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class WaitableEvent; | 20 class WaitableEvent; |
| 20 } | 21 } |
| 21 | 22 |
| 22 // When running a plugin in a different process from the renderer, we need to | 23 // When running a plugin in a different process from the renderer, we need to |
| 23 // proxy calls to NPObjects across process boundaries. This happens both ways, | 24 // proxy calls to NPObjects across process boundaries. This happens both ways, |
| 24 // as a plugin can get an NPObject for the window, and a page can get an | 25 // as a plugin can get an NPObject for the window, and a page can get an |
| 25 // NPObject for the plugin. In the process that interacts with the NPobject we | 26 // NPObject for the plugin. In the process that interacts with the NPobject we |
| 26 // give it an NPObjectProxy instead. All calls to it are sent across an IPC | 27 // give it an NPObjectProxy instead. All calls to it are sent across an IPC |
| 27 // channel (specifically, a PluginChannelBase). The NPObjectStub on the other | 28 // channel (specifically, a PluginChannelBase). The NPObjectStub on the other |
| 28 // side translates the IPC messages into calls to the actual NPObject, and | 29 // side translates the IPC messages into calls to the actual NPObject, and |
| 29 // returns the marshalled result. | 30 // returns the marshalled result. |
| 30 class NPObjectProxy : public IPC::Channel::Listener, | 31 class NPObjectProxy : public IPC::Channel::Listener, |
| 31 public IPC::Message::Sender { | 32 public IPC::Message::Sender { |
| 32 public: | 33 public: |
| 33 ~NPObjectProxy(); | 34 ~NPObjectProxy(); |
| 34 | 35 |
| 35 // modal_dialog_event_ is must be valid for the lifetime of the NPObjectProxy. | 36 // modal_dialog_event_ is must be valid for the lifetime of the NPObjectProxy. |
| 36 static NPObject* Create(PluginChannelBase* channel, | 37 static NPObject* Create(PluginChannelBase* channel, |
| 37 int route_id, | 38 int route_id, |
| 38 intptr_t npobject_ptr, | 39 intptr_t npobject_ptr, |
| 39 base::WaitableEvent* modal_dialog_event); | 40 base::WaitableEvent* modal_dialog_event, |
| 41 const GURL& page_url); |
| 40 | 42 |
| 41 // IPC::Message::Sender implementation: | 43 // IPC::Message::Sender implementation: |
| 42 bool Send(IPC::Message* msg); | 44 bool Send(IPC::Message* msg); |
| 43 int route_id() { return route_id_; } | 45 int route_id() { return route_id_; } |
| 44 PluginChannelBase* channel() { return channel_; } | 46 PluginChannelBase* channel() { return channel_; } |
| 45 | 47 |
| 46 // Returns the real NPObject's pointer (obviously only valid in the other | 48 // Returns the real NPObject's pointer (obviously only valid in the other |
| 47 // process). | 49 // process). |
| 48 intptr_t npobject_ptr() { return npobject_ptr_; } | 50 intptr_t npobject_ptr() { return npobject_ptr_; } |
| 49 | 51 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 uint32_t arg_count, | 96 uint32_t arg_count, |
| 95 NPVariant *result); | 97 NPVariant *result); |
| 96 | 98 |
| 97 static NPObjectProxy* GetProxy(NPObject* object); | 99 static NPObjectProxy* GetProxy(NPObject* object); |
| 98 static const NPClass* npclass() { return &npclass_proxy_; } | 100 static const NPClass* npclass() { return &npclass_proxy_; } |
| 99 | 101 |
| 100 private: | 102 private: |
| 101 NPObjectProxy(PluginChannelBase* channel, | 103 NPObjectProxy(PluginChannelBase* channel, |
| 102 int route_id, | 104 int route_id, |
| 103 intptr_t npobject_ptr, | 105 intptr_t npobject_ptr, |
| 104 base::WaitableEvent* modal_dialog_event); | 106 base::WaitableEvent* modal_dialog_event, |
| 107 const GURL& page_url); |
| 105 | 108 |
| 106 // IPC::Channel::Listener implementation: | 109 // IPC::Channel::Listener implementation: |
| 107 void OnMessageReceived(const IPC::Message& msg); | 110 void OnMessageReceived(const IPC::Message& msg); |
| 108 void OnChannelError(); | 111 void OnChannelError(); |
| 109 | 112 |
| 110 static NPObject* NPAllocate(NPP, NPClass*); | 113 static NPObject* NPAllocate(NPP, NPClass*); |
| 111 static void NPDeallocate(NPObject* npObj); | 114 static void NPDeallocate(NPObject* npObj); |
| 112 | 115 |
| 113 // This function is only caled on NPObjects from the plugin. | 116 // This function is only caled on NPObjects from the plugin. |
| 114 static void NPPInvalidate(NPObject *obj); | 117 static void NPPInvalidate(NPObject *obj); |
| 115 static NPClass npclass_proxy_; | 118 static NPClass npclass_proxy_; |
| 116 | 119 |
| 117 scoped_refptr<PluginChannelBase> channel_; | 120 scoped_refptr<PluginChannelBase> channel_; |
| 118 int route_id_; | 121 int route_id_; |
| 119 intptr_t npobject_ptr_; | 122 intptr_t npobject_ptr_; |
| 120 base::WaitableEvent* modal_dialog_event_; | 123 base::WaitableEvent* modal_dialog_event_; |
| 124 |
| 125 // The url of the main frame hosting the plugin. |
| 126 GURL page_url_; |
| 121 }; | 127 }; |
| 122 | 128 |
| 123 #endif // CHROME_PLUGIN_NPOBJECT_PROXY_H_ | 129 #endif // CHROME_PLUGIN_NPOBJECT_PROXY_H_ |
| OLD | NEW |