blob: e5591c95413a4eaaa322a6390936e4abbdbcd034 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2019 The Chromium Authors
danakjc492bf82020-09-09 20:02:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_IPC_UTILS_H_
6#define CONTENT_BROWSER_RENDERER_HOST_IPC_UTILS_H_
7
8#include "base/memory/ref_counted.h"
9#include "content/common/frame.mojom.h"
Etienne Pierre-dorayfc7952f02025-06-06 00:04:3310#include "content/public/browser/render_process_host.h"
danakjc492bf82020-09-09 20:02:4411#include "services/network/public/cpp/shared_url_loader_factory.h"
12#include "third_party/blink/public/mojom/frame/frame.mojom.h"
Minggang Wangb9f3fa92021-07-01 15:30:3113#include "third_party/blink/public/mojom/navigation/navigation_params.mojom-forward.h"
danakjc492bf82020-09-09 20:02:4414#include "url/gurl.h"
15
16namespace content {
17
Yao Xiao1ac702d2022-06-08 17:20:4918class RenderFrameHostImpl;
danakjc492bf82020-09-09 20:02:4419
Sharon Yang1987cec2023-03-24 23:40:1920// Verifies that |params| are valid and can be accessed by |process|.
danakjc492bf82020-09-09 20:02:4421//
22// If the |params| are valid, returns true.
23//
Sharon Yang1987cec2023-03-24 23:40:1924// Otherwise, terminates |process| and returns false.
danakjc492bf82020-09-09 20:02:4425//
26// This function has to be called on the UI thread.
Sharon Yang1987cec2023-03-24 23:40:1927bool VerifyDownloadUrlParams(RenderProcessHost* process,
danakjc492bf82020-09-09 20:02:4428 const blink::mojom::DownloadURLParams& params);
29
Sharon Yang59197b2a2023-03-24 17:49:2430// Verifies that |params| are valid and can be accessed by |process|.
31// |current_rfh| represents the current frame on which OpenURL is being called
danakjc492bf82020-09-09 20:02:4432//
33// Returns true if the |params| are valid. As a side-effect of the verification
34// |out_validated_url| and |out_blob_url_loader_factory| will be populated.
35//
Sharon Yang59197b2a2023-03-24 17:49:2436// Terminates |process| and returns false if the |params| are invalid.
danakjc492bf82020-09-09 20:02:4437//
38// This function has to be called on the UI thread.
Yao Xiao1ac702d2022-06-08 17:20:4939bool VerifyOpenURLParams(RenderFrameHostImpl* current_rfh,
Sharon Yang59197b2a2023-03-24 17:49:2440 RenderProcessHost* process,
Yeunjoo Choi9232ea32021-03-08 16:25:1741 const blink::mojom::OpenURLParamsPtr& params,
danakjc492bf82020-09-09 20:02:4442 GURL* out_validated_url,
43 scoped_refptr<network::SharedURLLoaderFactory>*
44 out_blob_url_loader_factory);
45
Sharon Yang1987cec2023-03-24 23:40:1946// Verifies that CommonNavigationParams are valid and can be accessed by
47// |current_rfh|'s process.
danakjc492bf82020-09-09 20:02:4448//
49// Returns true if the CommonNavigationParams are valid. As a side-effect of
50// the verification parts of |common_params| will be rewritten (e.g. some
51// URLs will be filtered).
52//
Sharon Yang1987cec2023-03-24 23:40:1953// Terminates |current_rfh|'s process and returns false if the
54// CommonNavigationParams are invalid.
danakjc492bf82020-09-09 20:02:4455//
56// This function has to be called on the UI thread.
57bool VerifyBeginNavigationCommonParams(
Chris Fredrickson73ba7492023-02-21 17:08:0658 const RenderFrameHostImpl& current_rfh,
Rakina Zata Amni60131052023-09-05 22:33:5459 blink::mojom::CommonNavigationParams* common_params,
Arthur Sonzognic686e8f2024-01-11 08:36:3760 std::optional<blink::LocalFrameToken>& initiator_frame_token);
danakjc492bf82020-09-09 20:02:4461
Yao Xiao1ac702d2022-06-08 17:20:4962// Verify that the initiator frame identified by `initiator_frame_token` and
63// `initiator_process_id` can navigate `current_rfh`.
64//
65// This is best effort: the frame with the corresponding frame token may have
66// been deleted before the navigation begins.
67//
68// Returns true if the navigation is valid, or if the an initiator frame is not
69// found. Terminates the renderer the process associated with
70// |initiator_process_id| and returns false if the navigation is not allowed.
71//
72// This function has to be called on the UI thread.
73bool VerifyNavigationInitiator(
74 RenderFrameHostImpl* current_rfh,
Arthur Sonzognic686e8f2024-01-11 08:36:3775 const std::optional<blink::LocalFrameToken>& initiator_frame_token,
Yao Xiao1ac702d2022-06-08 17:20:4976 int initiator_process_id);
77
danakjc492bf82020-09-09 20:02:4478} // namespace content
79
80#endif // CONTENT_BROWSER_RENDERER_HOST_IPC_UTILS_H_