15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * This file defines three functions that your module must
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * implement to interact with the browser.
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#inline c
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_module.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/pp_stdint.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/ppb.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if __GNUC__ >= 4
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define PP_EXPORT __attribute__ ((visibility("default")))
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(_MSC_VER)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define PP_EXPORT __declspec(dllexport)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* {PENDING: undefine PP_EXPORT?} */
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* We don't want name mangling for these external functions.  We only need
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 'extern "C"' if we're compiling with a C++ compiler.
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef __cplusplus
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern "C" {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @addtogroup Functions
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @{
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * PPP_InitializeModule() is the entry point for a module and is called by the
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * browser when your module loads. Your code must implement this function.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Failure indicates to the browser that this module can not be used. In this
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * case, the module will be unloaded and ShutdownModule will NOT be called.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param[in] module A handle to your module. Generally you should store this
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * value since it will be required for other API calls.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param[in] get_browser_interface A pointer to the function that you can
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * use to query for browser interfaces. Generally you should store this value
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * for future use.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @return <code>PP_OK</code> on success. Any other value on failure.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PP_EXPORT int32_t PPP_InitializeModule(PP_Module module,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       PPB_GetInterface get_browser_interface);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @}
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @addtogroup Functions
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @{
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * PPP_ShutdownModule() is <strong>sometimes</strong> called before the module
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * is unloaded. It is not recommended that you implement this function.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * There is no practical use of this function for third party modules. Its
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * existence is because of some internal use cases inside Chrome.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Since your module runs in a separate process, there's no need to free
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * allocated memory. There is also no need to free any resources since all of
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * resources associated with an instance will be force-freed when that instance
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * is deleted.
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * <strong>Note:</strong> This function will always be skipped on untrusted
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * (Native Client) implementations. This function may be skipped on trusted
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * implementations in certain circumstances when Chrome does "fast shutdown"
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * of a web page.
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PP_EXPORT void PPP_ShutdownModule(void);
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @}
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @addtogroup Functions
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @{
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * PPP_GetInterface() is called by the browser to query the module for
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * interfaces it supports.
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Your module must implement the <code>PPP_Instance</code> interface or it
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * will be unloaded. Other interfaces are optional.
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * This function is called from within browser code whenever an interface is
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * needed. This means your plugin could be reentered via this function if you
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * make a browser call and it needs an interface. Furthermore, you should not
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * make any other browser calls from within your implementation to avoid
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * reentering the browser.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * As a result, your implementation of this should merely provide a lookup
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * from the requested name to an interface pointer, via something like a big
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * if/else block or a map, and not do any other work.
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param[in] interface_name A pointer to a "PPP" (plugin) interface name.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Interface names are null-terminated ASCII strings.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @return A pointer for the interface or <code>NULL</code> if the interface is
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * not supported.
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PP_EXPORT const void* PPP_GetInterface(const char* interface_name);
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @}
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef __cplusplus
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  /* extern "C" */
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endinl
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Defines the type of the <code>PPP_InitializeModule</code> function.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef int32_t PP_InitializeModule_Func(
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    [in] PP_Module module,
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    [in] PPB_GetInterface get_browser_interface);
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Defines the type of the <code>PPP_ShutdownModule</code> function.
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef void PP_ShutdownModule_Func();
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Defines the type of the <code>PPP_ShutdownModule</code> function.
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef interface_t PP_GetInterface_Func([in] str_t interface_name);
140