Skip to content

Commit

Permalink
Add browser side of anchor element interaction preloading feature.
Browse files Browse the repository at this point in the history
Adds mojo interface along with browser service that will trigger
preconnect on PointerDown events forwarded by the renderer. This
also improves testing in the renderer by intercepting mojo
message.

Full end-to-end browser tests will be added next.

Bug: 1297312
Change-Id: I59ca4fcf6bda7f09b834c3f5f87c7a3b451f65a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3537709
Reviewed-by: Max Curran <curranmax@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: David Bokan <bokan@chromium.org>
Commit-Queue: Jacob Stanley <jacobstanley@google.com>
Cr-Commit-Position: refs/heads/main@{#985601}
  • Loading branch information
Jacob Stanley authored and Chromium LUCI CQ committed Mar 26, 2022
1 parent ae369e7 commit 2978fad
Show file tree
Hide file tree
Showing 20 changed files with 390 additions and 186 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/BUILD.gn
Expand Up @@ -808,6 +808,8 @@ static_library("browser") {
"metrics/variations/chrome_variations_service_client.cc",
"metrics/variations/chrome_variations_service_client.h",
"native_window_notification_source.h",
"navigation_predictor/anchor_element_preloader.cc",
"navigation_predictor/anchor_element_preloader.h",
"navigation_predictor/navigation_predictor.cc",
"navigation_predictor/navigation_predictor.h",
"navigation_predictor/navigation_predictor_features.cc",
Expand Down
8 changes: 8 additions & 0 deletions chrome/browser/chrome_browser_interface_binders.cc
Expand Up @@ -16,6 +16,7 @@
#include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
#include "chrome/browser/media/history/media_history_store.mojom.h"
#include "chrome/browser/media/media_engagement_score_details.mojom.h"
#include "chrome/browser/navigation_predictor/anchor_element_preloader.h"
#include "chrome/browser/navigation_predictor/navigation_predictor.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/predictors/network_hints_handler_impl.h"
Expand Down Expand Up @@ -78,6 +79,7 @@
#include "services/image_annotation/public/mojom/image_annotation.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/credentialmanagement/credential_manager.mojom.h"
#include "third_party/blink/public/mojom/loader/anchor_element_interaction_host.mojom.h"
#include "third_party/blink/public/mojom/loader/navigation_predictor.mojom.h"
#include "third_party/blink/public/mojom/payments/payment_credential.mojom.h"
#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
Expand Down Expand Up @@ -629,6 +631,12 @@ void PopulateChromeFrameBinders(
map->Add<blink::mojom::AnchorElementMetricsHost>(
base::BindRepeating(&NavigationPredictor::Create));

if (base::FeatureList::IsEnabled(
blink::features::kAnchorElementInteraction)) {
map->Add<blink::mojom::AnchorElementInteractionHost>(
base::BindRepeating(&AnchorElementPreloader::Create));
}

map->Add<dom_distiller::mojom::DistillabilityService>(
base::BindRepeating(&BindDistillabilityService));

Expand Down
39 changes: 39 additions & 0 deletions chrome/browser/navigation_predictor/anchor_element_preloader.cc
@@ -0,0 +1,39 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/navigation_predictor/anchor_element_preloader.h"
#include "chrome/browser/predictors/loading_predictor.h"
#include "chrome/browser/predictors/loading_predictor_factory.h"
#include "content/public/browser/browser_context.h"

AnchorElementPreloader::AnchorElementPreloader(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::AnchorElementInteractionHost> receiver)
: content::DocumentService<blink::mojom::AnchorElementInteractionHost>(
render_frame_host,
std::move(receiver)) {}

void AnchorElementPreloader::Create(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::AnchorElementInteractionHost>
receiver) {
// The object is bound to the lifetime of the |render_frame_host| and the mojo
// connection. See DocumentService for details.
new AnchorElementPreloader(render_frame_host, std::move(receiver));
}

void AnchorElementPreloader::OnPointerDown(const GURL& target) {
auto* loading_predictor = predictors::LoadingPredictorFactory::GetForProfile(
Profile::FromBrowserContext(render_frame_host()->GetBrowserContext()));

if (!loading_predictor) {
return;
}

net::SchemefulSite schemeful_site(target);
net::NetworkIsolationKey network_isolation_key(schemeful_site,
schemeful_site);
loading_predictor->PreconnectURLIfAllowed(target, /*allow_credentials=*/true,
network_isolation_key);
}
28 changes: 28 additions & 0 deletions chrome/browser/navigation_predictor/anchor_element_preloader.h
@@ -0,0 +1,28 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_NAVIGATION_PREDICTOR_ANCHOR_ELEMENT_PRELOADER_H_
#define CHROME_BROWSER_NAVIGATION_PREDICTOR_ANCHOR_ELEMENT_PRELOADER_H_

#include "content/public/browser/document_service.h"
#include "third_party/blink/public/mojom/loader/anchor_element_interaction_host.mojom.h"

class AnchorElementPreloader
: content::DocumentService<blink::mojom::AnchorElementInteractionHost> {
public:
static void Create(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::AnchorElementInteractionHost>
receiver);

private:
AnchorElementPreloader(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::AnchorElementInteractionHost>
receiver);
// Preconnects to the given URL `target`.
void OnPointerDown(const GURL& target) override;
};

#endif // CHROME_BROWSER_NAVIGATION_PREDICTOR_ANCHOR_ELEMENT_PRELOADER_H_
1 change: 1 addition & 0 deletions third_party/blink/public/mojom/BUILD.gn
Expand Up @@ -102,6 +102,7 @@ mojom("mojom_platform") {
"keyboard_lock/keyboard_lock.mojom",
"leak_detector/leak_detector.mojom",
"link_to_text/link_to_text.mojom",
"loader/anchor_element_interaction_host.mojom",
"loader/code_cache.mojom",
"loader/content_security_notifier.mojom",
"loader/fetch_client_settings_object.mojom",
Expand Down
@@ -0,0 +1,16 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module blink.mojom;

import "url/mojom/url.mojom";

// Interface for sending the URL from the renderer side to browser process.
interface AnchorElementInteractionHost {
// On PointerDown events for anchor elements that are part
// of the HTTP family, the renderer calls OnPointerDown to pass
// the URL to the browser process. In the browser process, the URL gets
// preresolved and preconnected.
OnPointerDown(url.mojom.Url target);
};
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/BUILD.gn
Expand Up @@ -1282,7 +1282,6 @@ source_set("unit_tests") {
"fragment_directive/text_fragment_selector_generator_test.cc",
"fragment_directive/text_fragment_selector_test.cc",
"frame/ad_tracker_test.cc",
"frame/anchor_element_listener_test.cc",
"frame/attribution_response_parsing_test.cc",
"frame/attribution_src_loader_test.cc",
"frame/browser_controls_test.cc",
Expand Down Expand Up @@ -1346,6 +1345,7 @@ source_set("unit_tests") {
"inspector/protocol_unittest.cc",
"intersection_observer/intersection_observer_test.cc",
"loader/alternate_signed_exchange_resource_info_test.cc",
"loader/anchor_element_interaction_test.cc",
"loader/base_fetch_context_test.cc",
"loader/cookie_jar_unittest.cc",
"loader/document_load_timing_test.cc",
Expand Down
7 changes: 7 additions & 0 deletions third_party/blink/renderer/core/dom/document.cc
Expand Up @@ -249,6 +249,7 @@
#include "third_party/blink/renderer/core/layout/layout_object_factory.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/text_autosizer.h"
#include "third_party/blink/renderer/core/loader/anchor_element_interaction_tracker.h"
#include "third_party/blink/renderer/core/loader/cookie_jar.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/frame_fetch_context.h"
Expand Down Expand Up @@ -2723,6 +2724,11 @@ void Document::Initialize() {
autosizer->UpdatePageInfo();

GetFrame()->DidAttachDocument();
if (AnchorElementInteractionTracker::IsFeatureEnabled() &&
!GetFrame()->IsProvisional()) {
anchor_element_interaction_tracker_ =
MakeGarbageCollected<AnchorElementInteractionTracker>(*this);
}
lifecycle_.AdvanceTo(DocumentLifecycle::kStyleClean);

if (View())
Expand Down Expand Up @@ -7943,6 +7949,7 @@ void Document::Trace(Visitor* visitor) const {
visitor->Trace(meta_theme_color_elements_);
visitor->Trace(unassociated_listed_elements_);
visitor->Trace(intrinsic_size_observer_);
visitor->Trace(anchor_element_interaction_tracker_);
Supplementable<Document>::Trace(visitor);
TreeScope::Trace(visitor);
ContainerNode::Trace(visitor);
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/core/dom/document.h
Expand Up @@ -110,6 +110,7 @@ enum class CSPDisposition : int32_t;

namespace blink {

class AnchorElementInteractionTracker;
class AnimationClock;
class AXContext;
class AXObjectCache;
Expand Down Expand Up @@ -2119,6 +2120,7 @@ class CORE_EXPORT Document : public ContainerNode,
Member<Element> document_element_;
UserActionElementSet user_action_elements_;
Member<RootScrollerController> root_scroller_controller_;
Member<AnchorElementInteractionTracker> anchor_element_interaction_tracker_;

double overscroll_accumulated_delta_x_ = 0;
double overscroll_accumulated_delta_y_ = 0;
Expand Down

This file was deleted.

126 changes: 0 additions & 126 deletions third_party/blink/renderer/core/frame/anchor_element_listener_test.cc

This file was deleted.

4 changes: 0 additions & 4 deletions third_party/blink/renderer/core/frame/build.gni
Expand Up @@ -5,10 +5,6 @@
blink_core_sources_frame = [
"ad_tracker.cc",
"ad_tracker.h",
"anchor_element_listener.cc",
"anchor_element_listener.h",
"anchor_element_interaction_tracker.cc",
"anchor_element_interaction_tracker.h",
"attribution_reporting.cc",
"attribution_reporting.h",
"attribution_response_parsing.cc",
Expand Down
6 changes: 0 additions & 6 deletions third_party/blink/renderer/core/frame/local_frame.cc
Expand Up @@ -109,7 +109,6 @@
#include "third_party/blink/renderer/core/fileapi/public_url_manager.h"
#include "third_party/blink/renderer/core/fragment_directive/text_fragment_handler.h"
#include "third_party/blink/renderer/core/frame/ad_tracker.h"
#include "third_party/blink/renderer/core/frame/anchor_element_interaction_tracker.h"
#include "third_party/blink/renderer/core/frame/attribution_src_loader.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/event_handler_registry.h"
Expand Down Expand Up @@ -398,7 +397,6 @@ void LocalFrame::Trace(Visitor* visitor) const {
visitor->Trace(console_);
visitor->Trace(smooth_scroll_sequencer_);
visitor->Trace(content_capture_manager_);
visitor->Trace(anchor_element_interaction_tracker_);
visitor->Trace(system_clipboard_);
visitor->Trace(virtual_keyboard_overlay_changed_observers_);
visitor->Trace(pause_handle_receivers_);
Expand Down Expand Up @@ -711,10 +709,6 @@ void LocalFrame::DidAttachDocument() {
// appendChild()), the drag source will detach and stop firing drag events
// even after the frame reattaches.
GetEventHandler().Clear();
if (AnchorElementInteractionTracker::IsFeatureEnabled() && !IsProvisional()) {
anchor_element_interaction_tracker_ =
MakeGarbageCollected<AnchorElementInteractionTracker>(*document);
}
Selection().DidAttachDocument(document);
notified_color_scheme_ = false;
}
Expand Down

0 comments on commit 2978fad

Please sign in to comment.