OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_UI_STATIC_CONTENT_STATIC_HTML_VIEW_CONTROLLER_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_STATIC_CONTENT_STATIC_HTML_VIEW_CONTROLLER_H_ |
| 7 |
| 8 #import <UIKit/UIKit.h> |
| 9 #import <WebKit/WebKit.h> |
| 10 |
| 11 #import "ios/chrome/browser/ui/url_loader.h" |
| 12 #import "ios/web/public/block_types.h" |
| 13 |
| 14 @protocol CRWNativeContentDelegate; |
| 15 |
| 16 namespace web { |
| 17 class BrowserState; |
| 18 struct Referrer; |
| 19 } |
| 20 |
| 21 // Callback for the HtmlGenerator protocol. |
| 22 typedef void (^HtmlCallback)(NSString*); |
| 23 |
| 24 // An object that can generate HTML to be displayed. |
| 25 @protocol HtmlGenerator<NSObject> |
| 26 // Generates the HTML to be displayed. This is called on the main thread. If |
| 27 // heavy work must be done, it should be done asynchronously. |
| 28 - (void)generateHtml:(HtmlCallback)callback; |
| 29 @end |
| 30 |
| 31 // HtmlGenerator that get HTML from a IDR_ id. |
| 32 @interface IdrHtmlGenerator : NSObject<HtmlGenerator> { |
| 33 @private |
| 34 // The IDR_ constant. |
| 35 int resourceId_; |
| 36 // The encoding of the resource. |
| 37 NSStringEncoding encoding_; |
| 38 } |
| 39 |
| 40 // Init with the IDR_ constant that point to a UTF8 string. |
| 41 - (id)initWithResourceId:(int)resourceId; |
| 42 |
| 43 // Init with the IDR_ constant that point to a string with the given encoding. |
| 44 - (id)initWithResourceId:(int)resourceId encoding:(NSStringEncoding)encoding; |
| 45 |
| 46 @end |
| 47 |
| 48 // Displays html pages either located in the application bundle, the application |
| 49 // data directory, or obtained by a |HtmlGenerator|. |
| 50 @interface StaticHtmlViewController : NSObject |
| 51 |
| 52 // The web view that is displaying the content. It is lazily created. |
| 53 @property(nonatomic, readonly) WKWebView* webView; |
| 54 |
| 55 // Returns the web controller scrollview. |
| 56 - (UIScrollView*)scrollView; |
| 57 |
| 58 // Initialization method. |resource| is the location of the static page to |
| 59 // display, relative to the root of the application bundle. |browserState| is |
| 60 // the user browser state to use for loading resources and must not be null. |
| 61 - (instancetype)initWithResource:(NSString*)resource |
| 62 browserState:(web::BrowserState*)browserState; |
| 63 |
| 64 // Initialization method. |generator| will produce the html to display. Its |
| 65 // generation method will be called each time reload is called. |browserState| |
| 66 // is the user browser state to use for loading resources and must not be null. |
| 67 - (instancetype)initWithGenerator:(id<HtmlGenerator>)generator |
| 68 browserState:(web::BrowserState*)browserState; |
| 69 |
| 70 // Initialization method. |fileURL| is the location of the page in the |
| 71 // application data directory. |resourcesRoot| is the root directory where the |
| 72 // page pointed by |fileURL| can find its resources. Web view will get read |
| 73 // access to the |resourcesRoot| directory. |fileURL| must be contained in |
| 74 // |resourcesRoot|. |browserState| is the user browser state to use for |
| 75 // loading resources and must not be null. |
| 76 - (instancetype)initWithFileURL:(const GURL&)fileURL |
| 77 allowingReadAccessToURL:(const GURL&)resourcesRoot |
| 78 browserState:(web::BrowserState*)browserState; |
| 79 |
| 80 // Set the |loader| to use to allow navigation to external URL. The |referrer| |
| 81 // is the URL that will be used as referrer for those navigations. |
| 82 - (void)setLoader:(id<UrlLoader>)loader referrer:(const web::Referrer&)referrer; |
| 83 |
| 84 // Asynchronously executes the supplied JavaScript. Calls |completionHandler| |
| 85 // with results of the execution. If the controller cannot execute JS at the |
| 86 // moment, |completionHandler| is called with an NSError. The |
| 87 // |completionHandler| can be nil. |
| 88 - (void)executeJavaScript:(NSString*)script |
| 89 completionHandler:(web::JavaScriptResultBlock)completionHandler; |
| 90 |
| 91 // The web page title. Will return nil if not available. |
| 92 - (NSString*)title; |
| 93 |
| 94 // Reload the content of the web page. |
| 95 - (void)reload; |
| 96 |
| 97 // Causes the page to start loading immediately if there is a pending load; |
| 98 // normally if the web view has been paged out for memory reasons, loads are |
| 99 // started lazily the next time the view is displayed. This can be called to |
| 100 // bypass the lazy behavior. This is equivalent to calling -webView, but should |
| 101 // be used when deliberately pre-triggering a load without displaying. |
| 102 - (void)triggerPendingLoad; |
| 103 |
| 104 // Called when memory is low. Release anything (such as views) that can be |
| 105 // easily re-created to free up RAM. |
| 106 - (void)handleLowMemory; |
| 107 |
| 108 // Returns YES if there is currently a live view in the tab (e.g., the view |
| 109 // hasn't been discarded due to low memory). |
| 110 // NOTE: This should be used for metrics-gathering only; for any other purpose |
| 111 // callers should not know or care whether the view is live. |
| 112 - (BOOL)isViewAlive; |
| 113 |
| 114 // Set a |CRWNativeContentDelegate| that will be notified each time the title of |
| 115 // the page changes. |
| 116 - (void)setDelegate:(id<CRWNativeContentDelegate>)delegate; |
| 117 |
| 118 // Enables or disables the scrolling in the native view. |
| 119 - (void)setScrollEnabled:(BOOL)enabled; |
| 120 |
| 121 @end |
| 122 |
| 123 #endif // IOS_CHROME_BROWSER_UI_STATIC_CONTENT_STATIC_HTML_VIEW_CONTROLLER_H_ |
OLD | NEW |