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" |
Peilin Wang | ae08e26e | 2024-06-10 20:55:30 | [diff] [blame] | 12 | #include "cc/input/browser_controls_offset_tags_info.h" |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 13 | #include "content/browser/manifest/manifest_manager_host.h" |
Dave Tapuska | 9c9afe8 | 2021-06-22 19:07:45 | [diff] [blame] | 14 | #include "content/browser/renderer_host/frame_tree_node.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 15 | #include "content/browser/renderer_host/page_delegate.h" |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 16 | #include "content/browser/renderer_host/render_frame_host_delegate.h" |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 17 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 18 | #include "content/browser/renderer_host/render_frame_proxy_host.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 19 | #include "content/browser/renderer_host/render_view_host_delegate.h" |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 20 | #include "content/browser/renderer_host/render_view_host_impl.h" |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 21 | #include "content/public/browser/content_browser_client.h" |
Aman Verma | 39fe049 | 2024-06-17 14:07:01 | [diff] [blame] | 22 | #include "content/public/browser/peak_gpu_memory_tracker_factory.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 23 | #include "content/public/browser/render_view_host.h" |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 24 | #include "content/public/common/content_client.h" |
Peilin Wang | ae08e26e | 2024-06-10 20:55:30 | [diff] [blame] | 25 | #include "services/viz/public/mojom/compositing/offset_tag.mojom.h" |
Camillia Smith Barnes | ddaf5b1 | 2023-01-24 00:06:32 | [diff] [blame] | 26 | #include "third_party/blink/public/common/features.h" |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 27 | #include "third_party/blink/public/common/loader/loader_constants.h" |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 28 | #include "third_party/blink/public/common/shared_storage/shared_storage_utils.h" |
Julie Jeongeun Kim | 33ef6a20 | 2022-03-22 09:46:11 | [diff] [blame] | 29 | #include "third_party/blink/public/mojom/manifest/manifest.mojom.h" |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 30 | #include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h" |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 31 | #include "third_party/perfetto/include/perfetto/tracing/traced_value.h" |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 32 | |
| 33 | namespace content { |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 34 | |
| 35 | PageImpl::PageImpl(RenderFrameHostImpl& rfh, PageDelegate& delegate) |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 36 | : main_document_(rfh), |
| 37 | delegate_(delegate), |
Camillia Smith Barnes | ddaf5b1 | 2023-01-24 00:06:32 | [diff] [blame] | 38 | text_autosizer_page_info_({0, 0, 1.f}) { |
| 39 | if (base::FeatureList::IsEnabled( |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 40 | blink::features::kSharedStorageSelectURLLimit)) { |
| 41 | select_url_overall_budget_ = static_cast<double>( |
| 42 | blink::features::kSharedStorageSelectURLBitBudgetPerPageLoad.Get()); |
Camillia Smith Barnes | 7455223 | 2023-10-02 18:50:07 | [diff] [blame] | 43 | select_url_max_bits_per_site_ = static_cast<double>( |
| 44 | blink::features::kSharedStorageSelectURLBitBudgetPerSitePerPageLoad |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 45 | .Get()); |
| 46 | } |
Camillia Smith Barnes | ddaf5b1 | 2023-01-24 00:06:32 | [diff] [blame] | 47 | } |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 48 | |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 49 | PageImpl::~PageImpl() { |
| 50 | // As SupportsUserData is a base class of PageImpl, Page members will be |
| 51 | // destroyed before running ~SupportsUserData, which would delete the |
| 52 | // associated PageUserData objects. Avoid this by calling ClearAllUserData |
| 53 | // explicitly here to ensure that the PageUserData destructors can access |
| 54 | // associated Page object. |
| 55 | ClearAllUserData(); |
Adithya Srinivasan | a5795b9 | 2023-12-20 22:35:22 | [diff] [blame] | 56 | |
| 57 | // If we still have a PeakGpuMemoryTracker, then the loading it was observing |
| 58 | // never completed. Cancel its callback so that we don't report partial |
| 59 | // loads to UMA. |
| 60 | CancelLoadingMemoryTracker(); |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 61 | } |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 62 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 63 | const std::optional<GURL>& PageImpl::GetManifestUrl() const { |
Sreeja Kamishetty | 7c91ab2 | 2021-06-03 13:29:52 | [diff] [blame] | 64 | return manifest_url_; |
| 65 | } |
| 66 | |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 67 | void PageImpl::GetManifest(GetManifestCallback callback) { |
| 68 | ManifestManagerHost* manifest_manager_host = |
Julie Jeongeun Kim | 33ef6a20 | 2022-03-22 09:46:11 | [diff] [blame] | 69 | ManifestManagerHost::GetOrCreateForPage(*this); |
Jeremy Roman | 4bd173d | 2021-06-17 00:05:44 | [diff] [blame] | 70 | manifest_manager_host->GetManifest(std::move(callback)); |
| 71 | } |
| 72 | |
Julie Jeongeun Kim | da52992 | 2023-01-13 02:59:59 | [diff] [blame] | 73 | bool PageImpl::IsPrimary() const { |
Kevin McNee | f1b0f0b | 2024-09-17 21:49:41 | [diff] [blame^] | 74 | return main_document_->IsInPrimaryMainFrame(); |
Dave Tapuska | 9c9afe8 | 2021-06-22 19:07:45 | [diff] [blame] | 75 | } |
| 76 | |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 77 | void PageImpl::UpdateManifestUrl(const GURL& manifest_url) { |
| 78 | manifest_url_ = manifest_url; |
| 79 | |
| 80 | // If |main_document_| is not active, the notification is sent on the page |
| 81 | // activation. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 82 | if (!main_document_->IsActive()) |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 83 | return; |
| 84 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 85 | main_document_->delegate()->OnManifestUrlChanged(*this); |
Julie Jeongeun Kim | 9e20451 | 2021-06-24 07:28:54 | [diff] [blame] | 86 | } |
| 87 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 88 | void PageImpl::WriteIntoTrace(perfetto::TracedValue context) { |
| 89 | auto dict = std::move(context).WriteDictionary(); |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 90 | dict.Add("main_document", *main_document_); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 91 | } |
| 92 | |
Miyoung Shin | fa182e47 | 2021-09-03 12:39:32 | [diff] [blame] | 93 | base::WeakPtr<Page> PageImpl::GetWeakPtr() { |
| 94 | return weak_factory_.GetWeakPtr(); |
| 95 | } |
| 96 | |
Yao Xiao | c722436 | 2022-02-16 08:21:40 | [diff] [blame] | 97 | base::WeakPtr<PageImpl> PageImpl::GetWeakPtrImpl() { |
| 98 | return weak_factory_.GetWeakPtr(); |
| 99 | } |
| 100 | |
Kevin McNee | 3183a779 | 2021-11-09 21:03:36 | [diff] [blame] | 101 | bool PageImpl::IsPageScaleFactorOne() { |
Kevin McNee | c4325ba | 2022-04-08 23:18:23 | [diff] [blame] | 102 | return GetPageScaleFactor() == 1.f; |
Kevin McNee | 3183a779 | 2021-11-09 21:03:36 | [diff] [blame] | 103 | } |
| 104 | |
Takashi Toyoshima | 6c58bbd | 2023-05-19 09:41:35 | [diff] [blame] | 105 | const std::string& PageImpl::GetContentsMimeType() const { |
| 106 | return contents_mime_type_; |
| 107 | } |
| 108 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 109 | void PageImpl::SetResizableForTesting(std::optional<bool> resizable) { |
Sonja | 5f1ab74 | 2023-11-09 14:48:36 | [diff] [blame] | 110 | SetResizable(resizable); |
| 111 | } |
| 112 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 113 | void PageImpl::SetResizable(std::optional<bool> resizable) { |
Sonja | 5f1ab74 | 2023-11-09 14:48:36 | [diff] [blame] | 114 | resizable_ = resizable; |
| 115 | delegate_->OnCanResizeFromWebAPIChanged(); |
| 116 | } |
| 117 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 118 | std::optional<bool> PageImpl::GetResizable() { |
Sonja | 5f1ab74 | 2023-11-09 14:48:36 | [diff] [blame] | 119 | return resizable_; |
| 120 | } |
| 121 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 122 | void PageImpl::OnFirstVisuallyNonEmptyPaint() { |
| 123 | did_first_visually_non_empty_paint_ = true; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 124 | delegate_->OnFirstVisuallyNonEmptyPaint(*this); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 125 | } |
| 126 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 127 | void PageImpl::OnThemeColorChanged(const std::optional<SkColor>& theme_color) { |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 128 | main_document_theme_color_ = theme_color; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 129 | delegate_->OnThemeColorChanged(*this); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 130 | } |
| 131 | |
Aaron Krajeski | 628c58c | 2023-04-04 16:24:12 | [diff] [blame] | 132 | void PageImpl::DidChangeBackgroundColor(SkColor4f background_color, |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 133 | bool color_adjust) { |
Aaron Krajeski | 628c58c | 2023-04-04 16:24:12 | [diff] [blame] | 134 | // TODO(aaronhk): This should remain an SkColor4f |
| 135 | main_document_background_color_ = background_color.toSkColor(); |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 136 | delegate_->OnBackgroundColorChanged(*this); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 137 | if (color_adjust) { |
| 138 | // <meta name="color-scheme" content="dark"> may pass the dark canvas |
| 139 | // background before the first paint in order to avoid flashing the white |
| 140 | // background in between loading documents. If we perform a navigation |
| 141 | // within the same renderer process, we keep the content background from the |
| 142 | // previous page while rendering is blocked in the new page, but for cross |
| 143 | // process navigations we would paint the default background (typically |
| 144 | // white) while the rendering is blocked. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 145 | main_document_->GetRenderWidgetHost()->GetView()->SetContentBackgroundColor( |
Aaron Krajeski | 628c58c | 2023-04-04 16:24:12 | [diff] [blame] | 146 | background_color.toSkColor()); |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Michael Bai | 19f17a30 | 2021-12-08 04:08:33 | [diff] [blame] | 150 | void PageImpl::DidInferColorScheme( |
| 151 | blink::mojom::PreferredColorScheme color_scheme) { |
| 152 | main_document_inferred_color_scheme_ = color_scheme; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 153 | delegate_->DidInferColorScheme(*this); |
Michael Bai | 19f17a30 | 2021-12-08 04:08:33 | [diff] [blame] | 154 | } |
| 155 | |
Julie Jeongeun Kim | d4597df1 | 2022-11-11 02:44:51 | [diff] [blame] | 156 | void PageImpl::NotifyPageBecameCurrent() { |
| 157 | if (!IsPrimary()) |
| 158 | return; |
| 159 | delegate_->NotifyPageBecamePrimary(*this); |
| 160 | } |
| 161 | |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 162 | void PageImpl::SetContentsMimeType(std::string mime_type) { |
| 163 | contents_mime_type_ = std::move(mime_type); |
| 164 | } |
| 165 | |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 166 | void PageImpl::OnTextAutosizerPageInfoChanged( |
| 167 | blink::mojom::TextAutosizerPageInfoPtr page_info) { |
| 168 | OPTIONAL_TRACE_EVENT0("content", "PageImpl::OnTextAutosizerPageInfoChanged"); |
| 169 | |
Dave Tapuska | 2cf1f53 | 2022-08-10 15:30:49 | [diff] [blame] | 170 | // Keep a copy of `page_info` in case we create a new `blink::WebView` before |
| 171 | // the next update, so that the PageImpl can tell the newly created |
| 172 | // `blink::WebView` about the autosizer info. |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 173 | text_autosizer_page_info_.main_frame_width = page_info->main_frame_width; |
| 174 | text_autosizer_page_info_.main_frame_layout_width = |
| 175 | page_info->main_frame_layout_width; |
| 176 | text_autosizer_page_info_.device_scale_adjustment = |
| 177 | page_info->device_scale_adjustment; |
| 178 | |
| 179 | auto remote_frames_broadcast_callback = base::BindRepeating( |
| 180 | [](const blink::mojom::TextAutosizerPageInfo& page_info, |
| 181 | RenderFrameProxyHost* proxy_host) { |
| 182 | DCHECK(proxy_host); |
| 183 | proxy_host->GetAssociatedRemoteMainFrame()->UpdateTextAutosizerPageInfo( |
| 184 | page_info.Clone()); |
| 185 | }, |
| 186 | text_autosizer_page_info_); |
| 187 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 188 | main_document_->frame_tree() |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 189 | ->root() |
| 190 | ->render_manager() |
| 191 | ->ExecuteRemoteFramesBroadcastMethod( |
| 192 | std::move(remote_frames_broadcast_callback), |
Sharon Yang | 6b531343 | 2023-03-24 05:07:57 | [diff] [blame] | 193 | main_document_->GetSiteInstance()->group()); |
Lingqi Chi | dcf72244 | 2021-09-02 01:47:19 | [diff] [blame] | 194 | } |
| 195 | |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 196 | void PageImpl::SetActivationStartTime(base::TimeTicks activation_start) { |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 197 | CHECK(!activation_start_time_); |
| 198 | activation_start_time_ = activation_start; |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 199 | } |
| 200 | |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 201 | void PageImpl::Activate( |
| 202 | ActivationType type, |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 203 | StoredPage::RenderViewHostImplSafeRefSet& render_view_hosts, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 204 | std::optional<blink::ViewTransitionState> view_transition_state, |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 205 | base::OnceCallback<void(base::TimeTicks)> completion_callback) { |
| 206 | TRACE_EVENT1("navigation", "PageImpl::Activate", "activation_type", type); |
Lingqi Chi | ef8657c | 2023-06-08 08:40:31 | [diff] [blame] | 207 | |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 208 | // SetActivationStartTime() should be called first as the value is used in |
| 209 | // the callback below. |
| 210 | CHECK(activation_start_time_.has_value()); |
| 211 | |
| 212 | base::OnceClosure did_activate_render_views = base::BindOnce( |
| 213 | &PageImpl::DidActivateAllRenderViewsForPrerenderingOrPreview, |
| 214 | weak_factory_.GetWeakPtr(), std::move(completion_callback)); |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 215 | |
| 216 | base::RepeatingClosure barrier = base::BarrierClosure( |
| 217 | render_view_hosts.size(), std::move(did_activate_render_views)); |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 218 | bool view_transition_state_consumed = false; |
Dave Tapuska | c3e5835 | 2022-09-28 19:05:27 | [diff] [blame] | 219 | for (const auto& rvh : render_view_hosts) { |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 220 | auto params = blink::mojom::PrerenderPageActivationParams::New(); |
| 221 | |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 222 | if (main_document_->GetRenderViewHost() == &*rvh) { |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 223 | // For prerendering activation, send activation_start only to the |
| 224 | // RenderViewHost for the main frame to avoid sending the info |
| 225 | // cross-origin. Only this RenderViewHost needs the info, as we expect the |
| 226 | // other RenderViewHosts are made for cross-origin iframes which have not |
| 227 | // yet loaded their document. To the renderer, it just looks like an |
| 228 | // ongoing navigation is happening in the frame and has not yet committed. |
| 229 | // These RenderViews still need to know about activation so their |
| 230 | // documents are created in the non-prerendered state once their |
| 231 | // navigation is committed. |
| 232 | params->activation_start = *activation_start_time_; |
| 233 | // Note that there cannot be a use-after-move since the if condition |
| 234 | // should be true at most once. |
| 235 | CHECK(!view_transition_state_consumed); |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 236 | params->view_transition_state = std::move(view_transition_state); |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 237 | view_transition_state_consumed = true; |
| 238 | } else if (type == ActivationType::kPreview) { |
| 239 | // For preview activation, send activation_start to all RenderViewHosts |
| 240 | // as preview loads cross-origin subframes under the capability control, |
| 241 | // and activation_start time is meaningful there. |
| 242 | params->activation_start = *activation_start_time_; |
Vladimir Levin | 48d5100 | 2023-02-27 17:23:27 | [diff] [blame] | 243 | } |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 244 | |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 245 | // For preview activation, there is no way to activate the previewed page |
| 246 | // other than with a user action, or testing only methods. |
Hiroki Nakagawa | ab53cd2 | 2022-04-13 19:18:02 | [diff] [blame] | 247 | params->was_user_activated = |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 248 | (main_document_->frame_tree_node() |
| 249 | ->has_received_user_gesture_before_nav() || |
| 250 | type == ActivationType::kPreview) |
Hiroki Nakagawa | ab53cd2 | 2022-04-13 19:18:02 | [diff] [blame] | 251 | ? blink::mojom::WasActivatedOption::kYes |
| 252 | : blink::mojom::WasActivatedOption::kNo; |
Hiroki Nakagawa | ab53cd2 | 2022-04-13 19:18:02 | [diff] [blame] | 253 | rvh->ActivatePrerenderedPage(std::move(params), barrier); |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | // Prepare each RenderFrameHostImpl in this Page for activation. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 257 | main_document_->ForEachRenderFrameHostIncludingSpeculative( |
Kevin McNee | 4d35f5a | 2024-07-09 16:39:38 | [diff] [blame] | 258 | [](RenderFrameHostImpl* rfh) { |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 259 | rfh->RendererWillActivateForPrerenderingOrPreview(); |
Daniel Cheng | 982f2b2 | 2022-08-25 23:46:16 | [diff] [blame] | 260 | }); |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 261 | } |
| 262 | |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 263 | void PageImpl::MaybeDispatchLoadEventsOnPrerenderActivation() { |
| 264 | DCHECK(IsPrimary()); |
| 265 | |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 266 | // Dispatch LoadProgressChanged notification on activation with the |
| 267 | // prerender last load progress value if the value is not equal to |
| 268 | // blink::kFinalLoadProgress, whose notification is dispatched during call |
| 269 | // to DidStopLoading. |
| 270 | if (load_progress() != blink::kFinalLoadProgress) |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 271 | main_document_->DidChangeLoadProgress(load_progress()); |
Sreeja Kamishetty | 0be3b1b | 2021-08-12 17:04:15 | [diff] [blame] | 272 | |
Sreeja Kamishetty | 4978330 | 2022-01-28 17:52:25 | [diff] [blame] | 273 | // Dispatch PrimaryMainDocumentElementAvailable before dispatching following |
| 274 | // load complete events. |
| 275 | if (is_main_document_element_available()) |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 276 | main_document_->MainDocumentElementAvailable(uses_temporary_zoom_level()); |
Sreeja Kamishetty | cd556091 | 2021-11-22 11:54:53 | [diff] [blame] | 277 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 278 | main_document_->ForEachRenderFrameHost( |
Daniel Cheng | 982f2b2 | 2022-08-25 23:46:16 | [diff] [blame] | 279 | &RenderFrameHostImpl::MaybeDispatchDOMContentLoadedOnPrerenderActivation); |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 280 | |
| 281 | if (is_on_load_completed_in_main_document()) |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 282 | main_document_->DocumentOnLoadCompleted(); |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 283 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 284 | main_document_->ForEachRenderFrameHost( |
Daniel Cheng | 982f2b2 | 2022-08-25 23:46:16 | [diff] [blame] | 285 | &RenderFrameHostImpl::MaybeDispatchDidFinishLoadOnPrerenderActivation); |
Sreeja Kamishetty | 81fbeefb | 2021-08-12 07:21:41 | [diff] [blame] | 286 | } |
| 287 | |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 288 | void PageImpl::DidActivateAllRenderViewsForPrerenderingOrPreview( |
| 289 | base::OnceCallback<void(base::TimeTicks)> completion_callback) { |
Lingqi Chi | ef8657c | 2023-06-08 08:40:31 | [diff] [blame] | 290 | TRACE_EVENT0("navigation", |
| 291 | "PageImpl::DidActivateAllRenderViewsForPrerendering"); |
| 292 | |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 293 | // Tell each RenderFrameHostImpl in this Page that activation finished. |
Hiroki Nakagawa | f98d009a | 2023-03-16 02:26:10 | [diff] [blame] | 294 | main_document_->ForEachRenderFrameHostIncludingSpeculative( |
| 295 | [this](RenderFrameHostImpl* rfh) { |
| 296 | if (&rfh->GetPage() != this) { |
| 297 | return; |
| 298 | } |
| 299 | rfh->RendererDidActivateForPrerendering(); |
| 300 | }); |
Takashi Toyoshima | 881f4d7 | 2023-11-09 05:07:43 | [diff] [blame] | 301 | CHECK(activation_start_time_.has_value()); |
| 302 | std::move(completion_callback).Run(*activation_start_time_); |
Matt Falkenhagen | f78c219 | 2021-07-24 02:01:43 | [diff] [blame] | 303 | } |
| 304 | |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 305 | RenderFrameHost& PageImpl::GetMainDocumentHelper() { |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 306 | return *main_document_; |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | RenderFrameHostImpl& PageImpl::GetMainDocument() const { |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 310 | return *main_document_; |
Sreeja Kamishetty | 1b5c143 | 2021-06-25 11:32:59 | [diff] [blame] | 311 | } |
| 312 | |
Peilin Wang | ae08e26e | 2024-06-10 20:55:30 | [diff] [blame] | 313 | void PageImpl::UpdateBrowserControlsState( |
| 314 | cc::BrowserControlsState constraints, |
| 315 | cc::BrowserControlsState current, |
| 316 | bool animate, |
| 317 | const std::optional<cc::BrowserControlsOffsetTagsInfo>& offset_tags_info) { |
Alison Gale | 47d1537d | 2024-04-19 21:31:46 | [diff] [blame] | 318 | // TODO(crbug.com/40159655): Asking for the LocalMainFrame interface |
Yoshisato Yanagisawa | d016d62d3 | 2021-10-15 04:38:55 | [diff] [blame] | 319 | // before the RenderFrame is created is racy. |
Nasko Oskov | 8b04f40 | 2022-05-26 23:29:56 | [diff] [blame] | 320 | if (!GetMainDocument().IsRenderFrameLive()) |
Yoshisato Yanagisawa | d016d62d3 | 2021-10-15 04:38:55 | [diff] [blame] | 321 | return; |
| 322 | |
Sky Malice | 3774b00 | 2022-10-21 19:18:40 | [diff] [blame] | 323 | if (base::FeatureList::IsEnabled( |
| 324 | features::kUpdateBrowserControlsWithoutProxy)) { |
| 325 | GetMainDocument().GetRenderWidgetHost()->UpdateBrowserControlsState( |
Peilin Wang | ae08e26e | 2024-06-10 20:55:30 | [diff] [blame] | 326 | constraints, current, animate, offset_tags_info); |
Sky Malice | 3774b00 | 2022-10-21 19:18:40 | [diff] [blame] | 327 | } else { |
| 328 | GetMainDocument().GetAssociatedLocalMainFrame()->UpdateBrowserControlsState( |
Peilin Wang | ae08e26e | 2024-06-10 20:55:30 | [diff] [blame] | 329 | constraints, current, animate, offset_tags_info); |
Sky Malice | 3774b00 | 2022-10-21 19:18:40 | [diff] [blame] | 330 | } |
Yoshisato Yanagisawa | d016d62d3 | 2021-10-15 04:38:55 | [diff] [blame] | 331 | } |
| 332 | |
Kevin McNee | c4325ba | 2022-04-08 23:18:23 | [diff] [blame] | 333 | float PageImpl::GetPageScaleFactor() const { |
| 334 | return GetMainDocument().GetPageScaleFactor(); |
| 335 | } |
| 336 | |
Dominic Farolino | 5c606c1 | 2021-12-18 09:40:14 | [diff] [blame] | 337 | void PageImpl::UpdateEncoding(const std::string& encoding_name) { |
| 338 | if (encoding_name == last_reported_encoding_) |
| 339 | return; |
| 340 | last_reported_encoding_ = encoding_name; |
| 341 | |
| 342 | canonical_encoding_ = |
| 343 | base::GetCanonicalEncodingNameByAliasName(encoding_name); |
| 344 | } |
| 345 | |
Yoshisato Yanagisawa | 8ae0d11 | 2022-04-20 01:49:30 | [diff] [blame] | 346 | void PageImpl::NotifyVirtualKeyboardOverlayRect( |
| 347 | const gfx::Rect& keyboard_rect) { |
Alison Gale | 81f4f2c7 | 2024-04-22 19:33:31 | [diff] [blame] | 348 | // TODO(crbug.com/40222405): send notification to outer frames if |
Yoshisato Yanagisawa | 8ae0d11 | 2022-04-20 01:49:30 | [diff] [blame] | 349 | // needed. |
David Bokan | d6e44055b | 2022-09-21 03:58:08 | [diff] [blame] | 350 | DCHECK_EQ(virtual_keyboard_mode(), |
| 351 | ui::mojom::VirtualKeyboardMode::kOverlaysContent); |
Yoshisato Yanagisawa | 8ae0d11 | 2022-04-20 01:49:30 | [diff] [blame] | 352 | GetMainDocument().GetAssociatedLocalFrame()->NotifyVirtualKeyboardOverlayRect( |
| 353 | keyboard_rect); |
| 354 | } |
| 355 | |
David Bokan | d6e44055b | 2022-09-21 03:58:08 | [diff] [blame] | 356 | void PageImpl::SetVirtualKeyboardMode(ui::mojom::VirtualKeyboardMode mode) { |
| 357 | if (virtual_keyboard_mode_ == mode) |
| 358 | return; |
| 359 | |
| 360 | virtual_keyboard_mode_ = mode; |
| 361 | |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 362 | delegate_->OnVirtualKeyboardModeChanged(*this); |
David Bokan | d6e44055b | 2022-09-21 03:58:08 | [diff] [blame] | 363 | } |
| 364 | |
Yoshisato Yanagisawa | 668f844 | 2022-04-20 04:45:58 | [diff] [blame] | 365 | base::flat_map<std::string, std::string> PageImpl::GetKeyboardLayoutMap() { |
| 366 | return GetMainDocument().GetRenderWidgetHost()->GetKeyboardLayoutMap(); |
| 367 | } |
| 368 | |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 369 | blink::SharedStorageSelectUrlBudgetStatus |
| 370 | PageImpl::CheckAndMaybeDebitSelectURLBudgets(const net::SchemefulSite& site, |
| 371 | double bits_to_charge) { |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 372 | if (!select_url_overall_budget_) { |
| 373 | // The limits are not enabled. |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 374 | return blink::SharedStorageSelectUrlBudgetStatus::kSufficientBudget; |
Camillia Smith Barnes | 9d70e5ae8 | 2023-01-18 19:25:24 | [diff] [blame] | 375 | } |
| 376 | |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 377 | // Return insufficient if there is insufficient overall budget. |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 378 | if (bits_to_charge > select_url_overall_budget_.value()) { |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 379 | GetContentClient()->browser()->LogWebFeatureForCurrentPage( |
| 380 | &GetMainDocument(), |
| 381 | blink::mojom::WebFeature:: |
| 382 | kSharedStorageAPI_SelectURLOverallPageloadBudgetInsufficient); |
| 383 | return blink::SharedStorageSelectUrlBudgetStatus:: |
| 384 | kInsufficientOverallPageloadBudget; |
Camillia Smith Barnes | 574d4d4 | 2023-01-10 18:57:47 | [diff] [blame] | 385 | } |
| 386 | |
Camillia Smith Barnes | 7455223 | 2023-10-02 18:50:07 | [diff] [blame] | 387 | DCHECK(select_url_max_bits_per_site_); |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 388 | |
Camillia Smith Barnes | 7455223 | 2023-10-02 18:50:07 | [diff] [blame] | 389 | // 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] | 390 | // current bits to charge. |
Camillia Smith Barnes | 7455223 | 2023-10-02 18:50:07 | [diff] [blame] | 391 | if (bits_to_charge > select_url_max_bits_per_site_.value()) { |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 392 | return blink::SharedStorageSelectUrlBudgetStatus:: |
| 393 | kInsufficientSitePageloadBudget; |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 394 | } |
| 395 | |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 396 | // Charge the per-site budget or return insufficient if there is not enough. |
Camillia Smith Barnes | 7455223 | 2023-10-02 18:50:07 | [diff] [blame] | 397 | auto it = select_url_per_site_budget_.find(site); |
| 398 | if (it == select_url_per_site_budget_.end()) { |
| 399 | select_url_per_site_budget_[site] = |
| 400 | select_url_max_bits_per_site_.value() - bits_to_charge; |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 401 | } else if (bits_to_charge > it->second) { |
Camillia Smith Barnes | 7455223 | 2023-10-02 18:50:07 | [diff] [blame] | 402 | // There is insufficient per-site budget remaining. |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 403 | return blink::SharedStorageSelectUrlBudgetStatus:: |
| 404 | kInsufficientSitePageloadBudget; |
Camillia Smith Barnes | 477a311 | 2023-02-28 19:06:30 | [diff] [blame] | 405 | } else { |
| 406 | it->second -= bits_to_charge; |
| 407 | } |
| 408 | |
| 409 | // Charge the overall budget. |
| 410 | select_url_overall_budget_.value() -= bits_to_charge; |
Camillia Smith Barnes | 385a2e9 | 2024-04-16 17:49:40 | [diff] [blame] | 411 | return blink::SharedStorageSelectUrlBudgetStatus::kSufficientBudget; |
Camillia Smith Barnes | 574d4d4 | 2023-01-10 18:57:47 | [diff] [blame] | 412 | } |
| 413 | |
Adithya Srinivasan | a5795b9 | 2023-12-20 22:35:22 | [diff] [blame] | 414 | void PageImpl::TakeLoadingMemoryTracker(NavigationRequest* request) { |
| 415 | CHECK(IsPrimary()); |
| 416 | loading_memory_tracker_ = request->TakePeakGpuMemoryTracker(); |
| 417 | } |
| 418 | |
| 419 | void PageImpl::ResetLoadingMemoryTracker() { |
| 420 | CHECK(IsPrimary()); |
| 421 | if (loading_memory_tracker_) { |
| 422 | loading_memory_tracker_.reset(); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | void PageImpl::CancelLoadingMemoryTracker() { |
| 427 | if (loading_memory_tracker_) { |
| 428 | loading_memory_tracker_->Cancel(); |
| 429 | loading_memory_tracker_.reset(); |
| 430 | } |
| 431 | } |
| 432 | |
Adithya Srinivasan | ec6b3f9 | 2024-01-09 16:31:01 | [diff] [blame] | 433 | void PageImpl::SetLastCommitParams( |
| 434 | mojom::DidCommitProvisionalLoadParamsPtr commit_params) { |
| 435 | CHECK(GetMainDocument().IsOutermostMainFrame()); |
| 436 | last_commit_params_ = std::move(commit_params); |
| 437 | } |
| 438 | |
| 439 | mojom::DidCommitProvisionalLoadParamsPtr PageImpl::TakeLastCommitParams() { |
| 440 | CHECK(GetMainDocument().IsOutermostMainFrame()); |
| 441 | return std::move(last_commit_params_); |
| 442 | } |
| 443 | |
Sreeja Kamishetty | 9e1d0e73 | 2021-05-27 18:20:09 | [diff] [blame] | 444 | } // namespace content |