blob: fb63c259001b75616e3e5518e7457d5b9ff0dc79 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Foundation/Foundation.h>
#include "url/gurl.h"
namespace web {
// Block type for WebUI page build completion callback.
typedef void (^WebUIPageCompletion)(NSString*);
// Block type for WebUI page builder delegate completion callback.
typedef void (^WebUIDelegateCompletion)(NSString*, const GURL&);
} // namespace web
@class CRWWebUIPageBuilder;
// Delegate for CRWWebUIPageBuilder. Handles resource retrieval.
@protocol CRWWebUIPageBuilderDelegate<NSObject>
// Fetches resource for resourceURL and invokes completionHandler with the
// result.
- (void)webUIPageBuilder:(CRWWebUIPageBuilder*)webUIPageBuilder
fetchResourceWithURL:(const GURL&)resourceURL
// Class for requesting and building WebUI HTML pages. Due to limitations on
// custom network protocols for WKWebView, it is not possible to directly load
// WebUI in WKWebView via the network stack. Instead, WebUI resources are
// manually fetched from the network stack and then flattened and loaded into
// the web view.
// To flatten the WebUI resources, tags for JS and CSS resources are replaced
// with retrieved resources. For example, if a WebUI HTML resource looks like:
// <html>
// <script src='chrome://javascript.js></script>
// <link rel="stylesheet" href="chrome://stylesheet.css">
// </html>
// the flattened version would look like:
// <html>
// <script>[Content of chrome://javascript.js]</script>
// <style>[Content of chrome://stylesheet.css]</style>
// </html>
@interface CRWWebUIPageBuilder : NSObject
// Designated initializer.
- (instancetype)initWithDelegate:(id<CRWWebUIPageBuilderDelegate>)delegate;
// Builds and flattens page for webUIURL, and invokes completionHandler with the
// result.
- (void)buildWebUIPageForURL:(const GURL&)webUIURL