1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_WEBUI_CRW_WEB_UI_PAGE_BUILDER_H_
6 #define IOS_WEB_WEBUI_CRW_WEB_UI_PAGE_BUILDER_H_
8 #import <Foundation/Foundation.h>
13 // Block type for WebUI page build completion callback.
14 typedef void (^WebUIPageCompletion
)(NSString
*);
15 // Block type for WebUI page builder delegate completion callback.
16 typedef void (^WebUIDelegateCompletion
)(NSString
*, const GURL
&);
19 @
class CRWWebUIPageBuilder
;
21 // Delegate for CRWWebUIPageBuilder. Handles resource retrieval.
22 @protocol CRWWebUIPageBuilderDelegate
<NSObject
>
23 // Fetches resource for resourceURL and invokes completionHandler with the
25 - (void)webUIPageBuilder
:(CRWWebUIPageBuilder
*)webUIPageBuilder
26 fetchResourceWithURL
:(const GURL
&)resourceURL
27 completionHandler
:(web::WebUIDelegateCompletion
)completionHandler
;
30 // Class for requesting and building WebUI HTML pages. Due to limitations on
31 // custom network protocols for WKWebView, it is not possible to directly load
32 // WebUI in WKWebView via the network stack. Instead, WebUI resources are
33 // manually fetched from the network stack and then flattened and loaded into
36 // To flatten the WebUI resources, tags for JS and CSS resources are replaced
37 // with retrieved resources. For example, if a WebUI HTML resource looks like:
39 // <script src='chrome://javascript.js></script>
40 // <link rel="stylesheet" href="chrome://stylesheet.css">
42 // the flattened version would look like:
44 // <script>[Content of chrome://javascript.js]</script>
45 // <style>[Content of chrome://stylesheet.css]</style>
47 @interface CRWWebUIPageBuilder
: NSObject
49 // Designated initializer.
50 - (instancetype
)initWithDelegate
:(id
<CRWWebUIPageBuilderDelegate
>)delegate
;
52 // Builds and flattens page for webUIURL, and invokes completionHandler with the
54 - (void)buildWebUIPageForURL
:(const GURL
&)webUIURL
55 completionHandler
:(web::WebUIPageCompletion
)completionHandler
;
59 #endif // IOS_WEB_WEBUI_CRW_WEB_UI_PAGE_BUILDER_H_