| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 |
| 5 #ifndef IOS_WEB_NAVIGATION_WK_BASED_NAVIGATION_MANAGER_IMPL_H_ |
| 6 #define IOS_WEB_NAVIGATION_WK_BASED_NAVIGATION_MANAGER_IMPL_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <vector> |
| 12 |
| 13 #import "base/mac/scoped_nsobject.h" |
| 14 #include "base/macros.h" |
| 15 #import "ios/web/navigation/navigation_item_impl.h" |
| 16 #import "ios/web/navigation/navigation_manager_impl.h" |
| 17 #include "ios/web/public/reload_type.h" |
| 18 #include "ui/base/page_transition_types.h" |
| 19 #include "url/gurl.h" |
| 20 |
| 21 namespace web { |
| 22 class BrowserState; |
| 23 class NavigationItem; |
| 24 struct Referrer; |
| 25 class NavigationManagerDelegate; |
| 26 class SessionStorageBuilder; |
| 27 |
| 28 // WKBackForwardList based implementation of NavigationManagerImpl. |
| 29 class WKBasedNavigationManagerImpl : public NavigationManagerImpl { |
| 30 public: |
| 31 WKBasedNavigationManagerImpl(); |
| 32 ~WKBasedNavigationManagerImpl() override; |
| 33 |
| 34 // NavigationManagerImpl: |
| 35 void SetDelegate(NavigationManagerDelegate* delegate) override; |
| 36 void SetBrowserState(BrowserState* browser_state) override; |
| 37 void SetSessionController(CRWSessionController* session_controller) override; |
| 38 void InitializeSession() override; |
| 39 void ReplaceSessionHistory(std::vector<std::unique_ptr<NavigationItem>> items, |
| 40 int current_index) override; |
| 41 void OnNavigationItemsPruned(size_t pruned_item_count) override; |
| 42 void OnNavigationItemChanged() override; |
| 43 void OnNavigationItemCommitted() override; |
| 44 CRWSessionController* GetSessionController() const override; |
| 45 void AddTransientItem(const GURL& url) override; |
| 46 void AddPendingItem( |
| 47 const GURL& url, |
| 48 const web::Referrer& referrer, |
| 49 ui::PageTransition navigation_type, |
| 50 NavigationInitiationType initiation_type, |
| 51 UserAgentOverrideOption user_agent_override_option) override; |
| 52 void CommitPendingItem() override; |
| 53 std::unique_ptr<std::vector<BrowserURLRewriter::URLRewriter>> |
| 54 GetTransientURLRewriters() override; |
| 55 void RemoveTransientURLRewriters() override; |
| 56 int GetIndexForOffset(int offset) const override; |
| 57 int GetPreviousItemIndex() const override; |
| 58 |
| 59 // NavigationManager: |
| 60 BrowserState* GetBrowserState() const override; |
| 61 WebState* GetWebState() const override; |
| 62 NavigationItem* GetVisibleItem() const override; |
| 63 NavigationItem* GetLastCommittedItem() const override; |
| 64 NavigationItem* GetPendingItem() const override; |
| 65 NavigationItem* GetTransientItem() const override; |
| 66 void DiscardNonCommittedItems() override; |
| 67 void LoadURLWithParams(const NavigationManager::WebLoadParams&) override; |
| 68 void AddTransientURLRewriter( |
| 69 BrowserURLRewriter::URLRewriter rewriter) override; |
| 70 int GetItemCount() const override; |
| 71 NavigationItem* GetItemAtIndex(size_t index) const override; |
| 72 int GetIndexOfItem(const NavigationItem* item) const override; |
| 73 int GetPendingItemIndex() const override; |
| 74 int GetLastCommittedItemIndex() const override; |
| 75 bool RemoveItemAtIndex(int index) override; |
| 76 bool CanGoBack() const override; |
| 77 bool CanGoForward() const override; |
| 78 bool CanGoToOffset(int offset) const override; |
| 79 void GoBack() override; |
| 80 void GoForward() override; |
| 81 void GoToIndex(int index) override; |
| 82 void Reload(ReloadType reload_type, bool check_for_reposts) override; |
| 83 NavigationItemList GetBackwardItems() const override; |
| 84 NavigationItemList GetForwardItems() const override; |
| 85 void CopyStateFromAndPrune(const NavigationManager* source) override; |
| 86 bool CanPruneAllButLastCommittedItem() const override; |
| 87 |
| 88 private: |
| 89 // The SessionStorageBuilder functions require access to private variables of |
| 90 // NavigationManagerImpl. |
| 91 friend SessionStorageBuilder; |
| 92 |
| 93 // NavigationManagerImpl methods used by SessionStorageBuilder. |
| 94 NavigationItemImpl* GetNavigationItemImplAtIndex(size_t index) const override; |
| 95 |
| 96 // Current item is the anchor of the navigation history. |
| 97 // int GetCurrentItemIndex() const; |
| 98 // NavigationItem* GetCurrentItem() const; |
| 99 |
| 100 // Sync navigation_items_ to WKBackForwardList. This should be no-op in most |
| 101 // cases, but will do real work after a renderer-initiated navigation. |
| 102 // This method guarantees the navigation_items_ invariant. |
| 103 // Returns true if committed_navigation_items_ were updated; false if no-op. |
| 104 bool SyncNavigationItems() const; |
| 105 |
| 106 // The primary delegate for this manager. |
| 107 NavigationManagerDelegate* delegate_; |
| 108 |
| 109 // The BrowserState that is associated with this instance. |
| 110 BrowserState* browser_state_; |
| 111 |
| 112 // List of transient url rewriters added by |AddTransientURLRewriter()|. |
| 113 std::unique_ptr<std::vector<BrowserURLRewriter::URLRewriter>> |
| 114 transient_url_rewriters_; |
| 115 |
| 116 // NavigationItemImpl objects associated with the back/forward history. |
| 117 // Invariant: |
| 118 // navigation_items_.size() == GetItemCount() == backList.count + |
| 119 // forwardList.count + currentItem ? 1 : 0. |
| 120 mutable std::vector<std::unique_ptr<NavigationItemImpl>> |
| 121 committed_navigation_items_; |
| 122 |
| 123 std::unique_ptr<NavigationItemImpl> pending_item_; |
| 124 std::unique_ptr<NavigationItemImpl> transient_item_; |
| 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(WKBasedNavigationManagerImpl); |
| 127 }; |
| 128 |
| 129 } // namespace web |
| 130 |
| 131 #endif // IOS_WEB_NAVIGATION_WK_BASED_NAVIGATION_MANAGER_IMPL_H_ |
| OLD | NEW |