Bug 1373604 - Only try to switch focus to targetDocShell if the load succeeds. r=smaug

MozReview-Commit-ID: H1TsRcbagg4
This commit is contained in:
Samael Wang 2017-06-21 14:54:15 +08:00
Родитель 35588e8dd0
Коммит eaa22c46f8
1 изменённых файлов: 12 добавлений и 10 удалений

Просмотреть файл

@ -10179,16 +10179,18 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// do nothing.
}
// Switch to target tab if we're currently focused window.
// Take loadDivertedInBackground into account so the behavior would be
// the same as how the tab first opened.
bool isTargetActive = false;
targetDocShell->GetIsActive(&isTargetActive);
if (mIsActive && !isTargetActive &&
!Preferences::GetBool("browser.tabs.loadDivertedInBackground", false)) {
if (NS_FAILED(nsContentUtils::DispatchFocusChromeEvent(
targetDocShell->GetWindow()))) {
return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
// Switch to target tab if we're currently focused window.
// Take loadDivertedInBackground into account so the behavior would be
// the same as how the tab first opened.
bool isTargetActive = false;
targetDocShell->GetIsActive(&isTargetActive);
nsCOMPtr<nsPIDOMWindowOuter> domWin = targetDocShell->GetWindow();
if (mIsActive && !isTargetActive && domWin &&
!Preferences::GetBool("browser.tabs.loadDivertedInBackground", false)) {
if (NS_FAILED(nsContentUtils::DispatchFocusChromeEvent(domWin))) {
return NS_ERROR_FAILURE;
}
}
}
}