tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 521ac98b00ebf290745ed9c871d4d7ebb3694e5c
parent 541bfcd3ab81d09803fc465938efa59c864c1e66
Author: Valentin Gosu <valentin.gosu@gmail.com>
Date:   Tue, 11 Nov 2025 11:54:35 +0000

Bug 1999266 - Extract PREDICT_LINK from predictor r=necko-reviewers,jesup

Differential Revision: https://phabricator.services.mozilla.com/D271984

Diffstat:
Mdocshell/base/nsDocShell.cpp | 17+++++++++++++++--
Mnetwerk/base/Predictor.cpp | 38--------------------------------------
Mnetwerk/base/Predictor.h | 9---------
Mnetwerk/base/nsINetworkPredictor.idl | 7-------
Mnetwerk/test/unit/test_predictor.js | 23-----------------------
5 files changed, 15 insertions(+), 79 deletions(-)

diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp @@ -13751,8 +13751,21 @@ nsresult nsDocShell::OnOverLink(nsIContent* aContent, nsIURI* aURI, NS_ConvertUTF8toUTF16 uStr(spec); - PredictorPredict(aURI, mCurrentURI, nsINetworkPredictor::PREDICT_LINK, - aContent->NodePrincipal()->OriginAttributesRef(), nullptr); + // The speculative connect used to go through the predictor, but we don't + // need all that just to initiate a speculative connect. + if ((StaticPrefs::network_predictor_enable_hover_on_ssl() && + mCurrentURI->SchemeIs("https")) || + mCurrentURI->SchemeIs("http")) { + if (nsCOMPtr<nsISpeculativeConnect> specService = + mozilla::components::IO::Service()) { + // This would be a navigation, so if this is cross origin the speculative + // connection needs to have the origin of the URL not the current page. + nsCOMPtr<nsIPrincipal> principal = BasePrincipal::CreateContentPrincipal( + aURI, aContent->NodePrincipal()->OriginAttributesRef()); + + specService->SpeculativeConnect(aURI, principal, nullptr, false); + } + } rv = browserChrome->SetLinkStatus(uStr); return rv; diff --git a/netwerk/base/Predictor.cpp b/netwerk/base/Predictor.cpp @@ -540,15 +540,6 @@ Predictor::PredictNative(nsIURI* targetURI, nsIURI* sourceURI, nsCOMPtr<nsIURI> uriKey = targetURI; nsCOMPtr<nsIURI> originKey; switch (reason) { - case nsINetworkPredictor::PREDICT_LINK: - if (!targetURI || !sourceURI) { - PREDICTOR_LOG((" link invalid URI state")); - return NS_ERROR_INVALID_ARG; - } - // Link hover is a special case where we can predict without hitting the - // db, so let's go ahead and fire off that prediction here. - PredictForLink(targetURI, sourceURI, originAttributes, verifier); - return NS_OK; case nsINetworkPredictor::PREDICT_LOAD: if (!targetURI || sourceURI) { PREDICTOR_LOG((" load invalid URI state")); @@ -661,35 +652,6 @@ bool Predictor::PredictInternal(PredictorPredictReason reason, return rv; } -void Predictor::PredictForLink(nsIURI* targetURI, nsIURI* sourceURI, - const OriginAttributes& originAttributes, - nsINetworkPredictorVerifier* verifier) { - MOZ_ASSERT(NS_IsMainThread()); - - PREDICTOR_LOG(("Predictor::PredictForLink")); - if (!mSpeculativeService) { - PREDICTOR_LOG((" missing speculative service")); - return; - } - - if (!StaticPrefs::network_predictor_enable_hover_on_ssl()) { - if (sourceURI->SchemeIs("https")) { - // We don't want to predict from an HTTPS page, to avoid info leakage - PREDICTOR_LOG((" Not predicting for link hover - on an SSL page")); - return; - } - } - - nsCOMPtr<nsIPrincipal> principal = - BasePrincipal::CreateContentPrincipal(targetURI, originAttributes); - - mSpeculativeService->SpeculativeConnect(targetURI, principal, nullptr, false); - if (verifier) { - PREDICTOR_LOG((" sending verification")); - verifier->OnPredictPreconnect(targetURI); - } -} - // This is the driver for prediction based on a new pageload. static const uint8_t MAX_PAGELOAD_DEPTH = 10; bool Predictor::PredictForPageload(nsICacheEntry* entry, nsIURI* targetURI, diff --git a/netwerk/base/Predictor.h b/netwerk/base/Predictor.h @@ -243,15 +243,6 @@ class Predictor final : public nsINetworkPredictor, nsINetworkPredictorVerifier* verifier, uint8_t stackCount); - // Used when predicting because the user's mouse hovered over a link - // * targetURI - the URI target of the link - // * sourceURI - the URI of the page on which the link appears - // * originAttributes - the originAttributes for this prediction - // * verifier - used for testing to verify the expected predictions happen - void PredictForLink(nsIURI* targetURI, nsIURI* sourceURI, - const OriginAttributes& originAttributes, - nsINetworkPredictorVerifier* verifier); - // Used when predicting because a page is being loaded (which may include // being the target of a redirect). All arguments are the same as for // PredictInternal. Returns true if any predictions were queued up. diff --git a/netwerk/base/nsINetworkPredictor.idl b/netwerk/base/nsINetworkPredictor.idl @@ -35,16 +35,12 @@ interface nsINetworkPredictor : nsISupports /** * Prediction reasons * - * PREDICT_LINK - we are being asked to take predictive action because - * the user is hovering over a link. - * * PREDICT_LOAD - we are being asked to take predictive action because * the user has initiated a pageload. * * PREDICT_STARTUP - we are being asked to take predictive action * because the browser is starting up. */ - const PredictorPredictReason PREDICT_LINK = 0; const PredictorPredictReason PREDICT_LOAD = 1; const PredictorPredictReason PREDICT_STARTUP = 2; @@ -62,9 +58,6 @@ interface nsINetworkPredictor : nsISupports * example). * @param reason - The reason we are being asked to take actions. Can be * any of the PREDICT_* values above. - * In the case of PREDICT_LINK, targetURI should be the URI of the link - * that is being hovered over, and sourceURI should be the URI of the page - * on which the link appears. * In the case of PREDICT_LOAD, targetURI should be the URI of the page that * is being loaded and sourceURI should be null. * In the case of PREDICT_STARTUP, both targetURI and sourceURI should be diff --git a/netwerk/test/unit/test_predictor.js b/netwerk/test/unit/test_predictor.js @@ -184,28 +184,6 @@ function open_and_continue(uris, continueCallback) { } } -function test_link_hover() { - if (!running_single_process && !is_child_process()) { - // This one we can just proxy to the child and be done with, no extra setup - // is necessary. - sendCommand("test_link_hover();"); - return; - } - - var uri = newURI("http://localhost:4444/foo/bar"); - var referrer = newURI("http://localhost:4444/foo"); - var preconns = ["http://localhost:4444"]; - - var verifier = new Verifier("hover", [], preconns, []); - predictor.predict( - uri, - referrer, - predictor.PREDICT_LINK, - origin_attributes, - verifier - ); -} - const pageload_toplevel = newURI("http://localhost:4444/index.html"); function continue_test_pageload() { @@ -765,7 +743,6 @@ function cleanup() { var tests = [ // This must ALWAYS come first, to ensure a clean slate reset_predictor, - test_link_hover, test_pageload, // TODO: These are disabled until the features are re-written //test_redirect,