A method, device and electronic equipment for dynamically extending browser javascript engine functionality
By binding an interface between the browser and the extension library, customers can customize the extension library and dynamically connect it with the browser, solving the problems of DOM tree dependency and recompilation in existing technologies, and realizing flexible expansion and confidentiality of the browser's JavaScript engine functionality.
Patent Information
- Application Number
- CN202110363980.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-03
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2041-04-03
AI Technical Summary
Existing JavaScript extension methods rely on the DOM tree, or require the TV manufacturer to provide the name and parameters of the extension function, or require the entire browser to be compiled, making it impossible to dynamically extend the browser's JavaScript engine.
This paper provides a method for dynamically extending the functionality of a browser's JavaScript engine. By customizing the browser and binding it with an extension library, an interface is provided. Customers customize the extension library and dynamically connect it with the browser. Web pages call the extension library functions, avoiding dependence on the DOM tree. The extension library is executed immediately after the JavaScript engine completes initialization. It does not require knowing the specific function names that the TV manufacturer wants to extend, nor does it require recompiling the entire browser.
It enables flexible expansion of the browser's JavaScript engine functionality, saves upgrade costs, increases confidentiality, and does not rely on TV manufacturers to disclose function names, thus avoiding the need for browser recompilation.
Smart Images

Figure CN113138754B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of browser JavaScript dynamic extension technology, and in particular to a method, apparatus and electronic device for dynamically extending the functionality of a browser JavaScript engine. Background Technology
[0002] Browsers are typically utility programs implemented to meet W3C standards. Unlike PC browsers, TV browsers often have customized features provided by the manufacturer.
[0003] While browsers are currently very powerful, their JavaScript engines sometimes fall short of real-world needs. For example, they may not be able to read the MAC address of a network card, or, on a television, they may not be able to determine the currently playing TV program or retrieve program information—behaviors outside the W3C specification. Front-end web developers are looking to expand the capabilities of television browsers through mechanisms. Another use case is when web developers find traditional HTML / JS / CSS development limited and want to use C / C++ libraries that can be called by the webpage to meet application requirements.
[0004] Some TV manufacturers prefer that JavaScript extensions remain confidential, requiring browsers to only provide a mechanism for extensions—that is, a channel from web pages to the system platform—while the specific function names and functionalities are determined by the manufacturers themselves, without needing to inform the browser. Since this information doesn't need to be disclosed to the browser, manufacturers also hope that the browser SDK won't need to be recompiled with changes to JavaScript extensions. The goal is for the browser to be standardized once, with functionality that can be extended at any time.
[0005] Normally, once a browser has finished compiling, JavaScript cannot be dynamically extended; the JavaScript must be manually modified and recompiled. Dynamically extending JavaScript only requires adding system-specific functions to an external extension library and compiling only the extension library; the entire browser remains unchanged.
[0006] Currently, browsers can be extended to a certain extent using plugins. A plugin is a general term referring to dynamic libraries that interact with the browser based on defined standard interfaces.
[0007] JavaScript provides two mechanisms for extending the JavaScript function interface:
[0008] First, binding: IDL files or interface files are used to generate binding files, and then these generated files are compiled together with the JavaScript engine.
[0009] Secondly, there's Extension: This achieves extension through the base class "Extension" provided by JavaScript. Its basic principle is to provide a base class "Extension" and a global registration function. A browser's Extension instance is essentially a webpage with JavaScript code and CSS style code added.
[0010] Using plugins to extend JavaScript interfaces has a drawback: it requires adding "embed" or "object" nodes to the DOM tree and initializing the plugin beforehand, even if it may not be needed later. Functions provided by the plugin can only be activated after the DOM tree is complete.
[0011] JavaScript extension static binding technology: The problem with the binding mechanism is that the newly generated files need to be compiled together with the JavaScript engine, and the newly generated code cannot be dynamically executed after the engine has finished executing. This limits its use cases, because web developers need to be able to dynamically provide new objects and functions that can be directly called by JavaScript code. Moreover, browser manufacturers must tell browser manufacturers the names and parameters of the extension functions.
[0012] JavaScript Extension Mechanism: The functionality that JavaScript Extensions can achieve is limited to the functions defined in JavaScript. Chrome has now expanded these functions, such as creating tabs and extracting tab characteristics. However, these extended functions are fixed when the browser is generated. Web developers can use different functions to complete their own functions according to different scenarios, but cannot use functions that did not exist in the first place. Summary of the Invention
[0013] In view of the above-mentioned deficiencies of the prior art, the technical problem to be solved by the present invention is that existing JavaScript extension methods rely on the DOM tree, or require the TV manufacturer to provide the name and parameters of the extension function, or require the entire browser to be compiled. The present invention provides a method, device and electronic device for dynamically extending the functionality of the browser's JavaScript engine, which does not require the use of plugins, avoids dependence on the DOM tree, and can be executed immediately after the JavaScript engine completes initialization. Furthermore, it does not require knowing the specific function name that the TV manufacturer wants to extend and does not require recompiling the entire browser.
[0014] To achieve the above objectives, the present invention provides a method for dynamically extending the functionality of a browser's JavaScript engine, comprising the following steps:
[0015] Customize the browser to bind the browser's JavaScript engine to the extension library and provide an interface to the client;
[0016] Customers customize extension libraries according to their needs and dynamically link the extension libraries with the browser for the browser to load;
[0017] Customize the web page to display data obtained from the system platform and call customer-defined functions in the extension library.
[0018] Furthermore, the browser is customized to bind its JavaScript engine to extension libraries and provide interfaces to clients, specifically including the following steps:
[0019] It provides a base class for extension interfaces, including basic interface functions and auxiliary parameter types, to connect the browser and the extension library. By calling the base class, the browser indirectly calls functions within the extension library; the browser can be seen as an intermediary layer between the web page and the extension library.
[0020] Furthermore, customers customize extension libraries according to their needs, enabling the extension libraries to be dynamically linked with the browser for loading. This specifically includes the following steps:
[0021] The extension library inherits the extension interface base class set by the browser and sets the functions that implement the extension interface base class;
[0022] Compile the extension library into a dynamic link library, and then place the compiled dynamic link library in a specified directory that the browser can read.
[0023] Furthermore, the web page is customized to display data retrieved from the system platform, specifically including the following steps:
[0024] The web page creates an instance based on the class name in the extension library;
[0025] Use the created instance to call functions or member variables defined within the extension library;
[0026] Web pages register callback functions for system platform calls;
[0027] Web pages display data retrieved from the system platform via calls or callbacks.
[0028] Furthermore, the browser passes the functionality required by the web page to the loaded extension library by calling basic interface functions, or the system platform passes the data obtained by the system platform to the web page asynchronously through callback functions registered in the extension library; the web page thus controls the system platform and can display the data inside the system platform.
[0029] Furthermore, after the browser starts, it loads the extension library in the specified directory;
[0030] When the extension library is loaded, the browser calls the initialization function to notify the system platform;
[0031] Browsers obtain the class names and the names of functions and member variables within the extended library by calling basic interface functions;
[0032] The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0033] Web pages create extension instances using class names within the extension library;
[0034] The browser calls the functions in the extension library based on the function names registered in the extension library.
[0035] The browser calls functions from the extension library based on different function names to read or write data to the system platform.
[0036] Furthermore, when changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
[0037] Furthermore, the browser uses the member variable name to call the corresponding function to read or write data.
[0038] Furthermore, after the browser starts, it loads the extension library in the specified directory;
[0039] When the extended library is loaded, the browser calls the added initialization function to notify the system platform;
[0040] Browsers obtain the class names and the names of functions and member variables within the extended library by calling basic interface functions;
[0041] The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0042] Web pages create extension instances using class names within the extension library;
[0043] The browser reads the list of function pointers in the extension library, iterates through the list, and adds the strings corresponding to the function pointers to the JavaScript engine for binding.
[0044] The browser binds the function pointer of the called member variable name to the JavaScript engine;
[0045] When changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
[0046] Another preferred embodiment of the present invention provides an apparatus for dynamically extending the functionality of a browser's JavaScript engine, comprising the following modules:
[0047] Browser customization module, used to customize the browser, bind the browser's JavaScript engine to the extension library, and provide interfaces to clients;
[0048] The extension library customization module allows customers to customize extension libraries according to their needs and dynamically link the extension libraries with the browser for loading.
[0049] The Web page customization module is used to customize Web pages, enabling them to display data obtained from the system platform and call customer-customized functions in the extension library.
[0050] Furthermore, browser customization modules include
[0051] Provides an extension interface base class, including basic interface functions and auxiliary parameter types, for connecting browsers and extension libraries.
[0052] Furthermore, the extended library customization module includes
[0053] The configuration unit, the extension library inherits the browser's extension interface base class, and sets the functions that implement the extension interface base class;
[0054] The compilation unit is used to compile the extension library into a dynamic link library, and then place the compiled dynamic link library in a specified directory that can be read by the browser.
[0055] Furthermore, the web page customization module includes:
[0056] Create a unit, which is used by the web page to create instances based on class names in the extension library;
[0057] The calling unit is used to call functions or member variables defined within the extension library through a created instance;
[0058] The registration unit is used to register callback functions for web pages, which are then called by the system platform.
[0059] The data retrieval unit is used by web pages to display data retrieved from the system platform via calls or callbacks.
[0060] Furthermore, the browser passes the functionality required by the web page to the loaded extension library by calling basic interface functions, or the system platform passes the data obtained by the system platform to the web page asynchronously through callback functions registered in the extension library; the web page thus controls the system platform and can display the data inside the system platform.
[0061] Furthermore, after the browser starts, it loads the extension library in the specified directory;
[0062] When the extension library is loaded, the browser calls the initialization function to notify the system platform;
[0063] Browsers obtain the class names and the names of functions and member variables within the extended library by calling basic interface functions;
[0064] The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0065] Web pages create extension instances using class names within the extension library;
[0066] The browser calls the functions in the extension library based on the function names registered in the extension library.
[0067] The browser calls functions from the extension library based on different function names to read or write data to the system platform.
[0068] Furthermore, when changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
[0069] Furthermore, the browser uses the member variable name to call the corresponding function to read or write data.
[0070] Furthermore, after the browser starts, it loads the extension library in the specified directory;
[0071] When the extended library is loaded, the browser calls the initialization function to notify the system platform;
[0072] Browsers obtain the class names and the names of functions and member variables within the extended library by calling basic interface functions;
[0073] The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0074] Web pages create extension instances using class names within the extension library;
[0075] The browser reads the list of function pointers in the extension library, iterates through the list, and adds the strings corresponding to the function pointers to the JavaScript engine for binding.
[0076] The browser binds the function pointer of the called member variable name to the JavaScript engine;
[0077] When changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
[0078] Another preferred embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, when the processor executes the program, it implements the method as described in any of the above.
[0079] Another preferred embodiment of the present invention provides a computer-readable storage medium storing a computer program, characterized in that the computer program enables a method for dynamically extending the functionality of a browser JavaScript engine as described above when executed by a computer.
[0080] Technical effect
[0081] The present invention discloses a method, apparatus, and electronic device for dynamically extending the functionality of a browser's JavaScript engine. This allows for the extension of any function for use by web page developers, offering great flexibility. It eliminates the need to recompile the entire browser, replacing only one extension library and saving on upgrade costs. Furthermore, television manufacturers are not required to disclose the necessary functions, and since these functions are based on the C language, confidentiality is enhanced.
[0082] The following will further explain the concept, specific structure, and technical effects of the present invention in conjunction with the accompanying drawings, so as to fully understand the purpose, features, and effects of the present invention. Attached Figure Description
[0083] Figure 1 This is a schematic diagram illustrating the operation of a method for dynamically extending the functionality of a browser's JavaScript engine, according to a preferred embodiment of the present invention.
[0084] Figure 2 This is a schematic diagram illustrating the operation of a method for dynamically extending the functionality of a browser's JavaScript engine, according to another preferred embodiment of the present invention. Detailed Implementation
[0085] To make the technical problems to be solved, the technical solutions, and the beneficial effects of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present invention and are not intended to limit the present invention.
[0086] In the following description, specific details, such as particular internal procedures and techniques, are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of the invention. However, those skilled in the art will appreciate that the invention may be practiced in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of the invention with unnecessary detail.
[0087] This invention provides a method for dynamically extending the functionality of a browser's JavaScript engine, comprising the following three main parts:
[0088] 1. Customize the browser to bind its JavaScript engine to the extension library:
[0089] The function that loads the extension library in the browser reads the settings file at startup to determine whether the extension library needs to be loaded and in which path;
[0090] Set up a base class for the extension interface, including basic interface functions and auxiliary parameter types, to connect the browser and the extension library;
[0091] The browser binds functions within the extension library to the JavaScript engine through an interface. This way, JavaScript function calls are transformed by the engine into calls to the platform system, and the platform system callbacks are transformed into function calls to WebJavascript.
[0092] 2. Customize the extension library according to requirements and enable the extension library to dynamically connect with the browser;
[0093] The extension library inherits the extension interface base class set by the browser and sets the functions that implement the extension interface base class; the extension library is compiled into a dynamic link library so that the browser can run even if the extension library is not present; and then the compiled dynamic link library is placed in a specified directory that the browser can read.
[0094] 3. Customize the web page to display data obtained from the system platform (here, the system platform refers to the Linux or Android system in the embedded device);
[0095] The web page creates an instance based on the class name within the extension library;
[0096] Use the created instance to call functions or member variables defined within the extension library;
[0097] Web pages register callback functions for system platform calls;
[0098] Web pages display data retrieved from the system platform via calls or callbacks.
[0099] The browser side first completes the binding of the three modules mentioned above and provides an interface to the client; the client completes the extension library according to the interface so that the browser can load it; finally, the web page is completed and calls the client-customized functions in the extension library.
[0100] It's important to note that if the JavaScript engine dynamically creates a class on a web page, it must know the name of that class. For example, if the extension library defines the name as "TV Menu," since this name is arbitrarily chosen and not within a built-in method of the JavaScript engine, it needs to be defined through an interface provided by the browser (an interface within the base class). After loading the extension library, the browser will perform an initialization action (i.e., call the initialization function to notify the system platform). At this time, it will request the name of the class that the JavaScript engine needs on the page from the extension library, which is "TV Menu."
[0101] The browser passes the functionality required by the web page to the loaded extension library by calling basic interface functions, or the system platform passes the data obtained by the system platform to the web page asynchronously through callback functions registered in the extension library; the web page thus controls the system platform and can display the data inside the system platform.
[0102] The aforementioned callback function registration works in a layered manner. Callbacks on the web page follow standard JavaScript syntax, effectively connecting the browser and the page. The browser needs to register functions with the extension library, thus connecting the browser and the extension library. Below the extension library lies the system platform. For a concrete example, the page registers a callback for switching TV channels; this callback is registered with the browser. The browser then registers a function in its extension library. When the user switches TV channels, the system platform is the first to know, sending a callback to the browser via the extension library. The browser then sends a callback to the page, allowing the page to perform the corresponding action. Similarly, if a web page needs to display a volume bar, neither the web page nor the browser knows the specific volume value. Therefore, it needs to request the data from the system platform via an API, send it back to the browser, and then pass it to the page. The page then uses this value to draw the corresponding volume bar length.
[0103] Browser extensions refer to functions that browsers do not possess, achieved through web technologies—HTML, CSS, and JavaScript. These include functions such as collecting website information, adding or deleting content from web pages, and adding new tools and browsing features. These extensions are based on interfaces provided by the browser itself, allowing for functional development on top of them. However, the browser's own interfaces cannot be extended, and their functionality is fixed from the page to the system level and cannot be modified. For example, it's impossible to obtain internal system information solely through extensions.
[0104] This can be achieved through extension libraries. Users need to load their own custom extension libraries and, in conjunction with JavaScript calls, enable operations from the web to the platform. In principle, JavaScript extensions can accomplish any function from a web page to a system platform, and browser providers do not need to know the specific details or functions of the extensions. The browser merely provides a channel; the specific functionality depends on the extension libraries provided by the TV manufacturer or SOC manufacturer.
[0105] Example 1
[0106] This embodiment provides a specific implementation method for dynamically extending the functionality of a browser's JavaScript engine, such as... Figure 1 As shown, the specific steps include:
[0107] 1. Load the extension library in the specified directory after the browser starts; if it fails, return without further action.
[0108] 2. When the extension library is loaded, the browser calls the initialization function to notify the system platform. The extension library initializes the corresponding modules on the system platform; this part is reserved for the platform system. When the extension library is loaded, the browser calls this initialization function to notify the platform system that the extension library has been loaded and that platform pre-operations can be performed. This part depends on the system itself and can be empty.
[0109] 3. The browser obtains the class names and the names of functions and member variables within the class from the extension library by calling the basic interface;
[0110] 4. The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0111] 5. Web pages create extended instances using class names; if the class name has not been registered, an exception is thrown.
[0112] 6. The browser will call the function by name. Since this function has already been implemented in the extension library, it is equivalent to the browser directly calling the function in the extension library and telling the web page which function is being called by passing in the parameters. The unified function in the extension library calls the system platform interface to implement the functions required by the web page according to the different parameters (function name); for example, calling the function to get the MAC address of the terminal or the TV program list.
[0113] 7. The browser will call the unified read or write member variable functions of the extension library through variable names. One function is used to read the data stored in the member variable, and the other is used to write the data to the member variable. Depending on the parameters (function name), the browser will call the system platform's interface to read or write data to the system platform.
[0114] When changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
[0115] Example 2
[0116] This embodiment provides a specific implementation method for dynamically extending the functionality of a browser's JavaScript engine, such as... Figure 2 As shown, it includes the following steps:
[0117] 1. Load the extension library in the specified directory after the browser starts; if it fails, return without further action.
[0118] 2. When the extension library is loaded, the browser calls the initialization function to notify the system platform; the extension library initializes the corresponding module on the system platform. This part is reserved for the platform system; when the extension library is loaded, the browser calls this initialization function to notify the platform system that the extension library has been loaded and can perform platform pre-operations. This part depends on the system itself and can be empty;
[0119] 3. The browser obtains the class names and the names of functions and member variables within the class from the extension library by calling the basic interface;
[0120] 4. The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0121] 5. Web pages create extended instances using class names; if the class name has not been registered, an exception is thrown.
[0122] 6. The browser reads the list of function pointers in the extension library, iterates through the list, and adds the strings corresponding to the function pointers to the JavaScript engine for binding. Specifically, the browser reads the list of function pointers in the extension library, iterates through the list, and adds the strings corresponding to the function pointers to the JavaScript engine for binding. Since the interface is provided by the extension library and its function names are visible, it can be directly bound one-to-one.
[0123] 7. The browser binds the function pointer of the called member variable name to the JavaScript engine; the specific steps are similar to step 6.
[0124] 8. When changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing. For example, the system platform might download an image from the network and then use this callback mechanism to send the image to the web page for display.
[0125] Implementation 2 and Implementation 1 can achieve the same effect, but Implementation 2 uses an extension library to provide the interface, which is adapted by the browser and has a special scope of use.
[0126] The method for dynamically extending the functionality of a browser's JavaScript engine provided in Embodiments 1 and 2 above has the following advantages:
[0127] 1. It does not use plugins, avoids dependence on the DOM tree, and can be executed immediately after the JavaScript engine completes initialization;
[0128] 2. Without using JavaScript extension static binding, this technology does not need to know the specific function names that the TV manufacturer wants to extend, and it does not require recompiling the entire browser;
[0129] 3. Dynamically bind the client's own Javascript interface; all extended interfaces are not fixed during browser compilation.
[0130] Because one method of dynamically extending the functionality of a browser's JavaScript engine in this embodiment of the invention uses a dynamically loaded extension library, and the names of the functions to be extended in the extension library do not need to be determined when compiling the browser, this not only ensures maximum flexibility, but also directly connects the JavaScript of the web page and the system platform through dynamic extension functions, thus breaking through the limitations of static interfaces and dynamic usage of JavaScript Extensions.
[0131] Example 3
[0132] A device for dynamically extending the functionality of a browser's JavaScript engine, comprising the following modules:
[0133] Browser customization module, used to customize the browser, bind the browser's JavaScript engine to the extension library, and provide interfaces to clients;
[0134] The extension library customization module allows customers to customize extension libraries according to their needs and dynamically link the extension libraries with the browser for loading.
[0135] The Web page customization module is used to customize Web pages, enabling them to display data obtained from the system platform and call customer-customized functions in the extension library.
[0136] Furthermore, browser customization modules include
[0137] Provides an extension interface base class, including basic interface functions and auxiliary parameter types, for connecting browsers and extension libraries.
[0138] Furthermore, the extended library customization module includes
[0139] The configuration unit, the extension library inherits the browser's extension interface base class, and sets the functions that implement the extension interface base class;
[0140] The compilation unit is used to compile the extension library into a dynamic link library, and then place the compiled dynamic link library in a specified directory that can be read by the browser.
[0141] Furthermore, the web page customization module includes:
[0142] Create a unit, which is used by the web page to create instances based on class names in the extension library;
[0143] The calling unit is used to call functions or member variables defined within the extension library through a created instance;
[0144] The registration unit is used to register callback functions for web pages, which are then called by the system platform.
[0145] The data retrieval unit is used by web pages to display data retrieved from the system platform via calls or callbacks.
[0146] Furthermore, the browser passes the functionality required by the web page to the loaded extension library by calling basic interface functions, or the system platform passes the data obtained by the system platform to the web page asynchronously through callback functions registered in the extension library; the web page thus controls the system platform and can display the data inside the system platform.
[0147] Furthermore, after the browser starts, it loads the extension library in the specified directory;
[0148] When the extension library is loaded, the browser calls the initialization function to notify the system platform;
[0149] Browsers obtain the class names and the names of functions and member variables within the extended library by calling basic interface functions;
[0150] The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0151] Web pages create extension instances using class names within the extension library;
[0152] The browser calls the functions in the extension library based on the function names registered in the extension library.
[0153] The browser calls functions from the extension library based on different function names to read or write data to the system platform.
[0154] Furthermore, when changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
[0155] Furthermore, the browser uses the member variable name to call the corresponding function to read or write data.
[0156] Furthermore, after the browser starts, it loads the extension library in the specified directory;
[0157] When the extended library is loaded, the browser calls the initialization function to notify the system platform;
[0158] Browsers obtain the class names and the names of functions and member variables within the extended library by calling basic interface functions;
[0159] The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine;
[0160] Web pages create extension instances using class names within the extension library;
[0161] The browser reads the list of function pointers in the extension library, iterates through the list, and adds the strings corresponding to the function pointers to the JavaScript engine for binding.
[0162] The browser binds the function pointer of the called member variable name to the JavaScript engine;
[0163] When changes occur within the system platform, the extension library can be notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
[0164] The embodiments of the present invention are for implementing the above embodiments, and their implementation methods are the same as those of the above embodiments, therefore, they will not be described again here.
[0165] Example 4
[0166] Another embodiment of the present invention provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements the method described above.
[0167] The computer device of this embodiment includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps in the various embodiments described above. Alternatively, when the processor executes the computer program, it implements the functions of each module / unit in the various device embodiments described above.
[0168] For example, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the computer device.
[0169] The computer device may be a desktop computer, laptop, handheld computer, or cloud server, etc. The computer device may include, but is not limited to, a processor and memory.
[0170] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0171] The memory can be an internal storage unit of the computer device, such as a hard drive or RAM. The memory can also be an external storage device of the computer device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory can include both internal and external storage units. The memory is used to store the computer program and other programs and data required by the computer device. The memory can also be used to temporarily store data that has been output or will be output.
[0172] Another preferred embodiment of the present invention provides a computer-readable storage medium storing a computer program, characterized in that the computer program enables a method for dynamically extending the functionality of a browser JavaScript engine as described above when executed by a computer.
[0173] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.
Claims
1. A method for dynamically extending the functionality of a browser's JavaScript engine, characterized in that, Without using plugins or JavaScript extensions for static binding, the steps include: A customized browser is provided to bind the browser's JavaScript engine to the extension library and provide an interface to the client. An extension interface base class is provided, including basic interface functions and auxiliary parameter types, to connect the browser and the extension library. The browser binds the functions in the extension library to the JavaScript engine through the interface. In this way, the JavaScript function calls will be transformed by the engine into calls to the platform system, and the callbacks of the platform system will be transformed into function calls to Web JavaScript. The client customizes an extension library according to their needs and dynamically links the extension library with the browser for loading by the browser; specifically, this includes the following steps: The extension library inherits the extension interface base class set by the browser and sets functions that implement the extension interface base class; The extension library is compiled into a dynamic link library, and then the compiled dynamic link library is placed in a specified directory that the browser can read; A customized web page is created to display data retrieved from the system platform and call customer-customized functions in the extension library. Users need to load their own extension library and use JavaScript to perform operations from the web page to the platform. Specifically, this includes the following steps: The web page creates an instance based on the class name in the extension library; The created instance can be used to call functions or member variables defined within the extended library; The web page registration callback function is used for invocation by the system platform; The web page displays data obtained from the system platform through calls or callbacks.
2. The method for dynamically extending the functionality of a browser's JavaScript engine as described in claim 1, characterized in that, The browser passes the required functions of the web page to the loaded extension library by calling the basic interface functions, or the system platform passes the data obtained by the system platform to the web page asynchronously through the callback functions registered in the extension library; the web page thus controls the system platform and can display the data inside the system platform.
3. The method for dynamically extending the functionality of a browser's JavaScript engine as described in claim 2, characterized in that, The browser loads the extension library in the specified directory after startup; When the extension library is loaded, the browser calls the initialization function to notify the system platform; The browser obtains the class names and the names of functions and member variables within the extended library by calling the basic interface functions; The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine. The web page creates an extension instance using the class name within the extension library; The browser calls the functions in the extension library based on the function names registered in the extension library. The browser calls functions from the extension library based on different function names to read or write data to the system platform.
4. The method for dynamically extending the functionality of a browser's JavaScript engine as described in claim 3, characterized in that, When changes occur within the system platform, the extension library is notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
5. The method for dynamically extending the functionality of a browser's JavaScript engine as described in claim 3, characterized in that, Browsers use member variable names to call corresponding functions to read or write data.
6. The method for dynamically extending the functionality of a browser's JavaScript engine as described in claim 3, characterized in that, The browser loads the extension library in the specified directory after startup; When the extended library is loaded, the browser calls the initialization function to notify the system platform; The browser obtains the class names and the names of functions and member variables within the extended library by calling basic interface functions; The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine. The web page creates an extension instance using the class name within the extension library; The browser reads the list of function pointers in the extension library, iterates through the list, and adds the strings corresponding to the function pointers to the JavaScript engine for binding. The browser binds the function pointer of the called member variable name to the JavaScript engine; When changes occur within the system platform, the extension library is notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
7. A device for dynamically extending the functionality of a browser's JavaScript engine, characterized in that, Includes the following modules: A browser customization module is used to customize the browser, binding the browser's JavaScript engine to the extension library and providing an interface to the client; the browser binds the functions in the extension library to the JavaScript engine through the interface, so that JavaScript function calls will be transformed by the engine into calls to the platform system, and the platform system callbacks will be transformed into function calls to Web JavaScript; The extension library customization module is used by the customer to customize the extension library according to their needs and to dynamically connect the extension library with the browser for loading by the browser; The Web page customization module is used to customize Web pages, enabling the Web pages to display data obtained from the system platform and call the customer-customized functions in the extended library; Users need to load their own custom extension libraries and use JavaScript to make calls, which will enable operations from the Web to the platform.
8. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 7, characterized in that, The browser customization module includes Provide an extension interface base class, including basic interface functions and auxiliary parameter types, for connecting the browser and the extension library.
9. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 8, characterized in that, The extension library customization module includes The configuration unit specifies that the extension library inherits the extension interface base class set by the browser and configures functions that implement the extension interface base class. The compilation unit is used to compile the extension library into a dynamic link library, and then place the compiled dynamic link library in a specified directory that the browser can read.
10. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 8, characterized in that, Web page customization modules include: A creation unit is used by the web page to create an instance based on the class name in the extension library; A calling unit is used to call functions or member variables defined within the extended library through a created instance; A registration unit is used to register callback functions on the web page for use by the system platform. A data acquisition unit is used by the web page to display data acquired from the system platform through a call or callback.
11. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 8, characterized in that, The browser passes the required functions of the web page to the loaded extension library by calling the basic interface functions, or the system platform passes the data obtained by the system platform to the web page asynchronously through the callback functions registered in the extension library; the web page thus controls the system platform and can display the data inside the system platform.
12. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 11, characterized in that, The browser loads the extension library in the specified directory after startup; When the extension library is loaded, the browser calls the initialization function to notify the system platform; The browser obtains the class names and the names of functions and member variables within the extended library by calling the basic interface functions; The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine. The web page creates an extension instance using the class name within the extension library; The browser calls the functions in the extension library based on the function names registered in the extension library. The browser calls functions from the extension library based on different function names to read or write data to the system platform.
13. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 12, characterized in that, When changes occur within the system platform, the extension library is notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
14. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 13, characterized in that, Browsers use member variable names to call corresponding functions to read or write data.
15. The apparatus for dynamically extending the functionality of a browser's JavaScript engine as described in claim 12, characterized in that, The browser loads the extension library in the specified directory after startup; When the extended library is loaded, the browser calls the initialization function to notify the system platform; The browser obtains the class names and the names of functions and member variables within the extended library by calling basic interface functions; The browser registers and binds the obtained class name, as well as the names of the functions and member variables within the class, within the browser's JavaScript engine. The web page creates an extension instance using the class name within the extension library; The browser reads the list of function pointers in the extension library, iterates through the list, and adds the strings corresponding to the function pointers to the JavaScript engine for binding. The browser binds the function pointer of the called member variable name to the JavaScript engine; When changes occur within the system platform, the extension library is notified. The extension library then notifies the browser through a callback mechanism in the base class, and the browser then sends the changes back to the web page for processing.
16. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-6.
17. A computer-readable storage medium storing a computer program, characterized in that, The computer program enables a computer to implement a method for dynamically extending the functionality of a browser's JavaScript engine as described in any one of claims 1-6 when executed.
Citation Information
Patent Citations
Information interaction method and information interaction device of Web application and in-vehicle infortainment system
CN103049316A
Method and equipment of loading plugins of terminal network application based on browser
CN107066295A