blob: bcc4de48dd3f9f38cb3d88825a690fab311e3aaa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "peppermain.h"
#include "event_handler.h"
#include <qbytearray.h>
#include <qlist.h>
void qt_nacl_message_output_callback(void *data);
void qt_nacl_setup()
{
// Initialize the qDebug message handler. Hooks into
// qt_message_output in qglobal.cpp.
extern void (*qt_nacl_message_handler) (const char *);
qt_nacl_message_handler = qt_nacl_message_output;
}
/*
Prints messages to the JavaScript console.
(If using the default javascript NaCl module loader.)
This function is thread-safe.
*/
void qt_nacl_message_output(const char *message)
{
char *copy = qstrdup(message);
// Pass the message to the plugin thread.
NPN_PluginThreadAsyncCall(event_handler->npp_, qt_nacl_message_output_callback, copy);
}
void qt_nacl_message_output_callback(void *data)
{
char * message = reinterpret_cast<char *>(data);
extern EventHandler* event_handler;
// Startup handling. If there is no output object,
// add the messages to an internal list for later
// output.
static QList<char *> pendingMessages;
if (event_handler->text_box_ == NULL) {
pendingMessages.append(message);
return;
}
if (pendingMessages.isEmpty() == false) {
foreach (char *message, pendingMessages) {
event_handler->addText(message);
free(message);
}
pendingMessages.clear();
}
event_handler->addText(message);
free(message);
}
|