move request_ready into PPInstance

This commit is contained in:
David Rose 2009-07-10 18:17:37 +00:00
parent 3e8b1c6ffd
commit e71220779c
3 changed files with 45 additions and 42 deletions

View File

@ -445,7 +445,7 @@ handle_request(P3D_request *request) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PPInstance::handle_request_loop // Function: PPInstance::handle_request_loop
// Access: Public, Static // Access: Private, Static
// Description: Checks for any new requests from the plugin, and // Description: Checks for any new requests from the plugin, and
// dispatches them to the appropriate PPInstance. This // dispatches them to the appropriate PPInstance. This
// function is called only in the main thread. // function is called only in the main thread.
@ -582,6 +582,48 @@ variant_to_p3dobj(const NPVariant *variant) {
return P3D_new_none_object(); 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 // Function: PPInstance::start_download
// Access: Private // Access: Private

View File

@ -61,6 +61,8 @@ public:
static void output_np_variant(ostream &out, const NPVariant &result); static void output_np_variant(ostream &out, const NPVariant &result);
private: private:
static void request_ready(P3D_instance *instance);
void start_download(const string &url, PPDownloadRequest *req); void start_download(const string &url, PPDownloadRequest *req);
void downloaded_file(PPDownloadRequest *req, const string &filename); void downloaded_file(PPDownloadRequest *req, const string &filename);
static string get_filename_from_url(const string &url); static string get_filename_from_url(const string &url);

View File

@ -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 // Function: NP_GetMIMEDescription
// Description: On Unix, this function is called by the browser to // Description: On Unix, this function is called by the browser to