Closed Bug 83573 Opened 23 years ago Closed 22 years ago

XMLHttpRequest should use load groups

Categories

(Core :: XML, defect, P3)

defect

Tracking

()

RESOLVED FIXED
mozilla1.2alpha

People

(Reporter: hjtoi-bugzilla, Assigned: hjtoi-bugzilla)

References

()

Details

Attachments

(1 file, 2 obsolete files)

We should use the document's load group in XMLHttpRequest so that things will
get cleaned up properly when we go to another page.

If we are called from JS we should be able to get it following the practices in
nsHTMLImageElement.cpp.
Priority: -- → P3
Target Milestone: --- → mozilla1.0
Target Milestone: mozilla1.0 → mozilla0.9.9
Target Milestone: mozilla0.9.9 → mozilla1.0
Target Milestone: mozilla1.0 → mozilla1.0.1
Target Milestone: mozilla1.0.1 → mozilla1.2alpha
Target Milestone: mozilla1.2alpha → Future
Keywords: nsbeta1+
Target Milestone: Future → mozilla1.2alpha
Johnny, you meantioned I can get the loadgroup from JS stack or something if
XMLHttpRequest is used from JS. How do I do that?
Attached patch work-in-process (obsolete) — Splinter Review
This patch seems to work, but I don't like the side effects. 

In IE, the throbber will not spin, and pressing STOP button has no effect. With
this patch, the trobber will spin when XMLHttpRequest is active, and pressing
STOP will stop request. Also, in Mozilla the throbber NEVER stops, even after
succesful request, or after pressing STOP.

Darin, do you have any ideas on how to achieve the functionality that
XMLHttpRequest stops automatically when user leaves page, but will NOT make
throbber active and will NOT respond to STOP button?
URL is a testcase for both IE & Mozilla. There is a 5 second delay on the
server, so you have time to observe behavior, hit stop, leave page etc.
try setting the LOAD_BACKGROUND load flag on the channel being added to the load
group.
LOAD_BACKGROUND should take care of the throbber business, but the STOP button
should still kill off the request if it lives in a load group.  however, iirc
the STOP button will go inactive once the throbber goes inactive.
Attached patch Proposed fix (obsolete) — Splinter Review
Thanks, that did the trick :)
Attachment #95480 - Attachment is obsolete: true
Greg & other users of XMLHttpRequest: once this fix gets checked in, you should
no longer need to call XMLHttpRequest.abort() on the page's onunload handler.
This is a significant change, so it would be great if you could test your
applications as soon as possible after this has been fixed.
Status: NEW → ASSIGNED
Comment on attachment 95485 [details] [diff] [review]
Proposed fix

>+nsresult 
>+nsXMLHttpRequest::GetLoadGroup(nsILoadGroup **aLoadGroup)
>+{
>+  if (!mScriptContext) {
>+    GetCurrentContext(getter_AddRefs(mScriptContext));
>+  }
>+
>+  if (mScriptContext) {
>+    nsCOMPtr<nsIScriptGlobalObject> global;
>+    mScriptContext->GetGlobalObject(getter_AddRefs(global));
>+    nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(global);
>+    if (window) {
>+      nsCOMPtr<nsIDOMDocument> domdoc;
>+      window->GetDocument(getter_AddRefs(domdoc));
>+      nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
>+      if (doc) {
>+        doc->GetDocumentLoadGroup(aLoadGroup);
>+      }
>+    }
>+  }
>+
>+  return NS_OK;
>+}

Could you use an
if (!foo) {
  return NS_OK;
}
...

pattern here instead of

if (foo) {
  ...
}
return NS_OK;

That should avoid the deep nesting. You could even use NS_ENSURE_TRUE on the
two last since thay should never fail.

with that, r=sicking
Attachment #95485 - Flags: review+
oh, and you need to set *aLoadGroup to nsnull at the top of the function in case
the doc->GetDocumentLoadGroup(aLoadGroup) line isn't reached
Attached patch Fix v2Splinter Review
I usually prefer less return points from functions unless the indentation
becomes really deep, so I did not change that.

I did add the nulling out of out param, good catch!
Attachment #95485 - Attachment is obsolete: true
Comment on attachment 96725 [details] [diff] [review]
Fix v2

sr=bzbarsky
Attachment #96725 - Flags: superreview+
Checked in.
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
QA Contact: petersen → rakeshmishra
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: