outparamdel nsIDocShell::GetPresShell()

RESOLVED FIXED in mozilla20

Status

()

defect
RESOLVED FIXED
7 years ago
7 years ago

People

(Reporter: tbsaunde, Assigned: tbsaunde)

Tracking

unspecified
mozilla20
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

basically nobody checks the return value anyway, and even when they do it only ever returns NS_OK.
Comment on attachment 696499 [details] [diff] [review]
outparamdel nsIDocShell::GetPresShell()


>   static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer)
>   {
>     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
>-    nsCOMPtr<nsIPresShell> presShell;
>-    docShell->GetPresShell(getter_AddRefs(presShell));
>-    return GetAccService()->GetDocAccessible(presShell);
>+    return GetAccService()->GetDocAccessible(docShell->GetPresShell());
I assume GetDocAccessible doesn't expect caller to keep presshell alive.


>@@ -189,18 +189,17 @@ nsAccessibilityService::GetRootDocumentAccessible(nsIPresShell* aPresShell,
>   if (documentNode) {
>     nsCOMPtr<nsISupports> container = documentNode->GetContainer();
>     nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(container));
>     if (treeItem) {
>       nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
>       treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
>       if (treeItem != rootTreeItem) {
>         nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(rootTreeItem));
>-        nsCOMPtr<nsIPresShell> presShell;
>-        docShell->GetPresShell(getter_AddRefs(presShell));
>+        nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
>         documentNode = presShell->GetDocument();
I don't see reason for nsCOMPtr here.

> nsDocShell::ScrollToAnchor(nsACString & aCurHash, nsACString & aNewHash,
>                            uint32_t aLoadType)
> {
>     if (!mCurrentURI) {
>         return NS_OK;
>     }
> 
>-    nsCOMPtr<nsIPresShell> shell;
>-    nsresult rv = GetPresShell(getter_AddRefs(shell));
>-    if (NS_FAILED(rv) || !shell) {
>+    nsCOMPtr<nsIPresShell> shell = GetPresShell();
>+    if (!shell) {
>         // If we failed to get the shell, or if there is no shell,
>         // nothing left to do here.
>-        return rv;
>+        return NS_ERROR_FAILURE;
>     }
You change behavior here. Why? I'd just return NS_OK;

+++ b/docshell/base/nsIDocShell.idl
update uuid
Attachment #696499 - Flags: review?(bugs) → review+
(In reply to Olli Pettay [:smaug] from comment #2)
> Comment on attachment 696499 [details] [diff] [review]
> outparamdel nsIDocShell::GetPresShell()
> 
> 
> >   static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer)
> >   {
> >     nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
> >-    nsCOMPtr<nsIPresShell> presShell;
> >-    docShell->GetPresShell(getter_AddRefs(presShell));
> >-    return GetAccService()->GetDocAccessible(presShell);
> >+    return GetAccService()->GetDocAccessible(docShell->GetPresShell());
> I assume GetDocAccessible doesn't expect caller to keep presshell alive.

correct, there's even code slightly higher in the file that assumes that.

> >@@ -189,18 +189,17 @@ nsAccessibilityService::GetRootDocumentAccessible(nsIPresShell* aPresShell,
> >   if (documentNode) {
> >     nsCOMPtr<nsISupports> container = documentNode->GetContainer();
> >     nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(container));
> >     if (treeItem) {
> >       nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
> >       treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
> >       if (treeItem != rootTreeItem) {
> >         nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(rootTreeItem));
> >-        nsCOMPtr<nsIPresShell> presShell;
> >-        docShell->GetPresShell(getter_AddRefs(presShell));
> >+        nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
> >         documentNode = presShell->GetDocument();
> I don't see reason for nsCOMPtr here.

yeah, it can go away, it will anyway when I rebase it on top of bug 822664.

> > nsDocShell::ScrollToAnchor(nsACString & aCurHash, nsACString & aNewHash,
> >                            uint32_t aLoadType)
> > {
> >     if (!mCurrentURI) {
> >         return NS_OK;
> >     }
> > 
> >-    nsCOMPtr<nsIPresShell> shell;
> >-    nsresult rv = GetPresShell(getter_AddRefs(shell));
> >-    if (NS_FAILED(rv) || !shell) {
> >+    nsCOMPtr<nsIPresShell> shell = GetPresShell();
> >+    if (!shell) {
> >         // If we failed to get the shell, or if there is no shell,
> >         // nothing left to do here.
> >-        return rv;
> >+        return NS_ERROR_FAILURE;
> >     }
> You change behavior here. Why? I'd just return NS_OK;

it seemed safer when I was writing it, but I think your right, callers had to expect NS_OK being returned here before so safer to stay with that.  I'll change it to NS_OK.

> +++ b/docshell/base/nsIDocShell.idl
> update uuid

ugh how did I forget that
https://hg.mozilla.org/mozilla-central/rev/ba035df3292b
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla20
You need to log in before you can comment on or make changes to this bug.