Ruby 2.0.0p247(2013-06-27revision41674)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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 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 | 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_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

## Macro Definition Documentation

#define EVAL_PREFIX_LEN 5

Referenced by Messaging_HandleMessage().

#define GET_PEPPER_INSTANCE | ( | ) |  | (pruby_get_instance(current_instance))

Definition at line 113 of file pepper_main.c.

Referenced by init_libraries_if_necessary(), Messaging_HandleMessage(), rb_file_load_ok(), and rb_load_file().

## Function Documentation

static void* init_libraries | ( | void * | data) |  |
| static

Definition at line 362 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 int init_libraries_if_necessary | ( | void | ) |  |
| static

Definition at line 387 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().

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

Definition at line 140 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 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] | 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 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] | 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 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] | 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.

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] | instance | The 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] | instance | The identifier of the instance representing this NaCl module.
  [in] | url_loader | A 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

Definition at line 773 of file pepper_main.c.

References PepperInstance::async_call_args, PepperInstance::instance, loader_interface, pruby_async_return_int(), pruby_cstr_to_var(), request_interface, result, and PepperInstance::url_loader.

Referenced by rb_load_file().

static void load_file_read_contents | ( | void * | data,
|  | int | result
| ) |  |
| static

Definition at line 815 of file pepper_main.c.

References PepperInstance::as_value, PepperInstance::async_call_result, PepperInstance::buf, PepperInstance::instance, load_file_read_contents_callback(), loader_interface, rb_str_new(), and PepperInstance::url_loader.

Referenced by rb_load_file().

static void load_file_read_contents_callback | ( | void * | data,
|  | int | result
| ) |  |
| static

Definition at line 797 of file pepper_main.c.

References PepperInstance::as_value, PepperInstance::async_call_result, PepperInstance::buf, PepperInstance::instance, INT2FIX, loader_interface, pruby_async_return_value(), rb_str_buf_cat(), and PepperInstance::url_loader.

Referenced by load_file_read_contents().

static void load_ok_internal | ( | void * | data,
|  | int32_t | unused
| ) |  |
| static

Definition at line 689 of file pepper_main.c.

References PepperInstance::async_call_args, PepperInstance::instance, loader_interface, pruby_async_return_int(), pruby_cstr_to_var(), request_interface, result, and PepperInstance::url_loader.

Referenced by rb_file_load_ok().

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] | instance | The instance ID.
  [in] | message | The 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_name | name 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_id | Module ID
  [in] | get_browser_interface | Pointer 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
| ) |  |

Definition at line 168 of file pepper_main.c.

References PepperInstance::as_int, PepperInstance::async_call_result, PepperInstance::cond, PepperInstance::instance, and result.

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

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

Definition at line 179 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 190 of file pepper_main.c.

References PepperInstance::as_value, PepperInstance::async_call_result, PepperInstance::cond, and PepperInstance::instance.

Referenced by load_file_read_contents_callback().

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] | str | C 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

Definition at line 422 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().

static void pruby_file_fetch_check_response | ( | void * | data,
|  | int32_t | unused
| ) |  |
| static

Definition at line 713 of file pepper_main.c.

References PepperInstance::instance, loader_interface, messaging_interface, pruby_async_return_int(), pruby_cstr_to_var(), response_interface, and PepperInstance::url_loader.

Referenced by rb_file_load_ok(), and rb_load_file().

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

Definition at line 405 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 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) |  |

Definition at line 315 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 327 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 116 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 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] | var | PP_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) |  |

Definition at line 741 of file pepper_main.c.

References PepperInstance::as_int, PepperInstance::async_call_args, PepperInstance::async_call_result, PepperInstance::cond, core_interface, GET_PEPPER_INSTANCE, PepperInstance::instance, load_ok_internal(), PepperInstance::mutex, and pruby_file_fetch_check_response().

void* rb_load_file | ( | const char * | path) |  |

Definition at line 824 of file pepper_main.c.

References PepperInstance::as_int, PepperInstance::as_value, PepperInstance::async_call_args, PepperInstance::async_call_result, PepperInstance::cond, core_interface, f, FIXNUM_P, GET_PEPPER_INSTANCE, PepperInstance::instance, load_file_internal(), load_file_read_contents(), PepperInstance::mutex, pruby_file_fetch_check_response(), rb_compile_cstr(), RB_TYPE_P, RSTRING_LEN, RSTRING_PTR, and T_STRING.

## Variable Documentation

PPB_Core* core_interface = NULL
| static

Definition at line 57 of file pepper_main.c.

Referenced by init_libraries(), Instance_DidDestroy(), PPP_InitializeModule(), pruby_eval(), rb_file_load_ok(), and rb_load_file().

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

Definition at line 66 of file pepper_main.c.

Referenced by pruby_get_instance(), pruby_init(), pruby_register_instance(), and pruby_unregister_instance().

PPB_URLLoader* loader_interface = NULL
| static

Definition at line 60 of file pepper_main.c.

Referenced by load_file_internal(), load_file_read_contents(), load_file_read_contents_callback(), load_ok_internal(), PPP_InitializeModule(), and pruby_file_fetch_check_response().

PPB_Messaging* messaging_interface = NULL
| static

Definition at line 58 of file pepper_main.c.

Referenced by PPP_GetInterface(), PPP_InitializeModule(), pruby_file_fetch_check_response(), pruby_post_cstr(), and pruby_post_value().

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",
{ inst_mark, inst_free, inst_memsize }
}

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

Definition at line 59 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().