WKNavigationDelegate.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2014-2019 Apple 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. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #import <WebKit/WKFoundation.h>
  26. #import <Foundation/Foundation.h>
  27. NS_ASSUME_NONNULL_BEGIN
  28. @class WKNavigation;
  29. @class WKNavigationAction;
  30. @class WKNavigationResponse;
  31. @class WKWebView;
  32. @class WKWebpagePreferences;
  33. /*! @enum WKNavigationActionPolicy
  34. @abstract The policy to pass back to the decision handler from the
  35. webView:decidePolicyForNavigationAction:decisionHandler: method.
  36. @constant WKNavigationActionPolicyCancel Cancel the navigation.
  37. @constant WKNavigationActionPolicyAllow Allow the navigation to continue.
  38. */
  39. typedef NS_ENUM(NSInteger, WKNavigationActionPolicy) {
  40. WKNavigationActionPolicyCancel,
  41. WKNavigationActionPolicyAllow,
  42. } API_AVAILABLE(macos(10.10), ios(8.0));
  43. /*! @enum WKNavigationResponsePolicy
  44. @abstract The policy to pass back to the decision handler from the webView:decidePolicyForNavigationResponse:decisionHandler: method.
  45. @constant WKNavigationResponsePolicyCancel Cancel the navigation.
  46. @constant WKNavigationResponsePolicyAllow Allow the navigation to continue.
  47. */
  48. typedef NS_ENUM(NSInteger, WKNavigationResponsePolicy) {
  49. WKNavigationResponsePolicyCancel,
  50. WKNavigationResponsePolicyAllow,
  51. } API_AVAILABLE(macos(10.10), ios(8.0));
  52. /*! A class conforming to the WKNavigationDelegate protocol can provide
  53. methods for tracking progress for main frame navigations and for deciding
  54. policy for main frame and subframe navigations.
  55. */
  56. @protocol WKNavigationDelegate <NSObject>
  57. @optional
  58. /*! @abstract Decides whether to allow or cancel a navigation.
  59. @param webView The web view invoking the delegate method.
  60. @param navigationAction Descriptive information about the action
  61. triggering the navigation request.
  62. @param decisionHandler The decision handler to call to allow or cancel the
  63. navigation. The argument is one of the constants of the enumerated type WKNavigationActionPolicy.
  64. @discussion If you do not implement this method, the web view will load the request or, if appropriate, forward it to another application.
  65. */
  66. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;
  67. /*! @abstract Decides whether to allow or cancel a navigation.
  68. @param webView The web view invoking the delegate method.
  69. @param navigationAction Descriptive information about the action
  70. triggering the navigation request.
  71. @param preferences The default set of webpage preferences. This may be
  72. changed by setting defaultWebpagePreferences on WKWebViewConfiguration.
  73. @param decisionHandler The policy decision handler to call to allow or cancel
  74. the navigation. The arguments are one of the constants of the enumerated type
  75. WKNavigationActionPolicy, as well as an instance of WKWebpagePreferences.
  76. @discussion If you implement this method,
  77. -webView:decidePolicyForNavigationAction:decisionHandler: will not be called.
  78. */
  79. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction preferences:(WKWebpagePreferences *)preferences decisionHandler:(void (^)(WKNavigationActionPolicy, WKWebpagePreferences *))decisionHandler API_AVAILABLE(macos(10.15), ios(13.0));
  80. /*! @abstract Decides whether to allow or cancel a navigation after its
  81. response is known.
  82. @param webView The web view invoking the delegate method.
  83. @param navigationResponse Descriptive information about the navigation
  84. response.
  85. @param decisionHandler The decision handler to call to allow or cancel the
  86. navigation. The argument is one of the constants of the enumerated type WKNavigationResponsePolicy.
  87. @discussion If you do not implement this method, the web view will allow the response, if the web view can show it.
  88. */
  89. - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler;
  90. /*! @abstract Invoked when a main frame navigation starts.
  91. @param webView The web view invoking the delegate method.
  92. @param navigation The navigation.
  93. */
  94. - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation;
  95. /*! @abstract Invoked when a server redirect is received for the main
  96. frame.
  97. @param webView The web view invoking the delegate method.
  98. @param navigation The navigation.
  99. */
  100. - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(null_unspecified WKNavigation *)navigation;
  101. /*! @abstract Invoked when an error occurs while starting to load data for
  102. the main frame.
  103. @param webView The web view invoking the delegate method.
  104. @param navigation The navigation.
  105. @param error The error that occurred.
  106. */
  107. - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error;
  108. /*! @abstract Invoked when content starts arriving for the main frame.
  109. @param webView The web view invoking the delegate method.
  110. @param navigation The navigation.
  111. */
  112. - (void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation;
  113. /*! @abstract Invoked when a main frame navigation completes.
  114. @param webView The web view invoking the delegate method.
  115. @param navigation The navigation.
  116. */
  117. - (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation;
  118. /*! @abstract Invoked when an error occurs during a committed main frame
  119. navigation.
  120. @param webView The web view invoking the delegate method.
  121. @param navigation The navigation.
  122. @param error The error that occurred.
  123. */
  124. - (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error;
  125. /*! @abstract Invoked when the web view needs to respond to an authentication challenge.
  126. @param webView The web view that received the authentication challenge.
  127. @param challenge The authentication challenge.
  128. @param completionHandler The completion handler you must invoke to respond to the challenge. The
  129. disposition argument is one of the constants of the enumerated type
  130. NSURLSessionAuthChallengeDisposition. When disposition is NSURLSessionAuthChallengeUseCredential,
  131. the credential argument is the credential to use, or nil to indicate continuing without a
  132. credential.
  133. @discussion If you do not implement this method, the web view will respond to the authentication challenge with the NSURLSessionAuthChallengeRejectProtectionSpace disposition.
  134. */
  135. - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler;
  136. /*! @abstract Invoked when the web view's web content process is terminated.
  137. @param webView The web view whose underlying web content process was terminated.
  138. */
  139. - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView API_AVAILABLE(macos(10.11), ios(9.0));
  140. @end
  141. NS_ASSUME_NONNULL_END