In order to extend the interface, one should add the following lines to the
variables section of
<platform-directory>/cobalt/configuration.gypi (see Starboard's Application Customization for more information):
windowelement (see 3.
enums that may then be referenced as types in a file from 1.
The first two lists get included by cobalt/browser/browser_bindings_gen.gyp, where you can look to see many examples of existing Cobalt IDL files that define the Web API available through Cobalt. For each of these, you can also examine their corresponding
.h files and in most cases their
.cc files as well.
An example configuration for these variables is available at starboard/shared/test_webapi_extension/test_webapi_extension.gypi, which contains the following variable definitions:
'cobalt_webapi_extension_source_idl_files': [ 'my_new_interface.idl' ], 'cobalt_webapi_extension_generated_header_idl_files': [ 'my_new_enum.idl' ], 'cobalt_webapi_extension_gyp_target': '<(DEPTH)/starboard/shared/test_webapi_extension/webapi_extension.gyp:cobalt_test_webapi_extension',
As discussed above in 3.
cobalt_webapi_extension_gyp_target, you must provide an implementation of the two functions declared in browser/webapi_extension.h.
You should implement
GetWebAPIExtensionObjectPropertyName() to return the name of the injected
window property. For example, in the example from the beginning of this document,
window.myInterface.RunMyFunction(), we would have the function return
std::string("myInterface"). If you return
nullopt from this function, it is assumed that you do not wish to extend the web interface.
Note that you should NOT name your
This function should instantiate and return the object to be accessed from
window. The object must be defined by an IDL file.
Here is an example of an example interface being exercised through the debug console: