From ee7c5cea02327013f7d00cb022788b9e8c14419b Mon Sep 17 00:00:00 2001 From: "vangelis@google.com" Date: Wed, 30 Sep 2009 18:10:53 +0000 Subject: Switching asynchronous tick callback in chrome to use the empty data url method instead of NPN_PluginThreadAsyncCall. NPN_PluginThreadAsyncCall causes Chrome to misbehave including freezing up when closing tabs (http://code.google.com/p/o3d/issues/detail?id=149). Review URL: http://codereview.chromium.org/235059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27634 0039d316-1c4b-4281-b951-d872f2087c98 --- o3d/plugin/cross/o3d_glue.cc | 47 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/o3d/plugin/cross/o3d_glue.cc b/o3d/plugin/cross/o3d_glue.cc index 5911285..91a12f7 100644 --- a/o3d/plugin/cross/o3d_glue.cc +++ b/o3d/plugin/cross/o3d_glue.cc @@ -847,15 +847,46 @@ void PluginObject::AsyncTick() { ++pending_ticks_; - // Invoke Tick asynchronously if NPN_PluginThreadAsyncCall is supported. - // Otherwise invoke it synchronously. - int plugin_major, plugin_minor, browser_major, browser_minor; - NPN_Version(&plugin_major, &plugin_minor, &browser_major, &browser_minor); - if (browser_major > 0 || - browser_minor >= NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL) { - NPN_PluginThreadAsyncCall(npp_, TickPluginObject, this); + // In Chrome NPN_PluginThreadAsyncCall doesn't seem to function properly. + // We resort to loading a data: url with zero bytes to get a tick callback + // asynchronously. + // TODO(vangelis): Remove this special path when Chrome's + // NPN_PluginThreadAsyncCall is fixed. + if (IsChrome()) { + class TickCallback : public StreamManager::FinishedCallback { + public: + explicit TickCallback(PluginObject* plugin_object) + : plugin_object_(plugin_object) { + } + + virtual void Run(DownloadStream*, + bool, + const std::string&, + const std::string&) { + plugin_object_->Tick(); + } + + private: + PluginObject* plugin_object_; + }; + + if (!stream_manager_->LoadURL("data:,", NULL, NULL, NULL, + new TickCallback(this), NP_NORMAL)) { + DLOG(ERROR) << "Chrome failed to access data url"; + // If the async call fails then tick synchronously. + Tick(); + } } else { - Tick(); + // Invoke Tick asynchronously if NPN_PluginThreadAsyncCall is supported. + // Otherwise invoke it synchronously. + int plugin_major, plugin_minor, browser_major, browser_minor; + NPN_Version(&plugin_major, &plugin_minor, &browser_major, &browser_minor); + if (browser_major > 0 || + browser_minor >= NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL) { + NPN_PluginThreadAsyncCall(npp_, TickPluginObject, this); + } else { + Tick(); + } } } -- cgit v1.1