13 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/c/pp_module.h"
15 #include "ppapi/c/pp_var.h"
16 #include "ppapi/c/ppb.h"
17 #include "ppapi/c/ppb_core.h"
18 #include "ppapi/c/ppb_file_ref.h"
19 #include "ppapi/c/ppb_instance.h"
20 #include "ppapi/c/ppb_messaging.h"
21 #include "ppapi/c/ppb_url_loader.h"
22 #include "ppapi/c/ppb_url_request_info.h"
23 #include "ppapi/c/ppb_url_response_info.h"
24 #include "ppapi/c/ppb_var.h"
25 #include "ppapi/c/ppp.h"
26 #include "ppapi/c/ppp_instance.h"
27 #include "ppapi/c/ppp_messaging.h"
34 #ifdef HAVE_STRUCT_PPB_CORE
35 typedef struct PPB_Core PPB_Core;
37 #ifdef HAVE_STRUCT_PPB_MESSAGING
38 typedef struct PPB_Messaging PPB_Messaging;
40 #ifdef HAVE_STRUCT_PPB_VAR
41 typedef struct PPB_Var PPB_Var;
43 #ifdef HAVE_STRUCT_PPB_URLLOADER
44 typedef struct PPB_URLLoader PPB_URLLoader;
46 #ifdef HAVE_STRUCT_PPB_URLREQUESTINFO
47 typedef struct PPB_URLRequestInfo PPB_URLRequestInfo;
49 #ifdef HAVE_STRUCT_PPB_URLRESPONSEINFO
50 typedef struct PPB_URLResponseInfo PPB_URLResponseInfo;
52 #ifdef HAVE_STRUCT_PPP_INSTANCE
53 typedef struct PPP_Instance PPP_Instance;
113 #define GET_PEPPER_INSTANCE() (pruby_get_instance(current_instance))
126 pthread_cond_init(&data->
cond,
NULL);
161 return sizeof(*inst);
173 if (pthread_cond_signal(&instance->
cond)) {
174 perror(
"pepper-ruby:pthread_cond_signal");
184 if (pthread_cond_signal(&instance->
cond)) {
185 perror(
"pepper-ruby:pthread_cond_signal");
195 if (pthread_cond_signal(&instance->
cond)) {
196 perror(
"pepper-ruby:pthread_cond_signal");
213 #ifdef PPB_VAR_INTERFACE_1_0
216 return PP_MakeUndefined();
239 char* c_str = (
char*)
malloc(len + 1);
240 memcpy(c_str, var_c_str, len);
252 fprintf(stderr,
"[BUG] Unexpected object type: %x\n",
TYPE(str));
255 #ifdef PPB_VAR_INTERFACE_1_0
262 return PP_MakeUndefined();
268 static const char*
const error =
269 "throw 'Failed to convert the result to a JavaScript object';";
288 const char*
const cstr =
var_interface->VarToUtf8(lhs, &len);
289 return strncmp(cstr, rhs, len) == 0;
301 const char*
const cstr =
var_interface->VarToUtf8(var, &len);
302 const size_t prefix_len =
strlen(prefix);
303 return len >= prefix_len &&
memcmp(cstr, prefix, len) == 0;
368 if (pthread_mutex_lock(&instance->
mutex)) {
369 perror(
"pepper-ruby:pthread_mutex_lock");
373 pthread_mutex_unlock(&instance->
mutex);
389 static int initialized = 0;
396 fprintf(stderr,
"pepper_ruby:pthread_create: %s\n",
strerror(err));
399 pthread_detach(instance->
th);
432 if (pthread_mutex_lock(&instance->
mutex)) {
433 perror(
"pepper-ruby:pthread_mutex_lock");
438 pthread_mutex_unlock(&instance->
mutex);
520 #ifdef PPP_INSTANCE_INTERFACE_1_0
523 const struct PP_Rect* position,
524 const struct PP_Rect* clip)
593 size_t message_len =
strlen(message);
600 #define EVAL_PREFIX_LEN 5
605 fprintf(stderr,
"pepper_ruby:pthread_create: %s\n",
strerror(err));
608 pthread_detach(instance_data->
th);
624 core_interface = (PPB_Core*)(get_browser_interface(PPB_CORE_INTERFACE));
627 var_interface = (PPB_Var*)(get_browser_interface(PPB_VAR_INTERFACE));
633 loader_interface = (PPB_URLLoader*)(get_browser_interface(PPB_URLLOADER_INTERFACE));
636 request_interface = (PPB_URLRequestInfo*)(get_browser_interface(PPB_URLREQUESTINFO_INTERFACE));
639 response_interface = (PPB_URLResponseInfo*)(get_browser_interface(PPB_URLRESPONSEINFO_INTERFACE));
642 fileref_interface = (PPB_FileRef*)(get_browser_interface(PPB_FILEREF_INTERFACE));
645 return pruby_init() ? PP_ERROR_FAILED : PP_OK;
654 PP_EXPORT
const void*
657 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) {
658 static PPP_Instance instance_interface = {
665 return &instance_interface;
666 }
else if (strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0) {
707 if (
result != PP_OK_COMPLETIONPENDING) {
721 struct PP_Var status =
723 if (status.type == PP_VARTYPE_INT32) {
744 if (path[0] ==
'.' && path[1] ==
'/') path += 2;
749 if (pthread_cond_wait(&instance->
cond, &instance->
mutex)) {
750 perror(
"pepper-ruby:pthread_cond_wait");
754 fprintf(stderr,
"Failed to open URL: %d: %s\n",
761 if (pthread_cond_wait(&instance->
cond, &instance->
mutex)) {
762 perror(
"pepper-ruby:pthread_cond_wait");
791 if (
result != PP_OK_COMPLETIONPENDING) {
802 instance->
buf, result);
806 else if (result == 0) {
826 const char *real_path;
828 if (path[0] !=
'.' || path[1] !=
'/') path += 2;
835 if (pthread_cond_wait(&instance->
cond, &instance->
mutex)) {
836 perror(
"pepper-ruby:pthread_cond_wait");
840 fprintf(stderr,
"Failed to open URL: %d: %s\n",
847 if (pthread_cond_wait(&instance->
cond, &instance->
mutex)) {
848 perror(
"pepper-ruby:pthread_cond_wait");
855 if (pthread_cond_wait(&instance->
cond, &instance->
mutex)) {
856 perror(
"pepper-ruby:pthread_cond_wait");
864 extern void*
rb_compile_cstr(
const char *
f,
const char *s,
int len,
int line);