@@ -31,49 +31,21 @@ std::thread(&CACKeyInstance::pcscNaClInitWrapper, this, core).detach(); } virtual ~CACKeyInstance() {} - virtual void HandleMessage(const pp::Var& messagePlain) { + virtual void HandleMessageThread(pp::VarDictionary *message) { int numCertificates, i; struct cackey_certificate *certificates; - pp::VarDictionary *message; pp::VarDictionary *reply; pp::VarArray certificatesPPArray; pp::VarArrayBuffer *certificateContents; - pp::Var command, target; - - /* - * The incoming message must be a dictionary - */ - if (!messagePlain.is_dictionary()) { - return; - } - - /* - * Process the appropriate command from the incoming message - */ - message = new pp::VarDictionary(messagePlain); - - /* - * Verify that this message is destined for us - */ - if (!message->HasKey("target")) { - return; - } - - target = message->Get("target"); - if (target.AsString() != "cackey") { - return; - } - - /* - * Determine what we are being asked to do - */ - if (!message->HasKey("command")) { - return; - } + pp::Var command; + + /* + * Extract the command + */ command = message->Get("command"); /* * Do the thing we are being asked to do */ @@ -117,10 +89,53 @@ /* * Send the reply back to the requestor, hopefully they are waiting for this message */ PostMessage(*reply); + return; + } + + virtual void HandleMessage(const pp::Var& messagePlain) { + pp::VarDictionary *message; + pp::Var target; + + /* + * The incoming message must be a dictionary + */ + if (!messagePlain.is_dictionary()) { + return; + } + + /* + * Process the appropriate command from the incoming message + */ + message = new pp::VarDictionary(messagePlain); + + /* + * Verify that this message is destined for us + */ + if (!message->HasKey("target")) { + return; + } + + target = message->Get("target"); + if (target.AsString() != "cackey") { + return; + } + + /* + * Determine what we are being asked to do + */ + if (!message->HasKey("command")) { + return; + } + + /* + * Process the request in another thread + */ + std::thread(&CACKeyInstance::HandleMessageThread, this, message).detach(); + return; } }; class CACKeyModule : public pp::Module {