Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [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 | #include "content/browser/renderer_host/page_impl.h" |
| 6 | |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 7 | #include "base/barrier_closure.h" |
Sky Malice | 3774b00 | 2022-10-21 19:18:40 | [diff] [blame] | 8 | #include "base/feature_list.h" |
Dominic Farolino | 5c606c1 | 2021-12-18 09:40:14 | [diff] [blame] | 9 | #include "base/i18n/character_encoding.h" |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 10 | #include "base/trace_event/optional_trace_event.h" |
Sky Malice | 3774b00 | 2022-10-21 19:18:40 | [diff] [blame] | 11 | #include "cc/base/features.h" |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 12 | #include "content/browser/manifest/manifest_manager_host.h" |
Dave Tapuska | 9c9afe8 | 2021-06-22 19:07:45 | [diff] [blame] | 13 | #include "content/browser/renderer_host/frame_tree_node.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 14 | #include "content/browser/renderer_host/page_delegate.h" |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 15 | #include "content/browser/renderer_host/render_frame_host_delegate.h" |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 16 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 17 | #include "content/browser/renderer_host/render_frame_proxy_host.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 18 | #include "content/browser/renderer_host/render_view_host_delegate.h" |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 19 | #include "content/browser/renderer_host/render_view_host_impl.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 20 | #include "content/public/browser/render_view_host.h" |
Camillia Smith Barnes | ddaf5b1 | 2023-01-24 00:06:32 | [diff] [blame] | 21 | #include "third_party/blink/public/common/features.h" |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 22 | #include "third_party/blink/public/common/loader/loader_constants.h" |
Julie Jeongeun Kim | 33ef6a2 | 2022-03-22 09:46:11 | [diff] [blame] | 23 | #include "third_party/blink/public/mojom/manifest/manifest.mojom.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 24 | #include "third_party/perfetto/include/perfetto/tracing/traced_value.h" |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 25 | |
| 26 | namespace content { |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 27 | |
| 28 | PageImpl::PageImpl(RenderFrameHostImpl& rfh, PageDelegate& delegate) |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 29 | : main_document_(rfh), |
| 30 | delegate_(delegate), |
Camillia Smith Barnes | ddaf5b1 | 2023-01-24 00:06:32 | [diff] [blame] | 31 | text_autosizer_page_info_({0, 0, 1.f}) { |
| 32 | if (base::FeatureList::IsEnabled( |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 33 | blink::features::kSharedStorageSelectURLLimit)) { |
| 34 | select_url_overall_budget_ = static_cast<double>( |
| 35 | blink::features::kSharedStorageSelectURLBitBudgetPerPageLoad.Get()); |
| 36 | select_url_max_bits_per_origin_ = static_cast<double>( |
| 37 | blink::features::kSharedStorageSelectURLBitBudgetPerOriginPerPageLoad |
| 38 | .Get()); |
| 39 | } |
Camillia Smith Barnes | ddaf5b1 | 2023-01-24 00:06:32 | [diff] [blame] | 40 | } |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 41 | |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 42 | PageImpl::~PageImpl() { |
| 43 | // As SupportsUserData is a base class of PageImpl, Page members will be |
| 44 | // destroyed before running ~SupportsUserData, which would delete the |
| 45 | // associated PageUserData objects. Avoid this by calling ClearAllUserData |
| 46 | // explicitly here to ensure that the PageUserData destructors can access |
| 47 | // associated Page object. |
| 48 | ClearAllUserData(); |
| 49 | } |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 50 | |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 51 | const absl::optional<GURL>& PageImpl::GetManifestUrl() const { |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 52 | return manifest_url_; |
| 53 | } |
| 54 | |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 55 | void PageImpl::GetManifest(GetManifestCallback callback) { |
| 56 | ManifestManagerHost* manifest_manager_host = |
Julie Jeongeun Kim | 33ef6a2 | 2022-03-22 09:46:11 | [diff] [blame] | 57 | ManifestManagerHost::GetOrCreateForPage(*this); |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 58 | manifest_manager_host->GetManifest(std::move(callback)); |
| 59 | } |
| 60 | |
Julie Jeongeun Kim | da52992 | 2023-01-13 02:59:59 | [diff] [blame] | 61 | bool PageImpl::IsPrimary() const { |
Dominic Farolino | 4bc10ee | 2021-08-31 00:37:36 | [diff] [blame] | 62 | // TODO(1244137): Check for portals as well, once they are migrated to MPArch. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 63 | if (main_document_->IsFencedFrameRoot()) |
Dominic Farolino | 4bc10ee | 2021-08-31 00:37:36 | [diff] [blame] | 64 | return false; |
| 65 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 66 | return main_document_->lifecycle_state() == |
Khushal | c5eaf22 | 2021-06-30 20:15:48 | [diff] [blame] | 67 | RenderFrameHostImpl::LifecycleStateImpl::kActive; |
Dave Tapuska | 9c9afe8 | 2021-06-22 19:07:45 | [diff] [blame] | 68 | } |
| 69 | |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 70 | void PageImpl::UpdateManifestUrl(const GURL& manifest_url) { |
| 71 | manifest_url_ = manifest_url; |
| 72 | |
| 73 | // If |main_document_| is not active, the notification is sent on the page |
| 74 | // activation. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 75 | if (!main_document_->IsActive()) |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 76 | return; |
| 77 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 78 | main_document_->delegate()->OnManifestUrlChanged(*this); |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 79 | } |
| 80 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 81 | void PageImpl::WriteIntoTrace(perfetto::TracedValue context) { |
| 82 | auto dict = std::move(context).WriteDictionary(); |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 83 | dict.Add("main_document", *main_document_); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 84 | } |
| 85 | |
Miyoung Shin | fa182e47 | 2021-09-03 12:39:32 | [diff] [blame] | 86 | base::WeakPtr<Page> PageImpl::GetWeakPtr() { |
| 87 | return weak_factory_.GetWeakPtr(); |
| 88 | } |
| 89 | |
Yao Xiao | c722436 | 2022-02-16 08:21:40 | [diff] [blame] | 90 | base::WeakPtr<PageImpl> PageImpl::GetWeakPtrImpl() { |
| 91 | return weak_factory_.GetWeakPtr(); |
| 92 | } |
| 93 | |
Kevin McNee | 3183a779 | 2021-11-09 21:03:36 | [diff] [blame] | 94 | bool PageImpl::IsPageScaleFactorOne() { |
Kevin McNee | c4325ba | 2022-04-08 23:18:23 | [diff] [blame] | 95 | return GetPageScaleFactor() == 1.f; |
Kevin McNee | 3183a779 | 2021-11-09 21:03:36 | [diff] [blame] | 96 | } |
| 97 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 98 | void PageImpl::OnFirstVisuallyNonEmptyPaint() { |
| 99 | did_first_visually_non_empty_paint_ = true; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 100 | delegate_->OnFirstVisuallyNonEmptyPaint(*this); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void PageImpl::OnThemeColorChanged(const absl::optional<SkColor>& theme_color) { |
| 104 | main_document_theme_color_ = theme_color; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 105 | delegate_->OnThemeColorChanged(*this); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 106 | } |
| 107 | |
Aaron Krajeski | 628c58c | 2023-04-04 16:24:12 | [diff] [blame^] | 108 | void PageImpl::DidChangeBackgroundColor(SkColor4f background_color, |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 109 | bool color_adjust) { |
Aaron Krajeski | 628c58c | 2023-04-04 16:24:12 | [diff] [blame^] | 110 | // TODO(aaronhk): This should remain an SkColor4f |
| 111 | main_document_background_color_ = background_color.toSkColor(); |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 112 | delegate_->OnBackgroundColorChanged(*this); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 113 | if (color_adjust) { |
| 114 | // <meta name="color-scheme" content="dark"> may pass the dark canvas |
| 115 | // background before the first paint in order to avoid flashing the white |
| 116 | // background in between loading documents. If we perform a navigation |
| 117 | // within the same renderer process, we keep the content background from the |
| 118 | // previous page while rendering is blocked in the new page, but for cross |
| 119 | // process navigations we would paint the default background (typically |
| 120 | // white) while the rendering is blocked. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 121 | main_document_->GetRenderWidgetHost()->GetView()->SetContentBackgroundColor( |
Aaron Krajeski | 628c58c | 2023-04-04 16:24:12 | [diff] [blame^] | 122 | background_color.toSkColor()); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Michael Bai | 19f17a30 | 2021-12-08 04:08:33 | [diff] [blame] | 126 | void PageImpl::DidInferColorScheme( |
| 127 | blink::mojom::PreferredColorScheme color_scheme) { |
| 128 | main_document_inferred_color_scheme_ = color_scheme; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 129 | delegate_->DidInferColorScheme(*this); |
Michael Bai | 19f17a30 | 2021-12-08 04:08:33 | [diff] [blame] | 130 | } |
| 131 | |
Julie Jeongeun Kim | d4597df1 | 2022-11-11 02:44:51 | [diff] [blame] | 132 | void PageImpl::NotifyPageBecameCurrent() { |
| 133 | if (!IsPrimary()) |
| 134 | return; |
| 135 | delegate_->NotifyPageBecamePrimary(*this); |
| 136 | } |
| 137 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 138 | void PageImpl::SetContentsMimeType(std::string mime_type) { |
| 139 | contents_mime_type_ = std::move(mime_type); |
| 140 | } |
| 141 | |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 142 | void PageImpl::OnTextAutosizerPageInfoChanged( |
| 143 | blink::mojom::TextAutosizerPageInfoPtr page_info) { |
| 144 | OPTIONAL_TRACE_EVENT0("content", "PageImpl::OnTextAutosizerPageInfoChanged"); |
| 145 | |
Dave Tapuska | 2cf1f53 | 2022-08-10 15:30:49 | [diff] [blame] | 146 | // Keep a copy of `page_info` in case we create a new `blink::WebView` before |
| 147 | // the next update, so that the PageImpl can tell the newly created |
| 148 | // `blink::WebView` about the autosizer info. |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 149 | text_autosizer_page_info_.main_frame_width = page_info->main_frame_width; |
| 150 | text_autosizer_page_info_.main_frame_layout_width = |
| 151 | page_info->main_frame_layout_width; |
| 152 | text_autosizer_page_info_.device_scale_adjustment = |
| 153 | page_info->device_scale_adjustment; |
| 154 | |
| 155 | auto remote_frames_broadcast_callback = base::BindRepeating( |
| 156 | [](const blink::mojom::TextAutosizerPageInfo& page_info, |
| 157 | RenderFrameProxyHost* proxy_host) { |
| 158 | DCHECK(proxy_host); |
| 159 | proxy_host->GetAssociatedRemoteMainFrame()->UpdateTextAutosizerPageInfo( |
| 160 | page_info.Clone()); |
| 161 | }, |
| 162 | text_autosizer_page_info_); |
| 163 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 164 | main_document_->frame_tree() |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 165 | ->root() |
| 166 | ->render_manager() |
| 167 | ->ExecuteRemoteFramesBroadcastMethod( |
| 168 | std::move(remote_frames_broadcast_callback), |
Sharon Yang | 6b531343 | 2023-03-24 05:07:57 | [diff] [blame] | 169 | main_document_->GetSiteInstance()->group()); |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 170 | } |
| 171 | |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 172 | void PageImpl::SetActivationStartTime(base::TimeTicks activation_start) { |
| 173 | DCHECK(!activation_start_time_for_prerendering_); |
| 174 | activation_start_time_for_prerendering_ = activation_start; |
| 175 | } |
| 176 | |
| 177 | void PageImpl::ActivateForPrerendering( |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 178 | StoredPage::RenderViewHostImplSafeRefSet& render_view_hosts, |
| 179 | absl::optional<blink::ViewTransitionState> view_transition_state) { |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 180 | base::OnceClosure did_activate_render_views = |
| 181 | base::BindOnce(&PageImpl::DidActivateAllRenderViewsForPrerendering, |
| 182 | weak_factory_.GetWeakPtr()); |
| 183 | |
| 184 | base::RepeatingClosure barrier = base::BarrierClosure( |
| 185 | render_view_hosts.size(), std::move(did_activate_render_views)); |
Dave Tapuska | c3e5835 | 2022-09-28 19:05:27 | [diff] [blame] | 186 | for (const auto& rvh : render_view_hosts) { |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 187 | auto params = blink::mojom::PrerenderPageActivationParams::New(); |
| 188 | |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 189 | // Only send navigation_start to the RenderViewHost for the main frame to |
| 190 | // avoid sending the info cross-origin. Only this RenderViewHost needs the |
| 191 | // info, as we expect the other RenderViewHosts are made for cross-origin |
| 192 | // iframes which have not yet loaded their document. To the renderer, it |
| 193 | // just looks like an ongoing navigation is happening in the frame and has |
| 194 | // not yet committed. These RenderViews still need to know about activation |
| 195 | // so their documents are created in the non-prerendered state once their |
| 196 | // navigation is committed. |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 197 | if (main_document_->GetRenderViewHost() == &*rvh) { |
| 198 | params->activation_start = *activation_start_time_for_prerendering_; |
| 199 | params->view_transition_state = std::move(view_transition_state); |
| 200 | } |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 201 | |
Hiroki Nakagawa | ab53cd2 | 2022-04-13 19:18:02 | [diff] [blame] | 202 | params->was_user_activated = |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 203 | main_document_->frame_tree_node() |
| 204 | ->has_received_user_gesture_before_nav() |
Hiroki Nakagawa | ab53cd2 | 2022-04-13 19:18:02 | [diff] [blame] | 205 | ? blink::mojom::WasActivatedOption::kYes |
| 206 | : blink::mojom::WasActivatedOption::kNo; |
Hiroki Nakagawa | ab53cd2 | 2022-04-13 19:18:02 | [diff] [blame] | 207 | rvh->ActivatePrerenderedPage(std::move(params), barrier); |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // Prepare each RenderFrameHostImpl in this Page for activation. |
| 211 | // TODO(https://crbug.com/1232528): Currently we check GetPage() below because |
| 212 | // RenderFrameHostImpls may be in a different Page, if, e.g., they are in an |
| 213 | // inner WebContents. These are in a different FrameTree which might not know |
| 214 | // it is being prerendered. We should teach these FrameTrees that they are |
| 215 | // being prerendered, or ban inner FrameTrees in a prerendering page. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 216 | main_document_->ForEachRenderFrameHostIncludingSpeculative( |
Daniel Cheng | 982f2b2 | 2022-08-25 23:46:16 | [diff] [blame] | 217 | [this](RenderFrameHostImpl* rfh) { |
| 218 | if (&rfh->GetPage() != this) |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 219 | return; |
| 220 | rfh->RendererWillActivateForPrerendering(); |
Daniel Cheng | 982f2b2 | 2022-08-25 23:46:16 | [diff] [blame] | 221 | }); |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 222 | } |
| 223 | |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 224 | void PageImpl::MaybeDispatchLoadEventsOnPrerenderActivation() { |
| 225 | DCHECK(IsPrimary()); |
| 226 | |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 227 | // Dispatch LoadProgressChanged notification on activation with the |
| 228 | // prerender last load progress value if the value is not equal to |
| 229 | // blink::kFinalLoadProgress, whose notification is dispatched during call |
| 230 | // to DidStopLoading. |
| 231 | if (load_progress() != blink::kFinalLoadProgress) |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 232 | main_document_->DidChangeLoadProgress(load_progress()); |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 233 | |
Sreeja Kamishetty | 4978330 | 2022-01-28 17:52:25 | [diff] [blame] | 234 | // Dispatch PrimaryMainDocumentElementAvailable before dispatching following |
| 235 | // load complete events. |
| 236 | if (is_main_document_element_available()) |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 237 | main_document_->MainDocumentElementAvailable(uses_temporary_zoom_level()); |
Sreeja Kamishetty | cd556091 | 2021-11-22 11:54:53 | [diff] [blame] | 238 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 239 | main_document_->ForEachRenderFrameHost( |
Daniel Cheng | 982f2b2 | 2022-08-25 23:46:16 | [diff] [blame] | 240 | &RenderFrameHostImpl::MaybeDispatchDOMContentLoadedOnPrerenderActivation); |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 241 | |
| 242 | if (is_on_load_completed_in_main_document()) |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 243 | main_document_->DocumentOnLoadCompleted(); |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 244 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 245 | main_document_->ForEachRenderFrameHost( |
Daniel Cheng | 982f2b2 | 2022-08-25 23:46:16 | [diff] [blame] | 246 | &RenderFrameHostImpl::MaybeDispatchDidFinishLoadOnPrerenderActivation); |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 247 | } |
| 248 | |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 249 | void PageImpl::DidActivateAllRenderViewsForPrerendering() { |
| 250 | // Tell each RenderFrameHostImpl in this Page that activation finished. |
Hiroki Nakagawa | f98d009a | 2023-03-16 02:26:10 | [diff] [blame] | 251 | main_document_->ForEachRenderFrameHostIncludingSpeculative( |
| 252 | [this](RenderFrameHostImpl* rfh) { |
| 253 | if (&rfh->GetPage() != this) { |
| 254 | return; |
| 255 | } |
| 256 | rfh->RendererDidActivateForPrerendering(); |
| 257 | }); |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 258 | } |
| 259 | |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 260 | RenderFrameHost& PageImpl::GetMainDocumentHelper() { |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 261 | return *main_document_; |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | RenderFrameHostImpl& PageImpl::GetMainDocument() const { |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 265 | return *main_document_; |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 266 | } |
| 267 | |
Yoshisato Yanagisawa | d016d62d3 | 2021-10-15 04:38:55 | [diff] [blame] | 268 | void PageImpl::UpdateBrowserControlsState(cc::BrowserControlsState constraints, |
| 269 | cc::BrowserControlsState current, |
| 270 | bool animate) { |
| 271 | // TODO(https://crbug.com/1154852): Asking for the LocalMainFrame interface |
| 272 | // before the RenderFrame is created is racy. |
Nasko Oskov | 8b04f40 | 2022-05-26 23:29:56 | [diff] [blame] | 273 | if (!GetMainDocument().IsRenderFrameLive()) |
Yoshisato Yanagisawa | d016d62d3 | 2021-10-15 04:38:55 | [diff] [blame] | 274 | return; |
| 275 | |
Sky Malice | 3774b00 | 2022-10-21 19:18:40 | [diff] [blame] | 276 | if (base::FeatureList::IsEnabled( |
| 277 | features::kUpdateBrowserControlsWithoutProxy)) { |
| 278 | GetMainDocument().GetRenderWidgetHost()->UpdateBrowserControlsState( |
| 279 | constraints, current, animate); |
| 280 | } else { |
| 281 | GetMainDocument().GetAssociatedLocalMainFrame()->UpdateBrowserControlsState( |
| 282 | constraints, current, animate); |
| 283 | } |
Yoshisato Yanagisawa | d016d62d3 | 2021-10-15 04:38:55 | [diff] [blame] | 284 | } |
| 285 | |
Kevin McNee | c4325ba | 2022-04-08 23:18:23 | [diff] [blame] | 286 | float PageImpl::GetPageScaleFactor() const { |
| 287 | return GetMainDocument().GetPageScaleFactor(); |
| 288 | } |
| 289 | |
Dominic Farolino | 5c606c1 | 2021-12-18 09:40:14 | [diff] [blame] | 290 | void PageImpl::UpdateEncoding(const std::string& encoding_name) { |
| 291 | if (encoding_name == last_reported_encoding_) |
| 292 | return; |
| 293 | last_reported_encoding_ = encoding_name; |
| 294 | |
| 295 | canonical_encoding_ = |
| 296 | base::GetCanonicalEncodingNameByAliasName(encoding_name); |
| 297 | } |
| 298 | |
Yoshisato Yanagisawa | 8ae0d11 | 2022-04-20 01:49:30 | [diff] [blame] | 299 | void PageImpl::NotifyVirtualKeyboardOverlayRect( |
| 300 | const gfx::Rect& keyboard_rect) { |
| 301 | // TODO(https://crbug.com/1317002): send notification to outer frames if |
| 302 | // needed. |
David Bokan | d6e44055b | 2022-09-21 03:58:08 | [diff] [blame] | 303 | DCHECK_EQ(virtual_keyboard_mode(), |
| 304 | ui::mojom::VirtualKeyboardMode::kOverlaysContent); |
Yoshisato Yanagisawa | 8ae0d11 | 2022-04-20 01:49:30 | [diff] [blame] | 305 | GetMainDocument().GetAssociatedLocalFrame()->NotifyVirtualKeyboardOverlayRect( |
| 306 | keyboard_rect); |
| 307 | } |
| 308 | |
David Bokan | d6e44055b | 2022-09-21 03:58:08 | [diff] [blame] | 309 | void PageImpl::SetVirtualKeyboardMode(ui::mojom::VirtualKeyboardMode mode) { |
| 310 | if (virtual_keyboard_mode_ == mode) |
| 311 | return; |
| 312 | |
| 313 | virtual_keyboard_mode_ = mode; |
| 314 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 315 | delegate_->OnVirtualKeyboardModeChanged(*this); |
David Bokan | d6e44055b | 2022-09-21 03:58:08 | [diff] [blame] | 316 | } |
| 317 | |
Yoshisato Yanagisawa | 668f844 | 2022-04-20 04:45:58 | [diff] [blame] | 318 | base::flat_map<std::string, std::string> PageImpl::GetKeyboardLayoutMap() { |
| 319 | return GetMainDocument().GetRenderWidgetHost()->GetKeyboardLayoutMap(); |
| 320 | } |
| 321 | |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 322 | bool PageImpl::CheckAndMaybeDebitSelectURLBudgets(const url::Origin& origin, |
| 323 | double bits_to_charge) { |
| 324 | if (!select_url_overall_budget_) { |
| 325 | // The limits are not enabled. |
Camillia Smith Barnes | 9d70e5ae8 | 2023-01-18 19:25:24 | [diff] [blame] | 326 | return true; |
| 327 | } |
| 328 | |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 329 | // Return false if there is insufficient overall budget. |
| 330 | if (bits_to_charge > select_url_overall_budget_.value()) { |
Camillia Smith Barnes | 574d4d4 | 2023-01-10 18:57:47 | [diff] [blame] | 331 | return false; |
| 332 | } |
| 333 | |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 334 | DCHECK(select_url_max_bits_per_origin_); |
| 335 | |
| 336 | // Return false if the max bits per origin is set to a value smaller than the |
| 337 | // current bits to charge. |
| 338 | if (bits_to_charge > select_url_max_bits_per_origin_.value()) { |
| 339 | return false; |
| 340 | } |
| 341 | |
| 342 | // Charge the per-origin budget or return false if there is not enough. |
| 343 | auto it = select_url_per_origin_budget_.find(origin); |
| 344 | if (it == select_url_per_origin_budget_.end()) { |
| 345 | select_url_per_origin_budget_[origin] = |
| 346 | select_url_max_bits_per_origin_.value() - bits_to_charge; |
| 347 | } else if (bits_to_charge > it->second) { |
| 348 | // There is insufficient per-origin budget remaining. |
| 349 | return false; |
| 350 | } else { |
| 351 | it->second -= bits_to_charge; |
| 352 | } |
| 353 | |
| 354 | // Charge the overall budget. |
| 355 | select_url_overall_budget_.value() -= bits_to_charge; |
Camillia Smith Barnes | 574d4d4 | 2023-01-10 18:57:47 | [diff] [blame] | 356 | return true; |
| 357 | } |
| 358 | |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 359 | } // namespace content |