blob: b5dbbba62f17cd80c818f7d417352cd59b4e1d2c [file] [log] [blame]
// Copyright 2013 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 CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_
#define CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "content/browser/frame_host/navigation_controller_impl.h"
#include "content/browser/frame_host/navigator.h"
#include "content/common/content_export.h"
#include "content/common/navigation_params.h"
#include "content/common/navigation_params.mojom.h"
#include "content/public/common/previews_state.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "url/gurl.h"
class GURL;
namespace content {
class NavigationControllerImpl;
class NavigatorDelegate;
struct LoadCommittedDetails;
// This class is an implementation of Navigator, responsible for managing
// navigations in regular browser tabs.
class CONTENT_EXPORT NavigatorImpl : public Navigator {
public:
NavigatorImpl(NavigationControllerImpl* navigation_controller,
NavigatorDelegate* delegate);
// This method verifies that a navigation to |url| doesn't commit into a WebUI
// process if it is not allowed to. Callers of this method should take one of
// two actions if the method returns false:
// * When called from browser process logic (e.g. NavigationRequest), this
// indicates issues with the navigation logic and the browser process must
// be terminated to avoid security issues.
// * If the codepath is processing an IPC message from a renderer process,
// then the renderer process is misbehaving and must be terminated.
// TODO(nasko): Remove the is_renderer_initiated_check parameter when callers
// of this method are migrated to use CHECK instead of DumpWithoutCrashing.
static WARN_UNUSED_RESULT bool CheckWebUIRendererDoesNotDisplayNormalURL(
RenderFrameHostImpl* render_frame_host,
const GURL& url,
bool is_renderer_initiated_check);
static bool ShouldIgnoreIncomingRendererRequest(
const NavigationRequest* ongoing_navigation_request,
bool has_user_gesture);
// Navigator implementation.
NavigatorDelegate* GetDelegate() override;
NavigationController* GetController() override;
void DidFailLoadWithError(RenderFrameHostImpl* render_frame_host,
const GURL& url,
int error_code) override;
void DidNavigate(RenderFrameHostImpl* render_frame_host,
const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
std::unique_ptr<NavigationRequest> navigation_request,
bool was_within_same_document) override;
bool StartHistoryNavigationInNewSubframe(
RenderFrameHostImpl* render_frame_host,
mojo::PendingAssociatedRemote<mojom::NavigationClient>* navigation_client)
override;
void Navigate(std::unique_ptr<NavigationRequest> request,
ReloadType reload_type,
RestoreType restore_type) override;
void RequestOpenURL(
RenderFrameHostImpl* render_frame_host,
const GURL& url,
const GlobalFrameRoutingId& initiator_routing_id,
const base::Optional<url::Origin>& initiator_origin,
const scoped_refptr<network::ResourceRequestBody>& post_body,
const std::string& extra_headers,
const Referrer& referrer,
WindowOpenDisposition disposition,
bool should_replace_current_entry,
bool user_gesture,
blink::TriggeringEventInfo triggering_event_info,
const std::string& href_translate,
scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
const base::Optional<Impression>& impression) override;
void NavigateFromFrameProxy(
RenderFrameHostImpl* render_frame_host,
const GURL& url,
const GlobalFrameRoutingId& initiator_routing_id,
const url::Origin& initiator_origin,
SiteInstance* source_site_instance,
const Referrer& referrer,
ui::PageTransition page_transition,
bool should_replace_current_entry,
NavigationDownloadPolicy download_policy,
const std::string& method,
scoped_refptr<network::ResourceRequestBody> post_body,
const std::string& extra_headers,
scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
bool has_user_gesture,
const base::Optional<Impression>& impression) override;
void BeforeUnloadCompleted(FrameTreeNode* frame_tree_node,
bool proceed,
const base::TimeTicks& proceed_time) override;
void OnBeginNavigation(
FrameTreeNode* frame_tree_node,
mojom::CommonNavigationParamsPtr common_params,
mojom::BeginNavigationParamsPtr begin_params,
scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client,
mojo::PendingRemote<blink::mojom::NavigationInitiator>
navigation_initiator,
scoped_refptr<PrefetchedSignedExchangeCache>
prefetched_signed_exchange_cache,
std::unique_ptr<WebBundleHandleTracker> web_bundle_handle_tracker)
override;
void RestartNavigationAsCrossDocument(
std::unique_ptr<NavigationRequest> navigation_request) override;
void LogResourceRequestTime(base::TimeTicks timestamp,
const GURL& url) override;
void LogBeforeUnloadTime(
const base::TimeTicks& renderer_before_unload_start_time,
const base::TimeTicks& renderer_before_unload_end_time) override;
void CancelNavigation(FrameTreeNode* frame_tree_node) override;
private:
// Holds data used to track browser side navigation metrics.
struct NavigationMetricsData;
friend class NavigatorTestWithBrowserSideNavigation;
~NavigatorImpl() override;
void RecordNavigationMetrics(
const LoadCommittedDetails& details,
const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
SiteInstance* site_instance);
// Called when a renderer initiated navigation has started. Returns the
// pending NavigationEntry to be used. Either null or a new one owned
// NavigationController.
NavigationEntryImpl* GetNavigationEntryForRendererInitiatedNavigation(
const mojom::CommonNavigationParams& common_params,
FrameTreeNode* frame_tree_node);
// The NavigationController that will keep track of session history for all
// RenderFrameHost objects using this NavigatorImpl.
// TODO(nasko): Move ownership of the NavigationController from
// WebContentsImpl to this class.
NavigationControllerImpl* controller_;
// Used to notify the object embedding this Navigator about navigation
// events. Can be NULL in tests.
NavigatorDelegate* delegate_;
std::unique_ptr<NavigatorImpl::NavigationMetricsData> navigation_data_;
DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
};
} // namespace content
#endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_