blob: 45e514517f831b3badc8e0501e759ceaf9ebdffd [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
Rakina Zata Amni65a5dc42025-03-03 02:51:5518#if BUILDFLAG(IS_ANDROID)
19#include "base/android/scoped_java_ref.h"
20#endif
21
Sreeja Kamishetty7c91ab22021-06-03 13:29:5222namespace 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 Kamishetty0a0961f2021-10-11 16:23:5329// |DocumentUserData| for more details and crbug.com/936696 for the
Sreeja Kamishetty7c91ab22021-06-03 13:29:5230// 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 Harrison32de7d72021-12-10 17:10:4040// 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 Kamishetty7c91ab22021-06-03 13:29:5243// 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 McNee88bf2242022-11-23 00:27:3455// See docs/frame_trees.md for more details.
Sreeja Kamishetty7c91ab22021-06-03 13:29:5256
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 Tapuska2cf1f532022-08-10 15:30:4960// 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 Kamishetty1b5c1432021-06-25 11:32:5965class CONTENT_EXPORT Page : public base::SupportsUserData {
Sreeja Kamishetty7c91ab22021-06-03 13:29:5266 public:
Sreeja Kamishetty1b5c1432021-06-25 11:32:5967 ~Page() override = default;
Sreeja Kamishetty7c91ab22021-06-03 13:29:5268
69 // The GURL for the page's web application manifest.
70 // See https://w3c.github.io/manifest/#web-application-manifest
Arthur Sonzognic686e8f2024-01-11 08:36:3771 virtual const std::optional<GURL>& GetManifestUrl() const = 0;
Sreeja Kamishetty7c91ab22021-06-03 13:29:5272
Jeremy Roman4bd173d2021-06-17 00:05:4473 // 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 Kruisselbrink2db1d3a2024-07-19 15:53:2777 base::OnceCallback<void(blink::mojom::ManifestRequestResult,
78 const GURL&,
79 blink::mojom::ManifestPtr)>;
Jeremy Roman4bd173d2021-06-17 00:05:4480
81 // Requests the manifest URL and the Manifest of the main frame's document.
Alan Cutterbc7df2da2022-10-10 03:15:1782 // |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 Roman4bd173d2021-06-17 00:05:4485 virtual void GetManifest(GetManifestCallback callback) = 0;
86
Dave Tapuska9c9afe82021-06-22 19:07:4587 // Returns true iff this Page is primary for the associated `WebContents`
88 // (i.e. web_contents->GetPrimaryPage() == this_page). Non-primary pages
Adithya Srinivasan39c81912024-07-11 20:44:2189 // include pages in bfcache, prerendering, fenced frames, pending commit and
90 // pending deletion pages. See WebContents::GetPrimaryPage for more details.
Julie Jeongeun Kimda529922023-01-13 02:59:5991 virtual bool IsPrimary() const = 0;
Dave Tapuska9c9afe82021-06-22 19:07:4592
Sreeja Kamishetty1b5c1432021-06-25 11:32:5993 // Returns the main RenderFrameHost associated with this Page.
94 RenderFrameHost& GetMainDocument() { return GetMainDocumentHelper(); }
95
Jeremy Roman2d8dfe132021-07-06 20:51:2696 // Write a description of this Page into the provided |context|.
97 virtual void WriteIntoTrace(perfetto::TracedValue context) = 0;
98
Miyoung Shinfa182e472021-09-03 12:39:3299 virtual base::WeakPtr<Page> GetWeakPtr() = 0;
100
Kevin McNee3183a7792021-11-09 21:03:36101 // 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 Toyoshima6c58bbd2023-05-19 09:41:35105 // Returns the MIME type bound to the Page contents after a navigation.
106 virtual const std::string& GetContentsMimeType() const = 0;
107
Sonja5f1ab742023-11-09 14:48:36108 // 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 Sonzognic686e8f2024-01-11 08:36:37111 virtual void SetResizableForTesting(std::optional<bool> resizable) = 0;
112 // Returns the value set by `window.setResizable(bool)` API or `std::nullopt`
Sonja5f1ab742023-11-09 14:48:36113 // if unset which can override `BrowserView::CanResize`.
Arthur Sonzognic686e8f2024-01-11 08:36:37114 virtual std::optional<bool> GetResizable() = 0;
Sonja5f1ab742023-11-09 14:48:36115
Rakina Zata Amni65a5dc42025-03-03 02:51:55116#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 Kamishetty7c91ab22021-06-03 13:29:52121 private:
Sreeja Kamishetty1b5c1432021-06-25 11:32:59122 // 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 Kamishetty7c91ab22021-06-03 13:29:52130 // This interface should only be implemented inside content.
131 friend class PageImpl;
Sreeja Kamishetty1b5c1432021-06-25 11:32:59132 Page() = default;
Sreeja Kamishetty7c91ab22021-06-03 13:29:52133};
134
135} // namespace content
136
137#endif // CONTENT_PUBLIC_BROWSER_PAGE_H_