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