crw_wk_navigation_states.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2016 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_STATES_H_
  5. #define IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_STATES_H_
  6. #include <memory>
  7. #import <Foundation/Foundation.h>
  8. #import <WebKit/WebKit.h>
  9. namespace web {
  10. class NavigationContextImpl;
  11. // State of in-flight WKNavigation objects.
  12. enum class WKNavigationState : int {
  13. // Navigation does not exist.
  14. NONE = 0,
  15. // WKNavigation returned from |loadRequest:|, |goToBackForwardListItem:|,
  16. // |loadFileURL:allowingReadAccessToURL:|, |loadHTMLString:baseURL:|,
  17. // |loadData:MIMEType:characterEncodingName:baseURL:|, |goBack|, |goForward|,
  18. // |reload| or |reloadFromOrigin|.
  19. REQUESTED,
  20. // WKNavigation passed to |webView:didStartProvisionalNavigation:|.
  21. STARTED,
  22. // WKNavigation passed to
  23. // |webView:didReceiveServerRedirectForProvisionalNavigation:|.
  24. REDIRECTED,
  25. // WKNavigation passed to |webView:didFailProvisionalNavigation:|.
  26. PROVISIONALY_FAILED,
  27. // WKNavigation passed to |webView:didCommitNavigation:|.
  28. COMMITTED,
  29. // WKNavigation passed to |webView:didFinishNavigation:|.
  30. FINISHED,
  31. // WKNavigation passed to |webView:didFailNavigation:withError:|.
  32. FAILED,
  33. };
  34. } // namespace web
  35. // Stores states and navigation contexts for WKNavigation objects.
  36. // Allows looking up for last added navigation object. null WKNavigation is a
  37. // valid navigation and treated as a unique key. WKWebView passes null
  38. // WKNavigation to WKNavigationDelegate callbacks if navigation represents
  39. // window opening action.
  40. @interface CRWWKNavigationStates : NSObject
  41. // Adds a new navigation if it was not added yet. If navigation was already
  42. // added then updates state for existing navigation. Updating state does not
  43. // affect the result of |lastAddedNavigation| method. New added navigations
  44. // should have WKNavigationState::REQUESTED, WKNavigationState::STARTED or
  45. // WKNavigationState::COMMITTED state. |navigation| will be held as a weak
  46. // reference and will not be retained. No-op if |navigation| is null.
  47. - (void)setState:(web::WKNavigationState)state
  48. forNavigation:(WKNavigation*)navigation;
  49. // Returns state for a given |navigation| or NONE if navigation does not exist.
  50. - (web::WKNavigationState)stateForNavigation:(WKNavigation*)navigation;
  51. // Removes given |navigation| and returns ownership of the associated navigation
  52. // context. Fails if |navigation| does not exist. |navigation| can be null.
  53. // Cliens don't have to call this method for non-null navigations because
  54. // non-null navigations are weak and will be automatically removed when system
  55. // releases finished navigaitons. This method must always be called for
  56. // completed null navigations because they are not removed automatically.
  57. - (std::unique_ptr<web::NavigationContextImpl>)removeNavigation:
  58. (WKNavigation*)navigation;
  59. // Adds a new navigation if it was not added yet. If navigation was already
  60. // added then updates context for existing navigation. Updating context does not
  61. // affect the result of |lastAddedNavigation| method. |navigation| will be held
  62. // as a weak reference and will not be retained. No-op if |navigation| is null.
  63. - (void)setContext:(std::unique_ptr<web::NavigationContextImpl>)context
  64. forNavigation:(WKNavigation*)navigation;
  65. // Returns context if one was previously associated with given |navigation|.
  66. // Returns null if |navigation| is null.
  67. - (web::NavigationContextImpl*)contextForNavigation:(WKNavigation*)navigation;
  68. // WKNavigation which was added the most recently via |setState:forNavigation:|.
  69. // Updating navigation state via |setState:forNavigation:| does not change the
  70. // last added navigation. Returns nil if there are no stored navigations or
  71. // last navigation was null.
  72. - (WKNavigation*)lastAddedNavigation;
  73. // WKNavigation which was added the most recently via |setState:forNavigation:|
  74. // and has associated navigation context with pending item.
  75. - (WKNavigation*)lastNavigationWithPendingItemInNavigationContext;
  76. // State of WKNavigation which was added the most recently via
  77. // |setState:forNavigation:|. WKNavigationState::NONE if CRWWKNavigationStates
  78. // is empty.
  79. - (web::WKNavigationState)lastAddedNavigationState;
  80. // Returns navigations that are not yet committed, finished or failed.
  81. // This array may contain NSNull to represent null WKNavigation.
  82. - (NSSet*)pendingNavigations;
  83. // webView:didCommitNavigation: can be called multiple times.
  84. // webView:didFinishNavigation: can be called before
  85. // webView:didCommitNavigation:. This method returns YES if the given navigation
  86. // has ever been committed.
  87. - (BOOL)isCommittedNavigation:(WKNavigation*)navigation;
  88. @end
  89. #endif // IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_STATES_H_