blob: 1ac586d2519d8afe06fa3bdbb2abdfbf40361c39 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2021 The Chromium Authors
Sreeja Kamishetty7c91ab22021-06-03 13:29:522// 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 Sonzognic686e8f2024-01-11 08:36:378#include <optional>
9
Avi Drissmanadac21992023-01-11 23:46:3910#include "base/functional/callback.h"
Sreeja Kamishetty1b5c1432021-06-25 11:32:5911#include "base/supports_user_data.h"
Sreeja Kamishetty7c91ab22021-06-03 13:29:5212#include "content/common/content_export.h"
Sreeja Kamishetty1b5c1432021-06-25 11:32:5913#include "content/public/browser/render_frame_host.h"
Alan Cuttere511d18a2021-08-04 23:10:3814#include "third_party/blink/public/mojom/manifest/manifest.mojom-forward.h"
Jeremy Roman2d8dfe132021-07-06 20:51:2615#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"
Sreeja Kamishetty7c91ab22021-06-03 13:29:5216#include "url/gurl.h"
17
18namespace 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 Kamishetty0a0961f2021-10-11 16:23:5325// |DocumentUserData| for more details and crbug.com/936696 for the
Sreeja Kamishetty7c91ab22021-06-03 13:29:5226// 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 Harrison32de7d72021-12-10 17:10:4036// 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 Kamishetty7c91ab22021-06-03 13:29:5239// 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 McNee88bf2242022-11-23 00:27:3451// See docs/frame_trees.md for more details.
Sreeja Kamishetty7c91ab22021-06-03 13:29:5252
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 Tapuska2cf1f532022-08-10 15:30:4956// 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 Kamishetty1b5c1432021-06-25 11:32:5961class CONTENT_EXPORT Page : public base::SupportsUserData {
Sreeja Kamishetty7c91ab22021-06-03 13:29:5262 public:
Sreeja Kamishetty1b5c1432021-06-25 11:32:5963 ~Page() override = default;
Sreeja Kamishetty7c91ab22021-06-03 13:29:5264
65 // The GURL for the page's web application manifest.
66 // See https://w3c.github.io/manifest/#web-application-manifest
Arthur Sonzognic686e8f2024-01-11 08:36:3767 virtual const std::optional<GURL>& GetManifestUrl() const = 0;
Sreeja Kamishetty7c91ab22021-06-03 13:29:5268
Jeremy Roman4bd173d2021-06-17 00:05:4469 // 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 Kruisselbrink2db1d3a2024-07-19 15:53:2773 base::OnceCallback<void(blink::mojom::ManifestRequestResult,
74 const GURL&,
75 blink::mojom::ManifestPtr)>;
Jeremy Roman4bd173d2021-06-17 00:05:4476
77 // Requests the manifest URL and the Manifest of the main frame's document.
Alan Cutterbc7df2da2022-10-10 03:15:1778 // |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 Roman4bd173d2021-06-17 00:05:4481 virtual void GetManifest(GetManifestCallback callback) = 0;
82
Dave Tapuska9c9afe82021-06-22 19:07:4583 // Returns true iff this Page is primary for the associated `WebContents`
84 // (i.e. web_contents->GetPrimaryPage() == this_page). Non-primary pages
Adithya Srinivasan39c81912024-07-11 20:44:2185 // include pages in bfcache, prerendering, fenced frames, pending commit and
86 // pending deletion pages. See WebContents::GetPrimaryPage for more details.
Julie Jeongeun Kimda529922023-01-13 02:59:5987 virtual bool IsPrimary() const = 0;
Dave Tapuska9c9afe82021-06-22 19:07:4588
Sreeja Kamishetty1b5c1432021-06-25 11:32:5989 // Returns the main RenderFrameHost associated with this Page.
90 RenderFrameHost& GetMainDocument() { return GetMainDocumentHelper(); }
91
Jeremy Roman2d8dfe132021-07-06 20:51:2692 // Write a description of this Page into the provided |context|.
93 virtual void WriteIntoTrace(perfetto::TracedValue context) = 0;
94
Miyoung Shinfa182e472021-09-03 12:39:3295 virtual base::WeakPtr<Page> GetWeakPtr() = 0;
96
Kevin McNee3183a7792021-11-09 21:03:3697 // 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 Toyoshima6c58bbd2023-05-19 09:41:35101 // Returns the MIME type bound to the Page contents after a navigation.
102 virtual const std::string& GetContentsMimeType() const = 0;
103
Sonja5f1ab742023-11-09 14:48:36104 // 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 Sonzognic686e8f2024-01-11 08:36:37107 virtual void SetResizableForTesting(std::optional<bool> resizable) = 0;
108 // Returns the value set by `window.setResizable(bool)` API or `std::nullopt`
Sonja5f1ab742023-11-09 14:48:36109 // if unset which can override `BrowserView::CanResize`.
Arthur Sonzognic686e8f2024-01-11 08:36:37110 virtual std::optional<bool> GetResizable() = 0;
Sonja5f1ab742023-11-09 14:48:36111
Sreeja Kamishetty7c91ab22021-06-03 13:29:52112 private:
Sreeja Kamishetty1b5c1432021-06-25 11:32:59113 // 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 Kamishetty7c91ab22021-06-03 13:29:52121 // This interface should only be implemented inside content.
122 friend class PageImpl;
Sreeja Kamishetty1b5c1432021-06-25 11:32:59123 Page() = default;
Sreeja Kamishetty7c91ab22021-06-03 13:29:52124};
125
126} // namespace content
127
128#endif // CONTENT_PUBLIC_BROWSER_PAGE_H_