Chrome Source Learning: JS and the underlying C + + communication

Source: Internet
Author: User

Take the query history as an example:

1. In the upper History.js, send the event request and related parameters to the bottom through Chrome.send (), where ' queryhistory ' is the signal name, [This.searchtext_, This.offset_, This.rangeindays_, EndTime, MaxResults] is the parameter passed to the bottom:

Chrome.send (' QueryHistory ', [This This] rangeindays_, EndTime, MaxResults]);

2. In the underlying browsing_history_handler.cc, the Registermessages function responds to events from the upper layer:

void browsinghistoryhandler::registermessages () {...  ... WEB_UI ()->registermessagecallback ("queryhistory",      Base :: Bind (&browsinghistoryhandler::handlequeryhistory,                 base:: Unretained (  this))); ...}

The event response for the query history is then processed in the Browsinghistoryhandler::handlequeryhistory () function.

3. After processing, call the upper JS method via Calljavascriptfunction () and return the data that needs to be returned.

void browsinghistoryhandler::returnresultstofrontend () {...  ... WEB_UI (),calljavascriptfunction (      "historyresult", Results_ Info_value_, results_value);

4. Then the upper-layer-specified method, i.e. Historyresult (), obtains the history of the originally specified query and can proceed with the related processing, completing a complete communication above:

function Historyresult (info, results) {  Historymodel.addresults (info, results);}

Report:

Pull substitution code: Git clone

Force recovery to a committed version: Git reset--hard

Chrome Source Learning: JS and the underlying C + + communication

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.