Fix for bug 743666 (Add back deprecated XHR.onuploadprogress). r=bzbarsky, a=lsblakk
authorPeter Van der Beken <peterv@propagandism.org>
Tue, 05 Jun 2012 15:00:45 -0400
changeset 98042 fcf10dd798a1fdb23990da82c0ffdf75d5d6626b
parent 98041 002be3d4ce41a97d7368c7ca5801cb9c49df7b97
child 98043 809a7e55a042e76e075083764edb15b59c21264a
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky, lsblakk
bugs743666
milestone15.0a2
Fix for bug 743666 (Add back deprecated XHR.onuploadprogress). r=bzbarsky, a=lsblakk
content/base/public/nsDeprecatedOperationList.h
content/base/src/nsXMLHttpRequest.h
content/base/test/Makefile.in
content/base/test/test_XHR_onuploadprogress.html
dom/bindings/Bindings.conf
dom/locales/en-US/chrome/dom/dom.properties
dom/webidl/XMLHttpRequest.webidl
dom/workers/XMLHttpRequest.h
--- a/content/base/public/nsDeprecatedOperationList.h
+++ b/content/base/public/nsDeprecatedOperationList.h
@@ -43,8 +43,9 @@ DEPRECATED_OPERATION(Position)
 DEPRECATED_OPERATION(TotalSize)
 DEPRECATED_OPERATION(InputEncoding)
 DEPRECATED_OPERATION(MozBeforePaint)
 DEPRECATED_OPERATION(MozBlobBuilder)
 DEPRECATED_OPERATION(DOMExceptionCode)
 DEPRECATED_OPERATION(NoExposedProps)
 DEPRECATED_OPERATION(MutationEvent)
 DEPRECATED_OPERATION(MozSlice)
+DEPRECATED_OPERATION(Onuploadprogress)
--- a/content/base/src/nsXMLHttpRequest.h
+++ b/content/base/src/nsXMLHttpRequest.h
@@ -241,16 +241,34 @@ public:
   NS_FORWARD_NSIDOMEVENTTARGET(nsXHREventTarget::)
 
 #ifdef DEBUG
   void StaticAssertions();
 #endif
 
   // event handler
   IMPL_EVENT_HANDLER(readystatechange, Readystatechange)
+  JSObject* GetOnuploadprogress(JSContext* /* unused */)
+  {
+    nsIDocument* doc = GetOwner() ? GetOwner()->GetExtantDoc() : NULL;
+    if (doc) {
+      doc->WarnOnceAbout(nsIDocument::eOnuploadprogress);
+    }
+    return GetListenerAsJSObject(mOnUploadProgressListener);
+  }
+  void SetOnuploadprogress(JSContext* aCx, JSObject* aCallback,
+                           ErrorResult& aRv)
+  {
+    nsIDocument* doc = GetOwner() ? GetOwner()->GetExtantDoc() : NULL;
+    if (doc) {
+      doc->WarnOnceAbout(nsIDocument::eOnuploadprogress);
+    }
+    aRv = SetJSObjectListener(aCx, NS_LITERAL_STRING("uploadprogress"),
+                              mOnUploadProgressListener, aCallback);
+  }
 
   // states
   uint16_t GetReadyState();
 
   // request
   void Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync,
             const mozilla::dom::Optional<nsAString>& aUser,
             const mozilla::dom::Optional<nsAString>& aPassword,
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -544,16 +544,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug650386_redirect_307.html \
 		file_bug650386_content.sjs \
 		file_bug650386_report.sjs \
 		test_bug719533.html \
 		test_bug737087.html \
 		test_bug433662.html \
 		test_bug749367.html \
 		test_bug753278.html \
+		test_XHR_onuploadprogress.html \
 		$(NULL)
 
 _CHROME_FILES =	\
 		test_bug357450.js \
 		$(NULL)
 
 # This test fails on the Mac for some reason
 ifneq (,$(filter gtk2 windows,$(MOZ_WIDGET_TOOLKIT)))
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_XHR_onuploadprogress.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=743666
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 743666</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=743666">Mozilla Bug 743666</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 743666 **/
+
+var called = false;
+function uploadprogress()
+{
+  called = true;
+}
+
+var xhr = new XMLHttpRequest();
+xhr.onuploadprogress = uploadprogress;
+var event = document.createEvent("ProgressEvent");
+event.initProgressEvent("uploadprogress", false, false, false, false, 0);
+xhr.dispatchEvent(event);
+ok(called,
+   "XMLHttpRequest.onuploadprogress sets uploadprogress event listener");
+
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -227,17 +227,17 @@ DOMInterfaces = {
     'prefable': True,
     'infallible': {
         'all': [
             'readyState', 'withCredentials', 'abort', 'statusText',
             'getAllResponseHeaders', 'overrideMimeType', 'mozBackgroundRequest',
             'multipart', 'channel', 'upload', 'status'
         ],
         'getterOnly': [
-            'responseType', 'timeout', 'onreadystatechange'
+            'responseType', 'timeout', 'onreadystatechange', 'onuploadprogress'
         ]
     },
     # XXXbz need a JSContext for send() and sendAsBinary because of
     # the old nsIVariant-based signatures which actually use it for
     # typed arrays.  Once those go away, we can nuke this line.
     'implicitJSContext': [ 'send', 'sendAsBinary' ],
     'resultNotAddRefed': [ 'upload', 'responseXML' ]
 },
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -120,8 +120,9 @@ MozBlobBuilderWarning=Use of MozBlobBuil
 # LOCALIZATION NOTE: Do not translate "DOMException", "code" and "name"
 DOMExceptionCodeWarning=Use of DOMException's code attribute is deprecated. Use name instead.
 # LOCALIZATION NOTE: Do not translate "__exposedProps__"
 NoExposedPropsWarning=Exposing chrome JS objects to content without __exposedProps__ is insecure and deprecated. See https://developer.mozilla.org/en/XPConnect_wrappers for more information.
 # LOCALIZATION NOTE: Do not translate "Mutation Event" and "MutationObserver"
 MutationEventWarning=Use of Mutation Events is deprecated. Use MutationObserver instead.
 # LOCALIZATION NOTE: Do not translate "Blob", "mozSlice", or "slice"
 MozSliceWarning=Use of mozSlice on the Blob object is deprecated.  Use slice instead.
+OnuploadprogressWarning=Use of XMLHttpRequest's onuploadprogress attribute is deprecated.
--- a/dom/webidl/XMLHttpRequest.webidl
+++ b/dom/webidl/XMLHttpRequest.webidl
@@ -74,9 +74,10 @@ interface XMLHttpRequest : XMLHttpReques
   readonly attribute Document? responseXML;
 
   // Mozilla-specific stuff
   attribute boolean multipart;
   attribute boolean mozBackgroundRequest;
   [ChromeOnly] readonly attribute MozChannel channel;
   void sendAsBinary(DOMString body);
   any getInterface(IID iid);
+  [TreatNonCallableAsNull] attribute Function? onuploadprogress;
 };
--- a/dom/workers/XMLHttpRequest.h
+++ b/dom/workers/XMLHttpRequest.h
@@ -90,16 +90,28 @@ public:
   {                                                                            \
     SetEventListener(NS_LITERAL_STRING(#_type), aListener, aRv);               \
   }
 
   IMPL_GETTER_AND_SETTER(readystatechange)
 
 #undef IMPL_GETTER_AND_SETTER
 
+  JSObject*
+  GetOnuploadprogress(JSContext* /* unused */, ErrorResult& aRv)
+  {
+    aRv = NS_ERROR_NOT_IMPLEMENTED;
+    return NULL;
+  }
+  void
+  SetOnuploadprogress(JSContext* /* unused */, JSObject* aListener, ErrorResult& aRv)
+  {
+    aRv = NS_ERROR_NOT_IMPLEMENTED;
+  }
+
   uint16_t
   GetReadyState() const
   {
     return mStateData.mReadyState;
   }
 
   void
   Open(const nsAString& aMethod, const nsAString& aUrl, bool aAsync,