crw_wk_navigation_handler.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_HANDLER_H_
  5. #define IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_HANDLER_H_
  6. #import <UIKit/UIKit.h>
  7. #import <WebKit/WebKit.h>
  8. #import <memory>
  9. #import "ios/web/security/cert_verification_error.h"
  10. #import "ios/web/web_state/ui/crw_web_view_handler.h"
  11. #import "ios/web/web_state/ui/crw_web_view_handler_delegate.h"
  12. #include "ui/base/page_transition_types.h"
  13. @class CRWWKNavigationHandler;
  14. @class CRWPendingNavigationInfo;
  15. @class CRWWKNavigationStates;
  16. @class CRWCertVerificationController;
  17. class GURL;
  18. namespace web {
  19. enum class WKNavigationState;
  20. enum class ErrorRetryCommand;
  21. struct Referrer;
  22. class NavigationContextImpl;
  23. class WKBackForwardListItemHolder;
  24. }
  25. // CRWWKNavigationHandler uses this protocol to interact with its owner.
  26. @protocol CRWWKNavigationHandlerDelegate <CRWWebViewHandlerDelegate>
  27. // Returns associated certificate verificatio controller.
  28. - (CRWCertVerificationController*)
  29. certVerificationControllerForNavigationHandler:
  30. (CRWWKNavigationHandler*)navigationHandler;
  31. // Sets document URL to newURL, and updates any relevant state information.
  32. - (void)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
  33. setDocumentURL:(const GURL&)newURL
  34. context:(web::NavigationContextImpl*)context;
  35. // Sets up WebUI for URL.
  36. - (void)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
  37. createWebUIForURL:(const GURL&)URL;
  38. - (std::unique_ptr<web::NavigationContextImpl>)
  39. navigationHandler:(CRWWKNavigationHandler*)navigationHandler
  40. registerLoadRequestForURL:(const GURL&)URL
  41. sameDocumentNavigation:(BOOL)sameDocumentNavigation
  42. hasUserGesture:(BOOL)hasUserGesture
  43. rendererInitiated:(BOOL)renderedInitiated;
  44. // Instructs the delegate to display the webView.
  45. - (void)navigationHandlerDisplayWebView:
  46. (CRWWKNavigationHandler*)navigationHandler;
  47. // Notifies the delegate that the page has actually started loading.
  48. - (void)navigationHandlerDidStartLoading:
  49. (CRWWKNavigationHandler*)navigationHandler;
  50. // Notifies the delegate that web process has crashed.
  51. - (void)navigationHandlerWebProcessDidCrash:
  52. (CRWWKNavigationHandler*)navigationHandler;
  53. // Instructs the delegate to load current URL.
  54. - (void)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
  55. loadCurrentURLWithRendererInitiatedNavigation:(BOOL)rendererInitiated;
  56. // Notifies the delegate that load has completed.
  57. - (void)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
  58. didCompleteLoadWithSuccess:(BOOL)loadSuccess
  59. forContext:(web::NavigationContextImpl*)context;
  60. // Resumes download using |webView|
  61. - (void)resumeDownloadWithData:(NSData*)data
  62. completionHandler:(void (^)(WKDownload*))completionHandler
  63. API_AVAILABLE(ios(15));
  64. @end
  65. // Handler class for WKNavigationDelegate, deals with navigation callbacks from
  66. // WKWebView and maintains page loading state.
  67. @interface CRWWKNavigationHandler : CRWWebViewHandler <WKNavigationDelegate>
  68. - (instancetype)init NS_UNAVAILABLE;
  69. - (instancetype)initWithDelegate:(id<CRWWKNavigationHandlerDelegate>)delegate
  70. NS_DESIGNATED_INITIALIZER;
  71. // Indicates if the webview reported a crash.
  72. @property(nonatomic, assign, readonly) BOOL webProcessCrashed;
  73. // Indicates if the next call to decidePolicyForNavigationAction will block
  74. // universal links. This is useful for native session restore's navigation.
  75. @property(nonatomic, assign, readwrite)
  76. BOOL blockUniversalLinksOnNextDecidePolicy;
  77. // Pending information for an in-progress page navigation. The lifetime of
  78. // this object starts at |decidePolicyForNavigationAction| where the info is
  79. // extracted from the request, and ends at either |didCommitNavigation| or
  80. // |didFailProvisionalNavigation|.
  81. @property(nonatomic, strong) CRWPendingNavigationInfo* pendingNavigationInfo;
  82. // Holds all WKNavigation objects and their states which are currently in
  83. // flight.
  84. @property(nonatomic, readonly, strong) CRWWKNavigationStates* navigationStates;
  85. // The current page loading phase.
  86. // TODO(crbug.com/956511): Remove this once refactor is done.
  87. @property(nonatomic, readwrite, assign) web::WKNavigationState navigationState;
  88. // Returns the WKBackForwardlistItemHolder of current navigation item.
  89. @property(nonatomic, readonly, assign)
  90. web::WKBackForwardListItemHolder* currentBackForwardListItemHolder;
  91. // Returns the referrer for the current page.
  92. @property(nonatomic, readonly, assign) web::Referrer currentReferrer;
  93. // Instructs this handler to stop loading.
  94. - (void)stopLoading;
  95. // Informs this handler that any outstanding load operations are cancelled.
  96. - (void)loadCancelled;
  97. // Returns context for pending navigation that has |URL|. null if there is no
  98. // matching pending navigation.
  99. - (web::NavigationContextImpl*)contextForPendingMainFrameNavigationWithURL:
  100. (const GURL&)URL;
  101. // Returns YES if current navigation item is WKNavigationTypeBackForward.
  102. - (BOOL)isCurrentNavigationBackForward;
  103. // Returns YES if the current navigation item corresponds to a web page
  104. // loaded by a POST request.
  105. - (BOOL)isCurrentNavigationItemPOST;
  106. // Sets last committed NavigationItem's title to the given |title|, which can
  107. // not be nil.
  108. - (void)setLastCommittedNavigationItemTitle:(NSString*)title;
  109. // Maps WKNavigationType to ui::PageTransition.
  110. - (ui::PageTransition)pageTransitionFromNavigationType:
  111. (WKNavigationType)navigationType;
  112. // Called when the web page has changed document and/or URL, and so the page
  113. // navigation should be reported to the delegate, and internal state updated to
  114. // reflect the fact that the navigation has occurred. |context| contains
  115. // information about the navigation that triggered the document/URL change.
  116. - (void)webPageChangedWithContext:(web::NavigationContextImpl*)context
  117. webView:(WKWebView*)webView;
  118. @end
  119. #endif // IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_HANDLER_H_