diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 45ca8e37b040..85b42ba6156c 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -978,37 +978,50 @@ GlobalWindowImpl::SetLocation(jsval aLocation) NS_IMETHODIMP GlobalWindowImpl::GetTitle(nsAWritableString& aTitle) { - aTitle.Truncate(); - if (mDocShell) { + aTitle.Truncate(); + + nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); + if (docShellAsItem) { // See if we're a chrome shell. PRInt32 type; - nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); docShellAsItem->GetItemType(&type); if(type == nsIDocShellTreeItem::typeChrome) { - nsCOMPtr docShellAsWin(do_QueryInterface(mDocShell)); - if(docShellAsWin) { - nsXPIDLString title; - docShellAsWin->GetTitle(getter_Copies(title)); - - aTitle.Assign(title); + nsCOMPtr treeOwner; + GetTreeOwner(getter_AddRefs(treeOwner)); + if (treeOwner) { + nsCOMPtr primaryContent; + treeOwner->GetPrimaryContentShell(getter_AddRefs(primaryContent)); + nsCOMPtr docShellAsWin(do_QueryInterface(primaryContent)); + if (docShellAsWin) { + nsXPIDLString title; + docShellAsWin->GetTitle(getter_Copies(title)); + aTitle.Assign(title); + } } } } + return NS_OK; } NS_IMETHODIMP GlobalWindowImpl::SetTitle(const nsAReadableString& aTitle) { - if(mDocShell) { + nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); + if(docShellAsItem) { // See if we're a chrome shell. PRInt32 type; - nsCOMPtr docShellAsItem(do_QueryInterface(mDocShell)); docShellAsItem->GetItemType(&type); if(type == nsIDocShellTreeItem::typeChrome) { - nsCOMPtr docShellAsWin(do_QueryInterface(mDocShell)); - if(docShellAsWin) { - docShellAsWin->SetTitle(nsPromiseFlatString(aTitle)); + nsCOMPtr treeOwner; + GetTreeOwner(getter_AddRefs(treeOwner)); + if (treeOwner) { + nsCOMPtr primaryContent; + treeOwner->GetPrimaryContentShell(getter_AddRefs(primaryContent)); + nsCOMPtr docShellAsWin(do_QueryInterface(primaryContent)); + if (docShellAsWin) { + docShellAsWin->SetTitle(nsPromiseFlatString(aTitle)); + } } } }