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");
194 instance->async_call_result.as_value = value;
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;
319 const char*
const msg = (
const char*)
instance->async_call_args;
368 if (pthread_mutex_lock(&
instance->mutex)) {
369 perror(
"pepper-ruby:pthread_mutex_lock");
373 pthread_mutex_unlock(&
instance->mutex);
379 instance->async_call_args = (
void*)
"rubyReady";
389 static int initialized = 0;
396 fprintf(stderr,
"pepper_ruby:pthread_create: %s\n",
strerror(
err));
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));
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) {
693 const char *
const path = (
const char*)
instance->async_call_args;
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;
746 instance->async_call_args = (
void*)path;
750 perror(
"pepper-ruby:pthread_cond_wait");
753 if (
instance->async_call_result.as_int != PP_OK) {
754 fprintf(stderr,
"Failed to open URL: %d: %s\n",
755 instance->async_call_result.as_int, path);
762 perror(
"pepper-ruby:pthread_cond_wait");
765 return instance->async_call_result.as_int == PP_OK;
777 const char *
const path = (
const char*)
instance->async_call_args;
791 if (
result != PP_OK_COMPLETIONPENDING) {
826 const char *real_path;
828 if (path[0] !=
'.' || path[1] !=
'/') path += 2;
832 instance->async_call_args = (
void*)path;
836 perror(
"pepper-ruby:pthread_cond_wait");
839 if (
instance->async_call_result.as_int != PP_OK) {
840 fprintf(stderr,
"Failed to open URL: %d: %s\n",
841 instance->async_call_result.as_int, path);
848 perror(
"pepper-ruby:pthread_cond_wait");
851 if (
instance->async_call_result.as_int != PP_OK)
return 0;
856 perror(
"pepper-ruby:pthread_cond_wait");
864 extern void*
rb_compile_cstr(
const char *
f,
const char *s,
int len,
int line);
static void load_file_read_contents_callback(void *data, int result)
static int pruby_init(void)
RUBY_EXTERN VALUE rb_cData
int ruby_cleanup(volatile int ex)
Destructs the VM.
static const rb_data_type_t pepper_instance_data_type
static void Instance_DidChangeFocus(PP_Instance instance, PP_Bool has_focus)
Notification that the given NaCl module has gained or lost focus.
size_t strlen(const char *)
int pruby_unregister_instance(PP_Instance instance)
if(dispIdMember==DISPID_VALUE)
static PPB_URLResponseInfo * response_interface
#define TypedData_Get_Struct(obj, type, data_type, sval)
struct PepperInstance * pruby_register_instance(PP_Instance instance)
VALUE rb_str_concat(VALUE, VALUE)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define RUBY_MARK_LEAVE(msg)
static void init_loadpath(void)
static void * pruby_eval(void *data)
static PP_Instance current_instance
static struct PP_Var pruby_obj_to_var(volatile VALUE obj)
PP_EXPORT const void * PPP_GetInterface(const char *interface_name)
Returns an interface pointer for the interface of the given name, or NULL if the interface is not sup...
static void Instance_DidChangeView(PP_Instance instance, PP_Resource view_resource)
Called when the position, the size, or the clip rect of the element in the browser that corresponds t...
void * rb_load_file(const char *path)
void pruby_async_return_str(void *data, const char *result)
static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance, PP_Resource url_loader)
Handler that gets called after a full-frame module is instantiated based on registered MIME types...
void ruby_incpush(const char *)
VALUE rb_str_buf_cat(VALUE, const char *, long)
#define RB_TYPE_P(obj, type)
int pruby_var_equal_to_cstr_p(struct PP_Var lhs, const char *rhs)
static VALUE init_libraries_internal(VALUE unused)
static PPB_Messaging * messaging_interface
RUBY_EXTERN char * strstr(const char *, const char *)
VALUE rb_obj_as_string(VALUE)
PP_EXPORT void PPP_ShutdownModule()
Called before the plugin module is unloaded.
static struct PP_Var pruby_str_to_var(volatile VALUE str)
static void inst_mark(void *const ptr)
#define RUBY_MARK_ENTER(msg)
void rb_gc_register_mark_object(VALUE obj)
struct PepperInstance * pruby_get_instance(PP_Instance instance)
NODE * rb_compile_cstr(const char *f, const char *s, int len, int line)
static char * pruby_var_to_cstr(struct PP_Var var)
Returns a mutable C string contained in the var or NULL if var is not string.
static VALUE instance_table
static PP_Module module_id
VALUE rb_hash_delete(VALUE hash, VALUE key)
static struct st_table * instance_data
static size_t inst_memsize(void *const ptr)
static PPB_Core * core_interface
static PPB_FileRef * fileref_interface
static int init_libraries_if_necessary(void)
void pruby_post_value(void *data)
int memcmp(const void *s1, const void *s2, size_t len)
PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id, PPB_GetInterface get_browser_interface)
Entry points for the module.
#define GET_PEPPER_INSTANCE()
union PepperInstance::@92 async_call_result
void rb_set_errinfo(VALUE err)
static struct PP_Var pruby_cstr_to_var(const char *str)
Creates a new string PP_Var from C string.
VALUE rb_hash_aref(VALUE hash, VALUE key)
static void Instance_DidDestroy(PP_Instance instance)
Called when the NaCl module is destroyed.
VALUE ruby_eval_string_from_file_protect(const char *str, const char *filename, int *state)
RUBY_EXTERN char * strerror(int)
void pruby_post_cstr(void *data)
int pruby_var_prefixed_p(struct PP_Var var, const char *prefix)
static PPB_URLRequestInfo * request_interface
static void pruby_file_fetch_check_response(void *data, int32_t unused)
#define RUBY_MARK_UNLESS_NULL(ptr)
static void * init_libraries(void *data)
#define TypedData_Make_Struct(klass, type, data_type, sval)
#define RUBY_INIT_STACK
A convenience macro to call ruby_init_stack().
int rb_file_load_ok(const char *path)
static void load_ok_internal(void *data, int32_t unused)
void Messaging_HandleMessage(PP_Instance instance, struct PP_Var var_message)
Handler for messages coming in from the browser via postMessage.
static void inst_free(void *const ptr)
static PPB_Var * var_interface
void pruby_async_return_value(void *data, VALUE value)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
static PP_Bool Instance_DidCreate(PP_Instance instance, uint32_t argc, const char *argn[], const char *argv[])
Called when the NaCl module is instantiated on the web page.
static void load_file_internal(void *data, int32_t unused)
static void load_file_read_contents(void *data, int result)
VALUE rb_usascii_str_new_cstr(const char *)
void pruby_async_return_int(void *data, int32_t result)
VALUE rb_str_new(const char *, long)
static PPB_URLLoader * loader_interface