Bug 991149 - Improve image/* source compliance with Mozilla Coding Style. r=seth
authorGlenn Randers-Pehrson <glennrp+bmo@gmail.com>
Fri, 14 Nov 2014 12:59:00 -0500
changeset 215867 08434d415b5c69d764ade5007868f0fb90624019
parent 215866 d94b6a6469b49f666334af051b62ef0a95aceb3d
child 215868 fcb277a52bddfdbe352b2aa850267a42f01485c5
push id27829
push usergszorc@mozilla.com
push dateSat, 15 Nov 2014 22:34:49 +0000
treeherdermozilla-central@19f75e1211e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth
bugs991149
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 991149 - Improve image/* source compliance with Mozilla Coding Style. r=seth
dom/base/nsImageLoadingContent.cpp
image/decoders/EXIF.cpp
image/decoders/EXIF.h
image/decoders/GIF2.h
image/decoders/iccjpeg.c
image/decoders/iccjpeg.h
image/decoders/icon/android/nsIconChannel.cpp
image/decoders/icon/android/nsIconChannel.h
image/decoders/icon/gtk/nsIconChannel.cpp
image/decoders/icon/gtk/nsIconChannel.h
image/decoders/icon/mac/nsIconChannel.h
image/decoders/icon/mac/nsIconChannelCocoa.mm
image/decoders/icon/nsIIconURI.idl
image/decoders/icon/nsIconModule.cpp
image/decoders/icon/nsIconProtocolHandler.cpp
image/decoders/icon/nsIconProtocolHandler.h
image/decoders/icon/nsIconURI.cpp
image/decoders/icon/nsIconURI.h
image/decoders/icon/qt/gtkqticonsconverter.js
image/decoders/icon/qt/nsIconChannel.cpp
image/decoders/icon/qt/nsIconChannel.h
image/decoders/icon/win/nsIconChannel.cpp
image/decoders/icon/win/nsIconChannel.h
image/decoders/nsBMPDecoder.cpp
image/decoders/nsBMPDecoder.h
image/decoders/nsGIFDecoder2.cpp
image/decoders/nsGIFDecoder2.h
image/decoders/nsICODecoder.cpp
image/decoders/nsICODecoder.h
image/decoders/nsIconDecoder.cpp
image/decoders/nsIconDecoder.h
image/decoders/nsJPEGDecoder.cpp
image/decoders/nsJPEGDecoder.h
image/decoders/nsPNGDecoder.cpp
image/decoders/nsPNGDecoder.h
image/encoders/bmp/nsBMPEncoder.cpp
image/encoders/bmp/nsBMPEncoder.h
image/encoders/ico/nsICOEncoder.cpp
image/encoders/ico/nsICOEncoder.h
image/encoders/jpeg/nsJPEGEncoder.cpp
image/encoders/jpeg/nsJPEGEncoder.h
image/encoders/png/nsPNGEncoder.cpp
image/public/imgILoader.idl
image/src/Decoder.h
image/src/imgLoader.h
image/test/unit/test_encoder_apng.js
image/test/unit/test_encoder_png.js
layout/reftests/reftest.list
--- a/dom/base/nsImageLoadingContent.cpp
+++ b/dom/base/nsImageLoadingContent.cpp
@@ -1002,18 +1002,18 @@ nsImageLoadingContent::ImageState() cons
 
   return states;
 }
 
 void
 nsImageLoadingContent::UpdateImageState(bool aNotify)
 {
   if (mStateChangerDepth > 0) {
-    // Ignore this call; we'll update our state when the outermost state
-    // changer is destroyed. Need this to work around the fact that some libpr0n
+    // Ignore this call; we'll update our state when the outermost state changer
+    // is destroyed. Need this to work around the fact that some ImageLib
     // stuff is actually sync and hence we can get OnStopDecode called while
     // we're still under LoadImage, and OnStopDecode doesn't know anything about
     // aNotify.
     // XXX - This machinery should be removed after bug 521604.
     return;
   }
 
   nsCOMPtr<nsIContent> thisContent = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
--- a/image/decoders/EXIF.cpp
+++ b/image/decoders/EXIF.cpp
@@ -38,31 +38,35 @@ static const char* EXIFHeader = "Exif\0\
 static const uint32_t EXIFHeaderLength = 6;
 
 /////////////////////////////////////////////////////////////
 // Parse EXIF data, typically found in a JPEG's APP1 segment.
 /////////////////////////////////////////////////////////////
 EXIFData
 EXIFParser::ParseEXIF(const uint8_t* aData, const uint32_t aLength)
 {
-  if (!Initialize(aData, aLength))
+  if (!Initialize(aData, aLength)) {
     return EXIFData();
+  }
 
-  if (!ParseEXIFHeader())
+  if (!ParseEXIFHeader()) {
     return EXIFData();
+  }
 
   uint32_t offsetIFD;
-  if (!ParseTIFFHeader(offsetIFD))
+  if (!ParseTIFFHeader(offsetIFD)) {
     return EXIFData();
+  }
 
   JumpTo(offsetIFD);
 
   Orientation orientation;
-  if (!ParseIFD0(orientation))
+  if (!ParseIFD0(orientation)) {
     return EXIFData();
+  }
 
   // We only care about orientation at this point, so we don't bother with the
   // other IFDs. If we got this far we're done.
   return EXIFData(orientation);
 }
 
 /////////////////////////////////////////////////////////
 // Parse the EXIF header. (Section 4.7.2, Figure 30)
@@ -75,91 +79,100 @@ EXIFParser::ParseEXIFHeader()
 
 /////////////////////////////////////////////////////////
 // Parse the TIFF header. (Section 4.5.2, Table 1)
 /////////////////////////////////////////////////////////
 bool
 EXIFParser::ParseTIFFHeader(uint32_t& aIFD0OffsetOut)
 {
   // Determine byte order.
-  if (MatchString("MM\0*", 4))
+  if (MatchString("MM\0*", 4)) {
     mByteOrder = ByteOrder::BigEndian;
-  else if (MatchString("II*\0", 4))
+  } else if (MatchString("II*\0", 4)) {
     mByteOrder = ByteOrder::LittleEndian;
-  else
+  } else {
     return false;
+  }
 
   // Determine offset of the 0th IFD. (It shouldn't be greater than 64k, which
   // is the maximum size of the entry APP1 segment.)
   uint32_t ifd0Offset;
-  if (!ReadUInt32(ifd0Offset) || ifd0Offset > 64 * 1024)
+  if (!ReadUInt32(ifd0Offset) || ifd0Offset > 64 * 1024) {
     return false;
+  }
 
   // The IFD offset is relative to the beginning of the TIFF header, which
   // begins after the EXIF header, so we need to increase the offset
   // appropriately.
   aIFD0OffsetOut = ifd0Offset + EXIFHeaderLength;
   return true;
 }
 
 /////////////////////////////////////////////////////////
 // Parse the entries in IFD0. (Section 4.6.2)
 /////////////////////////////////////////////////////////
 bool
 EXIFParser::ParseIFD0(Orientation& aOrientationOut)
 {
   uint16_t entryCount;
-  if (!ReadUInt16(entryCount))
+  if (!ReadUInt16(entryCount)) {
     return false;
+  }
 
   for (uint16_t entry = 0 ; entry < entryCount ; ++entry) {
     // Read the fields of the entry.
     uint16_t tag;
-    if (!ReadUInt16(tag))
+    if (!ReadUInt16(tag)) {
       return false;
+    }
 
     // Right now, we only care about orientation, so we immediately skip to the
     // next entry if we find anything else.
     if (tag != OrientationTag) {
       Advance(10);
       continue;
     }
 
     uint16_t type;
-    if (!ReadUInt16(type))
+    if (!ReadUInt16(type)) {
       return false;
+    }
 
     uint32_t count;
-    if (!ReadUInt32(count))
+    if (!ReadUInt32(count)) {
       return false;
+    }
 
     // We should have an orientation value here; go ahead and parse it.
-    if (!ParseOrientation(type, count, aOrientationOut))
+    if (!ParseOrientation(type, count, aOrientationOut)) {
       return false;
+    }
 
     // Since the orientation is all we care about, we're done.
     return true;
   }
 
   // We didn't find an orientation field in the IFD. That's OK; we assume the
   // default orientation in that case.
   aOrientationOut = Orientation();
   return true;
 }
 
 bool
 EXIFParser::ParseOrientation(uint16_t aType, uint32_t aCount, Orientation& aOut)
 {
   // Sanity check the type and count.
-  if (aType != ShortType || aCount != 1)
+  if (aType != ShortType || aCount != 1) {
     return false;
+  }
 
   uint16_t value;
-  if (!ReadUInt16(value))
+  if (!ReadUInt16(value)) {
     return false;
+  }
 
   switch (value) {
     case 1: aOut = Orientation(Angle::D0,   Flip::Unflipped);  break;
     case 2: aOut = Orientation(Angle::D0,   Flip::Horizontal); break;
     case 3: aOut = Orientation(Angle::D180, Flip::Unflipped);  break;
     case 4: aOut = Orientation(Angle::D180, Flip::Horizontal); break;
     case 5: aOut = Orientation(Angle::D90,  Flip::Horizontal); break;
     case 6: aOut = Orientation(Angle::D90,  Flip::Unflipped);  break;
@@ -172,22 +185,24 @@ EXIFParser::ParseOrientation(uint16_t aT
   // 16 bits. We need to advance another 16 bits to consume the entire field.
   Advance(2);
   return true;
 }
 
 bool
 EXIFParser::Initialize(const uint8_t* aData, const uint32_t aLength)
 {
-  if (aData == nullptr)
+  if (aData == nullptr) {
     return false;
+  }
 
   // An APP1 segment larger than 64k violates the JPEG standard.
-  if (aLength > 64 * 1024)
+  if (aLength > 64 * 1024) {
     return false;
+  }
 
   mStart = mCurrent = aData;
   mLength = mRemainingLength = aLength;
   mByteOrder = ByteOrder::Unknown;
   return true;
 }
 
 void
@@ -212,97 +227,105 @@ EXIFParser::JumpTo(const uint32_t aOffse
     mCurrent = mStart;
     mRemainingLength = 0;
   }
 }
 
 bool
 EXIFParser::MatchString(const char* aString, const uint32_t aLength)
 {
-  if (mRemainingLength < aLength)
+  if (mRemainingLength < aLength) {
     return false;
+  }
 
   for (uint32_t i = 0 ; i < aLength ; ++i) {
-    if (mCurrent[i] != aString[i])
+    if (mCurrent[i] != aString[i]) {
       return false;
+    }
   }
 
   Advance(aLength);
   return true;
 }
 
 bool
 EXIFParser::MatchUInt16(const uint16_t aValue)
 {
-  if (mRemainingLength < 2)
+  if (mRemainingLength < 2) {
     return false;
-  
+  }
+
   bool matched;
   switch (mByteOrder) {
     case ByteOrder::LittleEndian:
       matched = LittleEndian::readUint16(mCurrent) == aValue;
       break;
     case ByteOrder::BigEndian:
       matched = BigEndian::readUint16(mCurrent) == aValue;
       break;
     default:
       NS_NOTREACHED("Should know the byte order by now");
       matched = false;
   }
 
-  if (matched)
+  if (matched) {
     Advance(2);
+  }
 
   return matched;
 }
 
 bool
 EXIFParser::ReadUInt16(uint16_t& aValue)
 {
-  if (mRemainingLength < 2)
+  if (mRemainingLength < 2) {
     return false;
-  
+  }
+
   bool matched = true;
   switch (mByteOrder) {
     case ByteOrder::LittleEndian:
       aValue = LittleEndian::readUint16(mCurrent);
       break;
     case ByteOrder::BigEndian:
       aValue = BigEndian::readUint16(mCurrent);
       break;
     default:
       NS_NOTREACHED("Should know the byte order by now");
       matched = false;
   }
 
-  if (matched)
+  if (matched) {
     Advance(2);
+  }
 
   return matched;
 }
 
 bool
 EXIFParser::ReadUInt32(uint32_t& aValue)
 {
-  if (mRemainingLength < 4)
+  if (mRemainingLength < 4) {
     return false;
-  
+  }
+
   bool matched = true;
   switch (mByteOrder) {
     case ByteOrder::LittleEndian:
       aValue = LittleEndian::readUint32(mCurrent);
       break;
     case ByteOrder::BigEndian:
       aValue = BigEndian::readUint32(mCurrent);
       break;
     default:
       NS_NOTREACHED("Should know the byte order by now");
       matched = false;
   }
 
-  if (matched)
+  if (matched) {
     Advance(4);
+  }
 
   return matched;
 }
 
 } // namespace image
 } // namespace mozilla
--- a/image/decoders/EXIF.h
+++ b/image/decoders/EXIF.h
@@ -1,15 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef MOZILLA_IMAGELIB_EXIF_H_
-#define MOZILLA_IMAGELIB_EXIF_H_
+#ifndef MOZILLA_IMAGELIB_EXIF_H
+#define MOZILLA_IMAGELIB_EXIF_H
 
 #include <stdint.h>
 #include "mozilla/TypedEnum.h"
 #include "nsDebug.h"
 
 #include "Orientation.h"
 
 namespace mozilla {
@@ -65,12 +65,12 @@ private:
 
   const uint8_t* mStart;
   const uint8_t* mCurrent;
   uint32_t       mLength;
   uint32_t       mRemainingLength;
   ByteOrder      mByteOrder;
 };
 
-}
-}
+} // namespace image
+} // namespace mozilla
 
-#endif
+#endif // MOZILLA_IMAGELIB_EXIF_H
--- a/image/decoders/GIF2.h
+++ b/image/decoders/GIF2.h
@@ -1,31 +1,32 @@
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef _GIF_H_
-#define _GIF_H_
+
+#ifndef GIF2_H
+#define GIF2_H
 
 #define MAX_LZW_BITS          12
-#define MAX_BITS            4097 /* 2^MAX_LZW_BITS+1 */
+#define MAX_BITS            4097 // 2^MAX_LZW_BITS+1
 #define MAX_COLORS           256
 #define MIN_HOLD_SIZE        256
 
-enum { GIF_TRAILER                     = 0x3B }; //';'
-enum { GIF_IMAGE_SEPARATOR             = 0x2C }; //','
-enum { GIF_EXTENSION_INTRODUCER        = 0x21 }; //'!'
+enum { GIF_TRAILER                     = 0x3B }; // ';'
+enum { GIF_IMAGE_SEPARATOR             = 0x2C }; // ','
+enum { GIF_EXTENSION_INTRODUCER        = 0x21 }; // '!'
 enum { GIF_GRAPHIC_CONTROL_LABEL       = 0xF9 };
 enum { GIF_COMMENT_LABEL               = 0xFE };
 enum { GIF_PLAIN_TEXT_LABEL            = 0x01 };
 enum { GIF_APPLICATION_EXTENSION_LABEL = 0xFF };
 
-/* gif2.h  
-   The interface for the GIF87/89a decoder. 
-*/
+// gif2.h
+// The interface for the GIF87/89a decoder.
+
 // List of possible parsing states
 typedef enum {
     gif_type,
     gif_global_header,
     gif_global_colormap,
     gif_image_start,
     gif_image_header,
     gif_image_header_continue,
@@ -42,66 +43,68 @@ typedef enum {
     gif_error,
     gif_comment_extension,
     gif_application_extension,
     gif_netscape_extension_block,
     gif_consume_netscape_extension,
     gif_consume_comment
 } gstate;
 
-/* A GIF decoder's state */
+// A GIF decoder's state
 typedef struct gif_struct {
-    /* Parsing state machine */
-    gstate state;                   /* Curent decoder master state */
-    uint32_t bytes_to_consume;      /* Number of bytes to accumulate */
-    uint32_t bytes_in_hold;         /* bytes accumulated so far*/
+    // Parsing state machine
+    gstate state;               // Current decoder master state
+    uint32_t bytes_to_consume;  // Number of bytes to accumulate
+    uint32_t bytes_in_hold;     // bytes accumulated so far
 
-    /* LZW decoder state machine */
-    uint8_t *stackp;              /* Current stack pointer */
+    // LZW decoder state machine
+    uint8_t* stackp;            // Current stack pointer
     int datasize;
     int codesize;
     int codemask;
-    int avail;                  /* Index of next available slot in dictionary */
+    int avail;                  // Index of next available slot in dictionary
     int oldcode;
     uint8_t firstchar;
-    int count;                  /* Remaining # bytes in sub-block */
-    int bits;                   /* Number of unread bits in "datum" */
-    int32_t datum;              /* 32-bit input buffer */
+    int count;                  // Remaining # bytes in sub-block
+    int bits;                   // Number of unread bits in "datum"
+    int32_t datum;              // 32-bit input buffer
 
-    /* Output state machine */
-    int ipass;                  /* Interlace pass; Ranges 1-4 if interlaced. */
-    unsigned rows_remaining;        /* Rows remaining to be output */
-    unsigned irow;                  /* Current output row, starting at zero */
-    uint8_t *rowp;                 /* Current output pointer */
+    // Output state machine
+    int ipass;                  // Interlace pass; Ranges 1-4 if interlaced.
+    unsigned rows_remaining;    // Rows remaining to be output
+    unsigned irow;              // Current output row, starting at zero
+    uint8_t* rowp;              // Current output pointer
 
-    /* Parameters for image frame currently being decoded*/
-    unsigned x_offset, y_offset;    /* With respect to "screen" origin */
+    // Parameters for image frame currently being decoded
+    unsigned x_offset, y_offset; // With respect to "screen" origin
     unsigned height, width;
-    int tpixel;                 /* Index of transparent pixel */
-    int32_t disposal_method;    /* Restore to background, leave in place, etc.*/
-    uint32_t *local_colormap;   /* Per-image colormap */
-    int local_colormap_size;    /* Size of local colormap array. */
-    uint32_t delay_time;        /* Display time, in milliseconds,
-                                   for this image in a multi-image GIF */
+    int tpixel;                 // Index of transparent pixel
+    int32_t disposal_method;    // Restore to background, leave in place, etc.
+    uint32_t* local_colormap;   // Per-image colormap
+    int local_colormap_size;    // Size of local colormap array.
+    uint32_t delay_time;        // Display time, in milliseconds,
+                                // for this image in a multi-image GIF
 
-    /* Global (multi-image) state */
-    int version;                /* Either 89 for GIF89 or 87 for GIF87 */
-    unsigned screen_width;       /* Logical screen width & height */
+    // Global (multi-image) state
+    int version;                // Either 89 for GIF89 or 87 for GIF87
+    unsigned screen_width;      // Logical screen width & height
     unsigned screen_height;
-    uint32_t global_colormap_depth;  /* Depth of global colormap array. */
-    int images_decoded;         /* Counts images for multi-part GIFs */
-    int loop_count;             /* Netscape specific extension block to control
-                                   the number of animation loops a GIF renders. */
+    uint32_t global_colormap_depth; // Depth of global colormap array
+    int images_decoded;         // Counts images for multi-part GIFs
+    int loop_count;             // Netscape specific extension block to control
+                                // the number of animation loops a GIF
+                                // renders.
 
-    bool progressive_display;    /* If TRUE, do Haeberli interlace hack */
-    bool interlaced;             /* TRUE, if scanlines arrive interlaced order */
-    bool is_transparent;         /* TRUE, if tpixel is valid */
+    bool progressive_display;   // If TRUE, do Haeberli interlace hack
+    bool interlaced;            // TRUE, if scanlines arrive interlaced order
+    bool is_transparent;        // TRUE, if tpixel is valid
 
-    uint16_t  prefix[MAX_BITS];          /* LZW decoding tables */
-    uint8_t*  hold;                      /* Accumulation buffer */
-    uint32_t  global_colormap[MAX_COLORS];   /* Default colormap if local not supplied */
-    uint8_t   suffix[MAX_BITS];          /* LZW decoding tables */
-    uint8_t   stack[MAX_BITS];           /* Base of LZW decoder stack */
+    uint16_t  prefix[MAX_BITS];            // LZW decoding tables
+    uint8_t*  hold;                        // Accumulation buffer
+    uint32_t  global_colormap[MAX_COLORS]; // Default colormap if local not
+                                           //   supplied
+    uint8_t   suffix[MAX_BITS];            // LZW decoding tables
+    uint8_t   stack[MAX_BITS];             // Base of LZW decoder stack
 
 } gif_struct;
 
-#endif
+#endif // GIF2_H
 
--- a/image/decoders/iccjpeg.c
+++ b/image/decoders/iccjpeg.c
@@ -1,14 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
- * iccprofile.c
+ * iccjpeg.c
  *
  * This file provides code to read and write International Color Consortium
  * (ICC) device profiles embedded in JFIF JPEG image files.  The ICC has
  * defined a standard format for including such data in JPEG "APP2" markers.
  * The code given here does not know anything about the internal structure
  * of the ICC profile data; it just knows how to put the profile data into
  * a JPEG file being written, or get it back out when reading.
  *
@@ -17,35 +17,35 @@
  *
  * NOTE: this code would need surgery to work on 16-bit-int machines
  * with ICC profiles exceeding 64K bytes in size.  If you need to do that,
  * change all the "unsigned int" variables to "INT32".  You'll also need
  * to find a malloc() replacement that can allocate more than 64K.
  */
 
 #include "iccjpeg.h"
-#include <stdlib.h>			/* define malloc() */
+#include <stdlib.h>  /* define malloc() */
 
 
 /*
  * Since an ICC profile can be larger than the maximum size of a JPEG marker
  * (64K), we need provisions to split it into multiple markers.  The format
  * defined by the ICC specifies one or more APP2 markers containing the
  * following data:
- *	Identifying string	ASCII "ICC_PROFILE\0"  (12 bytes)
- *	Marker sequence number	1 for first APP2, 2 for next, etc (1 byte)
- *	Number of markers	Total number of APP2's used (1 byte)
- *      Profile data		(remainder of APP2 data)
+ *      Identifying string      ASCII "ICC_PROFILE\0"  (12 bytes)
+ *      Marker sequence number  1 for first APP2, 2 for next, etc (1 byte)
+ *      Number of markers       Total number of APP2's used (1 byte)
+ *      Profile data            (remainder of APP2 data)
  * Decoders should use the marker sequence numbers to reassemble the profile,
  * rather than assuming that the APP2 markers appear in the correct sequence.
  */
 
-#define ICC_MARKER  (JPEG_APP0 + 2)	/* JPEG marker code for ICC */
-#define ICC_OVERHEAD_LEN  14		/* size of non-profile data in APP2 */
-#define MAX_BYTES_IN_MARKER  65533	/* maximum data len of a JPEG marker */
+#define ICC_MARKER  (JPEG_APP0 + 2)      /* JPEG marker code for ICC */
+#define ICC_OVERHEAD_LEN  14             /* size of non-profile data in APP2 */
+#define MAX_BYTES_IN_MARKER  65533       /* maximum data len of a JPEG marker */
 #define MAX_DATA_BYTES_IN_MARKER  (MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN)
 
 /*
  * Prepare for reading an ICC profile
  */
 
 void
 setup_read_icc_profile (j_decompress_ptr cinfo)
@@ -97,90 +97,97 @@ marker_is_icc (jpeg_saved_marker_ptr mar
  * will prefer to have the data stick around after decompression finishes.)
  *
  * NOTE: if the file contains invalid ICC APP2 markers, we just silently
  * return FALSE.  You might want to issue an error message instead.
  */
 
 boolean
 read_icc_profile (j_decompress_ptr cinfo,
-		  JOCTET **icc_data_ptr,
-		  unsigned int *icc_data_len)
+  JOCTET** icc_data_ptr,
+  unsigned int* icc_data_len)
 {
   jpeg_saved_marker_ptr marker;
   int num_markers = 0;
   int seq_no;
-  JOCTET *icc_data;
+  JOCTET* icc_data;
   unsigned int total_length;
-#define MAX_SEQ_NO  255		/* sufficient since marker numbers are bytes */
-  char marker_present[MAX_SEQ_NO+1];	  /* 1 if marker found */
+#define MAX_SEQ_NO  255        /* sufficient since marker numbers are bytes */
+  char marker_present[MAX_SEQ_NO+1];      /* 1 if marker found */
   unsigned int data_length[MAX_SEQ_NO+1]; /* size of profile data in marker */
   unsigned int data_offset[MAX_SEQ_NO+1]; /* offset for data in marker */
 
-  *icc_data_ptr = NULL;		/* avoid confusion if FALSE return */
+  *icc_data_ptr = NULL;                   /* avoid confusion if FALSE return */
   *icc_data_len = 0;
 
   /* This first pass over the saved markers discovers whether there are
    * any ICC markers and verifies the consistency of the marker numbering.
    */
 
   for (seq_no = 1; seq_no <= MAX_SEQ_NO; seq_no++)
     marker_present[seq_no] = 0;
 
   for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
     if (marker_is_icc(marker)) {
-      if (num_markers == 0)
-	num_markers = GETJOCTET(marker->data[13]);
-      else if (num_markers != GETJOCTET(marker->data[13]))
-	return FALSE;		/* inconsistent num_markers fields */
+      if (num_markers == 0) {
+        num_markers = GETJOCTET(marker->data[13]);
+      } else if (num_markers != GETJOCTET(marker->data[13])) {
+        return FALSE;  /* inconsistent num_markers fields */
+      }
       seq_no = GETJOCTET(marker->data[12]);
-      if (seq_no <= 0 || seq_no > num_markers)
-	return FALSE;		/* bogus sequence number */
-      if (marker_present[seq_no])
-	return FALSE;		/* duplicate sequence numbers */
+      if (seq_no <= 0 || seq_no > num_markers) {
+        return FALSE;   /* bogus sequence number */
+      }
+      if (marker_present[seq_no]) {
+        return FALSE;   /* duplicate sequence numbers */
+      }
       marker_present[seq_no] = 1;
       data_length[seq_no] = marker->data_length - ICC_OVERHEAD_LEN;
     }
   }
 
-  if (num_markers == 0)
+  if (num_markers == 0) {
     return FALSE;
+  }
 
   /* Check for missing markers, count total space needed,
    * compute offset of each marker's part of the data.
    */
 
   total_length = 0;
   for (seq_no = 1; seq_no <= num_markers; seq_no++) {
-    if (marker_present[seq_no] == 0)
-      return FALSE;		/* missing sequence number */
+    if (marker_present[seq_no] == 0) {
+      return FALSE;  /* missing sequence number */
+    }
     data_offset[seq_no] = total_length;
     total_length += data_length[seq_no];
   }
 
-  if (total_length <= 0)
-    return FALSE;		/* found only empty markers? */
+  if (total_length <= 0) {
+    return FALSE;  /* found only empty markers? */
+  }
 
   /* Allocate space for assembled data */
-  icc_data = (JOCTET *) malloc(total_length * sizeof(JOCTET));
-  if (icc_data == NULL)
-    return FALSE;		/* oops, out of memory */
+  icc_data = (JOCTET*) malloc(total_length * sizeof(JOCTET));
+  if (icc_data == NULL) {
+    return FALSE;   /* oops, out of memory */
+  }
 
   /* and fill it in */
   for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) {
     if (marker_is_icc(marker)) {
-      JOCTET FAR *src_ptr;
-      JOCTET *dst_ptr;
+      JOCTET FAR* src_ptr;
+      JOCTET* dst_ptr;
       unsigned int length;
       seq_no = GETJOCTET(marker->data[12]);
       dst_ptr = icc_data + data_offset[seq_no];
       src_ptr = marker->data + ICC_OVERHEAD_LEN;
       length = data_length[seq_no];
       while (length--) {
-	*dst_ptr++ = *src_ptr++;
+        *dst_ptr++ = *src_ptr++;
       }
     }
   }
 
   *icc_data_ptr = icc_data;
   *icc_data_len = total_length;
 
   return TRUE;
--- a/image/decoders/iccjpeg.h
+++ b/image/decoders/iccjpeg.h
@@ -1,31 +1,34 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
- * iccprofile.h
+ * iccjpeg.h
  *
  * This file provides code to read and write International Color Consortium
  * (ICC) device profiles embedded in JFIF JPEG image files.  The ICC has
  * defined a standard format for including such data in JPEG "APP2" markers.
  * The code given here does not know anything about the internal structure
  * of the ICC profile data; it just knows how to put the profile data into
  * a JPEG file being written, or get it back out when reading.
  *
  * This code depends on new features added to the IJG JPEG library as of
  * IJG release 6b; it will not compile or work with older IJG versions.
  *
  * NOTE: this code would need surgery to work on 16-bit-int machines
  * with ICC profiles exceeding 64K bytes in size.  See iccprofile.c
  * for details.
  */
 
-#include <stdio.h>		/* needed to define "FILE", "NULL" */
+#ifndef ICCJPEG_H
+#define ICCJPEG_H
+
+#include <stdio.h>  /* needed to define "FILE", "NULL" */
 #include "jpeglib.h"
 
 /*
  * Reading a JPEG file that may contain an ICC profile requires two steps:
  *
  * 1. After jpeg_create_decompress() but before jpeg_read_header(),
  *    call setup_read_icc_profile().  This routine tells the IJG library
  *    to save in memory any APP2 markers it may find in the file.
@@ -54,10 +57,11 @@ extern void setup_read_icc_profile JPP((
  * and must be freed by the caller with free() when the caller no longer
  * needs it.  (Alternatively, we could write this routine to use the
  * IJG library's memory allocator, so that the data would be freed implicitly
  * at jpeg_finish_decompress() time.  But it seems likely that many apps
  * will prefer to have the data stick around after decompression finishes.)
  */
 
 extern boolean read_icc_profile JPP((j_decompress_ptr cinfo,
-				     JOCTET **icc_data_ptr,
-				     unsigned int *icc_data_len));
+                                     JOCTET** icc_data_ptr,
+                                     unsigned int* icc_data_len));
+#endif // ICCJPEG_H
--- a/image/decoders/icon/android/nsIconChannel.cpp
+++ b/image/decoders/icon/android/nsIconChannel.cpp
@@ -17,75 +17,83 @@
 NS_IMPL_ISUPPORTS(nsIconChannel,
                   nsIRequest,
                   nsIChannel)
 
 using namespace mozilla;
 using mozilla::dom::ContentChild;
 
 static nsresult
-GetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t * const aBuf)
+GetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize,
+                    uint8_t* const aBuf)
 {
-    if (!AndroidBridge::Bridge())
+    if (!AndroidBridge::Bridge()) {
         return NS_ERROR_FAILURE;
+    }
 
     AndroidBridge::Bridge()->GetIconForExtension(aFileExt, aIconSize, aBuf);
 
     return NS_OK;
 }
 
 static nsresult
-CallRemoteGetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t * const aBuf)
+CallRemoteGetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize,
+                              uint8_t* const aBuf)
 {
   NS_ENSURE_TRUE(aBuf != nullptr, NS_ERROR_NULL_POINTER);
 
   // An array has to be used to get data from remote process
   InfallibleTArray<uint8_t> bits;
   uint32_t bufSize = aIconSize * aIconSize * 4;
 
-  if (!ContentChild::GetSingleton()->SendGetIconForExtension(PromiseFlatCString(aFileExt), aIconSize, &bits))
+  if (!ContentChild::GetSingleton()->SendGetIconForExtension(
+                     PromiseFlatCString(aFileExt), aIconSize, &bits)) {
     return NS_ERROR_FAILURE;
+  }
 
   NS_ASSERTION(bits.Length() == bufSize, "Pixels array is incomplete");
-  if (bits.Length() != bufSize)
+  if (bits.Length() != bufSize) {
     return NS_ERROR_FAILURE;
+  }
 
   memcpy(aBuf, bits.Elements(), bufSize);
 
   return NS_OK;
 }
 
 static nsresult
-moz_icon_to_channel(nsIURI *aURI, const nsACString& aFileExt, uint32_t aIconSize, nsIChannel **aChannel)
+moz_icon_to_channel(nsIURI* aURI, const nsACString& aFileExt,
+                    uint32_t aIconSize, nsIChannel** aChannel)
 {
   NS_ENSURE_TRUE(aIconSize < 256 && aIconSize > 0, NS_ERROR_UNEXPECTED);
 
   int width = aIconSize;
   int height = aIconSize;
 
   // moz-icon data should have two bytes for the size,
   // then the ARGB pixel values with pre-multiplied Alpha
   const int channels = 4;
   long int buf_size = 2 + channels * height * width;
-  uint8_t * const buf = (uint8_t*)NS_Alloc(buf_size);
+  uint8_t* const buf = (uint8_t*)NS_Alloc(buf_size);
   NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
-  uint8_t * out = buf;
+  uint8_t* out = buf;
 
   *(out++) = width;
   *(out++) = height;
 
   nsresult rv;
-  if (XRE_GetProcessType() == GeckoProcessType_Default)
+  if (XRE_GetProcessType() == GeckoProcessType_Default) {
     rv = GetIconForExtension(aFileExt, aIconSize, out);
-  else
+  } else {
     rv = CallRemoteGetIconForExtension(aFileExt, aIconSize, out);
+  }
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Encode the RGBA data
-  const uint8_t * in = out;
+  const uint8_t* in = out;
   for (int y = 0; y < height; ++y) {
     for (int x = 0; x < width; ++x) {
       uint8_t r = *(in++);
       uint8_t g = *(in++);
       uint8_t b = *(in++);
       uint8_t a = *(in++);
 #define DO_PREMULTIPLY(c_) uint8_t(uint16_t(c_) * uint16_t(a) / uint16_t(255))
       *(out++) = DO_PREMULTIPLY(b);
@@ -126,10 +134,11 @@ nsIconChannel::Init(nsIURI* aURI)
   iconURI->GetStockIcon(stockIcon);
 
   uint32_t desiredImageSize;
   iconURI->GetImageSize(&desiredImageSize);
 
   nsAutoCString iconFileExt;
   iconURI->GetFileExtension(iconFileExt);
 
-  return moz_icon_to_channel(iconURI, iconFileExt, desiredImageSize, getter_AddRefs(mRealChannel));
+  return moz_icon_to_channel(iconURI, iconFileExt, desiredImageSize,
+                             getter_AddRefs(mRealChannel));
 }
--- a/image/decoders/icon/android/nsIconChannel.h
+++ b/image/decoders/icon/android/nsIconChannel.h
@@ -19,27 +19,27 @@
  * that file to which all calls will be proxied.
  */
 class nsIconChannel MOZ_FINAL : public nsIChannel {
   public:
     NS_DECL_ISUPPORTS
     NS_FORWARD_NSIREQUEST(mRealChannel->)
     NS_FORWARD_NSICHANNEL(mRealChannel->)
 
-    nsIconChannel() {}
+    nsIconChannel() { }
 
     /**
      * Called by nsIconProtocolHandler after it creates this channel.
      * Must be called before calling any other function on this object.
      * If this method fails, no other function must be called on this object.
      */
     nsresult Init(nsIURI* aURI);
 
   private:
-    ~nsIconChannel() {}
+    ~nsIconChannel() { }
 
     /**
      * The channel to the temp icon file (e.g. to /tmp/2qy9wjqw.html).
      * Will always be non-null after a successful Init.
      */
     nsCOMPtr<nsIChannel> mRealChannel;
 };
 
--- a/image/decoders/icon/gtk/nsIconChannel.cpp
+++ b/image/decoders/icon/gtk/nsIconChannel.cpp
@@ -39,68 +39,77 @@ extern "C" {
 
 #include "nsIconChannel.h"
 
 NS_IMPL_ISUPPORTS(nsIconChannel,
                   nsIRequest,
                   nsIChannel)
 
 #ifdef MOZ_ENABLE_GNOMEUI
-// These let us have a soft dependency on libgnomeui rather than a hard one. These are just basically the prototypes
-// of the functions in the libraries.
-typedef char* (*_GnomeIconLookup_fn)(GtkIconTheme *icon_theme, GnomeThumbnailFactory *thumbnail_factory,
-                                     const char *file_uri, const char *custom_icon, GnomeVFSFileInfo *file_info,
-                                     const char *mime_type, GnomeIconLookupFlags flags, GnomeIconLookupResultFlags *result);
+// These let us have a soft dependency on libgnomeui rather than a hard one.
+// These are just basically the prototypes of the functions in the libraries.
+typedef char* (*_GnomeIconLookup_fn)(GtkIconTheme* icon_theme,
+                                     GnomeThumbnailFactory* thumbnail_factory,
+                                     const char* file_uri,
+                                     const char* custom_icon,
+                                     GnomeVFSFileInfo* file_info,
+                                     const char* mime_type,
+                                     GnomeIconLookupFlags flags,
+                                     GnomeIconLookupResultFlags* result);
 typedef GnomeIconTheme* (*_GnomeIconThemeNew_fn)(void);
-typedef int (*_GnomeInit_fn)(const char *app_id, const char *app_version, int argc, char **argv, const struct poptOption *options,
-                             int flags, poptContext *return_ctx);
+typedef int (*_GnomeInit_fn)(const char* app_id, const char* app_version,
+                             int argc, char** argv,
+                             const struct poptOption* options,
+                             int flags, poptContext* return_ctx);
 typedef GnomeProgram* (*_GnomeProgramGet_fn)(void);
-typedef GnomeVFSResult (*_GnomeVFSGetFileInfo_fn)(const gchar *text_uri, GnomeVFSFileInfo *info, GnomeVFSFileInfoOptions options);
-typedef void (*_GnomeVFSFileInfoClear_fn)(GnomeVFSFileInfo *info);
+typedef GnomeVFSResult (*_GnomeVFSGetFileInfo_fn)(const gchar* text_uri,
+                        GnomeVFSFileInfo* info,
+                        GnomeVFSFileInfoOptions options);
+typedef void (*_GnomeVFSFileInfoClear_fn)(GnomeVFSFileInfo* info);
 
 static PRLibrary* gLibGnomeUI = nullptr;
 static PRLibrary* gLibGnome = nullptr;
 static PRLibrary* gLibGnomeVFS = nullptr;
 static bool gTriedToLoadGnomeLibs = false;
 
 static _GnomeIconLookup_fn _gnome_icon_lookup = nullptr;
 static _GnomeIconThemeNew_fn _gnome_icon_theme_new = nullptr;
 static _GnomeInit_fn _gnome_init = nullptr;
 static _GnomeProgramGet_fn _gnome_program_get = nullptr;
 static _GnomeVFSGetFileInfo_fn _gnome_vfs_get_file_info = nullptr;
 static _GnomeVFSFileInfoClear_fn _gnome_vfs_file_info_clear = nullptr;
 #endif //MOZ_ENABLE_GNOMEUI
 
 static nsresult
-moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
-                          nsIChannel **aChannel)
+moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI* aURI,
+                          nsIChannel** aChannel)
 {
   int width = gdk_pixbuf_get_width(aPixbuf);
   int height = gdk_pixbuf_get_height(aPixbuf);
   NS_ENSURE_TRUE(height < 256 && width < 256 && height > 0 && width > 0 &&
                  gdk_pixbuf_get_colorspace(aPixbuf) == GDK_COLORSPACE_RGB &&
                  gdk_pixbuf_get_bits_per_sample(aPixbuf) == 8 &&
                  gdk_pixbuf_get_has_alpha(aPixbuf) &&
                  gdk_pixbuf_get_n_channels(aPixbuf) == 4,
                  NS_ERROR_UNEXPECTED);
 
   const int n_channels = 4;
   gsize buf_size = 2 + n_channels * height * width;
-  uint8_t * const buf = (uint8_t*)NS_Alloc(buf_size);
+  uint8_t* const buf = (uint8_t*)NS_Alloc(buf_size);
   NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
-  uint8_t *out = buf;
+  uint8_t* out = buf;
 
   *(out++) = width;
   *(out++) = height;
 
-  const guchar * const pixels = gdk_pixbuf_get_pixels(aPixbuf);
+  const guchar* const pixels = gdk_pixbuf_get_pixels(aPixbuf);
   int rowextra = gdk_pixbuf_get_rowstride(aPixbuf) - width * n_channels;
 
   // encode the RGB data and the A data
-  const guchar * in = pixels;
+  const guchar* in = pixels;
   for (int y = 0; y < height; ++y, in += rowextra) {
     for (int x = 0; x < width; ++x) {
       uint8_t r = *(in++);
       uint8_t g = *(in++);
       uint8_t b = *(in++);
       uint8_t a = *(in++);
 #define DO_PREMULTIPLY(c_) uint8_t(uint16_t(c_) * uint16_t(a) / uint16_t(255))
 #if MOZ_LITTLE_ENDIAN
@@ -146,20 +155,20 @@ moz_gdk_pixbuf_to_channel(GdkPixbuf* aPi
                                   aURI,
                                   stream,
                                   nullPrincipal,
                                   nsILoadInfo::SEC_NORMAL,
                                   nsIContentPolicy::TYPE_OTHER,
                                   NS_LITERAL_CSTRING(IMAGE_ICON_MS));
 }
 
-static GtkWidget *gProtoWindow = nullptr;
-static GtkWidget *gStockImageWidget = nullptr;
+static GtkWidget* gProtoWindow = nullptr;
+static GtkWidget* gStockImageWidget = nullptr;
 #ifdef MOZ_ENABLE_GNOMEUI
-static GnomeIconTheme *gIconTheme = nullptr;
+static GnomeIconTheme* gIconTheme = nullptr;
 #endif //MOZ_ENABLE_GNOMEUI
 
 static void
 ensure_stock_image_widget()
 {
   // Only the style of the GtkImage needs to be used, but the widget is kept
   // to track dynamic style changes.
   if (!gProtoWindow) {
@@ -173,211 +182,244 @@ ensure_stock_image_widget()
     gtk_widget_ensure_style(gStockImageWidget);
   }
 }
 
 #ifdef MOZ_ENABLE_GNOMEUI
 static nsresult
 ensure_libgnomeui()
 {
-  // Attempt to get the libgnomeui symbol references. We do it this way so that stock icons from Init()
-  // don't get held back by InitWithGnome()'s libgnomeui dependency.
+  // Attempt to get the libgnomeui symbol references. We do it this way
+  // so that stock icons from Init() don't get held back by InitWithGnome()'s
+  // libgnomeui dependency.
   if (!gTriedToLoadGnomeLibs) {
     gLibGnomeUI = PR_LoadLibrary("libgnomeui-2.so.0");
-    if (!gLibGnomeUI)
+    if (!gLibGnomeUI) {
       return NS_ERROR_NOT_AVAILABLE;
+    }
 
-    _gnome_init = (_GnomeInit_fn)PR_FindFunctionSymbol(gLibGnomeUI, "gnome_init_with_popt_table");
-    _gnome_icon_theme_new = (_GnomeIconThemeNew_fn)PR_FindFunctionSymbol(gLibGnomeUI, "gnome_icon_theme_new");
-    _gnome_icon_lookup = (_GnomeIconLookup_fn)PR_FindFunctionSymbol(gLibGnomeUI, "gnome_icon_lookup");
+    _gnome_init =
+      (_GnomeInit_fn)PR_FindFunctionSymbol(gLibGnomeUI,
+                                           "gnome_init_with_popt_table");
+    _gnome_icon_theme_new =
+      (_GnomeIconThemeNew_fn)PR_FindFunctionSymbol(gLibGnomeUI,
+                                                   "gnome_icon_theme_new");
+    _gnome_icon_lookup =
+      (_GnomeIconLookup_fn)PR_FindFunctionSymbol(gLibGnomeUI,
+                                                 "gnome_icon_lookup");
 
     if (!_gnome_init || !_gnome_icon_theme_new || !_gnome_icon_lookup) {
       PR_UnloadLibrary(gLibGnomeUI);
       gLibGnomeUI = nullptr;
       return NS_ERROR_NOT_AVAILABLE;
     }
   }
 
-  if (!gLibGnomeUI)
+  if (!gLibGnomeUI) {
     return NS_ERROR_NOT_AVAILABLE;
+  }
 
   return NS_OK;
 }
 
 static nsresult
 ensure_libgnome()
 {
   if (!gTriedToLoadGnomeLibs) {
     gLibGnome = PR_LoadLibrary("libgnome-2.so.0");
-    if (!gLibGnome)
+    if (!gLibGnome) {
       return NS_ERROR_NOT_AVAILABLE;
+    }
 
-    _gnome_program_get = (_GnomeProgramGet_fn)PR_FindFunctionSymbol(gLibGnome, "gnome_program_get");
+    _gnome_program_get =
+      (_GnomeProgramGet_fn)PR_FindFunctionSymbol(gLibGnome,
+                                                 "gnome_program_get");
     if (!_gnome_program_get) {
       PR_UnloadLibrary(gLibGnome);
       gLibGnome = nullptr;
       return NS_ERROR_NOT_AVAILABLE;
     }
   }
 
-  if (!gLibGnome)
+  if (!gLibGnome) {
     return NS_ERROR_NOT_AVAILABLE;
+  }
 
   return NS_OK;
 }
 
 static nsresult
 ensure_libgnomevfs()
 {
   if (!gTriedToLoadGnomeLibs) {
     gLibGnomeVFS = PR_LoadLibrary("libgnomevfs-2.so.0");
-    if (!gLibGnomeVFS)
+    if (!gLibGnomeVFS) {
       return NS_ERROR_NOT_AVAILABLE;
+    }
 
-    _gnome_vfs_get_file_info = (_GnomeVFSGetFileInfo_fn)PR_FindFunctionSymbol(gLibGnomeVFS, "gnome_vfs_get_file_info");
-    _gnome_vfs_file_info_clear = (_GnomeVFSFileInfoClear_fn)PR_FindFunctionSymbol(gLibGnomeVFS, "gnome_vfs_file_info_clear");
+    _gnome_vfs_get_file_info =
+      (_GnomeVFSGetFileInfo_fn)PR_FindFunctionSymbol(gLibGnomeVFS,
+                                                     "gnome_vfs_get_file_info");
+    _gnome_vfs_file_info_clear =
+        (_GnomeVFSFileInfoClear_fn)PR_FindFunctionSymbol(gLibGnomeVFS,
+                                                         "gnome_vfs_file_"
+                                                         "info_clear");
     if (!_gnome_vfs_get_file_info || !_gnome_vfs_file_info_clear) {
       PR_UnloadLibrary(gLibGnomeVFS);
       gLibGnomeVFS = nullptr;
       return NS_ERROR_NOT_AVAILABLE;
     }
   }
 
-  if (!gLibGnomeVFS)
+  if (!gLibGnomeVFS) {
     return NS_ERROR_NOT_AVAILABLE;
+  }
 
   return NS_OK;
 }
 #endif //MOZ_ENABLE_GNOMEUI
 
 static GtkIconSize
-moz_gtk_icon_size(const char *name)
+moz_gtk_icon_size(const char* name)
 {
-  if (strcmp(name, "button") == 0)
+  if (strcmp(name, "button") == 0) {
     return GTK_ICON_SIZE_BUTTON;
+  }
 
-  if (strcmp(name, "menu") == 0)
+  if (strcmp(name, "menu") == 0) {
     return GTK_ICON_SIZE_MENU;
+  }
 
-  if (strcmp(name, "toolbar") == 0)
+  if (strcmp(name, "toolbar") == 0) {
     return GTK_ICON_SIZE_LARGE_TOOLBAR;
+  }
 
-  if (strcmp(name, "toolbarsmall") == 0)
+  if (strcmp(name, "toolbarsmall") == 0) {
     return GTK_ICON_SIZE_SMALL_TOOLBAR;
+  }
 
-  if (strcmp(name, "dnd") == 0)
+  if (strcmp(name, "dnd") == 0) {
     return GTK_ICON_SIZE_DND;
+  }
 
-  if (strcmp(name, "dialog") == 0)
+  if (strcmp(name, "dialog") == 0) {
     return GTK_ICON_SIZE_DIALOG;
+  }
 
   return GTK_ICON_SIZE_MENU;
 }
 
 #if defined(MOZ_ENABLE_GNOMEUI) || defined(MOZ_ENABLE_GIO)
 static int32_t
-GetIconSize(nsIMozIconURI *aIconURI)
+GetIconSize(nsIMozIconURI* aIconURI)
 {
   nsAutoCString iconSizeString;
 
   aIconURI->GetIconSize(iconSizeString);
   if (iconSizeString.IsEmpty()) {
     uint32_t size;
     mozilla::DebugOnly<nsresult> rv = aIconURI->GetImageSize(&size);
     NS_ASSERTION(NS_SUCCEEDED(rv), "GetImageSize failed");
-    return size; 
+    return size;
   } else {
     int size;
 
     GtkIconSize icon_size = moz_gtk_icon_size(iconSizeString.get());
     gtk_icon_size_lookup(icon_size, &size, nullptr);
     return size;
   }
 }
 
 /* Scale icon buffer to preferred size */
 static nsresult
-ScaleIconBuf(GdkPixbuf **aBuf, int32_t iconSize)
+ScaleIconBuf(GdkPixbuf** aBuf, int32_t iconSize)
 {
   // Scale buffer only if width or height differ from preferred size
   if (gdk_pixbuf_get_width(*aBuf)  != iconSize &&
       gdk_pixbuf_get_height(*aBuf) != iconSize) {
-    GdkPixbuf *scaled = gdk_pixbuf_scale_simple(*aBuf, iconSize, iconSize,
+    GdkPixbuf* scaled = gdk_pixbuf_scale_simple(*aBuf, iconSize, iconSize,
                                                 GDK_INTERP_BILINEAR);
     // replace original buffer by scaled
     g_object_unref(*aBuf);
     *aBuf = scaled;
-    if (!scaled)
+    if (!scaled) {
       return NS_ERROR_OUT_OF_MEMORY;
+    }
   }
   return NS_OK;
 }
 #endif
 
 #ifdef MOZ_ENABLE_GNOMEUI
 nsresult
-nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI)
+nsIconChannel::InitWithGnome(nsIMozIconURI* aIconURI)
 {
   nsresult rv;
 
-  if (NS_FAILED(ensure_libgnomeui()) || NS_FAILED(ensure_libgnome()) || NS_FAILED(ensure_libgnomevfs())) {
+  if (NS_FAILED(ensure_libgnomeui()) || NS_FAILED(ensure_libgnome()) ||
+      NS_FAILED(ensure_libgnomevfs())) {
     gTriedToLoadGnomeLibs = true;
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   gTriedToLoadGnomeLibs = true;
 
   if (!_gnome_program_get()) {
     // Get the brandShortName from the string bundle to pass to GNOME
     // as the application name.  This may be used for things such as
     // the title of grouped windows in the panel.
-    nsCOMPtr<nsIStringBundleService> bundleService = 
+    nsCOMPtr<nsIStringBundleService> bundleService =
       do_GetService(NS_STRINGBUNDLE_CONTRACTID);
 
     NS_ASSERTION(bundleService, "String bundle service must be present!");
 
     nsCOMPtr<nsIStringBundle> bundle;
     bundleService->CreateBundle("chrome://branding/locale/brand.properties",
                                 getter_AddRefs(bundle));
     nsAutoString appName;
 
     if (bundle) {
       bundle->GetStringFromName(MOZ_UTF16("brandShortName"),
                                 getter_Copies(appName));
     } else {
-      NS_WARNING("brand.properties not present, using default application name");
+      NS_WARNING(
+         "brand.properties not present, using default application name");
       appName.AssignLiteral(MOZ_UTF16("Gecko"));
     }
 
     char* empty[] = { "" };
     _gnome_init(NS_ConvertUTF16toUTF8(appName).get(),
                 "1.0", 1, empty, nullptr, 0, nullptr);
   }
 
   uint32_t iconSize = GetIconSize(aIconURI);
   nsAutoCString type;
   aIconURI->GetContentType(type);
 
   GnomeVFSFileInfo fileInfo = {0};
-  fileInfo.refcount = 1; // In case some GnomeVFS function addrefs and releases it
+  fileInfo.refcount = 1; // In case some GnomeVFS function addrefs and
+                         // releases it
 
   nsAutoCString spec;
   nsCOMPtr<nsIURL> url;
   rv = aIconURI->GetIconURL(getter_AddRefs(url));
   if (url) {
     url->GetAsciiSpec(spec);
     // Only ask gnome-vfs for a GnomeVFSFileInfo for file: uris, to avoid a
     // network request
     bool isFile;
     if (NS_SUCCEEDED(url->SchemeIs("file", &isFile)) && isFile) {
-      _gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT);
+      _gnome_vfs_get_file_info(spec.get(), &fileInfo,
+                               GNOME_VFS_FILE_INFO_DEFAULT);
     }
     else {
-      // The filename we get is UTF-8-compatible, which matches gnome expectations.
-      // See also: http://lists.gnome.org/archives/gnome-vfs-list/2004-March/msg00049.html
+      // The filename we get is UTF-8-compatible, which matches gnome
+      // expectations.
+      // See also:
+      // http://lists.gnome.org/archives/gnome-vfs-list/2004-March/msg00049.html
       // "Whenever we can detect the charset used for the URI type we try to
       //  convert it to/from utf8 automatically inside gnome-vfs."
       // I'll interpret that as "otherwise, this field is random junk".
       nsAutoCString name;
       url->GetFileName(name);
       fileInfo.name = g_strdup(name.get());
 
       if (!type.IsEmpty()) {
@@ -407,133 +449,137 @@ nsIconChannel::InitWithGnome(nsIMozIconU
     }
   }
 
   char* name = _gnome_icon_lookup(gIconTheme, nullptr, spec.get(), nullptr,
                                   &fileInfo, type.get(),
                                   GNOME_ICON_LOOKUP_FLAGS_NONE, nullptr);
 
   _gnome_vfs_file_info_clear(&fileInfo);
-  if (!name)
+  if (!name) {
     return NS_ERROR_NOT_AVAILABLE;
-  
+  }
+
   // Get the default theme associated with the screen
   // Do NOT free.
-  GtkIconTheme *theme = gtk_icon_theme_get_default();
+  GtkIconTheme* theme = gtk_icon_theme_get_default();
   if (!theme) {
     g_free(name);
     return NS_ERROR_UNEXPECTED;
   }
 
-  GError *err = nullptr;
-  GdkPixbuf* buf = gtk_icon_theme_load_icon(theme, name, iconSize, (GtkIconLookupFlags)0, &err);
+  GError* err = nullptr;
+  GdkPixbuf* buf = gtk_icon_theme_load_icon(theme, name, iconSize,
+                                            (GtkIconLookupFlags)0, &err);
   g_free(name);
 
   if (!buf) {
-    if (err)
+    if (err) {
       g_error_free(err);
+    }
     return NS_ERROR_UNEXPECTED;
   }
 
   rv = ScaleIconBuf(&buf, iconSize);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = moz_gdk_pixbuf_to_channel(buf, aIconURI,
                                  getter_AddRefs(mRealChannel));
   g_object_unref(buf);
   return rv;
 }
 #endif // MOZ_ENABLE_GNOMEUI
 
 #ifdef MOZ_ENABLE_GIO
 nsresult
-nsIconChannel::InitWithGIO(nsIMozIconURI *aIconURI)
+nsIconChannel::InitWithGIO(nsIMozIconURI* aIconURI)
 {
   GIcon *icon = nullptr;
   nsCOMPtr<nsIURL> fileURI;
 
   // Read icon content
   aIconURI->GetIconURL(getter_AddRefs(fileURI));
 
   // Get icon for file specified by URI
   if (fileURI) {
     bool isFile;
     nsAutoCString spec;
     fileURI->GetAsciiSpec(spec);
     if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) {
-      GFile *file = g_file_new_for_uri(spec.get());
-      GFileInfo *fileInfo = g_file_query_info(file,
+      GFile* file = g_file_new_for_uri(spec.get());
+      GFileInfo* fileInfo = g_file_query_info(file,
                                               G_FILE_ATTRIBUTE_STANDARD_ICON,
                                               G_FILE_QUERY_INFO_NONE,
                                               nullptr, nullptr);
       g_object_unref(file);
       if (fileInfo) {
         // icon from g_content_type_get_icon doesn't need unref
         icon = g_file_info_get_icon(fileInfo);
-        if (icon)
+        if (icon) {
           g_object_ref(icon);
+        }
         g_object_unref(fileInfo);
       }
     }
   }
-  
+
   // Try to get icon by using MIME type
   if (!icon) {
     nsAutoCString type;
     aIconURI->GetContentType(type);
     // Try to get MIME type from file extension by using nsIMIMEService
     if (type.IsEmpty()) {
       nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1"));
       if (ms) {
         nsAutoCString fileExt;
         aIconURI->GetFileExtension(fileExt);
         ms->GetTypeFromExtension(fileExt, type);
       }
     }
-    char *ctype = nullptr; // character representation of content type
+    char* ctype = nullptr; // character representation of content type
     if (!type.IsEmpty()) {
       ctype = g_content_type_from_mime_type(type.get());
     }
     if (ctype) {
       icon = g_content_type_get_icon(ctype);
       g_free(ctype);
     }
   }
 
   // Get default icon theme
-  GtkIconTheme *iconTheme = gtk_icon_theme_get_default();  
-  GtkIconInfo *iconInfo = nullptr;
+  GtkIconTheme* iconTheme = gtk_icon_theme_get_default();
+  GtkIconInfo* iconInfo = nullptr;
   // Get icon size
   int32_t iconSize = GetIconSize(aIconURI);
 
   if (icon) {
     // Use icon and theme to get GtkIconInfo
     iconInfo = gtk_icon_theme_lookup_by_gicon(iconTheme,
                                               icon, iconSize,
                                               (GtkIconLookupFlags)0);
     g_object_unref(icon);
   }
-  
+
   if (!iconInfo) {
     // Mozilla's mimetype lookup failed. Try the "unknown" icon.
     iconInfo = gtk_icon_theme_lookup_icon(iconTheme,
                                           "unknown", iconSize,
                                           (GtkIconLookupFlags)0);
     if (!iconInfo) {
       return NS_ERROR_NOT_AVAILABLE;
     }
   }
-  
+
   // Create a GdkPixbuf buffer containing icon and scale it
   GdkPixbuf* buf = gtk_icon_info_load_icon(iconInfo, nullptr);
   gtk_icon_info_free(iconInfo);
   if (!buf) {
     return NS_ERROR_UNEXPECTED;
   }
-  
+
   nsresult rv = ScaleIconBuf(&buf, iconSize);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = moz_gdk_pixbuf_to_channel(buf, aIconURI,
                                  getter_AddRefs(mRealChannel));
   g_object_unref(buf);
   return rv;
 }
@@ -545,17 +591,17 @@ nsIconChannel::Init(nsIURI* aURI)
   nsCOMPtr<nsIMozIconURI> iconURI = do_QueryInterface(aURI);
   NS_ASSERTION(iconURI, "URI is not an nsIMozIconURI");
 
   nsAutoCString stockIcon;
   iconURI->GetStockIcon(stockIcon);
   if (stockIcon.IsEmpty()) {
 #ifdef MOZ_ENABLE_GNOMEUI
     return InitWithGnome(iconURI);
-#else 
+#else
 #ifdef MOZ_ENABLE_GIO
     return InitWithGIO(iconURI);
 #else
     return NS_ERROR_NOT_AVAILABLE;
 #endif
 #endif
   }
 
@@ -587,72 +633,73 @@ nsIconChannel::Init(nsIURI* aURI)
   } else {
     // GTK versions < 2.22 use icon names from concatenating stock id with
     // -(rtl|ltr), which is how the moz-icon stock name is interpreted here.
     stockID = Substring(stockIcon, 0, stockIcon.Length() - 4);
     // However, if we lookup bidi icons by the stock name, then GTK versions
     // >= 2.22 will use a bidi lookup convention that most icon themes do not
     // yet follow.  Therefore, we first check to see if the theme supports the
     // old icon name as this will have bidi support (if found).
-    GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
+    GtkIconTheme* icon_theme = gtk_icon_theme_get_default();
     // Micking what gtk_icon_set_render_icon does with sizes, though it's not
     // critical as icons will be scaled to suit size.  It just means we follow
     // the same pathes and so share caches.
     gint width, height;
     if (gtk_icon_size_lookup(icon_size, &width, &height)) {
       gint size = std::min(width, height);
       // We use gtk_icon_theme_lookup_icon() without
       // GTK_ICON_LOOKUP_USE_BUILTIN instead of gtk_icon_theme_has_icon() so
       // we don't pick up fallback icons added by distributions for backward
       // compatibility.
-      GtkIconInfo *icon =
+      GtkIconInfo* icon =
         gtk_icon_theme_lookup_icon(icon_theme, stockIcon.get(),
                                    size, (GtkIconLookupFlags)0);
       if (icon) {
         useIconName = true;
         gtk_icon_info_free(icon);
       }
     }
   }
 
   ensure_stock_image_widget();
-  GtkStyle *style = gtk_widget_get_style(gStockImageWidget);
-  GtkIconSet *icon_set = nullptr;
+  GtkStyle* style = gtk_widget_get_style(gStockImageWidget);
+  GtkIconSet* icon_set = nullptr;
   if (!useIconName) {
     icon_set = gtk_style_lookup_icon_set(style, stockID.get());
   }
 
   if (!icon_set) {
     // Either we have choosen icon-name lookup for a bidi icon, or stockIcon is
     // not a stock id so we assume it is an icon name.
     useIconName = true;
     // Creating a GtkIconSet is a convenient way to allow the style to
     // render the icon, possibly with variations suitable for insensitive
     // states.
     icon_set = gtk_icon_set_new();
-    GtkIconSource *icon_source = gtk_icon_source_new();
-    
+    GtkIconSource* icon_source = gtk_icon_source_new();
+
     gtk_icon_source_set_icon_name(icon_source, stockIcon.get());
     gtk_icon_set_add_source(icon_set, icon_source);
     gtk_icon_source_free(icon_source);
   }
 
-  GdkPixbuf *icon =
+  GdkPixbuf* icon =
     gtk_icon_set_render_icon(icon_set, style, direction, state,
                              icon_size, gStockImageWidget, nullptr);
   if (useIconName) {
     gtk_icon_set_unref(icon_set);
   }
 
   // According to documentation, gtk_icon_set_render_icon() never returns
   // nullptr, but it does return nullptr when we have the problem reported
   // here: https://bugzilla.gnome.org/show_bug.cgi?id=629878#c13
-  if (!icon)
+  if (!icon) {
     return NS_ERROR_NOT_AVAILABLE;
-  
+  }
+
   nsresult rv = moz_gdk_pixbuf_to_channel(icon, iconURI,
                                           getter_AddRefs(mRealChannel));
 
   g_object_unref(icon);
 
   return rv;
 }
 
--- a/image/decoders/icon/gtk/nsIconChannel.h
+++ b/image/decoders/icon/gtk/nsIconChannel.h
@@ -8,45 +8,38 @@
 #include "mozilla/Attributes.h"
 
 #include "nsIChannel.h"
 #include "nsIStreamListener.h"
 #include "nsIURI.h"
 #include "nsIIconURI.h"
 #include "nsCOMPtr.h"
 
-/**
- * This class is the gnome implementation of nsIconChannel. It basically asks
- * gtk/gnome for an icon, saves it as a tmp icon, and creates a new channel for
- * that file to which all calls will be proxied.
- */
-class nsIconChannel MOZ_FINAL : public nsIChannel {
+/// This class is the gnome implementation of nsIconChannel. It basically asks
+/// gtk/gnome for an icon, saves it as a tmp icon, and creates a new channel for
+/// that file to which all calls will be proxied.
+class nsIconChannel MOZ_FINAL : public nsIChannel
+{
   public:
     NS_DECL_ISUPPORTS
     NS_FORWARD_NSIREQUEST(mRealChannel->)
     NS_FORWARD_NSICHANNEL(mRealChannel->)
 
-    nsIconChannel() {}
+    nsIconChannel() { }
 
     static void Shutdown();
 
-    /**
-     * Called by nsIconProtocolHandler after it creates this channel.
-     * Must be called before calling any other function on this object.
-     * If this method fails, no other function must be called on this object.
-     */
+    /// Called by nsIconProtocolHandler after it creates this channel.
+    /// Must be called before calling any other function on this object.
+    /// If this method fails, no other function must be called on this object.
     nsresult Init(nsIURI* aURI);
   private:
-    ~nsIconChannel() {}
-    /**
-     * The channel to the temp icon file (e.g. to /tmp/2qy9wjqw.html).
-     * Will always be non-null after a successful Init.
-     */
+    ~nsIconChannel() { }
+    /// The channel to the temp icon file (e.g. to /tmp/2qy9wjqw.html).
+    /// Will always be non-null after a successful Init.
     nsCOMPtr<nsIChannel> mRealChannel;
 
-    /**
-     * Called by Init if we need to use the gnomeui library.
-     */
-    nsresult InitWithGnome(nsIMozIconURI *aURI);
-    nsresult InitWithGIO(nsIMozIconURI *aIconURI);
+    /// Called by Init if we need to use the gnomeui library.
+    nsresult InitWithGnome(nsIMozIconURI* aURI);
+    nsresult InitWithGIO(nsIMozIconURI* aIconURI);
 };
 
 #endif
--- a/image/decoders/icon/mac/nsIconChannel.h
+++ b/image/decoders/icon/mac/nsIconChannel.h
@@ -35,24 +35,26 @@ public:
 
   nsresult Init(nsIURI* uri);
 
 protected:
   virtual ~nsIconChannel();
 
   nsCOMPtr<nsIURI> mUrl;
   nsCOMPtr<nsIURI> mOriginalURI;
-  int64_t          mContentLength;
+  int64_t mContentLength;
   nsCOMPtr<nsILoadGroup> mLoadGroup;
   nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
   nsCOMPtr<nsISupports>  mOwner;
   nsCOMPtr<nsILoadInfo>  mLoadInfo;
-  
+
   nsCOMPtr<nsIInputStreamPump> mPump;
   nsCOMPtr<nsIStreamListener>  mListener;
-  
+
   nsresult MakeInputStream(nsIInputStream** _retval, bool nonBlocking);
-  
-  nsresult ExtractIconInfoFromUrl(nsIFile ** aLocalFile, uint32_t * aDesiredImageSize,
-                           nsACString &aContentType, nsACString &aFileExtension);
+
+  nsresult ExtractIconInfoFromUrl(nsIFile** aLocalFile,
+                                  uint32_t* aDesiredImageSize,
+                                  nsACString& aContentType,
+                                  nsACString& aFileExtension);
 };
 
 #endif /* nsIconChannel_h___ */
--- a/image/decoders/icon/mac/nsIconChannelCocoa.mm
+++ b/image/decoders/icon/mac/nsIconChannelCocoa.mm
@@ -26,202 +26,231 @@
 
 #include <Cocoa/Cocoa.h>
 
 // nsIconChannel methods
 nsIconChannel::nsIconChannel()
 {
 }
 
-nsIconChannel::~nsIconChannel() 
+nsIconChannel::~nsIconChannel()
 {
   if (mLoadInfo) {
     nsCOMPtr<nsIThread> mainThread;
     NS_GetMainThread(getter_AddRefs(mainThread));
 
-    nsILoadInfo *forgetableLoadInfo;
+    nsILoadInfo* forgetableLoadInfo;
     mLoadInfo.forget(&forgetableLoadInfo);
     NS_ProxyRelease(mainThread, forgetableLoadInfo, false);
   }
 }
 
-NS_IMPL_ISUPPORTS(nsIconChannel, 
-                  nsIChannel, 
+NS_IMPL_ISUPPORTS(nsIconChannel,
+                  nsIChannel,
                   nsIRequest,
-			       nsIRequestObserver,
-			       nsIStreamListener)
+                  nsIRequestObserver,
+                  nsIStreamListener)
 
-nsresult nsIconChannel::Init(nsIURI* uri)
+nsresult
+nsIconChannel::Init(nsIURI* uri)
 {
   NS_ASSERTION(uri, "no uri");
   mUrl = uri;
   mOriginalURI = uri;
   nsresult rv;
   mPump = do_CreateInstance(NS_INPUTSTREAMPUMP_CONTRACTID, &rv);
   return rv;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIRequest methods:
 
-NS_IMETHODIMP nsIconChannel::GetName(nsACString &result)
+NS_IMETHODIMP
+nsIconChannel::GetName(nsACString& result)
 {
   return mUrl->GetSpec(result);
 }
 
-NS_IMETHODIMP nsIconChannel::IsPending(bool *result)
+NS_IMETHODIMP
+nsIconChannel::IsPending(bool* result)
 {
   return mPump->IsPending(result);
 }
 
-NS_IMETHODIMP nsIconChannel::GetStatus(nsresult *status)
+NS_IMETHODIMP
+nsIconChannel::GetStatus(nsresult* status)
 {
   return mPump->GetStatus(status);
 }
 
-NS_IMETHODIMP nsIconChannel::Cancel(nsresult status)
+NS_IMETHODIMP
+nsIconChannel::Cancel(nsresult status)
 {
   return mPump->Cancel(status);
 }
 
-NS_IMETHODIMP nsIconChannel::Suspend(void)
+NS_IMETHODIMP
+nsIconChannel::Suspend(void)
 {
   return mPump->Suspend();
 }
 
-NS_IMETHODIMP nsIconChannel::Resume(void)
+NS_IMETHODIMP
+nsIconChannel::Resume(void)
 {
   return mPump->Resume();
 }
 
 // nsIRequestObserver methods
-NS_IMETHODIMP nsIconChannel::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
+NS_IMETHODIMP
+nsIconChannel::OnStartRequest(nsIRequest* aRequest,
+                                            nsISupports* aContext)
 {
-  if (mListener)
+  if (mListener) {
     return mListener->OnStartRequest(this, aContext);
+  }
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext, nsresult aStatus)
+NS_IMETHODIMP
+nsIconChannel::OnStopRequest(nsIRequest* aRequest,
+                                           nsISupports* aContext,
+                                           nsresult aStatus)
 {
   if (mListener) {
     mListener->OnStopRequest(this, aContext, aStatus);
     mListener = nullptr;
   }
 
   // Remove from load group
-  if (mLoadGroup)
+  if (mLoadGroup) {
     mLoadGroup->RemoveRequest(this, nullptr, aStatus);
+  }
 
   return NS_OK;
 }
 
 // nsIStreamListener methods
-NS_IMETHODIMP nsIconChannel::OnDataAvailable(nsIRequest* aRequest,
+NS_IMETHODIMP
+nsIconChannel::OnDataAvailable(nsIRequest* aRequest,
                                              nsISupports* aContext,
                                              nsIInputStream* aStream,
                                              uint64_t aOffset,
                                              uint32_t aCount)
 {
-  if (mListener)
+  if (mListener) {
     return mListener->OnDataAvailable(this, aContext, aStream, aOffset, aCount);
+  }
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIChannel methods:
 
-NS_IMETHODIMP nsIconChannel::GetOriginalURI(nsIURI* *aURI)
+NS_IMETHODIMP
+nsIconChannel::GetOriginalURI(nsIURI** aURI)
 {
   *aURI = mOriginalURI;
   NS_ADDREF(*aURI);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetOriginalURI(nsIURI* aURI)
+NS_IMETHODIMP
+nsIconChannel::SetOriginalURI(nsIURI* aURI)
 {
   NS_ENSURE_ARG_POINTER(aURI);
   mOriginalURI = aURI;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetURI(nsIURI* *aURI)
+NS_IMETHODIMP
+nsIconChannel::GetURI(nsIURI** aURI)
 {
   *aURI = mUrl;
   NS_IF_ADDREF(*aURI);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsIconChannel::Open(nsIInputStream **_retval)
+nsIconChannel::Open(nsIInputStream** _retval)
 {
   return MakeInputStream(_retval, false);
 }
 
-nsresult nsIconChannel::ExtractIconInfoFromUrl(nsIFile ** aLocalFile, uint32_t * aDesiredImageSize, nsACString &aContentType, nsACString &aFileExtension)
+nsresult
+nsIconChannel::ExtractIconInfoFromUrl(nsIFile** aLocalFile,
+                                               uint32_t* aDesiredImageSize,
+                                               nsACString& aContentType,
+                                               nsACString& aFileExtension)
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMozIconURI> iconURI (do_QueryInterface(mUrl, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   iconURI->GetImageSize(aDesiredImageSize);
   iconURI->GetContentType(aContentType);
   iconURI->GetFileExtension(aFileExtension);
-  
+
   nsCOMPtr<nsIURL> url;
   rv = iconURI->GetIconURL(getter_AddRefs(url));
   if (NS_FAILED(rv) || !url) return NS_OK;
 
   nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(url, &rv);
   if (NS_FAILED(rv) || !fileURL) return NS_OK;
 
   nsCOMPtr<nsIFile> file;
   rv = fileURL->GetFile(getter_AddRefs(file));
   if (NS_FAILED(rv) || !file) return NS_OK;
-  
+
   nsCOMPtr<nsILocalFileMac> localFileMac (do_QueryInterface(file, &rv));
   if (NS_FAILED(rv) || !localFileMac) return NS_OK;
-  
+
   *aLocalFile = file;
   NS_IF_ADDREF(*aLocalFile);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
+NS_IMETHODIMP
+nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
+                                       nsISupports* ctxt)
 {
   nsCOMPtr<nsIInputStream> inStream;
   nsresult rv = MakeInputStream(getter_AddRefs(inStream), true);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Init our stream pump
   rv = mPump->Init(inStream, int64_t(-1), int64_t(-1), 0, 0, false);
   NS_ENSURE_SUCCESS(rv, rv);
-  
+
   rv = mPump->AsyncRead(this, ctxt);
   if (NS_SUCCEEDED(rv)) {
     // Store our real listener
     mListener = aListener;
     // Add ourself to the load group, if available
-    if (mLoadGroup)
+    if (mLoadGroup) {
       mLoadGroup->AddRequest(this, nullptr);
+    }
   }
 
   return rv;
 }
 
-nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, bool nonBlocking)
+nsresult
+nsIconChannel::MakeInputStream(nsIInputStream** _retval,
+                                        bool aNonBlocking)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   nsXPIDLCString contentType;
   nsAutoCString fileExt;
   nsCOMPtr<nsIFile> fileloc; // file we want an icon for
   uint32_t desiredImageSize;
-  nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(fileloc), &desiredImageSize, contentType, fileExt);
+  nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(fileloc),
+                                       &desiredImageSize, contentType, fileExt);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool fileExists = false;
   if (fileloc) {
     // ensure that we DO NOT resolve aliases, very important for file views
     fileloc->SetFollowLinks(false);
     fileloc->Exists(&fileExists);
   }
@@ -230,65 +259,75 @@ nsresult nsIconChannel::MakeInputStream(
 
   // first try to get the icon from the file if it exists
   if (fileExists) {
     nsCOMPtr<nsILocalFileMac> localFileMac(do_QueryInterface(fileloc, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
 
     CFURLRef macURL;
     if (NS_SUCCEEDED(localFileMac->GetCFURL(&macURL))) {
-      iconImage = [[NSWorkspace sharedWorkspace] iconForFile:[(NSURL*)macURL path]];
+      iconImage = [[NSWorkspace sharedWorkspace]
+                   iconForFile:[(NSURL*)macURL path]];
       ::CFRelease(macURL);
     }
   }
 
   // if we don't have an icon yet try to get one by extension
   if (!iconImage && !fileExt.IsEmpty()) {
     NSString* fileExtension = [NSString stringWithUTF8String:fileExt.get()];
     iconImage = [[NSWorkspace sharedWorkspace] iconForFileType:fileExtension];
   }
 
   // If we still don't have an icon, get the generic document icon.
-  if (!iconImage)
-    iconImage = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeUnknown];
+  if (!iconImage) {
+    iconImage = [[NSWorkspace sharedWorkspace]
+                 iconForFileType:NSFileTypeUnknown];
+  }
 
-  if (!iconImage)
+  if (!iconImage) {
     return NS_ERROR_FAILURE;
+  }
 
   // we have an icon now, size it
   NSRect desiredSizeRect = NSMakeRect(0, 0, desiredImageSize, desiredImageSize);
   [iconImage setSize:desiredSizeRect.size];
 
   [iconImage lockFocus];
-  NSBitmapImageRep* bitmapRep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect:desiredSizeRect] autorelease];
+  NSBitmapImageRep* bitmapRep = [[[NSBitmapImageRep alloc]
+                                  initWithFocusedViewRect:desiredSizeRect]
+                                  autorelease];
   [iconImage unlockFocus];
 
   // we expect the following things to be true about our bitmapRep
   NS_ENSURE_TRUE(![bitmapRep isPlanar] &&
-                 // Not necessarily: on a HiDPI-capable system, we'll get a 2x bitmap
-                 // (unsigned int)[bitmapRep bytesPerPlane] == desiredImageSize * desiredImageSize * 4 &&
+                 // Not necessarily: on a HiDPI-capable system, we'll get
+                 // a 2x bitmap
+                 // (unsigned int)[bitmapRep bytesPerPlane] ==
+                 //    desiredImageSize * desiredImageSize * 4 &&
                  [bitmapRep bitsPerPixel] == 32 &&
                  [bitmapRep samplesPerPixel] == 4 &&
                  [bitmapRep hasAlpha] == YES,
                  NS_ERROR_UNEXPECTED);
 
   // check what size we actually got, and ensure it isn't too big to return
   uint32_t actualImageSize = [bitmapRep bytesPerRow] / 4;
   NS_ENSURE_TRUE(actualImageSize < 256, NS_ERROR_UNEXPECTED);
 
   // now we can validate the amount of data
-  NS_ENSURE_TRUE((unsigned int)[bitmapRep bytesPerPlane] == actualImageSize * actualImageSize * 4,
+  NS_ENSURE_TRUE((unsigned int)[bitmapRep bytesPerPlane] ==
+                 actualImageSize * actualImageSize * 4,
                  NS_ERROR_UNEXPECTED);
 
   // rgba, pre-multiplied data
   uint8_t* bitmapRepData = (uint8_t*)[bitmapRep bitmapData];
 
   // create our buffer
   int32_t bufferCapacity = 2 + [bitmapRep bytesPerPlane];
-  nsAutoTArray<uint8_t, 3 + 16 * 16 * 5> iconBuffer; // initial size is for 16x16
+  nsAutoTArray<uint8_t, 3 + 16 * 16 * 5> iconBuffer; // initial size is for
+                                                     // 16x16
   iconBuffer.SetLength(bufferCapacity);
 
   uint8_t* iconBufferPtr = iconBuffer.Elements();
 
   // write header data into buffer
   *iconBufferPtr++ = actualImageSize;
   *iconBufferPtr++ = actualImageSize;
 
@@ -319,162 +358,184 @@ nsresult nsIconChannel::MakeInputStream(
 
   NS_ASSERTION(iconBufferPtr == iconBuffer.Elements() + bufferCapacity,
                "buffer size miscalculation");
 
   // Now, create a pipe and stuff our data into it
   nsCOMPtr<nsIInputStream> inStream;
   nsCOMPtr<nsIOutputStream> outStream;
   rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(outStream),
-                  bufferCapacity, bufferCapacity, nonBlocking);
+                  bufferCapacity, bufferCapacity, aNonBlocking);
 
   if (NS_SUCCEEDED(rv)) {
     uint32_t written;
-    rv = outStream->Write((char*)iconBuffer.Elements(), bufferCapacity, &written);
-    if (NS_SUCCEEDED(rv))
+    rv = outStream->Write((char*)iconBuffer.Elements(), bufferCapacity,
+                          &written);
+    if (NS_SUCCEEDED(rv)) {
       NS_IF_ADDREF(*_retval = inStream);
+    }
   }
 
   // Drop notification callbacks to prevent cycles.
   mCallbacks = nullptr;
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
-NS_IMETHODIMP nsIconChannel::GetLoadFlags(uint32_t *aLoadAttributes)
+NS_IMETHODIMP
+nsIconChannel::GetLoadFlags(uint32_t* aLoadAttributes)
 {
   return mPump->GetLoadFlags(aLoadAttributes);
 }
 
-NS_IMETHODIMP nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes)
+NS_IMETHODIMP
+nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes)
 {
   return mPump->SetLoadFlags(aLoadAttributes);
 }
 
-NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType) 
+NS_IMETHODIMP
+nsIconChannel::GetContentType(nsACString& aContentType)
 {
   aContentType.AssignLiteral(IMAGE_ICON_MS);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsIconChannel::SetContentType(const nsACString &aContentType)
-{
-  //It doesn't make sense to set the content-type on this type
-  // of channel...
-  return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP nsIconChannel::GetContentCharset(nsACString &aContentCharset) 
-{
-  aContentCharset.AssignLiteral(IMAGE_ICON_MS);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsIconChannel::SetContentCharset(const nsACString &aContentCharset)
+nsIconChannel::SetContentType(const nsACString& aContentType)
 {
   //It doesn't make sense to set the content-type on this type
   // of channel...
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::GetContentDisposition(uint32_t *aContentDisposition)
+nsIconChannel::GetContentCharset(nsACString& aContentCharset)
+{
+  aContentCharset.AssignLiteral(IMAGE_ICON_MS);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsIconChannel::SetContentCharset(const nsACString& aContentCharset)
+{
+  //It doesn't make sense to set the content-type on this type
+  // of channel...
+  return NS_ERROR_FAILURE;
+}
+
+NS_IMETHODIMP
+nsIconChannel::GetContentDisposition(uint32_t* aContentDisposition)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
 nsIconChannel::SetContentDisposition(uint32_t aContentDisposition)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
+nsIconChannel::
+  GetContentDispositionFilename(nsAString& aContentDispositionFilename)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename)
+nsIconChannel::
+  SetContentDispositionFilename(const nsAString& aContentDispositionFilename)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
+nsIconChannel::
+  GetContentDispositionHeader(nsACString& aContentDispositionHeader)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
-NS_IMETHODIMP nsIconChannel::GetContentLength(int64_t *aContentLength)
+NS_IMETHODIMP
+nsIconChannel::GetContentLength(int64_t* aContentLength)
 {
   *aContentLength = mContentLength;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetContentLength(int64_t aContentLength)
+NS_IMETHODIMP
+nsIconChannel::SetContentLength(int64_t aContentLength)
 {
   NS_NOTREACHED("nsIconChannel::SetContentLength");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP nsIconChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
+NS_IMETHODIMP
+nsIconChannel::GetLoadGroup(nsILoadGroup** aLoadGroup)
 {
   *aLoadGroup = mLoadGroup;
   NS_IF_ADDREF(*aLoadGroup);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
+NS_IMETHODIMP
+nsIconChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
 {
   mLoadGroup = aLoadGroup;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetOwner(nsISupports* *aOwner)
+NS_IMETHODIMP
+nsIconChannel::GetOwner(nsISupports** aOwner)
 {
   *aOwner = mOwner.get();
   NS_IF_ADDREF(*aOwner);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetOwner(nsISupports* aOwner)
+NS_IMETHODIMP
+nsIconChannel::SetOwner(nsISupports* aOwner)
 {
   mOwner = aOwner;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetLoadInfo(nsILoadInfo* *aLoadInfo)
+NS_IMETHODIMP
+nsIconChannel::GetLoadInfo(nsILoadInfo** aLoadInfo)
 {
   NS_IF_ADDREF(*aLoadInfo = mLoadInfo);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
+NS_IMETHODIMP
+nsIconChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
 {
   mLoadInfo = aLoadInfo;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
+NS_IMETHODIMP
+nsIconChannel::
+  GetNotificationCallbacks(nsIInterfaceRequestor** aNotificationCallbacks)
 {
   *aNotificationCallbacks = mCallbacks.get();
   NS_IF_ADDREF(*aNotificationCallbacks);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
+NS_IMETHODIMP
+nsIconChannel::
+  SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
 {
   mCallbacks = aNotificationCallbacks;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
+NS_IMETHODIMP
+nsIconChannel::GetSecurityInfo(nsISupports** aSecurityInfo)
 {
   *aSecurityInfo = nullptr;
   return NS_OK;
 }
 
--- a/image/decoders/icon/nsIIconURI.idl
+++ b/image/decoders/icon/nsIIconURI.idl
@@ -9,87 +9,63 @@
   /**
    * nsIIconURI
    *
    * This interface derives from nsIURI, to provide additional information
    * about moz-icon URIs.
    *
    * What *is* a moz-icon URI you ask?  Well, it has the following syntax:
    *
-   * moz-icon:[<valid-url> | //<file-with-extension> | //stock/<stock-icon>]? ['?'[<parameter-value-pairs>]]
+   * moz-icon:[<valid-url> | //<file-with-extension> | //stock/<stock-icon>]?
+   *            ['?'[<parameter-value-pairs>]]
    *
    * <valid-url> is a valid URL spec.
    *
    * <file-with-extension> is any filename with an extension, e.g. "dummy.html".
-   * If the file you want an icon for isn't known to exist, you can use this instead of a URL and just
-   * place a dummy file name with the extension or content type you want.
+   * If the file you want an icon for isn't known to exist, you can use this
+   * instead of a URL and just place a dummy file name with the extension or
+   * content type you want.
    *
    * <stock-icon> is the name of a platform-dependant stock icon.
    *
    * Legal parameter value pairs are listed below:
    *
    *   Parameter:   size
-   *   Values:      [<integer> | button | toolbar | toolbarsmall | menu | dialog]
-   *   Description: If integer, this is the desired size in square pixels of the icon
+   *   Values:      [<integer> | button | toolbar | toolbarsmall | menu |
+   *                 dialog]
+   *   Description: If integer, this is the desired size in square pixels of
+   *                the icon
    *                Else, use the OS default for the specified keyword context.
    *
    *   Parameter:   state
    *   Values:      [normal | disabled]
    *   Description: The state of the icon.
    *
    *   Parameter:   contentType
    *   Values:      <mime-type>
-   *   Description: The mime type we want an icon for. This is ignored by stock images.
+   *   Description: The mime type we want an icon for. This is ignored by
+   *                stock images.
    */
 
 [scriptable, uuid(da53adda-cbe3-41bc-a57d-fdd7a0ff448b)]
-interface nsIMozIconURI : nsIURI 
+interface nsIMozIconURI : nsIURI
 {
-  /**
-   * iconFile
-   *
-   * the file URL contained within this moz-icon url, or null.
-   */
+  /// iconFile: the file URL contained within this moz-icon url, or null.
   attribute nsIURL iconURL;
 
-  /**
-   * imageSize
-   *
-   * The image area in square pixels, defaulting to 16 if unspecified.
-   */
+  /// imageSize: The image area in square pixels, defaults to 16 if unspecified.
   attribute unsigned long imageSize;
 
-  /**
-   * stockIcon
-   *
-   * The stock icon name requested from the OS.
-   */
+  /// stockIcon: The stock icon name requested from the OS.
    readonly attribute ACString stockIcon;
 
-  /**
-   * iconSize
-   *
-   * The stock icon size requested from the OS.
-   */
+  /// iconSize: The stock icon size requested from the OS.
    readonly attribute ACString iconSize;
 
-  /**
-   * iconState
-   *
-   * The stock icon state requested from the OS.
-   */
+  /// iconState: The stock icon state requested from the OS.
    readonly attribute ACString iconState;
 
-  /**
-   * contentType
-   *
-   * A valid mime type, or the empty string.
-   */
-
+  /// contentType: A valid mime type, or the empty string.
   attribute ACString contentType;
 
-  /**
-   * fileExtension
-   *
-   * The file extension of the file which we are looking up.
-   */
+  /// fileExtension: The file extension of the file which we are looking up.
   readonly attribute ACString fileExtension;
 };
--- a/image/decoders/icon/nsIconModule.cpp
+++ b/image/decoders/icon/nsIconModule.cpp
@@ -7,20 +7,21 @@
 #include "mozilla/ModuleUtils.h"
 #include "nsServiceManagerUtils.h"
 
 #include "nsIconProtocolHandler.h"
 #include "nsIconURI.h"
 #include "nsIconChannel.h"
 
 // objects that just require generic constructors
-/******************************************************************************
- * Protocol CIDs
- */
-#define NS_ICONPROTOCOL_CID   { 0xd0f9db12, 0x249c, 0x11d5, { 0x99, 0x5, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b } } 
+//*****************************************************************************
+// Protocol CIDs
+
+#define NS_ICONPROTOCOL_CID { 0xd0f9db12, 0x249c, 0x11d5, \
+                              { 0x99, 0x5, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b } }
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsIconProtocolHandler)
 
 NS_DEFINE_NAMED_CID(NS_ICONPROTOCOL_CID);
 
 static const mozilla::Module::CIDEntry kIconCIDs[] = {
   { &kNS_ICONPROTOCOL_CID, false, nullptr, nsIconProtocolHandlerConstructor },
   { nullptr }
--- a/image/decoders/icon/nsIconProtocolHandler.cpp
+++ b/image/decoders/icon/nsIconProtocolHandler.cpp
@@ -9,63 +9,70 @@
 #include "nsIconProtocolHandler.h"
 #include "nsIURL.h"
 #include "nsCRT.h"
 #include "nsCOMPtr.h"
 #include "nsIComponentManager.h"
 #include "nsIServiceManager.h"
 #include "nsNetCID.h"
 
-////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
 
-nsIconProtocolHandler::nsIconProtocolHandler() 
-{
-}
+nsIconProtocolHandler::nsIconProtocolHandler()
+{ }
 
-nsIconProtocolHandler::~nsIconProtocolHandler() 
-{}
+nsIconProtocolHandler::~nsIconProtocolHandler()
+{ }
 
-NS_IMPL_ISUPPORTS(nsIconProtocolHandler, nsIProtocolHandler, nsISupportsWeakReference)
+NS_IMPL_ISUPPORTS(nsIconProtocolHandler, nsIProtocolHandler,
+                  nsISupportsWeakReference)
 
-    
-////////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////
 // nsIProtocolHandler methods:
 
-NS_IMETHODIMP nsIconProtocolHandler::GetScheme(nsACString &result) 
+NS_IMETHODIMP
+nsIconProtocolHandler::GetScheme(nsACString& result)
 {
   result = "moz-icon";
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconProtocolHandler::GetDefaultPort(int32_t *result) 
+NS_IMETHODIMP
+nsIconProtocolHandler::GetDefaultPort(int32_t* result)
 {
   *result = 0;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconProtocolHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
+NS_IMETHODIMP
+nsIconProtocolHandler::AllowPort(int32_t port,
+                                 const char* scheme,
+                                 bool* _retval)
 {
-    // don't override anything.  
+    // don't override anything.
     *_retval = false;
     return NS_OK;
 }
 
-NS_IMETHODIMP nsIconProtocolHandler::GetProtocolFlags(uint32_t *result)
+NS_IMETHODIMP
+nsIconProtocolHandler::GetProtocolFlags(uint32_t* result)
 {
   *result = URI_NORELATIVE | URI_NOAUTH | URI_IS_UI_RESOURCE |
             URI_IS_LOCAL_RESOURCE;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconProtocolHandler::NewURI(const nsACString &aSpec,
-                                            const char *aOriginCharset, // ignored
-                                            nsIURI *aBaseURI,
-                                            nsIURI **result) 
+NS_IMETHODIMP
+nsIconProtocolHandler::NewURI(const nsACString& aSpec,
+                              const char* aOriginCharset, // ignored
+                              nsIURI* aBaseURI,
+                              nsIURI** result)
 {
-  
+
   nsCOMPtr<nsIURI> uri = new nsMozIconURI();
   if (!uri) return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv = uri->SetSpec(aSpec);
   if (NS_FAILED(rv)) return rv;
 
   NS_ADDREF(*result = uri);
   return NS_OK;
@@ -73,28 +80,30 @@ NS_IMETHODIMP nsIconProtocolHandler::New
 
 NS_IMETHODIMP
 nsIconProtocolHandler::NewChannel2(nsIURI* url,
                                    nsILoadInfo* aLoadInfo,
                                    nsIChannel** result)
 {
   NS_ENSURE_ARG_POINTER(url);
   nsIconChannel* channel = new nsIconChannel;
-  if (!channel)
+  if (!channel) {
     return NS_ERROR_OUT_OF_MEMORY;
+  }
   NS_ADDREF(channel);
 
   nsresult rv = channel->Init(url);
   if (NS_FAILED(rv)) {
     NS_RELEASE(channel);
     return rv;
   }
 
   *result = channel;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconProtocolHandler::NewChannel(nsIURI* url, nsIChannel* *result)
+NS_IMETHODIMP
+nsIconProtocolHandler::NewChannel(nsIURI* url, nsIChannel** result)
 {
   return NewChannel2(url, nullptr, result);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/image/decoders/icon/nsIconProtocolHandler.h
+++ b/image/decoders/icon/nsIconProtocolHandler.h
@@ -4,17 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsIconProtocolHandler_h___
 #define nsIconProtocolHandler_h___
 
 #include "nsWeakReference.h"
 #include "nsIProtocolHandler.h"
 
-class nsIconProtocolHandler : public nsIProtocolHandler, public nsSupportsWeakReference
+class nsIconProtocolHandler : public nsIProtocolHandler,
+                              public nsSupportsWeakReference
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIPROTOCOLHANDLER
 
     // nsIconProtocolHandler methods:
     nsIconProtocolHandler();
 
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -23,564 +23,562 @@ using namespace mozilla;
 #elif defined(PATH_MAX)
 #define SANE_FILE_NAME_LEN PATH_MAX
 #else
 #define SANE_FILE_NAME_LEN 1024
 #endif
 
 // helper function for parsing out attributes like size, and contentType
 // from the icon url.
-static void extractAttributeValue(const char * searchString, const char * attributeName, nsCString& aResult);
- 
-static const char *kSizeStrings[] =
+static void extractAttributeValue(const char* aSearchString,
+                                  const char* aAttributeName,
+                                  nsCString& aResult);
+
+static const char* kSizeStrings[] =
 {
   "button",
   "toolbar",
   "toolbarsmall",
   "menu",
   "dnd",
   "dialog"
 };
 
-static const char *kStateStrings[] =
+static const char* kStateStrings[] =
 {
   "normal",
   "disabled"
 };
 
 ////////////////////////////////////////////////////////////////////////////////
- 
+
 nsMozIconURI::nsMozIconURI()
   : mSize(DEFAULT_IMAGE_SIZE),
     mIconSize(-1),
     mIconState(-1)
-{
-}
- 
+{ }
+
 nsMozIconURI::~nsMozIconURI()
-{
-}
+{ }
 
 NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI)
 
 #define MOZICON_SCHEME "moz-icon:"
 #define MOZICON_SCHEME_LEN (sizeof(MOZICON_SCHEME) - 1)
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIURI methods:
 
 NS_IMETHODIMP
-nsMozIconURI::GetSpec(nsACString &aSpec)
+nsMozIconURI::GetSpec(nsACString& aSpec)
 {
   aSpec = MOZICON_SCHEME;
 
-  if (mIconURL)
-  {
+  if (mIconURL) {
     nsAutoCString fileIconSpec;
     nsresult rv = mIconURL->GetSpec(fileIconSpec);
     NS_ENSURE_SUCCESS(rv, rv);
     aSpec += fileIconSpec;
-  }
-  else if (!mStockIcon.IsEmpty())
-  {
+  } else if (!mStockIcon.IsEmpty()) {
     aSpec += "//stock/";
     aSpec += mStockIcon;
-  }
-  else
-  {
+  } else {
     aSpec += "//";
     aSpec += mFileName;
   }
 
   aSpec += "?size=";
-  if (mIconSize >= 0)
-  {
+  if (mIconSize >= 0) {
     aSpec += kSizeStrings[mIconSize];
-  }
-  else
-  {
+  } else {
     char buf[20];
     PR_snprintf(buf, sizeof(buf), "%d", mSize);
     aSpec.Append(buf);
   }
 
   if (mIconState >= 0) {
     aSpec += "&state=";
     aSpec += kStateStrings[mIconState];
   }
 
-  if (!mContentType.IsEmpty())
-  {
+  if (!mContentType.IsEmpty()) {
     aSpec += "&contentType=";
     aSpec += mContentType.get();
   }
-  
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetSpecIgnoringRef(nsACString &result)
+nsMozIconURI::GetSpecIgnoringRef(nsACString& result)
 {
   return GetSpec(result);
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetHasRef(bool *result)
+nsMozIconURI::GetHasRef(bool* result)
 {
   *result = false;
   return NS_OK;
 }
 
-// takes a string like ?size=32&contentType=text/html and returns a new string 
+// takes a string like ?size=32&contentType=text/html and returns a new string
 // containing just the attribute value. i.e you could pass in this string with
 // an attribute name of 'size=', this will return 32
 // Assumption: attribute pairs in the string are separated by '&'.
-void extractAttributeValue(const char * searchString, const char * attributeName, nsCString& result)
+void
+extractAttributeValue(const char* aSearchString,
+                           const char* aAttributeName,
+                           nsCString& aResult)
 {
   //NS_ENSURE_ARG_POINTER(extractAttributeValue);
 
-  result.Truncate();
+  aResult.Truncate();
 
-  if (searchString && attributeName)
-  {
+  if (aSearchString && aAttributeName) {
     // search the string for attributeName
-    uint32_t attributeNameSize = strlen(attributeName);
-    const char * startOfAttribute = PL_strcasestr(searchString, attributeName);
+    uint32_t attributeNameSize = strlen(aAttributeName);
+    const char* startOfAttribute = PL_strcasestr(aSearchString, aAttributeName);
     if (startOfAttribute &&
-       ( *(startOfAttribute-1) == '?' || *(startOfAttribute-1) == '&') )
-    {
+       ( *(startOfAttribute-1) == '?' || *(startOfAttribute-1) == '&') ) {
       startOfAttribute += attributeNameSize; // skip over the attributeName
-      if (*startOfAttribute) // is there something after the attribute name
-      {
-        const char * endofAttribute = strchr(startOfAttribute, '&');
-        if (endofAttribute)
-          result.Assign(Substring(startOfAttribute, endofAttribute));
-        else
-          result.Assign(startOfAttribute);
+      // is there something after the attribute name
+      if (*startOfAttribute) {
+        const char* endofAttribute = strchr(startOfAttribute, '&');
+        if (endofAttribute) {
+          aResult.Assign(Substring(startOfAttribute, endofAttribute));
+        } else {
+          aResult.Assign(startOfAttribute);
+        }
       } // if we have a attribute value
     } // if we have a attribute name
   } // if we got non-null search string and attribute name values
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetSpec(const nsACString &aSpec)
+nsMozIconURI::SetSpec(const nsACString& aSpec)
 {
   // Reset everything to default values.
   mIconURL = nullptr;
   mSize = DEFAULT_IMAGE_SIZE;
   mContentType.Truncate();
   mFileName.Truncate();
   mStockIcon.Truncate();
   mIconSize = -1;
   mIconState = -1;
 
   nsAutoCString iconSpec(aSpec);
-  if (!Substring(iconSpec, 0, MOZICON_SCHEME_LEN).EqualsLiteral(MOZICON_SCHEME))
+  if (!Substring(iconSpec, 0,
+                 MOZICON_SCHEME_LEN).EqualsLiteral(MOZICON_SCHEME)) {
     return NS_ERROR_MALFORMED_URI;
+  }
 
   int32_t questionMarkPos = iconSpec.Find("?");
-  if (questionMarkPos != -1 && static_cast<int32_t>(iconSpec.Length()) > (questionMarkPos + 1))
-  {
+  if (questionMarkPos != -1 &&
+      static_cast<int32_t>(iconSpec.Length()) > (questionMarkPos + 1)) {
     extractAttributeValue(iconSpec.get(), "contentType=", mContentType);
 
     nsAutoCString sizeString;
     extractAttributeValue(iconSpec.get(), "size=", sizeString);
-    if (!sizeString.IsEmpty())
-    {      
-      const char *sizeStr = sizeString.get();
-      for (uint32_t i = 0; i < ArrayLength(kSizeStrings); i++)
-      {
-        if (PL_strcasecmp(sizeStr, kSizeStrings[i]) == 0)
-        {
+    if (!sizeString.IsEmpty()) {
+      const char* sizeStr = sizeString.get();
+      for (uint32_t i = 0; i < ArrayLength(kSizeStrings); i++) {
+        if (PL_strcasecmp(sizeStr, kSizeStrings[i]) == 0) {
           mIconSize = i;
           break;
         }
       }
 
       int32_t sizeValue = atoi(sizeString.get());
-      if (sizeValue)
+      if (sizeValue) {
         mSize = sizeValue;
+      }
     }
 
     nsAutoCString stateString;
     extractAttributeValue(iconSpec.get(), "state=", stateString);
-    if (!stateString.IsEmpty())
-    {
-      const char *stateStr = stateString.get();
-      for (uint32_t i = 0; i < ArrayLength(kStateStrings); i++)
-      {
-        if (PL_strcasecmp(stateStr, kStateStrings[i]) == 0)
-        {
+    if (!stateString.IsEmpty()) {
+      const char* stateStr = stateString.get();
+      for (uint32_t i = 0; i < ArrayLength(kStateStrings); i++) {
+        if (PL_strcasecmp(stateStr, kStateStrings[i]) == 0) {
           mIconState = i;
           break;
         }
       }
     }
   }
 
   int32_t pathLength = iconSpec.Length() - MOZICON_SCHEME_LEN;
-  if (questionMarkPos != -1)
+  if (questionMarkPos != -1) {
     pathLength = questionMarkPos - MOZICON_SCHEME_LEN;
-  if (pathLength < 3)
+  }
+  if (pathLength < 3) {
     return NS_ERROR_MALFORMED_URI;
+  }
 
   nsAutoCString iconPath(Substring(iconSpec, MOZICON_SCHEME_LEN, pathLength));
 
   // Icon URI path can have three forms:
   // (1) //stock/<icon-identifier>
   // (2) //<some dummy file with an extension>
   // (3) a valid URL
 
-  if (!strncmp("//stock/", iconPath.get(), 8))
-  {
+  if (!strncmp("//stock/", iconPath.get(), 8)) {
     mStockIcon.Assign(Substring(iconPath, 8));
     // An icon identifier must always be specified.
-    if (mStockIcon.IsEmpty())
+    if (mStockIcon.IsEmpty()) {
       return NS_ERROR_MALFORMED_URI;
+    }
     return NS_OK;
   }
 
-  if (StringBeginsWith(iconPath, NS_LITERAL_CSTRING("//")))
-  {
+  if (StringBeginsWith(iconPath, NS_LITERAL_CSTRING("//"))) {
     // Sanity check this supposed dummy file name.
-    if (iconPath.Length() > SANE_FILE_NAME_LEN)
+    if (iconPath.Length() > SANE_FILE_NAME_LEN) {
       return NS_ERROR_MALFORMED_URI;
+    }
     iconPath.Cut(0, 2);
     mFileName.Assign(iconPath);
   }
 
   nsresult rv;
   nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIURI> uri;
   ioService->NewURI(iconPath, nullptr, nullptr, getter_AddRefs(uri));
   mIconURL = do_QueryInterface(uri);
-  if (mIconURL)
+  if (mIconURL) {
     mFileName.Truncate();
-  else if (mFileName.IsEmpty())
+  } else if (mFileName.IsEmpty()) {
     return NS_ERROR_MALFORMED_URI;
+  }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetPrePath(nsACString &prePath)
+nsMozIconURI::GetPrePath(nsACString& prePath)
 {
   prePath = MOZICON_SCHEME;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetScheme(nsACString &aScheme)
+nsMozIconURI::GetScheme(nsACString& aScheme)
 {
   aScheme = "moz-icon";
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetScheme(const nsACString &aScheme)
+nsMozIconURI::SetScheme(const nsACString& aScheme)
 {
   // doesn't make sense to set the scheme of a moz-icon URL
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetUsername(nsACString &aUsername)
+nsMozIconURI::GetUsername(nsACString& aUsername)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetUsername(const nsACString &aUsername)
+nsMozIconURI::SetUsername(const nsACString& aUsername)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetPassword(nsACString &aPassword)
+nsMozIconURI::GetPassword(nsACString& aPassword)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetPassword(const nsACString &aPassword)
+nsMozIconURI::SetPassword(const nsACString& aPassword)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetUserPass(nsACString &aUserPass)
+nsMozIconURI::GetUserPass(nsACString& aUserPass)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetUserPass(const nsACString &aUserPass)
+nsMozIconURI::SetUserPass(const nsACString& aUserPass)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetHostPort(nsACString &aHostPort)
+nsMozIconURI::GetHostPort(nsACString& aHostPort)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetHostPort(const nsACString &aHostPort)
+nsMozIconURI::SetHostPort(const nsACString& aHostPort)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetHost(nsACString &aHost)
+nsMozIconURI::GetHost(nsACString& aHost)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetHost(const nsACString &aHost)
+nsMozIconURI::SetHost(const nsACString& aHost)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsMozIconURI::GetPort(int32_t *aPort)
 {
   return NS_ERROR_FAILURE;
 }
- 
+
 NS_IMETHODIMP
 nsMozIconURI::SetPort(int32_t aPort)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetPath(nsACString &aPath)
+nsMozIconURI::GetPath(nsACString& aPath)
 {
   aPath.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetPath(const nsACString &aPath)
+nsMozIconURI::SetPath(const nsACString& aPath)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetRef(nsACString &aRef)
+nsMozIconURI::GetRef(nsACString& aRef)
 {
   aRef.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetRef(const nsACString &aRef)
+nsMozIconURI::SetRef(const nsACString& aRef)
 {
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::Equals(nsIURI *other, bool *result)
+nsMozIconURI::Equals(nsIURI *other, bool* result)
 {
   NS_ENSURE_ARG_POINTER(other);
   NS_PRECONDITION(result, "null pointer");
 
   nsAutoCString spec1;
   nsAutoCString spec2;
 
   other->GetSpec(spec2);
   GetSpec(spec1);
-  if (!PL_strcasecmp(spec1.get(), spec2.get()))
+  if (!PL_strcasecmp(spec1.get(), spec2.get())) {
     *result = true;
-  else
+  } else {
     *result = false;
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::EqualsExceptRef(nsIURI *other, bool *result)
+nsMozIconURI::EqualsExceptRef(nsIURI* other, bool* result)
 {
   // GetRef/SetRef not supported by nsMozIconURI, so
   // EqualsExceptRef() is the same as Equals().
   return Equals(other, result);
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SchemeIs(const char *i_Scheme, bool *o_Equals)
+nsMozIconURI::SchemeIs(const char* aScheme, bool* aEquals)
 {
-  NS_ENSURE_ARG_POINTER(o_Equals);
-  if (!i_Scheme) return NS_ERROR_INVALID_ARG;
-  
-  *o_Equals = PL_strcasecmp("moz-icon", i_Scheme) ? false : true;
+  NS_ENSURE_ARG_POINTER(aEquals);
+  if (!aScheme) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  *aEquals = PL_strcasecmp("moz-icon", aScheme) ? false : true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::Clone(nsIURI **result)
+nsMozIconURI::Clone(nsIURI** result)
 {
   nsCOMPtr<nsIURL> newIconURL;
-  if (mIconURL)
-  {
+  if (mIconURL) {
     nsCOMPtr<nsIURI> newURI;
     nsresult rv = mIconURL->Clone(getter_AddRefs(newURI));
-    if (NS_FAILED(rv))
+    if (NS_FAILED(rv)) {
       return rv;
+    }
     newIconURL = do_QueryInterface(newURI, &rv);
-    if (NS_FAILED(rv))
+    if (NS_FAILED(rv)) {
       return rv;
+    }
   }
 
-  nsMozIconURI *uri = new nsMozIconURI();
+  nsMozIconURI* uri = new nsMozIconURI();
   newIconURL.swap(uri->mIconURL);
   uri->mSize = mSize;
   uri->mContentType = mContentType;
   uri->mFileName = mFileName;
   uri->mStockIcon = mStockIcon;
   uri->mIconSize = mIconSize;
   uri->mIconState = mIconState;
   NS_ADDREF(*result = uri);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::CloneIgnoringRef(nsIURI **result)
+nsMozIconURI::CloneIgnoringRef(nsIURI** result)
 {
   // GetRef/SetRef not supported by nsMozIconURI, so
   // CloneIgnoringRef() is the same as Clone().
   return Clone(result);
 }
 
 NS_IMETHODIMP
-nsMozIconURI::Resolve(const nsACString &relativePath, nsACString &result)
+nsMozIconURI::Resolve(const nsACString& relativePath, nsACString& result)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetAsciiSpec(nsACString &aSpecA)
+nsMozIconURI::GetAsciiSpec(nsACString& aSpecA)
 {
   return GetSpec(aSpecA);
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetAsciiHost(nsACString &aHostA)
+nsMozIconURI::GetAsciiHost(nsACString& aHostA)
 {
   return GetHost(aHostA);
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetOriginCharset(nsACString &result)
+nsMozIconURI::GetOriginCharset(nsACString& result)
 {
   result.Truncate();
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIIconUri methods:
 
 NS_IMETHODIMP
-nsMozIconURI::GetIconURL(nsIURL* * aFileUrl)
+nsMozIconURI::GetIconURL(nsIURL** aFileUrl)
 {
   *aFileUrl = mIconURL;
   NS_IF_ADDREF(*aFileUrl);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMozIconURI::SetIconURL(nsIURL* aFileUrl)
 {
   // this isn't called anywhere, needs to go through SetSpec parsing
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetImageSize(uint32_t * aImageSize)  // measured by # of pixels in a row. defaults to 16.
+nsMozIconURI::GetImageSize(uint32_t * aImageSize)
+              // measured by # of pixels in a row. defaults to 16.
 {
   *aImageSize = mSize;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetImageSize(uint32_t aImageSize)  // measured by # of pixels in a row. defaults to 16.
+nsMozIconURI::SetImageSize(uint32_t aImageSize)
+              // measured by # of pixels in a row. defaults to 16.
 {
   mSize = aImageSize;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetContentType(nsACString &aContentType)
+nsMozIconURI::GetContentType(nsACString& aContentType)
 {
   aContentType = mContentType;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::SetContentType(const nsACString &aContentType) 
+nsMozIconURI::SetContentType(const nsACString& aContentType)
 {
   mContentType = aContentType;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetFileExtension(nsACString &aFileExtension)  
+nsMozIconURI::GetFileExtension(nsACString& aFileExtension)
 {
   // First, try to get the extension from mIconURL if we have one
-  if (mIconURL)
-  {
+  if (mIconURL) {
     nsAutoCString fileExt;
-    if (NS_SUCCEEDED(mIconURL->GetFileExtension(fileExt)))
-    {
-      if (!fileExt.IsEmpty())
-      {
-        // unfortunately, this code doesn't give us the required '.' in front of the extension
-        // so we have to do it ourselves..
+    if (NS_SUCCEEDED(mIconURL->GetFileExtension(fileExt))) {
+      if (!fileExt.IsEmpty()) {
+        // unfortunately, this code doesn't give us the required '.' in
+        // front of the extension so we have to do it ourselves.
         aFileExtension.Assign('.');
         aFileExtension.Append(fileExt);
       }
     }
     return NS_OK;
   }
 
-  if (!mFileName.IsEmpty())
-  {
+  if (!mFileName.IsEmpty()) {
     // truncate the extension out of the file path...
-    const char * chFileName = mFileName.get(); // get the underlying buffer
-    const char * fileExt = strrchr(chFileName, '.');
-    if (!fileExt)
+    const char* chFileName = mFileName.get(); // get the underlying buffer
+    const char* fileExt = strrchr(chFileName, '.');
+    if (!fileExt) {
       return NS_OK;
+    }
     aFileExtension = fileExt;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetStockIcon(nsACString &aStockIcon)
+nsMozIconURI::GetStockIcon(nsACString& aStockIcon)
 {
   aStockIcon = mStockIcon;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetIconSize(nsACString &aSize)
+nsMozIconURI::GetIconSize(nsACString& aSize)
 {
-  if (mIconSize >= 0)
+  if (mIconSize >= 0) {
     aSize = kSizeStrings[mIconSize];
-  else
+  } else {
     aSize.Truncate();
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsMozIconURI::GetIconState(nsACString &aState)
+nsMozIconURI::GetIconState(nsACString& aState)
 {
-  if (mIconState >= 0)
+  if (mIconState >= 0) {
     aState = kStateStrings[mIconState];
-  else
+  } else {
     aState.Truncate();
+  }
   return NS_OK;
 }
 ////////////////////////////////////////////////////////////////////////////////
--- a/image/decoders/icon/nsIconURI.h
+++ b/image/decoders/icon/nsIconURI.h
@@ -16,28 +16,33 @@
     0x43a88e0e,                                      \
     0x2d37,                                          \
     0x11d5,                                          \
     { 0x99, 0x7, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b }   \
 }
 
 class nsMozIconURI MOZ_FINAL : public nsIMozIconURI
 {
-public:    
+public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIURI
   NS_DECL_NSIMOZICONURI
 
   // nsMozIconURI
   nsMozIconURI();
 
 protected:
   virtual ~nsMozIconURI();
   nsCOMPtr<nsIURL> mIconURL; // a URL that we want the icon for
-  uint32_t mSize; // the # of pixels in a row that we want for this image. Typically 16, 32, 128, etc.
-  nsCString mContentType; // optional field explicitly specifying the content type
-  nsCString mFileName; // for if we don't have an actual file path, we're just given a filename with an extension
+  uint32_t mSize; // the # of pixels in a row that we want for this image.
+                  // Typically 16, 32, 128, etc.
+  nsCString mContentType; // optional field explicitly specifying the content
+                          // type
+  nsCString mFileName; // for if we don't have an actual file path, we're just
+                       // given a filename with an extension
   nsCString mStockIcon;
-  int32_t mIconSize;     // -1 if not specified, otherwise index into kSizeStrings
-  int32_t mIconState;    // -1 if not specified, otherwise index into kStateStrings
+  int32_t mIconSize;   // -1 if not specified, otherwise index into
+                       // kSizeStrings
+  int32_t mIconState;  // -1 if not specified, otherwise index into
+                       // kStateStrings
 };
 
 #endif // nsMozIconURI_h__
--- a/image/decoders/icon/qt/gtkqticonsconverter.js
+++ b/image/decoders/icon/qt/gtkqticonsconverter.js
@@ -1,134 +1,138 @@
 /* vim:set ts=2 sw=2 sts=2 cin et: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 
-function GtkQtIconsConverter() { };
-GtkQtIconsConverter.prototype = {
+function GtkQtIconsConverter()
+{ };
+GtkQtIconsConverter.prototype =
+{
   classID:          Components.ID("{c0783c34-a831-40c6-8c03-98c9f74cca45}"),
-  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIGtkQtIconsConverter]),
+  QueryInterface: XPCOMUtils.generateQI(
+                                [Components.interfaces.nsIGtkQtIconsConverter]),
   convert: function(icon) { return this._gtk_qt_icons_table[icon]; },
-  _gtk_qt_icons_table: {
+  _gtk_qt_icons_table:
+  {
     'about':
     0,
     'add':
     0,
     'apply':
-    44, /* QStyle::SP_DialogApplyButton */
+    44, // QStyle::SP_DialogApplyButton
     'cancel':
-    39, /* QStyle::SP_DialogCancelButton */
+    39, // QStyle::SP_DialogCancelButton
     'clear':
-    45, /* QStyle::SP_DialogResetButton  */
+    45, // QStyle::SP_DialogResetButton
     'color-picker':
     0,
     'copy':
     0,
     'close':
-    43, /* QStyle::SP_DialogCloseButton */
+    43, // QStyle::SP_DialogCloseButton
     'cut':
     0,
     'delete':
     0,
     'dialog-error':
     0,
     'dialog-info':
     0,
     'dialog-question':
-    12, /* QStyle::SP_MessageBoxQuestion */
+    12, // QStyle::SP_MessageBoxQuestion
     'dialog-warning':
-    10, /* QStyle::SP_MessageBoxWarning */
+    10, // QStyle::SP_MessageBoxWarning
     'directory':
-    37, /* QStyle::SP_DirIcon */
+    37, // QStyle::SP_DirIcon
     'file':
-    24, /* QStyle::SP_FileIcon */
+    24, // QStyle::SP_FileIcon
     'find':
     0,
     'go-back-ltr':
-    53, /* QStyle::SP_ArrowBack */
+    53, // QStyle::SP_ArrowBack
     'go-back-rtl':
-    53, /* QStyle::SP_ArrowBack */
+    53, // QStyle::SP_ArrowBack
     'go-back':
-    53, /* QStyle::SP_ArrowBack */
+    53, // QStyle::SP_ArrowBack
     'go-forward-ltr':
-    54, /* QStyle::SP_ArrowForward */
+    54, // QStyle::SP_ArrowForward
     'go-forward-rtl':
-    54, /* QStyle::SP_ArrowForward */
+    54, // QStyle::SP_ArrowForward
     'go-forward':
-    54, /* QStyle::SP_ArrowForward */
+    54, // QStyle::SP_ArrowForward
     'go-up':
-    49, /* QStyle::SP_ArrowUp */
+    49, // QStyle::SP_ArrowUp
     'goto-first':
     0,
     'goto-last':
     0,
     'help':
-    7, /* QStyle::SP_TitleBarContextHelpButton */
+    7, // QStyle::SP_TitleBarContextHelpButton
     'home':
-    55, /* QStyle::SP_DirHomeIcon */
+    55, // QStyle::SP_DirHomeIcon
     'info':
-    9, /* QStyle::SP_MessageBoxInformation */
+    9, // QStyle::SP_MessageBoxInformation
     'jump-to':
     0,
     'media-pause':
     0,
     'media-play':
     0,
     'network':
-    20, /* QStyle::SP_DriveNetIcon */
+    20, // QStyle::SP_DriveNetIcon
     'no':
-    48, /* QStyle::SP_DialogNoButton */
+    48, // QStyle::SP_DialogNoButton
     'ok':
-    38, /* QStyle::SP_DialogOkButton */
+    38, // QStyle::SP_DialogOkButton
     'open':
-    21, /* QStyle::SP_DirOpenIcon */
+    21, // QStyle::SP_DirOpenIcon
     'orientation-landscape':
     0,
     'orientation-portrait':
     0,
     'paste':
     0,
     'preferences':
-    34, /* QStyle::SP_FileDialogContentsView */
+    34, // QStyle::SP_FileDialogContentsView
     'print-preview':
     0,
     'print':
     0,
     'properties':
     0,
     'quit':
     0,
     'redo':
     0,
     'refresh':
-    58, /* QStyle::SP_BrowserReload */
+    58, // QStyle::SP_BrowserReload
     'remove':
     0,
     'revert-to-saved':
     0,
     'save-as':
-    42, /* QStyle::SP_DialogSaveButton */
+    42, // QStyle::SP_DialogSaveButton
     'save':
-    42, /* QStyle::SP_DialogSaveButton */
+    42, // QStyle::SP_DialogSaveButton
     'select-all':
     0,
     'select-font':
     0,
     'stop':
-    59, /* QStyle::SP_BrowserStop */
+    59, // QStyle::SP_BrowserStop
     'undelete':
     0,
     'undo':
     0,
     'yes':
-    47, /* QStyle::SP_DialogYesButton */
+    47, // QStyle::SP_DialogYesButton
     'zoom-100':
     0,
     'zoom-in':
     0,
     'zoom-out':
     0
   },
 }
--- a/image/decoders/icon/qt/nsIconChannel.cpp
+++ b/image/decoders/icon/qt/nsIconChannel.cpp
@@ -22,41 +22,41 @@
 #include "nsIconChannel.h"
 #include "nsGtkQtIconsConverter.h"
 
 NS_IMPL_ISUPPORTS(nsIconChannel,
                   nsIRequest,
                   nsIChannel)
 
 static nsresult
-moz_qicon_to_channel(QImage *image, nsIURI *aURI,
-                     nsIChannel **aChannel)
+moz_qicon_to_channel(QImage* image, nsIURI* aURI,
+                     nsIChannel** aChannel)
 {
   NS_ENSURE_ARG_POINTER(image);
 
   int width = image->width();
   int height = image->height();
 
   NS_ENSURE_TRUE(height < 256 && width < 256 && height > 0 && width > 0,
                  NS_ERROR_UNEXPECTED);
 
   const int n_channels = 4;
   long int buf_size = 2 + n_channels * height * width;
-  uint8_t * const buf = (uint8_t*)NS_Alloc(buf_size);
+  uint8_t* const buf = (uint8_t*)NS_Alloc(buf_size);
   NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
-  uint8_t *out = buf;
+  uint8_t* out = buf;
 
   *(out++) = width;
   *(out++) = height;
 
-  const uchar * const pixels = image->bits();
+  const uchar* const pixels = image->bits();
   int rowextra = image->bytesPerLine() - width * n_channels;
 
   // encode the RGB data and the A data
-  const uchar * in = pixels;
+  const uchar* in = pixels;
   for (int y = 0; y < height; ++y, in += rowextra) {
     for (int x = 0; x < width; ++x) {
       uint8_t r = *(in++);
       uint8_t g = *(in++);
       uint8_t b = *(in++);
       uint8_t a = *(in++);
 #define DO_PREMULTIPLY(c_) uint8_t(uint16_t(c_) * uint16_t(a) / uint16_t(255))
 #if MOZ_LITTLE_ENDIAN
@@ -112,18 +112,22 @@ nsIconChannel::Init(nsIURI* aURI)
 
   uint32_t desiredImageSize;
   iconURI->GetImageSize(&desiredImageSize);
 
   nsAutoCString iconStateString;
   iconURI->GetIconState(iconStateString);
   bool disabled = iconStateString.EqualsLiteral("disabled");
 
-  // This is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=662299
-  // Try to find corresponding freedesktop icon and fallback to empty QIcon if failed.
-  QIcon icon = QIcon::fromTheme(QString(stockIcon.get()).replace("gtk-", "edit-"));
-  QPixmap pixmap = icon.pixmap(desiredImageSize, desiredImageSize, disabled ? QIcon::Disabled : QIcon::Normal);
+  // This is a workaround for
+  // https://bugzilla.mozilla.org/show_bug.cgi?id=662299
+  // Try to find corresponding freedesktop icon and fallback to empty QIcon
+  // if failed.
+  QIcon icon = QIcon::fromTheme(QString(stockIcon.get()).replace("gtk-",
+                                                                 "edit-"));
+  QPixmap pixmap = icon.pixmap(desiredImageSize, desiredImageSize,
+                               disabled ? QIcon::Disabled : QIcon::Normal);
 
   QImage image = pixmap.toImage();
 
   return moz_qicon_to_channel(&image, iconURI,
                               getter_AddRefs(mRealChannel));
 }
--- a/image/decoders/icon/qt/nsIconChannel.h
+++ b/image/decoders/icon/qt/nsIconChannel.h
@@ -9,38 +9,32 @@
 #include "mozilla/Attributes.h"
 
 #include "nsIChannel.h"
 #include "nsIStreamListener.h"
 #include "nsIURI.h"
 #include "nsIIconURI.h"
 #include "nsCOMPtr.h"
 
-/**
- * This class is the gnome implementation of nsIconChannel. It basically asks
- * qt for an icon, and creates a new channel for
- * that file to which all calls will be proxied.
- */
+/// This class is the gnome implementation of nsIconChannel. It basically asks
+/// qt for an icon, and creates a new channel for
+/// that file to which all calls will be proxied.
 class nsIconChannel MOZ_FINAL : public nsIChannel {
   public:
     NS_DECL_ISUPPORTS
     NS_FORWARD_NSIREQUEST(mRealChannel->)
     NS_FORWARD_NSICHANNEL(mRealChannel->)
 
-    nsIconChannel() {};
+    nsIconChannel() { };
 
-    /**
-     * Called by nsIconProtocolHandler after it creates this channel.
-     * Must be called before calling any other function on this object.
-     * If this method fails, no other function must be called on this object.
-     */
+    /// Called by nsIconProtocolHandler after it creates this channel.
+    /// Must be called before calling any other function on this object.
+    /// If this method fails, no other function must be called on this object.
     nsresult Init(nsIURI* aURI);
   private:
-    ~nsIconChannel() {};
+    ~nsIconChannel() { };
 
-    /**
-     * The channel to the temp icon file (e.g. to /tmp/2qy9wjqw.html).
-     * Will always be non-null after a successful Init.
-     */
+    /// The channel to the temp icon file (e.g. to /tmp/2qy9wjqw.html).
+    /// Will always be non-null after a successful Init.
     nsCOMPtr<nsIChannel> mRealChannel;
 };
 
 #endif
--- a/image/decoders/icon/win/nsIconChannel.cpp
+++ b/image/decoders/icon/win/nsIconChannel.cpp
@@ -52,140 +52,159 @@ struct ICONENTRY {
   uint8_t ieReserved;
   uint16_t iePlanes;
   uint16_t ieBitCount;
   uint32_t ieSizeImage;
   uint32_t ieFileOffset;
 };
 
 // Match stock icons with names
-static SHSTOCKICONID GetStockIconIDForName(const nsACString &aStockName)
+static SHSTOCKICONID
+GetStockIconIDForName(const nsACString& aStockName)
 {
-  return aStockName.EqualsLiteral("uac-shield") ? SIID_SHIELD : SIID_INVALID;
+  return aStockName.EqualsLiteral("uac-shield") ? SIID_SHIELD :
+                                                  SIID_INVALID;
 }
 
 // nsIconChannel methods
 nsIconChannel::nsIconChannel()
 {
 }
 
-nsIconChannel::~nsIconChannel() 
+nsIconChannel::~nsIconChannel()
 {
   if (mLoadInfo) {
     nsCOMPtr<nsIThread> mainThread;
     NS_GetMainThread(getter_AddRefs(mainThread));
 
-    nsILoadInfo *forgetableLoadInfo;
+    nsILoadInfo* forgetableLoadInfo;
     mLoadInfo.forget(&forgetableLoadInfo);
     NS_ProxyRelease(mainThread, forgetableLoadInfo, false);
   }
 }
 
-NS_IMPL_ISUPPORTS(nsIconChannel, 
-                  nsIChannel, 
+NS_IMPL_ISUPPORTS(nsIconChannel,
+                  nsIChannel,
                   nsIRequest,
                   nsIRequestObserver,
                   nsIStreamListener)
 
-nsresult nsIconChannel::Init(nsIURI* uri)
+nsresult
+nsIconChannel::Init(nsIURI* uri)
 {
   NS_ASSERTION(uri, "no uri");
   mUrl = uri;
   mOriginalURI = uri;
   nsresult rv;
   mPump = do_CreateInstance(NS_INPUTSTREAMPUMP_CONTRACTID, &rv);
   return rv;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIRequest methods:
 
-NS_IMETHODIMP nsIconChannel::GetName(nsACString &result)
+NS_IMETHODIMP
+nsIconChannel::GetName(nsACString& result)
 {
   return mUrl->GetSpec(result);
 }
 
-NS_IMETHODIMP nsIconChannel::IsPending(bool *result)
+NS_IMETHODIMP
+nsIconChannel::IsPending(bool* result)
 {
   return mPump->IsPending(result);
 }
 
-NS_IMETHODIMP nsIconChannel::GetStatus(nsresult *status)
+NS_IMETHODIMP
+nsIconChannel::GetStatus(nsresult* status)
 {
   return mPump->GetStatus(status);
 }
 
-NS_IMETHODIMP nsIconChannel::Cancel(nsresult status)
+NS_IMETHODIMP
+nsIconChannel::Cancel(nsresult status)
 {
   return mPump->Cancel(status);
 }
 
-NS_IMETHODIMP nsIconChannel::Suspend(void)
+NS_IMETHODIMP
+nsIconChannel::Suspend(void)
 {
   return mPump->Suspend();
 }
 
-NS_IMETHODIMP nsIconChannel::Resume(void)
+NS_IMETHODIMP
+nsIconChannel::Resume(void)
 {
   return mPump->Resume();
 }
-NS_IMETHODIMP nsIconChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
+NS_IMETHODIMP
+nsIconChannel::GetLoadGroup(nsILoadGroup** aLoadGroup)
 {
   *aLoadGroup = mLoadGroup;
   NS_IF_ADDREF(*aLoadGroup);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
+NS_IMETHODIMP
+nsIconChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
 {
   mLoadGroup = aLoadGroup;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetLoadFlags(uint32_t *aLoadAttributes)
+NS_IMETHODIMP
+nsIconChannel::GetLoadFlags(uint32_t* aLoadAttributes)
 {
   return mPump->GetLoadFlags(aLoadAttributes);
 }
 
-NS_IMETHODIMP nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes)
+NS_IMETHODIMP
+nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes)
 {
   return mPump->SetLoadFlags(aLoadAttributes);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIChannel methods:
 
-NS_IMETHODIMP nsIconChannel::GetOriginalURI(nsIURI* *aURI)
+NS_IMETHODIMP
+nsIconChannel::GetOriginalURI(nsIURI** aURI)
 {
   *aURI = mOriginalURI;
   NS_ADDREF(*aURI);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetOriginalURI(nsIURI* aURI)
+NS_IMETHODIMP
+nsIconChannel::SetOriginalURI(nsIURI* aURI)
 {
   NS_ENSURE_ARG_POINTER(aURI);
   mOriginalURI = aURI;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetURI(nsIURI* *aURI)
+NS_IMETHODIMP
+nsIconChannel::GetURI(nsIURI** aURI)
 {
   *aURI = mUrl;
   NS_IF_ADDREF(*aURI);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsIconChannel::Open(nsIInputStream **_retval)
+nsIconChannel::Open(nsIInputStream** _retval)
 {
   return MakeInputStream(_retval, false);
 }
 
-nsresult nsIconChannel::ExtractIconInfoFromUrl(nsIFile ** aLocalFile, uint32_t * aDesiredImageSize, nsCString &aContentType, nsCString &aFileExtension)
+nsresult
+nsIconChannel::ExtractIconInfoFromUrl(nsIFile** aLocalFile,
+                        uint32_t* aDesiredImageSize, nsCString& aContentType,
+                        nsCString& aFileExtension)
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMozIconURI> iconURI (do_QueryInterface(mUrl, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   iconURI->GetImageSize(aDesiredImageSize);
   iconURI->GetContentType(aContentType);
   iconURI->GetFileExtension(aFileExtension);
@@ -199,319 +218,348 @@ nsresult nsIconChannel::ExtractIconInfoF
 
   nsCOMPtr<nsIFile> file;
   rv = fileURL->GetFile(getter_AddRefs(file));
   if (NS_FAILED(rv) || !file) return NS_OK;
 
   return file->Clone(aLocalFile);
 }
 
-NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
+NS_IMETHODIMP
+nsIconChannel::AsyncOpen(nsIStreamListener* aListener,
+                                       nsISupports* ctxt)
 {
   nsCOMPtr<nsIInputStream> inStream;
   nsresult rv = MakeInputStream(getter_AddRefs(inStream), true);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   // Init our streampump
   rv = mPump->Init(inStream, int64_t(-1), int64_t(-1), 0, 0, false);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   rv = mPump->AsyncRead(this, ctxt);
   if (NS_SUCCEEDED(rv)) {
     // Store our real listener
     mListener = aListener;
     // Add ourself to the load group, if available
-    if (mLoadGroup)
+    if (mLoadGroup) {
       mLoadGroup->AddRequest(this, nullptr);
+    }
   }
   return rv;
 }
 
-static DWORD GetSpecialFolderIcon(nsIFile* aFile, int aFolder, SHFILEINFOW* aSFI, UINT aInfoFlags)
+static DWORD
+GetSpecialFolderIcon(nsIFile* aFile, int aFolder,
+                                  SHFILEINFOW* aSFI, UINT aInfoFlags)
 {
   DWORD shellResult = 0;
 
-  if (!aFile)
+  if (!aFile) {
     return shellResult;
+  }
 
   wchar_t fileNativePath[MAX_PATH];
   nsAutoString fileNativePathStr;
   aFile->GetPath(fileNativePathStr);
-  ::GetShortPathNameW(fileNativePathStr.get(), fileNativePath, ArrayLength(fileNativePath));
+  ::GetShortPathNameW(fileNativePathStr.get(), fileNativePath,
+                      ArrayLength(fileNativePath));
 
   LPITEMIDLIST idList;
   HRESULT hr = ::SHGetSpecialFolderLocation(nullptr, aFolder, &idList);
   if (SUCCEEDED(hr)) {
     wchar_t specialNativePath[MAX_PATH];
     ::SHGetPathFromIDListW(idList, specialNativePath);
-    ::GetShortPathNameW(specialNativePath, specialNativePath, ArrayLength(specialNativePath));
-  
+    ::GetShortPathNameW(specialNativePath, specialNativePath,
+                        ArrayLength(specialNativePath));
+
     if (!wcsicmp(fileNativePath, specialNativePath)) {
       aInfoFlags |= (SHGFI_PIDL | SHGFI_SYSICONINDEX);
-      shellResult = ::SHGetFileInfoW((LPCWSTR)(LPCITEMIDLIST)idList, 0, aSFI,
+      shellResult = ::SHGetFileInfoW((LPCWSTR)(LPCITEMIDLIST)idList, 0,
+                                      aSFI,
                                      sizeof(*aSFI), aInfoFlags);
     }
   }
   CoTaskMemFree(idList);
   return shellResult;
 }
 
-static UINT GetSizeInfoFlag(uint32_t aDesiredImageSize)
+static UINT
+GetSizeInfoFlag(uint32_t aDesiredImageSize)
 {
-  UINT infoFlag;
-  if (aDesiredImageSize > 16)
-    infoFlag = SHGFI_SHELLICONSIZE;
-  else
-    infoFlag = SHGFI_SMALLICON;
-
-  return infoFlag;
+  return
+    (UINT) (aDesiredImageSize > 16 ? SHGFI_SHELLICONSIZE : SHGFI_SMALLICON);
 }
 
-nsresult nsIconChannel::GetHIconFromFile(HICON *hIcon)
+nsresult
+nsIconChannel::GetHIconFromFile(HICON* hIcon)
 {
   nsXPIDLCString contentType;
   nsCString fileExt;
   nsCOMPtr<nsIFile> localFile; // file we want an icon for
   uint32_t desiredImageSize;
-  nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, contentType, fileExt);
+  nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile),
+                                       &desiredImageSize, contentType,
+                                       fileExt);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // if the file exists, we are going to use it's real attributes...otherwise we only want to use it for it's extension...
+  // if the file exists, we are going to use it's real attributes...
+  // otherwise we only want to use it for it's extension...
   SHFILEINFOW      sfi;
   UINT infoFlags = SHGFI_ICON;
-  
+
   bool fileExists = false;
- 
+
   nsAutoString filePath;
   CopyASCIItoUTF16(fileExt, filePath);
-  if (localFile)
-  {
+  if (localFile) {
     rv = localFile->Normalize();
     NS_ENSURE_SUCCESS(rv, rv);
 
     localFile->GetPath(filePath);
-    if (filePath.Length() < 2 || filePath[1] != ':')
+    if (filePath.Length() < 2 || filePath[1] != ':') {
       return NS_ERROR_MALFORMED_URI; // UNC
+    }
 
-    if (filePath.Last() == ':')
+    if (filePath.Last() == ':') {
       filePath.Append('\\');
-    else {
+    } else {
       localFile->Exists(&fileExists);
-      if (!fileExists)
+      if (!fileExists) {
        localFile->GetLeafName(filePath);
+      }
     }
   }
 
-  if (!fileExists)
+  if (!fileExists) {
    infoFlags |= SHGFI_USEFILEATTRIBUTES;
+  }
 
   infoFlags |= GetSizeInfoFlag(desiredImageSize);
 
-  // if we have a content type... then use it! but for existing files, we want
-  // to show their real icon.
-  if (!fileExists && !contentType.IsEmpty())
-  {
-    nsCOMPtr<nsIMIMEService> mimeService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
+  // if we have a content type... then use it! but for existing files,
+  // we want to show their real icon.
+  if (!fileExists && !contentType.IsEmpty()) {
+    nsCOMPtr<nsIMIMEService> mimeService
+      (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoCString defFileExt;
     mimeService->GetPrimaryExtension(contentType, fileExt, defFileExt);
     // If the mime service does not know about this mime type, we show
     // the generic icon.
     // In any case, we need to insert a '.' before the extension.
-    filePath = NS_LITERAL_STRING(".") + NS_ConvertUTF8toUTF16(defFileExt);
+    filePath = NS_LITERAL_STRING(".") +
+               NS_ConvertUTF8toUTF16(defFileExt);
   }
 
   // Is this the "Desktop" folder?
-  DWORD shellResult = GetSpecialFolderIcon(localFile, CSIDL_DESKTOP, &sfi, infoFlags);
+  DWORD shellResult = GetSpecialFolderIcon(localFile, CSIDL_DESKTOP,
+                                           &sfi, infoFlags);
   if (!shellResult) {
     // Is this the "My Documents" folder?
-    shellResult = GetSpecialFolderIcon(localFile, CSIDL_PERSONAL, &sfi, infoFlags);
+    shellResult = GetSpecialFolderIcon(localFile, CSIDL_PERSONAL,
+                                       &sfi, infoFlags);
   }
 
-  // There are other "Special Folders" and Namespace entities that we are not 
-  // fetching icons for, see: 
-  // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
-  // If we ever need to get them, code to do so would be inserted here. 
+  // There are other "Special Folders" and Namespace entities that we
+  // are not fetching icons for, see:
+  // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
+  //        shellcc/platform/shell/reference/enums/csidl.asp
+  // If we ever need to get them, code to do so would be inserted here.
 
   // Not a special folder, or something else failed above.
-  if (!shellResult)
+  if (!shellResult) {
     shellResult = ::SHGetFileInfoW(filePath.get(),
-                                   FILE_ATTRIBUTE_ARCHIVE, &sfi, sizeof(sfi), infoFlags);
+                                   FILE_ATTRIBUTE_ARCHIVE,
+                                   &sfi, sizeof(sfi), infoFlags);
+  }
 
-  if (shellResult && sfi.hIcon)
+  if (shellResult && sfi.hIcon) {
     *hIcon = sfi.hIcon;
-  else
+  } else {
     rv = NS_ERROR_NOT_AVAILABLE;
+  }
 
   return rv;
 }
 
-nsresult nsIconChannel::GetStockHIcon(nsIMozIconURI *aIconURI, HICON *hIcon)
+nsresult
+nsIconChannel::GetStockHIcon(nsIMozIconURI* aIconURI,
+                                      HICON* hIcon)
 {
   nsresult rv = NS_OK;
 
   // We can only do this on Vista or above
   HMODULE hShellDLL = ::LoadLibraryW(L"shell32.dll");
   decltype(SHGetStockIconInfo)* pSHGetStockIconInfo =
-    (decltype(SHGetStockIconInfo)*) ::GetProcAddress(hShellDLL, "SHGetStockIconInfo");
+    (decltype(SHGetStockIconInfo)*) ::GetProcAddress(hShellDLL,
+                                                    "SHGetStockIconInfo");
 
-  if (pSHGetStockIconInfo)
-  {
+  if (pSHGetStockIconInfo) {
     uint32_t desiredImageSize;
     aIconURI->GetImageSize(&desiredImageSize);
     nsAutoCString stockIcon;
     aIconURI->GetStockIcon(stockIcon);
 
     SHSTOCKICONID stockIconID = GetStockIconIDForName(stockIcon);
-    if (stockIconID == SIID_INVALID)
+    if (stockIconID == SIID_INVALID) {
       return NS_ERROR_NOT_AVAILABLE;
+    }
 
     UINT infoFlags = SHGSI_ICON;
     infoFlags |= GetSizeInfoFlag(desiredImageSize);
 
     SHSTOCKICONINFO sii = {0};
     sii.cbSize = sizeof(sii);
     HRESULT hr = pSHGetStockIconInfo(stockIconID, infoFlags, &sii);
 
-    if (SUCCEEDED(hr))
+    if (SUCCEEDED(hr)) {
       *hIcon = sii.hIcon;
-    else
+    } else {
       rv = NS_ERROR_FAILURE;
-  }
-  else
-  {
+    }
+  } else {
     rv = NS_ERROR_NOT_AVAILABLE;
   }
 
-  if (hShellDLL)
+  if (hShellDLL) {
     ::FreeLibrary(hShellDLL);
+  }
 
   return rv;
 }
 
 // Given a BITMAPINFOHEADER, returns the size of the color table.
-static int GetColorTableSize(BITMAPINFOHEADER* aHeader)
+static int
+GetColorTableSize(BITMAPINFOHEADER* aHeader)
 {
   int colorTableSize = -1;
 
   // http://msdn.microsoft.com/en-us/library/dd183376%28v=VS.85%29.aspx
   switch (aHeader->biBitCount) {
   case 0:
     colorTableSize = 0;
     break;
   case 1:
     colorTableSize = 2 * sizeof(RGBQUAD);
     break;
   case 4:
-  case 8:
-  {
+  case 8: {
     // The maximum possible size for the color table is 2**bpp, so check for
     // that and fail if we're not in those bounds
     unsigned int maxEntries = 1 << (aHeader->biBitCount);
-    if (aHeader->biClrUsed > 0 && aHeader->biClrUsed <= maxEntries)
+    if (aHeader->biClrUsed > 0 && aHeader->biClrUsed <= maxEntries) {
       colorTableSize = aHeader->biClrUsed * sizeof(RGBQUAD);
-    else if (aHeader->biClrUsed == 0)
+    } else if (aHeader->biClrUsed == 0) {
       colorTableSize = maxEntries * sizeof(RGBQUAD);
+    }
     break;
   }
   case 16:
   case 32:
     // If we have BI_BITFIELDS compression, we would normally need 3 DWORDS for
-    // the bitfields mask which would be stored in the color table; However, 
+    // the bitfields mask which would be stored in the color table; However,
     // we instead force the bitmap to request data of type BI_RGB so the color
-    // table should be of size 0.  
-    // Setting aHeader->biCompression = BI_RGB forces the later call to 
+    // table should be of size 0.
+    // Setting aHeader->biCompression = BI_RGB forces the later call to
     // GetDIBits to return to us BI_RGB data.
     if (aHeader->biCompression == BI_BITFIELDS) {
       aHeader->biCompression = BI_RGB;
     }
     colorTableSize = 0;
     break;
   case 24:
     colorTableSize = 0;
     break;
   }
 
-  if (colorTableSize < 0)
+  if (colorTableSize < 0) {
     NS_WARNING("Unable to figure out the color table size for this bitmap");
+  }
 
   return colorTableSize;
 }
 
 // Given a header and a size, creates a freshly allocated BITMAPINFO structure.
 // It is the caller's responsibility to null-check and delete the structure.
-static BITMAPINFO* CreateBitmapInfo(BITMAPINFOHEADER* aHeader,
-                                    size_t aColorTableSize)
+static BITMAPINFO*
+CreateBitmapInfo(BITMAPINFOHEADER* aHeader, size_t aColorTableSize)
 {
   BITMAPINFO* bmi = (BITMAPINFO*) ::operator new(sizeof(BITMAPINFOHEADER) +
                                                  aColorTableSize,
                                                  mozilla::fallible_t());
   if (bmi) {
     memcpy(bmi, aHeader, sizeof(BITMAPINFOHEADER));
     memset(bmi->bmiColors, 0, aColorTableSize);
   }
   return bmi;
 }
 
-nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, bool nonBlocking)
+nsresult
+nsIconChannel::MakeInputStream(nsIInputStream** _retval, bool aNonBlocking)
 {
   // Check whether the icon requested's a file icon or a stock icon
   nsresult rv = NS_ERROR_NOT_AVAILABLE;
 
   // GetDIBits does not exist on windows mobile.
   HICON hIcon = nullptr;
 
   nsCOMPtr<nsIMozIconURI> iconURI(do_QueryInterface(mUrl, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoCString stockIcon;
   iconURI->GetStockIcon(stockIcon);
-  if (!stockIcon.IsEmpty())
+  if (!stockIcon.IsEmpty()) {
     rv = GetStockHIcon(iconURI, &hIcon);
-  else
+  } else {
     rv = GetHIconFromFile(&hIcon);
+  }
 
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (hIcon)
-  {
-    // we got a handle to an icon. Now we want to get a bitmap for the icon using GetIconInfo....
+  if (hIcon) {
+    // we got a handle to an icon. Now we want to get a bitmap for the icon
+    // using GetIconInfo....
     ICONINFO iconInfo;
-    if (GetIconInfo(hIcon, &iconInfo))
-    {
+    if (GetIconInfo(hIcon, &iconInfo)) {
       // we got the bitmaps, first find out their size
-      HDC hDC = CreateCompatibleDC(nullptr); // get a device context for the screen.
+      HDC hDC = CreateCompatibleDC(nullptr); // get a device context for
+                                             // the screen.
       BITMAPINFOHEADER maskHeader  = {sizeof(BITMAPINFOHEADER)};
       BITMAPINFOHEADER colorHeader = {sizeof(BITMAPINFOHEADER)};
       int colorTableSize, maskTableSize;
-      if (GetDIBits(hDC, iconInfo.hbmMask,  0, 0, nullptr, (BITMAPINFO*)&maskHeader,  DIB_RGB_COLORS) &&
-          GetDIBits(hDC, iconInfo.hbmColor, 0, 0, nullptr, (BITMAPINFO*)&colorHeader, DIB_RGB_COLORS) &&
+      if (GetDIBits(hDC, iconInfo.hbmMask,  0, 0, nullptr,
+                    (BITMAPINFO*)&maskHeader,  DIB_RGB_COLORS) &&
+          GetDIBits(hDC, iconInfo.hbmColor, 0, 0, nullptr,
+                    (BITMAPINFO*)&colorHeader, DIB_RGB_COLORS) &&
           maskHeader.biHeight == colorHeader.biHeight &&
           maskHeader.biWidth  == colorHeader.biWidth  &&
           colorHeader.biBitCount > 8 &&
           colorHeader.biSizeImage > 0 &&
           colorHeader.biWidth >= 0 && colorHeader.biWidth <= 255 &&
           colorHeader.biHeight >= 0 && colorHeader.biHeight <= 255 &&
           maskHeader.biSizeImage > 0  &&
           (colorTableSize = GetColorTableSize(&colorHeader)) >= 0 &&
           (maskTableSize  = GetColorTableSize(&maskHeader))  >= 0) {
         uint32_t iconSize = sizeof(ICONFILEHEADER) +
                             sizeof(ICONENTRY) +
                             sizeof(BITMAPINFOHEADER) +
                             colorHeader.biSizeImage +
                             maskHeader.biSizeImage;
 
-        char *buffer = new char[iconSize];
-        if (!buffer)
+        char* buffer = new char[iconSize];
+        if (!buffer) {
           rv = NS_ERROR_OUT_OF_MEMORY;
-        else {
-          char *whereTo = buffer;
+        } else {
+          char* whereTo = buffer;
           int howMuch;
 
           // the data starts with an icon file header
           ICONFILEHEADER iconHeader;
           iconHeader.ifhReserved = 0;
           iconHeader.ifhType = 1;
           iconHeader.ifhCount = 1;
           howMuch = sizeof(ICONFILEHEADER);
@@ -540,33 +588,36 @@ nsresult nsIconChannel::MakeInputStream(
           colorHeader.biSizeImage += maskHeader.biSizeImage;
           howMuch = sizeof(BITMAPINFOHEADER);
           memcpy(whereTo, &colorHeader, howMuch);
           whereTo += howMuch;
           colorHeader.biHeight /= 2;
           colorHeader.biSizeImage -= maskHeader.biSizeImage;
 
           // followed by the XOR bitmap data (colorHeader)
-          // (you'd expect the color table to come here, but it apparently doesn't)
-          BITMAPINFO* colorInfo = CreateBitmapInfo(&colorHeader, colorTableSize);
+          // (you'd expect the color table to come here, but it apparently
+          // doesn't)
+          BITMAPINFO* colorInfo = CreateBitmapInfo(&colorHeader,
+                                                   colorTableSize);
           if (colorInfo && GetDIBits(hDC, iconInfo.hbmColor, 0,
                                      colorHeader.biHeight, whereTo, colorInfo,
                                      DIB_RGB_COLORS)) {
             whereTo += colorHeader.biSizeImage;
 
             // and finally the AND bitmap data (maskHeader)
             BITMAPINFO* maskInfo = CreateBitmapInfo(&maskHeader, maskTableSize);
             if (maskInfo && GetDIBits(hDC, iconInfo.hbmMask, 0,
                                       maskHeader.biHeight, whereTo, maskInfo,
                                       DIB_RGB_COLORS)) {
               // Now, create a pipe and stuff our data into it
               nsCOMPtr<nsIInputStream> inStream;
               nsCOMPtr<nsIOutputStream> outStream;
-              rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(outStream),
-                              iconSize, iconSize, nonBlocking);
+              rv = NS_NewPipe(getter_AddRefs(inStream),
+                              getter_AddRefs(outStream),
+                              iconSize, iconSize, aNonBlocking);
               if (NS_SUCCEEDED(rv)) {
                 uint32_t written;
                 rv = outStream->Write(buffer, iconSize, &written);
                 if (NS_SUCCEEDED(rv)) {
                   NS_ADDREF(*_retval = inStream);
                 }
               }
 
@@ -581,163 +632,187 @@ nsresult nsIconChannel::MakeInputStream(
       DeleteDC(hDC);
       DeleteObject(iconInfo.hbmColor);
       DeleteObject(iconInfo.hbmMask);
     } // if we got icon info
     DestroyIcon(hIcon);
   } // if we got an hIcon
 
   // If we didn't make a stream, then fail.
-  if (!*_retval && NS_SUCCEEDED(rv))
+  if (!*_retval && NS_SUCCEEDED(rv)) {
     rv = NS_ERROR_NOT_AVAILABLE;
+  }
   return rv;
 }
 
-NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType) 
+NS_IMETHODIMP
+nsIconChannel::GetContentType(nsACString& aContentType)
 {
   aContentType.AssignLiteral(IMAGE_ICO);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsIconChannel::SetContentType(const nsACString &aContentType)
+nsIconChannel::SetContentType(const nsACString& aContentType)
 {
   // It doesn't make sense to set the content-type on this type
   // of channel...
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP nsIconChannel::GetContentCharset(nsACString &aContentCharset) 
+NS_IMETHODIMP nsIconChannel::GetContentCharset(nsACString& aContentCharset)
 {
   aContentCharset.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsIconChannel::SetContentCharset(const nsACString &aContentCharset)
+nsIconChannel::SetContentCharset(const nsACString& aContentCharset)
 {
   // It doesn't make sense to set the content-charset on this type
   // of channel...
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::GetContentDisposition(uint32_t *aContentDisposition)
+nsIconChannel::GetContentDisposition(uint32_t* aContentDisposition)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
 nsIconChannel::SetContentDisposition(uint32_t aContentDisposition)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
+nsIconChannel::
+  GetContentDispositionFilename(nsAString& aContentDispositionFilename)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename)
+nsIconChannel::
+  SetContentDispositionFilename(const nsAString& aContentDispositionFilename)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 NS_IMETHODIMP
-nsIconChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
+nsIconChannel::
+  GetContentDispositionHeader(nsACString& aContentDispositionHeader)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
-NS_IMETHODIMP nsIconChannel::GetContentLength(int64_t *aContentLength)
+NS_IMETHODIMP
+nsIconChannel::GetContentLength(int64_t* aContentLength)
 {
   *aContentLength = mContentLength;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetContentLength(int64_t aContentLength)
+NS_IMETHODIMP
+nsIconChannel::SetContentLength(int64_t aContentLength)
 {
   NS_NOTREACHED("nsIconChannel::SetContentLength");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-NS_IMETHODIMP nsIconChannel::GetOwner(nsISupports* *aOwner)
+NS_IMETHODIMP
+nsIconChannel::GetOwner(nsISupports** aOwner)
 {
   *aOwner = mOwner.get();
   NS_IF_ADDREF(*aOwner);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetOwner(nsISupports* aOwner)
+NS_IMETHODIMP
+nsIconChannel::SetOwner(nsISupports* aOwner)
 {
   mOwner = aOwner;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetLoadInfo(nsILoadInfo* *aLoadInfo)
+NS_IMETHODIMP
+nsIconChannel::GetLoadInfo(nsILoadInfo** aLoadInfo)
 {
   NS_IF_ADDREF(*aLoadInfo = mLoadInfo);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
+NS_IMETHODIMP
+nsIconChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
 {
   mLoadInfo = aLoadInfo;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
+NS_IMETHODIMP
+nsIconChannel::
+  GetNotificationCallbacks(nsIInterfaceRequestor** aNotificationCallbacks)
 {
   *aNotificationCallbacks = mCallbacks.get();
   NS_IF_ADDREF(*aNotificationCallbacks);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
+NS_IMETHODIMP
+nsIconChannel::
+  SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
 {
   mCallbacks = aNotificationCallbacks;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
+NS_IMETHODIMP
+nsIconChannel::GetSecurityInfo(nsISupports** aSecurityInfo)
 {
   *aSecurityInfo = nullptr;
   return NS_OK;
 }
 
 // nsIRequestObserver methods
-NS_IMETHODIMP nsIconChannel::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
+NS_IMETHODIMP nsIconChannel::OnStartRequest(nsIRequest* aRequest,
+                                            nsISupports* aContext)
 {
-  if (mListener)
+  if (mListener) {
     return mListener->OnStartRequest(this, aContext);
+  }
   return NS_OK;
 }
 
-NS_IMETHODIMP nsIconChannel::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext, nsresult aStatus)
+NS_IMETHODIMP
+nsIconChannel::OnStopRequest(nsIRequest* aRequest,
+                             nsISupports* aContext,
+                             nsresult aStatus)
 {
   if (mListener) {
     mListener->OnStopRequest(this, aContext, aStatus);
     mListener = nullptr;
   }
 
   // Remove from load group
-  if (mLoadGroup)
+  if (mLoadGroup) {
     mLoadGroup->RemoveRequest(this, nullptr, aStatus);
+  }
 
   // Drop notification callbacks to prevent cycles.
   mCallbacks = nullptr;
 
   return NS_OK;
 }
 
 // nsIStreamListener methods
-NS_IMETHODIMP nsIconChannel::OnDataAvailable(nsIRequest* aRequest,
-                                             nsISupports* aContext,
-                                             nsIInputStream* aStream,
-                                             uint64_t aOffset,
-                                             uint32_t aCount)
+NS_IMETHODIMP
+nsIconChannel::OnDataAvailable(nsIRequest* aRequest,
+                               nsISupports* aContext,
+                               nsIInputStream* aStream,
+                               uint64_t aOffset,
+                               uint32_t aCount)
 {
-  if (mListener)
+  if (mListener) {
     return mListener->OnDataAvailable(this, aContext, aStream, aOffset, aCount);
+  }
   return NS_OK;
 }
--- a/image/decoders/icon/win/nsIconChannel.h
+++ b/image/decoders/icon/win/nsIconChannel.h
@@ -41,24 +41,27 @@ public:
   nsresult Init(nsIURI* uri);
 
 protected:
   nsCOMPtr<nsIURI> mUrl;
   nsCOMPtr<nsIURI> mOriginalURI;
   int64_t          mContentLength;
   nsCOMPtr<nsILoadGroup> mLoadGroup;
   nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
-  nsCOMPtr<nsISupports>  mOwner; 
+  nsCOMPtr<nsISupports>  mOwner;
   nsCOMPtr<nsILoadInfo>  mLoadInfo;
 
   nsCOMPtr<nsIInputStreamPump> mPump;
   nsCOMPtr<nsIStreamListener>  mListener;
 
-  nsresult ExtractIconInfoFromUrl(nsIFile ** aLocalFile, uint32_t * aDesiredImageSize, nsCString &aContentType, nsCString &aFileExtension);
-  nsresult GetHIconFromFile(HICON *hIcon);
+  nsresult ExtractIconInfoFromUrl(nsIFile** aLocalFile,
+                                  uint32_t* aDesiredImageSize,
+                                  nsCString& aContentType,
+                                  nsCString& aFileExtension);
+  nsresult GetHIconFromFile(HICON* hIcon);
   nsresult MakeInputStream(nsIInputStream** _retval, bool nonBlocking);
 
   // Functions specific to Vista and above
 protected:
-  nsresult GetStockHIcon(nsIMozIconURI *aIconURI, HICON *hIcon);
+  nsresult GetStockHIcon(nsIMozIconURI* aIconURI, HICON* hIcon);
 };
 
 #endif /* nsIconChannel_h___ */
--- a/image/decoders/nsBMPDecoder.cpp
+++ b/image/decoders/nsBMPDecoder.cpp
@@ -1,46 +1,48 @@
 /* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/* I got the format description from http://www.daubnet.com/formats/BMP.html */
+
+// I got the format description from http://www.daubnet.com/formats/BMP.html
 
-/* This is a Cross-Platform BMP Decoder, which should work everywhere, including
- * Big-Endian machines like the PowerPC. */
+// This is a Cross-Platform BMP Decoder, which should work everywhere, including
+// Big-Endian machines like the PowerPC.
 
 #include <stdlib.h>
 
 #include "ImageLogging.h"
 #include "mozilla/Endian.h"
 #include "nsBMPDecoder.h"
 
 #include "nsIInputStream.h"
 #include "RasterImage.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace image {
 
 #ifdef PR_LOGGING
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetBMPLog()
 {
-  static PRLogModuleInfo *sBMPLog;
-  if (!sBMPLog)
+  static PRLogModuleInfo* sBMPLog;
+  if (!sBMPLog) {
     sBMPLog = PR_NewLogModule("BMPDecoder");
+  }
   return sBMPLog;
 }
 #endif
 
 // Convert from row (1..height) to absolute line (0..height-1)
 #define LINE(row) ((mBIH.height < 0) ? (-mBIH.height - (row)) : ((row) - 1))
 #define PIXEL_OFFSET(row, col) (LINE(row) * mBIH.width + col)
 
-nsBMPDecoder::nsBMPDecoder(RasterImage &aImage)
+nsBMPDecoder::nsBMPDecoder(RasterImage& aImage)
  : Decoder(aImage)
 {
   mColors = nullptr;
   mRow = nullptr;
   mCurPos = mPos = mNumColors = mRowBytes = 0;
   mOldLine = mCurLine = 1; // Otherwise decoder will never start
   mState = eRLEStateInitial;
   mStateData = 0;
@@ -52,77 +54,78 @@ nsBMPDecoder::~nsBMPDecoder()
 {
   delete[] mColors;
   if (mRow) {
       moz_free(mRow);
   }
 }
 
 // Sets whether or not the BMP will use alpha data
-void 
-nsBMPDecoder::SetUseAlphaData(bool useAlphaData) 
+void
+nsBMPDecoder::SetUseAlphaData(bool useAlphaData)
 {
   mUseAlphaData = useAlphaData;
 }
 
 // Obtains the bits per pixel from the internal BIH header
-int32_t 
+int32_t
 nsBMPDecoder::GetBitsPerPixel() const
 {
   return mBIH.bpp;
 }
 
 // Obtains the width from the internal BIH header
-int32_t 
+int32_t
 nsBMPDecoder::GetWidth() const
 {
-  return mBIH.width; 
+  return mBIH.width;
 }
 
 // Obtains the abs-value of the height from the internal BIH header
-int32_t 
+int32_t
 nsBMPDecoder::GetHeight() const
 {
   return abs(mBIH.height);
 }
 
 // Obtains the internal output image buffer
-uint32_t* 
-nsBMPDecoder::GetImageData() 
+uint32_t*
+nsBMPDecoder::GetImageData()
 {
   return reinterpret_cast<uint32_t*>(mImageData);
 }
 
 // Obtains the size of the compressed image resource
-int32_t 
+int32_t
 nsBMPDecoder::GetCompressedImageSize() const
 {
   // For everything except BI_RGB the header field must be defined
   if (mBIH.compression != BI_RGB) {
     return mBIH.image_size;
   }
 
   // mBIH.image_size isn't always filled for BI_RGB so calculate it manually
   // The pixel array size is calculated based on extra 4 byte boundary padding
   uint32_t rowSize = (mBIH.bpp * mBIH.width + 7) / 8; // + 7 to round up
+
   // Pad to DWORD Boundary
   if (rowSize % 4) {
     rowSize += (4 - (rowSize % 4));
   }
 
   // The height should be the absolute value of what the height is in the BIH.
   // If positive the bitmap is stored bottom to top, otherwise top to bottom
   int32_t pixelArraySize = rowSize * GetHeight();
   return pixelArraySize;
 }
 
 // Obtains whether or not a BMP file had alpha data in its 4th byte
 // for 32BPP bitmaps.  Only use after the bitmap has been processed.
-bool 
-nsBMPDecoder::HasAlphaData() const 
+bool
+nsBMPDecoder::HasAlphaData() const
 {
   return mHaveAlphaData;
 }
 
 
 void
 nsBMPDecoder::FinishInternal()
 {
@@ -147,35 +150,36 @@ nsBMPDecoder::FinishInternal()
         PostDecodeDone();
     }
 }
 
 // ----------------------------------------
 // Actual Data Processing
 // ----------------------------------------
 
-static void calcBitmask(uint32_t aMask, uint8_t& aBegin, uint8_t& aLength)
+static void
+calcBitmask(uint32_t aMask, uint8_t& aBegin, uint8_t& aLength)
 {
     // find the rightmost 1
     uint8_t pos;
     bool started = false;
     aBegin = aLength = 0;
     for (pos = 0; pos <= 31; pos++) {
         if (!started && (aMask & (1 << pos))) {
             aBegin = pos;
             started = true;
-        }
-        else if (started && !(aMask & (1 << pos))) {
+        } else if (started && !(aMask & (1 << pos))) {
             aLength = pos - aBegin;
             break;
         }
     }
 }
 
-NS_METHOD nsBMPDecoder::CalcBitShift()
+NS_METHOD
+nsBMPDecoder::CalcBitShift()
 {
     uint8_t begin, length;
     // red
     calcBitmask(mBitFields.red, begin, length);
     mBitFields.redRightShift = begin;
     mBitFields.redLeftShift = 8 - length;
     // green
     calcBitmask(mBitFields.green, begin, length);
@@ -184,705 +188,754 @@ NS_METHOD nsBMPDecoder::CalcBitShift()
     // blue
     calcBitmask(mBitFields.blue, begin, length);
     mBitFields.blueRightShift = begin;
     mBitFields.blueLeftShift = 8 - length;
     return NS_OK;
 }
 
 void
-nsBMPDecoder::WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy)
+nsBMPDecoder::WriteInternal(const char* aBuffer, uint32_t aCount,
+                            DecodeStrategy)
 {
-    NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
+  NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
+
+  // aCount=0 means EOF, mCurLine=0 means we're past end of image
+  if (!aCount || !mCurLine) {
+      return;
+  }
+
+  // This code assumes that mRawBuf == WIN_V3_INTERNAL_BIH_LENGTH
+  // and that sizeof(mRawBuf) >= BFH_INTERNAL_LENGTH
+  MOZ_ASSERT(sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH);
+  MOZ_ASSERT(sizeof(mRawBuf) >= BFH_INTERNAL_LENGTH);
+  MOZ_ASSERT(OS2_INTERNAL_BIH_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH);
+
+  // This code also assumes it's working with a byte array
+  MOZ_ASSERT(sizeof(mRawBuf[0]) == 1);
 
-    // aCount=0 means EOF, mCurLine=0 means we're past end of image
-    if (!aCount || !mCurLine)
-        return;
+  if (mPos < BFH_INTERNAL_LENGTH) { /* In BITMAPFILEHEADER */
+      // BFH_INTERNAL_LENGTH < sizeof(mRawBuf)
+      // mPos < BFH_INTERNAL_LENGTH
+      // BFH_INTERNAL_LENGTH - mPos < sizeof(mRawBuf)
+      // so toCopy <= BFH_INTERNAL_LENGTH
+      // so toCopy < sizeof(mRawBuf)
+      // so toCopy > 0 && toCopy <= BFH_INTERNAL_LENGTH
+      uint32_t toCopy = BFH_INTERNAL_LENGTH - mPos;
+      if (toCopy > aCount) {
+          toCopy = aCount;
+      }
+
+      // mRawBuf is a byte array of size WIN_V3_INTERNAL_BIH_LENGTH
+      // (verified above)
+      // mPos is < BFH_INTERNAL_LENGTH
+      // BFH_INTERNAL_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH
+      // so mPos < sizeof(mRawBuf)
+      //
+      // Therefore this assert should hold
+      MOZ_ASSERT(mPos < sizeof(mRawBuf));
 
-    // This code assumes that mRawBuf == WIN_V3_INTERNAL_BIH_LENGTH
-    // and that sizeof(mRawBuf) >= BFH_INTERNAL_LENGTH
-    MOZ_ASSERT(sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH);
-    MOZ_ASSERT(sizeof(mRawBuf) >= BFH_INTERNAL_LENGTH);
-    MOZ_ASSERT(OS2_INTERNAL_BIH_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH);
-    // This code also assumes it's working with a byte array
-    MOZ_ASSERT(sizeof(mRawBuf[0]) == 1);
+      // toCopy <= BFH_INTERNAL_LENGTH
+      // mPos >= 0 && mPos < BFH_INTERNAL_LENGTH
+      // sizeof(mRawBuf) >= BFH_INTERNAL_LENGTH (verified above)
+      //
+      // Therefore this assert should hold
+      MOZ_ASSERT(mPos + toCopy <= sizeof(mRawBuf));
+
+      memcpy(mRawBuf + mPos, aBuffer, toCopy);
+      mPos += toCopy;
+      aCount -= toCopy;
+      aBuffer += toCopy;
+  }
+  if (mPos == BFH_INTERNAL_LENGTH) {
+      ProcessFileHeader();
+      if (mBFH.signature[0] != 'B' || mBFH.signature[1] != 'M') {
+          PostDataError();
+          return;
+      }
+      if (mBFH.bihsize == OS2_BIH_LENGTH) {
+          mLOH = OS2_HEADER_LENGTH;
+      }
+  }
+  if (mPos >= BFH_INTERNAL_LENGTH && mPos < mLOH) { /* In BITMAPINFOHEADER */
+      // mLOH == WIN_V3_HEADER_LENGTH || mLOH == OS2_HEADER_LENGTH
+      // OS2_HEADER_LENGTH < WIN_V3_HEADER_LENGTH
+      // BFH_INTERNAL_LENGTH < OS2_HEADER_LENGTH
+      // BFH_INTERNAL_LENGTH < WIN_V3_HEADER_LENGTH
+      //
+      // So toCopy is in the range
+      //      1 to (WIN_V3_HEADER_LENGTH - BFH_INTERNAL_LENGTH)
+      // or   1 to (OS2_HEADER_LENGTH - BFH_INTERNAL_LENGTH)
+      //
+      // But WIN_V3_HEADER_LENGTH =
+      //     BFH_INTERNAL_LENGTH + WIN_V3_INTERNAL_BIH_LENGTH
+      // and OS2_HEADER_LENGTH = BFH_INTERNAL_LENGTH + OS2_INTERNAL_BIH_LENGTH
+      //
+      // So toCopy is in the range
+      //
+      //      1 to WIN_V3_INTERNAL_BIH_LENGTH
+      // or   1 to OS2_INTERNAL_BIH_LENGTH
+      // and  OS2_INTERNAL_BIH_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH
+      //
+      // sizeof(mRawBuf) = WIN_V3_INTERNAL_BIH_LENGTH
+      // so toCopy <= sizeof(mRawBuf)
+      uint32_t toCopy = mLOH - mPos;
+      if (toCopy > aCount) {
+          toCopy = aCount;
+      }
 
-    if (mPos < BFH_INTERNAL_LENGTH) { /* In BITMAPFILEHEADER */
-        // BFH_INTERNAL_LENGTH < sizeof(mRawBuf)
-        // mPos < BFH_INTERNAL_LENGTH
-        // BFH_INTERNAL_LENGTH - mPos < sizeof(mRawBuf)
-        // so toCopy <= BFH_INTERNAL_LENGTH
-        // so toCopy < sizeof(mRawBuf)
-        // so toCopy > 0 && toCopy <= BFH_INTERNAL_LENGTH
-        uint32_t toCopy = BFH_INTERNAL_LENGTH - mPos;
-        if (toCopy > aCount)
-            toCopy = aCount;
+      // mPos is in the range
+      //      BFH_INTERNAL_LENGTH to (WIN_V3_HEADER_LENGTH - 1)
+      //
+      // offset is then in the range (see toCopy comments for more details)
+      //      0 to (WIN_V3_INTERNAL_BIH_LENGTH - 1)
+      //
+      // sizeof(mRawBuf) is WIN_V3_INTERNAL_BIH_LENGTH so this
+      // offset stays within bounds and this assert should hold
+      const uint32_t offset = mPos - BFH_INTERNAL_LENGTH;
+      MOZ_ASSERT(offset < sizeof(mRawBuf));
+
+      // Two cases:
+      //      mPos = BFH_INTERNAL_LENGTH
+      //      mLOH = WIN_V3_HEADER_LENGTH
+      //
+      // offset = 0
+      // toCopy = WIN_V3_INTERNAL_BIH_LENGTH
+      //
+      //      This will be in the bounds of sizeof(mRawBuf)
+      //
+      // Second Case:
+      //      mPos = WIN_V3_HEADER_LENGTH - 1
+      //      mLOH = WIN_V3_HEADER_LENGTH
+      //
+      // offset = WIN_V3_INTERNAL_BIH_LENGTH - 1
+      // toCopy = 1
+      //
+      //      This will be in the bounds of sizeof(mRawBuf)
+      //
+      // As sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH (verified above)
+      // and WIN_V3_HEADER_LENGTH is the largest range of values. If mLOH
+      // was equal to OS2_HEADER_LENGTH then the ranges are smaller.
+      MOZ_ASSERT(offset + toCopy <= sizeof(mRawBuf));
+
+      memcpy(mRawBuf + offset, aBuffer, toCopy);
+      mPos += toCopy;
+      aCount -= toCopy;
+      aBuffer += toCopy;
+  }
+
+  // At this point mPos should be >= mLOH unless aBuffer did not have enough
+  // data. In the latter case aCount should be 0.
+  MOZ_ASSERT(mPos >= mLOH || aCount == 0);
 
-        // mRawBuf is a byte array of size WIN_V3_INTERNAL_BIH_LENGTH (verified above)
-        // mPos is < BFH_INTERNAL_LENGTH
-        // BFH_INTERNAL_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH
-        // so mPos < sizeof(mRawBuf)
-        //
-        // Therefore this assert should hold
-        MOZ_ASSERT(mPos < sizeof(mRawBuf));
+  // HasSize is called to ensure that if at this point mPos == mLOH but
+  // we have no data left to process, the next time WriteInternal is called
+  // we won't enter this condition again.
+  if (mPos == mLOH && !HasSize()) {
+      ProcessInfoHeader();
+      PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
+             ("BMP is %lix%lix%lu. compression=%lu\n",
+             mBIH.width, mBIH.height, mBIH.bpp, mBIH.compression));
+      // Verify we support this bit depth
+      if (mBIH.bpp != 1 && mBIH.bpp != 4 && mBIH.bpp != 8 &&
+          mBIH.bpp != 16 && mBIH.bpp != 24 && mBIH.bpp != 32) {
+        PostDataError();
+        return;
+      }
+
+      // BMPs with negative width are invalid
+      // Reject extremely wide images to keep the math sane
+      const int32_t k64KWidth = 0x0000FFFF;
+      if (mBIH.width < 0 || mBIH.width > k64KWidth) {
+        PostDataError();
+        return;
+      }
 
-        // toCopy <= BFH_INTERNAL_LENGTH
-        // mPos >= 0 && mPos < BFH_INTERNAL_LENGTH
-        // sizeof(mRawBuf) >= BFH_INTERNAL_LENGTH (verified above)
-        //
-        // Therefore this assert should hold
-        MOZ_ASSERT(mPos + toCopy <= sizeof(mRawBuf));
+      if (mBIH.height == INT_MIN) {
+        PostDataError();
+        return;
+      }
+
+      uint32_t real_height = GetHeight();
+
+      // Post our size to the superclass
+      PostSize(mBIH.width, real_height);
+      if (HasError()) {
+        // Setting the size led to an error.
+        return;
+      }
 
-        memcpy(mRawBuf + mPos, aBuffer, toCopy);
-        mPos += toCopy;
-        aCount -= toCopy;
-        aBuffer += toCopy;
-    }
-    if (mPos == BFH_INTERNAL_LENGTH) {
-        ProcessFileHeader();
-        if (mBFH.signature[0] != 'B' || mBFH.signature[1] != 'M') {
-            PostDataError();
-            return;
+      // We have the size. If we're doing a size decode, we got what
+      // we came for.
+      if (IsSizeDecode()) {
+        return;
+      }
+
+      // We're doing a real decode.
+      mOldLine = mCurLine = real_height;
+
+      if (mBIH.bpp <= 8) {
+        mNumColors = 1 << mBIH.bpp;
+        if (mBIH.colors && mBIH.colors < mNumColors) {
+            mNumColors = mBIH.colors;
         }
-        if (mBFH.bihsize == OS2_BIH_LENGTH)
-            mLOH = OS2_HEADER_LENGTH;
-    }
-    if (mPos >= BFH_INTERNAL_LENGTH && mPos < mLOH) { /* In BITMAPINFOHEADER */
-        // mLOH == WIN_V3_HEADER_LENGTH || mLOH == OS2_HEADER_LENGTH
-        // OS2_HEADER_LENGTH < WIN_V3_HEADER_LENGTH
-        // BFH_INTERNAL_LENGTH < OS2_HEADER_LENGTH
-        // BFH_INTERNAL_LENGTH < WIN_V3_HEADER_LENGTH
-        //
-        // So toCopy is in the range
-        //      1 to (WIN_V3_HEADER_LENGTH - BFH_INTERNAL_LENGTH)
-        // or   1 to (OS2_HEADER_LENGTH - BFH_INTERNAL_LENGTH)
-        //
-        // But WIN_V3_HEADER_LENGTH = BFH_INTERNAL_LENGTH + WIN_V3_INTERNAL_BIH_LENGTH
-        // and OS2_HEADER_LENGTH = BFH_INTERNAL_LENGTH + OS2_INTERNAL_BIH_LENGTH
-        //
-        // So toCopy is in the range
-        //
-        //      1 to WIN_V3_INTERNAL_BIH_LENGTH
-        // or   1 to OS2_INTERNAL_BIH_LENGTH
-        // and  OS2_INTERNAL_BIH_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH
-        //
-        // sizeof(mRawBuf) = WIN_V3_INTERNAL_BIH_LENGTH
-        // so toCopy <= sizeof(mRawBuf)
-        uint32_t toCopy = mLOH - mPos;
-        if (toCopy > aCount)
-            toCopy = aCount;
 
-        // mPos is in the range
-        //      BFH_INTERNAL_LENGTH to (WIN_V3_HEADER_LENGTH - 1)
-        //
-        // offset is then in the range (see toCopy comments for more details)
-        //      0 to (WIN_V3_INTERNAL_BIH_LENGTH - 1)
-        //
-        // sizeof(mRawBuf) is WIN_V3_INTERNAL_BIH_LENGTH so this
-        // offset stays within bounds and this assert should hold
-        const uint32_t offset = mPos - BFH_INTERNAL_LENGTH;
-        MOZ_ASSERT(offset < sizeof(mRawBuf));
+        // Always allocate 256 even though mNumColors might be smaller
+        mColors = new colorTable[256];
+        memset(mColors, 0, 256 * sizeof(colorTable));
+      } else if (mBIH.compression != BI_BITFIELDS && mBIH.bpp == 16) {
+        // Use default 5-5-5 format
+        mBitFields.red   = 0x7C00;
+        mBitFields.green = 0x03E0;
+        mBitFields.blue  = 0x001F;
+        CalcBitShift();
+      }
+
+      // Make sure we have a valid value for our supported compression modes
+      // before adding the frame
+      if (mBIH.compression != BI_RGB && mBIH.compression != BI_RLE8 &&
+          mBIH.compression != BI_RLE4 && mBIH.compression != BI_BITFIELDS) {
+        PostDataError();
+        return;
+      }
 
-        // Two cases:
-        //      mPos = BFH_INTERNAL_LENGTH
-        //      mLOH = WIN_V3_HEADER_LENGTH
-        //
-        // offset = 0
-        // toCopy = WIN_V3_INTERNAL_BIH_LENGTH
-        //
-        //      This will be in the bounds of sizeof(mRawBuf)
-        //
-        // Second Case:
-        //      mPos = WIN_V3_HEADER_LENGTH - 1
-        //      mLOH = WIN_V3_HEADER_LENGTH
-        //
-        // offset = WIN_V3_INTERNAL_BIH_LENGTH - 1
-        // toCopy = 1
-        //
-        //      This will be in the bounds of sizeof(mRawBuf)
-        //
-        // As sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH (verified above)
-        // and WIN_V3_HEADER_LENGTH is the largest range of values. If mLOH
-        // was equal to OS2_HEADER_LENGTH then the ranges are smaller.
-        MOZ_ASSERT(offset + toCopy <= sizeof(mRawBuf));
+      // If we have RLE4 or RLE8 or BI_ALPHABITFIELDS, then ensure we
+      // have valid BPP values before adding the frame
+      if (mBIH.compression == BI_RLE8 && mBIH.bpp != 8) {
+        PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
+               ("BMP RLE8 compression only supports 8 bits per pixel\n"));
+        PostDataError();
+        return;
+      }
+      if (mBIH.compression == BI_RLE4 && mBIH.bpp != 4 && mBIH.bpp != 1) {
+        PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
+               ("BMP RLE4 compression only supports 4 bits per pixel\n"));
+        PostDataError();
+        return;
+      }
+      if (mBIH.compression == BI_ALPHABITFIELDS &&
+          mBIH.bpp != 16 && mBIH.bpp != 32) {
+        PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
+               ("BMP ALPHABITFIELDS only supports 16 or 32 bits per pixel\n"
+                ));
+        PostDataError();
+        return;
+      }
 
-        memcpy(mRawBuf + offset, aBuffer, toCopy);
-        mPos += toCopy;
-        aCount -= toCopy;
-        aBuffer += toCopy;
-    }
-
-    // At this point mPos should be >= mLOH unless aBuffer did not have enough
-    // data. In the latter case aCount should be 0.
-    MOZ_ASSERT(mPos >= mLOH || aCount == 0);
-
-    // HasSize is called to ensure that if at this point mPos == mLOH but
-    // we have no data left to process, the next time WriteInternal is called
-    // we won't enter this condition again.
-    if (mPos == mLOH && !HasSize()) {
-        ProcessInfoHeader();
-        PR_LOG(GetBMPLog(), PR_LOG_DEBUG, ("BMP is %lix%lix%lu. compression=%lu\n",
-               mBIH.width, mBIH.height, mBIH.bpp, mBIH.compression));
-        // Verify we support this bit depth
-        if (mBIH.bpp != 1 && mBIH.bpp != 4 && mBIH.bpp != 8 &&
-            mBIH.bpp != 16 && mBIH.bpp != 24 && mBIH.bpp != 32) {
+      if (mBIH.compression != BI_RLE8 && mBIH.compression != BI_RLE4 &&
+          mBIH.compression != BI_ALPHABITFIELDS) {
+        // mRow is not used for RLE encoded images
+        mRow = (uint8_t*)moz_malloc((mBIH.width * mBIH.bpp) / 8 + 4);
+        // + 4 because the line is padded to a 4 bit boundary, but
+        // I don't want to make exact calculations here, that's unnecessary.
+        // Also, it compensates rounding error.
+        if (!mRow) {
           PostDataError();
           return;
         }
+      }
+      if (!mImageData) {
+        PostDecoderError(NS_ERROR_FAILURE);
+        return;
+      }
 
-        // BMPs with negative width are invalid
-        // Reject extremely wide images to keep the math sane
-        const int32_t k64KWidth = 0x0000FFFF;
-        if (mBIH.width < 0 || mBIH.width > k64KWidth) {
-            PostDataError();
-            return;
+      // Prepare for transparency
+      if ((mBIH.compression == BI_RLE8) || (mBIH.compression == BI_RLE4)) {
+        // Clear the image, as the RLE may jump over areas
+        memset(mImageData, 0, mImageDataLength);
+      }
+  }
+
+  if (mColors && mPos >= mLOH) {
+    // OS/2 Bitmaps have no padding byte
+    uint8_t bytesPerColor = (mBFH.bihsize == OS2_BIH_LENGTH) ? 3 : 4;
+    if (mPos < (mLOH + mNumColors * bytesPerColor)) {
+      // Number of bytes already received
+      uint32_t colorBytes = mPos - mLOH;
+      // Color which is currently received
+      uint8_t colorNum = colorBytes / bytesPerColor;
+      uint8_t at = colorBytes % bytesPerColor;
+      while (aCount && (mPos < (mLOH + mNumColors * bytesPerColor))) {
+        switch (at) {
+          case 0:
+            mColors[colorNum].blue = *aBuffer;
+            break;
+          case 1:
+            mColors[colorNum].green = *aBuffer;
+            break;
+          case 2:
+            mColors[colorNum].red = *aBuffer;
+            // If there is no padding byte, increment the color index
+            // since we're done with the current color.
+            if (bytesPerColor == 3) {
+              colorNum++;
+            }
+            break;
+          case 3:
+            // This is a padding byte only in Windows BMPs. Increment
+            // the color index since we're done with the current color.
+            colorNum++;
+            break;
+        }
+        mPos++; aBuffer++; aCount--;
+        at = (at + 1) % bytesPerColor;
+      }
+    }
+  } else if (aCount && mBIH.compression == BI_BITFIELDS && mPos <
+         (WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH)) {
+    // If compression is used, this is a windows bitmap (compression
+    // can't be used with OS/2 bitmaps),
+    // hence we can use WIN_V3_HEADER_LENGTH instead of mLOH.
+    // (verified below)
+
+    // If aCount != 0 then mPos should be >= mLOH due to the if statements
+    // at the beginning of the function
+    MOZ_ASSERT(mPos >= mLOH);
+    MOZ_ASSERT(mLOH == WIN_V3_HEADER_LENGTH);
+
+    // mLOH == WIN_V3_HEADER_LENGTH (verified above)
+    // mPos >= mLOH (verified above)
+    // mPos < WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH
+    //
+    // So toCopy is in the range
+    //      0 to (BITFIELD_LENGTH - 1)
+    uint32_t toCopy = (WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH) - mPos;
+    if (toCopy > aCount) {
+      toCopy = aCount;
+    }
+
+    // mPos >= WIN_V3_HEADER_LENGTH
+    // mPos < WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH
+    //
+    // offset is in the range
+    //      0 to (BITFIELD_LENGTH - 1)
+    //
+    // BITFIELD_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH
+    // and sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH (verified at
+    // top of function)
+    //
+    // Therefore this assert should hold
+    const uint32_t offset = mPos - WIN_V3_HEADER_LENGTH;
+    MOZ_ASSERT(offset < sizeof(mRawBuf));
+
+    // Two cases:
+    //      mPos = WIN_V3_HEADER_LENGTH
+    //
+    // offset = 0
+    // toCopy = BITFIELD_LENGTH
+    //
+    //      This will be in the bounds of sizeof(mRawBuf)
+    //
+    // Second case:
+    //
+    //      mPos = WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH - 1
+    //
+    // offset = BITFIELD_LENGTH - 1
+    // toCopy = 1
+    //
+    //      This will be in the bounds of sizeof(mRawBuf)
+    //
+    // As BITFIELD_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH and
+    // sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH
+    //
+    // Therefore this assert should hold
+    MOZ_ASSERT(offset + toCopy <= sizeof(mRawBuf));
+
+    memcpy(mRawBuf + offset, aBuffer, toCopy);
+    mPos += toCopy;
+    aBuffer += toCopy;
+    aCount -= toCopy;
+  }
+  if (mPos == WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH &&
+    mBIH.compression == BI_BITFIELDS) {
+    mBitFields.red = LittleEndian::readUint32(reinterpret_cast<uint32_t*>
+                                              (mRawBuf));
+    mBitFields.green = LittleEndian::readUint32(reinterpret_cast<uint32_t*>
+                                                (mRawBuf + 4));
+    mBitFields.blue = LittleEndian::readUint32(reinterpret_cast<uint32_t*>
+                                               (mRawBuf + 8));
+    CalcBitShift();
+  }
+  while (aCount && (mPos < mBFH.dataoffset)) { // Skip whatever is between
+                                               // header and data
+    mPos++; aBuffer++; aCount--;
+  }
+  if (aCount && ++mPos >= mBFH.dataoffset) {
+    // Need to increment mPos, else we might get to mPos==mLOH again
+    // From now on, mPos is irrelevant
+    if (!mBIH.compression || mBIH.compression == BI_BITFIELDS) {
+        uint32_t rowSize = (mBIH.bpp * mBIH.width + 7) / 8; // + 7 to
+                                                            // round up
+        if (rowSize % 4) {
+          rowSize += (4 - (rowSize % 4)); // Pad to DWORD Boundary
+        }
+        uint32_t toCopy;
+        do {
+          toCopy = rowSize - mRowBytes;
+          if (toCopy) {
+            if (toCopy > aCount) {
+              toCopy = aCount;
+            }
+            memcpy(mRow + mRowBytes, aBuffer, toCopy);
+            aCount -= toCopy;
+            aBuffer += toCopy;
+            mRowBytes += toCopy;
         }
+        if (rowSize == mRowBytes) {
+          // Collected a whole row into mRow, process it
+          uint8_t* p = mRow;
+          uint32_t* d = reinterpret_cast<uint32_t*>(mImageData) +
+                        PIXEL_OFFSET(mCurLine, 0);
+          uint32_t lpos = mBIH.width;
+          switch (mBIH.bpp) {
+            case 1:
+              while (lpos > 0) {
+                int8_t bit;
+                uint8_t idx;
+                for (bit = 7; bit >= 0 && lpos > 0; bit--) {
+                  idx = (*p >> bit) & 1;
+                  SetPixel(d, idx, mColors);
+                  --lpos;
+                }
+                ++p;
+              }
+              break;
+            case 4:
+              while (lpos > 0) {
+                Set4BitPixel(d, *p, lpos, mColors);
+                ++p;
+              }
+              break;
+            case 8:
+              while (lpos > 0) {
+                SetPixel(d, *p, mColors);
+                --lpos;
+                ++p;
+              }
+              break;
+            case 16:
+              while (lpos > 0) {
+                uint16_t val = LittleEndian::
+                               readUint16(reinterpret_cast<uint16_t*>(p));
+                SetPixel(d,
+                         (val & mBitFields.red) >>
+                         mBitFields.redRightShift <<
+                         mBitFields.redLeftShift,
+                         (val & mBitFields.green) >>
+                         mBitFields.greenRightShift <<
+                         mBitFields.greenLeftShift,
+                         (val & mBitFields.blue) >>
+                         mBitFields.blueRightShift <<
+                         mBitFields.blueLeftShift);
+                --lpos;
+                p+=2;
+              }
+              break;
+            case 24:
+              while (lpos > 0) {
+                SetPixel(d, p[2], p[1], p[0]);
+                p += 2;
+                --lpos;
+                ++p;
+              }
+              break;
+            case 32:
+              while (lpos > 0) {
+                if (mUseAlphaData) {
+                  if (!mHaveAlphaData && p[3]) {
+                    // Non-zero alpha byte detected! Clear previous
+                    // pixels that we have already processed.
+                    // This works because we know that if we
+                    // are reaching here then the alpha data in byte
+                    // 4 has been right all along.  And we know it
+                    // has been set to 0 the whole time, so that
+                    // means that everything is transparent so far.
+                    uint32_t* start = reinterpret_cast<uint32_t*>
+                                      (mImageData) + GetWidth() *
+                                      (mCurLine - 1);
+                    uint32_t heightDifference = GetHeight() -
+                                                mCurLine + 1;
+                    uint32_t pixelCount = GetWidth() *
+                                          heightDifference;
 
-        if (mBIH.height == INT_MIN) {
-            PostDataError();
+                    memset(start, 0, pixelCount * sizeof(uint32_t));
+
+                    mHaveAlphaData = true;
+                  }
+                  SetPixel(d, p[2], p[1], p[0], mHaveAlphaData ?
+                           p[3] : 0xFF);
+                } else {
+                  SetPixel(d, p[2], p[1], p[0]);
+                }
+                p += 4;
+                --lpos;
+              }
+              break;
+            default:
+              NS_NOTREACHED("Unsupported color depth,"
+                            " but earlier check didn't catch it");
+          }
+          mCurLine --;
+          if (mCurLine == 0) { // Finished last line
+            break;
+          }
+          mRowBytes = 0;
+        }
+      } while (aCount > 0);
+    } else if ((mBIH.compression == BI_RLE8) ||
+             (mBIH.compression == BI_RLE4)) {
+      if (((mBIH.compression == BI_RLE8) && (mBIH.bpp != 8)) ||
+          ((mBIH.compression == BI_RLE4) && (mBIH.bpp != 4) &&
+           (mBIH.bpp != 1))) {
+        PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
+               ("BMP RLE8/RLE4 compression only supports 8/4 bits per"
+               " pixel\n"));
+        PostDataError();
+        return;
+      }
+
+      while (aCount > 0) {
+        uint8_t byte;
+
+        switch(mState) {
+          case eRLEStateInitial:
+            mStateData = (uint8_t)*aBuffer++;
+            aCount--;
+
+            mState = eRLEStateNeedSecondEscapeByte;
+            continue;
+
+          case eRLEStateNeedSecondEscapeByte:
+            byte = *aBuffer++;
+            aCount--;
+            if (mStateData != RLE_ESCAPE) { // encoded mode
+              // Encoded mode consists of two bytes:
+              // the first byte (mStateData) specifies the
+              // number of consecutive pixels to be drawn
+              // using the color index contained in
+              // the second byte
+              // Work around bitmaps that specify too many pixels
+              mState = eRLEStateInitial;
+              uint32_t pixelsNeeded = std::min<uint32_t>(mBIH.width - mCurPos,
+                                    mStateData);
+              if (pixelsNeeded) {
+                uint32_t* d = reinterpret_cast<uint32_t*>
+                              (mImageData) + PIXEL_OFFSET(mCurLine, mCurPos);
+                mCurPos += pixelsNeeded;
+                if (mBIH.compression == BI_RLE8) {
+                  do {
+                    SetPixel(d, byte, mColors);
+                    pixelsNeeded --;
+                  } while (pixelsNeeded);
+                } else {
+                    do {
+                      Set4BitPixel(d, byte, pixelsNeeded, mColors);
+                  } while (pixelsNeeded);
+                }
+              }
+              continue;
+            }
+
+            switch(byte) {
+              case RLE_ESCAPE_EOL:
+                // End of Line: Go to next row
+                mCurLine --;
+                mCurPos = 0;
+                mState = eRLEStateInitial;
+                break;
+
+              case RLE_ESCAPE_EOF: // EndOfFile
+                mCurPos = mCurLine = 0;
+                break;
+
+              case RLE_ESCAPE_DELTA:
+                mState = eRLEStateNeedXDelta;
+                continue;
+
+              default : // absolute mode
+                // Save the number of pixels to read
+                mStateData = byte;
+                if (mCurPos + mStateData > (uint32_t)mBIH.width) {
+                  // We can work around bitmaps that specify
+                  // one pixel too many, but only if their
+                  // width is odd.
+                  mStateData -= mBIH.width & 1;
+                  if (mCurPos + mStateData > (uint32_t)mBIH.width) {
+                      PostDataError();
+                      return;
+                  }
+                }
+
+              // See if we will need to skip a byte
+              // to word align the pixel data
+              // mStateData is a number of pixels
+              // so allow for the RLE compression type
+              // Pixels RLE8=1 RLE4=2
+              //    1    Pad    Pad
+              //    2    No     Pad
+              //    3    Pad    No
+              //    4    No     No
+              if (((mStateData - 1) & mBIH.compression) != 0) {
+                  mState = eRLEStateAbsoluteMode;
+              } else {
+                  mState = eRLEStateAbsoluteModePadded;
+              }
+              continue;
+            }
+            break;
+
+          case eRLEStateNeedXDelta:
+            // Handle the XDelta and proceed to get Y Delta
+            byte = *aBuffer++;
+            aCount--;
+            mCurPos += byte;
+            // Delta encoding makes it possible to skip pixels
+            // making the image transparent.
+            mUseAlphaData = mHaveAlphaData = true;
+            if (mCurPos > mBIH.width) {
+                mCurPos = mBIH.width;
+            }
+
+            mState = eRLEStateNeedYDelta;
+            continue;
+
+          case eRLEStateNeedYDelta:
+            // Get the Y Delta and then "handle" the move
+            byte = *aBuffer++;
+            aCount--;
+            mState = eRLEStateInitial;
+            // Delta encoding makes it possible to skip pixels
+            // making the image transparent.
+            mUseAlphaData = mHaveAlphaData = true;
+            mCurLine -= std::min<int32_t>(byte, mCurLine);
+            break;
+
+          case eRLEStateAbsoluteMode: // Absolute Mode
+          case eRLEStateAbsoluteModePadded:
+            if (mStateData) {
+              // In absolute mode, the second byte (mStateData)
+              // represents the number of pixels
+              // that follow, each of which contains
+              // the color index of a single pixel.
+              uint32_t* d = reinterpret_cast<uint32_t*>
+                            (mImageData) +
+                            PIXEL_OFFSET(mCurLine, mCurPos);
+              uint32_t* oldPos = d;
+              if (mBIH.compression == BI_RLE8) {
+                  while (aCount > 0 && mStateData > 0) {
+                    byte = *aBuffer++;
+                    aCount--;
+                    SetPixel(d, byte, mColors);
+                    mStateData--;
+                  }
+              } else {
+                  while (aCount > 0 && mStateData > 0) {
+                    byte = *aBuffer++;
+                    aCount--;
+                    Set4BitPixel(d, byte, mStateData, mColors);
+                  }
+              }
+              mCurPos += d - oldPos;
+            }
+
+            if (mStateData == 0) {
+              // In absolute mode, each run must
+              // be aligned on a word boundary
+
+              if (mState == eRLEStateAbsoluteMode) {
+                // word aligned
+                mState = eRLEStateInitial;
+              } else if (aCount > 0) {
+                // not word aligned
+                // "next" byte is just a padding byte
+                // so "move" past it and we can continue
+                aBuffer++;
+                aCount--;
+                mState = eRLEStateInitial;
+              }
+            }
+            // else state is still eRLEStateAbsoluteMode
+            continue;
+
+          default :
+            NS_ABORT_IF_FALSE(0,
+                           "BMP RLE decompression: unknown state!");
+            PostDecoderError(NS_ERROR_UNEXPECTED);
             return;
         }
-
-        uint32_t real_height = GetHeight();
-
-        // Post our size to the superclass
-        PostSize(mBIH.width, real_height);
-        if (HasError()) {
-          // Setting the size led to an error.
-          return;
-        }
-
-        // We have the size. If we're doing a size decode, we got what
-        // we came for.
-        if (IsSizeDecode())
-            return;
-
-        // We're doing a real decode.
-        mOldLine = mCurLine = real_height;
-
-        if (mBIH.bpp <= 8) {
-            mNumColors = 1 << mBIH.bpp;
-            if (mBIH.colors && mBIH.colors < mNumColors)
-                mNumColors = mBIH.colors;
-
-            // Always allocate 256 even though mNumColors might be smaller
-            mColors = new colorTable[256];
-            memset(mColors, 0, 256 * sizeof(colorTable));
-        }
-        else if (mBIH.compression != BI_BITFIELDS && mBIH.bpp == 16) {
-            // Use default 5-5-5 format
-            mBitFields.red   = 0x7C00;
-            mBitFields.green = 0x03E0;
-            mBitFields.blue  = 0x001F;
-            CalcBitShift();
-        }
-
-        // Make sure we have a valid value for our supported compression modes
-        // before adding the frame
-        if (mBIH.compression != BI_RGB && mBIH.compression != BI_RLE8 && 
-            mBIH.compression != BI_RLE4 && mBIH.compression != BI_BITFIELDS) {
-          PostDataError();
-          return;
-        }
-
-        // If we have RLE4 or RLE8 or BI_ALPHABITFIELDS, then ensure we
-        // have valid BPP values before adding the frame
-        if (mBIH.compression == BI_RLE8 && mBIH.bpp != 8) {
-          PR_LOG(GetBMPLog(), PR_LOG_DEBUG, 
-                 ("BMP RLE8 compression only supports 8 bits per pixel\n"));
-          PostDataError();
-          return;
-        }
-        if (mBIH.compression == BI_RLE4 && mBIH.bpp != 4 && mBIH.bpp != 1) {
-          PR_LOG(GetBMPLog(), PR_LOG_DEBUG, 
-                 ("BMP RLE4 compression only supports 4 bits per pixel\n"));
-          PostDataError();
-          return;
-        }
-        if (mBIH.compression == BI_ALPHABITFIELDS && 
-            mBIH.bpp != 16 && mBIH.bpp != 32) {
-          PR_LOG(GetBMPLog(), PR_LOG_DEBUG, 
-                 ("BMP ALPHABITFIELDS only supports 16 or 32 bits per pixel\n"));
-          PostDataError();
-          return;
-        }
-
-        if (mBIH.compression != BI_RLE8 && mBIH.compression != BI_RLE4 &&
-            mBIH.compression != BI_ALPHABITFIELDS) {
-            // mRow is not used for RLE encoded images
-            mRow = (uint8_t*)moz_malloc((mBIH.width * mBIH.bpp) / 8 + 4);
-            // + 4 because the line is padded to a 4 bit boundary, but I don't want
-            // to make exact calculations here, that's unnecessary.
-            // Also, it compensates rounding error.
-            if (!mRow) {
-              PostDataError();
-              return;
-            }
-        }
-        if (!mImageData) {
-            PostDecoderError(NS_ERROR_FAILURE);
-            return;
-        }
-
-        // Prepare for transparency
-        if ((mBIH.compression == BI_RLE8) || (mBIH.compression == BI_RLE4)) {
-            // Clear the image, as the RLE may jump over areas
-            memset(mImageData, 0, mImageDataLength);
-        }
-    }
-
-    if (mColors && mPos >= mLOH) {
-      // OS/2 Bitmaps have no padding byte
-      uint8_t bytesPerColor = (mBFH.bihsize == OS2_BIH_LENGTH) ? 3 : 4;
-      if (mPos < (mLOH + mNumColors * bytesPerColor)) {
-        // Number of bytes already received
-        uint32_t colorBytes = mPos - mLOH; 
-        // Color which is currently received
-        uint8_t colorNum = colorBytes / bytesPerColor;
-        uint8_t at = colorBytes % bytesPerColor;
-        while (aCount && (mPos < (mLOH + mNumColors * bytesPerColor))) {
-            switch (at) {
-                case 0:
-                    mColors[colorNum].blue = *aBuffer;
-                    break;
-                case 1:
-                    mColors[colorNum].green = *aBuffer;
-                    break;
-                case 2:
-                    mColors[colorNum].red = *aBuffer;
-                    // If there is no padding byte, increment the color index
-                    // since we're done with the current color.
-                    if (bytesPerColor == 3)
-                      colorNum++;
-                    break;
-                case 3:
-                    // This is a padding byte only in Windows BMPs. Increment
-                    // the color index since we're done with the current color.
-                    colorNum++;
-                    break;
-            }
-            mPos++; aBuffer++; aCount--;
-            at = (at + 1) % bytesPerColor;
+        // Because of the use of the continue statement
+        // we only get here for eol, eof or y delta
+        if (mCurLine == 0) {
+          // Finished last line
+          break;
         }
       }
     }
-    else if (aCount && mBIH.compression == BI_BITFIELDS && mPos < (WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH)) {
-        // If compression is used, this is a windows bitmap (compression can't be used with OS/2 bitmaps),
-        // hence we can use WIN_V3_HEADER_LENGTH instead of mLOH.
-        // (verified below)
-
-        // If aCount != 0 then mPos should be >= mLOH due to the if statements
-        // at the beginning of the function
-        MOZ_ASSERT(mPos >= mLOH);
-        MOZ_ASSERT(mLOH == WIN_V3_HEADER_LENGTH);
-
-        // mLOH == WIN_V3_HEADER_LENGTH (verified above)
-        // mPos >= mLOH (verified above)
-        // mPos < WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH
-        //
-        // So toCopy is in the range
-        //      0 to (BITFIELD_LENGTH - 1)
-        uint32_t toCopy = (WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH) - mPos;
-        if (toCopy > aCount)
-            toCopy = aCount;
-
-        // mPos >= WIN_V3_HEADER_LENGTH
-        // mPos < WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH
-        //
-        // offset is in the range
-        //      0 to (BITFIELD_LENGTH - 1)
-        //
-        // BITFIELD_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH
-        // and sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH (verified at top of function)
-        //
-        // Therefore this assert should hold
-        const uint32_t offset = mPos - WIN_V3_HEADER_LENGTH;
-        MOZ_ASSERT(offset < sizeof(mRawBuf));
-
-        // Two cases:
-        //      mPos = WIN_V3_HEADER_LENGTH
-        //
-        // offset = 0
-        // toCopy = BITFIELD_LENGTH
-        //
-        //      This will be in the bounds of sizeof(mRawBuf)
-        //
-        // Second case:
-        //
-        //      mPos = WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH - 1
-        //
-        // offset = BITFIELD_LENGTH - 1
-        // toCopy = 1
-        //
-        //      This will be in the bounds of sizeof(mRawBuf)
-        //
-        // As BITFIELD_LENGTH < WIN_V3_INTERNAL_BIH_LENGTH and
-        // sizeof(mRawBuf) == WIN_V3_INTERNAL_BIH_LENGTH
-        //
-        // Therefore this assert should hold
-        MOZ_ASSERT(offset + toCopy <= sizeof(mRawBuf));
+  }
 
-        memcpy(mRawBuf + offset, aBuffer, toCopy);
-        mPos += toCopy;
-        aBuffer += toCopy;
-        aCount -= toCopy;
-    }
-    if (mPos == WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH && 
-        mBIH.compression == BI_BITFIELDS) {
-        mBitFields.red = LittleEndian::readUint32(reinterpret_cast<uint32_t*>(mRawBuf));
-        mBitFields.green = LittleEndian::readUint32(reinterpret_cast<uint32_t*>(mRawBuf + 4));
-        mBitFields.blue = LittleEndian::readUint32(reinterpret_cast<uint32_t*>(mRawBuf + 8));
-        CalcBitShift();
-    }
-    while (aCount && (mPos < mBFH.dataoffset)) { // Skip whatever is between header and data
-        mPos++; aBuffer++; aCount--;
-    }
-    if (aCount && ++mPos >= mBFH.dataoffset) {
-        // Need to increment mPos, else we might get to mPos==mLOH again
-        // From now on, mPos is irrelevant
-        if (!mBIH.compression || mBIH.compression == BI_BITFIELDS) {
-            uint32_t rowSize = (mBIH.bpp * mBIH.width + 7) / 8; // + 7 to round up
-            if (rowSize % 4) {
-                rowSize += (4 - (rowSize % 4)); // Pad to DWORD Boundary
-            }
-            uint32_t toCopy;
-            do {
-                toCopy = rowSize - mRowBytes;
-                if (toCopy) {
-                    if (toCopy > aCount)
-                        toCopy = aCount;
-                    memcpy(mRow + mRowBytes, aBuffer, toCopy);
-                    aCount -= toCopy;
-                    aBuffer += toCopy;
-                    mRowBytes += toCopy;
-                }
-                if (rowSize == mRowBytes) {
-                    // Collected a whole row into mRow, process it
-                    uint8_t* p = mRow;
-                    uint32_t* d = reinterpret_cast<uint32_t*>(mImageData) + PIXEL_OFFSET(mCurLine, 0);
-                    uint32_t lpos = mBIH.width;
-                    switch (mBIH.bpp) {
-                      case 1:
-                        while (lpos > 0) {
-                          int8_t bit;
-                          uint8_t idx;
-                          for (bit = 7; bit >= 0 && lpos > 0; bit--) {
-                              idx = (*p >> bit) & 1;
-                              SetPixel(d, idx, mColors);
-                              --lpos;
-                          }
-                          ++p;
-                        }
-                        break;
-                      case 4:
-                        while (lpos > 0) {
-                          Set4BitPixel(d, *p, lpos, mColors);
-                          ++p;
-                        }
-                        break;
-                      case 8:
-                        while (lpos > 0) {
-                          SetPixel(d, *p, mColors);
-                          --lpos;
-                          ++p;
-                        }
-                        break;
-                      case 16:
-                        while (lpos > 0) {
-                          uint16_t val = LittleEndian::readUint16(reinterpret_cast<uint16_t*>(p));
-                          SetPixel(d,
-                                  (val & mBitFields.red) >> mBitFields.redRightShift << mBitFields.redLeftShift,
-                                  (val & mBitFields.green) >> mBitFields.greenRightShift << mBitFields.greenLeftShift,
-                                  (val & mBitFields.blue) >> mBitFields.blueRightShift << mBitFields.blueLeftShift);
-                          --lpos;
-                          p+=2;
-                        }
-                        break;
-                      case 24:
-                        while (lpos > 0) {
-                          SetPixel(d, p[2], p[1], p[0]);
-                          p += 2;
-                          --lpos;
-                          ++p;
-                        }
-                        break;
-                      case 32:
-                        while (lpos > 0) {
-                          if (mUseAlphaData) {
-                            if (!mHaveAlphaData && p[3]) {
-                              // Non-zero alpha byte detected! Clear previous
-                              // pixels that we have already processed.
-                              // This works because we know that if we 
-                              // are reaching here then the alpha data in byte 
-                              // 4 has been right all along.  And we know it
-                              // has been set to 0 the whole time, so that 
-                              // means that everything is transparent so far.
-                              uint32_t* start = reinterpret_cast<uint32_t*>(mImageData) + GetWidth() * (mCurLine - 1);
-                              uint32_t heightDifference = GetHeight() - mCurLine + 1;
-                              uint32_t pixelCount = GetWidth() * heightDifference;
+  const uint32_t rows = mOldLine - mCurLine;
+  if (rows) {
+    // Invalidate
+    nsIntRect r(0, mBIH.height < 0 ? -mBIH.height - mOldLine : mCurLine,
+                mBIH.width, rows);
+    PostInvalidation(r);
 
-                              memset(start, 0, pixelCount * sizeof(uint32_t));
+    mOldLine = mCurLine;
+  }
 
-                              mHaveAlphaData = true;
-                            }
-                            SetPixel(d, p[2], p[1], p[0], mHaveAlphaData ? p[3] : 0xFF);
-                          } else {
-                            SetPixel(d, p[2], p[1], p[0]);
-                          }
-                          p += 4;
-                          --lpos;
-                        }
-                        break;
-                      default:
-                        NS_NOTREACHED("Unsupported color depth, but earlier check didn't catch it");
-                    }
-                    mCurLine --;
-                    if (mCurLine == 0) { // Finished last line
-                      break;
-                    }
-                    mRowBytes = 0;
+  return;
+}
 
-                }
-            } while (aCount > 0);
-        }
-        else if ((mBIH.compression == BI_RLE8) || (mBIH.compression == BI_RLE4)) {
-            if (((mBIH.compression == BI_RLE8) && (mBIH.bpp != 8)) || 
-                ((mBIH.compression == BI_RLE4) && (mBIH.bpp != 4) && (mBIH.bpp != 1))) {
-              PR_LOG(GetBMPLog(), PR_LOG_DEBUG, ("BMP RLE8/RLE4 compression only supports 8/4 bits per pixel\n"));
-              PostDataError();
-              return;
-            }
-
-            while (aCount > 0) {
-                uint8_t byte;
-
-                switch(mState) {
-                    case eRLEStateInitial:
-                        mStateData = (uint8_t)*aBuffer++;
-                        aCount--;
-
-                        mState = eRLEStateNeedSecondEscapeByte;
-                        continue;
-
-                    case eRLEStateNeedSecondEscapeByte:
-                        byte = *aBuffer++;
-                        aCount--;
-                        if (mStateData != RLE_ESCAPE) { // encoded mode
-                            // Encoded mode consists of two bytes: 
-                            // the first byte (mStateData) specifies the
-                            // number of consecutive pixels to be drawn 
-                            // using the color index contained in
-                            // the second byte
-                            // Work around bitmaps that specify too many pixels
-                            mState = eRLEStateInitial;
-                            uint32_t pixelsNeeded = std::min<uint32_t>(mBIH.width - mCurPos, mStateData);
-                            if (pixelsNeeded) {
-                                uint32_t* d = reinterpret_cast<uint32_t*>(mImageData) + PIXEL_OFFSET(mCurLine, mCurPos);
-                                mCurPos += pixelsNeeded;
-                                if (mBIH.compression == BI_RLE8) {
-                                    do {
-                                        SetPixel(d, byte, mColors);
-                                        pixelsNeeded --;
-                                    } while (pixelsNeeded);
-                                } else {
-                                    do {
-                                        Set4BitPixel(d, byte, pixelsNeeded, mColors);
-                                    } while (pixelsNeeded);
-                                }
-                            }
-                            continue;
-                        }
-
-                        switch(byte) {
-                            case RLE_ESCAPE_EOL:
-                                // End of Line: Go to next row
-                                mCurLine --;
-                                mCurPos = 0;
-                                mState = eRLEStateInitial;
-                                break;
-
-                            case RLE_ESCAPE_EOF: // EndOfFile
-                                mCurPos = mCurLine = 0;
-                                break;
-
-                            case RLE_ESCAPE_DELTA:
-                                mState = eRLEStateNeedXDelta;
-                                continue;
-
-                            default : // absolute mode
-                                // Save the number of pixels to read
-                                mStateData = byte;
-                                if (mCurPos + mStateData > (uint32_t)mBIH.width) {
-                                    // We can work around bitmaps that specify one
-                                    // pixel too many, but only if their width is odd.
-                                    mStateData -= mBIH.width & 1;
-                                    if (mCurPos + mStateData > (uint32_t)mBIH.width) {
-                                        PostDataError();
-                                        return;
-                                    }
-                                }
+void
+nsBMPDecoder::ProcessFileHeader()
+{
+  memset(&mBFH, 0, sizeof(mBFH));
+  memcpy(&mBFH.signature, mRawBuf, sizeof(mBFH.signature));
+  memcpy(&mBFH.filesize, mRawBuf + 2, sizeof(mBFH.filesize));
+  memcpy(&mBFH.reserved, mRawBuf + 6, sizeof(mBFH.reserved));
+  memcpy(&mBFH.dataoffset, mRawBuf + 10, sizeof(mBFH.dataoffset));
+  memcpy(&mBFH.bihsize, mRawBuf + 14, sizeof(mBFH.bihsize));
 
-                                // See if we will need to skip a byte
-                                // to word align the pixel data
-                                // mStateData is a number of pixels
-                                // so allow for the RLE compression type
-                                // Pixels RLE8=1 RLE4=2
-                                //    1    Pad    Pad
-                                //    2    No     Pad
-                                //    3    Pad    No
-                                //    4    No     No
-                                if (((mStateData - 1) & mBIH.compression) != 0)
-                                    mState = eRLEStateAbsoluteMode;
-                                else
-                                    mState = eRLEStateAbsoluteModePadded;
-                                continue;
-                        }
-                        break;
-
-                    case eRLEStateNeedXDelta:
-                        // Handle the XDelta and proceed to get Y Delta
-                        byte = *aBuffer++;
-                        aCount--;
-                        mCurPos += byte;
-                        // Delta encoding makes it possible to skip pixels making
-                        // the image transparent.
-                        mUseAlphaData = mHaveAlphaData = true;
-                        if (mCurPos > mBIH.width)
-                            mCurPos = mBIH.width;
-
-                        mState = eRLEStateNeedYDelta;
-                        continue;
-
-                    case eRLEStateNeedYDelta:
-                        // Get the Y Delta and then "handle" the move
-                        byte = *aBuffer++;
-                        aCount--;
-                        mState = eRLEStateInitial;
-                        // Delta encoding makes it possible to skip pixels making
-                        // the image transparent.
-                        mUseAlphaData = mHaveAlphaData = true;
-                        mCurLine -= std::min<int32_t>(byte, mCurLine);
-                        break;
-
-                    case eRLEStateAbsoluteMode: // Absolute Mode
-                    case eRLEStateAbsoluteModePadded:
-                        if (mStateData) {
-                            // In absolute mode, the second byte (mStateData)
-                            // represents the number of pixels 
-                            // that follow, each of which contains 
-                            // the color index of a single pixel.
-                            uint32_t* d = reinterpret_cast<uint32_t*>(mImageData) + PIXEL_OFFSET(mCurLine, mCurPos);
-                            uint32_t* oldPos = d;
-                            if (mBIH.compression == BI_RLE8) {
-                                while (aCount > 0 && mStateData > 0) {
-                                    byte = *aBuffer++;
-                                    aCount--;
-                                    SetPixel(d, byte, mColors);
-                                    mStateData--;
-                                }
-                            } else {
-                                while (aCount > 0 && mStateData > 0) {
-                                    byte = *aBuffer++;
-                                    aCount--;
-                                    Set4BitPixel(d, byte, mStateData, mColors);
-                                }
-                            }
-                            mCurPos += d - oldPos;
-                        }
-
-                        if (mStateData == 0) {
-                            // In absolute mode, each run must 
-                            // be aligned on a word boundary
-
-                            if (mState == eRLEStateAbsoluteMode) { // Word Aligned
-                                mState = eRLEStateInitial;
-                            } else if (aCount > 0) {               // Not word Aligned
-                                // "next" byte is just a padding byte
-                                // so "move" past it and we can continue
-                                aBuffer++;
-                                aCount--;
-                                mState = eRLEStateInitial;
-                            }
-                        }
-                        // else state is still eRLEStateAbsoluteMode
-                        continue;
-
-                    default :
-                        NS_ABORT_IF_FALSE(0, "BMP RLE decompression: unknown state!");
-                        PostDecoderError(NS_ERROR_UNEXPECTED);
-                        return;
-                }
-                // Because of the use of the continue statement
-                // we only get here for eol, eof or y delta
-                if (mCurLine == 0) { // Finished last line
-                    break;
-                }
-            }
-        }
-    }
-
-    const uint32_t rows = mOldLine - mCurLine;
-    if (rows) {
-
-        // Invalidate
-        nsIntRect r(0, mBIH.height < 0 ? -mBIH.height - mOldLine : mCurLine,
-                    mBIH.width, rows);
-        PostInvalidation(r);
-
-        mOldLine = mCurLine;
-    }
-
-    return;
+  // Now correct the endianness of the header
+  mBFH.filesize = LittleEndian::readUint32(&mBFH.filesize);
+  mBFH.dataoffset = LittleEndian::readUint32(&mBFH.dataoffset);
+  mBFH.bihsize = LittleEndian::readUint32(&mBFH.bihsize);
 }
 
-void nsBMPDecoder::ProcessFileHeader()
-{
-    memset(&mBFH, 0, sizeof(mBFH));
-    memcpy(&mBFH.signature, mRawBuf, sizeof(mBFH.signature));
-    memcpy(&mBFH.filesize, mRawBuf + 2, sizeof(mBFH.filesize));
-    memcpy(&mBFH.reserved, mRawBuf + 6, sizeof(mBFH.reserved));
-    memcpy(&mBFH.dataoffset, mRawBuf + 10, sizeof(mBFH.dataoffset));
-    memcpy(&mBFH.bihsize, mRawBuf + 14, sizeof(mBFH.bihsize));
-
-    // Now correct the endianness of the header
-    mBFH.filesize = LittleEndian::readUint32(&mBFH.filesize);
-    mBFH.dataoffset = LittleEndian::readUint32(&mBFH.dataoffset);
-    mBFH.bihsize = LittleEndian::readUint32(&mBFH.bihsize);
-}
-
-void nsBMPDecoder::ProcessInfoHeader()
+void
+nsBMPDecoder::ProcessInfoHeader()
 {
-    memset(&mBIH, 0, sizeof(mBIH));
-    if (mBFH.bihsize == 12) { // OS/2 Bitmap
-        memcpy(&mBIH.width, mRawBuf, 2);
-        memcpy(&mBIH.height, mRawBuf + 2, 2);
-        memcpy(&mBIH.planes, mRawBuf + 4, sizeof(mBIH.planes));
-        memcpy(&mBIH.bpp, mRawBuf + 6, sizeof(mBIH.bpp));
-    }
-    else {
-        memcpy(&mBIH.width, mRawBuf, sizeof(mBIH.width));
-        memcpy(&mBIH.height, mRawBuf + 4, sizeof(mBIH.height));
-        memcpy(&mBIH.planes, mRawBuf + 8, sizeof(mBIH.planes));
-        memcpy(&mBIH.bpp, mRawBuf + 10, sizeof(mBIH.bpp));
-        memcpy(&mBIH.compression, mRawBuf + 12, sizeof(mBIH.compression));
-        memcpy(&mBIH.image_size, mRawBuf + 16, sizeof(mBIH.image_size));
-        memcpy(&mBIH.xppm, mRawBuf + 20, sizeof(mBIH.xppm));
-        memcpy(&mBIH.yppm, mRawBuf + 24, sizeof(mBIH.yppm));
-        memcpy(&mBIH.colors, mRawBuf + 28, sizeof(mBIH.colors));
-        memcpy(&mBIH.important_colors, mRawBuf + 32, sizeof(mBIH.important_colors));
-    }
+  memset(&mBIH, 0, sizeof(mBIH));
+  if (mBFH.bihsize == 12) { // OS/2 Bitmap
+    memcpy(&mBIH.width, mRawBuf, 2);
+    memcpy(&mBIH.height, mRawBuf + 2, 2);
+    memcpy(&mBIH.planes, mRawBuf + 4, sizeof(mBIH.planes));
+    memcpy(&mBIH.bpp, mRawBuf + 6, sizeof(mBIH.bpp));
+  } else {
+    memcpy(&mBIH.width, mRawBuf, sizeof(mBIH.width));
+    memcpy(&mBIH.height, mRawBuf + 4, sizeof(mBIH.height));
+    memcpy(&mBIH.planes, mRawBuf + 8, sizeof(mBIH.planes));
+    memcpy(&mBIH.bpp, mRawBuf + 10, sizeof(mBIH.bpp));
+    memcpy(&mBIH.compression, mRawBuf + 12, sizeof(mBIH.compression));
+    memcpy(&mBIH.image_size, mRawBuf + 16, sizeof(mBIH.image_size));
+    memcpy(&mBIH.xppm, mRawBuf + 20, sizeof(mBIH.xppm));
+    memcpy(&mBIH.yppm, mRawBuf + 24, sizeof(mBIH.yppm));
+    memcpy(&mBIH.colors, mRawBuf + 28, sizeof(mBIH.colors));
+    memcpy(&mBIH.important_colors, mRawBuf + 32,
+           sizeof(mBIH.important_colors));
+  }
 
-    // Convert endianness
-    mBIH.width = LittleEndian::readUint32(&mBIH.width);
-    mBIH.height = LittleEndian::readUint32(&mBIH.height);
-    mBIH.planes = LittleEndian::readUint16(&mBIH.planes);
-    mBIH.bpp = LittleEndian::readUint16(&mBIH.bpp);
+  // Convert endianness
+  mBIH.width = LittleEndian::readUint32(&mBIH.width);
+  mBIH.height = LittleEndian::readUint32(&mBIH.height);
+  mBIH.planes = LittleEndian::readUint16(&mBIH.planes);
+  mBIH.bpp = LittleEndian::readUint16(&mBIH.bpp);
 
-    mBIH.compression = LittleEndian::readUint32(&mBIH.compression);
-    mBIH.image_size = LittleEndian::readUint32(&mBIH.image_size);
-    mBIH.xppm = LittleEndian::readUint32(&mBIH.xppm);
-    mBIH.yppm = LittleEndian::readUint32(&mBIH.yppm);
-    mBIH.colors = LittleEndian::readUint32(&mBIH.colors);
-    mBIH.important_colors = LittleEndian::readUint32(&mBIH.important_colors);
+  mBIH.compression = LittleEndian::readUint32(&mBIH.compression);
+  mBIH.image_size = LittleEndian::readUint32(&mBIH.image_size);
+  mBIH.xppm = LittleEndian::readUint32(&mBIH.xppm);
+  mBIH.yppm = LittleEndian::readUint32(&mBIH.yppm);
+  mBIH.colors = LittleEndian::readUint32(&mBIH.colors);
+  mBIH.important_colors = LittleEndian::readUint32(&mBIH.important_colors);
 }
 
 } // namespace image
 } // namespace mozilla
--- a/image/decoders/nsBMPDecoder.h
+++ b/image/decoders/nsBMPDecoder.h
@@ -1,135 +1,146 @@
 /* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
-#ifndef _nsBMPDecoder_h
-#define _nsBMPDecoder_h
+#ifndef nsBMPDecoder_h
+#define nsBMPDecoder_h
 
+#include "BMPFileHeaders.h"
+#include "Decoder.h"
+#include "gfxColor.h"
 #include "nsAutoPtr.h"
-#include "gfxColor.h"
-#include "Decoder.h"
-#include "BMPFileHeaders.h"
 
 namespace mozilla {
 namespace image {
 
 class RasterImage;
 
-/**
- * Decoder for BMP-Files, as used by Windows and OS/2
- */
+/// Decoder for BMP-Files, as used by Windows and OS/2
+
 class nsBMPDecoder : public Decoder
 {
 public:
 
-    explicit nsBMPDecoder(RasterImage &aImage);
+    explicit nsBMPDecoder(RasterImage& aImage);
     ~nsBMPDecoder();
 
     // Specifies whether or not the BMP file will contain alpha data
     // If set to true and the BMP is 32BPP, the alpha data will be
-    // retrieved from the 4th byte of image data per pixel 
+    // retrieved from the 4th byte of image data per pixel
     void SetUseAlphaData(bool useAlphaData);
+
     // Obtains the bits per pixel from the internal BIH header
     int32_t GetBitsPerPixel() const;
+
     // Obtains the width from the internal BIH header
     int32_t GetWidth() const;
+
     // Obtains the abs-value of the height from the internal BIH header
     int32_t GetHeight() const;
+
     // Obtains the internal output image buffer
     uint32_t* GetImageData();
+
     // Obtains the size of the compressed image resource
     int32_t GetCompressedImageSize() const;
+
     // Obtains whether or not a BMP file had alpha data in its 4th byte
     // for 32BPP bitmaps.  Only use after the bitmap has been processed.
     bool HasAlphaData() const;
 
-    virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
+    virtual void WriteInternal(const char* aBuffer, uint32_t aCount,
+                               DecodeStrategy aStrategy) MOZ_OVERRIDE;
     virtual void FinishInternal();
 
 private:
 
-    /** Calculates the red-, green- and blueshift in mBitFields using
-     * the bitmasks from mBitFields */
+    /// Calculates the red-, green- and blueshift in mBitFields using
+    /// the bitmasks from mBitFields
     NS_METHOD CalcBitShift();
 
-    uint32_t mPos; ///< Number of bytes read from aBuffer in WriteInternal()
+    uint32_t mPos; //< Number of bytes read from aBuffer in WriteInternal()
 
     BMPFILEHEADER mBFH;
     BITMAPV5HEADER mBIH;
-    char mRawBuf[WIN_V3_INTERNAL_BIH_LENGTH]; ///< If this is changed, WriteInternal() MUST be updated
+    char mRawBuf[WIN_V3_INTERNAL_BIH_LENGTH]; //< If this is changed,
+                                              // WriteInternal() MUST be updated
 
-    uint32_t mLOH; ///< Length of the header
+    uint32_t mLOH; //< Length of the header
 
-    uint32_t mNumColors; ///< The number of used colors, i.e. the number of entries in mColors
-    colorTable *mColors;
+    uint32_t mNumColors; //< The number of used colors, i.e. the number of
+                         // entries in mColors
+    colorTable* mColors;
 
     bitFields mBitFields;
 
-    uint8_t *mRow;      ///< Holds one raw line of the image
-    uint32_t mRowBytes; ///< How many bytes of the row were already received
-    int32_t mCurLine;   ///< Index of the line of the image that's currently being decoded: [height,1]
-    int32_t mOldLine;   ///< Previous index of the line 
-    int32_t mCurPos;    ///< Index in the current line of the image
+    uint8_t* mRow;      //< Holds one raw line of the image
+    uint32_t mRowBytes; //< How many bytes of the row were already received
+    int32_t mCurLine;   //< Index of the line of the image that's currently
+                        // being decoded: [height,1]
+    int32_t mOldLine;   //< Previous index of the line
+    int32_t mCurPos;    //< Index in the current line of the image
 
-    ERLEState mState;   ///< Maintains the current state of the RLE decoding
-    uint32_t mStateData;///< Decoding information that is needed depending on mState
+    ERLEState mState;   //< Maintains the current state of the RLE decoding
+    uint32_t mStateData;//< Decoding information that is needed depending
+                        // on mState
 
-    /** Set mBFH from the raw data in mRawBuf, converting from little-endian
-     * data to native data as necessary */
+    /// Set mBFH from the raw data in mRawBuf, converting from little-endian
+    /// data to native data as necessary
     void ProcessFileHeader();
-    /** Set mBIH from the raw data in mRawBuf, converting from little-endian
-     * data to native data as necessary */
+
+    /// Set mBIH from the raw data in mRawBuf, converting from little-endian
+    /// data to native data as necessary
     void ProcessInfoHeader();
 
     // Stores whether the image data may store alpha data, or if
-    // the alpha data is unspecified and filled with a padding byte of 0. 
+    // the alpha data is unspecified and filled with a padding byte of 0.
     // When a 32BPP bitmap is stored in an ICO or CUR file, its 4th byte
     // is used for alpha transparency.  When it is stored in a BMP, its
     // 4th byte is reserved and is always 0.
-    // Reference: 
+    // Reference:
     // http://en.wikipedia.org/wiki/ICO_(file_format)#cite_note-9
     // Bitmaps where the alpha bytes are all 0 should be fully visible.
     bool mUseAlphaData;
+
     // Whether the 4th byte alpha data was found to be non zero and hence used.
     bool mHaveAlphaData;
 };
 
-/** Sets the pixel data in aDecoded to the given values.
- * @param aDecoded pointer to pixel to be set, will be incremented to point to the next pixel.
- */
-static inline void SetPixel(uint32_t*& aDecoded, uint8_t aRed, uint8_t aGreen, uint8_t aBlue, uint8_t aAlpha = 0xFF)
+/// Sets the pixel data in aDecoded to the given values.
+/// @param aDecoded pointer to pixel to be set, will be incremented to point to
+/// the next pixel.
+static inline void SetPixel(uint32_t*& aDecoded, uint8_t aRed, uint8_t aGreen,
+                            uint8_t aBlue, uint8_t aAlpha = 0xFF)
 {
     *aDecoded++ = gfxPackedPixel(aAlpha, aRed, aGreen, aBlue);
 }
 
-static inline void SetPixel(uint32_t*& aDecoded, uint8_t idx, colorTable* aColors)
+static inline void SetPixel(uint32_t*& aDecoded, uint8_t idx, colorTable*
+                            aColors)
 {
     SetPixel(aDecoded, aColors[idx].red, aColors[idx].green, aColors[idx].blue);
 }
 
-/** Sets two (or one if aCount = 1) pixels
- * @param aDecoded where the data is stored. Will be moved 4 resp 8 bytes
- * depending on whether one or two pixels are written.
- * @param aData The values for the two pixels
- * @param aCount Current count. Is decremented by one or two.
- */
+/// Sets two (or one if aCount = 1) pixels
+/// @param aDecoded where the data is stored. Will be moved 4 resp 8 bytes
+/// depending on whether one or two pixels are written.
+/// @param aData The values for the two pixels
+/// @param aCount Current count. Is decremented by one or two.
 inline void Set4BitPixel(uint32_t*& aDecoded, uint8_t aData,
                          uint32_t& aCount, colorTable* aColors)
 {
     uint8_t idx = aData >> 4;
     SetPixel(aDecoded, idx, aColors);
     if (--aCount > 0) {
         idx = aData & 0xF;
         SetPixel(aDecoded, idx, aColors);
         --aCount;
     }
 }
 
 } // namespace image
 } // namespace mozilla
 
-
-#endif
-
+#endif // nsBMPDecoder_h
--- a/image/decoders/nsGIFDecoder2.cpp
+++ b/image/decoders/nsGIFDecoder2.cpp
@@ -47,35 +47,33 @@ mailing address.
 #include "gfxColor.h"
 #include "gfxPlatform.h"
 #include "qcms.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace image {
 
-/*
- * GETN(n, s) requests at least 'n' bytes available from 'q', at start of state 's'
- *
- * Colormaps are directly copied in the resp. global_colormap or the local_colormap of the PAL image frame
- * So a fixed buffer in gif_struct is good enough.
- * This buffer is only needed to copy left-over data from one GifWrite call to the next
- */
+// GETN(n, s) requests at least 'n' bytes available from 'q', at start of state
+// 's'. Colormaps are directly copied in the resp. global_colormap or the
+// local_colormap of the PAL image frame So a fixed buffer in gif_struct is
+// good enough. This buffer is only needed to copy left-over data from one
+// GifWrite call to the next
 #define GETN(n,s)                      \
   PR_BEGIN_MACRO                       \
     mGIFStruct.bytes_to_consume = (n); \
     mGIFStruct.state = (s);            \
   PR_END_MACRO
 
-/* Get a 16-bit value stored in little-endian format */
+// Get a 16-bit value stored in little-endian format
 #define GETINT16(p)   ((p)[1]<<8|(p)[0])
 //////////////////////////////////////////////////////////////////////
 // GIF Decoder Implementation
 
-nsGIFDecoder2::nsGIFDecoder2(RasterImage &aImage)
+nsGIFDecoder2::nsGIFDecoder2(RasterImage& aImage)
   : Decoder(aImage)
   , mCurrentRow(-1)
   , mLastFlushedRow(-1)
   , mOldColor(0)
   , mCurrentFrameIndex(-1)
   , mCurrentPass(0)
   , mLastFlushedPass(0)
   , mGIFOpen(false)
@@ -100,75 +98,83 @@ nsGIFDecoder2::~nsGIFDecoder2()
 
 void
 nsGIFDecoder2::FinishInternal()
 {
   NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call FinishInternal after error!");
 
   // If the GIF got cut off, handle it anyway
   if (!IsSizeDecode() && mGIFOpen) {
-    if (mCurrentFrameIndex == mGIFStruct.images_decoded)
+    if (mCurrentFrameIndex == mGIFStruct.images_decoded) {
       EndImageFrame();
+    }
     PostDecodeDone(mGIFStruct.loop_count - 1);
     mGIFOpen = false;
   }
 }
 
 // Push any new rows according to mCurrentPass/mLastFlushedPass and
 // mCurrentRow/mLastFlushedRow.  Note: caller is responsible for
 // updating mlastFlushed{Row,Pass}.
 void
 nsGIFDecoder2::FlushImageData(uint32_t fromRow, uint32_t rows)
 {
-  nsIntRect r(mGIFStruct.x_offset, mGIFStruct.y_offset + fromRow, mGIFStruct.width, rows);
+  nsIntRect r(mGIFStruct.x_offset, mGIFStruct.y_offset + fromRow,
+              mGIFStruct.width, rows);
   PostInvalidation(r);
 }
 
 void
 nsGIFDecoder2::FlushImageData()
 {
   switch (mCurrentPass - mLastFlushedPass) {
     case 0:  // same pass
-      if (mCurrentRow - mLastFlushedRow)
+      if (mCurrentRow - mLastFlushedRow) {
         FlushImageData(mLastFlushedRow + 1, mCurrentRow - mLastFlushedRow);
+      }
       break;
-  
+
     case 1:  // one pass on - need to handle bottom & top rects
       FlushImageData(0, mCurrentRow + 1);
-      FlushImageData(mLastFlushedRow + 1, mGIFStruct.height - (mLastFlushedRow + 1));
+      FlushImageData(mLastFlushedRow + 1,
+                     mGIFStruct.height - (mLastFlushedRow + 1));
       break;
 
-    default:   // more than one pass on - push the whole frame
+    default: // more than one pass on - push the whole frame
       FlushImageData(0, mGIFStruct.height);
   }
 }
 
 //******************************************************************************
 // GIF decoder callback methods. Part of public API for GIF2
 //******************************************************************************
 
 //******************************************************************************
-void nsGIFDecoder2::BeginGIF()
+void
+nsGIFDecoder2::BeginGIF()
 {
-  if (mGIFOpen)
+  if (mGIFOpen) {
     return;
+  }
 
   mGIFOpen = true;
 
   PostSize(mGIFStruct.screen_width, mGIFStruct.screen_height);
 }
 
 //******************************************************************************
-void nsGIFDecoder2::BeginImageFrame(uint16_t aDepth)
+void
+nsGIFDecoder2::BeginImageFrame(uint16_t aDepth)
 {
   gfx::SurfaceFormat format;
-  if (mGIFStruct.is_transparent)
+  if (mGIFStruct.is_transparent) {
     format = gfx::SurfaceFormat::B8G8R8A8;
-  else
+  } else {
     format = gfx::SurfaceFormat::B8G8R8X8;
+  }
 
   MOZ_ASSERT(HasSize());
 
   // Use correct format, RGB for first frame, PAL for following frames
   // and include transparency to allow for optimization of opaque images
   if (mGIFStruct.images_decoded) {
     // Image data is stored with original depth and palette
     NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset,
@@ -183,33 +189,35 @@ void nsGIFDecoder2::BeginImageFrame(uint
                                                         mGIFStruct.y_offset,
                                                         mGIFStruct.width,
                                                         mGIFStruct.height))) {
       // Regardless of depth of input, image is decoded into 24bit RGB
       NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset,
                    mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height,
                    format);
     } else {
-      // Our preallocated frame matches up, with the possible exception of alpha.
+      // Our preallocated frame matches up, with the possible exception
+      // of alpha.
       if (format == gfx::SurfaceFormat::B8G8R8X8) {
         currentFrame->SetHasNoAlpha();
       }
     }
   }
 
   mCurrentFrameIndex = mGIFStruct.images_decoded;
 }
 
 
 //******************************************************************************
-void nsGIFDecoder2::EndImageFrame()
+void
+nsGIFDecoder2::EndImageFrame()
 {
   FrameBlender::FrameAlpha alpha = FrameBlender::kFrameHasAlpha;
 
-  // First flush all pending image data 
+  // First flush all pending image data
   if (!mGIFStruct.images_decoded) {
     // Only need to flush first frame
     FlushImageData();
 
     // If the first frame is smaller in height than the entire image, send an
     // invalidation for the area it does not have data for.
     // This will clear the remaining bits of the placeholder. (Bug 37589)
     const uint32_t realFrameHeight = mGIFStruct.height + mGIFStruct.y_offset;
@@ -226,17 +234,19 @@ void nsGIFDecoder2::EndImageFrame()
   }
   mCurrentRow = mLastFlushedRow = -1;
   mCurrentPass = mLastFlushedPass = 0;
 
   // Only add frame if we have any rows at all
   if (mGIFStruct.rows_remaining != mGIFStruct.height) {
     if (mGIFStruct.rows_remaining && mGIFStruct.images_decoded) {
       // Clear the remaining rows (only needed for the animation frames)
-      uint8_t *rowp = mImageData + ((mGIFStruct.height - mGIFStruct.rows_remaining) * mGIFStruct.width);
+      uint8_t* rowp =
+        mImageData + ((mGIFStruct.height - mGIFStruct.rows_remaining) *
+                      mGIFStruct.width);
       memset(rowp, 0, mGIFStruct.rows_remaining * mGIFStruct.width);
     }
   }
 
   // Unconditionally increment images_decoded, because we unconditionally
   // append frames in BeginImageFrame(). This ensures that images_decoded
   // always refers to the frame in mImage we're currently decoding,
   // even if some of them weren't decoded properly and thus are blank.
@@ -254,68 +264,71 @@ void nsGIFDecoder2::EndImageFrame()
   }
 
   mCurrentFrameIndex = -1;
 }
 
 
 //******************************************************************************
 // Send the data to the display front-end.
-uint32_t nsGIFDecoder2::OutputRow()
+uint32_t
+nsGIFDecoder2::OutputRow()
 {
   int drow_start, drow_end;
   drow_start = drow_end = mGIFStruct.irow;
 
-  /* Protect against too much image data */
+  // Protect against too much image data
   if ((unsigned)drow_start >= mGIFStruct.height) {
     NS_WARNING("GIF2.cpp::OutputRow - too much image data");
     return 0;
   }
 
   if (!mGIFStruct.images_decoded) {
-    /*
-     * Haeberli-inspired hack for interlaced GIFs: Replicate lines while
-     * displaying to diminish the "venetian-blind" effect as the image is
-     * loaded. Adjust pixel vertical positions to avoid the appearance of the
-     * image crawling up the screen as successive passes are drawn.
-     */
-    if (mGIFStruct.progressive_display && mGIFStruct.interlaced && (mGIFStruct.ipass < 4)) {
-      /* ipass = 1,2,3 results in resp. row_dup = 7,3,1 and row_shift = 3,1,0 */
+    // Haeberli-inspired hack for interlaced GIFs: Replicate lines while
+    // displaying to diminish the "venetian-blind" effect as the image is
+    // loaded. Adjust pixel vertical positions to avoid the appearance of the
+    // image crawling up the screen as successive passes are drawn.
+    if (mGIFStruct.progressive_display && mGIFStruct.interlaced &&
+        (mGIFStruct.ipass < 4)) {
+      // ipass = 1,2,3 results in resp. row_dup = 7,3,1 and row_shift = 3,1,0
       const uint32_t row_dup = 15 >> mGIFStruct.ipass;
       const uint32_t row_shift = row_dup >> 1;
-  
+
       drow_start -= row_shift;
       drow_end = drow_start + row_dup;
-  
-      /* Extend if bottom edge isn't covered because of the shift upward. */
-      if (((mGIFStruct.height - 1) - drow_end) <= row_shift)
+
+      // Extend if bottom edge isn't covered because of the shift upward.
+      if (((mGIFStruct.height - 1) - drow_end) <= row_shift) {
         drow_end = mGIFStruct.height - 1;
-  
-      /* Clamp first and last rows to upper and lower edge of image. */
-      if (drow_start < 0)
+      }
+
+      // Clamp first and last rows to upper and lower edge of image.
+      if (drow_start < 0) {
         drow_start = 0;
-      if ((unsigned)drow_end >= mGIFStruct.height)
+      }
+      if ((unsigned)drow_end >= mGIFStruct.height) {
         drow_end = mGIFStruct.height - 1;
+      }
     }
 
     // Row to process
-    const uint32_t bpr = sizeof(uint32_t) * mGIFStruct.width; 
-    uint8_t *rowp = mImageData + (mGIFStruct.irow * bpr);
+    const uint32_t bpr = sizeof(uint32_t) * mGIFStruct.width;
+    uint8_t* rowp = mImageData + (mGIFStruct.irow * bpr);
 
     // Convert color indices to Cairo pixels
-    uint8_t *from = rowp + mGIFStruct.width;
-    uint32_t *to = ((uint32_t*)rowp) + mGIFStruct.width;
-    uint32_t *cmap = mColormap;
+    uint8_t* from = rowp + mGIFStruct.width;
+    uint32_t* to = ((uint32_t*)rowp) + mGIFStruct.width;
+    uint32_t* cmap = mColormap;
     for (uint32_t c = mGIFStruct.width; c > 0; c--) {
       *--to = cmap[*--from];
     }
-  
+
     // check for alpha (only for first frame)
     if (mGIFStruct.is_transparent && !mSawTransparency) {
-      const uint32_t *rgb = (uint32_t*)rowp;
+      const uint32_t* rgb = (uint32_t*)rowp;
       for (uint32_t i = mGIFStruct.width; i > 0; i--) {
         if (*rgb++ == 0) {
           mSawTransparency = true;
           break;
         }
       }
     }
 
@@ -327,18 +340,19 @@ uint32_t nsGIFDecoder2::OutputRow()
           memcpy(mImageData + (r * bpr), rowp, bpr);
         }
       }
     }
   }
 
   mCurrentRow = drow_end;
   mCurrentPass = mGIFStruct.ipass;
-  if (mGIFStruct.ipass == 1)
+  if (mGIFStruct.ipass == 1) {
     mLastFlushedPass = mGIFStruct.ipass;   // interlaced starts at 1
+  }
 
   if (!mGIFStruct.interlaced) {
     mGIFStruct.irow++;
   } else {
     static const uint8_t kjump[5] = { 1, 8, 8, 4, 2 };
     do {
       // Row increments resp. per 8,8,4,2 rows
       mGIFStruct.irow += kjump[mGIFStruct.ipass];
@@ -349,177 +363,180 @@ uint32_t nsGIFDecoder2::OutputRow()
       }
     } while (mGIFStruct.irow >= mGIFStruct.height);
   }
 
   return --mGIFStruct.rows_remaining;
 }
 
 //******************************************************************************
-/* Perform Lempel-Ziv-Welch decoding */
+// Perform Lempel-Ziv-Welch decoding
 bool
-nsGIFDecoder2::DoLzw(const uint8_t *q)
+nsGIFDecoder2::DoLzw(const uint8_t* q)
 {
-  if (!mGIFStruct.rows_remaining)
+  if (!mGIFStruct.rows_remaining) {
     return true;
+  }
 
-  /* Copy all the decoder state variables into locals so the compiler
-   * won't worry about them being aliased.  The locals will be homed
-   * back into the GIF decoder structure when we exit.
-   */
+  // Copy all the decoder state variables into locals so the compiler
+  // won't worry about them being aliased.  The locals will be homed
+  // back into the GIF decoder structure when we exit.
   int avail       = mGIFStruct.avail;
   int bits        = mGIFStruct.bits;
   int codesize    = mGIFStruct.codesize;
   int codemask    = mGIFStruct.codemask;
   int count       = mGIFStruct.count;
   int oldcode     = mGIFStruct.oldcode;
   const int clear_code = ClearCode();
   uint8_t firstchar = mGIFStruct.firstchar;
   int32_t datum     = mGIFStruct.datum;
-  uint16_t *prefix  = mGIFStruct.prefix;
-  uint8_t *stackp   = mGIFStruct.stackp;
-  uint8_t *suffix   = mGIFStruct.suffix;
-  uint8_t *stack    = mGIFStruct.stack;
-  uint8_t *rowp     = mGIFStruct.rowp;
+  uint16_t* prefix  = mGIFStruct.prefix;
+  uint8_t* stackp   = mGIFStruct.stackp;
+  uint8_t* suffix   = mGIFStruct.suffix;
+  uint8_t* stack    = mGIFStruct.stack;
+  uint8_t* rowp     = mGIFStruct.rowp;
 
   uint32_t bpr = mGIFStruct.width;
-  if (!mGIFStruct.images_decoded) 
+  if (!mGIFStruct.images_decoded) {
     bpr *= sizeof(uint32_t);
-  uint8_t *rowend   = mImageData + (bpr * mGIFStruct.irow) + mGIFStruct.width;
+  }
+  uint8_t* rowend   = mImageData + (bpr * mGIFStruct.irow) + mGIFStruct.width;
 
 #define OUTPUT_ROW()                                        \
   PR_BEGIN_MACRO                                            \
     if (!OutputRow())                                       \
       goto END;                                             \
     rowp = mImageData + mGIFStruct.irow * bpr;              \
     rowend = rowp + mGIFStruct.width;                       \
   PR_END_MACRO
 
-  for (const uint8_t* ch = q; count-- > 0; ch++)
-  {
-    /* Feed the next byte into the decoder's 32-bit input buffer. */
-    datum += ((int32_t) *ch) << bits;
+  for (const uint8_t* ch = q; count-- > 0; ch++) {
+    // Feed the next byte into the decoder's 32-bit input buffer.
+    datum += ((int32_t)* ch) << bits;
     bits += 8;
 
-    /* Check for underflow of decoder's 32-bit input buffer. */
-    while (bits >= codesize)
-    {
-      /* Get the leading variable-length symbol from the data stream */
+    // Check for underflow of decoder's 32-bit input buffer.
+    while (bits >= codesize) {
+      // Get the leading variable-length symbol from the data stream
       int code = datum & codemask;
       datum >>= codesize;
       bits -= codesize;
 
-      /* Reset the dictionary to its original state, if requested */
+      // Reset the dictionary to its original state, if requested
       if (code == clear_code) {
         codesize = mGIFStruct.datasize + 1;
         codemask = (1 << codesize) - 1;
         avail = clear_code + 2;
         oldcode = -1;
         continue;
       }
 
-      /* Check for explicit end-of-stream code */
+      // Check for explicit end-of-stream code
       if (code == (clear_code + 1)) {
-        /* end-of-stream should only appear after all image data */
+        // end-of-stream should only appear after all image data
         return (mGIFStruct.rows_remaining == 0);
       }
 
       if (oldcode == -1) {
-        if (code >= MAX_BITS)
+        if (code >= MAX_BITS) {
           return false;
+        }
         *rowp++ = suffix[code] & mColorMask; // ensure index is within colormap
-        if (rowp == rowend)
+        if (rowp == rowend) {
           OUTPUT_ROW();
+        }
 
         firstchar = oldcode = code;
         continue;
       }
 
       int incode = code;
       if (code >= avail) {
         *stackp++ = firstchar;
         code = oldcode;
 
-        if (stackp >= stack + MAX_BITS)
+        if (stackp >= stack + MAX_BITS) {
           return false;
+        }
       }
 
-      while (code >= clear_code)
-      {
-        if ((code >= MAX_BITS) || (code == prefix[code]))
+      while (code >= clear_code) {
+        if ((code >= MAX_BITS) || (code == prefix[code])) {
           return false;
+        }
 
         *stackp++ = suffix[code];
         code = prefix[code];
 
-        if (stackp == stack + MAX_BITS)
+        if (stackp == stack + MAX_BITS) {
           return false;
+        }
       }
 
       *stackp++ = firstchar = suffix[code];
 
-      /* Define a new codeword in the dictionary. */
+      // Define a new codeword in the dictionary.
       if (avail < 4096) {
         prefix[avail] = oldcode;
         suffix[avail] = firstchar;
         avail++;
 
-        /* If we've used up all the codewords of a given length
-         * increase the length of codewords by one bit, but don't
-         * exceed the specified maximum codeword size of 12 bits.
-         */
+        // If we've used up all the codewords of a given length
+        // increase the length of codewords by one bit, but don't
+        // exceed the specified maximum codeword size of 12 bits.
         if (((avail & codemask) == 0) && (avail < 4096)) {
           codesize++;
           codemask += avail;
         }
       }
       oldcode = incode;
 
-      /* Copy the decoded data out to the scanline buffer. */
+      // Copy the decoded data out to the scanline buffer.
       do {
         *rowp++ = *--stackp & mColorMask; // ensure index is within colormap
-        if (rowp == rowend)
+        if (rowp == rowend) {
           OUTPUT_ROW();
+        }
       } while (stackp > stack);
     }
   }
 
   END:
 
-  /* Home the local copies of the GIF decoder state variables */
+  // Home the local copies of the GIF decoder state variables
   mGIFStruct.avail = avail;
   mGIFStruct.bits = bits;
   mGIFStruct.codesize = codesize;
   mGIFStruct.codemask = codemask;
   mGIFStruct.count = count;
   mGIFStruct.oldcode = oldcode;
   mGIFStruct.firstchar = firstchar;
   mGIFStruct.datum = datum;
   mGIFStruct.stackp = stackp;
   mGIFStruct.rowp = rowp;
 
   return true;
 }
 
-/** 
- * Expand the colormap from RGB to Packed ARGB as needed by Cairo.
- * And apply any LCMS transformation.
- */
-static void ConvertColormap(uint32_t *aColormap, uint32_t aColors)
+/// Expand the colormap from RGB to Packed ARGB as needed by Cairo.
+/// And apply any LCMS transformation.
+static void
+ConvertColormap(uint32_t* aColormap, uint32_t aColors)
 {
   // Apply CMS transformation if enabled and available
   if (gfxPlatform::GetCMSMode() == eCMSMode_All) {
-    qcms_transform *transform = gfxPlatform::GetCMSRGBTransform();
-    if (transform)
+    qcms_transform* transform = gfxPlatform::GetCMSRGBTransform();
+    if (transform) {
       qcms_transform_data(transform, aColormap, aColormap, aColors);
+    }
   }
   // Convert from the GIF's RGB format to the Cairo format.
   // Work from end to begin, because of the in-place expansion
-  uint8_t *from = ((uint8_t *)aColormap) + 3 * aColors;
-  uint32_t *to = aColormap + aColors;
+  uint8_t* from = ((uint8_t*)aColormap) + 3 * aColors;
+  uint32_t* to = aColormap + aColors;
 
   // Convert color entries to Cairo format
 
   // set up for loops below
   if (!aColors) return;
   uint32_t c = aColors;
 
   // copy as bytes until source pointer is 32-bit-aligned
@@ -541,32 +558,35 @@ static void ConvertColormap(uint32_t *aC
   // NB: can't use 32-bit reads, they might read off the end of the buffer
   while (c--) {
     from -= 3;
     *--to = gfxPackedPixel(0xFF, from[0], from[1], from[2]);
   }
 }
 
 void
-nsGIFDecoder2::WriteInternal(const char *aBuffer, uint32_t aCount, DecodeStrategy)
+nsGIFDecoder2::WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy)
 {
   NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
 
-  // These variables changed names, and renaming would make a much bigger patch :(
-  const uint8_t *buf = (const uint8_t *)aBuffer;
+  // These variables changed names; renaming would make a much bigger patch :(
+  const uint8_t* buf = (const uint8_t*)aBuffer;
   uint32_t len = aCount;
 
-  const uint8_t *q = buf;
+  const uint8_t* q = buf;
 
   // Add what we have sofar to the block
-  // If previous call to me left something in the hold first complete current block
-  // Or if we are filling the colormaps, first complete the colormap
-  uint8_t* p = (mGIFStruct.state == gif_global_colormap) ? (uint8_t*)mGIFStruct.global_colormap :
-               (mGIFStruct.state == gif_image_colormap) ? (uint8_t*)mColormap :
-               (mGIFStruct.bytes_in_hold) ? mGIFStruct.hold : nullptr;
+  // If previous call to me left something in the hold first complete current
+  // block, or if we are filling the colormaps, first complete the colormap
+  uint8_t* p =
+    (mGIFStruct.state ==
+      gif_global_colormap) ? (uint8_t*) mGIFStruct.global_colormap :
+        (mGIFStruct.state == gif_image_colormap) ? (uint8_t*) mColormap :
+          (mGIFStruct.bytes_in_hold) ? mGIFStruct.hold : nullptr;
 
   if (len == 0 && buf == nullptr) {
     // We've just gotten the frame we asked for. Time to use the data we
     // stashed away.
     len = mGIFStruct.bytes_in_hold;
     q = buf = p;
   } else if (p) {
     // Add what we have sofar to the block
@@ -587,86 +607,85 @@ nsGIFDecoder2::WriteInternal(const char 
   //    'q' is start of current to be processed block (hold, colormap or buf)
   //    'bytes_to_consume' is number of bytes to consume from 'buf'
   //    'buf' points to the bytes to be consumed from the input buffer
   //    'len' is number of bytes left in input buffer from position 'buf'.
   //    At entrance of the for loop will 'buf' will be moved 'bytes_to_consume'
   //    to point to next buffer, 'len' is adjusted accordingly.
   //    So that next round in for loop, q gets pointed to the next buffer.
 
-  for (;len >= mGIFStruct.bytes_to_consume; q=buf, mGIFStruct.bytes_in_hold = 0) {
+  for (;len >= mGIFStruct.bytes_to_consume; q=buf, mGIFStruct.bytes_in_hold = 0)
+  {
     // Eat the current block from the buffer, q keeps pointed at current block
     buf += mGIFStruct.bytes_to_consume;
     len -= mGIFStruct.bytes_to_consume;
 
-    switch (mGIFStruct.state)
-    {
+    switch (mGIFStruct.state) {
     case gif_lzw:
       if (!DoLzw(q)) {
         mGIFStruct.state = gif_error;
         break;
       }
       GETN(1, gif_sub_block);
       break;
 
-    case gif_lzw_start:
-    {
+    case gif_lzw_start: {
       // Make sure the transparent pixel is transparent in the colormap
       if (mGIFStruct.is_transparent) {
         // Save old value so we can restore it later
-        if (mColormap == mGIFStruct.global_colormap)
+        if (mColormap == mGIFStruct.global_colormap) {
             mOldColor = mColormap[mGIFStruct.tpixel];
+        }
         mColormap[mGIFStruct.tpixel] = 0;
       }
 
-      /* Initialize LZW parser/decoder */
+      // Initialize LZW parser/decoder
       mGIFStruct.datasize = *q;
       const int clear_code = ClearCode();
       if (mGIFStruct.datasize > MAX_LZW_BITS ||
           clear_code >= MAX_BITS) {
         mGIFStruct.state = gif_error;
         break;
       }
 
       mGIFStruct.avail = clear_code + 2;
       mGIFStruct.oldcode = -1;
       mGIFStruct.codesize = mGIFStruct.datasize + 1;
       mGIFStruct.codemask = (1 << mGIFStruct.codesize) - 1;
       mGIFStruct.datum = mGIFStruct.bits = 0;
 
-      /* init the tables */
+      // init the tables
       for (int i = 0; i < clear_code; i++)
         mGIFStruct.suffix[i] = i;
 
       mGIFStruct.stackp = mGIFStruct.stack;
 
       GETN(1, gif_sub_block);
     }
     break;
 
-    /* All GIF files begin with "GIF87a" or "GIF89a" */
+    // All GIF files begin with "GIF87a" or "GIF89a"
     case gif_type:
       if (!strncmp((char*)q, "GIF89a", 6)) {
         mGIFStruct.version = 89;
       } else if (!strncmp((char*)q, "GIF87a", 6)) {
         mGIFStruct.version = 87;
       } else {
         mGIFStruct.state = gif_error;
         break;
       }
       GETN(7, gif_global_header);
       break;
 
     case gif_global_header:
-      /* This is the height and width of the "screen" or
-       * frame into which images are rendered.  The
-       * individual images can be smaller than the
-       * screen size and located with an origin anywhere
-       * within the screen.
-       */
+      // This is the height and width of the "screen" or
+      // frame into which images are rendered.  The
+      // individual images can be smaller than the
+      // screen size and located with an origin anywhere
+      // within the screen.
 
       mGIFStruct.screen_width = GETINT16(q);
       mGIFStruct.screen_height = GETINT16(q + 2);
       mGIFStruct.global_colormap_depth = (q[4]&0x07) + 1;
 
       if (IsSizeDecode()) {
         MOZ_ASSERT(!mGIFOpen, "Gif should not be open at this point");
         PostSize(mGIFStruct.screen_width, mGIFStruct.screen_height);
@@ -674,17 +693,17 @@ nsGIFDecoder2::WriteInternal(const char 
       }
 
       // screen_bgcolor is not used
       //mGIFStruct.screen_bgcolor = q[5];
       // q[6] = Pixel Aspect Ratio
       //   Not used
       //   float aspect = (float)((q[6] + 15) / 64.0);
 
-      if (q[4] & 0x80) { /* global map */
+      if (q[4] & 0x80) { // global map
         // Get the global colormap
         const uint32_t size = (3 << mGIFStruct.global_colormap_depth);
         if (len < size) {
           // Use 'hold' pattern to get the global colormap
           GETN(size, gif_global_colormap);
           break;
         }
         // Copy everything, go to colormap state to do CMS correction
@@ -696,17 +715,18 @@ nsGIFDecoder2::WriteInternal(const char 
       }
 
       GETN(1, gif_image_start);
       break;
 
     case gif_global_colormap:
       // Everything is already copied into global_colormap
       // Convert into Cairo colors including CMS transformation
-      ConvertColormap(mGIFStruct.global_colormap, 1<<mGIFStruct.global_colormap_depth);
+      ConvertColormap(mGIFStruct.global_colormap,
+                      1<<mGIFStruct.global_colormap_depth);
       GETN(1, gif_image_start);
       break;
 
     case gif_image_start:
       switch (*q) {
         case GIF_TRAILER:
           mGIFStruct.state = gif_done;
           break;
@@ -715,54 +735,57 @@ nsGIFDecoder2::WriteInternal(const char 
           GETN(2, gif_extension);
           break;
 
         case GIF_IMAGE_SEPARATOR:
           GETN(9, gif_image_header);
           break;
 
         default:
-          /* If we get anything other than GIF_IMAGE_SEPARATOR, 
-           * GIF_EXTENSION_INTRODUCER, or GIF_TRAILER, there is extraneous data
-           * between blocks. The GIF87a spec tells us to keep reading
-           * until we find an image separator, but GIF89a says such
-           * a file is corrupt. We follow GIF89a and bail out. */
+          // If we get anything other than GIF_IMAGE_SEPARATOR,
+          // GIF_EXTENSION_INTRODUCER, or GIF_TRAILER, there is extraneous data
+          // between blocks. The GIF87a spec tells us to keep reading
+          // until we find an image separator, but GIF89a says such
+          // a file is corrupt. We follow GIF89a and bail out.
           if (mGIFStruct.images_decoded > 0) {
-            /* The file is corrupt, but one or more images have
-             * been decoded correctly. In this case, we proceed
-             * as if the file were correctly terminated and set
-             * the state to gif_done, so the GIF will display.
-             */
+            // The file is corrupt, but one or more images have
+            // been decoded correctly. In this case, we proceed
+            // as if the file were correctly terminated and set
+            // the state to gif_done, so the GIF will display.
             mGIFStruct.state = gif_done;
           } else {
-            /* No images decoded, there is nothing to display. */
+            // No images decoded, there is nothing to display.
             mGIFStruct.state = gif_error;
           }
       }
       break;
 
     case gif_extension:
       mGIFStruct.bytes_to_consume = q[1];
       if (mGIFStruct.bytes_to_consume) {
         switch (*q) {
         case GIF_GRAPHIC_CONTROL_LABEL:
-          // The GIF spec mandates that the GIFControlExtension header block length is 4 bytes,
-          // and the parser for this block reads 4 bytes, so we must enforce that the buffer
-          // contains at least this many bytes. If the GIF specifies a different length, we
-          // allow that, so long as it's larger; the additional data will simply be ignored.
+          // The GIF spec mandates that the GIFControlExtension header block
+          // length is 4 bytes, and the parser for this block reads 4 bytes,
+          // so we must enforce that the buffer contains at least this many
+          // bytes. If the GIF specifies a different length, we allow that, so
+          // long as it's larger; the additional data will simply be ignored.
           mGIFStruct.state = gif_control_extension;
-          mGIFStruct.bytes_to_consume = std::max(mGIFStruct.bytes_to_consume, 4u);
+          mGIFStruct.bytes_to_consume =
+            std::max(mGIFStruct.bytes_to_consume, 4u);
           break;
 
-        // The GIF spec also specifies the lengths of the following two extensions' headers
-        // (as 12 and 11 bytes, respectively). Because we ignore the plain text extension entirely
-        // and sanity-check the actual length of the application extension header before reading it,
-        // we allow GIFs to deviate from these values in either direction. This is important for
-        // real-world compatibility, as GIFs in the wild exist with application extension headers
-        // that are both shorter and longer than 11 bytes.
+        // The GIF spec also specifies the lengths of the following two
+        // extensions' headers (as 12 and 11 bytes, respectively). Because
+        // we ignore the plain text extension entirely and sanity-check the
+        // actual length of the application extension header before reading it,
+        // we allow GIFs to deviate from these values in either direction. This
+        // is important for real-world compatibility, as GIFs in the wild exist
+        // with application extension headers that are both shorter and longer
+        // than 11 bytes.
         case GIF_APPLICATION_EXTENSION_LABEL:
           mGIFStruct.state = gif_application_extension;
           break;
 
         case GIF_PLAIN_TEXT_LABEL:
           mGIFStruct.state = gif_skip_block;
           break;
 
@@ -774,221 +797,228 @@ nsGIFDecoder2::WriteInternal(const char 
           mGIFStruct.state = gif_skip_block;
         }
       } else {
         GETN(1, gif_image_start);
       }
       break;
 
     case gif_consume_block:
-      if (!*q)
+      if (!*q) {
         GETN(1, gif_image_start);
-      else
+      } else {
         GETN(*q, gif_skip_block);
+      }
       break;
 
     case gif_skip_block:
       GETN(1, gif_consume_block);
       break;
 
     case gif_control_extension:
       mGIFStruct.is_transparent = *q & 0x1;
       mGIFStruct.tpixel = q[3];
       mGIFStruct.disposal_method = ((*q) >> 2) & 0x7;
       // Some specs say 3rd bit (value 4), other specs say value 3
       // Let's choose 3 (the more popular)
-      if (mGIFStruct.disposal_method == 4)
+      if (mGIFStruct.disposal_method == 4) {
         mGIFStruct.disposal_method = 3;
+      }
       mGIFStruct.delay_time = GETINT16(q + 1) * 10;
       GETN(1, gif_consume_block);
       break;
 
     case gif_comment_extension:
-      if (*q)
+      if (*q) {
         GETN(*q, gif_consume_comment);
-      else
+      } else {
         GETN(1, gif_image_start);
+      }
       break;
 
     case gif_consume_comment:
       GETN(1, gif_comment_extension);
       break;
 
     case gif_application_extension:
-      /* Check for netscape application extension */
+      // Check for netscape application extension
       if (mGIFStruct.bytes_to_consume == 11 &&
           (!strncmp((char*)q, "NETSCAPE2.0", 11) ||
            !strncmp((char*)q, "ANIMEXTS1.0", 11)))
         GETN(1, gif_netscape_extension_block);
       else
         GETN(1, gif_consume_block);
       break;
 
-    /* Netscape-specific GIF extension: animation looping */
+    // Netscape-specific GIF extension: animation looping
     case gif_netscape_extension_block:
-      if (*q)
+      if (*q) {
         // We might need to consume 3 bytes in
         // gif_consume_netscape_extension, so make sure we have at least that.
         GETN(std::max(3, static_cast<int>(*q)), gif_consume_netscape_extension);
-      else
+      } else {
         GETN(1, gif_image_start);
+      }
       break;
 
-    /* Parse netscape-specific application extensions */
+    // Parse netscape-specific application extensions
     case gif_consume_netscape_extension:
       switch (q[0] & 7) {
         case 1:
-          /* Loop entire animation specified # of times.  Only read the
-             loop count during the first iteration. */
+          // Loop entire animation specified # of times.  Only read the
+          // loop count during the first iteration.
           mGIFStruct.loop_count = GETINT16(q + 1);
           GETN(1, gif_netscape_extension_block);
           break;
 
         case 2:
-          /* Wait for specified # of bytes to enter buffer */
+          // Wait for specified # of bytes to enter buffer
+
           // Don't do this, this extension doesn't exist (isn't used at all)
-          // and doesn't do anything, as our streaming/buffering takes care of it all...
+          // and doesn't do anything, as our streaming/buffering takes care
+          // of it all...
           // See: http://semmix.pl/color/exgraf/eeg24.htm
           GETN(1, gif_netscape_extension_block);
           break;
 
         default:
           // 0,3-7 are yet to be defined netscape extension codes
           mGIFStruct.state = gif_error;
       }
       break;
 
-    case gif_image_header:
-    {
-      /* Get image offsets, with respect to the screen origin */
+    case gif_image_header: {
+      // Get image offsets, with respect to the screen origin
       mGIFStruct.x_offset = GETINT16(q);
       mGIFStruct.y_offset = GETINT16(q + 2);
 
-      /* Get image width and height. */
+      // Get image width and height.
       mGIFStruct.width  = GETINT16(q + 4);
       mGIFStruct.height = GETINT16(q + 6);
 
       if (!mGIFStruct.images_decoded) {
-        /* Work around broken GIF files where the logical screen
-         * size has weird width or height.  We assume that GIF87a
-         * files don't contain animations.
-         */
+        // Work around broken GIF files where the logical screen
+        // size has weird width or height.  We assume that GIF87a
+        // files don't contain animations.
         if ((mGIFStruct.screen_height < mGIFStruct.height) ||
             (mGIFStruct.screen_width < mGIFStruct.width) ||
             (mGIFStruct.version == 87)) {
           mGIFStruct.screen_height = mGIFStruct.height;
           mGIFStruct.screen_width = mGIFStruct.width;
           mGIFStruct.x_offset = 0;
           mGIFStruct.y_offset = 0;
-        }    
+        }
         // Create the image container with the right size.
         BeginGIF();
         if (HasError()) {
           // Setting the size led to an error.
           mGIFStruct.state = gif_error;
           return;
         }
 
         // If we were doing a size decode, we're done
-        if (IsSizeDecode())
+        if (IsSizeDecode()) {
           return;
+        }
       }
 
-      /* Work around more broken GIF files that have zero image
-         width or height */
+      // Work around more broken GIF files that have zero image width or height
       if (!mGIFStruct.height || !mGIFStruct.width) {
         mGIFStruct.height = mGIFStruct.screen_height;
         mGIFStruct.width = mGIFStruct.screen_width;
         if (!mGIFStruct.height || !mGIFStruct.width) {
           mGIFStruct.state = gif_error;
           break;
         }
       }
 
-      /* Depth of colors is determined by colormap */
-      /* (q[8] & 0x80) indicates local colormap */
-      /* bits per pixel is (q[8]&0x07 + 1) when local colormap is set */
+      // Depth of colors is determined by colormap
+      // (q[8] & 0x80) indicates local colormap
+      // bits per pixel is (q[8]&0x07 + 1) when local colormap is set
       uint32_t depth = mGIFStruct.global_colormap_depth;
-      if (q[8] & 0x80)
+      if (q[8] & 0x80) {
         depth = (q[8]&0x07) + 1;
+      }
       uint32_t realDepth = depth;
       while (mGIFStruct.tpixel >= (1 << realDepth) && (realDepth < 8)) {
         realDepth++;
-      } 
+      }
       // Mask to limit the color values within the colormap
       mColorMask = 0xFF >> (8 - realDepth);
       BeginImageFrame(realDepth);
 
       if (NeedsNewFrame()) {
         // We now need a new frame from the decoder framework. We leave all our
-        // data in the buffer as if it wasn't consumed, copy to our hold and return
-        // to the decoder framework.
-        uint32_t size = len + mGIFStruct.bytes_to_consume + mGIFStruct.bytes_in_hold;
+        // data in the buffer as if it wasn't consumed, copy to our hold and
+        // return to the decoder framework.
+        uint32_t size =
+          len + mGIFStruct.bytes_to_consume + mGIFStruct.bytes_in_hold;
         if (size) {
-          if (SetHold(q, mGIFStruct.bytes_to_consume + mGIFStruct.bytes_in_hold, buf, len)) {
+          if (SetHold(q,
+                      mGIFStruct.bytes_to_consume + mGIFStruct.bytes_in_hold,
+                      buf, len)) {
             // Back into the decoder infrastructure so we can get called again.
             GETN(9, gif_image_header_continue);
             return;
           }
         }
         break;
       } else {
         // FALL THROUGH
       }
     }
 
-    case gif_image_header_continue:
-    {
+    case gif_image_header_continue: {
       // While decoders can reuse frames, we unconditionally increment
       // mGIFStruct.images_decoded when we're done with a frame, so we both can
       // and need to zero out the colormap and image data after every new frame.
       memset(mImageData, 0, mImageDataLength);
       if (mColormap) {
         memset(mColormap, 0, mColormapSize);
       }
 
       if (!mGIFStruct.images_decoded) {
-        // Send a onetime invalidation for the first frame if it has a y-axis offset. 
-        // Otherwise, the area may never be refreshed and the placeholder will remain
-        // on the screen. (Bug 37589)
+        // Send a onetime invalidation for the first frame if it has a y-axis
+        // offset. Otherwise, the area may never be refreshed and the
+        // placeholder will remain on the screen. (Bug 37589)
         if (mGIFStruct.y_offset > 0) {
           nsIntRect r(0, 0, mGIFStruct.screen_width, mGIFStruct.y_offset);
           PostInvalidation(r);
         }
       }
 
       if (q[8] & 0x40) {
         mGIFStruct.interlaced = true;
         mGIFStruct.ipass = 1;
       } else {
         mGIFStruct.interlaced = false;
         mGIFStruct.ipass = 0;
       }
 
-      /* Only apply the Haeberli display hack on the first frame */
+      // Only apply the Haeberli display hack on the first frame
       mGIFStruct.progressive_display = (mGIFStruct.images_decoded == 0);
 
-      /* Clear state from last image */
+      // Clear state from last image
       mGIFStruct.irow = 0;
       mGIFStruct.rows_remaining = mGIFStruct.height;
       mGIFStruct.rowp = mImageData;
 
-      /* Depth of colors is determined by colormap */
-      /* (q[8] & 0x80) indicates local colormap */
-      /* bits per pixel is (q[8]&0x07 + 1) when local colormap is set */
+      // Depth of colors is determined by colormap
+      // (q[8] & 0x80) indicates local colormap
+      // bits per pixel is (q[8]&0x07 + 1) when local colormap is set
       uint32_t depth = mGIFStruct.global_colormap_depth;
-      if (q[8] & 0x80)
+      if (q[8] & 0x80) {
         depth = (q[8]&0x07) + 1;
+      }
       uint32_t realDepth = depth;
       while (mGIFStruct.tpixel >= (1 << realDepth) && (realDepth < 8)) {
         realDepth++;
       }
-
-      if (q[8] & 0x80) /* has a local colormap? */
-      {
+      // has a local colormap?
+      if (q[8] & 0x80) {
         mGIFStruct.local_colormap_size = 1 << depth;
         if (!mGIFStruct.images_decoded) {
           // First frame has local colormap, allocate space for it
           // as the image frame doesn't have its own palette
           mColormapSize = sizeof(uint32_t) << realDepth;
           if (!mGIFStruct.local_colormap) {
             mGIFStruct.local_colormap = (uint32_t*)moz_xmalloc(mColormapSize);
           }
@@ -1006,17 +1036,17 @@ nsGIFDecoder2::WriteInternal(const char 
         }
         // Copy everything, go to colormap state to do CMS correction
         memcpy(mColormap, buf, size);
         buf += size;
         len -= size;
         GETN(0, gif_image_colormap);
         break;
       } else {
-        /* Switch back to the global palette */
+        // Switch back to the global palette
         if (mGIFStruct.images_decoded) {
           // Copy global colormap into the palette of current frame
           memcpy(mColormap, mGIFStruct.global_colormap, mColormapSize);
         } else {
           mColormap = mGIFStruct.global_colormap;
         }
       }
       GETN(1, gif_lzw_start);
@@ -1028,36 +1058,36 @@ nsGIFDecoder2::WriteInternal(const char 
       // Convert into Cairo colors including CMS transformation
       ConvertColormap(mColormap, mGIFStruct.local_colormap_size);
       GETN(1, gif_lzw_start);
       break;
 
     case gif_sub_block:
       mGIFStruct.count = *q;
       if (mGIFStruct.count) {
-        /* Still working on the same image: Process next LZW data block */
-        /* Make sure there are still rows left. If the GIF data */
-        /* is corrupt, we may not get an explicit terminator.   */
+        // Still working on the same image: Process next LZW data block
+        // Make sure there are still rows left. If the GIF data
+        // is corrupt, we may not get an explicit terminator.
         if (!mGIFStruct.rows_remaining) {
 #ifdef DONT_TOLERATE_BROKEN_GIFS
           mGIFStruct.state = gif_error;
           break;
 #else
-          /* This is an illegal GIF, but we remain tolerant. */
+          // This is an illegal GIF, but we remain tolerant.
           GETN(1, gif_sub_block);
 #endif
           if (mGIFStruct.count == GIF_TRAILER) {
-            /* Found a terminator anyway, so consider the image done */
+            // Found a terminator anyway, so consider the image done
             GETN(1, gif_done);
             break;
           }
         }
         GETN(mGIFStruct.count, gif_lzw);
       } else {
-        /* See if there are any more images in this sequence. */
+        // See if there are any more images in this sequence.
         EndImageFrame();
         GETN(1, gif_image_start);
       }
       break;
 
     case gif_done:
       MOZ_ASSERT(!IsSizeDecode(), "Size decodes shouldn't reach gif_done");
       FinishInternal();
@@ -1077,24 +1107,26 @@ nsGIFDecoder2::WriteInternal(const char 
   if (mGIFStruct.state == gif_error) {
       PostDataError();
       return;
   }
 
   // Copy the leftover into mGIFStruct.hold
   if (len) {
     // Add what we have sofar to the block
-    if (mGIFStruct.state != gif_global_colormap && mGIFStruct.state != gif_image_colormap) {
+    if (mGIFStruct.state != gif_global_colormap &&
+        mGIFStruct.state != gif_image_colormap) {
       if (!SetHold(buf, len)) {
         PostDataError();
         return;
       }
     } else {
-      uint8_t* p = (mGIFStruct.state == gif_global_colormap) ? (uint8_t*)mGIFStruct.global_colormap :
-                                                               (uint8_t*)mColormap;
+      uint8_t* p = (mGIFStruct.state == gif_global_colormap) ?
+                    (uint8_t*)mGIFStruct.global_colormap :
+                    (uint8_t*)mColormap;
       memcpy(p, buf, len);
       mGIFStruct.bytes_in_hold = len;
     }
 
     mGIFStruct.bytes_to_consume -= len;
   }
 
 // We want to flush before returning if we're on the first frame
@@ -1104,20 +1136,23 @@ done:
     mLastFlushedRow = mCurrentRow;
     mLastFlushedPass = mCurrentPass;
   }
 
   return;
 }
 
 bool
-nsGIFDecoder2::SetHold(const uint8_t* buf1, uint32_t count1, const uint8_t* buf2 /* = nullptr */, uint32_t count2 /* = 0 */)
+nsGIFDecoder2::SetHold(const uint8_t* buf1, uint32_t count1,
+                       const uint8_t* buf2 /* = nullptr */,
+                       uint32_t count2 /* = 0 */)
 {
   // We have to handle the case that buf currently points to hold
-  uint8_t* newHold = (uint8_t *) moz_malloc(std::max(uint32_t(MIN_HOLD_SIZE), count1 + count2));
+  uint8_t* newHold = (uint8_t*) moz_malloc(std::max(uint32_t(MIN_HOLD_SIZE),
+                                            count1 + count2));
   if (!newHold) {
     mGIFStruct.state = gif_error;
     return false;
   }
 
   memcpy(newHold, buf1, count1);
   if (buf2) {
     memcpy(newHold + count1, buf2, count2);
--- a/image/decoders/nsGIFDecoder2.h
+++ b/image/decoders/nsGIFDecoder2.h
@@ -1,53 +1,54 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef _nsGIFDecoder2_h
-#define _nsGIFDecoder2_h
+#ifndef nsGIFDecoder2_h
+#define nsGIFDecoder2_h
 
-#include "nsCOMPtr.h"
 #include "Decoder.h"
 
 #include "GIF2.h"
+#include "nsCOMPtr.h"
 
 namespace mozilla {
 namespace image {
 class RasterImage;
 
 //////////////////////////////////////////////////////////////////////
 // nsGIFDecoder2 Definition
 
 class nsGIFDecoder2 : public Decoder
 {
 public:
 
-  explicit nsGIFDecoder2(RasterImage &aImage);
+  explicit nsGIFDecoder2(RasterImage& aImage);
   ~nsGIFDecoder2();
 
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
+  virtual void WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy aStrategy) MOZ_OVERRIDE;
   virtual void FinishInternal();
   virtual Telemetry::ID SpeedHistogram();
 
 private:
-  /* These functions will be called when the decoder has a decoded row,
-   * frame size information, etc. */
+  // These functions will be called when the decoder has a decoded row,
+  // frame size information, etc.
 
   void      BeginGIF();
   void      BeginImageFrame(uint16_t aDepth);
   void      EndImageFrame();
   void      FlushImageData();
   void      FlushImageData(uint32_t fromRow, uint32_t rows);
 
-  nsresult  GifWrite(const uint8_t * buf, uint32_t numbytes);
+  nsresult  GifWrite(const uint8_t* buf, uint32_t numbytes);
   uint32_t  OutputRow();
-  bool      DoLzw(const uint8_t *q);
+  bool      DoLzw(const uint8_t* q);
   bool      SetHold(const uint8_t* buf, uint32_t count,
                     const uint8_t* buf2 = nullptr, uint32_t count2 = 0);
 
   inline int ClearCode() const { return 1 << mGIFStruct.datasize; }
 
   int32_t mCurrentRow;
   int32_t mLastFlushedRow;
 
@@ -64,9 +65,9 @@ private:
   bool mSawTransparency;
 
   gif_struct mGIFStruct;
 };
 
 } // namespace image
 } // namespace mozilla
 
-#endif
+#endif // nsGIFDecoder2_h
--- a/image/decoders/nsICODecoder.cpp
+++ b/image/decoders/nsICODecoder.cpp
@@ -21,26 +21,26 @@ namespace image {
 #define BITMAPINFOSIZE 40
 #define PREFICONSIZE 16
 
 // ----------------------------------------
 // Actual Data Processing
 // ----------------------------------------
 
 uint32_t
-nsICODecoder::CalcAlphaRowSize() 
+nsICODecoder::CalcAlphaRowSize()
 {
   // Calculate rowsize in DWORD's and then return in # of bytes
   uint32_t rowSize = (GetRealWidth() + 31) / 32; // + 31 to round up
   return rowSize * 4; // Return rowSize in bytes
 }
 
 // Obtains the number of colors from the bits per pixel
 uint16_t
-nsICODecoder::GetNumColors() 
+nsICODecoder::GetNumColors()
 {
   uint16_t numColors = 0;
   if (mBPP <= 8) {
     switch (mBPP) {
     case 1:
       numColors = 2;
       break;
     case 4:
@@ -52,17 +52,17 @@ nsICODecoder::GetNumColors()
     default:
       numColors = (uint16_t)-1;
     }
   }
   return numColors;
 }
 
 
-nsICODecoder::nsICODecoder(RasterImage &aImage)
+nsICODecoder::nsICODecoder(RasterImage& aImage)
  : Decoder(aImage)
 {
   mPos = mImageOffset = mCurrIcon = mNumIcons = mBPP = mRowBytes = 0;
   mIsPNG = false;
   mRow = nullptr;
   mOldLine = mCurLine = 1; // Otherwise decoder will never start
 }
 
@@ -83,21 +83,22 @@ nsICODecoder::FinishInternal()
   if (mContainedDecoder) {
     mContainedDecoder->FinishSharedDecoder();
     mDecodeDone = mContainedDecoder->GetDecodeDone();
   }
 }
 
 // Returns a buffer filled with the bitmap file header in little endian:
 // Signature 2 bytes 'BM'
-// FileSize	 4 bytes File size in bytes
-// reserved	 4 bytes unused (=0)
-// DataOffset	 4 bytes File offset to Raster Data
+// FileSize      4 bytes File size in bytes
+// reserved      4 bytes unused (=0)
+// DataOffset    4 bytes File offset to Raster Data
 // Returns true if successful
-bool nsICODecoder::FillBitmapFileHeaderBuffer(int8_t *bfh) 
+bool
+nsICODecoder::FillBitmapFileHeaderBuffer(int8_t* bfh)
 {
   memset(bfh, 0, 14);
   bfh[0] = 'B';
   bfh[1] = 'M';
   int32_t dataOffset = 0;
   int32_t fileSize = 0;
   dataOffset = BFH_LENGTH + BITMAPINFOSIZE;
 
@@ -105,116 +106,118 @@ bool nsICODecoder::FillBitmapFileHeaderB
   if (mDirEntry.mBitCount <= 8) {
     uint16_t numColors = GetNumColors();
     if (numColors == (uint16_t)-1) {
       return false;
     }
     dataOffset += 4 * numColors;
     fileSize = dataOffset + GetRealWidth() * GetRealHeight();
   } else {
-    fileSize = dataOffset + (mDirEntry.mBitCount * GetRealWidth() * 
+    fileSize = dataOffset + (mDirEntry.mBitCount * GetRealWidth() *
                              GetRealHeight()) / 8;
   }
 
   NativeEndian::swapToLittleEndianInPlace(&fileSize, 1);
   memcpy(bfh + 2, &fileSize, sizeof(fileSize));
   NativeEndian::swapToLittleEndianInPlace(&dataOffset, 1);
   memcpy(bfh + 10, &dataOffset, sizeof(dataOffset));
   return true;
 }
 
 // A BMP inside of an ICO has *2 height because of the AND mask
 // that follows the actual bitmap.  The BMP shouldn't know about
 // this difference though.
 bool
-nsICODecoder::FixBitmapHeight(int8_t *bih) 
+nsICODecoder::FixBitmapHeight(int8_t* bih)
 {
   // Get the height from the BMP file information header
   int32_t height;
   memcpy(&height, bih + 8, sizeof(height));
   NativeEndian::swapFromLittleEndianInPlace(&height, 1);
   // BMPs can be stored inverted by having a negative height
   height = abs(height);
 
   // The bitmap height is by definition * 2 what it should be to account for
   // the 'AND mask'. It is * 2 even if the `AND mask` is not present.
   height /= 2;
 
   if (height > 256) {
     return false;
   }
 
-  // We should always trust the height from the bitmap itself instead of 
+  // We should always trust the height from the bitmap itself instead of
   // the ICO height.  So fix the ICO height.
   if (height == 256) {
     mDirEntry.mHeight = 0;
   } else {
     mDirEntry.mHeight = (int8_t)height;
   }
 
   // Fix the BMP height in the BIH so that the BMP decoder can work properly
   NativeEndian::swapToLittleEndianInPlace(&height, 1);
   memcpy(bih + 8, &height, sizeof(height));
   return true;
 }
 
 // We should always trust the contained resource for the width
 // information over our own information.
 bool
-nsICODecoder::FixBitmapWidth(int8_t *bih) 
+nsICODecoder::FixBitmapWidth(int8_t* bih)
 {
   // Get the width from the BMP file information header
   int32_t width;
   memcpy(&width, bih + 4, sizeof(width));
   NativeEndian::swapFromLittleEndianInPlace(&width, 1);
   if (width > 256) {
     return false;
   }
 
-  // We should always trust the width  from the bitmap itself instead of 
+  // We should always trust the width  from the bitmap itself instead of
   // the ICO width.
   if (width == 256) {
     mDirEntry.mWidth = 0;
   } else {
     mDirEntry.mWidth = (int8_t)width;
   }
   return true;
 }
 
 // The BMP information header's bits per pixel should be trusted
 // more than what we have.  Usually the ICO's BPP is set to 0
-int32_t 
-nsICODecoder::ExtractBPPFromBitmap(int8_t *bih)
+int32_t
+nsICODecoder::ExtractBPPFromBitmap(int8_t* bih)
 {
   int32_t bitsPerPixel;
   memcpy(&bitsPerPixel, bih + 14, sizeof(bitsPerPixel));
   NativeEndian::swapFromLittleEndianInPlace(&bitsPerPixel, 1);
   return bitsPerPixel;
 }
 
-int32_t 
-nsICODecoder::ExtractBIHSizeFromBitmap(int8_t *bih)
+int32_t
+nsICODecoder::ExtractBIHSizeFromBitmap(int8_t* bih)
 {
   int32_t headerSize;
   memcpy(&headerSize, bih, sizeof(headerSize));
   NativeEndian::swapFromLittleEndianInPlace(&headerSize, 1);
   return headerSize;
 }
 
 void
-nsICODecoder::SetHotSpotIfCursor() {
+nsICODecoder::SetHotSpotIfCursor()
+{
   if (!mIsCursor) {
     return;
   }
 
   mImageMetadata.SetHotspot(mDirEntry.mXHotspot, mDirEntry.mYHotspot);
 }
 
 void
-nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy)
+nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount,
+                            DecodeStrategy aStrategy)
 {
   NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
 
   if (!aCount) {
     if (mContainedDecoder) {
       WriteToContainedDecoder(aBuffer, aCount, aStrategy);
     }
     return;
@@ -227,113 +230,117 @@ nsICODecoder::WriteInternal(const char* 
         return;
       }
       mIsCursor = (*aBuffer == 2);
     }
     mPos++; aBuffer++; aCount--;
   }
 
   if (mPos == ICONCOUNTOFFSET && aCount >= 2) {
-    mNumIcons = LittleEndian::readUint16(reinterpret_cast<const uint16_t*>(aBuffer));
+    mNumIcons =
+      LittleEndian::readUint16(reinterpret_cast<const uint16_t*>(aBuffer));
     aBuffer += 2;
     mPos += 2;
     aCount -= 2;
   }
 
-  if (mNumIcons == 0)
+  if (mNumIcons == 0) {
     return; // Nothing to do.
+  }
 
   uint16_t colorDepth = 0;
   nsIntSize prefSize = mImage.GetRequestedResolution();
   if (prefSize.width == 0 && prefSize.height == 0) {
     prefSize.SizeTo(PREFICONSIZE, PREFICONSIZE);
   }
 
   // A measure of the difference in size between the entry we've found
   // and the requested size. We will choose the smallest image that is
   // >= requested size (i.e. we assume it's better to downscale a larger
   // icon than to upscale a smaller one).
   int32_t diff = INT_MIN;
 
   // Loop through each entry's dir entry
-  while (mCurrIcon < mNumIcons) { 
-    if (mPos >= DIRENTRYOFFSET + (mCurrIcon * sizeof(mDirEntryArray)) && 
+  while (mCurrIcon < mNumIcons) {
+    if (mPos >= DIRENTRYOFFSET + (mCurrIcon * sizeof(mDirEntryArray)) &&
         mPos < DIRENTRYOFFSET + ((mCurrIcon + 1) * sizeof(mDirEntryArray))) {
-      uint32_t toCopy = sizeof(mDirEntryArray) - 
-                        (mPos - DIRENTRYOFFSET - mCurrIcon * sizeof(mDirEntryArray));
+      uint32_t toCopy = sizeof(mDirEntryArray) -
+                        (mPos - DIRENTRYOFFSET - mCurrIcon *
+                         sizeof(mDirEntryArray));
       if (toCopy > aCount) {
         toCopy = aCount;
       }
       memcpy(mDirEntryArray + sizeof(mDirEntryArray) - toCopy, aBuffer, toCopy);
       mPos += toCopy;
       aCount -= toCopy;
       aBuffer += toCopy;
     }
-    if (aCount == 0)
+    if (aCount == 0) {
       return; // Need more data
+    }
 
     IconDirEntry e;
-    if (mPos == (DIRENTRYOFFSET + ICODIRENTRYSIZE) + 
+    if (mPos == (DIRENTRYOFFSET + ICODIRENTRYSIZE) +
                 (mCurrIcon * sizeof(mDirEntryArray))) {
       mCurrIcon++;
       ProcessDirEntry(e);
       // We can't use GetRealWidth and GetRealHeight here because those operate
       // on mDirEntry, here we are going through each item in the directory.
       // Calculate the delta between this image's size and the desired size,
       // so we can see if it is better than our current-best option.
       // In the case of several equally-good images, we use the last one.
       int32_t delta = (e.mWidth == 0 ? 256 : e.mWidth) - prefSize.width +
                       (e.mHeight == 0 ? 256 : e.mHeight) - prefSize.height;
       if (e.mBitCount >= colorDepth &&
           ((diff < 0 && delta >= diff) || (delta >= 0 && delta <= diff))) {
         diff = delta;
         mImageOffset = e.mImageOffset;
 
         // ensure mImageOffset is >= size of the direntry headers (bug #245631)
-        uint32_t minImageOffset = DIRENTRYOFFSET + 
+        uint32_t minImageOffset = DIRENTRYOFFSET +
                                   mNumIcons * sizeof(mDirEntryArray);
         if (mImageOffset < minImageOffset) {
           PostDataError();
           return;
         }
 
         colorDepth = e.mBitCount;
         memcpy(&mDirEntry, &e, sizeof(IconDirEntry));
       }
     }
   }
 
   if (mPos < mImageOffset) {
     // Skip to (or at least towards) the desired image offset
     uint32_t toSkip = mImageOffset - mPos;
-    if (toSkip > aCount)
+    if (toSkip > aCount) {
       toSkip = aCount;
+    }
 
     mPos    += toSkip;
     aBuffer += toSkip;
     aCount  -= toSkip;
   }
 
   // If we are within the first PNGSIGNATURESIZE bytes of the image data,
   // then we have either a BMP or a PNG.  We use the first PNGSIGNATURESIZE
   // bytes to determine which one we have.
-  if (mCurrIcon == mNumIcons && mPos >= mImageOffset && 
-      mPos < mImageOffset + PNGSIGNATURESIZE)
-  {
+  if (mCurrIcon == mNumIcons && mPos >= mImageOffset &&
+      mPos < mImageOffset + PNGSIGNATURESIZE) {
     uint32_t toCopy = PNGSIGNATURESIZE - (mPos - mImageOffset);
     if (toCopy > aCount) {
       toCopy = aCount;
     }
 
     memcpy(mSignature + (mPos - mImageOffset), aBuffer, toCopy);
     mPos += toCopy;
     aCount -= toCopy;
     aBuffer += toCopy;
 
-    mIsPNG = !memcmp(mSignature, nsPNGDecoder::pngSignatureBytes, 
+    mIsPNG = !memcmp(mSignature, nsPNGDecoder::pngSignatureBytes,
                      PNGSIGNATURESIZE);
     if (mIsPNG) {
       mContainedDecoder = new nsPNGDecoder(mImage);
       mContainedDecoder->SetObserver(mObserver);
       mContainedDecoder->SetSizeDecode(IsSizeDecode());
       mContainedDecoder->InitSharedDecoder(mImageData, mImageDataLength,
                                            mColormap, mColormapSize,
                                            mCurrentFrame);
@@ -362,73 +369,76 @@ nsICODecoder::WriteInternal(const char* 
     // http://blogs.msdn.com/b/oldnewthing/archive/2010/10/22/10079192.aspx
     if (!IsSizeDecode() &&
         !static_cast<nsPNGDecoder*>(mContainedDecoder.get())->IsValidICO()) {
       PostDataError();
     }
     return;
   }
 
-  // We've processed all of the icon dir entries and are within the 
+  // We've processed all of the icon dir entries and are within the
   // bitmap info size
-  if (!mIsPNG && mCurrIcon == mNumIcons && mPos >= mImageOffset && 
-      mPos >= mImageOffset + PNGSIGNATURESIZE && 
+  if (!mIsPNG && mCurrIcon == mNumIcons && mPos >= mImageOffset &&
+      mPos >= mImageOffset + PNGSIGNATURESIZE &&
       mPos < mImageOffset + BITMAPINFOSIZE) {
 
     // As we were decoding, we did not know if we had a PNG signature or the
     // start of a bitmap information header.  At this point we know we had
     // a bitmap information header and not a PNG signature, so fill the bitmap
     // information header with the data it should already have.
     memcpy(mBIHraw, mSignature, PNGSIGNATURESIZE);
 
     // We've found the icon.
     uint32_t toCopy = sizeof(mBIHraw) - (mPos - mImageOffset);
-    if (toCopy > aCount)
+    if (toCopy > aCount) {
       toCopy = aCount;
+    }
 
     memcpy(mBIHraw + (mPos - mImageOffset), aBuffer, toCopy);
     mPos += toCopy;
     aCount -= toCopy;
     aBuffer += toCopy;
   }
 
   // If we have a BMP inside the ICO and we have read the BIH header
   if (!mIsPNG && mPos == mImageOffset + BITMAPINFOSIZE) {
 
     // Make sure we have a sane value for the bitmap information header
-    int32_t bihSize = ExtractBIHSizeFromBitmap(reinterpret_cast<int8_t*>(mBIHraw));
+    int32_t bihSize = ExtractBIHSizeFromBitmap(reinterpret_cast<int8_t*>
+                                               (mBIHraw));
     if (bihSize != BITMAPINFOSIZE) {
       PostDataError();
       return;
     }
-    // We are extracting the BPP from the BIH header as it should be trusted 
+    // We are extracting the BPP from the BIH header as it should be trusted
     // over the one we have from the icon header
     mBPP = ExtractBPPFromBitmap(reinterpret_cast<int8_t*>(mBIHraw));
-    
+
     // Init the bitmap decoder which will do most of the work for us
     // It will do everything except the AND mask which isn't present in bitmaps
     // bmpDecoder is for local scope ease, it will be freed by mContainedDecoder
-    nsBMPDecoder *bmpDecoder = new nsBMPDecoder(mImage);
+    nsBMPDecoder* bmpDecoder = new nsBMPDecoder(mImage);
     mContainedDecoder = bmpDecoder;
     bmpDecoder->SetUseAlphaData(true);
     mContainedDecoder->SetObserver(mObserver);
     mContainedDecoder->SetSizeDecode(IsSizeDecode());
     mContainedDecoder->InitSharedDecoder(mImageData, mImageDataLength,
                                          mColormap, mColormapSize,
                                          mCurrentFrame);
 
     // The ICO format when containing a BMP does not include the 14 byte
-    // bitmap file header. To use the code of the BMP decoder we need to 
+    // bitmap file header. To use the code of the BMP decoder we need to
     // generate this header ourselves and feed it to the BMP decoder.
     int8_t bfhBuffer[BMPFILEHEADERSIZE];
     if (!FillBitmapFileHeaderBuffer(bfhBuffer)) {
       PostDataError();
       return;
     }
-    if (!WriteToContainedDecoder((const char*)bfhBuffer, sizeof(bfhBuffer), aStrategy)) {
+    if (!WriteToContainedDecoder((const char*)bfhBuffer, sizeof(bfhBuffer),
+                                  aStrategy)) {
       return;
     }
 
     // Setup the cursor hot spot if one is present
     SetHotSpotIfCursor();
 
     // Fix the ICO height from the BIH.
     // Fix the height on the BIH to be /2 so our BMP decoder will understand.
@@ -448,18 +458,19 @@ nsICODecoder::WriteInternal(const char* 
       return;
     }
 
     PostSize(mContainedDecoder->GetImageMetadata().GetWidth(),
              mContainedDecoder->GetImageMetadata().GetHeight());
 
     // We have the size. If we're doing a size decode, we got what
     // we came for.
-    if (IsSizeDecode())
+    if (IsSizeDecode()) {
       return;
+    }
 
     // Sometimes the ICO BPP header field is not filled out
     // so we should trust the contained resource over our own
     // information.
     mBPP = bmpDecoder->GetBitsPerPixel();
 
     // Check to make sure we have valid color settings
     uint16_t numColors = GetNumColors();
@@ -473,18 +484,19 @@ nsICODecoder::WriteInternal(const char* 
   if (!mIsPNG && mContainedDecoder && mPos >= mImageOffset + BITMAPINFOSIZE) {
     uint16_t numColors = GetNumColors();
     if (numColors == (uint16_t)-1) {
       PostDataError();
       return;
     }
     // Feed the actual image data (not including headers) into the BMP decoder
     uint32_t bmpDataOffset = mDirEntry.mImageOffset + BITMAPINFOSIZE;
-    uint32_t bmpDataEnd = mDirEntry.mImageOffset + BITMAPINFOSIZE + 
-                          static_cast<nsBMPDecoder*>(mContainedDecoder.get())->GetCompressedImageSize() +
+    uint32_t bmpDataEnd = mDirEntry.mImageOffset + BITMAPINFOSIZE +
+                          static_cast<nsBMPDecoder*>(mContainedDecoder.get())->
+                            GetCompressedImageSize() +
                           4 * numColors;
 
     // If we are feeding in the core image data, but we have not yet
     // reached the ICO's 'AND buffer mask'
     if (mPos >= bmpDataOffset && mPos < bmpDataEnd) {
 
       // Figure out how much data the BMP decoder wants
       uint32_t toFeed = bmpDataEnd - mPos;
@@ -495,26 +507,28 @@ nsICODecoder::WriteInternal(const char* 
       if (!WriteToContainedDecoder(aBuffer, toFeed, aStrategy)) {
         return;
       }
 
       mPos += toFeed;
       aCount -= toFeed;
       aBuffer += toFeed;
     }
-  
+
     // If the bitmap is fully processed, treat any left over data as the ICO's
     // 'AND buffer mask' which appears after the bitmap resource.
     if (!mIsPNG && mPos >= bmpDataEnd) {
       // There may be an optional AND bit mask after the data.  This is
-      // only used if the alpha data is not already set. The alpha data 
+      // only used if the alpha data is not already set. The alpha data
       // is used for 32bpp bitmaps as per the comment in ICODecoder.h
       // The alpha mask should be checked in all other cases.
-      if (static_cast<nsBMPDecoder*>(mContainedDecoder.get())->GetBitsPerPixel() != 32 || 
-          !static_cast<nsBMPDecoder*>(mContainedDecoder.get())->HasAlphaData()) {
+      if (static_cast<nsBMPDecoder*>(mContainedDecoder.get())->
+            GetBitsPerPixel() != 32 ||
+          !static_cast<nsBMPDecoder*>(mContainedDecoder.get())->
+            HasAlphaData()) {
         uint32_t rowSize = ((GetRealWidth() + 31) / 32) * 4; // + 31 to round up
         if (mPos == bmpDataEnd) {
           mPos++;
           mRowBytes = 0;
           mCurLine = GetRealHeight();
           mRow = (uint8_t*)moz_realloc(mRow, rowSize);
           if (!mRow) {
             PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
@@ -536,18 +550,19 @@ nsICODecoder::WriteInternal(const char* 
             aCount -= toCopy;
             aBuffer += toCopy;
             mRowBytes += toCopy;
           }
           if (rowSize == mRowBytes) {
             mCurLine--;
             mRowBytes = 0;
 
-            uint32_t* imageData = 
-              static_cast<nsBMPDecoder*>(mContainedDecoder.get())->GetImageData();
+            uint32_t* imageData =
+              static_cast<nsBMPDecoder*>(mContainedDecoder.get())->
+                                           GetImageData();
             if (!imageData) {
               PostDataError();
               return;
             }
             uint32_t* decoded = imageData + mCurLine * GetRealWidth();
             uint32_t* decoded_end = decoded + GetRealWidth();
             uint8_t* p = mRow;
             uint8_t* p_end = mRow + rowSize;
@@ -564,17 +579,18 @@ nsICODecoder::WriteInternal(const char* 
           }
         }
       }
     }
   }
 }
 
 bool
-nsICODecoder::WriteToContainedDecoder(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy)
+nsICODecoder::WriteToContainedDecoder(const char* aBuffer, uint32_t aCount,
+                                      DecodeStrategy aStrategy)
 {
   mContainedDecoder->Write(aBuffer, aCount, aStrategy);
   if (mContainedDecoder->HasDataError()) {
     mDataError = mContainedDecoder->HasDataError();
   }
   if (mContainedDecoder->HasDecoderError()) {
     PostDecoderError(mContainedDecoder->GetDecoderError());
   }
@@ -590,17 +606,17 @@ nsICODecoder::ProcessDirEntry(IconDirEnt
   memcpy(&aTarget.mColorCount, mDirEntryArray + 2, sizeof(aTarget.mColorCount));
   memcpy(&aTarget.mReserved, mDirEntryArray + 3, sizeof(aTarget.mReserved));
   memcpy(&aTarget.mPlanes, mDirEntryArray + 4, sizeof(aTarget.mPlanes));
   aTarget.mPlanes = LittleEndian::readUint16(&aTarget.mPlanes);
   memcpy(&aTarget.mBitCount, mDirEntryArray + 6, sizeof(aTarget.mBitCount));
   aTarget.mBitCount = LittleEndian::readUint16(&aTarget.mBitCount);
   memcpy(&aTarget.mBytesInRes, mDirEntryArray + 8, sizeof(aTarget.mBytesInRes));
   aTarget.mBytesInRes = LittleEndian::readUint32(&aTarget.mBytesInRes);
-  memcpy(&aTarget.mImageOffset, mDirEntryArray + 12, 
+  memcpy(&aTarget.mImageOffset, mDirEntryArray + 12,
          sizeof(aTarget.mImageOffset));
   aTarget.mImageOffset = LittleEndian::readUint32(&aTarget.mImageOffset);
 }
 
 bool
 nsICODecoder::NeedsNewFrame() const
 {
   if (mContainedDecoder) {
--- a/image/decoders/nsICODecoder.h
+++ b/image/decoders/nsICODecoder.h
@@ -1,56 +1,58 @@
 /* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
-#ifndef _nsICODecoder_h
-#define _nsICODecoder_h
+#ifndef nsICODecoder_h
+#define nsICODecoder_h
 
 #include "nsAutoPtr.h"
 #include "Decoder.h"
 #include "nsBMPDecoder.h"
 #include "nsPNGDecoder.h"
 #include "ICOFileHeaders.h"
 
 namespace mozilla {
 namespace image {
 
 class RasterImage;
 
 class nsICODecoder : public Decoder
 {
 public:
 
-  explicit nsICODecoder(RasterImage &aImage);
+  explicit nsICODecoder(RasterImage& aImage);
   virtual ~nsICODecoder();
 
   // Obtains the width of the icon directory entry
   uint32_t GetRealWidth() const
   {
-    return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth; 
+    return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth;
   }
 
   // Obtains the height of the icon directory entry
   uint32_t GetRealHeight() const
   {
-    return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight; 
+    return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight;
   }
 
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
+  virtual void WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy aStrategy) MOZ_OVERRIDE;
   virtual void FinishInternal();
   virtual bool NeedsNewFrame() const;
   virtual nsresult AllocateFrame();
 
 private:
   // Writes to the contained decoder and sets the appropriate errors
   // Returns true if there are no errors.
-  bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
+  bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount,
+                               DecodeStrategy aStrategy);
 
   // Processes a single dir entry of the icon resource
   void ProcessDirEntry(IconDirEntry& aTarget);
   // Sets the hotspot property of if we have a cursor
   void SetHotSpotIfCursor();
   // Creates a bitmap file header buffer, returns true if successful
   bool FillBitmapFileHeaderBuffer(int8_t *bfh);
   // Fixes the ICO height to match that of the BIH.
@@ -70,30 +72,30 @@ private:
   // Obtains the number of colors from the BPP, mBPP must be filled in
   uint16_t GetNumColors();
 
   uint16_t mBPP; // Stores the images BPP
   uint32_t mPos; // Keeps track of the position we have decoded up until
   uint16_t mNumIcons; // Stores the number of icons in the ICO file
   uint16_t mCurrIcon; // Stores the current dir entry index we are processing
   uint32_t mImageOffset; // Stores the offset of the image data we want
-  uint8_t *mRow;      // Holds one raw line of the image
+  uint8_t* mRow;      // Holds one raw line of the image
   int32_t mCurLine;   // Line index of the image that's currently being decoded
   uint32_t mRowBytes; // How many bytes of the row were already received
-  int32_t mOldLine;   // Previous index of the line 
+  int32_t mOldLine;   // Previous index of the line
   nsRefPtr<Decoder> mContainedDecoder; // Contains either a BMP or PNG resource
 
   char mDirEntryArray[ICODIRENTRYSIZE]; // Holds the current dir entry buffer
   IconDirEntry mDirEntry; // Holds a decoded dir entry
   // Holds the potential bytes that can be a PNG signature
-  char mSignature[PNGSIGNATURESIZE]; 
+  char mSignature[PNGSIGNATURESIZE];
   // Holds the potential bytes for a bitmap information header
   char mBIHraw[40];
   // Stores whether or not the icon file we are processing has type 1 (icon)
   bool mIsCursor;
   // Stores whether or not the contained resource is a PNG
   bool mIsPNG;
 };
 
 } // namespace image
 } // namespace mozilla
 
-#endif
+#endif // nsICODecoder_h
--- a/image/decoders/nsIconDecoder.cpp
+++ b/image/decoders/nsIconDecoder.cpp
@@ -1,41 +1,41 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIconDecoder.h"
 #include "nsIInputStream.h"
-#include "RasterImage.h"
 #include "nspr.h"
 #include "nsRect.h"
-
 #include "nsError.h"
+#include "RasterImage.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace image {
 
-nsIconDecoder::nsIconDecoder(RasterImage &aImage)
+nsIconDecoder::nsIconDecoder(RasterImage& aImage)
  : Decoder(aImage),
    mWidth(-1),
    mHeight(-1),
    mPixBytesRead(0),
    mState(iconStateStart)
 {
   // Nothing to do
 }
 
 nsIconDecoder::~nsIconDecoder()
 { }
 
 void
-nsIconDecoder::WriteInternal(const char *aBuffer, uint32_t aCount, DecodeStrategy)
+nsIconDecoder::WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy)
 {
   NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
 
   // We put this here to avoid errors about crossing initialization with case
   // jumps on linux.
   uint32_t bytesToRead = 0;
 
   // Loop until the input data is gone
@@ -77,18 +77,17 @@ nsIconDecoder::WriteInternal(const char 
         }
 
         // Book Keeping
         aBuffer++;
         aCount--;
         mState = iconStateReadPixels;
         break;
 
-      case iconStateReadPixels:
-      {
+      case iconStateReadPixels: {
 
         // How many bytes are we reading?
         bytesToRead = std::min(aCount, mImageDataLength - mPixBytesRead);
 
         // Copy the bytes
         memcpy(mImageData + mPixBytesRead, aBuffer, bytesToRead);
 
         // Performance isn't critical here, so our update rectangle is
--- a/image/decoders/nsIconDecoder.h
+++ b/image/decoders/nsIconDecoder.h
@@ -1,52 +1,53 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef nsIconDecoder_h__
-#define nsIconDecoder_h__
+#ifndef nsIconDecoder_h
+#define nsIconDecoder_h
 
 #include "Decoder.h"
 
 #include "nsCOMPtr.h"
 
 namespace mozilla {
 namespace image {
 class RasterImage;
 
-//////////////////////////////////////////////////////////////////////////////////////////////
-// The icon decoder is a decoder specifically tailored for loading icons 
+////////////////////////////////////////////////////////////////////////////////
+// The icon decoder is a decoder specifically tailored for loading icons
 // from the OS. We've defined our own little format to represent these icons
-// and this decoder takes that format and converts it into 24-bit RGB with alpha channel
-// support. It was modeled a bit off the PPM decoder.
+// and this decoder takes that format and converts it into 24-bit RGB with
+// alpha channel support. It was modeled a bit off the PPM decoder.
 //
 // Assumptions about the decoder:
-// (1) We receive ALL of the data from the icon channel in one OnDataAvailable call. We don't
-//     support multiple ODA calls yet.
+// (1) We receive ALL of the data from the icon channel in one OnDataAvailable
+//     call. We don't support multiple ODA calls yet.
 // (2) the format of the incoming data is as follows:
-//     The first two bytes contain the width and the height of the icon. 
+//     The first two bytes contain the width and the height of the icon.
 //     The remaining bytes contain the icon data, 4 bytes per pixel, in
 //       ARGB order (platform endianness, A in highest bits, B in lowest
 //       bits), row-primary, top-to-bottom, left-to-right, with
 //       premultiplied alpha.
 //
 //
-//////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
 
 class nsIconDecoder : public Decoder
 {
 public:
 
-  explicit nsIconDecoder(RasterImage &aImage);
+  explicit nsIconDecoder(RasterImage& aImage);
   virtual ~nsIconDecoder();
 
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
+  virtual void WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy aStrategy) MOZ_OVERRIDE;
 
   uint8_t mWidth;
   uint8_t mHeight;
   uint32_t mPixBytesRead;
   uint32_t mState;
 };
 
 enum {
@@ -54,9 +55,9 @@ enum {
   iconStateHaveHeight = 1,
   iconStateReadPixels = 2,
   iconStateFinished   = 3
 };
 
 } // namespace image
 } // namespace mozilla
 
-#endif // nsIconDecoder_h__
+#endif // nsIconDecoder_h
--- a/image/decoders/nsJPEGDecoder.cpp
+++ b/image/decoders/nsJPEGDecoder.cpp
@@ -30,40 +30,42 @@ extern "C" {
 #endif
 
 static void cmyk_convert_rgb(JSAMPROW row, JDIMENSION width);
 
 namespace mozilla {
 namespace image {
 
 #if defined(PR_LOGGING)
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetJPEGLog()
 {
-  static PRLogModuleInfo *sJPEGLog;
-  if (!sJPEGLog)
+  static PRLogModuleInfo* sJPEGLog;
+  if (!sJPEGLog) {
     sJPEGLog = PR_NewLogModule("JPEGDecoder");
+  }
   return sJPEGLog;
 }
 
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetJPEGDecoderAccountingLog()
 {
-  static PRLogModuleInfo *sJPEGDecoderAccountingLog;
-  if (!sJPEGDecoderAccountingLog)
+  static PRLogModuleInfo* sJPEGDecoderAccountingLog;
+  if (!sJPEGDecoderAccountingLog) {
     sJPEGDecoderAccountingLog = PR_NewLogModule("JPEGDecoderAccounting");
+  }
   return sJPEGDecoderAccountingLog;
 }
 #else
 #define GetJPEGLog()
 #define GetJPEGDecoderAccountingLog()
 #endif
 
 static qcms_profile*
-GetICCProfile(struct jpeg_decompress_struct &info)
+GetICCProfile(struct jpeg_decompress_struct& info)
 {
   JOCTET* profilebuf;
   uint32_t profileLength;
   qcms_profile* profile = nullptr;
 
   if (read_icc_profile(&info, &profilebuf, &profileLength)) {
     profile = qcms_profile_from_memory(profilebuf, profileLength);
     free(profilebuf);
@@ -73,21 +75,22 @@ GetICCProfile(struct jpeg_decompress_str
 }
 
 METHODDEF(void) init_source (j_decompress_ptr jd);
 METHODDEF(boolean) fill_input_buffer (j_decompress_ptr jd);
 METHODDEF(void) skip_input_data (j_decompress_ptr jd, long num_bytes);
 METHODDEF(void) term_source (j_decompress_ptr jd);
 METHODDEF(void) my_error_exit (j_common_ptr cinfo);
 
-/* Normal JFIF markers can't have more bytes than this. */
+// Normal JFIF markers can't have more bytes than this.
 #define MAX_JPEG_MARKER_LENGTH  (((uint32_t)1 << 16) - 1)
 
 
-nsJPEGDecoder::nsJPEGDecoder(RasterImage& aImage, Decoder::DecodeStyle aDecodeStyle)
+nsJPEGDecoder::nsJPEGDecoder(RasterImage& aImage,
+                             Decoder::DecodeStyle aDecodeStyle)
  : Decoder(aImage)
  , mDecodeStyle(aDecodeStyle)
 {
   mState = JPEG_HEADER;
   mReading = true;
   mImageData = nullptr;
 
   mBytesToSkip = 0;
@@ -113,458 +116,474 @@ nsJPEGDecoder::nsJPEGDecoder(RasterImage
 
 nsJPEGDecoder::~nsJPEGDecoder()
 {
   // Step 8: Release JPEG decompression object
   mInfo.src = nullptr;
   jpeg_destroy_decompress(&mInfo);
 
   PR_FREEIF(mBackBuffer);
-  if (mTransform)
+  if (mTransform) {
     qcms_transform_release(mTransform);
-  if (mInProfile)
+  }
+  if (mInProfile) {
     qcms_profile_release(mInProfile);
+  }
 
   PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
          ("nsJPEGDecoder::~nsJPEGDecoder: Destroying JPEG decoder %p",
           this));
 }
 
 Telemetry::ID
 nsJPEGDecoder::SpeedHistogram()
 {
   return Telemetry::IMAGE_DECODE_SPEED_JPEG;
 }
 
 void
 nsJPEGDecoder::InitInternal()
 {
   mCMSMode = gfxPlatform::GetCMSMode();
-  if ((mDecodeFlags & DECODER_NO_COLORSPACE_CONVERSION) != 0)
+  if ((mDecodeFlags & DECODER_NO_COLORSPACE_CONVERSION) != 0) {
     mCMSMode = eCMSMode_Off;
+  }
 
-  /* We set up the normal JPEG error routines, then override error_exit. */
+  // We set up the normal JPEG error routines, then override error_exit.
   mInfo.err = jpeg_std_error(&mErr.pub);
-  /*   mInfo.err = jpeg_std_error(&mErr.pub); */
+  //   mInfo.err = jpeg_std_error(&mErr.pub);
   mErr.pub.error_exit = my_error_exit;
-  /* Establish the setjmp return context for my_error_exit to use. */
+  // Establish the setjmp return context for my_error_exit to use.
   if (setjmp(mErr.setjmp_buffer)) {
-    /* If we get here, the JPEG code has signaled an error.
-     * We need to clean up the JPEG object, close the input file, and return.
-     */
+    // If we get here, the JPEG code has signaled an error.
+    // We need to clean up the JPEG object, close the input file, and return.
     PostDecoderError(NS_ERROR_FAILURE);
     return;
   }
 
-  /* Step 1: allocate and initialize JPEG decompression object */
+  // Step 1: allocate and initialize JPEG decompression object
   jpeg_create_decompress(&mInfo);
-  /* Set the source manager */
+  // Set the source manager
   mInfo.src = &mSourceMgr;
 
-  /* Step 2: specify data source (eg, a file) */
+  // Step 2: specify data source (eg, a file)
 
-  /* Setup callback functions. */
+  // Setup callback functions.
   mSourceMgr.init_source = init_source;
   mSourceMgr.fill_input_buffer = fill_input_buffer;
   mSourceMgr.skip_input_data = skip_input_data;
   mSourceMgr.resync_to_restart = jpeg_resync_to_restart;
   mSourceMgr.term_source = term_source;
 
-  /* Record app markers for ICC data */
+  // Record app markers for ICC data
   for (uint32_t m = 0; m < 16; m++)
     jpeg_save_markers(&mInfo, JPEG_APP0 + m, 0xFFFF);
 }
 
 void
 nsJPEGDecoder::FinishInternal()
 {
-  /* If we're not in any sort of error case, flush the decoder.
-   *
-   * XXXbholley - It seems wrong that this should be necessary, but at the
-   * moment I'm just folding the contents of Flush() into Close() so that
-   * we can get rid of it.
-   *
-   * XXX(seth): It'd be great to get rid of this. For now, we treat this as a
-   * write to a synchronous decoder, which means that this must be called only
-   * on the main thread. (That's asserted in Decoder::Finish and
-   * Decoder::FinishSharedDecoder.)
-   */
+  // If we're not in any sort of error case, flush the decoder.
+  //
+  // XXXbholley - It seems wrong that this should be necessary, but at the
+  // moment I'm just folding the contents of Flush() into Close() so that
+  // we can get rid of it.
+  //
+  // XXX(seth): It'd be great to get rid of this. For now, we treat this as a
+  // write to a synchronous decoder, which means that this must be called only
+  // on the main thread. (That's asserted in Decoder::Finish and
+  // Decoder::FinishSharedDecoder.)
   if ((mState != JPEG_DONE && mState != JPEG_SINK_NON_JPEG_TRAILER) &&
       (mState != JPEG_ERROR) &&
-      !IsSizeDecode())
+      !IsSizeDecode()) {
     this->Write(nullptr, 0, DECODE_SYNC);
+  }
 }
 
 void
-nsJPEGDecoder::WriteInternal(const char *aBuffer, uint32_t aCount, DecodeStrategy)
+nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy)
 {
-  mSegment = (const JOCTET *)aBuffer;
+  mSegment = (const JOCTET*)aBuffer;
   mSegmentLen = aCount;
 
   NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
 
-  /* Return here if there is a fatal error within libjpeg. */
+  // Return here if there is a fatal error within libjpeg.
   nsresult error_code;
   // This cast to nsresult makes sense because setjmp() returns whatever we
   // passed to longjmp(), which was actually an nsresult.
   if ((error_code = (nsresult)setjmp(mErr.setjmp_buffer)) != NS_OK) {
     if (error_code == NS_ERROR_FAILURE) {
       PostDataError();
-      /* Error due to corrupt stream - return NS_OK and consume silently
-         so that libpr0n doesn't throw away a partial image load */
+      // Error due to corrupt stream - return NS_OK and consume silently
+      // so that ImageLib doesn't throw away a partial image load
       mState = JPEG_SINK_NON_JPEG_TRAILER;
       PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
              ("} (setjmp returned NS_ERROR_FAILURE)"));
       return;
     } else {
-      /* Error due to reasons external to the stream (probably out of
-         memory) - let libpr0n attempt to clean up, even though
-         mozilla is seconds away from falling flat on its face. */
+      // Error due to reasons external to the stream (probably out of
+      // memory) - let ImageLib attempt to clean up, even though
+      // mozilla is seconds away from falling flat on its face.
       PostDecoderError(error_code);
       mState = JPEG_ERROR;
       PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
              ("} (setjmp returned an error)"));
       return;
     }
   }
 
   PR_LOG(GetJPEGLog(), PR_LOG_DEBUG,
          ("[this=%p] nsJPEGDecoder::Write -- processing JPEG data\n", this));
 
   switch (mState) {
-  case JPEG_HEADER:
-  {
-    LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- entering JPEG_HEADER case");
+    case JPEG_HEADER: {
+      LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- entering JPEG_HEADER"
+                " case");
 
-    /* Step 3: read file parameters with jpeg_read_header() */
-    if (jpeg_read_header(&mInfo, TRUE) == JPEG_SUSPENDED) {
-      PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
-             ("} (JPEG_SUSPENDED)"));
-      return; /* I/O suspension */
-    }
+      // Step 3: read file parameters with jpeg_read_header()
+      if (jpeg_read_header(&mInfo, TRUE) == JPEG_SUSPENDED) {
+        PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
+               ("} (JPEG_SUSPENDED)"));
+        return; // I/O suspension
+      }
 
-    int sampleSize = mImage.GetRequestedSampleSize();
-    if (sampleSize > 0) {
-      mInfo.scale_num = 1;
-      mInfo.scale_denom = sampleSize;
-    }
+      int sampleSize = mImage.GetRequestedSampleSize();
+      if (sampleSize > 0) {
+        mInfo.scale_num = 1;
+        mInfo.scale_denom = sampleSize;
+      }
+
+      // Used to set up image size so arrays can be allocated
+      jpeg_calc_output_dimensions(&mInfo);
 
-    /* Used to set up image size so arrays can be allocated */
-    jpeg_calc_output_dimensions(&mInfo);
+      // Post our size to the superclass
+      PostSize(mInfo.output_width, mInfo.output_height,
+               ReadOrientationFromEXIF());
+      if (HasError()) {
+        // Setting the size led to an error.
+        mState = JPEG_ERROR;
+        return;
+      }
 
-    // Post our size to the superclass
-    PostSize(mInfo.output_width, mInfo.output_height, ReadOrientationFromEXIF());
-    if (HasError()) {
-      // Setting the size led to an error.
-      mState = JPEG_ERROR;
-      return;
-    }
+      // If we're doing a size decode, we're done.
+      if (IsSizeDecode()) {
+        return;
+      }
 
-    /* If we're doing a size decode, we're done. */
-    if (IsSizeDecode())
-      return;
-
-    /* We're doing a full decode. */
-    if (mCMSMode != eCMSMode_Off &&
-        (mInProfile = GetICCProfile(mInfo)) != nullptr) {
-      uint32_t profileSpace = qcms_profile_get_color_space(mInProfile);
-      bool mismatch = false;
+      // We're doing a full decode.
+      if (mCMSMode != eCMSMode_Off &&
+          (mInProfile = GetICCProfile(mInfo)) != nullptr) {
+        uint32_t profileSpace = qcms_profile_get_color_space(mInProfile);
+        bool mismatch = false;
 
 #ifdef DEBUG_tor
       fprintf(stderr, "JPEG profileSpace: 0x%08X\n", profileSpace);
 #endif
       switch (mInfo.jpeg_color_space) {
-      case JCS_GRAYSCALE:
-        if (profileSpace == icSigRgbData)
-          mInfo.out_color_space = JCS_RGB;
-        else if (profileSpace != icSigGrayData)
-          mismatch = true;
-        break;
-      case JCS_RGB:
-        if (profileSpace != icSigRgbData)
-          mismatch =  true;
-        break;
-      case JCS_YCbCr:
-        if (profileSpace == icSigRgbData)
-          mInfo.out_color_space = JCS_RGB;
-        else
-	  // qcms doesn't support ycbcr
-          mismatch = true;
-        break;
-      case JCS_CMYK:
-      case JCS_YCCK:
-	  // qcms doesn't support cmyk
-          mismatch = true;
-        break;
-      default:
-        mState = JPEG_ERROR;
-        PostDataError();
-        PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
-               ("} (unknown colorpsace (1))"));
-        return;
+        case JCS_GRAYSCALE:
+          if (profileSpace == icSigRgbData) {
+            mInfo.out_color_space = JCS_RGB;
+          } else if (profileSpace != icSigGrayData) {
+            mismatch = true;
+          }
+          break;
+        case JCS_RGB:
+          if (profileSpace != icSigRgbData) {
+            mismatch =  true;
+          }
+          break;
+        case JCS_YCbCr:
+          if (profileSpace == icSigRgbData) {
+            mInfo.out_color_space = JCS_RGB;
+          } else {
+            // qcms doesn't support ycbcr
+            mismatch = true;
+          }
+          break;
+        case JCS_CMYK:
+        case JCS_YCCK:
+            // qcms doesn't support cmyk
+            mismatch = true;
+          break;
+        default:
+          mState = JPEG_ERROR;
+          PostDataError();
+          PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
+                 ("} (unknown colorpsace (1))"));
+          return;
       }
 
       if (!mismatch) {
         qcms_data_type type;
         switch (mInfo.out_color_space) {
-        case JCS_GRAYSCALE:
-          type = QCMS_DATA_GRAY_8;
-          break;
-        case JCS_RGB:
-          type = QCMS_DATA_RGB_8;
-          break;
-        default:
-          mState = JPEG_ERROR;
-          PostDataError();
-          PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
-                 ("} (unknown colorpsace (2))"));
-          return;
+          case JCS_GRAYSCALE:
+            type = QCMS_DATA_GRAY_8;
+            break;
+          case JCS_RGB:
+            type = QCMS_DATA_RGB_8;
+            break;
+          default:
+            mState = JPEG_ERROR;
+            PostDataError();
+            PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
+                   ("} (unknown colorpsace (2))"));
+            return;
         }
 #if 0
-        /* We don't currently support CMYK profiles. The following
-         * code dealt with lcms types. Add something like this
-         * back when we gain support for CMYK.
-         */
-        /* Adobe Photoshop writes YCCK/CMYK files with inverted data */
-        if (mInfo.out_color_space == JCS_CMYK)
+        // We don't currently support CMYK profiles. The following
+        // code dealt with lcms types. Add something like this
+        // back when we gain support for CMYK.
+
+        // Adobe Photoshop writes YCCK/CMYK files with inverted data
+        if (mInfo.out_color_space == JCS_CMYK) {
           type |= FLAVOR_SH(mInfo.saw_Adobe_marker ? 1 : 0);
+        }
 #endif
 
         if (gfxPlatform::GetCMSOutputProfile()) {
 
-          /* Calculate rendering intent. */
+          // Calculate rendering intent.
           int intent = gfxPlatform::GetRenderingIntent();
-          if (intent == -1)
-              intent = qcms_profile_get_rendering_intent(mInProfile);
+          if (intent == -1) {
+            intent = qcms_profile_get_rendering_intent(mInProfile);
+          }
 
-          /* Create the color management transform. */
+          // Create the color management transform.
           mTransform = qcms_transform_create(mInProfile,
                                           type,
                                           gfxPlatform::GetCMSOutputProfile(),
                                           QCMS_DATA_RGB_8,
                                           (qcms_intent)intent);
         }
       } else {
 #ifdef DEBUG_tor
         fprintf(stderr, "ICM profile colorspace mismatch\n");
 #endif
       }
     }
 
     if (!mTransform) {
       switch (mInfo.jpeg_color_space) {
-      case JCS_GRAYSCALE:
-      case JCS_RGB:
-      case JCS_YCbCr:
-        // if we're not color managing we can decode directly to
-        // MOZ_JCS_EXT_NATIVE_ENDIAN_XRGB
-        if (mCMSMode != eCMSMode_All) {
-            mInfo.out_color_space = MOZ_JCS_EXT_NATIVE_ENDIAN_XRGB;
-            mInfo.out_color_components = 4;
-        } else {
-            mInfo.out_color_space = JCS_RGB;
-        }
-        break;
-      case JCS_CMYK:
-      case JCS_YCCK:
-        /* libjpeg can convert from YCCK to CMYK, but not to RGB */
-        mInfo.out_color_space = JCS_CMYK;
-        break;
-      default:
-        mState = JPEG_ERROR;
-        PostDataError();
-        PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
-               ("} (unknown colorpsace (3))"));
-        return;
-        break;
+        case JCS_GRAYSCALE:
+        case JCS_RGB:
+        case JCS_YCbCr:
+          // if we're not color managing we can decode directly to
+          // MOZ_JCS_EXT_NATIVE_ENDIAN_XRGB
+          if (mCMSMode != eCMSMode_All) {
+              mInfo.out_color_space = MOZ_JCS_EXT_NATIVE_ENDIAN_XRGB;
+              mInfo.out_color_components = 4;
+          } else {
+              mInfo.out_color_space = JCS_RGB;
+          }
+          break;
+        case JCS_CMYK:
+        case JCS_YCCK:
+          // libjpeg can convert from YCCK to CMYK, but not to RGB
+          mInfo.out_color_space = JCS_CMYK;
+          break;
+        default:
+          mState = JPEG_ERROR;
+          PostDataError();
+          PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
+                 ("} (unknown colorpsace (3))"));
+          return;
+          break;
       }
     }
 
-    /*
-     * Don't allocate a giant and superfluous memory buffer
-     * when not doing a progressive decode.
-     */
-    mInfo.buffered_image = mDecodeStyle == PROGRESSIVE && jpeg_has_multiple_scans(&mInfo);
+    // Don't allocate a giant and superfluous memory buffer
+    // when not doing a progressive decode.
+    mInfo.buffered_image = mDecodeStyle == PROGRESSIVE &&
+                           jpeg_has_multiple_scans(&mInfo);
 
     if (!mImageData) {
       mState = JPEG_ERROR;
       PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
       PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
              ("} (could not initialize image frame)"));
       return;
     }
 
     PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
-           ("        JPEGDecoderAccounting: nsJPEGDecoder::Write -- created image frame with %ux%u pixels",
+           ("        JPEGDecoderAccounting: nsJPEGDecoder::"
+            "Write -- created image frame with %ux%u pixels",
             mInfo.output_width, mInfo.output_height));
 
     mState = JPEG_START_DECOMPRESS;
   }
 
-  case JPEG_START_DECOMPRESS:
-  {
-    LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- entering JPEG_START_DECOMPRESS case");
-    /* Step 4: set parameters for decompression */
+  case JPEG_START_DECOMPRESS: {
+    LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- entering"
+                            " JPEG_START_DECOMPRESS case");
+    // Step 4: set parameters for decompression
 
-    /* FIXME -- Should reset dct_method and dither mode
-     * for final pass of progressive JPEG
-     */
+    // FIXME -- Should reset dct_method and dither mode
+    // for final pass of progressive JPEG
+
     mInfo.dct_method =  JDCT_ISLOW;
     mInfo.dither_mode = JDITHER_FS;
     mInfo.do_fancy_upsampling = TRUE;
     mInfo.enable_2pass_quant = FALSE;
     mInfo.do_block_smoothing = TRUE;
 
-    /* Step 5: Start decompressor */
+    // Step 5: Start decompressor
     if (jpeg_start_decompress(&mInfo) == FALSE) {
       PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
              ("} (I/O suspension after jpeg_start_decompress())"));
-      return; /* I/O suspension */
+      return; // I/O suspension
     }
 
 
-    /* If this is a progressive JPEG ... */
-    mState = mInfo.buffered_image ? JPEG_DECOMPRESS_PROGRESSIVE : JPEG_DECOMPRESS_SEQUENTIAL;
+    // If this is a progressive JPEG ...
+    mState = mInfo.buffered_image ?
+             JPEG_DECOMPRESS_PROGRESSIVE : JPEG_DECOMPRESS_SEQUENTIAL;
   }
 
-  case JPEG_DECOMPRESS_SEQUENTIAL:
-  {
-    if (mState == JPEG_DECOMPRESS_SEQUENTIAL)
-    {
-      LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- JPEG_DECOMPRESS_SEQUENTIAL case");
-      
+  case JPEG_DECOMPRESS_SEQUENTIAL: {
+    if (mState == JPEG_DECOMPRESS_SEQUENTIAL) {
+      LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- "
+                              "JPEG_DECOMPRESS_SEQUENTIAL case");
+
       bool suspend;
       OutputScanlines(&suspend);
-      
+
       if (suspend) {
         PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
                ("} (I/O suspension after OutputScanlines() - SEQUENTIAL)"));
-        return; /* I/O suspension */
+        return; // I/O suspension
       }
-      
-      /* If we've completed image output ... */
-      NS_ASSERTION(mInfo.output_scanline == mInfo.output_height, "We didn't process all of the data!");
+
+      // If we've completed image output ...
+      NS_ASSERTION(mInfo.output_scanline == mInfo.output_height,
+                   "We didn't process all of the data!");
       mState = JPEG_DONE;
     }
   }
 
-  case JPEG_DECOMPRESS_PROGRESSIVE:
-  {
-    if (mState == JPEG_DECOMPRESS_PROGRESSIVE)
-    {
-      LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::Write -- JPEG_DECOMPRESS_PROGRESSIVE case");
+  case JPEG_DECOMPRESS_PROGRESSIVE: {
+    if (mState == JPEG_DECOMPRESS_PROGRESSIVE) {
+      LOG_SCOPE(GetJPEGLog(),
+                "nsJPEGDecoder::Write -- JPEG_DECOMPRESS_PROGRESSIVE case");
 
       int status;
       do {
         status = jpeg_consume_input(&mInfo);
       } while ((status != JPEG_SUSPENDED) &&
                (status != JPEG_REACHED_EOI));
 
       for (;;) {
         if (mInfo.output_scanline == 0) {
           int scan = mInfo.input_scan_number;
 
-          /* if we haven't displayed anything yet (output_scan_number==0)
-             and we have enough data for a complete scan, force output
-             of the last full scan */
+          // if we haven't displayed anything yet (output_scan_number==0)
+          // and we have enough data for a complete scan, force output
+          // of the last full scan
           if ((mInfo.output_scan_number == 0) &&
               (scan > 1) &&
               (status != JPEG_REACHED_EOI))
             scan--;
 
           if (!jpeg_start_output(&mInfo, scan)) {
             PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
-                   ("} (I/O suspension after jpeg_start_output() - PROGRESSIVE)"));
-            return; /* I/O suspension */
+                   ("} (I/O suspension after jpeg_start_output() -"
+                    " PROGRESSIVE)"));
+            return; // I/O suspension
           }
         }
 
-        if (mInfo.output_scanline == 0xffffff)
+        if (mInfo.output_scanline == 0xffffff) {
           mInfo.output_scanline = 0;
+        }
 
         bool suspend;
         OutputScanlines(&suspend);
 
         if (suspend) {
           if (mInfo.output_scanline == 0) {
-            /* didn't manage to read any lines - flag so we don't call
-               jpeg_start_output() multiple times for the same scan */
+            // didn't manage to read any lines - flag so we don't call
+            // jpeg_start_output() multiple times for the same scan
             mInfo.output_scanline = 0xffffff;
           }
           PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
                  ("} (I/O suspension after OutputScanlines() - PROGRESSIVE)"));
-          return; /* I/O suspension */
+          return; // I/O suspension
         }
 
-        if (mInfo.output_scanline == mInfo.output_height)
-        {
+        if (mInfo.output_scanline == mInfo.output_height) {
           if (!jpeg_finish_output(&mInfo)) {
             PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
-                   ("} (I/O suspension after jpeg_finish_output() - PROGRESSIVE)"));
-            return; /* I/O suspension */
+                   ("} (I/O suspension after jpeg_finish_output() -"
+                    " PROGRESSIVE)"));
+            return; // I/O suspension
           }
 
           if (jpeg_input_complete(&mInfo) &&
               (mInfo.input_scan_number == mInfo.output_scan_number))
             break;
 
           mInfo.output_scanline = 0;
         }
       }
 
       mState = JPEG_DONE;
     }
   }
 
-  case JPEG_DONE:
-  {
-    LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::ProcessData -- entering JPEG_DONE case");
+  case JPEG_DONE: {
+    LOG_SCOPE(GetJPEGLog(), "nsJPEGDecoder::ProcessData -- entering"
+                            " JPEG_DONE case");
 
-    /* Step 7: Finish decompression */
+    // Step 7: Finish decompression
 
     if (jpeg_finish_decompress(&mInfo) == FALSE) {
       PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
              ("} (I/O suspension after jpeg_finish_decompress() - DONE)"));
-      return; /* I/O suspension */
+      return; // I/O suspension
     }
 
     mState = JPEG_SINK_NON_JPEG_TRAILER;
 
-    /* we're done dude */
+    // we're done dude
     break;
   }
   case JPEG_SINK_NON_JPEG_TRAILER:
     PR_LOG(GetJPEGLog(), PR_LOG_DEBUG,
-           ("[this=%p] nsJPEGDecoder::ProcessData -- entering JPEG_SINK_NON_JPEG_TRAILER case\n", this));
+           ("[this=%p] nsJPEGDecoder::ProcessData -- entering"
+            " JPEG_SINK_NON_JPEG_TRAILER case\n", this));
 
     break;
 
   case JPEG_ERROR:
-    NS_ABORT_IF_FALSE(0, "Should always return immediately after error and not re-enter decoder");
+    NS_ABORT_IF_FALSE(0, "Should always return immediately after error and"
+                         " not re-enter decoder");
   }
 
   PR_LOG(GetJPEGDecoderAccountingLog(), PR_LOG_DEBUG,
          ("} (end of function)"));
   return;
 }
 
 Orientation
 nsJPEGDecoder::ReadOrientationFromEXIF()
 {
   jpeg_saved_marker_ptr marker;
 
   // Locate the APP1 marker, where EXIF data is stored, in the marker list.
   for (marker = mInfo.marker_list ; marker != nullptr ; marker = marker->next) {
-    if (marker->marker == JPEG_APP0 + 1) 
+    if (marker->marker == JPEG_APP0 + 1) {
       break;
+    }
   }
 
   // If we're at the end of the list, there's no EXIF data.
-  if (!marker)
+  if (!marker) {
     return Orientation();
+  }
 
   // Extract the orientation information.
   EXIFData exif = EXIFParser::Parse(marker->data,
                                     static_cast<uint32_t>(marker->data_length));
   return exif.orientation;
 }
 
 void
@@ -577,133 +596,137 @@ nsJPEGDecoder::NotifyDone()
 void
 nsJPEGDecoder::OutputScanlines(bool* suspend)
 {
   *suspend = false;
 
   const uint32_t top = mInfo.output_scanline;
 
   while ((mInfo.output_scanline < mInfo.output_height)) {
-      /* Use the Cairo image buffer as scanline buffer */
-      uint32_t *imageRow = ((uint32_t*)mImageData) +
+      // Use the Cairo image buffer as scanline buffer
+      uint32_t* imageRow = ((uint32_t*)mImageData) +
                            (mInfo.output_scanline * mInfo.output_width);
 
       if (mInfo.out_color_space == MOZ_JCS_EXT_NATIVE_ENDIAN_XRGB) {
-        /* Special case: scanline will be directly converted into packed ARGB */
+        // Special case: scanline will be directly converted into packed ARGB
         if (jpeg_read_scanlines(&mInfo, (JSAMPARRAY)&imageRow, 1) != 1) {
-          *suspend = true; /* suspend */
+          *suspend = true; // suspend
           break;
         }
-        continue; /* all done for this row! */
+        continue; // all done for this row!
       }
 
       JSAMPROW sampleRow = (JSAMPROW)imageRow;
       if (mInfo.output_components == 3) {
-        /* Put the pixels at end of row to enable in-place expansion */
+        // Put the pixels at end of row to enable in-place expansion
         sampleRow += mInfo.output_width;
       }
 
-      /* Request one scanline.  Returns 0 or 1 scanlines. */    
+      // Request one scanline.  Returns 0 or 1 scanlines.
       if (jpeg_read_scanlines(&mInfo, &sampleRow, 1) != 1) {
-        *suspend = true; /* suspend */
+        *suspend = true; // suspend
         break;
       }
 
       if (mTransform) {
         JSAMPROW source = sampleRow;
         if (mInfo.out_color_space == JCS_GRAYSCALE) {
-          /* Convert from the 1byte grey pixels at begin of row 
-             to the 3byte RGB byte pixels at 'end' of row */
+          // Convert from the 1byte grey pixels at begin of row
+          // to the 3byte RGB byte pixels at 'end' of row
           sampleRow += mInfo.output_width;
         }
         qcms_transform_data(mTransform, source, sampleRow, mInfo.output_width);
-        /* Move 3byte RGB data to end of row */
+        // Move 3byte RGB data to end of row
         if (mInfo.out_color_space == JCS_CMYK) {
           memmove(sampleRow + mInfo.output_width,
                   sampleRow,
                   3 * mInfo.output_width);
           sampleRow += mInfo.output_width;
         }
       } else {
         if (mInfo.out_color_space == JCS_CMYK) {
-          /* Convert from CMYK to RGB */
-          /* We cannot convert directly to Cairo, as the CMSRGBTransform may wants to do a RGB transform... */
-          /* Would be better to have platform CMSenabled transformation from CMYK to (A)RGB... */
+          // Convert from CMYK to RGB
+          // We cannot convert directly to Cairo, as the CMSRGBTransform
+          // may wants to do a RGB transform...
+          // Would be better to have platform CMSenabled transformation
+          // from CMYK to (A)RGB...
           cmyk_convert_rgb((JSAMPROW)imageRow, mInfo.output_width);
           sampleRow += mInfo.output_width;
         }
         if (mCMSMode == eCMSMode_All) {
-          /* No embedded ICC profile - treat as sRGB */
-          qcms_transform *transform = gfxPlatform::GetCMSRGBTransform();
+          // No embedded ICC profile - treat as sRGB
+          qcms_transform* transform = gfxPlatform::GetCMSRGBTransform();
           if (transform) {
-            qcms_transform_data(transform, sampleRow, sampleRow, mInfo.output_width);
+            qcms_transform_data(transform, sampleRow, sampleRow,
+                                mInfo.output_width);
           }
         }
       }
 
       // counter for while() loops below
       uint32_t idx = mInfo.output_width;
 
       // copy as bytes until source pointer is 32-bit-aligned
       for (; (NS_PTR_TO_UINT32(sampleRow) & 0x3) && idx; --idx) {
-        *imageRow++ = gfxPackedPixel(0xFF, sampleRow[0], sampleRow[1], sampleRow[2]);
+        *imageRow++ = gfxPackedPixel(0xFF, sampleRow[0], sampleRow[1],
+                                     sampleRow[2]);
         sampleRow += 3;
       }
 
       // copy pixels in blocks of 4
       while (idx >= 4) {
         GFX_BLOCK_RGB_TO_FRGB(sampleRow, imageRow);
         idx       -=  4;
         sampleRow += 12;
         imageRow  +=  4;
       }
 
       // copy remaining pixel(s)
       while (idx--) {
         // 32-bit read of final pixel will exceed buffer, so read bytes
-        *imageRow++ = gfxPackedPixel(0xFF, sampleRow[0], sampleRow[1], sampleRow[2]);
+        *imageRow++ = gfxPackedPixel(0xFF, sampleRow[0], sampleRow[1],
+                                     sampleRow[2]);
         sampleRow += 3;
       }
   }
 
   if (top != mInfo.output_scanline) {
       nsIntRect r(0, top, mInfo.output_width, mInfo.output_scanline-top);
       PostInvalidation(r);
   }
 
 }
 
 
-/* Override the standard error method in the IJG JPEG decoder code. */
+// Override the standard error method in the IJG JPEG decoder code.
 METHODDEF(void)
 my_error_exit (j_common_ptr cinfo)
 {
-  decoder_error_mgr *err = (decoder_error_mgr *) cinfo->err;
+  decoder_error_mgr* err = (decoder_error_mgr*) cinfo->err;
 
-  /* Convert error to a browser error code */
+  // Convert error to a browser error code
   nsresult error_code = err->pub.msg_code == JERR_OUT_OF_MEMORY
                       ? NS_ERROR_OUT_OF_MEMORY
                       : NS_ERROR_FAILURE;
 
 #ifdef DEBUG
   char buffer[JMSG_LENGTH_MAX];
 
-  /* Create the message */
+  // Create the message
   (*err->pub.format_message) (cinfo, buffer);
 
   fprintf(stderr, "JPEG decoding error:\n%s\n", buffer);
 #endif
 
-  /* Return control to the setjmp point.  We pass an nsresult masquerading as
-   * an int, which works because the setjmp() caller casts it back. */
+  // Return control to the setjmp point.  We pass an nsresult masquerading as
+  // an int, which works because the setjmp() caller casts it back.
   longjmp(err->setjmp_buffer, static_cast<int>(error_code));
 }
 
-/******************************************************************************/
-/*-----------------------------------------------------------------------------
+/*******************************************************************************
  * This is the callback routine from the IJG JPEG library used to supply new
  * data to the decompressor when its input buffer is exhausted.  It juggles
  * multiple buffers in an attempt to avoid unnecessary copying of input data.
  *
  * (A simpler scheme is possible: It's much easier to use only a single
  * buffer; when fill_input_buffer() is called, move any unconsumed data
  * (beyond the current pointer/count) down to the beginning of this buffer and
  * then load new data into the remaining buffer space.  This approach requires
@@ -720,25 +743,24 @@ my_error_exit (j_common_ptr cinfo)
  * next_input_byte & bytes_in_buffer indicate where the restart point will be
  * if the current call returns FALSE.  Data beyond this point must be
  * rescanned after resumption, so it must be preserved in case the decompressor
  * decides to backtrack.
  *
  * Returns:
  *  TRUE if additional data is available, FALSE if no data present and
  *   the JPEG library should therefore suspend processing of input stream
- *---------------------------------------------------------------------------*/
+ ******************************************************************************/
 
 /******************************************************************************/
 /* data source manager method                                                 */
 /******************************************************************************/
 
-
 /******************************************************************************/
-/* data source manager method 
+/* data source manager method
         Initialize source.  This is called by jpeg_read_header() before any
         data is actually read.  May leave
         bytes_in_buffer set to 0 (in which case a fill_input_buffer() call
         will occur immediately).
 */
 METHODDEF(void)
 init_source (j_decompress_ptr jd)
 {
@@ -753,31 +775,29 @@ init_source (j_decompress_ptr jd)
         it may be possible to optimize away the reading of the skipped data,
         but it's not clear that being smart is worth much trouble; large
         skips are uncommon.  bytes_in_buffer may be zero on return.
         A zero or negative skip count should be treated as a no-op.
 */
 METHODDEF(void)
 skip_input_data (j_decompress_ptr jd, long num_bytes)
 {
-  struct jpeg_source_mgr *src = jd->src;
-  nsJPEGDecoder *decoder = (nsJPEGDecoder *)(jd->client_data);
+  struct jpeg_source_mgr* src = jd->src;
+  nsJPEGDecoder* decoder = (nsJPEGDecoder*)(jd->client_data);
 
   if (num_bytes > (long)src->bytes_in_buffer) {
-    /*
-     * Can't skip it all right now until we get more data from
-     * network stream. Set things up so that fill_input_buffer
-     * will skip remaining amount.
-     */
+    // Can't skip it all right now until we get more data from
+    // network stream. Set things up so that fill_input_buffer
+    // will skip remaining amount.
     decoder->mBytesToSkip = (size_t)num_bytes - src->bytes_in_buffer;
     src->next_input_byte += src->bytes_in_buffer;
     src->bytes_in_buffer = 0;
 
   } else {
-    /* Simple case. Just advance buffer pointer */
+    // Simple case. Just advance buffer pointer
 
     src->bytes_in_buffer -= (size_t)num_bytes;
     src->next_input_byte += num_bytes;
   }
 }
 
 
 /******************************************************************************/
@@ -790,127 +810,130 @@ skip_input_data (j_decompress_ptr jd, lo
         It is not necessary to fill the buffer entirely, only to obtain at
         least one more byte.  bytes_in_buffer MUST be set to a positive value
         if TRUE is returned.  A FALSE return should only be used when I/O
         suspension is desired.
 */
 METHODDEF(boolean)
 fill_input_buffer (j_decompress_ptr jd)
 {
-  struct jpeg_source_mgr *src = jd->src;
-  nsJPEGDecoder *decoder = (nsJPEGDecoder *)(jd->client_data);
+  struct jpeg_source_mgr* src = jd->src;
+  nsJPEGDecoder* decoder = (nsJPEGDecoder*)(jd->client_data);
 
   if (decoder->mReading) {
-    const JOCTET *new_buffer = decoder->mSegment;
+    const JOCTET* new_buffer = decoder->mSegment;
     uint32_t new_buflen = decoder->mSegmentLen;
-  
-    if (!new_buffer || new_buflen == 0)
-      return false; /* suspend */
+
+    if (!new_buffer || new_buflen == 0) {
+      return false; // suspend
+    }
 
     decoder->mSegmentLen = 0;
 
     if (decoder->mBytesToSkip) {
       if (decoder->mBytesToSkip < new_buflen) {
-        /* All done skipping bytes; Return what's left. */
+        // All done skipping bytes; Return what's left.
         new_buffer += decoder->mBytesToSkip;
         new_buflen -= decoder->mBytesToSkip;
         decoder->mBytesToSkip = 0;
       } else {
-        /* Still need to skip some more data in the future */
+        // Still need to skip some more data in the future
         decoder->mBytesToSkip -= (size_t)new_buflen;
-        return false; /* suspend */
+        return false; // suspend
       }
     }
 
-      decoder->mBackBufferUnreadLen = src->bytes_in_buffer;
+    decoder->mBackBufferUnreadLen = src->bytes_in_buffer;
 
     src->next_input_byte = new_buffer;
     src->bytes_in_buffer = (size_t)new_buflen;
     decoder->mReading = false;
 
     return true;
   }
 
   if (src->next_input_byte != decoder->mSegment) {
-    /* Backtrack data has been permanently consumed. */
+    // Backtrack data has been permanently consumed.
     decoder->mBackBufferUnreadLen = 0;
     decoder->mBackBufferLen = 0;
   }
 
-  /* Save remainder of netlib buffer in backtrack buffer */
-  const uint32_t new_backtrack_buflen = src->bytes_in_buffer + decoder->mBackBufferLen;
- 
-  /* Make sure backtrack buffer is big enough to hold new data. */
+  // Save remainder of netlib buffer in backtrack buffer
+  const uint32_t new_backtrack_buflen = src->bytes_in_buffer +
+                                        decoder->mBackBufferLen;
+
+  // Make sure backtrack buffer is big enough to hold new data.
   if (decoder->mBackBufferSize < new_backtrack_buflen) {
-    /* Check for malformed MARKER segment lengths, before allocating space for it */
+    // Check for malformed MARKER segment lengths, before allocating space
+    // for it
     if (new_backtrack_buflen > MAX_JPEG_MARKER_LENGTH) {
       my_error_exit((j_common_ptr)(&decoder->mInfo));
     }
 
-    /* Round up to multiple of 256 bytes. */
+    // Round up to multiple of 256 bytes.
     const size_t roundup_buflen = ((new_backtrack_buflen + 255) >> 8) << 8;
-    JOCTET *buf = (JOCTET *)PR_REALLOC(decoder->mBackBuffer, roundup_buflen);
-    /* Check for OOM */
+    JOCTET* buf = (JOCTET*)PR_REALLOC(decoder->mBackBuffer, roundup_buflen);
+    // Check for OOM
     if (!buf) {
       decoder->mInfo.err->msg_code = JERR_OUT_OF_MEMORY;
       my_error_exit((j_common_ptr)(&decoder->mInfo));
     }
     decoder->mBackBuffer = buf;
     decoder->mBackBufferSize = roundup_buflen;
   }
 
-  /* Copy remainder of netlib segment into backtrack buffer. */
+  // Copy remainder of netlib segment into backtrack buffer.
   memmove(decoder->mBackBuffer + decoder->mBackBufferLen,
           src->next_input_byte,
           src->bytes_in_buffer);
 
-  /* Point to start of data to be rescanned. */
-  src->next_input_byte = decoder->mBackBuffer + decoder->mBackBufferLen - decoder->mBackBufferUnreadLen;
+  // Point to start of data to be rescanned.
+  src->next_input_byte = decoder->mBackBuffer + decoder->mBackBufferLen -
+                         decoder->mBackBufferUnreadLen;
   src->bytes_in_buffer += decoder->mBackBufferUnreadLen;
   decoder->mBackBufferLen = (size_t)new_backtrack_buflen;
   decoder->mReading = true;
 
   return false;
 }
 
 /******************************************************************************/
 /* data source manager method */
 /*
  * Terminate source --- called by jpeg_finish_decompress() after all
- * data has been read to clean up JPEG source manager. NOT called by 
+ * data has been read to clean up JPEG source manager. NOT called by
  * jpeg_abort() or jpeg_destroy().
  */
 METHODDEF(void)
 term_source (j_decompress_ptr jd)
 {
-  nsJPEGDecoder *decoder = (nsJPEGDecoder *)(jd->client_data);
+  nsJPEGDecoder* decoder = (nsJPEGDecoder*)(jd->client_data);
 
   // This function shouldn't be called if we ran into an error we didn't
   // recover from.
   NS_ABORT_IF_FALSE(decoder->mState != JPEG_ERROR,
                     "Calling term_source on a JPEG with mState == JPEG_ERROR!");
 
   // Notify using a helper method to get around protectedness issues.
   decoder->NotifyDone();
 }
 
 } // namespace image
 } // namespace mozilla
 
 
-/**************** Inverted CMYK -> RGB conversion **************/
-/*
- * Input is (Inverted) CMYK stored as 4 bytes per pixel.
- * Output is RGB stored as 3 bytes per pixel.
- * @param row Points to row buffer containing the CMYK bytes for each pixel in the row.
- * @param width Number of pixels in the row.
- */
+///*************** Inverted CMYK -> RGB conversion *************************
+/// Input is (Inverted) CMYK stored as 4 bytes per pixel.
+/// Output is RGB stored as 3 bytes per pixel.
+/// @param row Points to row buffer containing the CMYK bytes for each pixel
+/// in the row.
+/// @param width Number of pixels in the row.
 static void cmyk_convert_rgb(JSAMPROW row, JDIMENSION width)
 {
-  /* Work from end to front to shrink from 4 bytes per pixel to 3 */
+  // Work from end to front to shrink from 4 bytes per pixel to 3
   JSAMPROW in = row + width*4;
   JSAMPROW out = in;
 
   for (uint32_t i = width; i > 0; i--) {
     in -= 4;
     out -= 3;
 
     // Source is 'Inverted CMYK', output is RGB.
@@ -925,17 +948,17 @@ static void cmyk_convert_rgb(JSAMPROW ro
     // From Inverted CMYK to CMY is thus:
     // C = ( (1-iC) * (1 - (1-iK)) + (1-iK) ) => 1 - iC*iK
     // Same for M and Y
 
     // Convert from CMY (0..1) to RGB (0..1)
     // R = 1 - C => 1 - (1 - iC*iK) => iC*iK
     // G = 1 - M => 1 - (1 - iM*iK) => iM*iK
     // B = 1 - Y => 1 - (1 - iY*iK) => iY*iK
-  
+
     // Convert from Inverted CMYK (0..255) to RGB (0..255)
     const uint32_t iC = in[0];
     const uint32_t iM = in[1];
     const uint32_t iY = in[2];
     const uint32_t iK = in[3];
     out[0] = iC*iK/255;   // Red
     out[1] = iM*iK/255;   // Green
     out[2] = iY*iK/255;   // Blue
--- a/image/decoders/nsJPEGDecoder.h
+++ b/image/decoders/nsJPEGDecoder.h
@@ -1,21 +1,21 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef nsJPEGDecoder_h__
-#define nsJPEGDecoder_h__
+#ifndef nsJPEGDecoder_h
+#define nsJPEGDecoder_h
 
 #include "RasterImage.h"
-/* On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32.
- * But the jpeg decoder has its own definition of INT32. To avoid build issues,
- * we need to undefine the version from 'windows.h'. */
+// On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32.
+// But the jpeg decoder has its own definition of INT32. To avoid build issues,
+// we need to undefine the version from 'windows.h'.
 #undef INT32
 
 #include "Decoder.h"
 
 #include "nsAutoPtr.h"
 
 #include "nsIInputStream.h"
 #include "nsIPipe.h"
@@ -26,42 +26,43 @@ extern "C" {
 }
 
 #include <setjmp.h>
 
 namespace mozilla {
 namespace image {
 
 typedef struct {
-    struct jpeg_error_mgr pub;  /* "public" fields for IJG library*/
-    jmp_buf setjmp_buffer;      /* For handling catastropic errors */
+    struct jpeg_error_mgr pub;  // "public" fields for IJG library
+    jmp_buf setjmp_buffer;      // For handling catastropic errors
 } decoder_error_mgr;
 
 typedef enum {
-    JPEG_HEADER,                          /* Reading JFIF headers */
+    JPEG_HEADER,                          // Reading JFIF headers
     JPEG_START_DECOMPRESS,
-    JPEG_DECOMPRESS_PROGRESSIVE,          /* Output progressive pixels */
-    JPEG_DECOMPRESS_SEQUENTIAL,           /* Output sequential pixels */
+    JPEG_DECOMPRESS_PROGRESSIVE,          // Output progressive pixels
+    JPEG_DECOMPRESS_SEQUENTIAL,           // Output sequential pixels
     JPEG_DONE,
-    JPEG_SINK_NON_JPEG_TRAILER,          /* Some image files have a */
-                                         /* non-JPEG trailer */
-    JPEG_ERROR    
+    JPEG_SINK_NON_JPEG_TRAILER,          // Some image files have a
+                                         // non-JPEG trailer
+    JPEG_ERROR
 } jstate;
 
 class RasterImage;
 struct Orientation;
 
 class nsJPEGDecoder : public Decoder
 {
 public:
-  nsJPEGDecoder(RasterImage &aImage, Decoder::DecodeStyle aDecodeStyle);
+  nsJPEGDecoder(RasterImage& aImage, Decoder::DecodeStyle aDecodeStyle);
   virtual ~nsJPEGDecoder();
 
   virtual void InitInternal();
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
+  virtual void WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy aStrategy) MOZ_OVERRIDE;
   virtual void FinishInternal();
 
   virtual Telemetry::ID SpeedHistogram();
   void NotifyDone();
 
 protected:
   Orientation ReadOrientationFromEXIF();
   void OutputScanlines(bool* suspend);
@@ -69,33 +70,33 @@ protected:
 public:
   struct jpeg_decompress_struct mInfo;
   struct jpeg_source_mgr mSourceMgr;
   decoder_error_mgr mErr;
   jstate mState;
 
   uint32_t mBytesToSkip;
 
-  const JOCTET *mSegment;   // The current segment we are decoding from
+  const JOCTET* mSegment;   // The current segment we are decoding from
   uint32_t mSegmentLen;     // amount of data in mSegment
 
-  JOCTET *mBackBuffer;
+  JOCTET* mBackBuffer;
   uint32_t mBackBufferLen; // Offset of end of active backtrack data
   uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with
   uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer
 
-  JOCTET  *mProfile;
+  JOCTET * mProfile;
   uint32_t mProfileLength;
 
-  qcms_profile *mInProfile;
-  qcms_transform *mTransform;
+  qcms_profile* mInProfile;
+  qcms_transform* mTransform;
 
   bool mReading;
 
   const Decoder::DecodeStyle mDecodeStyle;
 
   uint32_t mCMSMode;
 };
 
 } // namespace image
 } // namespace mozilla
 
-#endif // nsJPEGDecoder_h__
+#endif // nsJPEGDecoder_h
--- a/image/decoders/nsPNGDecoder.cpp
+++ b/image/decoders/nsPNGDecoder.cpp
@@ -17,31 +17,33 @@
 #include "RasterImage.h"
 
 #include <algorithm>
 
 namespace mozilla {
 namespace image {
 
 #ifdef PR_LOGGING
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetPNGLog()
 {
-  static PRLogModuleInfo *sPNGLog;
-  if (!sPNGLog)
+  static PRLogModuleInfo* sPNGLog;
+  if (!sPNGLog) {
     sPNGLog = PR_NewLogModule("PNGDecoder");
+  }
   return sPNGLog;
 }
 
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetPNGDecoderAccountingLog()
 {
-  static PRLogModuleInfo *sPNGDecoderAccountingLog;
-  if (!sPNGDecoderAccountingLog)
+  static PRLogModuleInfo* sPNGDecoderAccountingLog;
+  if (!sPNGDecoderAccountingLog) {
     sPNGDecoderAccountingLog = PR_NewLogModule("PNGDecoderAccounting");
+  }
   return sPNGDecoderAccountingLog;
 }
 #endif
 
 // Limit image dimensions (bug #251381, #591822, and #967656)
 #ifndef MOZ_PNG_MAX_DIMENSION
 #  define MOZ_PNG_MAX_DIMENSION 32767
 #endif
@@ -50,17 +52,17 @@ GetPNGDecoderAccountingLog()
 #define WIDTH_OFFSET 16
 #define HEIGHT_OFFSET (WIDTH_OFFSET + 4)
 #define BYTES_NEEDED_FOR_DIMENSIONS (HEIGHT_OFFSET + 4)
 
 nsPNGDecoder::AnimFrameInfo::AnimFrameInfo()
  : mDispose(FrameBlender::kDisposeKeep)
  , mBlend(FrameBlender::kBlendOver)
  , mTimeout(0)
-{}
+{ }
 
 #ifdef PNG_APNG_SUPPORTED
 nsPNGDecoder::AnimFrameInfo::AnimFrameInfo(png_structp aPNG, png_infop aInfo)
  : mDispose(FrameBlender::kDisposeKeep)
  , mBlend(FrameBlender::kBlendOver)
  , mTimeout(0)
 {
   png_uint_16 delay_num, delay_den;
@@ -70,18 +72,19 @@ nsPNGDecoder::AnimFrameInfo::AnimFrameIn
   delay_num = png_get_next_frame_delay_num(aPNG, aInfo);
   delay_den = png_get_next_frame_delay_den(aPNG, aInfo);
   dispose_op = png_get_next_frame_dispose_op(aPNG, aInfo);
   blend_op = png_get_next_frame_blend_op(aPNG, aInfo);
 
   if (delay_num == 0) {
     mTimeout = 0; // SetFrameTimeout() will set to a minimum
   } else {
-    if (delay_den == 0)
+    if (delay_den == 0) {
       delay_den = 100; // so says the APNG spec
+    }
 
     // Need to cast delay_num to float to have a proper division and
     // the result to int to avoid compiler warning
     mTimeout = static_cast<int32_t>(static_cast<double>(delay_num) *
                                     1000 / delay_den);
   }
 
   if (dispose_op == PNG_DISPOSE_OP_PREVIOUS) {
@@ -99,42 +102,46 @@ nsPNGDecoder::AnimFrameInfo::AnimFrameIn
   }
 }
 #endif
 
 // First 8 bytes of a PNG file
 const uint8_t
 nsPNGDecoder::pngSignatureBytes[] = { 137, 80, 78, 71, 13, 10, 26, 10 };
 
-nsPNGDecoder::nsPNGDecoder(RasterImage &aImage)
+nsPNGDecoder::nsPNGDecoder(RasterImage& aImage)
  : Decoder(aImage),
    mPNG(nullptr), mInfo(nullptr),
    mCMSLine(nullptr), interlacebuf(nullptr),
    mInProfile(nullptr), mTransform(nullptr),
    mHeaderBytesRead(0), mCMSMode(0),
    mChannels(0), mFrameIsHidden(false),
    mDisablePremultipliedAlpha(false),
    mNumFrames(0)
 {
 }
 
 nsPNGDecoder::~nsPNGDecoder()
 {
-  if (mPNG)
+  if (mPNG) {
     png_destroy_read_struct(&mPNG, mInfo ? &mInfo : nullptr, nullptr);
-  if (mCMSLine)
+  }
+  if (mCMSLine) {
     nsMemory::Free(mCMSLine);
-  if (interlacebuf)
+  }
+  if (interlacebuf) {
     nsMemory::Free(interlacebuf);
+  }
   if (mInProfile) {
     qcms_profile_release(mInProfile);
 
     // mTransform belongs to us only if mInProfile is non-null
-    if (mTransform)
+    if (mTransform) {
       qcms_transform_release(mTransform);
+    }
   }
 }
 
 // CreateFrame() is used for both simple and animated images
 void nsPNGDecoder::CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
                                int32_t width, int32_t height,
                                gfx::SurfaceFormat format)
 {
@@ -164,28 +171,31 @@ void nsPNGDecoder::CreateFrame(png_uint_
 #ifdef PNG_APNG_SUPPORTED
   if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL)) {
     mAnimInfo = AnimFrameInfo(mPNG, mInfo);
   }
 #endif
 }
 
 // set timeout and frame disposal method for the current frame
-void nsPNGDecoder::EndImageFrame()
+void
+nsPNGDecoder::EndImageFrame()
 {
-  if (mFrameIsHidden)
+  if (mFrameIsHidden) {
     return;
+  }
 
   mNumFrames++;
 
   FrameBlender::FrameAlpha alpha;
-  if (mFrameHasNoAlpha)
+  if (mFrameHasNoAlpha) {
     alpha = FrameBlender::kFrameOpaque;
-  else
+  } else {
     alpha = FrameBlender::kFrameHasAlpha;
+  }
 
 #ifdef PNG_APNG_SUPPORTED
   uint32_t numFrames = GetFrameCount();
 
   // We can't use mPNG->num_frames_read as it may be one ahead.
   if (numFrames > 1) {
     PostInvalidation(mFrameRect);
   }
@@ -199,18 +209,19 @@ void
 nsPNGDecoder::InitInternal()
 {
   // For size decodes, we don't need to initialize the png decoder
   if (IsSizeDecode()) {
     return;
   }
 
   mCMSMode = gfxPlatform::GetCMSMode();
-  if ((mDecodeFlags & DECODER_NO_COLORSPACE_CONVERSION) != 0)
+  if ((mDecodeFlags & DECODER_NO_COLORSPACE_CONVERSION) != 0) {
     mCMSMode = eCMSMode_Off;
+  }
   mDisablePremultipliedAlpha = (mDecodeFlags & DECODER_NO_PREMULTIPLY_ALPHA)
                                 != 0;
 
 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
   static png_byte color_chunks[]=
        { 99,  72,  82,  77, '\0',   // cHRM
         105,  67,  67,  80, '\0'};  // iCCP
   static png_byte unused_chunks[]=
@@ -245,26 +256,28 @@ nsPNGDecoder::InitInternal()
   if (!mInfo) {
     PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
     png_destroy_read_struct(&mPNG, nullptr, nullptr);
     return;
   }
 
 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
   // Ignore unused chunks
-  if (mCMSMode == eCMSMode_Off)
+  if (mCMSMode == eCMSMode_Off) {
     png_set_keep_unknown_chunks(mPNG, 1, color_chunks, 2);
+  }
 
   png_set_keep_unknown_chunks(mPNG, 1, unused_chunks,
                               (int)sizeof(unused_chunks)/5);
 #endif
 
 #ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
-  if (mCMSMode != eCMSMode_Off)
+  if (mCMSMode != eCMSMode_Off) {
     png_set_chunk_malloc_max(mPNG, 4000000L);
+  }
 #endif
 
 #ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
 #ifndef PR_LOGGING
   // Disallow palette-index checking, for speed; we would ignore the warning
   // anyhow unless we have defined PR_LOGGING.  This feature was added at
   // libpng version 1.5.10 and is disabled in the embedded libpng but enabled
   // by default in the system libpng.  This call also disables it in the
@@ -283,31 +296,32 @@ nsPNGDecoder::InitInternal()
   png_set_progressive_read_fn(mPNG, static_cast<png_voidp>(this),
                               nsPNGDecoder::info_callback,
                               nsPNGDecoder::row_callback,
                               nsPNGDecoder::end_callback);
 
 }
 
 void
-nsPNGDecoder::WriteInternal(const char *aBuffer, uint32_t aCount,
+nsPNGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount,
                             DecodeStrategy)
 {
   NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
 
   // If we only want width/height, we don't need to go through libpng
   if (IsSizeDecode()) {
 
     // Are we done?
-    if (mHeaderBytesRead == BYTES_NEEDED_FOR_DIMENSIONS)
+    if (mHeaderBytesRead == BYTES_NEEDED_FOR_DIMENSIONS) {
       return;
+    }
 
     // Scan the header for the width and height bytes
     uint32_t pos = 0;
-    const uint8_t *bptr = (uint8_t *)aBuffer;
+    const uint8_t* bptr = (uint8_t*)aBuffer;
 
     while (pos < aCount && mHeaderBytesRead < BYTES_NEEDED_FOR_DIMENSIONS) {
       // Verify the signature bytes
       if (mHeaderBytesRead < sizeof(pngSignatureBytes)) {
         if (bptr[pos] != nsPNGDecoder::pngSignatureBytes[mHeaderBytesRead]) {
           PostDataError();
           return;
         }
@@ -333,35 +347,35 @@ nsPNGDecoder::WriteInternal(const char *
       if ((width > MOZ_PNG_MAX_DIMENSION) || (height > MOZ_PNG_MAX_DIMENSION)) {
         PostDataError();
         return;
       }
 
       // Post our size to the superclass
       PostSize(width, height);
     }
-  }
 
   // Otherwise, we're doing a standard decode
-  else {
+  } else {
 
     // libpng uses setjmp/longjmp for error handling - set the buffer
     if (setjmp(png_jmpbuf(mPNG))) {
 
       // We might not really know what caused the error, but it makes more
       // sense to blame the data.
-      if (!HasError())
+      if (!HasError()) {
         PostDataError();
+      }
 
       png_destroy_read_struct(&mPNG, &mInfo, nullptr);
       return;
     }
 
     // Pass the data off to libpng
-    png_process_data(mPNG, mInfo, (unsigned char *)aBuffer, aCount);
+    png_process_data(mPNG, mInfo, (unsigned char*)aBuffer, aCount);
 
   }
 }
 
 // Sets up gamma pre-correction in libpng before our callback gets called.
 // We need to do this if we don't end up with a CMS profile.
 static void
 PNGDoGammaCorrection(png_structp png_ptr, png_infop info_ptr)
@@ -369,53 +383,54 @@ PNGDoGammaCorrection(png_structp png_ptr
   double aGamma;
 
   if (png_get_gAMA(png_ptr, info_ptr, &aGamma)) {
     if ((aGamma <= 0.0) || (aGamma > 21474.83)) {
       aGamma = 0.45455;
       png_set_gAMA(png_ptr, info_ptr, aGamma);
     }
     png_set_gamma(png_ptr, 2.2, aGamma);
+  } else {
+    png_set_gamma(png_ptr, 2.2, 0.45455);
   }
-  else
-    png_set_gamma(png_ptr, 2.2, 0.45455);
-
 }
 
 // Adapted from http://www.littlecms.com/pngchrm.c example code
-static qcms_profile *
+static qcms_profile*
 PNGGetColorProfile(png_structp png_ptr, png_infop info_ptr,
-                   int color_type, qcms_data_type *inType, uint32_t *intent)
+                   int color_type, qcms_data_type* inType, uint32_t* intent)
 {
-  qcms_profile *profile = nullptr;
+  qcms_profile* profile = nullptr;
   *intent = QCMS_INTENT_PERCEPTUAL; // Our default
 
   // First try to see if iCCP chunk is present
   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_iCCP)) {
     png_uint_32 profileLen;
     png_bytep profileData;
     png_charp profileName;
     int compression;
 
     png_get_iCCP(png_ptr, info_ptr, &profileName, &compression,
                  &profileData, &profileLen);
 
-    profile = qcms_profile_from_memory((char *)profileData, profileLen);
+    profile = qcms_profile_from_memory((char*)profileData, profileLen);
     if (profile) {
       uint32_t profileSpace = qcms_profile_get_color_space(profile);
 
       bool mismatch = false;
       if (color_type & PNG_COLOR_MASK_COLOR) {
-        if (profileSpace != icSigRgbData)
+        if (profileSpace != icSigRgbData) {
           mismatch = true;
+        }
       } else {
-        if (profileSpace == icSigRgbData)
+        if (profileSpace == icSigRgbData) {
           png_set_gray_to_rgb(png_ptr);
-        else if (profileSpace != icSigGrayData)
+        } else if (profileSpace != icSigGrayData) {
           mismatch = true;
+        }
       }
 
       if (mismatch) {
         qcms_profile_release(profile);
         profile = nullptr;
       } else {
         *intent = qcms_profile_get_rendering_intent(profile);
       }
@@ -455,33 +470,36 @@ PNGGetColorProfile(png_structp png_ptr, 
 
     double gammaOfFile;
 
     png_get_gAMA(png_ptr, info_ptr, &gammaOfFile);
 
     profile = qcms_profile_create_rgb_with_gamma(whitePoint, primaries,
                                                  1.0/gammaOfFile);
 
-    if (profile)
+    if (profile) {
       png_set_gray_to_rgb(png_ptr);
+    }
   }
 
   if (profile) {
     uint32_t profileSpace = qcms_profile_get_color_space(profile);
     if (profileSpace == icSigGrayData) {
-      if (color_type & PNG_COLOR_MASK_ALPHA)
+      if (color_type & PNG_COLOR_MASK_ALPHA) {
         *inType = QCMS_DATA_GRAYA_8;
-      else
+      } else {
         *inType = QCMS_DATA_GRAY_8;
+      }
     } else {
       if (color_type & PNG_COLOR_MASK_ALPHA ||
-          png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
+          png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
         *inType = QCMS_DATA_RGBA_8;
-      else
+      } else {
         *inType = QCMS_DATA_RGB_8;
+      }
     }
   }
 
   return profile;
 }
 
 void
 nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr)
@@ -489,101 +507,108 @@ nsPNGDecoder::info_callback(png_structp 
 //  int number_passes;   NOT USED
   png_uint_32 width, height;
   int bit_depth, color_type, interlace_type, compression_type, filter_type;
   unsigned int channels;
 
   png_bytep trans = nullptr;
   int num_trans = 0;
 
-  nsPNGDecoder *decoder =
+  nsPNGDecoder* decoder =
                static_cast<nsPNGDecoder*>(png_get_progressive_ptr(png_ptr));
 
   // Always decode to 24-bit RGB or 32-bit RGBA
   png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
                &interlace_type, &compression_type, &filter_type);
 
   // Are we too big?
-  if (width > MOZ_PNG_MAX_DIMENSION || height > MOZ_PNG_MAX_DIMENSION)
+  if (width > MOZ_PNG_MAX_DIMENSION || height > MOZ_PNG_MAX_DIMENSION) {
     png_longjmp(decoder->mPNG, 1);
+  }
 
   // Post our size to the superclass
   decoder->PostSize(width, height);
   if (decoder->HasError()) {
     // Setting the size led to an error.
     png_longjmp(decoder->mPNG, 1);
   }
 
-  if (color_type == PNG_COLOR_TYPE_PALETTE)
+  if (color_type == PNG_COLOR_TYPE_PALETTE) {
     png_set_expand(png_ptr);
+  }
 
-  if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
+  if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
     png_set_expand(png_ptr);
+  }
 
   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
     int sample_max = (1 << bit_depth);
     png_color_16p trans_values;
     png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &trans_values);
     // libpng doesn't reject a tRNS chunk with out-of-range samples
     // so we check it here to avoid setting up a useless opacity
     // channel or producing unexpected transparent pixels when using
     // libpng-1.2.19 through 1.2.26 (bug #428045)
     if ((color_type == PNG_COLOR_TYPE_GRAY &&
-       (int)trans_values->gray > sample_max) ||
-       (color_type == PNG_COLOR_TYPE_RGB &&
-       ((int)trans_values->red > sample_max ||
-       (int)trans_values->green > sample_max ||
-       (int)trans_values->blue > sample_max)))
-      {
-        // clear the tRNS valid flag and release tRNS memory
-        png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
-      }
-    else
+         (int)trans_values->gray > sample_max) ||
+         (color_type == PNG_COLOR_TYPE_RGB &&
+         ((int)trans_values->red > sample_max ||
+         (int)trans_values->green > sample_max ||
+         (int)trans_values->blue > sample_max))) {
+      // clear the tRNS valid flag and release tRNS memory
+      png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
+    } else {
       png_set_expand(png_ptr);
+    }
   }
 
-  if (bit_depth == 16)
+  if (bit_depth == 16) {
     png_set_scale_16(png_ptr);
+  }
 
   qcms_data_type inType = QCMS_DATA_RGBA_8;
   uint32_t intent = -1;
   uint32_t pIntent;
   if (decoder->mCMSMode != eCMSMode_Off) {
     intent = gfxPlatform::GetRenderingIntent();
     decoder->mInProfile = PNGGetColorProfile(png_ptr, info_ptr,
                                              color_type, &inType, &pIntent);
     // If we're not mandating an intent, use the one from the image.
-    if (intent == uint32_t(-1))
+    if (intent == uint32_t(-1)) {
       intent = pIntent;
+    }
   }
   if (decoder->mInProfile && gfxPlatform::GetCMSOutputProfile()) {
     qcms_data_type outType;
 
-    if (color_type & PNG_COLOR_MASK_ALPHA || num_trans)
+    if (color_type & PNG_COLOR_MASK_ALPHA || num_trans) {
       outType = QCMS_DATA_RGBA_8;
-    else
+    } else {
       outType = QCMS_DATA_RGB_8;
+    }
 
     decoder->mTransform = qcms_transform_create(decoder->mInProfile,
                                            inType,
                                            gfxPlatform::GetCMSOutputProfile(),
                                            outType,
                                            (qcms_intent)intent);
   } else {
     png_set_gray_to_rgb(png_ptr);
 
     // only do gamma correction if CMS isn't entirely disabled
-    if (decoder->mCMSMode != eCMSMode_Off)
+    if (decoder->mCMSMode != eCMSMode_Off) {
       PNGDoGammaCorrection(png_ptr, info_ptr);
+    }
 
     if (decoder->mCMSMode == eCMSMode_All) {
-      if (color_type & PNG_COLOR_MASK_ALPHA || num_trans)
+      if (color_type & PNG_COLOR_MASK_ALPHA || num_trans) {
         decoder->mTransform = gfxPlatform::GetCMSRGBATransform();
-      else
+      } else {
         decoder->mTransform = gfxPlatform::GetCMSRGBTransform();
+      }
     }
   }
 
   // let libpng expand interlaced images
   if (interlace_type == PNG_INTERLACE_ADAM7) {
     // number_passes =
     png_set_interlace_handling(png_ptr);
   }
@@ -592,48 +617,51 @@ nsPNGDecoder::info_callback(png_structp 
   // members and whatnot, after which we can get channels, rowbytes, etc.
   png_read_update_info(png_ptr, info_ptr);
   decoder->mChannels = channels = png_get_channels(png_ptr, info_ptr);
 
   //---------------------------------------------------------------//
   // copy PNG info into imagelib structs (formerly png_set_dims()) //
   //---------------------------------------------------------------//
 
-  if (channels == 1 || channels == 3)
+  if (channels == 1 || channels == 3) {
     decoder->format = gfx::SurfaceFormat::B8G8R8X8;
-  else if (channels == 2 || channels == 4)
+  } else if (channels == 2 || channels == 4) {
     decoder->format = gfx::SurfaceFormat::B8G8R8A8;
+  }
 
 #ifdef PNG_APNG_SUPPORTED
-  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_acTL))
+  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_acTL)) {
     png_set_progressive_frame_fn(png_ptr, nsPNGDecoder::frame_info_callback,
                                  nullptr);
+  }
 
   if (png_get_first_frame_is_hidden(png_ptr, info_ptr)) {
     decoder->mFrameIsHidden = true;
   } else {
 #endif
     decoder->CreateFrame(0, 0, width, height, decoder->format);
 #ifdef PNG_APNG_SUPPORTED
   }
 #endif
 
   if (decoder->mTransform &&
       (channels <= 2 || interlace_type == PNG_INTERLACE_ADAM7)) {
     uint32_t bpp[] = { 0, 3, 4, 3, 4 };
     decoder->mCMSLine =
-      (uint8_t *)moz_malloc(bpp[channels] * width);
+      (uint8_t*)moz_malloc(bpp[channels] * width);
     if (!decoder->mCMSLine) {
       png_longjmp(decoder->mPNG, 5); // NS_ERROR_OUT_OF_MEMORY
     }
   }
 
   if (interlace_type == PNG_INTERLACE_ADAM7) {
-    if (height < INT32_MAX / (width * channels))
-      decoder->interlacebuf = (uint8_t *)moz_malloc(channels * width * height);
+    if (height < INT32_MAX / (width * channels)) {
+      decoder->interlacebuf = (uint8_t*)moz_malloc(channels * width * height);
+    }
     if (!decoder->interlacebuf) {
       png_longjmp(decoder->mPNG, 5); // NS_ERROR_OUT_OF_MEMORY
     }
   }
 
   if (decoder->NeedsNewFrame()) {
     // We know that we need a new frame, so pause input so the decoder
     // infrastructure can give it to us.
@@ -667,59 +695,60 @@ nsPNGDecoder::row_callback(png_structp p
    *
    * where old_row is what was displayed for previous rows.  Note
    * that the first pass (pass == 0 really) will completely cover
    * the old row, so the rows do not have to be initialized.  After
    * the first pass (and only for interlaced images), you will have
    * to pass the current row, and the function will combine the
    * old row and the new row.
    */
-  nsPNGDecoder *decoder =
+  nsPNGDecoder* decoder =
                static_cast<nsPNGDecoder*>(png_get_progressive_ptr(png_ptr));
 
   // skip this frame
-  if (decoder->mFrameIsHidden)
+  if (decoder->mFrameIsHidden) {
     return;
+  }
 
-  if (row_num >= (png_uint_32) decoder->mFrameRect.height)
+  if (row_num >= (png_uint_32) decoder->mFrameRect.height) {
     return;
+  }
 
   if (new_row) {
     int32_t width = decoder->mFrameRect.width;
     uint32_t iwidth = decoder->mFrameRect.width;
 
     png_bytep line = new_row;
     if (decoder->interlacebuf) {
       line = decoder->interlacebuf + (row_num * decoder->mChannels * width);
       png_progressive_combine_row(png_ptr, line, new_row);
     }
 
     uint32_t bpr = width * sizeof(uint32_t);
-    uint32_t *cptr32 = (uint32_t*)(decoder->mImageData + (row_num*bpr));
+    uint32_t* cptr32 = (uint32_t*)(decoder->mImageData + (row_num*bpr));
     bool rowHasNoAlpha = true;
 
     if (decoder->mTransform) {
       if (decoder->mCMSLine) {
         qcms_transform_data(decoder->mTransform, line, decoder->mCMSLine,
                             iwidth);
         // copy alpha over
         uint32_t channels = decoder->mChannels;
         if (channels == 2 || channels == 4) {
           for (uint32_t i = 0; i < iwidth; i++)
             decoder->mCMSLine[4 * i + 3] = line[channels * i + channels - 1];
         }
         line = decoder->mCMSLine;
       } else {
         qcms_transform_data(decoder->mTransform, line, line, iwidth);
-       }
-     }
+      }
+    }
 
     switch (decoder->format) {
-      case gfx::SurfaceFormat::B8G8R8X8:
-      {
+      case gfx::SurfaceFormat::B8G8R8X8: {
         // counter for while() loops below
         uint32_t idx = iwidth;
 
         // copy as bytes until source pointer is 32-bit-aligned
         for (; (NS_PTR_TO_UINT32(line) & 0x3) && idx; --idx) {
           *cptr32++ = gfxPackedPixel(0xFF, line[0], line[1], line[2]);
           line += 3;
         }
@@ -735,42 +764,44 @@ nsPNGDecoder::row_callback(png_structp p
         // copy remaining pixel(s)
         while (idx--) {
           // 32-bit read of final pixel will exceed buffer, so read bytes
           *cptr32++ = gfxPackedPixel(0xFF, line[0], line[1], line[2]);
           line += 3;
         }
       }
       break;
-      case gfx::SurfaceFormat::B8G8R8A8:
-      {
+      case gfx::SurfaceFormat::B8G8R8A8: {
         if (!decoder->mDisablePremultipliedAlpha) {
           for (uint32_t x=width; x>0; --x) {
             *cptr32++ = gfxPackedPixel(line[3], line[0], line[1], line[2]);
-            if (line[3] != 0xff)
+            if (line[3] != 0xff) {
               rowHasNoAlpha = false;
+            }
             line += 4;
           }
         } else {
           for (uint32_t x=width; x>0; --x) {
             *cptr32++ = gfxPackedPixelNoPreMultiply(line[3], line[0], line[1],
                                                     line[2]);
-            if (line[3] != 0xff)
+            if (line[3] != 0xff) {
               rowHasNoAlpha = false;
+            }
             line += 4;
           }
         }
       }
       break;
       default:
         png_longjmp(decoder->mPNG, 1);
     }
 
-    if (!rowHasNoAlpha)
+    if (!rowHasNoAlpha) {
       decoder->mFrameHasNoAlpha = false;
+    }
 
     if (decoder->mNumFrames <= 1) {
       // Only do incremental image display for the first frame
       // XXXbholley - this check should be handled in the superclass
       nsIntRect r(0, row_num, width, 1);
       decoder->PostInvalidation(r);
     }
   }
@@ -779,17 +810,17 @@ nsPNGDecoder::row_callback(png_structp p
 #ifdef PNG_APNG_SUPPORTED
 // got the header of a new frame that's coming
 void
 nsPNGDecoder::frame_info_callback(png_structp png_ptr, png_uint_32 frame_num)
 {
   png_uint_32 x_offset, y_offset;
   int32_t width, height;
 
-  nsPNGDecoder *decoder =
+  nsPNGDecoder* decoder =
                static_cast<nsPNGDecoder*>(png_get_progressive_ptr(png_ptr));
 
   // old frame is done
   decoder->EndImageFrame();
 
   // Only the first frame can be hidden, so unhide unconditionally here.
   decoder->mFrameIsHidden = false;
 
@@ -818,17 +849,17 @@ nsPNGDecoder::end_callback(png_structp p
    * the IEND).  You will usually have the same info chunk as you
    * had in the header, although some data may have been added
    * to the comments and time fields.
    *
    * Most people won't do much here, perhaps setting a flag that
    * marks the image as finished.
    */
 
-  nsPNGDecoder *decoder =
+  nsPNGDecoder* decoder =
                static_cast<nsPNGDecoder*>(png_get_progressive_ptr(png_ptr));
 
   // We shouldn't get here if we've hit an error
   NS_ABORT_IF_FALSE(!decoder->HasError(), "Finishing up PNG but hit error!");
 
   int32_t loop_count = 0;
 #ifdef PNG_APNG_SUPPORTED
   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_acTL)) {
--- a/image/decoders/nsPNGDecoder.h
+++ b/image/decoders/nsPNGDecoder.h
@@ -19,21 +19,22 @@
 
 namespace mozilla {
 namespace image {
 class RasterImage;
 
 class nsPNGDecoder : public Decoder
 {
 public:
-  explicit nsPNGDecoder(RasterImage &aImage);
+  explicit nsPNGDecoder(RasterImage& aImage);
   virtual ~nsPNGDecoder();
 
   virtual void InitInternal();
-  virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
+  virtual void WriteInternal(const char* aBuffer, uint32_t aCount,
+                             DecodeStrategy aStrategy) MOZ_OVERRIDE;
   virtual Telemetry::ID SpeedHistogram();
 
   void CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
                    int32_t width, int32_t height,
                    gfx::SurfaceFormat format);
   void EndImageFrame();
 
   // Check if PNG is valid ICO (32bpp RGBA)
@@ -66,20 +67,20 @@ public:
       return false;
     }
   }
 
 public:
   png_structp mPNG;
   png_infop mInfo;
   nsIntRect mFrameRect;
-  uint8_t *mCMSLine;
-  uint8_t *interlacebuf;
-  qcms_profile *mInProfile;
-  qcms_transform *mTransform;
+  uint8_t* mCMSLine;
+  uint8_t* interlacebuf;
+  qcms_profile* mInProfile;
+  qcms_transform* mTransform;
 
   gfx::SurfaceFormat format;
 
   // For size decodes
   uint8_t mSizeBytes[8]; // Space for width and height, both 4 bytes
   uint32_t mHeaderBytesRead;
 
   // whether CMS or premultiplied alpha are forced off
@@ -101,22 +102,19 @@ public:
     FrameBlender::FrameBlendMethod mBlend;
     int32_t mTimeout;
   };
 
   AnimFrameInfo mAnimInfo;
 
   // The number of frames we've finished.
   uint32_t mNumFrames;
-  
-  /*
-   * libpng callbacks
-   *
-   * We put these in the class so that they can access protected members.
-   */
+
+  // libpng callbacks
+  // We put these in the class so that they can access protected members.
   static void PNGAPI info_callback(png_structp png_ptr, png_infop info_ptr);
   static void PNGAPI row_callback(png_structp png_ptr, png_bytep new_row,
                                   png_uint_32 row_num, int pass);
 #ifdef PNG_APNG_SUPPORTED
   static void PNGAPI frame_info_callback(png_structp png_ptr,
                                          png_uint_32 frame_num);
 #endif
   static void PNGAPI end_callback(png_structp png_ptr, png_infop info_ptr);
--- a/image/encoders/bmp/nsBMPEncoder.cpp
+++ b/image/encoders/bmp/nsBMPEncoder.cpp
@@ -8,25 +8,26 @@
 #include "prprf.h"
 #include "nsString.h"
 #include "nsStreamUtils.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
 
 using namespace mozilla;
 
-NS_IMPL_ISUPPORTS(nsBMPEncoder, imgIEncoder, nsIInputStream, nsIAsyncInputStream)
+NS_IMPL_ISUPPORTS(nsBMPEncoder, imgIEncoder, nsIInputStream,
+                  nsIAsyncInputStream)
 
-nsBMPEncoder::nsBMPEncoder() : mImageBufferStart(nullptr), 
+nsBMPEncoder::nsBMPEncoder() : mImageBufferStart(nullptr),
                                mImageBufferCurr(0),
-                               mImageBufferSize(0), 
-                               mImageBufferReadPoint(0), 
+                               mImageBufferSize(0),
+                               mImageBufferReadPoint(0),
                                mFinished(false),
-                               mCallback(nullptr), 
-                               mCallbackTarget(nullptr), 
+                               mCallback(nullptr),
+                               mCallbackTarget(nullptr),
                                mNotifyThreshold(0)
 {
 }
 
 nsBMPEncoder::~nsBMPEncoder()
 {
   if (mImageBufferStart) {
     moz_free(mImageBufferStart);
@@ -34,36 +35,37 @@ nsBMPEncoder::~nsBMPEncoder()
     mImageBufferCurr = nullptr;
   }
 }
 
 // nsBMPEncoder::InitFromData
 //
 // One output option is supported: bpp=<bpp_value>
 // bpp specifies the bits per pixel to use where bpp_value can be 24 or 32
-NS_IMETHODIMP nsBMPEncoder::InitFromData(const uint8_t* aData,
-                                         uint32_t aLength, // (unused,
-                                                           // req'd by JS)
-                                         uint32_t aWidth,
-                                         uint32_t aHeight,
-                                         uint32_t aStride,
-                                         uint32_t aInputFormat,
-                                         const nsAString& aOutputOptions)
+NS_IMETHODIMP
+nsBMPEncoder::InitFromData(const uint8_t* aData,
+                           uint32_t aLength, // (unused, req'd by JS)
+                           uint32_t aWidth,
+                           uint32_t aHeight,
+                           uint32_t aStride,
+                           uint32_t aInputFormat,
+                           const nsAString& aOutputOptions)
 {
   // validate input format
   if (aInputFormat != INPUT_FORMAT_RGB &&
       aInputFormat != INPUT_FORMAT_RGBA &&
       aInputFormat != INPUT_FORMAT_HOSTARGB) {
     return NS_ERROR_INVALID_ARG;
   }
 
   // Stride is the padded width of each row, so it better be longer
   if ((aInputFormat == INPUT_FORMAT_RGB &&
        aStride < aWidth * 3) ||
-      ((aInputFormat == INPUT_FORMAT_RGBA || aInputFormat == INPUT_FORMAT_HOSTARGB) &&
+      ((aInputFormat == INPUT_FORMAT_RGBA ||
+        aInputFormat == INPUT_FORMAT_HOSTARGB) &&
        aStride < aWidth * 4)) {
       NS_WARNING("Invalid stride for InitFromData");
       return NS_ERROR_INVALID_ARG;
   }
 
   nsresult rv;
   rv = StartImageEncode(aWidth, aHeight, aInputFormat, aOutputOptions);
   if (NS_FAILED(rv)) {
@@ -96,20 +98,21 @@ PaddingBytes(uint32_t aBPP, uint32_t aWi
   uint8_t paddingSize = 0;
   if(rowSize % 4) {
     paddingSize = (4 - (rowSize % 4));
   }
   return paddingSize;
 }
 
 // See ::InitFromData for other info.
-NS_IMETHODIMP nsBMPEncoder::StartImageEncode(uint32_t aWidth,
-                                             uint32_t aHeight,
-                                             uint32_t aInputFormat,
-                                             const nsAString& aOutputOptions)
+NS_IMETHODIMP
+nsBMPEncoder::StartImageEncode(uint32_t aWidth,
+                               uint32_t aHeight,
+                               uint32_t aInputFormat,
+                               const nsAString& aOutputOptions)
 {
   // can't initialize more than once
   if (mImageBufferStart || mImageBufferCurr) {
     return NS_ERROR_ALREADY_INITIALIZED;
   }
 
   // validate input format
   if (aInputFormat != INPUT_FORMAT_RGB &&
@@ -139,55 +142,57 @@ NS_IMETHODIMP nsBMPEncoder::StartImageEn
   EncodeFileHeader();
   EncodeInfoHeader();
 
   return NS_OK;
 }
 
 // Returns the number of bytes in the image buffer used.
 // For a BMP file, this is all bytes in the buffer.
-NS_IMETHODIMP nsBMPEncoder::GetImageBufferUsed(uint32_t *aOutputSize)
+NS_IMETHODIMP
+nsBMPEncoder::GetImageBufferUsed(uint32_t* aOutputSize)
 {
   NS_ENSURE_ARG_POINTER(aOutputSize);
   *aOutputSize = mImageBufferSize;
   return NS_OK;
 }
 
 // Returns a pointer to the start of the image buffer
-NS_IMETHODIMP nsBMPEncoder::GetImageBuffer(char **aOutputBuffer)
+NS_IMETHODIMP
+nsBMPEncoder::GetImageBuffer(char** aOutputBuffer)
 {
   NS_ENSURE_ARG_POINTER(aOutputBuffer);
   *aOutputBuffer = reinterpret_cast<char*>(mImageBufferStart);
   return NS_OK;
 }
 
-NS_IMETHODIMP nsBMPEncoder::AddImageFrame(const uint8_t* aData,
-