WebResourceLoadDelegate Protocol Reference

(informal protocol)

Framework
/System/Library/Frameworks/WebKit.framework
Availability
Available in OS X v10.2 and later.
Companion guide
Declared in
WebResourceLoadDelegate.h

Overview

Web view resource load delegates implement this informal protocol to be notified on the progress of loading individual resources. Note that there can be hundreds of resources, such as images and other media, per page. So, if you just want to get page loading status see the WebFrameLoadDelegate protocol.

There’s a separate client request and server response made for each resource on a page. By implementing the webView:identifierForInitialRequest:fromDataSource: method, resource load delegates provide a tracking object used to identify individual resources in subsequent calls to delegate methods. Delegates are then notified when resource loading starts, when data is incrementally received, when any load errors occur, and when the load is complete. Delegates may also change a request before it is sent. In some cases, depending on the page content and server redirects, methods defined in this protocol may be invoked multiple times (see individual method descriptions for more details). All the methods in this protocol are optional.

Tasks

Setting Identifiers

Loading Content

Authenticating Resources

Instance Methods

webView:identifierForInitialRequest:fromDataSource:

Returns an identifier object used to track the progress of loading a single resource.

- (id)webView:(WebView *)sender identifierForInitialRequest:(NSURLRequest *)request fromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

request

The request that initiated this load for dataSource.

dataSource

The data source for this web view.

Return Value

An identifier object that is retained by sender and passed as a parameter to all other delegate messages pertaining to this resource.

Discussion

Delegates might implement this method to begin tracking the progress of loading an individual resource. Note that this method is invoked once per load where as the webView:resource:willSendRequest:redirectResponse:fromDataSource: method may be invoked multiple times.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:plugInFailedWithError:dataSource:

Invoked when a plug-in fails to load.

- (void)webView:(WebView *)sender plugInFailedWithError:(NSError *)error dataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

error

The error that occurred during the process of loading that resource.

The userInfo dictionary of error may contain additional information about the failure. If the userInfo dictionary is not nil, it may contain some or all of these key-value pairs. The value of the NSErrorFailingURLKey key is a URL string of the SRC attribute. The value of the WebKitErrorPlugInNameKey key is a string containing the plug-in's name. The value for the WebKitErrorPlugInPageURLStringKey key is a URL string of the PLUGINSPAGE attribute. The value of the WebKitErrorMIMETypeKey key is a string of the TYPE attribute.

dataSource

The data source for this web view.

Discussion

This method might be invoked if a plug-in is not found, fails to load, or is not available for some reason. Delegates might implement this method to display or log a detailed error message. If you do not implement this method, no action is taken.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:resource:didCancelAuthenticationChallenge:fromDataSource:

Invoked when an authentication challenge for a resource was canceled.

- (void)webView:(WebView *)sender resource:(id)identifier didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

identifier

An identifier object used to track the resource being loaded by dataSource.

challenge

The authentication challenge that was canceled.

dataSource

The data source for this web view.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:resource:didFailLoadingWithError:fromDataSource:

Invoked when a resource failed to load.

- (void)webView:(WebView *)sender resource:(id)identifier didFailLoadingWithError:(NSError *)error fromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

identifier

An identifier object used to track the resource being loaded by dataSource.

error

The error that occurred loading that resource.

dataSource

The data source for this web view.

Discussion

Delegates might implement this method to display or log a detailed error message.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:resource:didFinishLoadingFromDataSource:

Invoked when all of the data for a given resource is loaded.

- (void)webView:(WebView *)sender resource:(id)identifier didFinishLoadingFromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

identifier

An identifier object used to track the resource being loaded by dataSource.

dataSource

The data source for this web view.

Discussion

The identifier parameter is used to track the resource being loaded by dataSource. Delegates might implement this method to update the load status of an individual resource.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:resource:didReceiveAuthenticationChallenge:fromDataSource:

Invoked when an authentication challenge has been received for a resource.

- (void)webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

identifier

An identifier object used to track the resource being loaded by dataSource.

challenge

The authentication challenge that was received.

dataSource

The data source for this web view.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:resource:didReceiveContentLength:fromDataSource:

Invoked when some of the data for a given resource has arrived.

- (void)webView:(WebView *)sender resource:(id)identifier didReceiveContentLength:(NSInteger)length fromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

identifier

An identifier object used to track the resource being loaded by dataSource.

length

The amount of incremental data received for this resource—the amount of data loaded since the last time this method was invoked for this resource, not the total amount received for this resource.

The length parameter type was changed from type unsigned int to type NSUInteger in Mac OS X v10.5.

dataSource

The data source for this web view.

Discussion

Delegates might implement this method to update the load status of an individual resource.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:resource:didReceiveResponse:fromDataSource:

Invoked after a resource has been loaded.

- (void)webView:(WebView *)sender resource:(id)identifier didReceiveResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

identifier

An identifier object used to track the resource being loaded by dataSource.

response

The reply that was received.

dataSource

The data source for this web view.

Discussion

In some rare cases, multiple responses may be received for a single resource. This happens in the case of multipart/x-mixed-replace, also known as a server push. In this case, delegates should assume that the progress of loading this resource restarts, and the expected content length may change.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h

webView:resource:willSendRequest:redirectResponse:fromDataSource:

Invoked before a request is initiated for a resource and returns a possibly modified request.

- (NSURLRequest *)webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)dataSource
Parameters
sender

The web view that sent this message.

identifier

An identifier object used to track the resource being loaded by dataSource.

request

The request that is sent.

redirectResponse

The redirect server response. If nil, there is no redirect in progress.

dataSource

The data source for this web view.

Return Value

A possibly modified request.

Discussion

Delegates might implement this method to modify resource requests before they are sent. Note that this method might be invoked multiple times per load (as a result of a server redirect) where as the webView:identifierForInitialRequest:fromDataSource: method is invoked once.

Availability
  • Available in OS X v10.2 and later.
Declared In
WebResourceLoadDelegate.h