browserutilities/downloadmgr/DownloadMgrServEng/Src/HttpDownload.cpp
changeset 13 10e98eab6f85
parent 8 7c90e6132015
child 16 a359256acfc6
--- a/browserutilities/downloadmgr/DownloadMgrServEng/Src/HttpDownload.cpp	Fri May 08 08:25:06 2009 +0300
+++ b/browserutilities/downloadmgr/DownloadMgrServEng/Src/HttpDownload.cpp	Fri Jul 03 15:54:40 2009 +0100
@@ -59,6 +59,7 @@
 const TInt KMaxHeaderOfMultipart = 32000;
 const TInt KRespSizeForRecognition = 1024;  //for THttpProgressState EHttpContTypeRecognitionAvail
 const TInt KMinDataSizeToSend = (32*1024);  //for Browser Control to call NewDownloadL     
+const TInt KErrCodHttpDownloadPaused = -20045;  //Error code set by the CodHandler if the download is paused by the client
 
 _LIT8( KHttpScheme, "http" );
 _LIT8( KHttpsScheme, "https" );
@@ -2440,7 +2441,19 @@
                 	
                 if( iProgState != EHttpProgMovingContentFile )
                     {
-                    TriggerEvent( iDlState, aValue ? EHttpDlProgProgressive : EHttpDlProgNonProgressive);
+                    if (aValue && iDlState == EHttpDlMultipleMOCompleted )
+                        {
+                        /* 
+                        if the file size is small, by the time the music player is launched, DMgr already triggered EHttpDlCompleted.
+                        So if the download state is EHttpDlMultipleMOCompleted, we need to trigger EHttpDlCompleted so that music player understands download is completed already
+                        This is needed to ensure backward compatibility
+                        */
+                        TriggerEvent( EHttpDlCompleted, EHttpDlProgProgressive);
+                        }   
+                    else
+                        {    
+                        TriggerEvent( iDlState, aValue ? EHttpDlProgProgressive : EHttpDlProgNonProgressive);
+                        }
                     }
                 }
             else
@@ -3187,7 +3200,12 @@
 	        	    iLastError = EGeneral;
 	           	    }
                 }
-    	    TriggerEvent( EHttpDlFailed, EHttpProgNone );
+            
+            //if the client pauses the download, Codhandler sets error code to KErrCodHttpDownloadPaused. In that case, no need to trigger EHttpDlFailed Event     
+            if ( result != KErrCodHttpDownloadPaused )
+                {    
+    	        TriggerEvent( EHttpDlFailed, EHttpProgNone );
+                }
             }
     	}
     }
@@ -3998,6 +4016,16 @@
 
     CLOG_WRITE("5");
 
+    
+    TInt size = GetHttpHeadersSize(iResponseHeaders)+ GetHttpHeadersSize(iRequestHeaders)+
+                GetHttpHeadersSize(iEntityHeaders)+ GetHttpHeadersSize(iGeneralHeaders) + newInfoPtr.Size();
+    
+    
+    if(size >= bufSz)
+        {
+    	User::LeaveIfError( KErrArgument );
+        }
+    
     AppendHeadersL( newInfoPtr, iResponseHeaders );
     AppendHeadersL( newInfoPtr, iRequestHeaders );
     AppendHeadersL( newInfoPtr, iEntityHeaders );
@@ -6150,7 +6178,7 @@
     if( iSilentMode )
         {
         if( !((aDlState == EHttpDlInprogress && aProgState == EHttpStarted)
-            || aDlState == EHttpDlMultipleMOCompleted || aDlState == EHttpDlFailed ))
+            || aDlState == EHttpDlMultipleMOCompleted || aDlState == EHttpDlFailed || aDlState == EHttpDlCompleted ))
             // See EDlAttrSilent
             {
             return;
@@ -6513,6 +6541,35 @@
     }
 
 // -----------------------------------------------------------------------------
+// CHttpDownload::GetHttpHeadersSize
+// -----------------------------------------------------------------------------
+//
+TInt CHttpDownload::GetHttpHeadersSize(CArrayPtrFlat<CHeaderField>* aHeaders )
+    {
+    TInt headers = aHeaders->Count();
+    CLOG_WRITE_1("Headers: %d", headers);
+
+    HBufC8* fieldName = NULL;
+    HBufC8* fieldRawData = NULL;
+    
+    TInt size  = 0;
+
+    for( TInt i = 0; i < headers; ++i )
+        {
+        fieldName = (*aHeaders)[i]->FieldName();
+        fieldRawData = (*aHeaders)[i]->FieldRawData();
+        
+        size = size + fieldName->Size() +  fieldRawData->Size();
+        
+        CLOG_WRITE8_1( "Size = %S:", size );
+        }
+
+    return size;
+    
+    }
+    
+    
+// -----------------------------------------------------------------------------
 // CHttpDownload::AddHeaderL
 // -----------------------------------------------------------------------------
 //