WebResourceLoadDelegate Protocol Reference
(informal protocol)
| 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 | 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
-
– webView:resource:willSendRequest:redirectResponse:fromDataSource: -
– webView:resource:didFinishLoadingFromDataSource: -
– webView:resource:didReceiveResponse:fromDataSource: -
– webView:resource:didReceiveContentLength:fromDataSource: -
– webView:resource:didFailLoadingWithError:fromDataSource: -
– webView:plugInFailedWithError:dataSource:
Authenticating Resources
Instance Methods
webView:identifierForInitialRequest:fromDataSource:
Returns an identifier object used to track the progress of loading a single resource.
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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:plugInFailedWithError:dataSource:
Invoked when a plug-in fails to load.
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
userInfodictionary is notnil, it may contain some or all of these key-value pairs. The value of theNSErrorFailingURLKeykey is a URL string of theSRCattribute. The value of theWebKitErrorPlugInNameKeykey is a string containing the plug-in's name. The value for theWebKitErrorPlugInPageURLStringKeykey is a URL string of thePLUGINSPAGEattribute. The value of theWebKitErrorMIMETypeKeykey is a string of theTYPEattribute.- 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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:resource:didCancelAuthenticationChallenge:fromDataSource:
Invoked when an authentication challenge for a resource was canceled.
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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:resource:didFailLoadingWithError:fromDataSource:
Invoked when a resource failed to load.
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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:resource:didFinishLoadingFromDataSource:
Invoked when all of the data for a given resource is loaded.
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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:resource:didReceiveAuthenticationChallenge:fromDataSource:
Invoked when an authentication challenge has been received for a resource.
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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:resource:didReceiveContentLength:fromDataSource:
Invoked when some of the data for a given resource has arrived.
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 intto typeNSUIntegerin 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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:resource:didReceiveResponse:fromDataSource:
Invoked after a resource has been loaded.
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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.hwebView:resource:willSendRequest:redirectResponse:fromDataSource:
Invoked before a request is initiated for a resource and returns a possibly modified request.
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 Mac OS X v10.2 with Safari 1.0 and later.
- Available in Mac OS X v10.2.7 and later.
Declared In
WebResourceLoadDelegate.h© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-02-24)