Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [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_PUBLIC_BROWSER_PAGE_H_ |
| 6 | #define CONTENT_PUBLIC_BROWSER_PAGE_H_ |
| 7 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 8 | #include <optional> |
| 9 | |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 10 | #include "base/functional/callback.h" |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 11 | #include "base/supports_user_data.h" |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 12 | #include "content/common/content_export.h" |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 13 | #include "content/public/browser/render_frame_host.h" |
Alan Cutter | e511d18a | 2021-08-04 23:10:38 | [diff] [blame] | 14 | #include "third_party/blink/public/mojom/manifest/manifest.mojom-forward.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 15 | #include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h" |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 16 | #include "url/gurl.h" |
| 17 | |
Rakina Zata Amni | 65a5dc4 | 2025-03-03 02:51:55 | [diff] [blame] | 18 | #if BUILDFLAG(IS_ANDROID) |
| 19 | #include "base/android/scoped_java_ref.h" |
| 20 | #endif |
| 21 | |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 22 | namespace content { |
| 23 | |
| 24 | // Page represents a collection of documents with the same main document. |
| 25 | |
| 26 | // At the moment some navigations might create a new blink::Document in the |
| 27 | // existing RenderFrameHost, which will lead to a creation of a new Page |
| 28 | // associated with the same main RenderFrameHost. See the comment in |
Sreeja Kamishetty | 0a0961f | 2021-10-11 16:23:53 | [diff] [blame] | 29 | // |DocumentUserData| for more details and crbug.com/936696 for the |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 30 | // progress on always creating a new RenderFrameHost for each new document. |
| 31 | |
| 32 | // Page is created when a main document is created, which can happen in the |
| 33 | // following ways: |
| 34 | // 1) Main RenderFrameHost is created. |
| 35 | // 2) A cross-document non-bfcached navigation is committed in the same |
| 36 | // RenderFrameHost. |
| 37 | // 3) Main RenderFrameHost is re-created after crash. |
| 38 | |
| 39 | // Page is deleted in the following cases: |
Charlie Harrison | 32de7d7 | 2021-12-10 17:10:40 | [diff] [blame] | 40 | // 1) Main RenderFrameHost is deleted. Note that this might be different from |
| 41 | // when the navigation commits, see the comment in |
| 42 | // RenderFrameHost::LifecycleState::kPendingDeletion for more details. |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 43 | // 2) A cross-document non-bfcached navigation is committed in the same |
| 44 | // RenderFrameHost. |
| 45 | // 3) Before main RenderFrameHost is re-created after crash. |
| 46 | |
| 47 | // If a method can be called only for main RenderFrameHosts or if its behaviour |
| 48 | // is identical when called on the parent / child RenderFrameHosts, it should |
| 49 | // be added to Page(Impl). |
| 50 | |
| 51 | // With Multiple Page Architecture (MPArch), each WebContents may have |
| 52 | // additional FrameTrees which will have their own associated Page. Please take |
| 53 | // into consideration when assuming that Page is appropriate for storing |
| 54 | // something that's common for all frames you see on a tab. |
Kevin McNee | 88bf224 | 2022-11-23 00:27:34 | [diff] [blame] | 55 | // See docs/frame_trees.md for more details. |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 56 | |
| 57 | // NOTE: Depending on the process model, the cross-origin iframes are likely to |
| 58 | // be hosted in a different renderer process than the main document, so a given |
| 59 | // page is hosted in multiple renderer processes at the same time. |
Dave Tapuska | 2cf1f53 | 2022-08-10 15:30:49 | [diff] [blame] | 60 | // RenderViewHost / `blink::WebView` / blink::Page (which are all 1:1:1) |
| 61 | // represent a part of a given content::Page in a given renderer process (note, |
| 62 | // however, that like RenderFrameHosts, these objects at the moment can be |
| 63 | // reused for a new content::Page for a cross-document same-site main-frame |
| 64 | // navigation). |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 65 | class CONTENT_EXPORT Page : public base::SupportsUserData { |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 66 | public: |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 67 | ~Page() override = default; |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 68 | |
| 69 | // The GURL for the page's web application manifest. |
| 70 | // See https://w3c.github.io/manifest/#web-application-manifest |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 71 | virtual const std::optional<GURL>& GetManifestUrl() const = 0; |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 72 | |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 73 | // The callback invoked when the renderer responds to a request for the main |
| 74 | // frame document's manifest. The url will be empty if the document specifies |
| 75 | // no manifest, and the manifest will be empty if any other failures occurred. |
| 76 | using GetManifestCallback = |
Marijn Kruisselbrink | 2db1d3a | 2024-07-19 15:53:27 | [diff] [blame] | 77 | base::OnceCallback<void(blink::mojom::ManifestRequestResult, |
| 78 | const GURL&, |
| 79 | blink::mojom::ManifestPtr)>; |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 80 | |
| 81 | // Requests the manifest URL and the Manifest of the main frame's document. |
Alan Cutter | bc7df2da | 2022-10-10 03:15:17 | [diff] [blame] | 82 | // |callback| may be called after the WebContents has been destroyed. |
| 83 | // This must be invoked on the UI thread, |callback| will be invoked on the UI |
| 84 | // thread. |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 85 | virtual void GetManifest(GetManifestCallback callback) = 0; |
| 86 | |
Dave Tapuska | 9c9afe8 | 2021-06-22 19:07:45 | [diff] [blame] | 87 | // Returns true iff this Page is primary for the associated `WebContents` |
| 88 | // (i.e. web_contents->GetPrimaryPage() == this_page). Non-primary pages |
Adithya Srinivasan | 39c8191 | 2024-07-11 20:44:21 | [diff] [blame] | 89 | // include pages in bfcache, prerendering, fenced frames, pending commit and |
| 90 | // pending deletion pages. See WebContents::GetPrimaryPage for more details. |
Julie Jeongeun Kim | da52992 | 2023-01-13 02:59:59 | [diff] [blame] | 91 | virtual bool IsPrimary() const = 0; |
Dave Tapuska | 9c9afe8 | 2021-06-22 19:07:45 | [diff] [blame] | 92 | |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 93 | // Returns the main RenderFrameHost associated with this Page. |
| 94 | RenderFrameHost& GetMainDocument() { return GetMainDocumentHelper(); } |
| 95 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 96 | // Write a description of this Page into the provided |context|. |
| 97 | virtual void WriteIntoTrace(perfetto::TracedValue context) = 0; |
| 98 | |
Miyoung Shin | fa182e47 | 2021-09-03 12:39:32 | [diff] [blame] | 99 | virtual base::WeakPtr<Page> GetWeakPtr() = 0; |
| 100 | |
Kevin McNee | 3183a779 | 2021-11-09 21:03:36 | [diff] [blame] | 101 | // Whether the most recent page scale factor sent by the main frame's renderer |
| 102 | // is 1 (i.e. no magnification). |
| 103 | virtual bool IsPageScaleFactorOne() = 0; |
| 104 | |
Takashi Toyoshima | 6c58bbd | 2023-05-19 09:41:35 | [diff] [blame] | 105 | // Returns the MIME type bound to the Page contents after a navigation. |
| 106 | virtual const std::string& GetContentsMimeType() const = 0; |
| 107 | |
Sonja | 5f1ab74 | 2023-11-09 14:48:36 | [diff] [blame] | 108 | // Test version of `PageImpl::SetResizable` to allow tests outside of |
| 109 | // //content to simulate the value normally set by the |
| 110 | // window.setResizable(bool) API. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 111 | virtual void SetResizableForTesting(std::optional<bool> resizable) = 0; |
| 112 | // Returns the value set by `window.setResizable(bool)` API or `std::nullopt` |
Sonja | 5f1ab74 | 2023-11-09 14:48:36 | [diff] [blame] | 113 | // if unset which can override `BrowserView::CanResize`. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 114 | virtual std::optional<bool> GetResizable() = 0; |
Sonja | 5f1ab74 | 2023-11-09 14:48:36 | [diff] [blame] | 115 | |
Rakina Zata Amni | 65a5dc4 | 2025-03-03 02:51:55 | [diff] [blame] | 116 | #if BUILDFLAG(IS_ANDROID) |
| 117 | // Returns a reference to Page Java counterpart. |
| 118 | virtual const base::android::JavaRef<jobject>& GetJavaPage() = 0; |
| 119 | #endif |
| 120 | |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 121 | private: |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 122 | // This method is needed to ensure that PageImpl can both implement a Page's |
| 123 | // method and define a new GetMainDocument() returning RenderFrameHostImpl. |
| 124 | // Covariant types can't be used here due to circular includes as |
| 125 | // RenderFrameHost::GetPage and RenderFrameHostImpl::GetPage already return |
| 126 | // Page& and PageImpl& respectively, which means that page_impl.h can't |
| 127 | // include render_frame_host_impl.h. |
| 128 | virtual RenderFrameHost& GetMainDocumentHelper() = 0; |
| 129 | |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 130 | // This interface should only be implemented inside content. |
| 131 | friend class PageImpl; |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 132 | Page() = default; |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | } // namespace content |
| 136 | |
| 137 | #endif // CONTENT_PUBLIC_BROWSER_PAGE_H_ |