11 #include <sys/mount.h> 14 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_module.h" 16 #include "ppapi/c/pp_var.h" 17 #include "ppapi/c/ppb.h" 18 #include "ppapi/c/ppb_core.h" 19 #include "ppapi/c/ppb_file_ref.h" 20 #include "ppapi/c/ppb_instance.h" 21 #include "ppapi/c/ppb_messaging.h" 22 #include "ppapi/c/ppb_url_loader.h" 23 #include "ppapi/c/ppb_url_request_info.h" 24 #include "ppapi/c/ppb_url_response_info.h" 25 #include "ppapi/c/ppb_var.h" 26 #include "ppapi/c/ppp.h" 27 #include "ppapi/c/ppp_instance.h" 28 #include "ppapi/c/ppp_messaging.h" 29 #include "nacl_io/nacl_io.h" 36 #ifdef HAVE_STRUCT_PPB_CORE 37 typedef struct PPB_Core PPB_Core;
39 #ifdef HAVE_STRUCT_PPB_MESSAGING 40 typedef struct PPB_Messaging PPB_Messaging;
42 #ifdef HAVE_STRUCT_PPB_VAR 43 typedef struct PPB_Var PPB_Var;
45 #ifdef HAVE_STRUCT_PPB_URLLOADER 46 typedef struct PPB_URLLoader PPB_URLLoader;
48 #ifdef HAVE_STRUCT_PPB_URLREQUESTINFO 49 typedef struct PPB_URLRequestInfo PPB_URLRequestInfo;
51 #ifdef HAVE_STRUCT_PPB_URLRESPONSEINFO 52 typedef struct PPB_URLResponseInfo PPB_URLResponseInfo;
54 #ifdef HAVE_STRUCT_PPP_INSTANCE 55 typedef struct PPP_Instance PPP_Instance;
116 #define GET_PEPPER_INSTANCE() (pruby_get_instance(current_instance)) 129 pthread_cond_init(&data->
cond,
NULL);
164 return sizeof(*inst);
176 if (pthread_cond_signal(&instance->
cond)) {
177 perror(
"pepper-ruby:pthread_cond_signal");
187 if (pthread_cond_signal(&instance->
cond)) {
188 perror(
"pepper-ruby:pthread_cond_signal");
198 if (pthread_cond_signal(&instance->
cond)) {
199 perror(
"pepper-ruby:pthread_cond_signal");
216 #ifndef PPB_VAR_INTERFACE_1_1 219 return PP_MakeUndefined();
242 char* c_str = (
char*)
malloc(len + 1);
243 memcpy(c_str, var_c_str, len);
255 fprintf(stderr,
"[BUG] Unexpected object type: %x\n",
TYPE(str));
258 #ifndef PPB_VAR_INTERFACE_1_1 265 return PP_MakeUndefined();
271 static const char*
const error =
272 "throw 'Failed to convert the result to a JavaScript object';";
291 const char*
const cstr =
var_interface->VarToUtf8(lhs, &len);
292 return strncmp(cstr, rhs, len) == 0;
304 const char*
const cstr =
var_interface->VarToUtf8(var, &len);
305 const size_t prefix_len =
strlen(prefix);
306 return len >= prefix_len &&
memcmp(cstr, prefix, len) == 0;
371 if (pthread_mutex_lock(&instance->
mutex)) {
372 perror(
"pepper-ruby:pthread_mutex_lock");
376 pthread_mutex_unlock(&instance->
mutex);
392 static int initialized = 0;
399 fprintf(stderr,
"pepper_ruby:pthread_create: %s\n",
strerror(err));
402 pthread_detach(instance->
th);
409 int fd2 = open(path, flags);
414 if (
dup2(fd2, fd) < 0) {
419 perror(
"close old fd");
453 if (pthread_mutex_lock(&instance->
mutex)) {
454 perror(
"pepper-ruby:pthread_mutex_lock");
459 pthread_mutex_unlock(&instance->
mutex);
516 if (mount(
"",
"/dev2",
"dev", 0,
"")) {
520 if (
reopen_fd(0,
"/dev2/stdin", O_RDONLY) < 0) {
521 perror(
"reopen stdin");
524 if (
reopen_fd(1,
"/dev2/stdout", O_WRONLY) < 0) {
525 perror(
"reopen stdout");
528 if (
reopen_fd(2,
"/dev2/console1", O_WRONLY) < 0) {
529 perror(
"reopen stderr");
535 if (mount(
"/lib",
"/lib",
"httpfs",
536 0,
"allow_cross_origin_requests=false")) {
537 perror(
"mount httpfs");
569 #ifndef PPP_INSTANCE_INTERFACE_1_1 572 const struct PP_Rect* position,
573 const struct PP_Rect* clip)
642 size_t message_len =
strlen(message);
649 #define EVAL_PREFIX_LEN 5 654 fprintf(stderr,
"pepper_ruby:pthread_create: %s\n",
strerror(err));
657 pthread_detach(instance_data->
th);
695 return pruby_init() ? PP_ERROR_FAILED : PP_OK;
704 PP_EXPORT
const void*
707 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) {
708 static PPP_Instance instance_interface = {
715 return &instance_interface;
716 }
else if (strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0) {
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)
static PPB_URLResponseInfo * response_interface
#define TypedData_Get_Struct(obj, type, data_type, sval)
struct PepperInstance * pruby_register_instance(PP_Instance instance)
if(len<=MAX_WORD_LENGTH &&len >=MIN_WORD_LENGTH)
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...
void pruby_async_return_str(void *data, const char *result)
static void Instance_DidChangeView(PP_Instance instance, const struct PP_Rect *position, const struct PP_Rect *clip)
Called when the position, the size, or the clip rect of the element in the browser that corresponds t...
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 *)
#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
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
RUBY_EXTERN char * strstr(const char *, const char *)
VALUE rb_obj_as_string(VALUE)
PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id, PPB_GetInterface a_get_browser_interface)
Entry points for the module.
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)
static int reopen_fd(int fd, const char *path, int flags)
struct PepperInstance * pruby_get_instance(PP_Instance instance)
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
union PepperInstance::@146 async_call_result
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)
register unsigned int len
#define GET_PEPPER_INSTANCE()
void rb_set_errinfo(VALUE err)
PP_EXPORT void PPP_ShutdownModule(void)
Called before the plugin module is unloaded.
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
#define RUBY_MARK_UNLESS_NULL(ptr)
static void * init_libraries(void *data)
#define TypedData_Make_Struct(klass, type, data_type, sval)
static PPB_GetInterface get_browser_interface
#define RUBY_INIT_STACK
A convenience macro to call ruby_init_stack().
RUBY_EXTERN int dup2(int, int)
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)
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.
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