From e71220779c7ca09c1f3903954f49a8a5aa681ac8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 10 Jul 2009 18:17:37 +0000 Subject: [PATCH] move request_ready into PPInstance --- direct/src/plugin_npapi/ppInstance.cxx | 44 +++++++++++++++++++++++++- direct/src/plugin_npapi/ppInstance.h | 2 ++ direct/src/plugin_npapi/startup.cxx | 41 ------------------------ 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index 686417dffc..fecafbadad 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -445,7 +445,7 @@ handle_request(P3D_request *request) { //////////////////////////////////////////////////////////////////// // Function: PPInstance::handle_request_loop -// Access: Public, Static +// Access: Private, Static // Description: Checks for any new requests from the plugin, and // dispatches them to the appropriate PPInstance. This // function is called only in the main thread. @@ -582,6 +582,48 @@ variant_to_p3dobj(const NPVariant *variant) { return P3D_new_none_object(); } +//////////////////////////////////////////////////////////////////// +// Function: PPInstance::request_ready +// Access: Private, Static +// Description: This function is attached as an asynchronous callback +// to each instance; it will be notified when the +// instance has a request ready. This function may be +// called in a sub-thread. +//////////////////////////////////////////////////////////////////// +void PPInstance:: +request_ready(P3D_instance *instance) { + logfile + << "request_ready in " << instance + // << " thread = " << GetCurrentThreadId() + << "\n" << flush; + +#ifdef _WIN32 + // Since we might be in a sub-thread at this point, use a Windows + // message to forward this event to the main thread. + + // Get the window handle for the window associated with this + // instance. + PPInstance *inst = (PPInstance *)(instance->_user_data); + assert(inst != NULL); + const NPWindow *win = inst->get_window(); + if (win != NULL && win->type == NPWindowTypeWindow) { + PostMessage((HWND)(win->window), WM_USER, 0, 0); + } + +#else + // On Mac, we ignore this asynchronous event, and rely on detecting + // it within HandleEvent(). TODO: enable a timer to ensure we get + // HandleEvent callbacks in a timely manner? Or maybe we should + // enable a one-shot timer in response to this asynchronous event? + +#ifndef __APPLE__ + // On Unix, HandleEvent isn't called, so we will do what it does + // right here. Not sure if this is right. + handle_request_loop(); +#endif // __APPLE__ +#endif // _WIN32 +} + //////////////////////////////////////////////////////////////////// // Function: PPInstance::start_download // Access: Private diff --git a/direct/src/plugin_npapi/ppInstance.h b/direct/src/plugin_npapi/ppInstance.h index ed2899cc47..c213f1c0bb 100644 --- a/direct/src/plugin_npapi/ppInstance.h +++ b/direct/src/plugin_npapi/ppInstance.h @@ -61,6 +61,8 @@ public: static void output_np_variant(ostream &out, const NPVariant &result); private: + static void request_ready(P3D_instance *instance); + void start_download(const string &url, PPDownloadRequest *req); void downloaded_file(PPDownloadRequest *req, const string &filename); static string get_filename_from_url(const string &url); diff --git a/direct/src/plugin_npapi/startup.cxx b/direct/src/plugin_npapi/startup.cxx index bfa8aa8b3e..47ad54566b 100644 --- a/direct/src/plugin_npapi/startup.cxx +++ b/direct/src/plugin_npapi/startup.cxx @@ -34,47 +34,6 @@ open_logfile() { } -//////////////////////////////////////////////////////////////////// -// Function: request_ready -// Description: This function is attached as an asynchronous callback -// to each instance; it will be notified when the -// instance has a request ready. This function may be -// called in a sub-thread. -//////////////////////////////////////////////////////////////////// -void -request_ready(P3D_instance *instance) { - logfile - << "request_ready in " << instance - // << " thread = " << GetCurrentThreadId() - << "\n" << flush; - -#ifdef _WIN32 - // Since we might be in a sub-thread at this point, use a Windows - // message to forward this event to the main thread. - - // Get the window handle for the window associated with this - // instance. - PPInstance *inst = (PPInstance *)(instance->_user_data); - assert(inst != NULL); - const NPWindow *win = inst->get_window(); - if (win != NULL && win->type == NPWindowTypeWindow) { - PostMessage((HWND)(win->window), WM_USER, 0, 0); - } - -#else - // On Mac, we ignore this asynchronous event, and rely on detecting - // it within HandleEvent(). TODO: enable a timer to ensure we get - // HandleEvent callbacks in a timely manner? Or maybe we should - // enable a one-shot timer in response to this asynchronous event? - -#ifndef __APPLE__ - // On Unix, HandleEvent isn't called, so we will do what it does - // right here. Not sure if this is right. - PPInstance::handle_request_loop(); -#endif // __APPLE__ -#endif // _WIN32 -} - //////////////////////////////////////////////////////////////////// // Function: NP_GetMIMEDescription // Description: On Unix, this function is called by the browser to