Ruby  2.4.2p198(2017-09-14revision59899)
Data Structures | Macros | Functions | Variables
pepper_main.c File Reference
#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"
Include dependency graph for pepper_main.c:

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 PepperInstancepruby_get_instance (PP_Instance instance)
 
struct PepperInstancepruby_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_tableinstance_data = NULL
 
static VALUE instance_table = Qundef
 
static PP_Instance current_instance = 0
 
static const rb_data_type_t pepper_instance_data_type
 

Macro Definition Documentation

◆ EVAL_PREFIX_LEN

#define EVAL_PREFIX_LEN   5

Referenced by Messaging_HandleMessage().

◆ GET_PEPPER_INSTANCE

#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().

Function Documentation

◆ init_libraries()

static void* init_libraries ( void *  data)
static

◆ init_libraries_if_necessary()

static int init_libraries_if_necessary ( void  )
static

◆ init_libraries_internal()

static VALUE init_libraries_internal ( VALUE  unused)
static

Definition at line 353 of file pepper_main.c.

References Init_enc(), Init_ext(), init_loadpath(), and Qnil.

Referenced by init_libraries().

◆ init_loadpath()

static void init_loadpath ( void  )
static

Definition at line 345 of file pepper_main.c.

References ruby_incpush(), and RUBY_PLATFORM.

Referenced by init_libraries_internal().

◆ inst_free()

static void inst_free ( void *const  ptr)
static

Definition at line 154 of file pepper_main.c.

References ruby_xfree().

◆ inst_mark()

static void inst_mark ( void *const  ptr)
static

◆ inst_memsize()

static size_t inst_memsize ( void *const  ptr)
static

Definition at line 160 of file pepper_main.c.

◆ Instance_DidChangeFocus()

static void Instance_DidChangeFocus ( PP_Instance  instance,
PP_Bool  has_focus 
)
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.

Parameters
[in]instanceThe identifier of the instance representing this NaCl module.
[in]has_focusIndicates whether this NaCl module gained or lost event focus.

Definition at line 601 of file pepper_main.c.

Referenced by PPP_GetInterface().

◆ Instance_DidChangeView()

static void Instance_DidChangeView ( PP_Instance  instance,
const struct PP_Rect *  position,
const struct PP_Rect *  clip 
)
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.

Parameters
[in]instanceThe identifier of the instance representing this NaCl module.
[in]positionThe 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]clipThe 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().

◆ Instance_DidCreate()

static PP_Bool Instance_DidCreate ( PP_Instance  instance,
uint32_t  argc,
const char *  argn[],
const char *  argv[] 
)
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.

Parameters
[in]instanceThe identifier of the new instance representing this NaCl module.
[in]argcThe number of arguments contained in argn and argv.
[in]argnAn 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]argvAn 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.
Returns
PP_TRUE on success.

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().

◆ Instance_DidDestroy()

static void Instance_DidDestroy ( PP_Instance  instance)
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.

Parameters
[in]instanceThe 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().

◆ Instance_HandleDocumentLoad()

static PP_Bool Instance_HandleDocumentLoad ( PP_Instance  instance,
PP_Resource  url_loader 
)
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.

Parameters
[in]instanceThe identifier of the instance representing this NaCl module.
[in]url_loaderA PP_Resource an open PPB_URLLoader instance.
Returns
PP_FALSE.

Definition at line 616 of file pepper_main.c.

Referenced by PPP_GetInterface().

◆ Messaging_HandleMessage()

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.

Parameters
[in]instanceThe instance ID.
[in]messageThe 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().

◆ PPP_GetInterface()

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.

Parameters
[in]interface_namename of the interface
Returns
pointer to 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.

◆ PPP_InitializeModule()

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.

Parameters
[in]a_module_idModule ID
[in]get_browser_interfacePointer to PPB_GetInterface
Returns
PP_OK on success, any other value on failure.

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.

◆ PPP_ShutdownModule()

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().

◆ pruby_async_return_int()

void pruby_async_return_int ( void *  data,
int32_t  result 
)

◆ pruby_async_return_str()

void pruby_async_return_str ( void *  data,
const char *  result 
)

◆ pruby_async_return_value()

void pruby_async_return_value ( void *  data,
VALUE  value 
)

◆ pruby_cstr_to_var()

static struct PP_Var pruby_cstr_to_var ( const char *  str)
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.

Parameters
[in]strC string to be converted to PP_Var
Returns
PP_Var containing string.

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().

◆ pruby_eval()

static void* pruby_eval ( void *  data)
static

◆ pruby_get_instance()

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().

◆ pruby_init()

static int pruby_init ( void  )
static

◆ pruby_obj_to_var()

static struct PP_Var pruby_obj_to_var ( volatile VALUE  obj)
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().

◆ pruby_post_cstr()

void pruby_post_cstr ( void *  data)

◆ pruby_post_value()

void pruby_post_value ( void *  data)

◆ pruby_register_instance()

struct PepperInstance* pruby_register_instance ( PP_Instance  instance)

◆ pruby_str_to_var()

static struct PP_Var pruby_str_to_var ( volatile VALUE  str)
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().

◆ pruby_unregister_instance()

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().

◆ pruby_var_equal_to_cstr_p()

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.

◆ pruby_var_prefixed_p()

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.

◆ pruby_var_to_cstr()

static char* pruby_var_to_cstr ( struct PP_Var  var)
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.

Parameters
[in]varPP_Var containing string.
Returns
a mutable C string representation of var.
Note
The caller is responsible for freeing the returned string.

Definition at line 236 of file pepper_main.c.

References len, malloc, memcpy, NULL, and var_interface.

Referenced by Messaging_HandleMessage().

◆ reopen_fd()

static int reopen_fd ( int  fd,
const char *  path,
int  flags 
)
static

Definition at line 408 of file pepper_main.c.

References dup2().

Referenced by Instance_DidCreate().

Variable Documentation

◆ core_interface

PPB_Core* core_interface = NULL
static

◆ current_instance

PP_Instance current_instance = 0
static

Definition at line 71 of file pepper_main.c.

Referenced by init_libraries(), Instance_DidCreate(), and Messaging_HandleMessage().

◆ fileref_interface

PPB_FileRef* fileref_interface = NULL
static

Definition at line 66 of file pepper_main.c.

Referenced by PPP_InitializeModule().

◆ get_browser_interface

PPB_GetInterface get_browser_interface = NULL
static

Definition at line 59 of file pepper_main.c.

Referenced by Instance_DidCreate(), and PPP_InitializeModule().

◆ instance_data

struct st_table* instance_data = NULL
static

Definition at line 67 of file pepper_main.c.

◆ instance_table

VALUE instance_table = Qundef
static

◆ loader_interface

PPB_URLLoader* loader_interface = NULL
static

Definition at line 63 of file pepper_main.c.

Referenced by PPP_InitializeModule().

◆ messaging_interface

PPB_Messaging* messaging_interface = NULL
static

◆ module_id

PP_Module module_id = 0
static

Definition at line 58 of file pepper_main.c.

Referenced by PPP_InitializeModule(), pruby_cstr_to_var(), and pruby_str_to_var().

◆ pepper_instance_data_type

const rb_data_type_t pepper_instance_data_type
static
Initial value:
= {
"PepperInstance",
}
static void inst_mark(void *const ptr)
Definition: pepper_main.c:143
static size_t inst_memsize(void *const ptr)
Definition: pepper_main.c:160
static void inst_free(void *const ptr)
Definition: pepper_main.c:154

Definition at line 80 of file pepper_main.c.

◆ request_interface

PPB_URLRequestInfo* request_interface = NULL
static

Definition at line 64 of file pepper_main.c.

Referenced by PPP_InitializeModule().

◆ response_interface

PPB_URLResponseInfo* response_interface = NULL
static

Definition at line 65 of file pepper_main.c.

Referenced by PPP_InitializeModule().

◆ var_interface

PPB_Var* var_interface = NULL
static