Ruby
2.4.2p198(2017-09-14revision59899)
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <fcntl.h>
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_module.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb.h"
#include "ppapi/c/ppb_core.h"
#include "ppapi/c/ppb_file_ref.h"
#include "ppapi/c/ppb_instance.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/c/ppb_url_loader.h"
#include "ppapi/c/ppb_url_request_info.h"
#include "ppapi/c/ppb_url_response_info.h"
#include "ppapi/c/ppb_var.h"
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppp_messaging.h"
#include "nacl_io/nacl_io.h"
#include "verconf.h"
#include "ruby/ruby.h"
#include "version.h"
#include "gc.h"
Go to the source code of this file.
Data Structures | |
struct | PepperInstance |
Macros | |
#define | GET_PEPPER_INSTANCE() (pruby_get_instance(current_instance)) |
#define | EVAL_PREFIX_LEN 5 |
Functions | |
static void | inst_mark (void *const ptr) |
static void | inst_free (void *const ptr) |
static size_t | inst_memsize (void *const ptr) |
struct PepperInstance * | pruby_get_instance (PP_Instance instance) |
struct PepperInstance * | pruby_register_instance (PP_Instance instance) |
int | pruby_unregister_instance (PP_Instance instance) |
void | pruby_async_return_int (void *data, int32_t result) |
void | pruby_async_return_str (void *data, const char *result) |
void | pruby_async_return_value (void *data, VALUE value) |
static struct PP_Var | pruby_cstr_to_var (const char *str) |
Creates a new string PP_Var from C string. More... | |
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. More... | |
static struct PP_Var | pruby_str_to_var (volatile VALUE str) |
static struct PP_Var | pruby_obj_to_var (volatile VALUE obj) |
int | pruby_var_equal_to_cstr_p (struct PP_Var lhs, const char *rhs) |
int | pruby_var_prefixed_p (struct PP_Var var, const char *prefix) |
void | pruby_post_cstr (void *data) |
void | pruby_post_value (void *data) |
static void | init_loadpath (void) |
static VALUE | init_libraries_internal (VALUE unused) |
static void * | init_libraries (void *data) |
static int | init_libraries_if_necessary (void) |
static int | reopen_fd (int fd, const char *path, int flags) |
static int | pruby_init (void) |
static void * | pruby_eval (void *data) |
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. More... | |
static void | Instance_DidDestroy (PP_Instance instance) |
Called when the NaCl module is destroyed. More... | |
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 to this NaCl module has changed. More... | |
static void | Instance_DidChangeFocus (PP_Instance instance, PP_Bool has_focus) |
Notification that the given NaCl module has gained or lost focus. More... | |
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. More... | |
void | Messaging_HandleMessage (PP_Instance instance, struct PP_Var var_message) |
Handler for messages coming in from the browser via postMessage. More... | |
PP_EXPORT int32_t | PPP_InitializeModule (PP_Module a_module_id, PPB_GetInterface a_get_browser_interface) |
Entry points for the module. More... | |
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 supported. More... | |
PP_EXPORT void | PPP_ShutdownModule (void) |
Called before the plugin module is unloaded. More... | |
Variables | |
static PP_Module | module_id = 0 |
static PPB_GetInterface | get_browser_interface = NULL |
static PPB_Core * | core_interface = NULL |
static PPB_Messaging * | messaging_interface = NULL |
static PPB_Var * | var_interface = NULL |
static PPB_URLLoader * | loader_interface = NULL |
static PPB_URLRequestInfo * | request_interface = NULL |
static PPB_URLResponseInfo * | response_interface = NULL |
static PPB_FileRef * | fileref_interface = NULL |
static struct st_table * | instance_data = NULL |
static VALUE | instance_table = Qundef |
static PP_Instance | current_instance = 0 |
static const rb_data_type_t | pepper_instance_data_type |
#define EVAL_PREFIX_LEN 5 |
Referenced by Messaging_HandleMessage().
#define GET_PEPPER_INSTANCE | ( | ) | (pruby_get_instance(current_instance)) |
Definition at line 116 of file pepper_main.c.
Referenced by init_libraries_if_necessary(), and Messaging_HandleMessage().
|
static |
Definition at line 365 of file pepper_main.c.
References PepperInstance::async_call_args, core_interface, current_instance, err, init_libraries_internal(), PepperInstance::instance, PepperInstance::mutex, NULL, pruby_post_cstr(), Qnil, rb_errinfo(), rb_obj_as_string(), and rb_protect().
Referenced by init_libraries_if_necessary().
|
static |
Definition at line 390 of file pepper_main.c.
References err, EXIT_FAILURE, GET_PEPPER_INSTANCE, init_libraries(), PepperInstance::instance, NULL, strerror(), and PepperInstance::th.
Referenced by Instance_DidCreate().
Definition at line 353 of file pepper_main.c.
References Init_enc(), Init_ext(), init_loadpath(), and Qnil.
Referenced by init_libraries().
|
static |
Definition at line 345 of file pepper_main.c.
References ruby_incpush(), and RUBY_PLATFORM.
Referenced by init_libraries_internal().
|
static |
Definition at line 154 of file pepper_main.c.
References ruby_xfree().
|
static |
Definition at line 143 of file pepper_main.c.
References PepperInstance::as_value, PepperInstance::async_call_result, RUBY_MARK_ENTER, RUBY_MARK_LEAVE, and RUBY_MARK_UNLESS_NULL.
|
static |
Definition at line 160 of file pepper_main.c.
|
static |
Notification that the given NaCl module has gained or lost focus.
Having focus means that keyboard events will be sent to the NaCl module represented by instance. A NaCl module's default condition is that it will not have focus.
Note: clicks on NaCl modules will give focus only if you handle the click event. You signal if you handled it by returning true from HandleInputEvent. Otherwise the browser will bubble the event and give focus to the element on the page that actually did end up consuming it. If you're not getting focus, check to make sure you're returning true from the mouse click in HandleInputEvent.
[in] | instance | The identifier of the instance representing this NaCl module. |
[in] | has_focus | Indicates whether this NaCl module gained or lost event focus. |
Definition at line 601 of file pepper_main.c.
Referenced by PPP_GetInterface().
|
static |
Called when the position, the size, or the clip rect of the element in the browser that corresponds to this NaCl module has changed.
[in] | instance | The identifier of the instance representing this NaCl module. |
[in] | position | The location on the page of this NaCl module. This is relative to the top left corner of the viewport, which changes as the page is scrolled. |
[in] | clip | The visible region of the NaCl module. This is relative to the top left of the plugin's coordinate system (not the page). If the plugin is invisible, clip will be (0, 0, 0, 0). |
Definition at line 571 of file pepper_main.c.
References PepperInstance::instance.
Referenced by PPP_GetInterface().
|
static |
Called when the NaCl module is instantiated on the web page.
The identifier of the new instance will be passed in as the first argument (this value is generated by the browser and is an opaque handle). This is called for each instantiation of the NaCl module, which is each time the <embed> tag for this module is encountered.
If this function reports a failure (by returning PP_FALSE), the NaCl module will be deleted and DidDestroy will be called.
[in] | instance | The identifier of the new instance representing this NaCl module. |
[in] | argc | The number of arguments contained in argn and argv. |
[in] | argn | An array of argument names. These argument names are supplied in the <embed> tag, for example: <embed id="nacl_module" dimensions="2"> will produce two arguments, one named "id" and one named "dimensions". |
[in] | argv | An array of argument values. These are the values of the arguments listed in the <embed> tag. In the above example, there will be two elements in this array, "nacl_module" and "2". The indices of these values match the indices of the corresponding names in argn. |
Definition at line 508 of file pepper_main.c.
References current_instance, get_browser_interface, init_libraries_if_necessary(), PepperInstance::instance, pruby_register_instance(), and reopen_fd().
Referenced by PPP_GetInterface().
|
static |
Called when the NaCl module is destroyed.
This will always be called, even if DidCreate returned failure. This routine should deallocate any data associated with the instance.
[in] | instance | The identifier of the instance representing this NaCl module. |
Definition at line 551 of file pepper_main.c.
References core_interface, pruby_get_instance(), pruby_unregister_instance(), and PepperInstance::url_loader.
Referenced by PPP_GetInterface().
|
static |
Handler that gets called after a full-frame module is instantiated based on registered MIME types.
This function is not called on NaCl modules. This function is essentially a place-holder for the required function pointer in the PPP_Instance structure.
[in] | instance | The identifier of the instance representing this NaCl module. |
[in] | url_loader | A PP_Resource an open PPB_URLLoader instance. |
Definition at line 616 of file pepper_main.c.
Referenced by PPP_GetInterface().
void Messaging_HandleMessage | ( | PP_Instance | instance, |
struct PP_Var | var_message | ||
) |
Handler for messages coming in from the browser via postMessage.
The var_message can contain anything: a JSON string; a string that encodes method names and arguments; etc. For example, you could use JSON.stringify in the browser to create a message that contains a method name and some parameters, something like this: var json_message = JSON.stringify({ "myMethod" : "3.14159" }); nacl_module.postMessage(json_message); On receipt of this message in var_message, you could parse the JSON to retrieve the method name, match it to a function call, and then call it with the parameter.
[in] | instance | The instance ID. |
[in] | message | The contents, copied by value, of the message sent from browser via postMessage. |
Definition at line 639 of file pepper_main.c.
References PepperInstance::async_call_args, current_instance, err, EVAL_PREFIX_LEN, EXIT_FAILURE, free(), GET_PEPPER_INSTANCE, PepperInstance::instance, NULL, pruby_eval(), pruby_var_to_cstr(), rb_str_new(), strerror(), strlen(), strstr(), and PepperInstance::th.
Referenced by PPP_GetInterface().
Returns an interface pointer for the interface of the given name, or NULL if the interface is not supported.
[in] | interface_name | name of the interface |
Definition at line 705 of file pepper_main.c.
References Instance_DidChangeFocus(), Instance_DidChangeView(), Instance_DidCreate(), Instance_DidDestroy(), Instance_HandleDocumentLoad(), Messaging_HandleMessage(), messaging_interface, and NULL.
PP_EXPORT int32_t PPP_InitializeModule | ( | PP_Module | a_module_id, |
PPB_GetInterface | a_get_browser_interface | ||
) |
Entry points for the module.
Initialize instance interface and scriptable object class.
[in] | a_module_id | Module ID |
[in] | get_browser_interface | Pointer to PPB_GetInterface |
Definition at line 670 of file pepper_main.c.
References core_interface, fileref_interface, get_browser_interface, loader_interface, messaging_interface, module_id, NULL, pruby_init(), request_interface, response_interface, and var_interface.
PP_EXPORT void PPP_ShutdownModule | ( | void | ) |
Called before the plugin module is unloaded.
Definition at line 729 of file pepper_main.c.
References ruby_cleanup().
void pruby_async_return_int | ( | void * | data, |
int32_t | result | ||
) |
Definition at line 171 of file pepper_main.c.
References PepperInstance::as_int, PepperInstance::async_call_result, PepperInstance::cond, PepperInstance::instance, and result.
void pruby_async_return_str | ( | void * | data, |
const char * | result | ||
) |
Definition at line 182 of file pepper_main.c.
References PepperInstance::as_str, PepperInstance::async_call_result, PepperInstance::cond, PepperInstance::instance, and result.
void pruby_async_return_value | ( | void * | data, |
VALUE | value | ||
) |
Definition at line 193 of file pepper_main.c.
References PepperInstance::as_value, PepperInstance::async_call_result, PepperInstance::cond, and PepperInstance::instance.
|
static |
Creates a new string PP_Var from C string.
The resulting object will be a refcounted string object. It will be AddRef()ed for the caller. When the caller is done with it, it should be Release()d.
[in] | str | C string to be converted to PP_Var |
Definition at line 214 of file pepper_main.c.
References module_id, NULL, strlen(), and var_interface.
Referenced by pruby_obj_to_var(), and pruby_post_cstr().
|
static |
Definition at line 443 of file pepper_main.c.
References PepperInstance::async_call_args, core_interface, if(), PepperInstance::instance, PepperInstance::mutex, NULL, pruby_post_value(), Qnil, rb_obj_as_string(), rb_set_errinfo(), rb_str_concat(), rb_usascii_str_new_cstr(), result, RSTRING_PTR, ruby_eval_string_from_file_protect(), and RUBY_INIT_STACK.
Referenced by Messaging_HandleMessage().
struct PepperInstance* pruby_get_instance | ( | PP_Instance | instance | ) |
Definition at line 103 of file pepper_main.c.
References instance_table, INT2FIX, NULL, rb_hash_aref(), RTEST, and TypedData_Get_Struct.
Referenced by Instance_DidDestroy().
|
static |
Definition at line 426 of file pepper_main.c.
References instance_table, rb_gc_register_mark_object(), rb_hash_new(), ruby_init(), and RUBY_INIT_STACK.
Referenced by PPP_InitializeModule().
|
static |
Definition at line 269 of file pepper_main.c.
References pruby_cstr_to_var(), pruby_str_to_var(), rb_obj_as_string(), and rb_protect().
Referenced by pruby_post_value().
void pruby_post_cstr | ( | void * | data | ) |
Definition at line 318 of file pepper_main.c.
References PepperInstance::async_call_args, PepperInstance::instance, messaging_interface, msg, and pruby_cstr_to_var().
Referenced by init_libraries().
void pruby_post_value | ( | void * | data | ) |
Definition at line 330 of file pepper_main.c.
References PepperInstance::async_call_args, PepperInstance::instance, messaging_interface, and pruby_obj_to_var().
Referenced by pruby_eval().
struct PepperInstance* pruby_register_instance | ( | PP_Instance | instance | ) |
Definition at line 119 of file pepper_main.c.
References PepperInstance::cond, PepperInstance::instance, instance_table, INT2FIX, PepperInstance::mutex, NULL, rb_cData, rb_hash_aset(), PepperInstance::self, TypedData_Make_Struct, and PepperInstance::url_loader.
Referenced by Instance_DidCreate().
|
static |
Definition at line 252 of file pepper_main.c.
References EXIT_FAILURE, module_id, NULL, RB_TYPE_P, RSTRING_LEN, RSTRING_PTR, T_STRING, TYPE, and var_interface.
Referenced by pruby_obj_to_var().
int pruby_unregister_instance | ( | PP_Instance | instance | ) |
Definition at line 136 of file pepper_main.c.
References instance_table, INT2FIX, rb_hash_delete(), and RTEST.
Referenced by Instance_DidDestroy().
int pruby_var_equal_to_cstr_p | ( | struct PP_Var | lhs, |
const char * | rhs | ||
) |
Definition at line 284 of file pepper_main.c.
References len, NULL, and var_interface.
int pruby_var_prefixed_p | ( | struct PP_Var | var, |
const char * | prefix | ||
) |
Definition at line 297 of file pepper_main.c.
References len, memcmp(), NULL, strlen(), and var_interface.
|
static |
Returns a mutable C string contained in the var or NULL if var is not string.
This makes a copy of the string in the var and adds a NULL terminator. Note that VarToUtf8() does not guarantee the NULL terminator on the returned string. See the comments for VarToUtf8() in ppapi/c/ppb_var.h for more info. The caller is responsible for freeing the returned memory.
[in] | var | PP_Var containing string. |
Definition at line 236 of file pepper_main.c.
References len, malloc, memcpy, NULL, and var_interface.
Referenced by Messaging_HandleMessage().
|
static |
Definition at line 408 of file pepper_main.c.
References dup2().
Referenced by Instance_DidCreate().
|
static |
Definition at line 60 of file pepper_main.c.
Referenced by init_libraries(), Instance_DidDestroy(), PPP_InitializeModule(), and pruby_eval().
|
static |
Definition at line 71 of file pepper_main.c.
Referenced by init_libraries(), Instance_DidCreate(), and Messaging_HandleMessage().
|
static |
Definition at line 66 of file pepper_main.c.
Referenced by PPP_InitializeModule().
|
static |
Definition at line 59 of file pepper_main.c.
Referenced by Instance_DidCreate(), and PPP_InitializeModule().
Definition at line 67 of file pepper_main.c.
Definition at line 69 of file pepper_main.c.
Referenced by pruby_get_instance(), pruby_init(), pruby_register_instance(), and pruby_unregister_instance().
|
static |
Definition at line 63 of file pepper_main.c.
Referenced by PPP_InitializeModule().
|
static |
Definition at line 61 of file pepper_main.c.
Referenced by PPP_GetInterface(), PPP_InitializeModule(), pruby_post_cstr(), and pruby_post_value().
|
static |
Definition at line 58 of file pepper_main.c.
Referenced by PPP_InitializeModule(), pruby_cstr_to_var(), and pruby_str_to_var().
|
static |
Definition at line 80 of file pepper_main.c.
|
static |
Definition at line 64 of file pepper_main.c.
Referenced by PPP_InitializeModule().
|
static |
Definition at line 65 of file pepper_main.c.
Referenced by PPP_InitializeModule().
|
static |
Definition at line 62 of file pepper_main.c.
Referenced by PPP_InitializeModule(), pruby_cstr_to_var(), pruby_str_to_var(), pruby_var_equal_to_cstr_p(), pruby_var_prefixed_p(), and pruby_var_to_cstr().