Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add browser side of anchor element interaction preloading feature.
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
Showing
20 changed files
with
390 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
chrome/browser/navigation_predictor/anchor_element_preloader.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
28
chrome/browser/navigation_predictor/anchor_element_preloader.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
third_party/blink/public/mojom/loader/anchor_element_interaction_host.mojom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
third_party/blink/renderer/core/frame/anchor_element_interaction_tracker.cc
This file was deleted.
Oops, something went wrong.
126 changes: 0 additions & 126 deletions
126
third_party/blink/renderer/core/frame/anchor_element_listener_test.cc
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.