Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Next Page > Hide TOC

WebDataSource Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/WebKit.framework
Availability
Available in Mac OS X v10.2 with Safari 1.0 and later.
Available in Mac OS X v10.2.7 and later.
Companion guide
Declared in
WebDataSource.h

Overview

WebDataSource encapsulates the web content to be displayed in a web frame view. A WebDataSource object has a representation object, conforming to the WebDocumentRepresentation protocol, that holds the data in an appropriate format depending on the MIME type. You can extend Web Kit to support new MIME types by implementing your own view and representation classes, and specifying the mapping between them using the WebView registerViewClass:representationClass:forMIMEType: class method.

WebDataSource objects have an associated initial request, possibly modified request, and response object. Since the data source may be in the process of being loaded, you should check the state of a data source using the isLoading method before accessing its data. Use the data method to get the raw data. Use the representation method to get the actual representation object and query it for more details.

Tasks

Initializing an Instance

Querying Page Data and State

Getting the Request and Response

Getting the Web Frame

Getting an Unreachable URL

Getting a Web Archive

Accessing Subresources

Instance Methods

addSubresource:

Adds a resource to the receiver’s list of subresources.

- (void)addSubresource:(WebResource *)subresource

Discussion

If the receiver needs to reload the resource’s URL, it will load the data from subresource instead of the network. For example, use this method if you want to use a previously downloaded image rather than accessing the network to reload a resource. If the receiver already has a resource with the same URL as subresource, then this method replaces it.

Availability
See Also
Declared In
WebDataSource.h

data

Returns the raw data that represents the receiver’s content.

- (NSData *)data

Discussion

The format of the data is dependent on the receiver’s MIME type (obtained from the response). The data will be incomplete until the data has finished loading. Returns nil if the receiver hasn’t loaded any data. Use the isLoading method to test if a data source is in the process of loading.

Availability
See Also
Declared In
WebDataSource.h

initialRequest

Returns a reference to the original request that was used to load the web content.

- (NSURLRequest *)initialRequest

Availability
See Also
Declared In
WebDataSource.h

initWithRequest:

initializes a data source with a URL request.

- (id)initWithRequest:(NSURLRequest *)request

Discussion

This method is the designated initializer for WebDataSource objects where request is used to load the web content. Normally, WebFrame objects create their data sources, so don’t invoke this method directly.

Availability
Declared In
WebDataSource.h

isLoading

Returns YES if the receiver is in the process of loading its content, NO otherwise.

- (BOOL)isLoading

Availability
See Also
Declared In
WebDataSource.h

mainResource

Creates and returns a WebResource representing the receiver.

- (WebResource *)mainResource

Discussion

The contents returned are based on the original downloaded data. You can use the returned value to create a WebArchive object instead of using the webArchive method.

Availability
Declared In
WebDataSource.h

pageTitle

Returns the title of the receiver’s page.

- (NSString *)pageTitle

Discussion

May return nil if the page has no title, or the page title hasn’t been loaded yet. The WebView will notify its frame load delegate when the page title is loaded by invoking the webView:didReceiveTitle:forFrame: delegate method.

Availability
See Also
Declared In
WebDataSource.h

representation

Returns the receiver’s representation depending on its MIME type.

- (id < WebDocumentRepresentation >)representation

Discussion

If the receiver is in the process of being loaded, this method may return nil if invoked before loading is complete. You can specify the mapping between a representation and MIME type using the WebView registerViewClass:representationClass:forMIMEType: class method.

Availability
See Also
Declared In
WebDataSource.h

request

Returns the request that was used to create the receiver.

- (NSMutableURLRequest *)request

Discussion

The URL returned may be different from the original request. A WebView’s resource load delegate may modify requests by implementing webView:resource:willSendRequest:redirectResponse:fromDataSource:.

Availability
See Also
Declared In
WebDataSource.h

response

Returns the associated WebResourceResponse for this data source.

- (NSURLResponse *)response

Discussion

This method returns nil if a response has not been received yet.

Availability
See Also
Declared In
WebDataSource.h

subresourceForURL:

Returns a subresource for the given URL.

- (WebResource *)subresourceForURL:(NSURL *)URL

Discussion

Return nil if the receiver hasn’t finished downloading the subresource.

Availability
See Also
Declared In
WebDataSource.h

subresources

Returns the receiver’s subresources that have finished downloading.

- (NSArray *)subresources

Availability
See Also
Declared In
WebDataSource.h

textEncodingName

Returns either the text encoding for the receiver’s WebView, if set, or the text encoding of the response.

- (NSString *)textEncodingName

Availability
Declared In
WebDataSource.h

unreachableURL

Returns the receiver’s unreachable URL if it exists, nil otherwise.

- (NSURL *)unreachableURL

Discussion

The receiver will have an unreachable URL if it was created using the loadAlternateHTMLString:baseURL:forUnreachableURL: WebFrame method.

Availability
Declared In
WebDataSource.h

webArchive

Returns a web archive representing the receiver, its subresources and subframes.

- (WebArchive *)webArchive

Discussion

Constructs the web archive using the original downloaded data. In the case of HTML, if the current content is preferred, then send webArchive to the appropriate DOM object.

Availability
See Also
Declared In
WebDataSource.h

webFrame

Returns the web frame that represents this data source.

- (WebFrame *)webFrame

Availability
Declared In
WebDataSource.h

Next Page > Hide TOC


Last updated: 2006-05-23




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice