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