mirror of
				https://github.com/mozilla/gecko-dev.git
				synced 2025-11-04 10:18:41 +02:00 
			
		
		
		
	UTFInputStream does not do very good error-recovery, so always
use nsConverterInputStream instead. Bug 183165, r=timeless, sr=sspitzer, general approval=dbaron
This commit is contained in:
		
							parent
							
								
									e9e48eadbf
								
							
						
					
					
						commit
						1866641871
					
				
					 2 changed files with 38 additions and 10 deletions
				
			
		| 
						 | 
					@ -1534,17 +1534,31 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
 | 
				
			||||||
      return rv;
 | 
					      return rv;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    nsCOMPtr<nsIUnicharInputStream> unicharStream;
 | 
					    nsCOMPtr<nsIConverterInputStream> converterStream = 
 | 
				
			||||||
    // This forces UA sheets to be UTF8, but that's ok, right?
 | 
					      do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);
 | 
				
			||||||
    rv = NS_NewUTF8ConverterStream(getter_AddRefs(unicharStream), stream, 0);
 | 
					    
 | 
				
			||||||
    if (NS_FAILED(rv)) {
 | 
					    if (NS_FAILED(rv)) {
 | 
				
			||||||
      LOG_ERROR(("  Failed to create UTF8 stream"));
 | 
					      LOG_ERROR(("  Failed to create converter stream"));
 | 
				
			||||||
 | 
					      SheetComplete(aLoadData, PR_FALSE);
 | 
				
			||||||
 | 
					      return rv;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // This forces UA sheets to be UTF-8.  We should really look for
 | 
				
			||||||
 | 
					    // @charset rules here via ReadSegments on the raw stream...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 8092 is a nice magic number that happens to be what a lot of
 | 
				
			||||||
 | 
					    // other things use for buffer sizes.
 | 
				
			||||||
 | 
					    rv = converterStream->Init(stream, NS_LITERAL_STRING("UTF-8").get(),
 | 
				
			||||||
 | 
					                               8092, PR_TRUE);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (NS_FAILED(rv)) {
 | 
				
			||||||
 | 
					      LOG_ERROR(("  Failed to initialize converter stream"));
 | 
				
			||||||
      SheetComplete(aLoadData, PR_FALSE);
 | 
					      SheetComplete(aLoadData, PR_FALSE);
 | 
				
			||||||
      return rv;
 | 
					      return rv;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PRBool completed;
 | 
					    PRBool completed;
 | 
				
			||||||
    rv = ParseSheet(unicharStream, aLoadData, completed);
 | 
					    rv = ParseSheet(converterStream, aLoadData, completed);
 | 
				
			||||||
    NS_ASSERTION(completed, "sync load did not complete");
 | 
					    NS_ASSERTION(completed, "sync load did not complete");
 | 
				
			||||||
    return rv;
 | 
					    return rv;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1534,17 +1534,31 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
 | 
				
			||||||
      return rv;
 | 
					      return rv;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    nsCOMPtr<nsIUnicharInputStream> unicharStream;
 | 
					    nsCOMPtr<nsIConverterInputStream> converterStream = 
 | 
				
			||||||
    // This forces UA sheets to be UTF8, but that's ok, right?
 | 
					      do_CreateInstance("@mozilla.org/intl/converter-input-stream;1", &rv);
 | 
				
			||||||
    rv = NS_NewUTF8ConverterStream(getter_AddRefs(unicharStream), stream, 0);
 | 
					    
 | 
				
			||||||
    if (NS_FAILED(rv)) {
 | 
					    if (NS_FAILED(rv)) {
 | 
				
			||||||
      LOG_ERROR(("  Failed to create UTF8 stream"));
 | 
					      LOG_ERROR(("  Failed to create converter stream"));
 | 
				
			||||||
 | 
					      SheetComplete(aLoadData, PR_FALSE);
 | 
				
			||||||
 | 
					      return rv;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // This forces UA sheets to be UTF-8.  We should really look for
 | 
				
			||||||
 | 
					    // @charset rules here via ReadSegments on the raw stream...
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 8092 is a nice magic number that happens to be what a lot of
 | 
				
			||||||
 | 
					    // other things use for buffer sizes.
 | 
				
			||||||
 | 
					    rv = converterStream->Init(stream, NS_LITERAL_STRING("UTF-8").get(),
 | 
				
			||||||
 | 
					                               8092, PR_TRUE);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (NS_FAILED(rv)) {
 | 
				
			||||||
 | 
					      LOG_ERROR(("  Failed to initialize converter stream"));
 | 
				
			||||||
      SheetComplete(aLoadData, PR_FALSE);
 | 
					      SheetComplete(aLoadData, PR_FALSE);
 | 
				
			||||||
      return rv;
 | 
					      return rv;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PRBool completed;
 | 
					    PRBool completed;
 | 
				
			||||||
    rv = ParseSheet(unicharStream, aLoadData, completed);
 | 
					    rv = ParseSheet(converterStream, aLoadData, completed);
 | 
				
			||||||
    NS_ASSERTION(completed, "sync load did not complete");
 | 
					    NS_ASSERTION(completed, "sync load did not complete");
 | 
				
			||||||
    return rv;
 | 
					    return rv;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue