Chromium Development preparation-redirect webui Resources

Source: Internet
Author: User

Webui resources are compiled in chrome. dll. When an internal URL is entered in the address bar, the corresponding resources are found in chrome. dll. Each time you modify the frontendCodeCompile chrome. dll again later, which is a waste of time, and the front-end is generally composed of Non-C ++ProgramIt is unreasonable for developers to compile the file, so there must be a way to redirect the URL to a local file. After consulting and viewing the code, we found the solution.

Webui, the association between URLs prefixed with "Chrome" and "UI processing objects" is done in "src \ chrome \ browser \ UI \ webui \ chrome_web_ui_controller_factory.cc. The UI processing object is responsible for locating the corresponding front-end page and binding the exported JS interface to the C ++ logic. Therefore, to redirect the front-end page path, it must be done in the UI processing object. The helloworldui written in the past few days is used as an example. The front-end resource is obtained from the constructor of the helloworldui class.
 
Chromewebuidatasource * html_source =NewChromewebuidatasource (chrome: kchromeuihelloworldhost );
Chromewebuidatasource can be derived. If you want to relocate the location of the chrome: // hello-World Resource, rewrite the startdatarequest function. The focus is on the startdatarequest function. In this function, read the file content in the new path (D: \ chromium_resources_test) and connect it to the original logic. If the new path does not exist, use the original front-end resources.
         Virtual   Void Startdatarequest ( Const STD :: String & Path, Bool Is_incognito, Int  Request_id) {filepath web_file_path (L  "D  : \ Chromium_resources_test \\  "  ); Web_file_path = Web_file_path.appendascii (source_name ()); //  Use hostname as the folder name Web_file_path = Web_file_path.appendascii (PATH); file_util: memorymappedfile memmap_file;  Bool Bfile = Memmap_file.initialize (web_file_path );  If  (Bfile) {scoped_refptr < Base : Refcountedstring> response = New   Base  : Refcountedstring (); Response -> Data () = reinterpret_cast < Const   Char *> (Memmap_file.data (); sendresponse (request_id, response);} chromewebuidatasource: startdatarequest (path, is_incognito, request_id );} 

In this way, the resource file can be placed in D: \ chromium_resources_test. For example, the helloworld resource can be stored in the D: \ chromium_resources_test \ hello-world \ path.

To do well, you must first sharpen your tools.

For detailed example code, see Attachment: http://files.cnblogs.com/cswuyg/redirect_webui_resource.zip

 

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.