1/* 2 * Copyright (C) 2003, 2004, 2005, 2012 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#import <Foundation/Foundation.h> 30#import <WebKitLegacy/WebDocument.h> 31 32@class NSMutableURLRequest; 33@class NSURLConnection; 34@class NSURLRequest; 35@class NSURLResponse; 36@class WebArchive; 37@class WebFrame; 38@class WebResource; 39 40/*! 41 @class WebDataSource 42 @discussion A WebDataSource represents the data associated with a web page. 43 A datasource has a WebDocumentRepresentation which holds an appropriate 44 representation of the data. WebDataSources manage a hierarchy of WebFrames. 45 WebDataSources are typically related to a view by their containing WebFrame. 46*/ 47@interface WebDataSource : NSObject 48{ 49@private 50 void *_private; 51} 52 53/*! 54 @method initWithRequest: 55 @abstract The designated initializer for WebDataSource. 56 @param request The request to use in creating a datasource. 57 @result Returns an initialized WebDataSource. 58*/ 59- (instancetype)initWithRequest:(NSURLRequest *)request; 60 61/*! 62 @property data 63 @abstract Returns the raw data associated with the datasource. Returns nil 64 if the datasource hasn't loaded any data. 65 @discussion The data will be incomplete until the datasource has completely loaded. 66*/ 67@property (nonatomic, readonly, copy) NSData *data; 68 69/*! 70 @property representation 71 @abstract The representation associated with this datasource. 72 Returns nil if the datasource hasn't created its representation. 73 @discussion A representation holds a type specific representation 74 of the datasource's data. The representation class is determined by mapping 75 a MIME type to a class. The representation is created once the MIME type 76 of the datasource content has been determined. 77*/ 78@property (nonatomic, readonly, strong) id<WebDocumentRepresentation> representation; 79 80/*! 81 @property webFrame 82 @abstract The frame that represents this data source. 83*/ 84@property (nonatomic, readonly, strong) WebFrame *webFrame; 85 86/*! 87 @property initialRequest 88 @abstract A reference to the original request that created the 89 datasource. This request will be unmodified by WebKit. 90*/ 91@property (nonatomic, readonly, strong) NSURLRequest *initialRequest; 92 93/*! 94 @property request 95 @abstract The request that was used to create this datasource. 96*/ 97@property (nonatomic, readonly, strong) NSMutableURLRequest *request; 98 99/*! 100 @property response 101 @abstract The NSURLResponse for the data source. 102*/ 103@property (nonatomic, readonly, strong) NSURLResponse *response; 104 105/*! 106 @property textEncodingName 107 @abstract Returns either the override encoding, as set on the WebView for this 108 dataSource or the encoding from the response. 109*/ 110@property (nonatomic, readonly, copy) NSString *textEncodingName; 111 112/*! 113 @property isLoading 114 @abstract Returns YES if there are any pending loads. 115*/ 116@property (nonatomic, getter=isLoading, readonly) BOOL loading; 117 118/*! 119 @property pageTitle 120 @abstract The page title or nil. 121*/ 122@property (nonatomic, readonly, copy) NSString *pageTitle; 123 124/*! 125 @property unreachableURL 126 @abstract The unreachableURL for which this dataSource is showing alternate content, or nil. 127 @discussion This will be non-nil only for dataSources created by calls to the 128 WebFrame method loadAlternateHTMLString:baseURL:forUnreachableURL:. 129*/ 130@property (nonatomic, readonly, strong) NSURL *unreachableURL; 131 132/*! 133 @property webArchive 134 @abstract A WebArchive representing the data source, its subresources and child frames. 135 @description This method constructs a WebArchive using the original downloaded data. 136 In the case of HTML, if the current state of the document is preferred, webArchive should be 137 called on the DOM document instead. 138*/ 139@property (nonatomic, readonly, strong) WebArchive *webArchive; 140 141/*! 142 @property mainResource 143 @abstract A WebResource representing the data source. 144 @description This method constructs a WebResource using the original downloaded data. 145 This method can be used to construct a WebArchive in case the archive returned by 146 WebDataSource's webArchive isn't sufficient. 147*/ 148@property (nonatomic, readonly, strong) WebResource *mainResource; 149 150/*! 151 @property subresources 152 @abstract All the subresources associated with the data source. 153 @description The returned array only contains subresources that have fully downloaded. 154*/ 155@property (nonatomic, readonly, copy) NSArray *subresources; 156 157/*! 158 method subresourceForURL: 159 @abstract Returns a subresource for a given URL. 160 @param URL The URL of the subresource. 161 @description Returns non-nil if the data source has fully downloaded a subresource with the given URL. 162*/ 163- (WebResource *)subresourceForURL:(NSURL *)URL; 164 165/*! 166 @method addSubresource: 167 @abstract Adds a subresource to the data source. 168 @param subresource The subresource to be added. 169 @description addSubresource: adds a subresource to the data source's list of subresources. 170 Later, if something causes the data source to load the URL of the subresource, the data source 171 will load the data from the subresource instead of from the network. For example, if one wants to add 172 an image that is already downloaded to a web page, addSubresource: can be called so that the data source 173 uses the downloaded image rather than accessing the network. NOTE: If the data source already has a 174 subresource with the same URL, addSubresource: will replace it. 175*/ 176- (void)addSubresource:(WebResource *)subresource; 177 178@end 179