Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: remoting/host/plugin/host_plugin.cc

Issue 7655006: Revert 97050 - Add PluginMessageLoopProxy and use it for Host plugin UI thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/host_mock_objects.cc ('k') | remoting/host/plugin/host_script_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #include <stdio.h> 5 #include <stdio.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/stringize_macros.h" 14 #include "base/stringize_macros.h"
15 #include "remoting/base/plugin_message_loop_proxy.h"
16 #include "remoting/host/plugin/host_plugin_utils.h" 15 #include "remoting/host/plugin/host_plugin_utils.h"
17 #include "remoting/host/plugin/host_script_object.h" 16 #include "remoting/host/plugin/host_script_object.h"
18 #include "third_party/npapi/bindings/npapi.h" 17 #include "third_party/npapi/bindings/npapi.h"
19 #include "third_party/npapi/bindings/npfunctions.h" 18 #include "third_party/npapi/bindings/npfunctions.h"
20 #include "third_party/npapi/bindings/npruntime.h" 19 #include "third_party/npapi/bindings/npruntime.h"
21 20
22 // Symbol export is handled with a separate def file on Windows. 21 // Symbol export is handled with a separate def file on Windows.
23 #if defined (__GNUC__) && __GNUC__ >= 4 22 #if defined (__GNUC__) && __GNUC__ >= 4
24 #define EXPORT __attribute__((visibility("default"))) 23 #define EXPORT __attribute__((visibility("default")))
25 #else 24 #else
(...skipping 26 matching lines...) Expand all
52 51
53 // The name and description are returned by GetValue, but are also 52 // The name and description are returned by GetValue, but are also
54 // combined with the MIME type to satisfy GetMIMEDescription, so we 53 // combined with the MIME type to satisfy GetMIMEDescription, so we
55 // use macros here to allow that to happen at compile-time. 54 // use macros here to allow that to happen at compile-time.
56 #define HOST_PLUGIN_NAME "Remoting Host Plugin" 55 #define HOST_PLUGIN_NAME "Remoting Host Plugin"
57 #define HOST_PLUGIN_DESCRIPTION "Remoting Host Plugin" 56 #define HOST_PLUGIN_DESCRIPTION "Remoting Host Plugin"
58 57
59 // NPAPI plugin implementation for remoting host. 58 // NPAPI plugin implementation for remoting host.
60 // Documentation for most of the calls in this class can be found here: 59 // Documentation for most of the calls in this class can be found here:
61 // https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Scripting_plugins 60 // https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Scripting_plugins
62 class HostNPPlugin : public remoting::PluginMessageLoopProxy::Delegate { 61 class HostNPPlugin {
63 public: 62 public:
64 // |mode| is the display mode of plug-in. Values: 63 // |mode| is the display mode of plug-in. Values:
65 // NP_EMBED: (1) Instance was created by an EMBED tag and shares the browser 64 // NP_EMBED: (1) Instance was created by an EMBED tag and shares the browser
66 // window with other content. 65 // window with other content.
67 // NP_FULL: (2) Instance was created by a separate file and is the primary 66 // NP_FULL: (2) Instance was created by a separate file and is the primary
68 // content in the window. 67 // content in the window.
69 HostNPPlugin(NPP instance, uint16 mode) 68 HostNPPlugin(NPP instance, uint16 mode)
70 : instance_(instance), 69 : instance_(instance), scriptable_object_(NULL) {}
71 scriptable_object_(NULL),
72 np_thread_id_(base::PlatformThread::CurrentId()) {
73 }
74 70
75 ~HostNPPlugin() { 71 ~HostNPPlugin() {
76 if (scriptable_object_) { 72 if (scriptable_object_) {
77 g_npnetscape_funcs->releaseobject(scriptable_object_); 73 g_npnetscape_funcs->releaseobject(scriptable_object_);
78 scriptable_object_ = NULL; 74 scriptable_object_ = NULL;
79 } 75 }
80 } 76 }
81 77
82 bool Init(int16 argc, char** argn, char** argv, NPSavedData* saved) { 78 bool Init(int16 argc, char** argn, char** argv, NPSavedData* saved) {
83 #if defined(OS_MACOSX) 79 #if defined(OS_MACOSX)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 &RemoveProperty, 139 &RemoveProperty,
144 &Enumerate, 140 &Enumerate,
145 NULL 141 NULL
146 }; 142 };
147 scriptable_object_ = g_npnetscape_funcs->createobject(instance_, 143 scriptable_object_ = g_npnetscape_funcs->createobject(instance_,
148 &npc_ref_object); 144 &npc_ref_object);
149 } 145 }
150 return scriptable_object_; 146 return scriptable_object_;
151 } 147 }
152 148
153 // PluginMessageLoopProxy::Delegate implementation.
154 virtual bool RunOnPluginThread(
155 int delay_ms, void(function)(void*), void* data) OVERRIDE {
156 if (delay_ms == 0) {
157 g_npnetscape_funcs->pluginthreadasynccall(instance_, function, data);
158 } else {
159 base::AutoLock auto_lock(timers_lock_);
160 uint32_t timer_id = g_npnetscape_funcs->scheduletimer(
161 instance_, delay_ms, false, &NPDelayedTaskSpringboard);
162 DelayedTask task = {function, data};
163 timers_[timer_id] = task;
164 }
165 return true;
166 }
167
168 virtual bool IsPluginThread() OVERRIDE {
169 return np_thread_id_ == base::PlatformThread::CurrentId();
170 }
171
172 static void NPDelayedTaskSpringboard(NPP npp, uint32_t timer_id) {
173 HostNPPlugin* self = reinterpret_cast<HostNPPlugin*>(npp->pdata);
174 DelayedTask task;
175 {
176 base::AutoLock auto_lock(self->timers_lock_);
177 std::map<uint32_t, DelayedTask>::iterator it =
178 self->timers_.find(timer_id);
179 CHECK(it != self->timers_.end());
180 task = it->second;
181 self->timers_.erase(it);
182 }
183 task.function(task.data);
184 }
185
186 private: 149 private:
187 struct ScriptableNPObject : public NPObject { 150 struct ScriptableNPObject : public NPObject {
188 HostNPScriptObject* scriptable_object; 151 HostNPScriptObject* scriptable_object;
189 }; 152 };
190 153
191 struct DelayedTask {
192 void (*function)(void*);
193 void* data;
194 };
195
196 static HostNPScriptObject* ScriptableFromObject(NPObject* obj) { 154 static HostNPScriptObject* ScriptableFromObject(NPObject* obj) {
197 return reinterpret_cast<ScriptableNPObject*>(obj)->scriptable_object; 155 return reinterpret_cast<ScriptableNPObject*>(obj)->scriptable_object;
198 } 156 }
199 157
200 static NPObject* Allocate(NPP npp, NPClass* aClass) { 158 static NPObject* Allocate(NPP npp, NPClass* aClass) {
201 VLOG(2) << "static Allocate"; 159 VLOG(2) << "static Allocate";
202 ScriptableNPObject* object = 160 ScriptableNPObject* object =
203 reinterpret_cast<ScriptableNPObject*>( 161 reinterpret_cast<ScriptableNPObject*>(
204 g_npnetscape_funcs->memalloc(sizeof(ScriptableNPObject))); 162 g_npnetscape_funcs->memalloc(sizeof(ScriptableNPObject)));
205 HostNPPlugin* plugin = reinterpret_cast<HostNPPlugin*>(npp->pdata);
206 163
207 object->_class = aClass; 164 object->_class = aClass;
208 object->referenceCount = 1; 165 object->referenceCount = 1;
209 object->scriptable_object = new HostNPScriptObject(npp, object, plugin); 166 object->scriptable_object = new HostNPScriptObject(npp, object);
210 if (!object->scriptable_object->Init()) { 167 if (!object->scriptable_object->Init()) {
211 Deallocate(object); 168 Deallocate(object);
212 object = NULL; 169 object = NULL;
213 } 170 }
214 return object; 171 return object;
215 } 172 }
216 173
217 static void Deallocate(NPObject* npobj) { 174 static void Deallocate(NPObject* npobj) {
218 VLOG(2) << "static Deallocate"; 175 VLOG(2) << "static Deallocate";
219 if (npobj) { 176 if (npobj) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 for (uint32_t i = 0; i < *count; ++i) { 283 for (uint32_t i = 0; i < *count; ++i) {
327 (*value)[i] = 284 (*value)[i] =
328 g_npnetscape_funcs->getstringidentifier(values[i].c_str()); 285 g_npnetscape_funcs->getstringidentifier(values[i].c_str());
329 } 286 }
330 } 287 }
331 return is_good; 288 return is_good;
332 } 289 }
333 290
334 NPP instance_; 291 NPP instance_;
335 NPObject* scriptable_object_; 292 NPObject* scriptable_object_;
336
337 base::PlatformThreadId np_thread_id_;
338 std::map<uint32_t, DelayedTask> timers_;
339 base::Lock timers_lock_;
340 }; 293 };
341 294
342 // Utility functions to map NPAPI Entry Points to C++ Objects. 295 // Utility functions to map NPAPI Entry Points to C++ Objects.
343 HostNPPlugin* PluginFromInstance(NPP instance) { 296 HostNPPlugin* PluginFromInstance(NPP instance) {
344 return reinterpret_cast<HostNPPlugin*>(instance->pdata); 297 return reinterpret_cast<HostNPPlugin*>(instance->pdata);
345 } 298 }
346 299
347 NPError CreatePlugin(NPMIMEType pluginType, 300 NPError CreatePlugin(NPMIMEType pluginType,
348 NPP instance, 301 NPP instance,
349 uint16 mode, 302 uint16 mode,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 445 }
493 446
494 EXPORT NPError API_CALL NP_GetValue(void* npp, 447 EXPORT NPError API_CALL NP_GetValue(void* npp,
495 NPPVariable variable, 448 NPPVariable variable,
496 void* value) { 449 void* value) {
497 return GetValue((NPP)npp, variable, value); 450 return GetValue((NPP)npp, variable, value);
498 } 451 }
499 #endif 452 #endif
500 453
501 } // extern "C" 454 } // extern "C"
OLDNEW
« no previous file with comments | « remoting/host/host_mock_objects.cc ('k') | remoting/host/plugin/host_script_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698