Ruby  2.0.0p353(2013-11-22revision43784)
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 <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 "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 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, PP_Resource view_resource)
 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 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 ()
 Called before the plugin module is unloaded. More...
 
static void load_ok_internal (void *data, int32_t unused)
 
static void pruby_file_fetch_check_response (void *data, int32_t unused)
 
int rb_file_load_ok (const char *path)
 
static void load_file_internal (void *data, int32_t unused)
 
static void load_file_read_contents_callback (void *data, int result)
 
static void load_file_read_contents (void *data, int result)
 
void * rb_load_file (const char *path)
 

Variables

static PP_Module module_id = 0
 
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

#define EVAL_PREFIX_LEN   5

Referenced by Messaging_HandleMessage().

#define GET_PEPPER_INSTANCE ( )    (pruby_get_instance(current_instance))

Function Documentation

static void* init_libraries ( void *  data)
static
static int init_libraries_if_necessary ( void  )
static
static VALUE init_libraries_internal ( VALUE  unused)
static

Definition at line 350 of file pepper_main.c.

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

Referenced by init_libraries().

static void init_loadpath ( void  )
static

Definition at line 342 of file pepper_main.c.

References ruby_incpush(), and RUBY_PLATFORM.

Referenced by init_libraries_internal().

static void inst_free ( void *const  ptr)
static

Definition at line 151 of file pepper_main.c.

References ruby_xfree().

static void inst_mark ( void *const  ptr)
static
static size_t inst_memsize ( void *const  ptr)
static

Definition at line 157 of file pepper_main.c.

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 552 of file pepper_main.c.

Referenced by PPP_GetInterface().

static void Instance_DidChangeView ( PP_Instance  instance,
PP_Resource  view_resource 
)
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 529 of file pepper_main.c.

Referenced by PPP_GetInterface().

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 487 of file pepper_main.c.

References current_instance, init_libraries_if_necessary(), PepperInstance::instance, and pruby_register_instance().

Referenced by PPP_GetInterface().

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 502 of file pepper_main.c.

References core_interface, pruby_get_instance(), pruby_unregister_instance(), and PepperInstance::url_loader.

Referenced by PPP_GetInterface().

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 567 of file pepper_main.c.

Referenced by PPP_GetInterface().

static void load_file_internal ( void *  data,
int32_t  unused 
)
static
static void load_file_read_contents ( void *  data,
int  result 
)
static
static void load_file_read_contents_callback ( void *  data,
int  result 
)
static
static void load_ok_internal ( void *  data,
int32_t  unused 
)
static
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 590 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().

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 655 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  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 621 of file pepper_main.c.

References core_interface, fileref_interface, loader_interface, messaging_interface, module_id, NULL, pruby_init(), request_interface, response_interface, and var_interface.

PP_EXPORT void PPP_ShutdownModule ( )

Called before the plugin module is unloaded.

Definition at line 679 of file pepper_main.c.

References ruby_cleanup().

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)
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 211 of file pepper_main.c.

References module_id, NULL, strlen(), and var_interface.

Referenced by load_file_internal(), load_ok_internal(), pruby_file_fetch_check_response(), pruby_obj_to_var(), and pruby_post_cstr().

static void* pruby_eval ( void *  data)
static
static void pruby_file_fetch_check_response ( void *  data,
int32_t  unused 
)
static
struct PepperInstance* pruby_get_instance ( PP_Instance  instance)

Definition at line 100 of file pepper_main.c.

References instance_table, INT2FIX, NULL, rb_hash_aref(), RTEST, and TypedData_Get_Struct.

Referenced by Instance_DidDestroy().

static int pruby_init ( void  )
static
static struct PP_Var pruby_obj_to_var ( volatile VALUE  obj)
static

Definition at line 266 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)
void pruby_post_value ( void *  data)
struct PepperInstance* pruby_register_instance ( PP_Instance  instance)
static struct PP_Var pruby_str_to_var ( volatile VALUE  str)
static

Definition at line 249 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 133 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 281 of file pepper_main.c.

References NULL, and var_interface.

int pruby_var_prefixed_p ( struct PP_Var  var,
const char *  prefix 
)

Definition at line 294 of file pepper_main.c.

References memcmp(), NULL, strlen(), and var_interface.

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 233 of file pepper_main.c.

References malloc, NULL, and var_interface.

Referenced by Messaging_HandleMessage().

int rb_file_load_ok ( const char *  path)
void* rb_load_file ( const char *  path)

Variable Documentation

PPB_Core* core_interface = NULL
static
PP_Instance current_instance = 0
static

Definition at line 68 of file pepper_main.c.

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

PPB_FileRef* fileref_interface = NULL
static

Definition at line 63 of file pepper_main.c.

Referenced by PPP_InitializeModule().

struct st_table* instance_data = NULL
static

Definition at line 64 of file pepper_main.c.

VALUE instance_table = Qundef
static
PPB_URLLoader* loader_interface = NULL
static
PPB_Messaging* messaging_interface = NULL
static
PP_Module module_id = 0
static

Definition at line 56 of file pepper_main.c.

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

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

Definition at line 77 of file pepper_main.c.

PPB_URLRequestInfo* request_interface = NULL
static

Definition at line 61 of file pepper_main.c.

Referenced by load_file_internal(), load_ok_internal(), and PPP_InitializeModule().

PPB_URLResponseInfo* response_interface = NULL
static

Definition at line 62 of file pepper_main.c.

Referenced by PPP_InitializeModule(), and pruby_file_fetch_check_response().

PPB_Var* var_interface = NULL
static