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