1/*
2 * Copyright (C) 2003, 2004, 2005, 2012 Apple Computer, 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 Computer, 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 <Cocoa/Cocoa.h>
30
31#import <WebKit/WebDocument.h>
32
33@class NSMutableURLRequest;
34@class NSURLConnection;
35@class NSURLRequest;
36@class NSURLResponse;
37@class WebArchive;
38@class WebFrame;
39@class WebResource;
40
41/*!
42    @class WebDataSource
43    @discussion A WebDataSource represents the data associated with a web page.
44    A datasource has a WebDocumentRepresentation which holds an appropriate
45    representation of the data.  WebDataSources manage a hierarchy of WebFrames.
46    WebDataSources are typically related to a view by their containing WebFrame.
47*/
48@interface WebDataSource : NSObject
49{
50@private
51    void *_private;
52}
53
54/*!
55    @method initWithRequest:
56    @abstract The designated initializer for WebDataSource.
57    @param request The request to use in creating a datasource.
58    @result Returns an initialized WebDataSource.
59*/
60- (id)initWithRequest:(NSURLRequest *)request;
61
62/*!
63    @method data
64    @discussion The data will be incomplete until the datasource has completely loaded.
65    @result Returns the raw data associated with the datasource.  Returns nil
66    if the datasource hasn't loaded any data.
67*/
68- (NSData *)data;
69
70/*!
71    @method representation
72    @discussion A representation holds a type specific representation
73    of the datasource's data.  The representation class is determined by mapping
74    a MIME type to a class.  The representation is created once the MIME type
75    of the datasource content has been determined.
76    @result Returns the representation associated with this datasource.
77    Returns nil if the datasource hasn't created it's representation.
78*/
79- (id <WebDocumentRepresentation>)representation;
80
81/*!
82    @method webFrame
83    @result Return the frame that represents this data source.
84*/
85- (WebFrame *)webFrame;
86
87/*!
88    @method initialRequest
89    @result Returns a reference to the original request that created the
90    datasource.  This request will be unmodified by WebKit.
91*/
92- (NSURLRequest *)initialRequest;
93
94/*!
95    @method request
96    @result Returns the request that was used to create this datasource.
97*/
98- (NSMutableURLRequest *)request;
99
100/*!
101    @method response
102    @result returns the WebResourceResponse for the data source.
103*/
104- (NSURLResponse *)response;
105
106/*!
107    @method textEncodingName
108    @result Returns either the override encoding, as set on the WebView for this
109    dataSource or the encoding from the response.
110*/
111- (NSString *)textEncodingName;
112
113/*!
114    @method isLoading
115    @discussion Returns YES if there are any pending loads.
116*/
117- (BOOL)isLoading;
118
119/*!
120    @method pageTitle
121    @result Returns nil or the page title.
122*/
123- (NSString *)pageTitle;
124
125/*!
126    @method unreachableURL
127    @discussion This will be non-nil only for dataSources created by calls to the
128    WebFrame method loadAlternateHTMLString:baseURL:forUnreachableURL:.
129    @result returns the unreachableURL for which this dataSource is showing alternate content, or nil
130*/
131- (NSURL *)unreachableURL;
132
133/*!
134    @method webArchive
135    @result A WebArchive representing the data source, its subresources and child frames.
136    @description This method constructs a WebArchive using the original downloaded data.
137    In the case of HTML, if the current state of the document is preferred, webArchive should be
138    called on the DOM document instead.
139*/
140- (WebArchive *)webArchive;
141
142/*!
143    @method mainResource
144    @result A WebResource representing the data source.
145    @description This method constructs a WebResource using the original downloaded data.
146    This method can be used to construct a WebArchive in case the archive returned by
147    WebDataSource's webArchive isn't sufficient.
148*/
149- (WebResource *)mainResource;
150
151/*!
152    @method subresources
153    @abstract Returns all the subresources associated with the data source.
154    @description The returned array only contains subresources that have fully downloaded.
155*/
156- (NSArray *)subresources;
157
158/*!
159    method subresourceForURL:
160    @abstract Returns a subresource for a given URL.
161    @param URL The URL of the subresource.
162    @description Returns non-nil if the data source has fully downloaded a subresource with the given URL.
163*/
164- (WebResource *)subresourceForURL:(NSURL *)URL;
165
166/*!
167    @method addSubresource:
168    @abstract Adds a subresource to the data source.
169    @param subresource The subresource to be added.
170    @description addSubresource: adds a subresource to the data source's list of subresources.
171    Later, if something causes the data source to load the URL of the subresource, the data source
172    will load the data from the subresource instead of from the network. For example, if one wants to add
173    an image that is already downloaded to a web page, addSubresource: can be called so that the data source
174    uses the downloaded image rather than accessing the network. NOTE: If the data source already has a
175    subresource with the same URL, addSubresource: will replace it.
176*/
177- (void)addSubresource:(WebResource *)subresource;
178
179@end
180