blob: 4af74389e665e2930606a40303ae286660105c9a [file] [log] [blame]
[email protected]d4a8ca482013-10-30 21:06:401// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]0dd3a0ab2011-02-18 08:17:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d4a8ca482013-10-30 21:06:405#ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_CONTROLLER_IMPL_H_
6#define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_CONTROLLER_IMPL_H_
[email protected]0dd3a0ab2011-02-18 08:17:447
avib7348942015-12-25 20:57:108#include <stddef.h>
9#include <stdint.h>
10
avif16f85a72015-11-13 18:25:0311#include <vector>
12
[email protected]c5b88d82012-10-06 17:03:3313#include "base/callback.h"
[email protected]3c15fcbc2011-12-29 16:43:1714#include "base/compiler_specific.h"
[email protected]c5b88d82012-10-06 17:03:3315#include "base/gtest_prod_util.h"
avib7348942015-12-25 20:57:1016#include "base/macros.h"
Lukasz Anforowicz63f3b9432019-05-30 05:42:5817#include "base/optional.h"
[email protected]a43858f2013-06-28 15:18:3718#include "base/time/time.h"
19#include "build/build_config.h"
Arthur Sonzogni620cec62018-12-13 13:08:5720#include "content/browser/frame_host/back_forward_cache.h"
[email protected]d4a8ca482013-10-30 21:06:4021#include "content/browser/frame_host/navigation_controller_delegate.h"
creis3da03872015-02-20 21:12:3222#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]74b962a2011-06-03 21:22:5423#include "content/browser/ssl/ssl_manager.h"
[email protected]71fde352011-12-29 03:29:5624#include "content/public/browser/navigation_controller.h"
[email protected]e6e646d2011-12-01 00:50:1125#include "content/public/browser/navigation_type.h"
toyoshim0df1d3a2016-09-09 09:52:4826#include "content/public/browser/reload_type.h"
[email protected]0dd3a0ab2011-02-18 08:17:4427
[email protected]37567b432014-02-12 01:12:2228struct FrameHostMsg_DidCommitProvisionalLoad_Params;
[email protected]0dd3a0ab2011-02-18 08:17:4429
[email protected]8286f51a2011-05-31 17:39:1330namespace content {
Owen Min45db3a5d2019-07-31 20:13:2931enum class WasActivatedOption;
creis3cdc3b02015-05-29 23:00:4732class FrameTreeNode;
creis3da03872015-02-20 21:12:3233class RenderFrameHostImpl;
[email protected]b6583592012-01-25 19:52:3334class SiteInstance;
[email protected]8ff00d72012-10-23 19:12:2135struct LoadCommittedDetails;
[email protected]8286f51a2011-05-31 17:39:1336
Nico Weber43ddd7a32017-08-15 19:19:2737class CONTENT_EXPORT NavigationControllerImpl : public NavigationController {
[email protected]0dd3a0ab2011-02-18 08:17:4438 public:
[email protected]adbfb8df2012-02-24 01:19:4339 NavigationControllerImpl(
[email protected]ec6c05f2013-10-23 18:41:5740 NavigationControllerDelegate* delegate,
[email protected]8ff00d72012-10-23 19:12:2141 BrowserContext* browser_context);
dchengc2282aa2014-10-21 12:07:5842 ~NavigationControllerImpl() override;
[email protected]0dd3a0ab2011-02-18 08:17:4443
[email protected]71fde352011-12-29 03:29:5644 // NavigationController implementation:
Lucas Furukawa Gadani5553a152019-01-08 18:55:5745 WebContents* GetWebContents() override;
46 BrowserContext* GetBrowserContext() override;
dchengc2282aa2014-10-21 12:07:5847 void Restore(int selected_navigation,
48 RestoreType type,
dcheng9bfa5162016-04-09 01:00:5749 std::vector<std::unique_ptr<NavigationEntry>>* entries) override;
Lucas Furukawa Gadani5553a152019-01-08 18:55:5750 NavigationEntryImpl* GetActiveEntry() override;
51 NavigationEntryImpl* GetVisibleEntry() override;
52 int GetCurrentEntryIndex() override;
53 NavigationEntryImpl* GetLastCommittedEntry() override;
54 int GetLastCommittedEntryIndex() override;
55 bool CanViewSource() override;
56 int GetEntryCount() override;
57 NavigationEntryImpl* GetEntryAtIndex(int index) override;
58 NavigationEntryImpl* GetEntryAtOffset(int offset) override;
dchengc2282aa2014-10-21 12:07:5859 void DiscardNonCommittedEntries() override;
Lucas Furukawa Gadani5553a152019-01-08 18:55:5760 NavigationEntryImpl* GetPendingEntry() override;
61 int GetPendingEntryIndex() override;
62 NavigationEntryImpl* GetTransientEntry() override;
dcheng9bfa5162016-04-09 01:00:5763 void SetTransientEntry(std::unique_ptr<NavigationEntry> entry) override;
dchengc2282aa2014-10-21 12:07:5864 void LoadURL(const GURL& url,
65 const Referrer& referrer,
66 ui::PageTransition type,
67 const std::string& extra_headers) override;
68 void LoadURLWithParams(const LoadURLParams& params) override;
69 void LoadIfNecessary() override;
Lucas Furukawa Gadani5553a152019-01-08 18:55:5770 bool CanGoBack() override;
71 bool CanGoForward() override;
72 bool CanGoToOffset(int offset) override;
dchengc2282aa2014-10-21 12:07:5873 void GoBack() override;
74 void GoForward() override;
75 void GoToIndex(int index) override;
76 void GoToOffset(int offset) override;
77 bool RemoveEntryAtIndex(int index) override;
Lucas Furukawa Gadani5553a152019-01-08 18:55:5778 const SessionStorageNamespaceMap& GetSessionStorageNamespaceMap() override;
dchengc2282aa2014-10-21 12:07:5879 SessionStorageNamespace* GetDefaultSessionStorageNamespace() override;
Lucas Furukawa Gadani5553a152019-01-08 18:55:5780 bool NeedsReload() override;
dchengc2282aa2014-10-21 12:07:5881 void SetNeedsReload() override;
82 void CancelPendingReload() override;
83 void ContinuePendingReload() override;
Lucas Furukawa Gadani5553a152019-01-08 18:55:5784 bool IsInitialNavigation() override;
85 bool IsInitialBlankNavigation() override;
toyoshim6142d96f2016-12-19 09:07:2586 void Reload(ReloadType reload_type, bool check_for_repost) override;
Lucas Furukawa Gadani5553a152019-01-08 18:55:5787 void NotifyEntryChanged(NavigationEntry* entry) override;
88 void CopyStateFrom(NavigationController* source, bool needs_reload) override;
dchengc2282aa2014-10-21 12:07:5889 void CopyStateFromAndPrune(NavigationController* source,
90 bool replace_entry) override;
91 bool CanPruneAllButLastCommitted() override;
92 void PruneAllButLastCommitted() override;
Christian Dullweber1af31e62018-02-22 11:49:4893 void DeleteNavigationEntries(
94 const DeletionPredicate& deletionPredicate) override;
Shivani Sharma883f5f32019-02-12 18:20:0195 bool IsEntryMarkedToBeSkipped(int index) override;
Christian Dullweber1af31e62018-02-22 11:49:4896
clamy987a3752018-05-03 17:36:2697 // Starts a navigation in a newly created subframe as part of a history
98 // navigation. Returns true if the history navigation could start, false
99 // otherwise. If this returns false, the caller should do a regular
Charlie Reis4d58b972019-07-15 19:32:40100 // navigation to the default src URL for the frame instead.
clamy987a3752018-05-03 17:36:26101 bool StartHistoryNavigationInNewSubframe(
102 RenderFrameHostImpl* render_frame_host,
Arthur Hemery06173ce2019-05-29 12:11:41103 mojom::NavigationClientAssociatedPtrInfo* navigation_client);
clamy987a3752018-05-03 17:36:26104
Dave Tapuska8bfd84c2019-03-26 20:47:16105 // Navigates to a specified offset from the "current entry". Currently records
106 // a histogram indicating whether the session history navigation would only
107 // affect frames within the subtree of |sandbox_frame_tree_node_id|, which
108 // initiated the navigation.
109 void GoToOffsetInSandboxedFrame(int offset, int sandbox_frame_tree_node_id);
110
clamy987a3752018-05-03 17:36:26111 // Called when a document requests a navigation through a
112 // RenderFrameProxyHost.
113 void NavigateFromFrameProxy(
114 RenderFrameHostImpl* render_frame_host,
115 const GURL& url,
Lukasz Anforowicz63f3b9432019-05-30 05:42:58116 const base::Optional<url::Origin>& initiator_origin,
clamy987a3752018-05-03 17:36:26117 bool is_renderer_initiated,
118 SiteInstance* source_site_instance,
119 const Referrer& referrer,
120 ui::PageTransition page_transition,
121 bool should_replace_current_entry,
Charlie Harrison8c113a32019-01-07 16:08:29122 NavigationDownloadPolicy download_policy,
clamy987a3752018-05-03 17:36:26123 const std::string& method,
124 scoped_refptr<network::ResourceRequestBody> post_body,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:09125 const std::string& extra_headers,
126 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory);
clamy987a3752018-05-03 17:36:26127
[email protected]aa62afd2014-04-22 19:22:46128 // Whether this is the initial navigation in an unmodified new tab. In this
129 // case, we know there is no content displayed in the page.
Lucas Furukawa Gadani5553a152019-01-08 18:55:57130 bool IsUnmodifiedBlankTab();
[email protected]aa62afd2014-04-22 19:22:46131
[email protected]fdac6ade2013-07-20 01:06:30132 // The session storage namespace that all child RenderViews belonging to
133 // |instance| should use.
134 SessionStorageNamespace* GetSessionStorageNamespace(
135 SiteInstance* instance);
136
[email protected]0dd3a0ab2011-02-18 08:17:44137 // Returns the index of the specified entry, or -1 if entry is not contained
138 // in this NavigationController.
[email protected]8ff00d72012-10-23 19:12:21139 int GetIndexOfEntry(const NavigationEntryImpl* entry) const;
[email protected]0dd3a0ab2011-02-18 08:17:44140
avi7c6f35e2015-05-08 17:52:38141 // Return the index of the entry with the given unique id, or -1 if not found.
142 int GetEntryIndexWithUniqueID(int nav_entry_id) const;
143
avi254eff02015-07-01 08:27:58144 // Return the entry with the given unique id, or null if not found.
145 NavigationEntryImpl* GetEntryWithUniqueID(int nav_entry_id) const;
146
[email protected]ec6c05f2013-10-23 18:41:57147 NavigationControllerDelegate* delegate() const {
148 return delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44149 }
150
Alex Moshchuk7b4f0652019-05-30 18:54:41151 // These values are persisted to logs. Entries should not be renumbered and
152 // numeric values should never be reused.
153 enum class NeedsReloadType {
154 kRequestedByClient = 0,
155 kRestoreSession = 1,
156 kCopyStateFrom = 2,
157 kCrashedSubframe = 3,
158 kMaxValue = kCrashedSubframe
159 };
160
161 // Request a reload to happen when activated. Same as the public
162 // SetNeedsReload(), but takes in a |type| which specifies why the reload is
163 // being requested.
164 void SetNeedsReload(NeedsReloadType type);
165
[email protected]b172aee2012-04-10 17:05:26166 // For use by WebContentsImpl ------------------------------------------------
[email protected]0dd3a0ab2011-02-18 08:17:44167
[email protected]59167c22013-06-03 18:07:32168 // Allow renderer-initiated navigations to create a pending entry when the
169 // provisional load starts.
dcheng9bfa5162016-04-09 01:00:57170 void SetPendingEntry(std::unique_ptr<NavigationEntryImpl> entry);
[email protected]59167c22013-06-03 18:07:32171
[email protected]0dd3a0ab2011-02-18 08:17:44172 // Handles updating the navigation state after the renderer has navigated.
[email protected]b172aee2012-04-10 17:05:26173 // This is used by the WebContentsImpl.
[email protected]0dd3a0ab2011-02-18 08:17:44174 //
175 // If a new entry is created, it will return true and will have filled the
176 // given details structure and broadcast the NOTIFY_NAV_ENTRY_COMMITTED
177 // notification. The caller can then use the details without worrying about
178 // listening for the notification.
179 //
180 // In the case that nothing has changed, the details structure is undefined
181 // and it will return false.
shivanisha41f04c52018-12-12 15:52:05182 //
Shivani Sharmaffb32b82019-04-09 16:58:47183 // |previous_document_was_activated| is true if the previous document had user
shivanisha41f04c52018-12-12 15:52:05184 // interaction. This is used for a new renderer-initiated navigation to decide
185 // if the page that initiated the navigation should be skipped on
186 // back/forward button.
[email protected]37567b432014-02-12 01:12:22187 bool RendererDidNavigate(
creis3da03872015-02-20 21:12:32188 RenderFrameHostImpl* rfh,
[email protected]37567b432014-02-12 01:12:22189 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
peary21b0f797b2016-09-28 17:28:33190 LoadCommittedDetails* details,
Eugene But712f03d2018-05-22 16:03:44191 bool is_same_document_navigation,
Shivani Sharmaffb32b82019-04-09 16:58:47192 bool previous_document_was_activated,
Camille Lamy10aafcd32018-12-05 15:48:13193 NavigationRequest* navigation_request);
[email protected]0dd3a0ab2011-02-18 08:17:44194
[email protected]b172aee2012-04-10 17:05:26195 // Notifies us that we just became active. This is used by the WebContentsImpl
[email protected]0dd3a0ab2011-02-18 08:17:44196 // so that we know to load URLs that were pending as "lazy" loads.
197 void SetActive(bool is_active);
198
Eugene But7cc259d2017-10-09 23:52:49199 // Returns true if the given URL would be a same-document navigation (e.g., if
200 // the reference fragment is different, or after a pushState) from the last
creisf164daa2016-06-07 00:17:05201 // committed URL in the specified frame. If there is no last committed entry,
Eugene But7cc259d2017-10-09 23:52:49202 // then nothing will be same-document.
[email protected]0dd3a0ab2011-02-18 08:17:44203 //
[email protected]ce760d742012-08-30 22:31:10204 // Special note: if the URLs are the same, it does NOT automatically count as
Eugene But7cc259d2017-10-09 23:52:49205 // a same-document navigation. Neither does an input URL that has no ref, even
206 // if the rest is the same. This may seem weird, but when we're considering
[email protected]ce760d742012-08-30 22:31:10207 // whether a navigation happened without loading anything, the same URL could
208 // be a reload, while only a different ref would be in-page (pages can't clear
[email protected]0dd3a0ab2011-02-18 08:17:44209 // refs without reload, only change to "#" which we don't count as empty).
[email protected]8d5cb212014-06-04 09:00:39210 //
[email protected]ce760d742012-08-30 22:31:10211 // The situation is made murkier by history.replaceState(), which could
Eugene But7cc259d2017-10-09 23:52:49212 // provide the same URL as part of a same-document navigation, not a reload.
213 // So we need to let the (untrustworthy) renderer resolve the ambiguity, but
creisf164daa2016-06-07 00:17:05214 // only when the URLs are on the same origin. We rely on |origin|, which
215 // matters in cases like about:blank that otherwise look cross-origin.
Eugene But7cc259d2017-10-09 23:52:49216 bool IsURLSameDocumentNavigation(const GURL& url,
217 const url::Origin& origin,
218 bool renderer_says_same_document,
Lucas Furukawa Gadani5553a152019-01-08 18:55:57219 RenderFrameHost* rfh);
[email protected]0dd3a0ab2011-02-18 08:17:44220
[email protected]fdac6ade2013-07-20 01:06:30221 // Sets the SessionStorageNamespace for the given |partition_id|. This is
222 // used during initialization of a new NavigationController to allow
223 // pre-population of the SessionStorageNamespace objects. Session restore,
224 // prerendering, and the implementaion of window.open() are the primary users
225 // of this API.
[email protected]d1198fd2012-08-13 22:50:19226 //
227 // Calling this function when a SessionStorageNamespace has already been
[email protected]fdac6ade2013-07-20 01:06:30228 // associated with a |partition_id| will CHECK() fail.
[email protected]d1198fd2012-08-13 22:50:19229 void SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:30230 const std::string& partition_id,
[email protected]8ff00d72012-10-23 19:12:21231 SessionStorageNamespace* session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:19232
[email protected]0dd3a0ab2011-02-18 08:17:44233 // Random data ---------------------------------------------------------------
234
[email protected]330614de2012-02-13 17:07:18235 SSLManager* ssl_manager() { return &ssl_manager_; }
236
[email protected]0dd3a0ab2011-02-18 08:17:44237 // Maximum number of entries before we start removing entries from the front.
[email protected]f3112a52011-09-30 23:47:49238 static void set_max_entry_count_for_testing(size_t max_entry_count) {
[email protected]9b51970d2011-12-09 23:10:23239 max_entry_count_for_testing_ = max_entry_count;
[email protected]0dd3a0ab2011-02-18 08:17:44240 }
[email protected]9b51970d2011-12-09 23:10:23241 static size_t max_entry_count();
[email protected]0dd3a0ab2011-02-18 08:17:44242
[email protected]c5b88d82012-10-06 17:03:33243 void SetGetTimestampCallbackForTest(
244 const base::Callback<base::Time()>& get_timestamp_callback);
245
avi45a72532015-04-07 21:01:45246 // Discards only the pending entry. |was_failure| should be set if the pending
247 // entry is being discarded because it failed to load.
248 void DiscardPendingEntry(bool was_failure);
[email protected]ec6c05f2013-10-23 18:41:57249
ananta3bdd8ae2016-12-22 17:11:55250 // Sets a flag on the pending NavigationEntryImpl instance if any that the
251 // navigation failed due to an SSL error.
252 void SetPendingNavigationSSLError(bool error);
253
Arthur Sonzogni620cec62018-12-13 13:08:57254 BackForwardCache& back_forward_cache() { return back_forward_cache_; }
255
Camille Lamy5193caa2018-10-12 11:59:42256// Returns true if the string corresponds to a valid data URL, false
257// otherwise.
258#if defined(OS_ANDROID)
259 static bool ValidateDataURLAsString(
260 const scoped_refptr<const base::RefCountedString>& data_url_as_string);
261#endif
262
Shivani Sharma194877032019-03-07 17:52:47263 // Invoked when a user activation occurs within the page, so that relevant
264 // entries can be updated as needed.
265 void NotifyUserActivation();
266
[email protected]0dd3a0ab2011-02-18 08:17:44267 private:
[email protected]0dd3a0ab2011-02-18 08:17:44268 friend class RestoreHelper;
[email protected]0dd3a0ab2011-02-18 08:17:44269
[email protected]c5b88d82012-10-06 17:03:33270 FRIEND_TEST_ALL_PREFIXES(TimeSmoother, Basic);
271 FRIEND_TEST_ALL_PREFIXES(TimeSmoother, SingleDuplicate);
272 FRIEND_TEST_ALL_PREFIXES(TimeSmoother, ManyDuplicates);
273 FRIEND_TEST_ALL_PREFIXES(TimeSmoother, ClockBackwardsJump);
274
[email protected]c5b88d82012-10-06 17:03:33275 // Helper class to smooth out runs of duplicate timestamps while still
276 // allowing time to jump backwards.
[email protected]c5b88d82012-10-06 17:03:33277 class CONTENT_EXPORT TimeSmoother {
278 public:
279 // Returns |t| with possibly some time added on.
280 base::Time GetSmoothedTime(base::Time t);
281
282 private:
283 // |low_water_mark_| is the first time in a sequence of adjusted
284 // times and |high_water_mark_| is the last.
285 base::Time low_water_mark_;
286 base::Time high_water_mark_;
287 };
288
Dave Tapuska8bfd84c2019-03-26 20:47:16289 // Navigates in session history to the given index. If
290 // |sandbox_frame_tree_node_id| is valid, then this request came
291 // from a sandboxed iframe with top level navigation disallowed. This
292 // is currently only used for tracking metrics.
293 void GoToIndex(int index, int sandbox_frame_tree_node_id);
294
clamy3cb9bea92018-07-10 12:42:02295 // Starts a navigation to an already existing pending NavigationEntry.
Dave Tapuska8bfd84c2019-03-26 20:47:16296 // Currently records a histogram indicating whether the session history
297 // navigation would only affect frames within the subtree of
298 // |sandbox_frame_tree_node_id|, which initiated the navigation.
299 void NavigateToExistingPendingEntry(ReloadType reload_type,
300 int sandboxed_source_frame_tree_node_id);
creis4e2ecb72015-06-20 00:46:30301
clamy3cb9bea92018-07-10 12:42:02302 // Recursively identifies which frames need to be navigated for a navigation
303 // to |pending_entry_|, starting at |frame| and exploring its children.
304 // |same_document_loads| and |different_document_loads| will be filled with
305 // the NavigationRequests needed to navigate to |pending_entry_|.
306 void FindFramesToNavigate(
307 FrameTreeNode* frame,
308 ReloadType reload_type,
309 std::vector<std::unique_ptr<NavigationRequest>>* same_document_loads,
310 std::vector<std::unique_ptr<NavigationRequest>>*
311 different_document_loads);
creis4e2ecb72015-06-20 00:46:30312
clamy21718cc22018-06-13 13:34:24313 // Starts a new navigation based on |load_params|, that doesn't correspond to
314 // an exisiting NavigationEntry.
315 void NavigateWithoutEntry(const LoadURLParams& load_params);
316
clamyea99ea12018-05-28 13:54:23317 // Handles a navigation to a renderer-debug URL.
318 void HandleRendererDebugURL(FrameTreeNode* frame_tree_node, const GURL& url);
319
clamy21718cc22018-06-13 13:34:24320 // Creates and returns a NavigationEntry based on |load_params| for a
321 // navigation in |node|.
Camille Lamy5193caa2018-10-12 11:59:42322 // |override_user_agent|, |should_replace_current_entry| and
323 // |has_user_gesture| will override the values from |load_params|. The same
324 // values should be passed to CreateNavigationRequestFromLoadParams.
clamy21718cc22018-06-13 13:34:24325 std::unique_ptr<NavigationEntryImpl> CreateNavigationEntryFromLoadParams(
326 FrameTreeNode* node,
Camille Lamy5193caa2018-10-12 11:59:42327 const LoadURLParams& load_params,
328 bool override_user_agent,
329 bool should_replace_current_entry,
330 bool has_user_gesture);
clamy21718cc22018-06-13 13:34:24331
Camille Lamy5193caa2018-10-12 11:59:42332 // Creates and returns a NavigationRequest based on |load_params| for a
333 // new navigation in |node|.
clamyea99ea12018-05-28 13:54:23334 // Will return nullptr if the parameters are invalid and the navigation cannot
335 // start.
Camille Lamy5193caa2018-10-12 11:59:42336 // |override_user_agent|, |should_replace_current_entry| and
337 // |has_user_gesture| will override the values from |load_params|. The same
338 // values should be passed to CreateNavigationEntryFromLoadParams.
339 // TODO(clamy): Remove the dependency on NavigationEntry and
340 // FrameNavigationEntry.
341 std::unique_ptr<NavigationRequest> CreateNavigationRequestFromLoadParams(
342 FrameTreeNode* node,
343 const LoadURLParams& load_params,
344 bool override_user_agent,
345 bool should_replace_current_entry,
346 bool has_user_gesture,
Charlie Harrison8c113a32019-01-07 16:08:29347 NavigationDownloadPolicy download_policy,
Camille Lamy5193caa2018-10-12 11:59:42348 ReloadType reload_type,
Lucas Furukawa Gadani5553a152019-01-08 18:55:57349 NavigationEntryImpl* entry,
Camille Lamy5193caa2018-10-12 11:59:42350 FrameNavigationEntry* frame_entry);
351
352 // Creates and returns a NavigationRequest for a navigation to |entry|. Will
353 // return nullptr if the parameters are invalid and the navigation cannot
354 // start.
355 // TODO(clamy): Ensure this is only called for navigations to existing
356 // NavigationEntries.
357 std::unique_ptr<NavigationRequest> CreateNavigationRequestFromEntry(
clamyea99ea12018-05-28 13:54:23358 FrameTreeNode* frame_tree_node,
Lucas Furukawa Gadani5553a152019-01-08 18:55:57359 NavigationEntryImpl* entry,
clamyea99ea12018-05-28 13:54:23360 FrameNavigationEntry* frame_entry,
361 ReloadType reload_type,
362 bool is_same_document_history_load,
Arthur Hemerybee4a752019-05-29 10:50:55363 bool is_history_navigation_in_new_child_frame);
clamyea99ea12018-05-28 13:54:23364
creisb4dc9332016-03-14 21:39:19365 // Returns whether there is a pending NavigationEntry whose unique ID matches
366 // the given NavigationHandle's pending_nav_entry_id.
367 bool PendingEntryMatchesHandle(NavigationHandleImpl* handle) const;
368
[email protected]0dd3a0ab2011-02-18 08:17:44369 // Classifies the given renderer navigation (see the NavigationType enum).
[email protected]8ff00d72012-10-23 19:12:21370 NavigationType ClassifyNavigation(
creis3da03872015-02-20 21:12:32371 RenderFrameHostImpl* rfh,
Lucas Furukawa Gadani5553a152019-01-08 18:55:57372 const FrameHostMsg_DidCommitProvisionalLoad_Params& params);
[email protected]0dd3a0ab2011-02-18 08:17:44373
[email protected]0dd3a0ab2011-02-18 08:17:44374 // Handlers for the different types of navigation types. They will actually
375 // handle the navigations corresponding to the different NavClasses above.
376 // They will NOT broadcast the commit notification, that should be handled by
377 // the caller.
378 //
379 // RendererDidNavigateAutoSubframe is special, it may not actually change
380 // anything if some random subframe is loaded. It will return true if anything
381 // changed, or false if not.
382 //
creis1857908a2016-02-25 20:31:52383 // The NewPage and NewSubframe functions take in |replace_entry| to pass to
384 // InsertOrReplaceEntry, in case the newly created NavigationEntry is meant to
385 // replace the current one (e.g., for location.replace or successful loads
386 // after net errors), in contrast to updating a NavigationEntry in place
387 // (e.g., for history.replaceState).
[email protected]0dd3a0ab2011-02-18 08:17:44388 void RendererDidNavigateToNewPage(
creis3da03872015-02-20 21:12:32389 RenderFrameHostImpl* rfh,
[email protected]37567b432014-02-12 01:12:22390 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
eugenebut604866f2017-05-10 21:35:36391 bool is_same_document,
clamy3bf35e3c2016-11-10 15:59:44392 bool replace_entry,
Shivani Sharmaffb32b82019-04-09 16:58:47393 bool previous_document_was_activated,
clamy3bf35e3c2016-11-10 15:59:44394 NavigationHandleImpl* handle);
[email protected]0dd3a0ab2011-02-18 08:17:44395 void RendererDidNavigateToExistingPage(
creis3da03872015-02-20 21:12:32396 RenderFrameHostImpl* rfh,
jam0576b132016-09-07 05:13:10397 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
eugenebut604866f2017-05-10 21:35:36398 bool is_same_document,
jam48cea9082017-02-15 06:13:29399 bool was_restored,
Peter Boströmd7592132019-01-30 04:50:31400 NavigationHandleImpl* handle,
401 bool keep_pending_entry);
[email protected]0dd3a0ab2011-02-18 08:17:44402 void RendererDidNavigateToSamePage(
creis3da03872015-02-20 21:12:32403 RenderFrameHostImpl* rfh,
clamy3bf35e3c2016-11-10 15:59:44404 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
Joe DeBlasio531e3d92018-11-06 06:26:12405 bool is_same_document,
clamy3bf35e3c2016-11-10 15:59:44406 NavigationHandleImpl* handle);
[email protected]0dd3a0ab2011-02-18 08:17:44407 void RendererDidNavigateNewSubframe(
creis3da03872015-02-20 21:12:32408 RenderFrameHostImpl* rfh,
creis1857908a2016-02-25 20:31:52409 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
eugenebut604866f2017-05-10 21:35:36410 bool is_same_document,
Shivani Sharmaffb32b82019-04-09 16:58:47411 bool replace_entry,
412 bool previous_document_was_activated,
413 NavigationHandleImpl* handle);
[email protected]0dd3a0ab2011-02-18 08:17:44414 bool RendererDidNavigateAutoSubframe(
creis3da03872015-02-20 21:12:32415 RenderFrameHostImpl* rfh,
Lukasz Anforowicz435bcb582019-07-12 20:50:06416 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
417 NavigationHandleImpl* handle);
[email protected]0dd3a0ab2011-02-18 08:17:44418
[email protected]0dd3a0ab2011-02-18 08:17:44419 // Allows the derived class to issue notifications that a load has been
420 // committed. This will fill in the active entry to the details structure.
[email protected]8ff00d72012-10-23 19:12:21421 void NotifyNavigationEntryCommitted(LoadCommittedDetails* details);
[email protected]0dd3a0ab2011-02-18 08:17:44422
423 // Updates the virtual URL of an entry to match a new URL, for cases where
424 // the real renderer URL is derived from the virtual URL, like view-source:
[email protected]8ff00d72012-10-23 19:12:21425 void UpdateVirtualURLToURL(NavigationEntryImpl* entry,
[email protected]10f417c52011-12-28 21:04:23426 const GURL& new_url);
[email protected]0dd3a0ab2011-02-18 08:17:44427
428 // Invoked after session/tab restore or cloning a tab. Resets the transition
429 // type of the entries, updates the max page id and creates the active
[email protected]2ca1ea662012-10-04 02:26:36430 // contents.
431 void FinishRestore(int selected_index, RestoreType type);
[email protected]0dd3a0ab2011-02-18 08:17:44432
433 // Inserts a new entry or replaces the current entry with a new one, removing
434 // all entries after it. The new entry will become the active one.
dcheng9bfa5162016-04-09 01:00:57435 void InsertOrReplaceEntry(std::unique_ptr<NavigationEntryImpl> entry,
avi25764702015-06-23 15:43:37436 bool replace);
[email protected]0dd3a0ab2011-02-18 08:17:44437
[email protected]6a13a6c2011-12-20 21:47:12438 // Removes the entry at |index|, as long as it is not the current entry.
[email protected]43032342011-03-21 14:10:31439 void RemoveEntryAtIndexInternal(int index);
440
[email protected]b12eb222013-09-10 00:11:48441 // Discards both the pending and transient entries.
[email protected]0dd3a0ab2011-02-18 08:17:44442 void DiscardNonCommittedEntriesInternal();
443
[email protected]b12eb222013-09-10 00:11:48444 // Discards only the transient entry.
[email protected]0dd3a0ab2011-02-18 08:17:44445 void DiscardTransientEntry();
446
Shivani Sharmad8c8d652019-02-13 17:27:57447 // If we have the maximum number of entries, remove the oldest entry that is
448 // marked to be skipped on back/forward button, in preparation to add another.
449 // If no entry is skippable, then the oldest entry will be pruned.
450 void PruneOldestSkippableEntryIfFull();
[email protected]944822b2012-03-02 20:57:25451
[email protected]474f8512013-05-31 22:31:16452 // Removes all entries except the last committed entry. If there is a new
[email protected]79368982013-11-13 01:11:01453 // pending navigation it is preserved. In contrast to
454 // PruneAllButLastCommitted() this does not update the session history of the
455 // RenderView. Callers must ensure that |CanPruneAllButLastCommitted| returns
456 // true before calling this.
457 void PruneAllButLastCommittedInternal();
[email protected]9350602e2013-02-26 23:27:44458
[email protected]0dd3a0ab2011-02-18 08:17:44459 // Inserts up to |max_index| entries from |source| into this. This does NOT
460 // adjust any of the members that reference entries_
461 // (last_committed_entry_index_, pending_entry_index_ or
462 // transient_entry_index_).
Lucas Furukawa Gadani5553a152019-01-08 18:55:57463 void InsertEntriesFrom(NavigationControllerImpl* source, int max_index);
[email protected]0dd3a0ab2011-02-18 08:17:44464
[email protected]9ba14052012-06-22 23:50:03465 // Returns the navigation index that differs from the current entry by the
466 // specified |offset|. The index returned is not guaranteed to be valid.
Lucas Furukawa Gadani5553a152019-01-08 18:55:57467 int GetIndexForOffset(int offset);
[email protected]9ba14052012-06-22 23:50:03468
Arthur Sonzogni620cec62018-12-13 13:08:57469 // BackForwardCache:
470 // Notify observers a document was restored from the bfcache.
471 // This updates the URL bar and the history buttons.
472 void CommitRestoreFromBackForwardCache();
473
Shivani Sharmaffb32b82019-04-09 16:58:47474 // History Manipulation intervention:
475 // The previous document that started this navigation needs to be skipped in
476 // subsequent back/forward UI navigations if it never received any user
477 // gesture. This is to intervene against pages that manipulate the history
478 // such that the user is not able to go back to the last site they interacted
479 // with (crbug.com/907167).
480 // Note that this function must be called before the new navigation entry is
481 // inserted in |entries_| to make sure UKM reports the URL of the document
482 // adding the entry.
483 void SetShouldSkipOnBackForwardUIIfNeeded(
484 RenderFrameHostImpl* rfh,
485 bool replace_entry,
486 bool previous_document_was_activated,
487 bool is_renderer_initiated);
488
Shivani Sharmac4cc8922019-04-18 03:11:17489 // This function sets all same document entries with the same value
490 // of skippable flag. This is to avoid back button abuse by inserting
491 // multiple history entries and also to help valid cases where a user gesture
492 // on the document should apply to all same document history entries and none
493 // should be skipped. All entries belonging to the same document as the entry
494 // at |reference_index| will get their skippable flag set to |skippable|.
495 void SetSkippableForSameDocumentEntries(int reference_index, bool skippable);
496
[email protected]0dd3a0ab2011-02-18 08:17:44497 // ---------------------------------------------------------------------------
498
[email protected]3d7474ff2011-07-27 17:47:37499 // The user browser context associated with this controller.
[email protected]8ff00d72012-10-23 19:12:21500 BrowserContext* browser_context_;
[email protected]0dd3a0ab2011-02-18 08:17:44501
avif16f85a72015-11-13 18:25:03502 // List of |NavigationEntry|s for this controller.
dcheng9bfa5162016-04-09 01:00:57503 std::vector<std::unique_ptr<NavigationEntryImpl>> entries_;
[email protected]0dd3a0ab2011-02-18 08:17:44504
505 // An entry we haven't gotten a response for yet. This will be discarded
506 // when we navigate again. It's used only so we know what the currently
507 // displayed tab is.
508 //
509 // This may refer to an item in the entries_ list if the pending_entry_index_
arthursonzogni02084c72017-05-03 22:52:39510 // != -1, or it may be its own entry that should be deleted. Be careful with
[email protected]0dd3a0ab2011-02-18 08:17:44511 // the memory management.
[email protected]8ff00d72012-10-23 19:12:21512 NavigationEntryImpl* pending_entry_;
[email protected]0dd3a0ab2011-02-18 08:17:44513
avi45a72532015-04-07 21:01:45514 // If a new entry fails loading, details about it are temporarily held here
creis865ad442016-03-15 16:43:09515 // until the error page is shown (or 0 otherwise).
avi45a72532015-04-07 21:01:45516 //
517 // TODO(avi): We need a better way to handle the connection between failed
518 // loads and the subsequent load of the error page. This current approach has
519 // issues: 1. This might hang around longer than we'd like if there is no
520 // error page loaded, and 2. This doesn't work very well for frames.
521 // http://crbug.com/474261
522 int failed_pending_entry_id_;
avi45a72532015-04-07 21:01:45523
524 // The index of the currently visible entry.
[email protected]0dd3a0ab2011-02-18 08:17:44525 int last_committed_entry_index_;
526
avi45a72532015-04-07 21:01:45527 // The index of the pending entry if it is in entries_, or -1 if
528 // pending_entry_ is a new entry (created by LoadURL).
[email protected]0dd3a0ab2011-02-18 08:17:44529 int pending_entry_index_;
530
531 // The index for the entry that is shown until a navigation occurs. This is
532 // used for interstitial pages. -1 if there are no such entry.
533 // Note that this entry really appears in the list of entries, but only
534 // temporarily (until the next navigation). Any index pointing to an entry
535 // after the transient entry will become invalid if you navigate forward.
536 int transient_entry_index_;
537
[email protected]ec6c05f2013-10-23 18:41:57538 // The delegate associated with the controller. Possibly NULL during
[email protected]0dd3a0ab2011-02-18 08:17:44539 // setup.
[email protected]ec6c05f2013-10-23 18:41:57540 NavigationControllerDelegate* delegate_;
[email protected]0dd3a0ab2011-02-18 08:17:44541
[email protected]b0f724c2013-09-05 04:21:13542 // Manages the SSL security UI.
[email protected]0dd3a0ab2011-02-18 08:17:44543 SSLManager ssl_manager_;
544
545 // Whether we need to be reloaded when made active.
546 bool needs_reload_;
547
Bo Liucdfa4b12018-11-06 00:21:44548 // Source of when |needs_reload_| is set. Only valid when |needs_reload_|
549 // is set.
550 NeedsReloadType needs_reload_type_ = NeedsReloadType::kRequestedByClient;
551
[email protected]27ba81c2012-08-21 17:04:09552 // Whether this is the initial navigation.
[email protected]cd2e15742013-03-08 04:08:31553 // Becomes false when initial navigation commits.
[email protected]27ba81c2012-08-21 17:04:09554 bool is_initial_navigation_;
[email protected]0dd3a0ab2011-02-18 08:17:44555
[email protected]40fd3032014-02-28 22:16:28556 // Prevent unsafe re-entrant calls to NavigateToPendingEntry.
557 bool in_navigate_to_pending_entry_;
558
[email protected]fdac6ade2013-07-20 01:06:30559 // Used to find the appropriate SessionStorageNamespace for the storage
560 // partition of a NavigationEntry.
561 //
562 // A NavigationController may contain NavigationEntries that correspond to
563 // different StoragePartitions. Even though they are part of the same
564 // NavigationController, only entries in the same StoragePartition may
565 // share session storage state with one another.
566 SessionStorageNamespaceMap session_storage_namespace_map_;
[email protected]0dd3a0ab2011-02-18 08:17:44567
[email protected]0dd3a0ab2011-02-18 08:17:44568 // The maximum number of entries that a navigation controller can store.
[email protected]9b51970d2011-12-09 23:10:23569 static size_t max_entry_count_for_testing_;
[email protected]0dd3a0ab2011-02-18 08:17:44570
toyoshim7dad4b1182016-04-01 14:28:05571 // If a repost is pending, its type (RELOAD or RELOAD_BYPASSING_CACHE),
[email protected]0dd3a0ab2011-02-18 08:17:44572 // NO_RELOAD otherwise.
573 ReloadType pending_reload_;
574
[email protected]c5b88d82012-10-06 17:03:33575 // Used to get timestamps for newly-created navigation entries.
576 base::Callback<base::Time()> get_timestamp_callback_;
577
578 // Used to smooth out timestamps from |get_timestamp_callback_|.
579 // Without this, whenever there is a run of redirects or
580 // code-generated navigations, those navigations may occur within
581 // the timer resolution, leading to things sometimes showing up in
582 // the wrong order in the history view.
583 TimeSmoother time_smoother_;
584
Arthur Sonzogni620cec62018-12-13 13:08:57585 // BackForwardCache:
586 //
587 // Stores frozen RenderFrameHost. Restores them on history navigation.
588 // See BackForwardCache class documentation.
589 BackForwardCache back_forward_cache_;
590
[email protected]d202a7c2012-01-04 07:53:47591 DISALLOW_COPY_AND_ASSIGN(NavigationControllerImpl);
[email protected]0dd3a0ab2011-02-18 08:17:44592};
593
[email protected]8ff00d72012-10-23 19:12:21594} // namespace content
595
[email protected]d4a8ca482013-10-30 21:06:40596#endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_CONTROLLER_IMPL_H_