mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1663757 - Part 4: Track current remote URI on CanonicalBrowsingContext, r=annyG,farre
This URI is intended to reflect the currentURI field on the content nsIDocShell, and is the value used for getters like `window.location.href`. For most documents, this generally matches the Document URI on WindowGlobalParent, it does not match in specific cases such as error pages or when performing a session restore. The field is kept up-to-date by listening to `OnLocationChange` notifications from the content process, and is ignored when the BrowsingContext is loaded in the parent process. Differential Revision: https://phabricator.services.mozilla.com/D105559
This commit is contained in:
parent
1dfe5d5e5b
commit
64fd29f182
@ -70,6 +70,10 @@ CanonicalBrowsingContext::CanonicalBrowsingContext(WindowContext* aParentWindow,
|
||||
// You are only ever allowed to create CanonicalBrowsingContexts in the
|
||||
// parent process.
|
||||
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
||||
|
||||
// The initial URI in a BrowsingContext is always "about:blank".
|
||||
MOZ_ALWAYS_SUCCEEDS(
|
||||
NS_NewURI(getter_AddRefs(mCurrentRemoteURI), "about:blank"));
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -1656,6 +1660,22 @@ void CanonicalBrowsingContext::EndDocumentLoad(bool aForProcessSwitch) {
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsIURI> CanonicalBrowsingContext::GetCurrentURI() const {
|
||||
nsCOMPtr<nsIURI> currentURI;
|
||||
if (nsIDocShell* docShell = GetDocShell()) {
|
||||
MOZ_ALWAYS_SUCCEEDS(
|
||||
nsDocShell::Cast(docShell)->GetCurrentURI(getter_AddRefs(currentURI)));
|
||||
} else {
|
||||
currentURI = mCurrentRemoteURI;
|
||||
}
|
||||
return currentURI.forget();
|
||||
}
|
||||
|
||||
void CanonicalBrowsingContext::SetCurrentRemoteURI(nsIURI* aCurrentRemoteURI) {
|
||||
MOZ_ASSERT(!GetDocShell());
|
||||
mCurrentRemoteURI = aCurrentRemoteURI;
|
||||
}
|
||||
|
||||
void CanonicalBrowsingContext::ResetSHEntryHasUserInteractionCache() {
|
||||
WindowContext* topWc = GetTopWindowContext();
|
||||
if (topWc && !topWc->IsDiscarded()) {
|
||||
|
@ -208,6 +208,10 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
void Reload(uint32_t aReloadFlags);
|
||||
void Stop(uint32_t aStopFlags);
|
||||
|
||||
// Get the publicly exposed current URI loaded in this BrowsingContext.
|
||||
already_AddRefed<nsIURI> GetCurrentURI() const;
|
||||
void SetCurrentRemoteURI(nsIURI* aCurrentRemoteURI);
|
||||
|
||||
BrowserParent* GetBrowserParent() const;
|
||||
|
||||
// Internal method to change which process a BrowsingContext is being loaded
|
||||
@ -360,6 +364,10 @@ class CanonicalBrowsingContext final : public BrowsingContext {
|
||||
// entries are added or replaced.
|
||||
void ResetSHEntryHasUserInteractionCache();
|
||||
|
||||
// The current URI loaded in this BrowsingContext. This value is only set for
|
||||
// BrowsingContexts loaded in content processes.
|
||||
nsCOMPtr<nsIURI> mCurrentRemoteURI;
|
||||
|
||||
// The current remoteness change which is in a pending state.
|
||||
RefPtr<PendingRemotenessChange> mPendingRemotenessChange;
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
interface URI;
|
||||
interface nsIDocShell;
|
||||
interface nsISecureBrowserUI;
|
||||
interface nsIWebProgress;
|
||||
@ -265,6 +266,10 @@ interface CanonicalBrowsingContext : BrowsingContext {
|
||||
readonly attribute MediaController? mediaController;
|
||||
|
||||
void resetScalingZoom();
|
||||
|
||||
// The current URI loaded in this BrowsingContext according to nsDocShell.
|
||||
// This may not match the current window global's document URI in some cases.
|
||||
readonly attribute URI? currentURI;
|
||||
};
|
||||
|
||||
[Exposed=Window, ChromeOnly]
|
||||
|
@ -2686,6 +2686,8 @@ mozilla::ipc::IPCResult BrowserParent::RecvOnLocationChange(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
browsingContext->SetCurrentRemoteURI(aLocation);
|
||||
|
||||
nsCOMPtr<nsIBrowser> browser = GetBrowser();
|
||||
if (!mozilla::SessionHistoryInParent() && browser) {
|
||||
Unused << browser->UpdateWebNavigationForLocationChange(aCanGoBack,
|
||||
|
Loading…
Reference in New Issue
Block a user