Local component dynamic calling method and system for browser

By dynamically calling methods on the browser side, parsing component configuration files and using preset dynamic library loading mechanisms, the problems of limited use scope and high maintenance costs in the existing technology are solved, and a variety of plug-ins and interfaces are realized. Reuse and dynamic updates improve development efficiency and flexibility.

CN119166242APending Publication Date: 2024-12-20DAREWAY SOFTWARE
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411343910.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-25
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

The existing technology method of calling local components, hardware and underlying dynamic libraries on the browser side under the B/S architecture has limited usage scope, high dependency, poor adaptability to new devices and new plug-in interfaces, and high maintenance costs, so it cannot be Implement dynamic calls at runtime, resulting in low development efficiency and insufficient flexibility.

Method used

Provide a browser's local component dynamic call method, parsing component configuration files through local component services, generating formatted interface configuration information, using the preset dynamic library loading mechanism to load the dynamic library, and encapsulate the interface to realize the implementation of multiple plug-ins Reuse with interfaces, supports runtime dynamic library loading and calling, and reduces compile-time dependencies.

Benefits of technology

Improve development efficiency and code maintainability, enhance program flexibility and scalability, and realize dynamic calls and automatic updates of new components without recompilation or restart, reducing operation and maintenance workload.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166242A_ABST
    Figure CN119166242A_ABST
Patent Text Reader

Abstract

The invention provides a local component dynamic calling method and system for a browser. The method comprises the steps that the browser issues a local component service calling request to a local component service; based on the component calling information in the calling request, dynamically calling the local component through the local component service; wherein the local component service specifically executes the following processing processes: analyzing a corresponding component configuration file to obtain formatted interface configuration information; based on the obtained interface configuration information, splicing related parameters after interface parameter type conversion to obtain execution parameters; according to the execution parameters, loading a corresponding dynamic library through a preset dynamic library loading mechanism, and packaging function calling of a corresponding interface in the dynamic library to generate a calling interface; and calling a local component function based on the calling interface to obtain a return value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of component dynamic calling, and in particular relates to a method and system for dynamically calling a local component of a browser. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] B / S architecture systems generally run on IE browsers. The traditional way for IE browsers to call local components, hardware, and underlying dynamic library plug-ins is to use Activex controls. With the development of informatization, browsers such as Chrome and FireFox have gradually become mainstream. Due to privacy security and stability, they no longer support Activex controls. At the same time, many programs using C / S structure are gradually migrating to B / S architecture. The underlying plug-ins and dynamic libraries previously used for C / S end are facing reconstruction and elimination, and the development cost of re-adapting plug-ins to B / S end is huge.

[0004] Currently, the common solution for browsers to call local system components, hardware, and underlying dynamic library plug-ins under the B / S architecture is to develop special plug-in programs for specific devices and plug-ins to adapt to specific browsers. Although the existing technology can realize the calling of plug-ins and hardware by the web page, it has high dependence, poor adaptability to new devices and new plug-in interfaces, lacks flexibility, and has limitations. For example, in Chinese patent [CN 110175055 A], a service-based browser and fingerprint device calling method is provided, which implements the packaging of the fingerprint device hardware driver and installs it on the client's server, and provides it in the form of application service for external browser calling. However, this method is only applied to fingerprint devices, and the scope of use is limited. When the plug-in interface is updated or adjusted, it needs to be redeveloped; in Chinese patent [CN 116450383 A], a method for calling the operating system through a web page is provided, which realizes the ability of the browser to call the local API. However, in this method, the website web page development needs to first clarify the local API that needs to be called and the dynamic library that needs to be integrated, and all dependent files need to be merged and compiled. The program package is large and the operating efficiency is low. It is impossible to realize dynamic calling at runtime. When the demand changes, the program package needs to be regenerated, and the maintenance cost is high. Summary of the invention

[0005] In order to solve the above problems, the present invention provides a method and system for dynamically calling local components for browsers, so as to solve the problem that the traditional local component calling method can only be used for specific plug-ins and has a limited scope of use, and the traditional method needs to merge and compile the files that the calling component depends on in advance, and when the demand changes, the program package needs to be regenerated, which has a high maintenance cost.

[0006] According to a first aspect of an embodiment of the present invention, a method for dynamically calling a local component of a browser is provided, which is applied to the browser and includes:

[0007] Send a local component service call request to the local component service;

[0008] Based on the component call information in the call request, the local component is dynamically called through the local component service; wherein the local component service specifically performs the following processing procedures: the corresponding component configuration file is parsed to obtain the formatted interface configuration information; based on the obtained interface configuration information, the relevant parameters are spliced ​​after the interface parameter type conversion to obtain the execution parameters; according to the execution parameters, the corresponding dynamic library is loaded through the preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a call interface; based on the call interface, the local component function is called to obtain the return value;

[0009] Receive the return value of the local component service feedback.

[0010] Furthermore, the corresponding dynamic library is loaded through a preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a calling interface. Specifically, based on the execution parameters, the corresponding dynamic library is loaded using the preset dynamic library loading mechanism, the target symbol and interface corresponding to the calling request are searched in the loaded dynamic library, the data type of the caller language is converted into the data type of the callee language, and then the call of the function in the dynamic library is encapsulated to form a calling interface.

[0011] Furthermore, the dynamic library loading mechanism is specifically as follows: when loading a dynamic library, the dynamic library is first searched for according to a specified path through the dynamic linker of the operating system; the dynamic linker loads the library file into the virtual address space of the process through a system call; the dynamic linker resolves the call to the library function or variable in the program through a symbol table.

[0012] Furthermore, based on the obtained interface configuration information, relevant parameters are spliced ​​after interface parameter type conversion to obtain execution parameters. Specifically, based on the input parameter type configuration item in the interface configuration information, the formatted interface parameter type is converted into a parameter type supported by a preset mapping rule, and according to the component detailed information in the interface configuration information, the storage location information, name information and interface information of the requested component are spliced ​​to obtain execution parameters.

[0013] Furthermore, the corresponding component configuration file is parsed to obtain formatted interface configuration information, specifically: based on the module name and interface name in the call request, the component configuration file is parsed to obtain formatted interface configuration information including component detailed information and interface parameter information.

[0014] Furthermore, the local component service intercepts and forwards the call request of the non-Local host and the loopback address, receives the call request other than the non-Local host and the loopback address, and executes the dynamic call of the local component.

[0015] According to a second aspect of an embodiment of the present invention, a method for dynamically calling a local component of a browser is provided, which is applied to a local component service and includes:

[0016] Responding to a local component service call request from a browser;

[0017] Based on the component call information in the call request, the corresponding component configuration file is parsed to obtain formatted interface configuration information;

[0018] Based on the obtained interface configuration information, relevant parameters are concatenated after interface parameter type conversion to obtain execution parameters;

[0019] According to the execution parameters, the corresponding dynamic library is loaded through a preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a calling interface;

[0020] Based on the calling interface, a local component function call is performed to obtain a return value, which is fed back to the browser.

[0021] According to a third aspect of an embodiment of the present invention, a method for dynamically calling a local component of a browser is provided, comprising:

[0022] The browser sends a local component service call request to the local component service;

[0023] Based on the component call information in the call request, the local component is dynamically called through the local component service; wherein the local component service specifically performs the following processing procedures: the corresponding component configuration file is parsed to obtain the formatted interface configuration information; based on the obtained interface configuration information, the relevant parameters are spliced ​​after the interface parameter type conversion to obtain the execution parameters; according to the execution parameters, the corresponding dynamic library is loaded through the preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a call interface; based on the call interface, the local component function is called to obtain the return value;

[0024] The local component service feeds back the obtained return value to the browser.

[0025] According to a fourth aspect of an embodiment of the present invention, a local component dynamic calling system for a browser is provided, comprising:

[0026] The browser is used to send a local component service call request to the local component service, and receive a local component call return value obtained from the local component service;

[0027] A local component service is used to receive a local component service call request from a browser, and based on the component call information in the call request, parse the corresponding component configuration file to obtain formatted interface configuration information; based on the obtained interface configuration information, concatenate related parameters after interface parameter type conversion to obtain execution parameters; based on the execution parameters, load the corresponding dynamic library through a preset dynamic library loading mechanism, and encapsulate the function call of the corresponding interface in the dynamic library to generate a call interface; based on the call interface, call the local component function, obtain the return value, and feed it back to the browser.

[0028] According to a fifth aspect of an embodiment of the present invention, there is provided an electronic device, comprising a memory, a processor, and a computer program stored and running on the memory, wherein when the processor executes the program, the method for dynamically calling a local component for a browser is implemented.

[0029] Compared with the prior art, the present invention has the following beneficial effects:

[0030] (1) The present invention provides a method and system for dynamically calling local components of a browser. The solution provides a unified packaged browser calling interface to implement a set of standard processes for reusing multiple plug-ins and interfaces. There is no need to rewrite code for each new requirement, which greatly improves development efficiency and enhances code maintainability.

[0031] (2) The solution described in the present invention is based on a dynamic interface calling module to realize the loading of dynamic libraries. On the one hand, it improves the flexibility of the program and can realize the loading and calling of dynamic libraries when the program is running, without linking it to the program during compilation. This means that the functions in the dynamic library can be updated or replaced without recompiling the main program. On the other hand, it improves the scalability of the program. Components can be added or modified according to the request configuration file rules, and the calling of new components can be realized without restarting or recompiling.

[0032] (3) The present invention can realize automatic downloading and updating of the plug-ins required by users. When the interface or plug-in is updated, it does not need to be sent separately, and the update management is unified, thus reducing the operation and maintenance workload.

[0033] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0035] Figure 1 A flow chart of a method for dynamically calling a local component of a browser according to an embodiment of the present invention;

[0036] Figure 2 The present invention is a schematic diagram of a system structure for dynamically calling a local component of a browser according to an embodiment of the present invention. DETAILED DESCRIPTION

[0037] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0038] It should be noted that the following detailed descriptions are all illustrative and intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0039] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0040] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0041] In order to solve the problems existing in the prior art, this embodiment provides a method for dynamically calling a local component of a browser, which is applied to the browser and includes:

[0042] Step 1: Send a local component service call request to the local component service;

[0043] The calling request is sent as follows: The browser sends a Websocket or Http request to the local component service through the JS method, specifically:

[0044] The JS method is a JavaScript function executed by a browser, and the present invention provides a unified reference JS method. First, the connection JS file is encapsulated into the local component service program to obtain a connection interface, including a Websocket connection interface and an Http connection interface, wherein the Websocket connection interface is used for the browser to asynchronously call the local component service, and the encapsulated Http connection interface is used for the browser to synchronously call the local component service. Then, the browser can introduce the relevant connection interface by referencing the JS file under the Locahost path. This process requires detecting whether the browser supports Websocket connection. The local component service can continuously monitor the Websocket and Http requests of the local port.

[0045] Step 2: Based on the component call information in the call request, dynamically call the local component through the local component service; wherein the local component service specifically performs the following processing: parse the corresponding component configuration file to obtain formatted interface configuration information; based on the obtained interface configuration information, concatenate the relevant parameters after interface parameter type conversion to obtain execution parameters; according to the execution parameters, load the corresponding dynamic library through the preset dynamic library loading mechanism, and encapsulate the function call of the corresponding interface in the dynamic library to generate a call interface; call the local component function based on the call interface to obtain a return value;

[0046] In a specific implementation, the corresponding dynamic library is loaded through a preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a calling interface. Specifically, based on the execution parameters, the corresponding dynamic library is loaded using the preset dynamic library loading mechanism, the target symbol and interface corresponding to the calling request are searched in the loaded dynamic library, the data type of the caller language is converted into the data type of the callee language, and then the call of the function in the dynamic library is encapsulated to form a calling interface.

[0047] In a specific implementation, based on the obtained interface configuration information, related parameters are spliced ​​after interface parameter type conversion to obtain execution parameters. Specifically, based on the input parameter type configuration item in the interface configuration information, the formatted interface parameter type is converted into a parameter type supported by a preset mapping rule, and according to the component detailed information in the interface configuration information, the storage location information, name information and interface information of the requested component are spliced ​​to obtain execution parameters.

[0048] In a specific implementation, the corresponding component configuration file is parsed to obtain formatted interface configuration information, specifically: based on the module name and interface name in the call request, the component configuration file is parsed to obtain formatted interface configuration information including component detailed information and interface parameter information.

[0049] In a specific implementation, the local component service intercepts and forwards call requests from non-Local hosts and loopback addresses, receives call requests other than non-Local hosts and loopback addresses, and executes dynamic calls of local components. Specifically, the handshake requests from non-Local hosts and loopback addresses are intercepted and forwarded, and correct requests are received. For the received requests, the corresponding component configuration file is parsed according to the module name and interface name in the request body to obtain formatted interface configuration information, including component detailed information and interface parameter information.

[0050] The conversion of the interface parameter type is based on the FFI mapping rules. According to the input parameter type configuration item in the interface configuration information, the formatted interface parameter type is converted into the parameter type supported by FFI. For pointer type and array type parameters, they are mapped to the pointer type in FFI; for ordinary type parameters, no conversion is done in FFI, such as Int and String, which are mapped to the corresponding Int and String types in FFI; for parameter types that do not exist in the rules, they are recorded and an error is returned.

[0051] The dynamic interface calling module (FFI) and the dynamic library can be loaded and called when the program is running. The execution parameters obtained in step 3 are passed into the dynamic interface calling module (FFI), and the corresponding dynamic library is loaded using the dynamic library loading mechanism provided by the programming language. The target symbol and interface are searched in the loaded dynamic library, and the data type of the calling language is converted into the data type of the called language. Then, the call of the function in the dynamic library is encapsulated to form a concise calling interface, and the calling interface is applied to call the local component function, and the return value is obtained. According to the return parameter type configuration item, the return result is converted into the corresponding parameter type supported by the browser.

[0052] The dynamic interface calling module is an open source component of the application software, and its purpose is to find the calling entry according to the symbol of the dynamic library, and then convert the parameters to realize the calling.

[0053] The dynamic library loading mechanism is specifically as follows: when loading a dynamic library, the dynamic linker of the operating system is first used to search for the dynamic library according to the specified path, and then the dynamic linker loads the library file into the virtual address space of the process through a system call. At this time, the code segment and data segment of the dynamic library are respectively mapped to executable or read-write memory areas. Then, the dynamic linker resolves the call to the library function or variable in the program through the symbol table. If the dynamic library itself also depends on other dynamic libraries, the dynamic linker will recursively load all dependent libraries until all libraries are loaded and resolved.

[0054] Step 3: Receive the return value fed back by the local component service.

[0055] Specifically, the local component service formats and assembles the interface return value, including converting it into a character type or a numerical type applicable to the browser side according to the output parameter type, and converting the return result into a corresponding character set according to the character set parameter in the request body. For the converted call result, a layer of the call result of the local component service is encapsulated to mark whether the call is successful, including success information or error information, and the success information or error information generated by the local component service call process is returned to the browser side for processing and display.

[0056] In one or more embodiments, a method for dynamically calling a local component for a browser is provided, which is applied to a local component service, and includes:

[0057] Step 1: responding to a local component service call request from a browser;

[0058] Step 2: Based on the component call information in the call request, parse the corresponding component configuration file to obtain formatted interface configuration information;

[0059] Step 3: Based on the obtained interface configuration information, relevant parameters are concatenated after interface parameter type conversion to obtain execution parameters;

[0060] Step 4: According to the execution parameters, the corresponding dynamic library is loaded through the preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a calling interface;

[0061] Step 5: Based on the calling interface, a local component function call is made, a return value is obtained, and the return value is fed back to the browser.

[0062] In one or more embodiments, Figure 1 As shown, a method for dynamically calling a local component of a browser is provided corresponding to the above embodiment, including:

[0063] Step 1: The browser sends a local component service call request to the local component service;

[0064] Step 2: Based on the component call information in the call request, dynamically call the local component through the local component service; wherein the local component service specifically performs the following processing: parse the corresponding component configuration file to obtain formatted interface configuration information; based on the obtained interface configuration information, concatenate the relevant parameters after interface parameter type conversion to obtain execution parameters; according to the execution parameters, load the corresponding dynamic library through the preset dynamic library loading mechanism, and encapsulate the function call of the corresponding interface in the dynamic library to generate a call interface; call the local component function based on the call interface to obtain a return value;

[0065] Step 3: The local component service feeds back the obtained return value to the browser.

[0066] For example, in order to more clearly illustrate the present invention, the technical details of the present invention are described in detail by taking the Node.js development language and the C / C++ development language as examples:

[0067] Example 1:

[0068] This embodiment provides a method for a browser to call a local component based on Node.js language development, including the following steps:

[0069] Encapsulate the connection JS file, implement Websocket communication through the MozWebSocket method of HTML in the JS file, and implement Http communication through Ajax request. It is necessary to detect whether the browser supports Websocket connection and whether it can connect to the local component service. The specific implementation method is to try to establish a connection with the local component service through the MozWebSocket method, and encapsulate and output it in the console according to the returned result. At the same time, it provides methods for encapsulated Websocket asynchronous call and Http synchronous call of local component service. In the method, you only need to pass in the component name, component interface, and component input parameter to be called, then you can request the local component service in the background to obtain the return result, assemble the returned result, and finally return it to the caller.

[0070] The browser uses the method in the connection JS file to establish a connection with the local component service using Websocket; or uses Ajax to send an HTTP request to the local component service.

[0071] The local component service is based on the WS (WebSocket instant messaging module) and Http (Http protocol module) modules of Node.js. It starts the listening service on the local machine and receives request information from a specific port (port 9539) in the local machine's 127.0.0.1 address.

[0072] For requests sent by the browser, the local component service distinguishes whether it needs to be processed based on the request source and request content, and forwards requests that do not need to be processed; specifically, first extract the Method in the request body:

[0073] 1. If it is a GET request, the URL module in Nodejs is used to parse the parameters in the request body, parse the requested address and file name, and use the FS module in Nodejs to parse the corresponding file in the local directory. If the corresponding file is not found, a 404 network error is returned. If the corresponding file is found, a message body in the corresponding format is returned according to the file extension.

[0074] 2. If it is an OPTIONS request, a 200 network success flag is returned directly.

[0075] 3. If it is a POST request, the URL module in Nodejs is used to parse the request body parameters. First, according to the request path, it is determined whether it is a request for a local component. For illegal requests, they are directly intercepted. For requests that need to be processed, that is, requests to call system local plug-ins, hardware, and dynamic libraries, the JSON method of the Typescript module in Nodejs is used to parse the request parameters, and they are processed separately according to the request type in the parameters.

[0076] According to the request type in the parameter, use Nodejs's Request to find the component configuration file in the corresponding directory. The configuration file is a JS file written according to the CommonJS module specification in Node.js. The read configuration file content is formatted content and can be directly referenced. After parsing the configuration file, obtain a detailed list of request type, module name, and interface information. Then, according to different request types, different processing is performed. The requests that need to be processed are mainly divided into three categories: call requests for Node.js's own modules; call requests for system Activex controls; and call requests for the system's underlying dynamic library .dll file interface.

[0077] Processing the call request of the Node.js built-in module: There are many practical functions in the Node.js module. The local component service integrates some commonly used Node.js modules, and encapsulates their interfaces and provides them for browser-side calls. After receiving the relevant request for the Node.js module, the local component service parses the corresponding configuration file in the local configuration file directory according to the corresponding module name. According to the module name in the configuration file, for unsupported modules, relevant prompt information is returned; for supported modules, Node.js's Request is used to introduce them, and according to the module interface in the configuration file, the relevant interface name and parameter type are obtained, and the corresponding interface is called to obtain relevant return information.

[0078] Processing of call requests for system Activex controls: After receiving the request for Activex controls, the local component service parses the corresponding configuration file in the local configuration file directory according to the corresponding module name. According to the module name in the configuration file, for unsupported modules, relevant prompt information is returned; for supported modules, according to the module interface in the configuration file, the relevant interface name and parameter type are obtained, the call statement is assembled, and the Winax module of Node.js is used to call the corresponding interface to obtain relevant return information.

[0079] Processing of call request for the underlying dynamic library .dll file of the system: After receiving the request for the underlying dynamic library interface, the local component service parses the corresponding configuration file in the local configuration file directory according to the corresponding dynamic library name. According to the module name in the configuration file, for unsupported modules, relevant prompt information is returned; for supported modules, the relevant dynamic library path, interface name, and parameter type are obtained according to the module interface in the configuration file; according to the original parameter type of the interface in the configuration file, it is converted into the parameter type format supported by the FFI module of Node.js, and the call statement is assembled, and the assembled call statement is passed to the FFI module of Node.js. Taking the dynamic library Libexample.dll as an example, the Calibrate interface is implemented in Libexample.dll developed in C language. Through the Calibrate symbol corresponding to the Calibrate interface, the external program can load Libexample.dll at runtime and call the Calibrate function. At the same time, the FFI module converts the parameter type of the passed-in interface into the corresponding parameter type of the C language, implements the call to the local component function, and obtains the return value.

[0080] After the local component service obtains the return result of the FFI module, based on the FFI mapping rules and the parameter type configuration item in the interface configuration information, the interface output parameter is converted into a data type supported by the browser. For example, when the parameter type is Char*, the Decode method of the Iconv module in Nodejs is used to convert the parameter data into a string type supported by the browser. At the same time, a layer of JSON format is assembled based on the return result. For successful calls, a success message is added. For failed calls, a layer of error information is packaged based on the error type. Finally, the assembled result is returned to the browser.

[0081] Example 2:

[0082] This embodiment provides a method for browser to call local components based on C language and C++ language development. Its encapsulation and connection JS file method and the steps of the browser sending Websocket or Http request to the local component service are consistent with Example 1, and will not be repeated here. The difference is that the local component service is based on the Libwebsockets class library (Websocket instant messaging module) of C language and the Http class library (Http protocol module) and Libevent class library (Http server) of C++ language, and starts the service process on the local machine to listen to and receive request information from the specific port (9539) of the local machine's 127.0.0.1 address.

[0083] For requests sent by the browser, the local component service distinguishes whether they need to be processed based on the request source and request content, and forwards requests that do not need to be processed; specifically, first use the JSON method in the Json-C class library to parse the request body and extract the Method in the request body:

[0084] 1. If it is a GET request, the JSON method is used to parse the parameters in the request body, parse the requested address and file name, and use the Fopen file operation module in the C++ standard library to parse the corresponding file in the local directory. If the corresponding file is not found, a 404 network error is returned. If the corresponding file is found, a message body in the corresponding format is returned according to the file extension.

[0085] 2. If it is an OPTIONS request, a 200 network success flag is returned directly.

[0086] If it is a POST request, the request body parameters are parsed using the JSON method. First, based on the request path, it is determined whether it is a request for requesting a local component. For illegal requests, they are directly intercepted. For requests that need to be processed, i.e., requests for calling system local plug-ins, hardware, and dynamic libraries, the corresponding configuration file is found in the configuration file of the local component service according to the module name, and the relevant configuration file is parsed to obtain a detailed list of request type, module name, and interface information. In this embodiment, the only request type is calling the system local dynamic library (.so file).

[0087] Processing of call requests for the underlying dynamic library .so file of the system: After the local component service receives the request for the underlying dynamic library interface, it uses the json_object_from_file method in the C-Json class library to parse the component configuration file in the corresponding directory according to the corresponding dynamic library name. The configuration file is a JSON file written in accordance with the JSON specification, and the configuration file content read is the formatted content. According to the module name in the configuration file, for unsupported modules, the module whose corresponding file is not found returns relevant error information; for supported modules, according to the module interface in the configuration file, obtain relevant dynamic library path, interface name, parameter type and other information.

[0088] According to the original parameter type of the interface in the configuration file, according to the FFI mapping rules, it is converted into the parameter type format supported by the C++ Libffi module, and the calling parameter array information is assembled. The assembled parameter array information, dynamic library information, and called interface information are passed to the FFI_call method of the C++ Libffi module. Taking the dynamic library Libexample.so as an example, the Calculate interface is implemented in Libexample.so developed in C language. Through the Calculate symbol corresponding to the Calculate interface, the external program can load Libexample.so at runtime and call the Calculate function. At the same time, the FFI_call method converts the interface parameter type passed in into the parameter type corresponding to the C language, implements the call to the local component function, and obtains the return value.

[0089] After the local component service obtains the return result of the FFI module, based on the FFI mapping rules and the parameter type configuration item in the interface configuration information, the interface output parameter is converted into the data type supported by the browser, and the coded character set conversion is performed. For example, when the output parameter type is a character set in GBK format, the Code_convert method of the Iconv class library of C++ is used to convert it into GBK format. At the same time, according to the return result, a layer of JSON format is assembled. For successful calls, a success message is added. For failed calls, a layer of error information is packaged according to the error type. Finally, the assembled result is returned to the browser.

[0090] In one or more embodiments, a local component dynamic invocation system for a browser is provided, comprising:

[0091] The browser is used to send a local component service call request to the local component service, and receive a local component call return value obtained from the local component service;

[0092] A local component service is used to receive a local component service call request from a browser, and based on the component call information in the call request, parse the corresponding component configuration file to obtain formatted interface configuration information; based on the obtained interface configuration information, concatenate related parameters after interface parameter type conversion to obtain execution parameters; based on the execution parameters, load the corresponding dynamic library through a preset dynamic library loading mechanism, and encapsulate the function call of the corresponding interface in the dynamic library to generate a call interface; based on the call interface, call the local component function, obtain the return value, and feed it back to the browser.

[0093] Specifically, for ease of understanding, the system described in this embodiment is described in detail below with reference to the accompanying drawings:

[0094] like Figure 2 As shown, a local component dynamic calling system for a browser includes a browser and a local component service. The browser and the local component service communicate with each other through a network communication module. The local component service can be divided into a parameter processing module, a dynamic calling module, a result assembly module and an automatic update module.

[0095] The network communication module 101 is used to realize the communication between the browser and the local component service, monitor, forward, and receive the call request sent by the browser to the local component service, and transmit the result returned by the local component to the browser. Specifically, it includes an Http communication module 1011, a Websocket communication module 1012, and a message parsing module 1013.

[0096] The Http communication module 1011 is used to monitor, forward, and receive Http requests sent by the browser to the local component service.

[0097] The WebSocket communication module 1012 is used to monitor, forward, and receive WebSocket requests sent by the browser to the local component service.

[0098] The message parsing module 1013 is used to parse the request address, parameters, message header information, etc. in the message body.

[0099] The parameter processing module 102 is used to parse the component configuration file corresponding to the request parameter, obtain the formatted interface configuration information, and convert the interface parameter type according to the interface configuration information corresponding to the component configuration file, splice related parameters, and form execution parameters. Specifically, it includes a file reading module 1021, a configuration file parsing module 1022, and a parameter type conversion module 1023.

[0100] The file reading module 1021 is used to read the local configuration file.

[0101] The configuration file parsing module 1022 is used to format the content in the configuration file and extract key information.

[0102] The parameter type conversion module 1023 is used to convert and splice the interface parameter information in the configuration file into execution parameters corresponding to the dynamic call module.

[0103] The dynamic calling module 103 is used to pass in execution parameters, dynamically call the corresponding interface component, and obtain the return value. It is characterized in that there is no need to declare the interface parameter type in advance. When the program is running, the interface parameter type is specified according to the passed-in parameters, so that the component interface can be dynamically called at runtime. It specifically includes a library loading module 1031, a symbol parsing module 1032, a data type conversion module 1033, a call encapsulation module 1034, and an error handling module 1035.

[0104] The library loading module 1031 is used to load the dynamic library when the program is running, and can realize loading and unloading the library.

[0105] The symbol resolution module 1032 is used to obtain the symbol address and search for symbols and interfaces in the loaded dynamic library.

[0106] The data type conversion module 1033 is used for mapping and converting data types, converting the data type of the caller language into the data type of the callee language, and performing reverse conversion.

[0107] The call encapsulation module 1034 is used to provide an interface for function calls, process parameter transfer and return value acquisition, and encapsulate calls to functions in dynamic libraries to make the calls concise and safe.

[0108] The error handling module 1035 is used to handle errors that occur during the process of loading libraries, resolving symbols, calling functions, etc.

[0109] The result assembly module 104 is used for the local component service to format and assemble the interface return value and return it to the browser end, and specifically includes an output parameter type conversion module 1041 , a character set conversion module 1042 , and a result information packaging module 1043 .

[0110] The output parameter type conversion module is used to convert the output parameters of the dynamic call module into the parameter type supported by the local component service program according to the configuration file.

[0111] The character set conversion module is used to convert the output character set format into the corresponding character set according to the character set parameters in the request body.

[0112] The result information encapsulation module is used to encapsulate the results, including the processing of error information.

[0113] The automatic update module 105 implements the distribution and update of the interface configuration file and the plug-in file, and realizes a set of programs to manage all the plug-ins, which is convenient for maintenance and update. Specifically, it includes an Http communication module 1051, a file download module 1052, a file reading module 1053, an update configuration file parsing module 1054, and an MD5 verification module 1055.

[0114] Http communication module, used to communicate with the update server.

[0115] The file download module is used to download the corresponding file to a local folder according to the request address.

[0116] The file reading module is used to read the local update configuration file and the downloaded server configuration file.

[0117] Update configuration file parsing module: used to parse the update configuration file and extract the content and description information that need to be downloaded.

[0118] The MD5 verification module is used to generate the MD5 values ​​of local files and server-side files for comparison and verification to verify the file integrity.

[0119] Those skilled in the art will appreciate that the units, i.e., algorithm steps, of the various examples described in the present embodiment can be implemented in electronic hardware or in a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0120] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for dynamically calling a local component of a browser, which is applied to the browser and is characterized in that: include: Send a local component service call request to the local component service; Based on the component call information in the call request, the local component is dynamically called through the local component service; wherein the local component service specifically performs the following processing procedures: the corresponding component configuration file is parsed to obtain the formatted interface configuration information; based on the obtained interface configuration information, the relevant parameters are spliced ​​after the interface parameter type conversion to obtain the execution parameters; according to the execution parameters, the corresponding dynamic library is loaded through the preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a call interface; based on the call interface, the local component function is called to obtain the return value; Receive the return value of the local component service feedback.

2. A method for dynamically calling a local component of a browser as claimed in claim 1, characterized in that: The method loads the corresponding dynamic library through a preset dynamic library loading mechanism, and encapsulates the function call of the corresponding interface in the dynamic library to generate a calling interface. Specifically, based on the execution parameters, the corresponding dynamic library is loaded using the preset dynamic library loading mechanism, the target symbol and interface corresponding to the calling request are searched in the loaded dynamic library, the data type of the caller language is converted into the data type of the callee language, and then the call of the function in the dynamic library is encapsulated to form a calling interface.

3. A method for dynamically calling a local component of a browser as claimed in claim 2, characterized in that: The dynamic library loading mechanism is specifically as follows: when loading a dynamic library, the dynamic library is first searched for according to a specified path by the dynamic linker of the operating system; the dynamic linker loads the library file into the virtual address space of the process through a system call; the dynamic linker resolves the call to the library function or variable in the program through a symbol table.

4. A method for dynamically calling a local component of a browser as claimed in claim 1, characterized in that: Based on the obtained interface configuration information, relevant parameters are spliced ​​after interface parameter type conversion to obtain execution parameters. Specifically, based on the input parameter type configuration item in the interface configuration information, the formatted interface parameter type is converted into a parameter type supported by a preset mapping rule, and according to the component detailed information in the interface configuration information, the storage location information, name information and interface information of the requested component are spliced ​​to obtain execution parameters.

5. A method for dynamically calling a local component of a browser as claimed in claim 1, characterized in that: The parsing of the corresponding component configuration file to obtain the formatted interface configuration information is specifically: based on the module name and interface name in the call request, the component configuration file is parsed to obtain the formatted interface configuration information including component detailed information and interface parameter information.

6. A method for dynamically calling a local component of a browser as claimed in claim 1, characterized in that: The local component service intercepts and forwards the call requests of non-Localhost and loopback addresses, receives the call requests other than the localhost and loopback addresses, and executes the dynamic call of the local component.

7. A method for dynamically calling a local component of a browser, which is applied to a local component service, characterized in that: include: Responding to a local component service call request from a browser; Based on the component call information in the call request, the corresponding component configuration file is parsed to obtain formatted interface configuration information; Based on the obtained interface configuration information, relevant parameters are concatenated after interface parameter type conversion to obtain execution parameters; According to the execution parameters, the corresponding dynamic library is loaded through a preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a calling interface; Based on the calling interface, a local component function call is performed to obtain a return value, which is fed back to the browser.

8. A method for dynamically calling a local component of a browser, characterized in that: include: The browser sends a local component service call request to the local component service; Based on the component call information in the call request, the local component is dynamically called through the local component service; wherein the local component service specifically performs the following processing procedures: the corresponding component configuration file is parsed to obtain the formatted interface configuration information; based on the obtained interface configuration information, the relevant parameters are spliced ​​after the interface parameter type conversion to obtain the execution parameters; according to the execution parameters, the corresponding dynamic library is loaded through the preset dynamic library loading mechanism, and the function call of the corresponding interface in the dynamic library is encapsulated to generate a call interface; based on the call interface, the local component function is called to obtain the return value; The local component service feeds back the obtained return value to the browser.

9. A local component dynamic calling system for a browser, characterized in that: include: The browser is used to send a local component service call request to the local component service, and receive a local component call return value obtained from the local component service; A local component service is used to receive a local component service call request from a browser, and based on the component call information in the call request, parse the corresponding component configuration file to obtain formatted interface configuration information; based on the obtained interface configuration information, concatenate related parameters after interface parameter type conversion to obtain execution parameters; based on the execution parameters, load the corresponding dynamic library through a preset dynamic library loading mechanism, and encapsulate the function call of the corresponding interface in the dynamic library to generate a call interface; based on the call interface, call the local component function, obtain the return value, and feed it back to the browser.

10. An electronic device comprising a memory, a processor and a computer program stored and running on the memory, characterized in that: When the processor executes the program, the method for dynamically calling a local component for a browser as described in any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Service-based browser and fingerprint instrument calling method

    CN110175055A

  • Method for calling operating system through webpage

    CN116450383A