Summary of the invention
The invention provides a kind of browser message treatment method and device, can handle the message of browser more neatly, to realize the function of browser better.
The invention provides following scheme:
A kind of browser message treatment method comprises:
Application program is created a message queue;
From operating system is to take out all current message the message queue of browser thread creation, puts into the message queue that said application program is created;
Judge in the message of said taking-up whether have the message that meets prerequisite, if exist, the message of prerequisite is carried out order adjustment with meeting;
According to the order of each message in the message queue of said application program establishment, each message distribution is handled to the corresponding window of browser.
Preferably, also comprise:
From operating system is to take out the message queue of browser thread creation after all current message, and the message of said taking-up is removed from the message queue that said operating system is created.
Wherein, whether have the message that meets prerequisite in the said message of judging said taking-up, if exist, the message of prerequisite is carried out order adjustment and is comprised with meeting:
Judge whether exist in the message of said taking-up and need if exist, then this message be adjusted to the front end of message queue by the current message that is in the window treatments of focus.
Wherein, whether have the message that meets prerequisite in the said message of judging said taking-up, if exist, the message of prerequisite is carried out order adjustment and is comprised with meeting:
Judge in the message of said taking-up whether have the message relevant,, then this message is adjusted to the front end of message queue if exist with user interactions.
Wherein, whether have the message that meets prerequisite in the said message of judging said taking-up, if exist, the message of prerequisite is carried out order adjustment and is comprised with meeting:
Judge whether there is second message that before first message, to handle in the message of said taking-up,, then said second message is adjusted to before said first message if exist.
A kind of message processing apparatus comprises:
The unit is created in formation, is used for application program and creates a message queue;
The message retrieval unit, being used for from operating system is all current message of message queue taking-up of browser thread creation, puts into the message queue that said application program is created;
The order adjustment unit is used for judging whether the message of said taking-up exists the message that meets prerequisite, if exist, the message of prerequisite is carried out the order adjustment with meeting;
The message distribution unit is used for the order according to each message of message queue of said application program establishment, and each message distribution is handled to the corresponding window of browser.
Wherein, also comprise:
Remove the unit, being used for from operating system is that the message queue of browser thread creation takes out after all current message, and the message of said taking-up is removed from the message queue that said operating system is created.
Wherein, said order adjustment unit comprises:
The first adjustment subelement is used for judging whether the message of said taking-up exists and need if exist, then this message be adjusted to the front end of message queue by the current message that is in the window treatments of focus.
Wherein, said order adjustment unit comprises:
The second adjustment subelement is used for judging whether the message of said taking-up exists the message relevant with user interactions, if exist, then this message is adjusted to the front end of message queue.
Wherein, said order adjustment unit comprises:
The 3rd adjustment subelement is used for judging whether the message of said taking-up exists second message that need before first message, handle, if exist, then said second message is adjusted to before said first message.
According to specific embodiment provided by the invention, the present invention has reached following technique effect:
Pass through the embodiment of the invention; Because application program can create message queue voluntarily, and be that current message in the message queue of browser thread creation is taken out with operating system, put into the message queue that this is created voluntarily; Thereby make that the priority execution sequence of message is adjustable; Rather than, like this, can handle the message in the message queue more neatly uniformly according to the principle of stipulating in the operating system of handling earlier that arrives first.For example; Can so that some real-time external events in time handled; And; Before other message that formerly arrives, handle the situation that just can reach desired effects if some message that arrives in the back must be caught up with, then can the message that arrive in the back be mentioned before the message that formerly arrives, thereby reach desired effects.
Embodiment
To combine the accompanying drawing in the embodiment of the invention below, the technical scheme in the embodiment of the invention is carried out clear, intactly description, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, the every other embodiment that those of ordinary skills obtained belongs to the scope that the present invention protects.
Referring to Fig. 1; The embodiment of the invention at first provides a kind of browser message treatment method; This method can be applied in the application program (this application program can be to be a kind of application program that realizes this message processing function exploitation, also can be this message processing function of increase on existing browser basis, or the like); During concrete the realization, this method can may further comprise the steps:
S101: application program is created a message queue;
This message queue is created by application program oneself, and therefore, what kind of the message that application program can be decided in its sole discretion wherein arrange with in proper order, can also adjust order voluntarily.
S102: from operating system is to take out all current message the message queue of browser thread creation, puts into the message queue that said application program is created;
In order to understand this step better, at first the message processing procedure in the operating system is introduced simply below.Generally speaking, be processed to the end can the following process of experience from producing for message (is example with outside input message): when mouse or keyboard had action, device drives converted input operation into message and it is put in the system message queue (1); When (2) operating system shifts out a message at every turn from system message queue; Can judge which target window is this message belong to; Then it is distributed in the message queue of the thread of creating target window; In other words, the message queue of thread is window all mouses of reception and the keyboard message of its establishment; (3) thread shifts out message and guidance system comes these message distributions message is handled to correct window from its message queue.It is thus clear that operating system can be created two kinds of message queues, a kind of is system message queue, and all message all can be put into this system message queue earlier; Another kind is the message queue of thread, need can be put into the message queue of this thread by all message of the window treatments of certain thread creation.
Accordingly; For for the browser program that moves in the operating system; Operating system also can be the thread creation message queue of browser, when the message of from system message queue, taking out belongs to certain thread of browser, will this message be put in the message queue of this thread.The embodiment of the invention is exactly that the thread in the message queue that is distributed to the browser thread is taken out, and is stored in the message queue of application program oneself establishment.
Need to prove that the message in the message queue of browser thread is except the message that comprises said external input (message that is also promptly produced by mouse-keyboard etc.); Also possibly comprise system message (message that also promptly produces), in addition, also possibly comprise the message that browser self produces by operating system; For example, certain operation possibly not be to handle immediately, at this moment; Can delay processing through the mode that produces message; Also promptly, this message is put in the message queue ranks earlier, thereby delay processing time of this message; Perhaps some operation possibly need cross-thread to carry out again, at this moment, also can be put into earlier in the message queue, be distributed to then in the corresponding thread message queue, or the like.In the embodiment of the invention, when from the message queue of browser thread, taking out current message, can comprise above-mentioned all types of message; Also be; All message, no matter its come from outside input still operating system still be browser self, can it be taken out; Put in the message queue that application program creates voluntarily, so that the order of message is adjusted.Certainly, the execution sequence of some system messages possibly be sealed mounted, at this moment, can this system message not carried out the order adjustment.
Need to prove that in addition specifically when from the message queue of browser thread, taking out message, the modes such as API (Application Programming Interface, API) function that can utilize operating system to provide are carried out.For example, can directly use following api function: PeekMessage.
Certainly, in program operation process, mistake occurs, the message queue of creating from operating system, take out after the current message, can also the message of taking out be removed from the message queue that said operating system is created.
S103: judge in the message of said taking-up whether have the message that meets prerequisite, if exist, the message of prerequisite is carried out order adjustment with meeting;
The foundation of specifically message being adjusted can be confirmed according to the needs in the practical application; For example; Can think that the message that some operations relevant with user interactions produce needs priority processing, at this moment, just can put into position earlier in the message queue with such message.And for example, if the user is seeing video, the operation that video is relevant so just possibly need priority service, at this moment, just can the corresponding message of this operation be put into position earlier in the message queue.For another example,, carried out other operations again if the user is when seeing video, then just can think that message of this operation correspondence of user need be jumped the queue, advanced processing, or the like.In addition, can also judge whether each message need be by the current window treatments that is in focus, if then can the order of this message be shifted to an earlier date.Moreover some message (message that is especially produced by browser self) possibly carried out before another message, at this moment, can also this message be adjusted to before this another message, or the like.
Need to prove; Operating system can be numbered each message, and each message has the ID of oneself, can comprise information such as window handle, type of message in the message; Api function through system (for example can be known these information; Can check whether keyboard or mouse information are arranged in thread message queue through GetInputState, can check the message of a certain type in the message queue through GetQueueStatus, or the like) can know each message operation that needs by which window are handled and message is corresponding respectively or the like according to these information; And then just can confirm the order of each message in message queue according to preset rule.For example, the corresponding operation of certain message of find taking out need be by certain video playback window treatments, and it is higher that the priority ratio of this type message is set in advance; Therefore; Just can this message be placed on position earlier in the message queue, even can put in the first place, or the like.
S104:, each message distribution is handled to the corresponding window of browser according to the order of each message in the message queue of said application program establishment.
Because in the message queue that application program is created voluntarily, each message is adjusted again, therefore, just can carry out distribution processor to each message according to the order after the adjustment.Concrete, owing to be the message of from the message queue of browser thread, taking out, therefore when distribution processor, can directly message distribution be arrived corresponding browser window in step S102, message is handled getting final product by the window of correspondence.That is to say; Be the equal of after operating system arrives concrete browser thread message queue with the message distribution in the system queue; Be not by thread oneself with message distribution to concrete window; But, replace each concrete thread to accomplish this distribute work by application program with the described message processing function of the embodiment of the invention.During concrete the realization, when replacing concrete thread to accomplish the operation of message distribution, can realize that (this api function can be: DispatchMessage) by the api function that this application program with message processing function uses operating system to provide equally.
In a word, the message treatment method that provides through the embodiment of the invention is because application program can be created message queue voluntarily; And be that current message in the message queue of browser thread creation is taken out with operating system; Put into the message queue that this is created voluntarily, thereby make that the priority execution sequence of message is adjustable, rather than uniformly according to the principle of stipulating in the operating system of handling earlier that arrives first; Like this, can handle the message in the message queue more neatly.For example; Can so that some real-time external events in time handled; And; Before other message that formerly arrives, handle the situation that just can reach desired effects if some message that arrives in the back must be caught up with, then can the message that arrive in the back be mentioned before the message that formerly arrives, thereby reach desired effects.
Corresponding with the browser message treatment method that the embodiment of the invention provides, the embodiment of the invention also provides a kind of browser message processing apparatus, and same, this device is applied in the application program, and referring to Fig. 2, this device comprises with lower unit:
Unit 201 is created in formation, is used for application program and creates a message queue;
Message retrieval unit 202, being used for from operating system is all current message of message queue taking-up of browser thread creation, puts into the message queue that said application program is created;
Order adjustment unit 203 is used for judging whether the message of said taking-up exists the message that meets prerequisite, if exist, the message of prerequisite is carried out the order adjustment with meeting;
Message distribution unit 204 is used for the order according to each message of message queue of said application program establishment, and each message distribution is handled to the corresponding window of browser.
Certainly, in program operation process, mistake occurs, the message queue of creating from operating system, take out after the current message, can also the message of taking out be removed from the message queue that said operating system is created.During concrete the realization, this device can also comprise:
Remove the unit, being used for from operating system is that the message queue of browser thread creation takes out after all current message, and the message of said taking-up is removed from the message queue that said operating system is created.
Wherein, when specifically realizing, order adjustment unit 203 specifically can comprise:
The first adjustment subelement is used for judging whether the message of said taking-up exists and need if exist, then this message be adjusted to the front end of message queue by the current message that is in the window treatments of focus.
Perhaps, order adjustment unit 203 specifically also can comprise:
The second adjustment subelement is used for judging whether the message of said taking-up exists the message relevant with user interactions, if exist, then this message is adjusted to the front end of message queue.
Moreover order adjustment unit 203 specifically can also comprise:
The 3rd adjustment subelement is used for judging whether the message of said taking-up exists second message that need before first message, handle, if exist, then said second message is adjusted to before said first message.
The message processing apparatus that provides through the embodiment of the invention; Because application program can create message queue voluntarily, and be that current message in the message queue of browser thread creation is taken out with operating system, put into the message queue that this is created voluntarily; Thereby make that the priority execution sequence of message is adjustable; Rather than, like this, can handle the message in the message queue more neatly uniformly according to the principle of stipulating in the operating system of handling earlier that arrives first.For example; Can so that some real-time external events in time handled; And; Before other message that formerly arrives, handle the situation that just can reach desired effects if some message that arrives in the back must be caught up with, then can the message that arrive in the back be mentioned before the message that formerly arrives, thereby reach desired effects.
Description through above embodiment can know, those skilled in the art can be well understood to the present invention and can realize by the mode that software adds essential general hardware platform.Based on such understanding; The part that technical scheme of the present invention contributes to prior art in essence in other words can be come out with the embodied of software product; This computer software product can be stored in the storage medium, like ROM/RAM, magnetic disc, CD etc., comprises that some instructions are with so that a computer equipment (can be a personal computer; Server, the perhaps network equipment etc.) carry out the described method of some part of each embodiment of the present invention or embodiment.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and identical similar part is mutually referring to getting final product between each embodiment, and each embodiment stresses all is the difference with other embodiment.Especially, for device or system embodiment, because it is basically similar in appearance to method embodiment, so describe fairly simplely, relevant part gets final product referring to the part explanation of method embodiment.Apparatus and system embodiment described above only is schematic; Wherein said unit as the separating component explanation can or can not be physically to separate also; The parts that show as the unit can be or can not be physical locations also; Promptly can be positioned at a place, perhaps also can be distributed on a plurality of NEs.Can select wherein some or all of module to realize the purpose of present embodiment scheme according to the actual needs.Those of ordinary skills promptly can understand and implement under the situation of not paying creative work.
More than to a kind of browser message treatment method provided by the present invention and device; Be described in detail; Used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, part in specific embodiments and applications all can change.In sum, this description should not be construed as limitation of the present invention.