OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_ | |
6 #define COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_ | |
7 | |
8 #include "base/memory/scoped_vector.h" | |
9 | |
10 #include "base/macros.h" | |
11 #include "components/web_view/public/interfaces/web_view.mojom.h" | |
12 #include "url/gurl.h" | |
13 | |
14 namespace web_view { | |
15 | |
16 class Frame; | |
17 class NavigationEntry; | |
18 class NavigationControllerDelegate; | |
19 enum class ReloadType; | |
20 | |
21 // A NavigationController maintains the back-forward list for a WebView and | |
22 // manages all navigation within that list. | |
23 // | |
24 // Each NavigationController belongs to one WebContents; each WebContents has | |
25 // exactly one NavigationController. | |
26 class NavigationController { | |
27 public: | |
28 explicit NavigationController(NavigationControllerDelegate* delegate); | |
29 ~NavigationController(); | |
30 | |
31 int GetCurrentEntryIndex() const; | |
32 int GetIndexForOffset(int offset) const; | |
33 int GetEntryCount() const; | |
34 NavigationEntry* GetEntryAtIndex(int index) const; | |
35 NavigationEntry* GetEntryAtOffset(int offset) const; | |
36 bool CanGoBack() const; | |
37 bool CanGoForward() const; | |
38 bool CanGoToOffset(int offset) const; | |
39 | |
40 void GoBack(); | |
41 void GoForward(); | |
42 | |
43 void LoadURL(mojo::URLRequestPtr request); | |
44 | |
45 void NavigateToPendingEntry(ReloadType reload_type, | |
46 bool update_navigation_start_time); | |
47 | |
48 // Takes ownership of a pending entry, and adds it to the current list. | |
49 // | |
50 // TODO(erg): This should eventually own the navigation transition like | |
51 // content::NavigationControllerImpl::NavigateToPendingEntry() does. | |
52 void SetPendingEntry(scoped_ptr<NavigationEntry> entry); | |
53 | |
54 // Discards only the pending entry. |was_failure| should be set if the pending | |
55 // entry is being discarded because it failed to load. | |
56 void DiscardPendingEntry(bool was_failure); | |
57 | |
58 // Called when a frame is committed. | |
59 void FrameDidCommitProvisionalLoad(Frame* frame); | |
60 | |
61 // Called when a frame navigated by itself. Adds the new url to the | |
62 // back/forward stack. | |
63 void FrameDidNavigateLocally(Frame* frame, const GURL& url); | |
64 | |
65 private: | |
66 using NavigationEntries = ScopedVector<NavigationEntry>; | |
67 | |
68 void ClearForwardEntries(); | |
69 | |
70 NavigationEntries entries_; | |
71 | |
72 // An entry we haven't gotten a response for yet. This will be discarded | |
73 // when we navigate again. It's used only so we know what the currently | |
74 // displayed tab is. | |
75 // | |
76 // This may refer to an item in the entries_ list if the pending_entry_index_ | |
77 // == -1, or it may be its own entry that should be deleted. Be careful with | |
78 // the memory management. | |
79 NavigationEntry* pending_entry_; | |
80 | |
81 // The index of the currently visible entry. | |
82 int last_committed_entry_index_; | |
83 | |
84 // The index of the pending entry if it is in entries_, or -1 if | |
85 // pending_entry_ is a new entry (created by LoadURL). | |
86 int pending_entry_index_; | |
87 | |
88 NavigationControllerDelegate* delegate_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(NavigationController); | |
91 }; | |
92 | |
93 } // namespace web_view | |
94 | |
95 #endif // COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_ | |
OLD | NEW |