(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 | WebPolicyDelegate.h |
The WebPolicyDelegate informal protocol works with the WebPolicyDecisionListener protocol to modify the policy decisions that the WebView class makes when handling URLs or the data objects they represent. The methods in this protocol are typically invoked in the following order.
The webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: method is invoked once for every load.
The webView:decidePolicyForNavigationAction:request:frame:decisionListener: method may be invoked zero or more times after a load started. This method is invoked every time a server redirect is encountered unless blocked by an earlier policy decision.
The webView:decidePolicyForMIMEType:request:frame:decisionListener: method is invoked after the MIME type of the content is known unless this method is blocked by an earlier policy decision.
The webView:unableToImplementPolicyWithError:frame: method is invoked when an error occurs implementing a policy decision.
– webView:unableToImplementPolicyWithError:frame: required method
Decides whether to display content with a given MIME type. (required)
- (void)webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener
The associated web view.
The MIME type of the content.
The request to load the content.
The frame for displaying the content.
The object that receives the policy decision.
This method is invoked during the process of loading content for request after the webView:didStartProvisionalLoadForFrame: method in the WebFrameLoadDelegate informal protocol is called by the WebView object. The web view implements a policy decision by sending one of the WebPolicyDecisionListener protocol messages to listener.
If you do not implement this method, the default behavior is used. The listener is told to ignore the MIME type unless webView specifies it can handle the type in its canShowMIMEType: method.
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, this method will be invoked multiple times.
WebPolicyDelegate.hRoutes a navigation action internally or to an external viewer. (required)
- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener
The WebView object for which this object is the policy delegate.
A description of the action that triggered the navigation request. The possible key-value pairs in this dictionary are defined in “Action Dictionary Keys.”
The request for which the navigation is made.
The WebFrame object in which the action occurred.
The WebPolicyDecisionListener object that receives the policy decision.
This method is invoked when a navigation decision needs to be made. The web view implements a policy decision by sending one of the WebPolicyDecisionListener protocol messages to listener. This method is invoked whenever a server redirect is encountered, and before loading starts.
If you do not implement this method, the default behavior is used. The listener handles the navigation internally if the request is for an error page or if the canHandleRequest: method of the NSURLConnection class returns YES when passed request. Otherwise, the listener ignores the navigation, and it is handled externally.
WebPolicyDelegate.hDecides whether to allow a targeted navigation event, such as opening a link in a new window. (required)
- (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id < WebPolicyDecisionListener >)listener
The WebView object for which this object is the policy delegate.
A description of the action that triggered the navigation request. The possible key-value pairs in this dictionary are defined in “Making content decisions.”
The request for which the new window action is performed.
The name of the new frame that contains the content returned from the request.
The WebPolicyDecisionListener object that receives the policy decision.
This method is invoked when a targeted navigation decision needs to be made. A targeted navigation typically opens a new window to display content. The receiver implements a policy decision by sending one of the WebPolicyDecisionListener protocol messages to listener. This method allows delegates to modify the behavior of targeted links which normally open a new window. Delegates might do something else, such as download or present the content in a special way. If this method sends use to listener then the new window will be opened, and webView:decidePolicyForNavigationAction:request:frame:decisionListener: will be invoked with a WebNavigationTypeOther as the value for the WebActionNavigationTypeKey key in the action dictionary.
The default behavior sends use to listener.
WebPolicyDelegate.hHandles or drops events that were rejected by a policy maker. (required)
- (void)webView:(WebView *)webView unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame
The WebView object for which this object is the policy delegate.
The error that occurred.
The frame in which the error occurred.
Delegates might implement this method to display or log an error message. If you do not implement this method, no action is taken.
WebPolicyDelegate.hKeys that might appear in a dictionary passed as the actionInformation parameter to the webView:decidePolicyForNavigationAction:request:frame:decisionListener: and webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: methods.
extern NSString *WebActionNavigationTypeKey; extern NSString *WebActionElementKey; extern NSString *WebActionButtonKey; extern NSString *WebActionModifierFlagsKey; extern NSString *WebActionOriginalURLKey;
WebActionNavigationTypeKeyThe navigation type of the action. Can be any of the values defined in “WebNavigationType” below.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebActionElementKeyA dictionary containing element information. See WebView Class Reference for a description of the key-value pairs in this dictionary.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebActionButtonKeyAn NSNumber object where 0 indicates the left button, 1 indicates the middle button, and 2 indicates the right button. In Mac OS X v10.6, the value changed from an event type.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebActionModifierFlagsKeyAn unsigned number that indicates the modifier flag.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebActionOriginalURLKeyThe URL that initiated the action.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
Possible values for the WebActionNavigationTypeKey key that appears in an action dictionary.
typedef enum {
WebNavigationTypeLinkClicked,
WebNavigationTypeFormSubmitted,
WebNavigationTypeBackForward,
WebNavigationTypeReload,
WebNavigationTypeFormResubmitted,
WebNavigationTypeOther
} WebNavigationType;
WebNavigationTypeLinkClickedA link (an href) was clicked.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebNavigationTypeFormSubmittedA form was submitted.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebNavigationTypeBackForwardThe user clicked back or forward button.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebNavigationTypeReloadThe user hit the reload button.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebNavigationTypeFormResubmittedA form was resubmitted (through a back, forward or reload action).
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
WebNavigationTypeOtherNavigation is taking place for some other reason.
Available in Mac OS X v10.2 and later.
Declared in WebPolicyDelegate.h.
Last updated: 2009-03-30