2008-08-18 Geoff Norton <gnorton@novell.com>
authorGeoff Norton <grompf@sublimeintervention.com>
Mon, 18 Aug 2008 03:12:39 +0000 (03:12 -0000)
committerGeoff Norton <grompf@sublimeintervention.com>
Mon, 18 Aug 2008 03:12:39 +0000 (03:12 -0000)
        * WebRequest_2_1.cs: Set a delegate callback for BrowserHttpWebRequest
        to update progress.
        * WebClient_2_1.cs: Refactor the OnDownloadedChanged method, as its already
        emitting on the right thread.  Clean up the OnOpenReadCompleted method.
        Set a delegate callback for BrowserHttpWebRequest to updated Progress.

svn path=/trunk/mcs/; revision=110707

mcs/class/System.Net/System.Net/ChangeLog
mcs/class/System.Net/System.Net/WebClient_2_1.cs
mcs/class/System.Net/System.Net/WebRequest_2_1.cs

index c114923055d89c8bc59f74e973a08bf28872d826..f265b0860faf989af4475265a72cbb7db4b8f3c2 100644 (file)
@@ -1,3 +1,11 @@
+2008-08-18  Geoff Norton  <gnorton@novell.com>
+
+       * WebRequest_2_1.cs: Set a delegate callback for BrowserHttpWebRequest
+       to update progress.
+       * WebClient_2_1.cs: Refactor the OnDownloadedChanged method, as its already
+       emitting on the right thread.  Clean up the OnOpenReadCompleted method.
+       Set a delegate callback for BrowserHttpWebRequest to updated Progress.
+
 2008-08-17  Geoff Norton  <gnorton@novell.com>
 
        * WebRequest_2_1.cs: We support relative URI's now.
index ab6d24e626e500ecdce1c8a3296969cc4c9d3c48..2a391791c8b53e0abdd72be5204cbdcb915f9001 100644 (file)
@@ -74,6 +74,8 @@ namespace System.Net
 #if NET_2_1
        public class WebClient
        {
+               private delegate void ProgressChangedDelegate (long read, long length, object state);
+
 //             static readonly string urlEncodedCType = "application/x-www-form-urlencoded";
 //             static byte [] hexBytes;
 //             ICredentials credentials;
@@ -904,6 +906,9 @@ namespace System.Net
 //                     }
 //
 //                     responseHeaders = null;
+                       request.SetupProgressDelegate ((ProgressChangedDelegate) delegate (long read, long length, object state) {
+                               OnDownloadProgressChanged (new DownloadProgressChangedEventArgs (read, length, state));
+                       });
                        return request;
                }
 
@@ -1409,28 +1414,31 @@ namespace System.Net
 //                             DownloadFileCompleted (this, args);
 //             }
 //
-                public delegate bool GSourceFunc  (IntPtr data);
-
-               [DllImport ("moon")]
-               static extern uint g_idle_add (GSourceFunc callback, IntPtr data);
-
-               private DownloadProgressChangedEventArgs e;
-               private GSourceFunc download_progress_delegate;
                protected virtual void OnDownloadProgressChanged (DownloadProgressChangedEventArgs e)
                {
                        if (DownloadProgressChanged != null) {
-                               this.e = e;
-                               download_progress_delegate = new GSourceFunc (download_progress_callback);
-                               g_idle_add (download_progress_delegate, IntPtr.Zero);
+                               DownloadProgressChanged (this, e);
                        }
                }
                
-               bool download_progress_callback (IntPtr data)
+               private ManualResetEvent wait_event = new ManualResetEvent (false);
+               private object callback_args;
+
+               protected virtual void OnOpenReadCompleted (OpenReadCompletedEventArgs args)
                {
-                       DownloadProgressChanged (this, e);
-                       return false;
+                       CompleteAsync ();
+                       if (OpenReadCompleted != null) {
+                               callback_args = args;
+                               g_idle_add ((GSourceFunc) delegate (IntPtr ctx) { OpenReadCompleted (this, (OpenReadCompletedEventArgs) callback_args); wait_event.Set (); return false; }, IntPtr.Zero);
+                               wait_event.WaitOne ();
+                       }
                }
 
+               public delegate bool GSourceFunc (IntPtr data);
+
+               [DllImport ("moon")]
+               static extern uint g_idle_add (GSourceFunc callback, IntPtr data);
+
 //             protected virtual void OnDownloadStringCompleted (DownloadStringCompletedEventArgs args)
 //             {
 //                     CompleteAsync ();
@@ -1438,23 +1446,6 @@ namespace System.Net
 //                             DownloadStringCompleted (this, args);
 //             }
 //
-               private OpenReadCompletedEventArgs args;
-               private GSourceFunc read_completed_delegate;
-               protected virtual void OnOpenReadCompleted (OpenReadCompletedEventArgs args)
-               {
-                       CompleteAsync ();
-                       if (OpenReadCompleted != null) {
-                               this.args = args;
-                               read_completed_delegate = new GSourceFunc (read_completed_callback);
-                               g_idle_add (read_completed_delegate, IntPtr.Zero);
-                       }
-               }
-
-               bool read_completed_callback (IntPtr data)
-               {
-                       OpenReadCompleted (this, args);
-                       return false;
-               }
 
 //             protected virtual void OnOpenWriteCompleted (OpenWriteCompletedEventArgs args)
 //             {
index 6b33a3146b34599570786b5c1c670d8b2eb6feb0..66024307cde94210fde4dd2e9fd7536a71daea9b 100644 (file)
@@ -88,6 +88,15 @@ namespace System.Net {
                {
                        throw new NotSupportedException ();
                }
+
+               internal void SetupProgressDelegate (Delegate progress_delegate)
+               {
+                       if (browser_http_request == null)
+                               browser_http_request = GetBrowserHttpFromMoonlight ();
+
+                       this.GetType ().GetField ("progress_delegate", BindingFlags.Instance | BindingFlags.NonPublic).SetValue (this, progress_delegate);
+               }
+               
        }
 }