Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2 | // 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-doray | fc7952f0 | 2025-06-06 00:04:33 | [diff] [blame] | 10 | #include "content/public/browser/render_process_host.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 11 | #include "services/network/public/cpp/shared_url_loader_factory.h" |
| 12 | #include "third_party/blink/public/mojom/frame/frame.mojom.h" |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 13 | #include "third_party/blink/public/mojom/navigation/navigation_params.mojom-forward.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 14 | #include "url/gurl.h" |
| 15 | |
| 16 | namespace content { |
| 17 | |
Yao Xiao | 1ac702d | 2022-06-08 17:20:49 | [diff] [blame] | 18 | class RenderFrameHostImpl; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 19 | |
Sharon Yang | 1987cec | 2023-03-24 23:40:19 | [diff] [blame] | 20 | // Verifies that |params| are valid and can be accessed by |process|. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 21 | // |
| 22 | // If the |params| are valid, returns true. |
| 23 | // |
Sharon Yang | 1987cec | 2023-03-24 23:40:19 | [diff] [blame] | 24 | // Otherwise, terminates |process| and returns false. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 25 | // |
| 26 | // This function has to be called on the UI thread. |
Sharon Yang | 1987cec | 2023-03-24 23:40:19 | [diff] [blame] | 27 | bool VerifyDownloadUrlParams(RenderProcessHost* process, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 28 | const blink::mojom::DownloadURLParams& params); |
| 29 | |
Sharon Yang | 59197b2a | 2023-03-24 17:49:24 | [diff] [blame] | 30 | // Verifies that |params| are valid and can be accessed by |process|. |
| 31 | // |current_rfh| represents the current frame on which OpenURL is being called |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 32 | // |
| 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 Yang | 59197b2a | 2023-03-24 17:49:24 | [diff] [blame] | 36 | // Terminates |process| and returns false if the |params| are invalid. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 37 | // |
| 38 | // This function has to be called on the UI thread. |
Yao Xiao | 1ac702d | 2022-06-08 17:20:49 | [diff] [blame] | 39 | bool VerifyOpenURLParams(RenderFrameHostImpl* current_rfh, |
Sharon Yang | 59197b2a | 2023-03-24 17:49:24 | [diff] [blame] | 40 | RenderProcessHost* process, |
Yeunjoo Choi | 9232ea3 | 2021-03-08 16:25:17 | [diff] [blame] | 41 | const blink::mojom::OpenURLParamsPtr& params, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 42 | GURL* out_validated_url, |
| 43 | scoped_refptr<network::SharedURLLoaderFactory>* |
| 44 | out_blob_url_loader_factory); |
| 45 | |
Sharon Yang | 1987cec | 2023-03-24 23:40:19 | [diff] [blame] | 46 | // Verifies that CommonNavigationParams are valid and can be accessed by |
| 47 | // |current_rfh|'s process. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 48 | // |
| 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 Yang | 1987cec | 2023-03-24 23:40:19 | [diff] [blame] | 53 | // Terminates |current_rfh|'s process and returns false if the |
| 54 | // CommonNavigationParams are invalid. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 55 | // |
| 56 | // This function has to be called on the UI thread. |
| 57 | bool VerifyBeginNavigationCommonParams( |
Chris Fredrickson | 73ba749 | 2023-02-21 17:08:06 | [diff] [blame] | 58 | const RenderFrameHostImpl& current_rfh, |
Rakina Zata Amni | 6013105 | 2023-09-05 22:33:54 | [diff] [blame] | 59 | blink::mojom::CommonNavigationParams* common_params, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 60 | std::optional<blink::LocalFrameToken>& initiator_frame_token); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 61 | |
Yao Xiao | 1ac702d | 2022-06-08 17:20:49 | [diff] [blame] | 62 | // 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. |
| 73 | bool VerifyNavigationInitiator( |
| 74 | RenderFrameHostImpl* current_rfh, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 75 | const std::optional<blink::LocalFrameToken>& initiator_frame_token, |
Yao Xiao | 1ac702d | 2022-06-08 17:20:49 | [diff] [blame] | 76 | int initiator_process_id); |
| 77 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 78 | } // namespace content |
| 79 | |
| 80 | #endif // CONTENT_BROWSER_RENDERER_HOST_IPC_UTILS_H_ |