Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / components / web_view / navigation_controller.h
blob6847a083e032ece33cfcb902ee739f4b5864da30
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.
5 #ifndef COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_
6 #define COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_
8 #include "base/memory/scoped_vector.h"
10 #include "components/web_view/public/interfaces/web_view.mojom.h"
12 namespace web_view {
14 class Frame;
15 class NavigationEntry;
16 class NavigationControllerDelegate;
17 enum class ReloadType;
19 // A NavigationController maintains the back-forward list for a WebView and
20 // manages all navigation within that list.
22 // Each NavigationController belongs to one WebContents; each WebContents has
23 // exactly one NavigationController.
24 class NavigationController {
25 public:
26 explicit NavigationController(NavigationControllerDelegate* delegate);
27 ~NavigationController();
29 int GetCurrentEntryIndex() const;
30 int GetIndexForOffset(int offset) const;
31 int GetEntryCount() const;
32 NavigationEntry* GetEntryAtIndex(int index) const;
33 NavigationEntry* GetEntryAtOffset(int offset) const;
34 bool CanGoBack() const;
35 bool CanGoForward() const;
36 bool CanGoToOffset(int offset) const;
38 void GoBack();
39 void GoForward();
41 void LoadURL(mojo::URLRequestPtr request);
43 void NavigateToPendingEntry(ReloadType reload_type);
45 // Takes ownership of a pending entry, and adds it to the current list.
47 // TODO(erg): This should eventually own the navigation transition like
48 // content::NavigationControllerImpl::NavigateToPendingEntry() does.
49 void SetPendingEntry(scoped_ptr<NavigationEntry> entry);
51 // Discards only the pending entry. |was_failure| should be set if the pending
52 // entry is being discarded because it failed to load.
53 void DiscardPendingEntry(bool was_failure);
55 // Called when a frame is committed.
56 void FrameDidCommitProvisionalLoad(Frame* frame);
58 private:
59 using NavigationEntries = ScopedVector<NavigationEntry>;
60 NavigationEntries entries_;
62 // An entry we haven't gotten a response for yet. This will be discarded
63 // when we navigate again. It's used only so we know what the currently
64 // displayed tab is.
66 // This may refer to an item in the entries_ list if the pending_entry_index_
67 // == -1, or it may be its own entry that should be deleted. Be careful with
68 // the memory management.
69 NavigationEntry* pending_entry_;
71 // The index of the currently visible entry.
72 int last_committed_entry_index_;
74 // The index of the pending entry if it is in entries_, or -1 if
75 // pending_entry_ is a new entry (created by LoadURL).
76 int pending_entry_index_;
78 NavigationControllerDelegate* delegate_;
80 DISALLOW_COPY_AND_ASSIGN(NavigationController);
83 } // namespace web_view
85 #endif // COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_