summaryrefslogtreecommitdiffstats
path: root/components/web_view/navigation_controller.h
blob: 635dfe591b4a10efb1d7cbd697cfaef7f9d66dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_
#define COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_

#include "base/memory/scoped_vector.h"

#include "components/web_view/public/interfaces/web_view.mojom.h"
#include "url/gurl.h"

namespace web_view {

class Frame;
class NavigationEntry;
class NavigationControllerDelegate;
enum class ReloadType;

// A NavigationController maintains the back-forward list for a WebView and
// manages all navigation within that list.
//
// Each NavigationController belongs to one WebContents; each WebContents has
// exactly one NavigationController.
class NavigationController {
 public:
  explicit NavigationController(NavigationControllerDelegate* delegate);
  ~NavigationController();

  int GetCurrentEntryIndex() const;
  int GetIndexForOffset(int offset) const;
  int GetEntryCount() const;
  NavigationEntry* GetEntryAtIndex(int index) const;
  NavigationEntry* GetEntryAtOffset(int offset) const;
  bool CanGoBack() const;
  bool CanGoForward() const;
  bool CanGoToOffset(int offset) const;

  void GoBack();
  void GoForward();

  void LoadURL(mojo::URLRequestPtr request);

  void NavigateToPendingEntry(ReloadType reload_type,
                              bool update_navigation_start_time);

  // Takes ownership of a pending entry, and adds it to the current list.
  //
  // TODO(erg): This should eventually own the navigation transition like
  // content::NavigationControllerImpl::NavigateToPendingEntry() does.
  void SetPendingEntry(scoped_ptr<NavigationEntry> entry);

  // Discards only the pending entry. |was_failure| should be set if the pending
  // entry is being discarded because it failed to load.
  void DiscardPendingEntry(bool was_failure);

  // Called when a frame is committed.
  void FrameDidCommitProvisionalLoad(Frame* frame);

  // Called when a frame navigated by itself. Adds the new url to the
  // back/forward stack.
  void FrameDidNavigateLocally(Frame* frame, const GURL& url);

 private:
  using NavigationEntries = ScopedVector<NavigationEntry>;

  void ClearForwardEntries();

  NavigationEntries entries_;

  // An entry we haven't gotten a response for yet.  This will be discarded
  // when we navigate again.  It's used only so we know what the currently
  // displayed tab is.
  //
  // This may refer to an item in the entries_ list if the pending_entry_index_
  // == -1, or it may be its own entry that should be deleted. Be careful with
  // the memory management.
  NavigationEntry* pending_entry_;

  // The index of the currently visible entry.
  int last_committed_entry_index_;

  // The index of the pending entry if it is in entries_, or -1 if
  // pending_entry_ is a new entry (created by LoadURL).
  int pending_entry_index_;

  NavigationControllerDelegate* delegate_;

  DISALLOW_COPY_AND_ASSIGN(NavigationController);
};

}  // namespace web_view

#endif  // COMPONENTS_WEB_VIEW_NAVIGATION_CONTROLLER_H_