Method and device for decoupling jsbridge and scheme based on Hongmeng webview container
By defining fzJSExportObject and schemeMap variables in the Hongmeng native webview component, combined with the two-way communication method of the FZJSExportObject class, the problem of difficulty in decoupling jsbridge and scheme in the webview component is solved, and the ability to reuse webview components on multiple web services is realized, improving development efficiency and performance.
Patent Information
- Application Number
- CN202411497564.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-10-25
AI Technical Summary
Due to its highly object-oriented properties, Hongmeng native webview components cannot support the decoupling of scheme and jsbridge well, making it difficult to apply to the multiplexing of product matrix.
By defining the fzJSExportObject variable and schemeMap variable in the webview component, jsbridge is decoupled, and the two-way communication between the webview component and the web business end is realized through the FZJSExportObject class, and the scheme is decoupled.
It realizes the decoupling of jsbridge and scheme, allowing multiple web service terminals to reuse the same webview component, improving development efficiency and performance.
Smart Images

Figure CN119011686B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of mobile application development, and in particular to a method and device for decoupling jsbridge and scheme based on the Hongmeng webview container. Background Art
[0002] HarmonyOS native webview component is a component based on Web technology, which can embed Web content in HarmonyOS application. By using the webview component, Web pages or applications can be embedded into HarmonyOS applications to achieve richer user interfaces and functions. Web components provide a series of APIs and tools so that developers can use these APIs and tools to control and operate embedded Web pages.
[0003] However, since the current HarmonyOS native framework is in the development and start-up stage, the webview group of the HarmonyOS native framework has its own properties and methods and is highly object-oriented. It has not been applied in large-scale product matrices, and small product matrices do not need to use webview containers in depth. Therefore, there is currently no general container library on the market that deeply encapsulates webview to adapt to multi-matrix products.
[0004] In addition, under normal circumstances, the webview component will not parse or process the protocol part (scheme) in the URL by default, but will directly load the resources specified by the URL without performing specific actions based on different protocols, making it difficult for the webview component to identify the protocol and meet the development needs of developers.
[0005] At the same time, JavaScript written in the webview component can call the API provided by the local application. However, when the webview component handles the complex requirements of the JavaScript Bridge (JSBridge), it usually needs to adopt a more tightly coupled approach to implement the corresponding functions, which makes it difficult to decouple the JavaScript Bridge.
[0006] In other words, the current native webview components of Hongmeng are highly object-oriented and cannot support the decoupling of scheme and jsbridge well, making it difficult to be well applied to the reuse of the product matrix. Summary of the invention
[0007] An embodiment of the present application provides a method and device for decoupling jsbridge and scheme based on the Hongmeng webview container, by defining the fzJSExportObject variable in the webview component and assigning a derived instance of the FZJSExportObject class to the fzJSExportObject variable to decouple jsbridge, and detecting the scheme link of the web business end through the schemeMap variable to jump externally to decouple the scheme.
[0008] In a first aspect, an embodiment of the present application provides a method for decoupling jsbridge and scheme based on a Hongmeng webview container, the method comprising:
[0009] In the Hongmeng native webview component, define the fzJSExportObject variable and schemeMap variable and encapsulate them into a har package. The initial value of the fzJSExportObject variable is empty, and the schemeMap variable defines a method for intercepting and detecting the scheme link of the web business end and transparently passing the scheme link to the web business end for redirection.
[0010] Define the FZJSExportObject class on the web business end, declare the fzJSExportObject variable as the FZJSExportObject class, and assign the instance derived from the FZJSExportObject class to the fzJSExportObject variable to perform two-way communication between the webview component and the web business end. The method for two-way communication between the web business end and the webview component is declared in the FZJSExportObject class.
[0011] In a second aspect, an embodiment of the present application provides a device for decoupling jsbridge and scheme based on the Hongmeng webview container, including:
[0012] Define a module for defining fzJSExportObject and schemeMap variables in the Hongmeng native webview component and encapsulating them into a har package. The initial value of the fzJSExportObject variable is empty, and the schemeMap variable defines a method for intercepting and detecting the scheme link of the web business end and transparently transmitting the scheme link to the web business end for redirection.
[0013] The communication module is used to define the FZJSExportObject class on the web business end, declare the fzJSExportObject variable as the FZJSExportObject class, and assign the instance derived from the FZJSExportObject class to the fzJSExportObject variable to perform two-way communication between the webview component and the web business end. The method for two-way communication between the web business end and the webview component is declared in the FZJSExportObject class.
[0014] In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute a method for decoupling jsbridge and scheme based on the Hongmeng webview container.
[0015] In a fourth aspect, an embodiment of the present application provides a readable storage medium, in which a computer program is stored. The computer program includes a program code for controlling a process to execute a process, and the process includes a method for decoupling jsbridge and scheme based on the Hongmeng webview container.
[0016] The main contributions and innovations of the present invention are as follows:
[0017] The embodiment of the present application defines an fzJSExportObject variable with an initial value of empty in the Hongmeng native webview component, defines an FZJSExportObject class on the web business end, and assigns a derived instance of the FZJSExportObject class to the fzJSExportObject variable to complete the injection of the Jsbridge object, so that multiple web business ends in the project matrix can call the same webview component to load web pages, thereby realizing the decoupling of jsbridge; the embodiment of the present application intercepts the scheme link customized by the web business end by defining a schemeMap variable that only intercepts scheme links, so that the web business end can jump to the customized scheme link through the webview component.
[0018] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 It is a flowchart of a method for decoupling jsbridge and scheme based on the Hongmeng webview container according to an embodiment of the present application;
[0021] Figure 2 It is a structural block diagram of a device for decoupling jsbridge and scheme based on the Hongmeng webview container according to an embodiment of the present application;
[0022] Figure 3 It is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0023] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0024] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0025] Embodiment 1
[0026] The embodiment of the present application provides a method for decoupling jsbridge and scheme based on the Hongmeng webview component, by defining the fzJSExportObject variable in the webview component, and assigning the derived instance of the FZJSExportObject class to the fzJSExportObject variable to decouple jsbridge, and detecting the scheme link of the web service end through the schemeMap variable to jump to the decoupled scheme externally. Specifically, refer to Figure 1 , the method comprising:
[0027] In the Hongmeng native webview component, define the fzJSExportObject variable and schemeMap variable and encapsulate them into a har package. The initial value of the fzJSExportObject variable is empty, and the schemeMap variable defines a method for intercepting and detecting the scheme link of the web business end and transparently passing the scheme link to the web business end for redirection.
[0028] Define the FZJSExportObject class on the web business end, declare the fzJSExportObject variable as the FZJSExportObject class, and assign the instance derived from the FZJSExportObject class to the fzJSExportObject variable to perform two-way communication between the webview component and the web business end. The method for two-way communication between the web business end and the webview component is declared in the FZJSExportObject class.
[0029] Jsbridge is a technology used to implement two-way communication between JavaScript code in Webview and the web business end. The communication method of each web business end may be different. For example, web business end A chooses to retain the communication, while web business end B chooses not to retain the communication. In the Hongmeng system, due to the weak support for Webview, the decoupling of jsbridge cannot be achieved, resulting in the need to build a separate Webview component for each web business end.
[0030] Therefore, this solution defines an fzJSExportObject variable with an empty initial value in the Hongmeng native webview component, defines the FZJSExportObject class on the web business side, and assigns the instance derived from the FZJSExportObject class to the fzJSExportObject variable to complete the injection of the Jsbridge object and achieve the decoupling effect.
[0031] In this solution, the derived instance of the FZJSExportObject class is assigned to the fzJSExportObject variable through the onControllerAttached interceptor in the webview component.
[0032] Furthermore, before any web service end in the project matrix assigns a derived instance of the FZJSExportObject class to the fzJSExportObject variable, the fzJSExportObject variable is set to an initial value.
[0033] That is to say, when there is a web business end in the project matrix that wants to communicate with the webview component, the value in the fzJSExportObject variable will be set to empty first. This can avoid the impact of other previous web business ends on the webview component, thereby realizing the reuse of the webview component and achieving the effect of decoupling jsbridge.
[0034] Specifically, the way to define the fzJSExportObject variable in the webview component is:
[0035] fzJSExportObject: FZJSExportObject | null = null;
[0036] The above code string indicates that the fzJSExportObject variable is assigned a value using the FZJSExportObject class. The initial value of fzJSExportObject is null.
[0037] In some specific embodiments, there is an English dubbing software and an English video teaching software. When the English dubbing software needs to communicate with the webview component to load a web page, the communication method is A, and when the English video teaching software needs to communicate with the webview component to load a web page, the communication method is B. After the English dubbing software communicates with the webview component, the fzJSExportObject variable in the webview component is the FZJSExportObject class of the English dubbing software. When the English video teaching software communicates with the webview component again, the value of the fzJSExportObject variable will be set to empty, thereby realizing two-way communication between the webview component and the English video teaching software, realizing decoupling jsbridge, and achieving the effect of reusing the webview component.
[0038] In this solution, the web business end is any software in a large-scale matrix product, such as English dubbing software, English teaching software, and AI foreign teacher software belonging to the same company. When these software load web pages based on the webview component, they often use the same logic to write the code. Therefore, the reuse of the webview component through the decoupled jsbridge and scheme methods can save a lot of loading time and technical personnel's development time.
[0039] In this solution, the FZJSExportObject class is a virtual base class. The methods for two-way communication between the web service end and the webview component declared in the FZJSExportObject class include the routing stack, the Webview controller, whether to refresh, whether to retain, the fallback retention method, the general web service end side bridge method, the webview component side bridge method, and the method for obtaining dynamic class instances.
[0040] In some specific embodiments, the code of the FZJSExportObject class is shown below:
[0041] export abstract class FZJSExportObject {
[0042] abstract pathStack: NavPathStack; / / routing stack
[0043] abstract controller: webview.WebviewController; / / webview controller
[0044] abstract backRefresh: number; / / Whether refresh is needed
[0045] abstract isRetain: boolean; / / Whether to retain
[0046] abstract RetainCallback: string; / / Fallback retention method
[0047] abstract nativeCallJs(actionName: string, data: CommonObj): void; / / General web business side bridge method
[0048] abstract jsCallback(callee: string): void; / / Bridge method on the webview component side
[0049] / / The injected jsObject must be returned by this method to dynamically inject pathStack and controller
[0050] abstract getInstance(pathStack: NavPathStack, controller:webview.WebviewController): FZJSExportObject
[0051] }
[0052] Specifically, the routing stack is used to manage the page navigation history within the application. Whenever a user visits a new page, the new path will be pushed to the top of the stack; when the user goes back, the path at the top of the stack will be popped out. This helps keep the user's navigation experience smooth and consistent.
[0053] Specifically, the Webview controller is used to control the behavior of the Web view, such as loading URLs, executing JavaScript codes, managing page life cycles, etc.
[0054] Specifically, whether refresh is needed is used to specify whether the previous page needs to reload or refresh data when the user returns to the previous page from the current page.
[0055] Specifically, whether to retain is used to display a prompt dialog box to ask the user whether he really wants to leave when the user tries to leave a page. If retention is set, a confirmation dialog box will be displayed.
[0056] Specifically, the fallback retention method is used when retention is set. This method specifies a callback function that should be executed when the user chooses to continue to stay on the current page.
[0057] Specifically, the general web service end-side bridge method allows native code to call JavaScript code to achieve communication between native and web views.
[0058] Specifically, the h5-side bridge method allows JavaScript in the web view to call native code, enabling communication between the web view and the native application.
[0059] Furthermore, since the FZJSExportObject class is a virtual base class, the business logic desired by the web business end can be inherited into the FZJSExportObject class to obtain a derived instance of the FZJSExportObject class and assign it to the fzJSExportObject variable to complete the two-way communication between the webview component and the web business end.
[0060] Specifically, the two-way communication between the webview component and the web business end requires the transparent transmission of data and functions on the web business end, but we cannot introduce business classes or objects in the general library. Then we can only implement the class definition in the general library through the virtual base class, and implement the class on the web business end. In this way, after we get the instance object in the general library and assemble it according to some data and instance methods in the general library, we can cleverly realize the desired instance transparent transmission and achieve the goal of decoupling.
[0061] Specifically, since it is necessary to implement various web business functions on the web page in the webview component, such as saving pictures, taking photos, jumping to other web business pages or default browsers and other app mini-programs, and all these functions need to be dynamically linked and implemented through pathStack and controller in Hongmeng, this solution dynamically writes pahtStack and controller into registerJavaScriptProxy and injects them into the webview component. egisterJavaScriptProxy provides a function that gives the capabilities of the Hongmeng client to the web page in the webview component, so that users can implement the functions of the web business end in the web page. Therefore, dynamically writing pahtStack and controller into registerJavaScriptProxy and injecting them into the object of the webview component can enable the web page in the webview component to call most of the web business end functions. In particular, pathStack is dynamically constructed when the project is running, and does not exist directly when the project is compiled, so it must be dynamically injected when the program is running.
[0062] For example, an instance derived from the FZJSExportObject class is shown below:
[0063] export class DiyFZJSExportObject extends FZJSExportObject {
[0064] pathStack: NavPathStack;
[0065] controller: webview.WebviewController;
[0066] public backRefresh: number = 0;
[0067] public isRetain: boolean = false;public RetainCallback: string = ''
[0068] private schemeName: string;
[0069] constructor(schemeName: string) {
[0070] super()
[0071] this.pathStack = new NavPathStack();
[0072] this.controller = new webview.WebviewController;
[0073] this.schemeName = schemeName
[0074] }
[0075] getInstance(pathStack: NavPathStack, controller:webview.WebviewController) {
[0076] this.pathStack = pathStack;
[0077] this.controller = controller;
[0078] return this
[0079] }
[0080] nativeCallJs(actionName: string, data: CommonObj) {
[0081] this.controller.runJavaScript(
[0082] `${actionName}(${JSON.stringify(JSON.stringify(data))})`, )
[0084] }
[0085] jsCallback(callee: string) {
[0086] let actionJson: JSONObject = JSONObject.parse(callee)
[0087] let action = actionJson.get("action");
[0088] let backRefresh = actionJson.get("backRefresh") as number;
[0089] let content = actionJson.get('content') as string;
[0090] let delta = actionJson.get('delta') as number;
[0091] / / Refresh flag
[0092] this.backRefresh = backRefresh;
[0093] switch (action) {
[0094] case 54:
[0095] this.action54(delta);
[0096] break;
[0097] }
[0098] }
[0099] }
[0100] In this solution, the schemeMap variable intercepts and detects the scheme link of the web business end based on the onLoadIntercept interceptor in the webview component.
[0101] Furthermore, the schemeMap variable is a function variable, and the code of the schemeMap variable is expressed as:
[0102] schemeMap: SchemeMap = (url: string, pathStack: NavPathStack) =>false
[0103] The meaning of the code is that SchemeMap receives two parameters, url and pathStack, and returns a Boolean value. The initial value is a default function that always returns false, indicating that no URL is intercepted.
[0104] Specifically, scheme link is a technology used for navigation and data transmission between mobile applications or from browser to mobile application. That is to say, when scheme link appears in the communication between web service end and webview component, it means that web service end needs to use webview component to jump to another specific web page, for example, it can jump from English dubbing software to English video teaching software, and conventional webview components often do not support such jump. Therefore, this scheme detects the scheme link of web service end by defining schemeMap variable. That is to say, when schemeMap variable detects and intercepts scheme link through onLoadIntercept interceptor, it will jump to the scheme link, so as to realize the jump to another web page.
[0105] It is worth mentioning that the schemeMap variable in this solution will filter normal jumps such as http links, and will only intercept custom schme links. The implementation logic of SchemeMap is as follows:
[0106] export function SchemeMap(url: string, pathStack: NavPathStack):boolean {
[0107] / / Website
[0108] if (WebUtil.isHttpLink(url)) {
[0109] return false
[0110] }
[0111] / / schema
[0112] if (WebUtil.isScheme(url)) {
[0113] let schemaName = WebUtil.getSchemeName(url);
[0114] if (schemaName == 'diyscheme') {
[0115] let path = WebUtil.getSchemePath(url);
[0116] let params = WebUtil.getSchemeParams(url);
[0117] / / test page
[0118] if (path == 'test') {
[0119] / / do something
[0120] }
[0121] }
[0122] return true
[0123] }
[0124] return false;
[0125] }
[0126] From the implementation of schemeMap, we can know that schemeMap detects and filters http and other links, intercepts custom schme links, and performs business processing.
[0127] For example, when the English dubbing software detects that the pronunciation is not standard during use, it is necessary to jump to the English video teaching software for teaching through the webview component. When the schemeMap variable detects and intercepts the custom scheme link that jumps to the English video teaching software through the onLoadIntercept interceptor, it will jump to the English video teaching software.
[0128] In this solution, the scheme link is transparently transmitted to the web business end for jump through the two-way communication between the webview component and the web business end.
[0129] Specifically, for a scheme link, the jump of each software in the project matrix is different. For example, software A needs to jump to software B, and software B needs to jump to software C. Therefore, the schme link will not be processed in the conventional webview component. This solution defines the schemeMap variable to intercept the scheme link separately, so the scheme link can be identified without affecting other links such as http links, and the scheme link is transmitted to the web business end for loading through two-way communication, thereby realizing the decoupling of the scheme and avoiding affecting the reuse of the webview component.
[0130] In some specific embodiments, the webview component loading code is as follows:
[0131] FzWebview({
[0132] appVersion: BuildProfile.APP_VERSION,
[0133] appName: BuildProfile.APP_NAME,
[0134] schemeName: BuildProfile.SCHEME_NAME,
[0135] schemeMap: SchemeMap, / / passed in via parameters
[0136] fzJSExportObject: new DiyFZJSExportObject(BuildProfile.SCHEME_NAME) / / passed in through parameters
[0137] })
[0138] Specifically, when the webview component is called on the web business side, the webview component is loaded through the webview component loading code. When the webview component is loaded, the custom schemeMap method and the custom DiyFZJSExportObject class of the web business side are passed into the initialized webview component.
[0139] In some specific embodiments, the code called by DiyFZJSExportObject is expressed as follows:
[0140] .onControllerAttached(() =>{
[0141] / / Register Agent
[0142] if (this.fzJSExportObject) {
[0143] this.controller.registerJavaScriptProxy(this.fzJSExportObject.getInstance(this.pathStack,
[0144] this.controller), "fZJSExportObject", ["jsCallback"])
[0145] }
[0146] / / Initialize on entry
[0147] this.controller.loadUrl(this.url);
[0148] })
[0149] Here, dynamic injection is performed through registerJavaScriptProxy, which can cleverly pass the runtime pathStack and controller to the business of the matrix project.
[0150] Embodiment 2
[0151] Based on the same idea, refer to Figure 2 , this application also proposes a device for decoupling jsbridge and scheme based on Hongmeng webview container, including:
[0152] Define a module for defining fzJSExportObject and schemeMap variables in the Hongmeng native webview component and encapsulating them into a har package. The initial value of the fzJSExportObject variable is empty, and the schemeMap variable defines the interception and detection of the scheme link of the web business end and transparently transmits the scheme link to the web business end for redirection.
[0153] The communication module is used to define the FZJSExportObject class on the web business end, associate the FZJSExportObject class with the fzJSExportObject variable, and assign the FZJSExportObject class to the fzJSExportObject variable to perform two-way communication between the webview component and the web business end. The FZJSExportObject class declares a method for two-way communication between the web business end and the webview component.
[0154] Embodiment 3
[0155] This embodiment also provides an electronic device, referring to Figure 3 , comprises a memory 404 and a processor 402, wherein the memory 404 stores a computer program, and the processor 402 is configured to run the computer program to execute the steps in any of the above method embodiments.
[0156] Specifically, the processor 402 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0157] Among them, the memory 404 may include a large capacity memory 404 for data or instructions. For example, but not limitation, the memory 404 may include a hard disk drive (HDD), a floppy disk drive, a solid state drive (SSD), a flash memory, an optical disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive, or a combination of two or more of these. In appropriate cases, the memory 404 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 404 may be inside or outside the data processing device. In a specific embodiment, the memory 404 is a non-volatile memory. In a specific embodiment, the memory 404 includes a read-only memory (ROM) and a random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (Programmable Read-Only Memory, PROM for short), an erasable PROM (Erasable Programmable Read-Only Memory, EPROM for short), an electrically erasable PROM (Electrically Erasable Programmable Read-Only Memory, EEPROM for short), an electrically alterable ROM (Electrically Alterable Read-Only Memory, EAROM for short) or a flash memory (FLASH) or a combination of two or more of these. In appropriate circumstances, the RAM may be a static random access memory (SRAM) or a dynamic random access memory (DRAM), wherein the DRAM may be a fast page mode dynamic random access memory 404 (FPMDRAM), an extended data output dynamic random access memory (EDODRAM), a synchronous dynamic random access memory (SDRAM), etc.
[0158] The memory 404 may be used to store or cache various data files required for processing and / or communication, as well as possible computer program instructions executed by the processor 402 .
[0159] The processor 402 reads and executes computer program instructions stored in the memory 404 to implement any one of the methods for decoupling jsbridge and scheme based on the Hongmeng webview container in the above embodiments.
[0160] Optionally, the electronic device may further include a transmission device 406 and an input / output device 408 , wherein the transmission device 406 is connected to the processor 402 , and the input / output device 408 is connected to the processor 402 .
[0161] The transmission device 406 can be used to receive or send data via a network. Specific examples of the above-mentioned network may include a wired or wireless network provided by a communication provider of the electronic device. In one example, the transmission device includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 406 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0162] The input / output device 408 is used to input or output information. In this embodiment, the input information may be fzJSExportObject variable and schemeMap variable, etc., and the output information may be the jump result of the custom scheme link.
[0163] Optionally, in this embodiment, the processor 402 may be configured to perform the following steps through a computer program:
[0164] In the Hongmeng native webview component, define the fzJSExportObject variable and schemeMap variable and encapsulate them into a har package. The initial value of the fzJSExportObject variable is empty, and the schemeMap variable defines a method for intercepting and detecting the scheme link of the web business end and transparently passing the scheme link to the web business end for redirection.
[0165] Define the FZJSExportObject class on the web business end, declare the fzJSExportObject variable as the FZJSExportObject class, and assign the instance derived from the FZJSExportObject class to the fzJSExportObject variable to perform two-way communication between the webview component and the web business end. The method for two-way communication between the web business end and the webview component is declared in the FZJSExportObject class.
[0166] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0167] In general, various embodiments may be implemented in hardware or dedicated circuits, software, logic, or any combination thereof. Some aspects of the invention may be implemented in hardware, while other aspects may be implemented in firmware or software that may be executed by a controller, microprocessor, or other computing device, but the invention is not limited thereto. Although various aspects of the invention may be shown and described as block diagrams, flow charts, or using some other graphical representation, it should be understood that, as non-limiting examples, the boxes, devices, systems, techniques, or methods described herein may be implemented in hardware, software, firmware, dedicated circuits or logic, general-purpose hardware or controllers or other computing devices, or some combination thereof.
[0168] Embodiments of the present invention may be implemented by computer software that is executable by a data processor of a mobile device, such as in a processor entity, or by hardware, or by a combination of software and hardware. Computer software or programs (also referred to as program products) including software routines, applets and / or macros may be stored in any device-readable data storage medium, and they include program instructions for performing specific tasks. A computer program product may include one or more computer executable components configured to perform an embodiment when the program is run. One or more computer executable components may be at least one software code or a portion thereof. In addition, at this point, it should be noted that, for example, Figure 3 Any block of the logic flow in the program may represent program steps, or interconnected logic circuits, blocks and functions, or a combination of program steps and logic circuits, blocks and functions. The software may be stored on physical media such as memory chips or storage blocks implemented within a processor, magnetic media such as hard disks or floppy disks, and optical media such as, for example, DVDs and their data variants, CDs, etc. Physical media are non-transitory media.
[0169] Those skilled in the art should understand that the technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0170] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for decoupling jsbridge and scheme based on Hongmeng webview container, characterized in that: The following steps are involved: In the Hongmeng native webview component, define the fzJSExportObject variable and the schemeMap variable and encapsulate them into a har package, where the initial value of the fzJSExportObject variable is empty, and the schemeMap variable defines a method for intercepting and detecting the scheme link of the web business end and transparently passing the scheme link to the web business end for redirection. The schemeMap variable intercepts and detects the scheme link of the web business end based on the onLoadIntercept interceptor in the webview component, and transparently passes the scheme link to the web business end for redirection through the two-way communication between the webview component and the web business end; Define the FZJSExportObject class on the web business end, declare the fzJSExportObject variable as the FZJSExportObject class, and assign the instance derived from the FZJSExportObject class to the fzJSExportObject variable to perform two-way communication between the webview component and the web business end. Before any web business end in the project matrix assigns the instance derived from the FZJSExportObject class to the fzJSExportObject variable, set the fzJSExportObject variable to the initial value. The FZJSExportObject class declares a method for two-way communication between the web business end and the webview component.
2. According to claim 1, a method for decoupling jsbridge and scheme based on Hongmeng webview container is characterized in that: The FZJSExportObject class is a virtual base class. The methods for two-way communication between the web service end and the webview component declared in the FZJSExportObject class include the routing stack, the Webview controller, whether to refresh, whether to retain, the fallback retention method, the general web service end side bridge method, the webview component side bridge method, and the method for obtaining dynamic class instances.
3. According to a method for decoupling jsbridge and scheme based on Hongmeng webview container according to claim 1, it is characterized in that: Assign the instance derived from the FZJSExportObject class to the fzJSExportObject variable through the onControllerAttached interceptor in the webview component.
4. According to a method for decoupling jsbridge and scheme based on Hongmeng webview container according to claim 1, it is characterized in that: Dynamically write pahtStack and controller to registerJavaScriptProxy and inject them into the webview component.
5. A device for decoupling jsbridge and scheme based on Hongmeng webview container, characterized in that: include: Define a module for defining fzJSExportObject and schemeMap variables in the Hongmeng native webview component and encapsulating them into a har package, wherein the initial value of the fzJSExportObject variable is empty, and the schemeMap variable defines a method for intercepting and detecting the scheme link of the web business end and transparently passing the scheme link to the web business end for redirection, wherein the schemeMap variable intercepts and detects the scheme link of the web business end based on the onLoadIntercept interceptor in the webview component, and transparently passes the scheme link to the web business end for redirection through the two-way communication between the webview component and the web business end; The communication module is used to define the FZJSExportObject class on the web business end, declare the fzJSExportObject variable as the FZJSExportObject class, and assign the instance derived from the FZJSExportObject class to the fzJSExportObject variable for two-way communication between the webview component and the web business end. Before any web business end in the project matrix assigns the instance derived from the FZJSExportObject class to the fzJSExportObject variable, the fzJSExportObject variable is set to the initial value. The FZJSExportObject class declares a method for two-way communication between the web business end and the webview component.
6. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute a method for decoupling jsbridge and scheme based on the Hongmeng webview container as described in any one of claims 1-4.
7. A readable storage medium, characterized in that: The readable storage medium stores a computer program, which includes a program code for controlling a process to execute a process, and the process includes a method for decoupling jsbridge and scheme based on the Hongmeng webview container according to any one of claims 1-4.
Citation Information
Patent Citations
Application interaction method and device, electronic equipment and readable storage medium
CN109901827A
Interaction method and device, electronic equipment and storage medium
CN117931477A