Virtual URLs

716 views
Skip to first unread message

Ryan Tarpine

unread,
Jan 26, 2024, 3:00:35 PM1/26/24
to navigat...@chromium.org
Hi Nav folks,

I noticed that it's possible for RenderFrameHost::GetLastCommittedURL() to return a different value from WebContents::GetLastCommittedURL() (even when the RenderFrameHost is from WebContents::GetPrimaryMainFrame())

In the particular case I discovered, when first opening a new tab, RFH is returning chrome://new-tab-page/ while WC returns chrome://newtab/

Digging around, it seems that new tabs initially navigate to chrome://new-tab-page/ and RFH reports that, but thanks to virtual URLs WC rewrites and reports it as chrome://newtab/

Is it intentional for these to differ?

The new tab page is a very special case, with a non-http scheme, but could this happen in more general cases? I'm interested because DIPS (go/dips) uses GetLastCommittedURL() for a number of things, and now I'm wondering which I should use.

Since I'm interested mainly in which domain accessed storage (e.g. cookies), if the URL domain could vary, I think I want the non-virtual one, assuming that's the one that actually accessed the storage. Is that correct? Should I call GetPrimaryMainFrame()->GetLastCommittedURL() instead of GetLastCommittedURL()?

Thanks,
Ryan

Charlie Reis

unread,
Jan 31, 2024, 5:42:30 PM1/31/24
to Ryan Tarpine, navigat...@chromium.org
Thanks for checking.  They differ for legacy reasons-- we would much rather return the actual last committed URL from both RenderFrameHost::GetLastCommittedURL() and WebContents::GetLastCommittedURL(), but the latter started out using virtual URLs and there are hundreds of callers that would need to be investigated if we changed the behavior.  (It's unclear which of those depend on seeing the virtual URL.)  This would be a viable code health project, but it hasn't been as high priority as other efforts (including the very similar https://crbug.com/237908).

I'm not an expert on virtual URLs, but I know they come up in a few more cases than the NTP, such as view-source.  See https://chromium.googlesource.com/chromium/src/+/main/docs/navigation_concepts.md#Virtual-URLs and BrowserUrlHandler.

My advice in your case would be to use GetPrimaryMainFrame()->GetLastCommittedURL() if you can.

Charlie


--
You received this message because you are subscribed to the Google Groups "navigation-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to navigation-de...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/navigation-dev/CAFdQzkRnNRLeT-NjWU-DOigzOSuLwEud9HdCMKWFRFRhRMb0Jw%40mail.gmail.com.

Ryan Tarpine

unread,
Feb 1, 2024, 11:30:22 AM2/1/24
to Charlie Reis, navigat...@chromium.org
Great, thanks for the explanation!
Reply all
Reply to author
Forward
0 new messages