RDK Resources
[*RDK Preferred*]
Code Management Facility
RDK Forums
[RDK Conferences]
RDK Support
Archives
Papers & Presentations Archive
Injected bundle is an Integration layer between Service Manager and the player in RDK Browser and WPE.
Code Block | ||
---|---|---|
| ||
The JS Bridge consists of 2 parts: - execution backend (written in C++) - client interface to execution backend (this one) Each part consists of 2 layers: - object interface (methods calls) - general messaging (serialized messages) Each method call JS => C++ is serialized into JSON, trasfered via IPC, received on another side, mapped into the corresponding method call. So, the route is: C++ JS ------------------- ------------------- object interface < < object interface ------------------ | |------------------- general messaging | | general messaging ------------------ | |------------------- IPC <===< IPC Responses and events are transferred in opposite direction (C++ => JS) |
...
...
Define an object of WKBundlePageLoaderClientV1 with your own function callback for didCommitLoadForFrame. This callback gets invoked when a page's DOM contens
...
finishes loading. This will also provide the mainFrame instance in which the JS object is to be loaded
...
.
Code Block | ||
---|---|---|
| ||
WKBundlePageLoaderClientV1 client {
|
Eg -
WKBundlePageLoaderClientV1 client {
...
{1, clientInfo}, |
...
// Version 0. |
...
nullptr, // didStartProvisionalLoadForFrame; |
...
nullptr, // didReceiveServerRedirectForProvisionalLoadForFrame; |
...
nullptr, // didFailProvisionalLoadWithErrorForFrame; |
...
didCommitLoad, // didCommitLoadForFrame; |
...
nullptr, // didFinishDocumentLoadForFrame; |
...
nullptr, // didFinishLoadForFrame; |
...
nullptr, // didFailLoadWithErrorForFrame; |
...
nullptr, // didSameDocumentNavigationForFrame; |
...
nullptr, // didReceiveTitleForFrame; |
...
nullptr, // didFirstLayoutForFrame; |
...
nullptr, // didFirstVisuallyNonEmptyLayoutForFrame; |
...
nullptr, // didRemoveFrameFromHierarchy; |
...
nullptr, // didDisplayInsecureContentForFrame; |
...
nullptr, // didRunInsecureContentForFrame; |
...
nullptr, // didClearWindowObjectForFrame; |
...
nullptr, // didCancelClientRedirectForFrame; |
...
nullptr, // willPerformClientRedirectForFrame; |
...
nullptr, // didHandleOnloadEventsForFrame; |
...
...
// Version 1. |
...
nullptr, // |
...
didLayoutForFrame nullptr, // didNewFirstVisuallyNonEmptyLayout_unavailable |
...
nullptr, // didNewFirstVisuallyNonEmptyLayout_unavailable |
...
nullptr,
nullptr, // globalObjectIsAvailableForFrame
nullptr, // globalObjectIsAvailableForFrame
nullptr, // didReconnectDOMWindowExtensionToGlobalObject
nullptr // willDestroyGlobalObjectForDOMWindowExtension
};
...
nullptr,
nullptr, // globalObjectIsAvailableForFrame
nullptr, // globalObjectIsAvailableForFrame
nullptr, // didReconnectDOMWindowExtensionToGlobalObject
nullptr // willDestroyGlobalObjectForDOMWindowExtension
}; |
...
Code Block | ||
---|---|---|
| ||
void didCommitLoad(WKBundlePageRef page, WKBundleFrameRef frame) |
...
{
...
{ JSGlobalContextRef context = WKBundleFrameGetJavaScriptContext(frame); |
...
LoadJS(context); |
...
} |
...
...
...
Code Block | |
---|---|
|
...
|
typedef struct |
...
int version; /* current (and only) version is 0 */
JSClassAttributes attributes;
const char* className;
JSClassRef parentClass;
const JSStaticValue* staticValues;
const JSStaticFunction* staticFunctions;
JSObjectInitializeCallback initialize;
JSObjectFinalizeCallback finalize;
JSObjectHasPropertyCallback hasProperty;
JSObjectGetPropertyCallback getProperty;
JSObjectSetPropertyCallback setProperty;
JSObjectDeletePropertyCallback deleteProperty;
JSObjectGetPropertyNamesCallback getPropertyNames;
JSObjectCallAsFunctionCallback callAsFunction;
JSObjectCallAsConstructorCallback callAsConstructor;
JSObjectHasInstanceCallback hasInstance;
JSObjectConvertToTypeCallback convertToType;
} JSClassDefinition;
...
{
int version; /* current (and only) version is 0 */
JSClassAttributes attributes;
const char* className;
JSClassRef parentClass;
const JSStaticValue* staticValues;
const JSStaticFunction* staticFunctions;
JSObjectInitializeCallback initialize;
JSObjectFinalizeCallback finalize;
JSObjectHasPropertyCallback hasProperty;
JSObjectGetPropertyCallback getProperty;
JSObjectSetPropertyCallback setProperty;
JSObjectDeletePropertyCallback deleteProperty;
JSObjectGetPropertyNamesCallback getPropertyNames;
JSObjectCallAsFunctionCallback callAsFunction;
JSObjectCallAsConstructorCallback callAsConstructor;
JSObjectHasInstanceCallback hasInstance;
JSObjectConvertToTypeCallback convertToType;
} JSClassDefinition; |
The important parameters for any JS object are staticValues, staticFunctions which helps to implement JSObject.property (get/set) and JSObject.function()
You may find more about the structure of JSStaticValue and JSStaticFunction in JSObjectRef.h
...
...
...
Code Block |
---|
static const JSClassDefinition JS_class_def; |
...
...
void LoadJS(JSGlobalContextRef context) |
...
{
...
{ //Create a custom object that holds the context and any other variables that are required, for eg- seesion keeping |
...
...
var. struct CustomObject* obj = new CustomObject(); JSClassRef classDef = JSClassCreate(&JS_class_def); |
...
JSObjectRef classObj = JSObjectMake(context, classDef, obj); |
...
JSObjectRef globalObj = JSContextGetGlobalObject(context); |
...
JSStringRef str = JSStringCreateWithUTF8CString("JSObject"); //If you would like to name your object as JSObject and access like JSObject.property |
...
JSObjectSetProperty(context, globalObj, str, classObj, kJSPropertyAttributeReadOnly, NULL); // |
...
this loads the JSObject |
...
to page JSClassRelease(classDef); |
...
JSStringRelease(str); |
...
} |
...
...
============================================================================================================================================================================
...
...
Pass the JS API function pointer to Native code and store it as a JSObjectRef
...
Code Block |
---|
JSObject.addEventListener(eventType, eventListener) //with eventListener having a definition like "function eventListener(event: any) {....}" |
...
...
static JSValueRef addEventListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) |
...
{
...
{ JSObjectRef callbackObj = JSValueToObject(context, arguments[1], NULL); |
...
...
if (callbackObj != NULL && JSObjectIsFunction(context, callbackObj)) |
...
{
...
{ //Store the callbackObj in a |
...
eventListener = callbackObj;
...
variable eventListener = callbackObj; JSValueProtect(context, callbackObj); |
...
}
else
{
...
} else { return JSValueMakeUndefined(context); |
...
}
...
} return JSValueMakeNull(context); |
...
} |
...
...
...
...