diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 760d7a72d29f..26372a5e11e1 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -6162,6 +6162,35 @@ nsDocShell::ForceRefreshURIFromTimer(nsIURI * aURI, return ForceRefreshURI(aURI, aDelay, aMetaRefresh); } +bool +nsDocShell::DoAppRedirectIfNeeded(nsIURI * aURI, + nsIDocShellLoadInfo * aLoadInfo, + bool aFirstParty) +{ + uint32_t appId; + nsresult rv = GetAppId(&appId); + if (NS_FAILED(rv)) { + return false; + } + + if (appId != nsIScriptSecurityManager::NO_APP_ID && + appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) { + nsCOMPtr appsService = + do_GetService(APPS_SERVICE_CONTRACTID); + NS_ASSERTION(appsService, "No AppsService available"); + nsCOMPtr redirect; + rv = appsService->GetRedirect(appId, aURI, getter_AddRefs(redirect)); + if (NS_SUCCEEDED(rv) && redirect) { + rv = LoadURI(redirect, aLoadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, aFirstParty); + if (NS_SUCCEEDED(rv)) { + return true; + } + } + } + + return false; +} + NS_IMETHODIMP nsDocShell::ForceRefreshURI(nsIURI * aURI, int32_t aDelay, @@ -6215,6 +6244,10 @@ nsDocShell::ForceRefreshURI(nsIURI * aURI, loadInfo->SetLoadType(nsIDocShellLoadInfo::loadRefresh); } + if (DoAppRedirectIfNeeded(aURI, loadInfo, true)) { + return NS_OK; + } + /* * LoadURI(...) will cancel all refresh timers... This causes the * Timer and its refreshData instance to be released... @@ -6848,29 +6881,10 @@ nsDocShell::OnRedirectStateChange(nsIChannel* aOldChannel, return; } - // Check if we have a redirect registered for this url. - uint32_t appId; - nsresult rv = GetAppId(&appId); - if (NS_FAILED(rv)) { + if (DoAppRedirectIfNeeded(newURI, nullptr, false)) { return; } - if (appId != nsIScriptSecurityManager::NO_APP_ID && - appId != nsIScriptSecurityManager::UNKNOWN_APP_ID) { - nsCOMPtr appsService = - do_GetService(APPS_SERVICE_CONTRACTID); - NS_ASSERTION(appsService, "No AppsService available"); - nsCOMPtr redirect; - rv = appsService->GetRedirect(appId, newURI, getter_AddRefs(redirect)); - if (NS_SUCCEEDED(rv) && redirect) { - aNewChannel->Cancel(NS_BINDING_ABORTED); - rv = LoadURI(redirect, nullptr, 0, false); - if (NS_SUCCEEDED(rv)) { - return; - } - } - } - // Below a URI visit is saved (see AddURIVisit method doc). // The visit chain looks something like: // ... diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index d2116282a22d..342c1f44065a 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -640,6 +640,12 @@ protected: // Convenience method for getting our parent docshell. Can return null already_AddRefed GetParentDocshell(); + + // Check if we have an app redirect registered for the URI and redirect if + // needed. Returns true if a redirect happened, false otherwise. + bool DoAppRedirectIfNeeded(nsIURI * aURI, + nsIDocShellLoadInfo * aLoadInfo, + bool aFirstParty); protected: nsresult GetCurScrollPos(int32_t scrollOrientation, int32_t * curPos); nsresult SetCurScrollPosEx(int32_t curHorizontalPos, int32_t curVerticalPos);