CN105630473B - Support the JavaScript event extended method of asynchronous call - Google Patents

Support the JavaScript event extended method of asynchronous call Download PDF

Info

Publication number
CN105630473B
CN105630473B CN201410610824.0A CN201410610824A CN105630473B CN 105630473 B CN105630473 B CN 105630473B CN 201410610824 A CN201410610824 A CN 201410610824A CN 105630473 B CN105630473 B CN 105630473B
Authority
CN
China
Prior art keywords
event
javascript
webcore
class
eventtarget
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201410610824.0A
Other languages
Chinese (zh)
Other versions
CN105630473A (en
Inventor
胡琳琳
王硕
郭志川
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhengzhou Xinrand Network Technology Co ltd
Original Assignee
Institute of Acoustics CAS
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Institute of Acoustics CAS filed Critical Institute of Acoustics CAS
Priority to CN201410610824.0A priority Critical patent/CN105630473B/en
Publication of CN105630473A publication Critical patent/CN105630473A/en
Application granted granted Critical
Publication of CN105630473B publication Critical patent/CN105630473B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The present invention relates to a kind of JavaScript event extended method for supporting asynchronous call, this method is realized based on WebKit, comprising: according to the title of the naming method extension JavaScript event of DOM event in WebCore;JavaScript event object is created according to the creation mode of JavaScript object in WebCore;The JavaScript event object created is extended to EventTarget;Event object event in WebCore being encapsulated as in V8;It compiles and disposes dynamic base.

Description

Support the JavaScript event extended method of asynchronous call
Technical field
The present invention relates to built-in field, in particular to a kind of JavaScript event extension side for supporting asynchronous call Method.
Background technique
On embedded device, user can not only obtain the information on internet by browser, while can be with It is interacted by browser controlling equipment with local functionality component.It is just gradually being risen by the Web of carrier application of browser, Web is answered With having many advantages, such as that exploitation threshold is low, it is easy transplanting.When constructing Web application, an important problem is to need to incite somebody to action this The Interface Expanding of ground component is JavaScript interface, is called for Web application.It is by local component Interface Expanding JavaScript has extensive demand.Synchronization call between local component and JavaScript is easier to realize, still Due to needing to return result in a manner of adjusting back after needing to do message transmission and asynchronous process when asynchronous call between cross-thread The features such as returning, it is relatively difficult to do asynchronous call between local component and JavaScript.
Summary of the invention
It is an object of the invention to overcome, the asynchronous call between local component and JavaScript is more in the prior art Difficult defect, to provide a kind of method that can preferably realize local component and JavaScript asynchronous call.
To achieve the goals above, the present invention provides a kind of JavaScript event extension sides for supporting asynchronous call Method, this method are realized based on WebKit, comprising:
Step 1), the title for extending JavaScript event according to the naming method of DOM event in WebCore;
Step 2) creates JavaScript event object according to the creation mode of JavaScript object in WebCore;
The JavaScript event object created in step 2) is extended to EventTarget by step 3);
Step 4), the event object being encapsulated as the event in WebCore in V8;
Step 5) compiles and disposes dynamic base.
In above-mentioned technical proposal, the step 2) includes:
The event for extending JavaScript object in WebCore, obtains JavaScript event object;
It states that the JavaScript event object inherits Event object, and defines the JavaScript event object Attribute;
In WebCore, it will be inherited in WebCore with C++ class corresponding to the JavaScript event object Event class realizes the getter method of attribute.
In above-mentioned technical proposal, the step 3) includes:
JavaScript object is enabled to inherit EventTarget;
It is an attribute of the JavaScript object by JavaScript event states;
In WebCore, enables and inherit EventTarget with C++ class corresponding to the JavaScript object, and at this Setter the and getter method of JavaScript event monitoring function is defined in class;
A function for creating and initiating JavaScript event is realized in the JavaScript object.
In above-mentioned technical proposal, the step 4) includes:
Getter method, this method are added in the base class EventTarget of C++ class corresponding to JavaScript object For Virtual Function, while this method is rewritten in the C++ class corresponding to the JavaScript object, return to this pointer;
The method for judging event type is added in Event class in WebCore, this method is equally Virtual Function, The derived class of Event rewrites this method in C++ class corresponding to JavaScript event object;
It is V8Event by the Event class wrapper in WebCore, the type that event is added judges and will be in WebCore Event class wrapper is the data format of V8.
The present invention has the advantages that
1, the present invention can efficiently solve the asynchronous call problem between local component and JavaScript.It is extended Between JavaScript object and local component not only can with synchronization call, can with asynchronous call, widened local component and Extend the method for calling between JavaScript object.
2, asynchronous invoking method proposed by the present invention is to be realized inside the browser by native mode, embedded Under the limited environment of equipment computing resource, computing resource can be saved, is particularly suitable in local component and JavaScript object Between have the scene of frequent asynchronous call.
Detailed description of the invention
Fig. 1 is the application scenarios schematic diagram of the JavaScript event extended method of support asynchronous call of the invention;
Fig. 2 is the flow chart of the JavaScript event extended method of support asynchronous call of the invention;
Fig. 3 is the DOM event mould of WebCore in the JavaScript event extended method of support asynchronous call of the invention Type static structure figure;
Fig. 4 is the function of OTTVideo event in the JavaScript event extended method of support asynchronous call of the invention Calling sequence figure.
Specific embodiment
Now in conjunction with attached drawing, the invention will be further described.
Method of the invention is realized based on WebKit, in order to make it easy to understand, doing specifically to method of the invention Before bright, brief description is done to WebKit first.
WebKit is an open source webpage layout engine, mainly includes two large divisions in WebKit kernel: WebCore and JavaScript engine.
WebCore is html document typesetting engine, is responsible for parsing, layout, rendering html document.It wherein include DOM The realization of (Document Object Module, DOM Document Object Model), while WebCore also has binding (binding) module, It can bind with JavaScript engine.JavaScript engine can manipulate DOM module in this way, control the behavior of webpage.
JavaScript engine is an interpreter of JavaScript language, provides the operation ring of JavaScript Border can parse and execute JavaScript script.Meanwhile the bindings module in JavaScript engine and WebCore It is associated, JavaScript script is allowed to operate DOM element.
Method of the invention is described further below with reference to example.
Fig. 1 is the schematic diagram of the application scenarios of the method for the present invention, as shown, include local component in a browser, And JavaScript script is run in Web page.In order to realize the synchronization call between local component and JavaScript script It is JavaScript interface by the Interface Expanding of local component with asynchronous call (especially asynchronous call).Described JavaScript interface realizes that including at least that is, in the interface has WebCore and JavaScript engine based on WebKit.
In the following example by by taking the broadcasting of streaming media video as an example, to method of the invention how by local component Interface Expanding is described further for JavaScript interface.
During streaming media video plays, user clicks a streaming media video in Web page, by Web page In JavaScript script call local component, local component then by asynchronous system obtain video the address URL, work as local After component gets out the address URL, Web page is notified in a manner of DOM event.Specifically, in the present embodiment, by local group Related object, which is played, with streaming media video in the WebCore of the JavaScript interface of part is denoted as OTTVideo object;By Web Related object, which is played, with streaming media video in the JavaScript script of the page is denoted as ottvideo object;By OTTVideo pairs As being denoted as onPlay to DOM event transmitted by ottvideo object.Then streaming media video playing process above-mentioned is are as follows: OTTVideo object requests the broadcasting link of streaming media video by asynchronous system to local component, and local component is ready to play After link, the OTTVideo object in WebCore is adjusted back, parameter is the character string containing broadcasting link URL;Then, WebCore In OTTVideo object need by the broadcasting link, (i.e. event onPlay) is sent to JavaScript in the form of DOM event The ottvideo object at end, parameter are name src, and parameter type is a character string.
With reference to Fig. 2, the method comprise the steps that
The event that step 1, extension are named with onPlay
According to the naming method of DOM event in WebCore, the title of customized JavaScript event is extended, packet is facilitated The event is used in Web page containing JavaScript script;Specifically, extension is in a manner of the event that onPlay is named It is as follows: macro in the #defineDOM_EVENT_NAMES_FOR_EACH (macro) of WebCore/dom/EventNames.h file Middle addition macro (Play) statement this event of onPlay.
Step 2, extension ottvideoevent object instance
According to the creation mode of JavaScript object in WebCore, JavaScript event object example is created.Creation JavaScript event object example includes: to extend the peculiar event of OTTVideo object in WebCore, obtained JavaScript event object is named as ottvideoevent, corresponding with the JavaScript event object in WebCore C++ class is named as OTTVideoEvent;In extension, it is also necessary to state JavaScript pairs in OTTVideoEvent.idl As ottvideoevent succession Event object, and define a read only attribute of ottvideoevent: src;? OTTVideoEvent class in WebCore then inherits the Event class in WebCore, realizes the getter method of src attribute.
After ottvideoevent object instance is expanded, when local component needs to send message to the page, local component The content of message is issued to the JavaScript event object ottvideoevent of WebCore.
Step 3, by OTTVideo object extension be EventTarget
Object OTTVideo is extended to EventTarget.With reference to Fig. 3, OTTVideo is extended to EventTarget can It is realized by inheriting EventTarget by OTTVideo.In Fig. 3, triangle indicates inheritance;Diamond shape indicates that combination is closed System;Black diamonds indicate syntagmatic, and state that the period is consistent;Dotted arrow indicates call relation.
In extension, it is also necessary to be an attribute of ottvideo object by onPlay event states.Specifically, exist In OTTVideo.idl, onPlay is claimed as to an attribute of ottvideo object, statement method is as follows:
attribute EventListener onPlay;
In this way, in Web page can used DOM0 rank event model be ottvideo object registration event monitoring Function.
Promoter of the OTTVideo class as event in WebCore illustrates that OTTVideo is a kind of EventTarget, So OTTVideo should inherit EventTarget.Meanwhile onPlay event monitoring function should be defined in OTTVideo class Setter and getter method because one has been defined in EventTarget to event registration setter and getter Method it is macro, we directly use this macro, the method is as follows:
DEFINE_ATTRIBUTE_EVENT_LISTENER(Play);
When OTTVideo is adjusted back by local component, it should onPlay event is initiated, so also needing to realize in extension One creates and initiates the function fireEvent () of onPlay event.It is worth noting that, at DOM event in WebCore Reason must be carried out in the main thread of browser, when the application realizes, return to browser main thread using Socket, and in main thread Middle creation simultaneously initiates onPlay event.
In this step, after event object being extended to EventTarget, event object has entered WebCore's In event control stream in DOM model.When local component asynchronous call JavaScript code, WebCore can utilize itself Case distribution mechanism, transmitting event give V8 engine (one kind of JavaScript engine), then, V8 engine can trigger accordingly EventListener, with response events.Wherein, EventListener is included in EventTarget, it is generation event Handle function.
Event in WebCore is encapsulated as V8 event by step 4.
Event object in WebCore is encapsulated as the object that V8 can be identified by binding module, it in this way can be real The interaction of existing event object and JavaScript code.
Specific encapsulation process is as follows:
The getter method of OTTVideo is added in the base class EventTarget of OTTVideo, this method is Virtual Function, This method is rewritten in derived class OTTVideo simultaneously, returns to this pointer of OTTVideo.
Equally, the isOTTVideoEvent method for judging event type, the party are added in the Event class in WebCore Method is equally Virtual Function, rewrites this method in the derived class OTTVideoEvent of Event.Can thus it pass through IsOTTVideoEvent identifies OTTVideoEvent, when the event of OTTVideo being facilitated to occur, triggers OTTVideo's Event sniffer.
In the function toV8 () of Source/WebCore/bindings/v8/custom/V8EventCustom.cpp The type judgement of Event is added in (Event in WebCore is encapsulated as V8Event by this function):
if(impl->isOTTVideoEvent()){
return toV8(static_cast<OTTVideoEvent*>(impl));
}
In V8Event, the Event in WebCore is encapsulated as the data format of V8 by voV8 function, is returned to V8 and is drawn It holds up.
Step 5, compiling.
WebCore and V8 is compiled, the module of the JavaScript event propagated through will be supported to be deployed in application environment.
It is compiled under Android source code external/webkit catalogue, generates libwebcore.so dynamic base.
Communication with reference to Fig. 4, after method of the invention is done local component and extended, between local component and Web page Journey is as follows: local component adjusts back the OTTVideo object in WebCore by onPlay method, passes through in WebCore Socket returns to browser main thread, and OTTVideo creates OTTVideoEvent object, then initiates thing by fireEvent Then part calls fireEventListener to call by dispatchEvent Distribution Events HandleEvent method call in V8AbstractEvenListener monitors function, and toV8 is then called in V8Event Event is converted to the event in V8 by method, calls invokeEventHandler finally to call actual monitoring function.
It should be noted last that the above examples are only used to illustrate the technical scheme of the present invention and are not limiting.Although ginseng It is described the invention in detail according to embodiment, those skilled in the art should understand that, to technical side of the invention Case is modified or replaced equivalently, and without departure from the spirit and scope of technical solution of the present invention, should all be covered in the present invention Scope of the claims in.

Claims (4)

1. a kind of JavaScript event extended method for supporting asynchronous call, this method is realized based on WebKit, comprising:
Step 1), the title for extending JavaScript event according to the naming method of DOM event in WebCore;
Step 2) creates JavaScript event object according to the creation mode of JavaScript object in WebCore;
The JavaScript event object created in step 2) is extended to EventTarget by step 3);
JavaScript event in WebCore is encapsulated as the event object in V8 by step 4);
Step 5) compiles and disposes dynamic base.
2. the JavaScript event extended method according to claim 1 for supporting asynchronous call, which is characterized in that described Step 2) includes:
The event for extending JavaScript object in WebCore, obtains JavaScript event object;
It states that the JavaScript event object inherits Event object, and defines the category of the JavaScript event object Property;
It, will be with the Event in the succession of C++ class corresponding to JavaScript event object WebCore in WebCore Class realizes the getter method of attribute.
3. the JavaScript event extended method according to claim 2 for supporting asynchronous call, which is characterized in that described Step 3) includes:
JavaScript object is enabled to inherit EventTarget;
It is an attribute of the JavaScript object by JavaScript event states;
In WebCore, enables and inherit EventTarget with C++ class corresponding to the JavaScript object, and in such Define setter the and getter method of JavaScript event monitoring function;
A function for creating and initiating JavaScript event is realized in the JavaScript object.
4. the JavaScript event extended method according to claim 3 for supporting asynchronous call, which is characterized in that described Step 4) include:
Getter method is added in the base class EventTarget of C++ class corresponding to JavaScript object, this method is void Function, while this method is rewritten in the C++ class corresponding to the JavaScript object, return to this pointer;
The method for judging event type is added in Event class in WebCore, this method is equally Virtual Function, Event's Derived class rewrites this method in C++ class corresponding to JavaScript event object;
It is V8Event by the Event class wrapper in WebCore, the type judgement of event is added and by the Event in WebCore Class wrapper is the data format of V8.
CN201410610824.0A 2014-11-03 2014-11-03 Support the JavaScript event extended method of asynchronous call Active CN105630473B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410610824.0A CN105630473B (en) 2014-11-03 2014-11-03 Support the JavaScript event extended method of asynchronous call

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410610824.0A CN105630473B (en) 2014-11-03 2014-11-03 Support the JavaScript event extended method of asynchronous call

Publications (2)

Publication Number Publication Date
CN105630473A CN105630473A (en) 2016-06-01
CN105630473B true CN105630473B (en) 2019-01-22

Family

ID=56045464

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410610824.0A Active CN105630473B (en) 2014-11-03 2014-11-03 Support the JavaScript event extended method of asynchronous call

Country Status (1)

Country Link
CN (1) CN105630473B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102214098A (en) * 2011-06-15 2011-10-12 中山大学 Dynamic webpage data acquisition method based on WebKit browser engine
CN104077213A (en) * 2013-03-26 2014-10-01 腾讯科技(深圳)有限公司 Webkit unit test method and webkit unit test device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102214098A (en) * 2011-06-15 2011-10-12 中山大学 Dynamic webpage data acquisition method based on WebKit browser engine
CN104077213A (en) * 2013-03-26 2014-10-01 腾讯科技(深圳)有限公司 Webkit unit test method and webkit unit test device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"基于JavaScript引擎的终端动态数据处理方法";刘春梅 等;《微计算机应用》;20100415;第31卷(第4期);第25-30页 *

Also Published As

Publication number Publication date
CN105630473A (en) 2016-06-01

Similar Documents

Publication Publication Date Title
US9715370B2 (en) Method and system for providing content
JP6629848B2 (en) Page processing for mobile applications
US10880227B2 (en) Apparatus, hybrid apparatus, and method for network resource access
EP2916243B1 (en) Method, apparatus, server and system for implementing web application
CN108965397A (en) Cloud video editing method and device, editing equipment and storage medium
CN109388766A (en) The method and apparatus of page load
CN105786513A (en) Mixed mobile application development method based on Html5
CN108132814A (en) Page loading method, device, computer equipment and the storage medium of application program
CN106874035B (en) Method for updating application (app) built-in H5 and framework thereof
CN103176834B (en) A kind of method of invoke extensions interface and device
Hales HTML5 and JavaScript Web Apps: Bridging the gap between the web and the mobile web
KR101416104B1 (en) A dynamic loading apparatus and method of java script code performing native functions of hybrid web applications
CN106997298A (en) A kind of application resource acquisition methods and device
CN110221848A (en) APP method for updating pages, device, electronic equipment and storage medium
CN105743955A (en) Method for JavaScript object expansion
CN104267972A (en) Brower local interface expansion method and device
CN109240697A (en) Calling processing method and device, storage medium
CN109460546A (en) List generation method, device and electronic equipment
CN105989068A (en) Hypertext markup language (HTML) based mobile application generating method and device
CN110020370B (en) Method and device for realizing animation in client application and framework of animation script
AU2019222873B2 (en) Method and system for providing content
CN111124924B (en) API deployment method and device, electronic equipment and storage medium
CN107239265B (en) Binding method and device of Java function and C function
CN102611930A (en) Browser self-adaptive display method and device and TV set
CN110825373B (en) Mobile terminal dynamic method and device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20210803

Address after: Room 1601, 16th floor, East Tower, Ximei building, No. 6, Changchun Road, high tech Industrial Development Zone, Zhengzhou, Henan 450001

Patentee after: Zhengzhou xinrand Network Technology Co.,Ltd.

Address before: 100190, No. 21 West Fourth Ring Road, Beijing, Haidian District

Patentee before: INSTITUTE OF ACOUSTICS, CHINESE ACADEMY OF SCIENCES