bug 915558 - save attributes of binding element to startup cache r=smaug
authorTrevor Saunders <trev.saunders@gmail.com>
Wed, 25 Sep 2013 16:32:05 -0400
changeset 166746 512ee2e8691ecd788ab848630e2ef6f95783ace0
parent 166745 f59777bbd950c1adc90385e95fc03a28b0ffdd98
child 166747 168ec48380971c95dfc73c46f225a400654ad9ab
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs915558
milestone27.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 915558 - save attributes of binding element to startup cache r=smaug
content/xbl/src/nsXBLPrototypeBinding.cpp
content/xbl/src/nsXBLSerialize.h
--- a/content/xbl/src/nsXBLPrototypeBinding.cpp
+++ b/content/xbl/src/nsXBLPrototypeBinding.cpp
@@ -993,35 +993,65 @@ nsXBLPrototypeBinding::Read(nsIObjectInp
       previousHandler->SetNextHandler(handler);
     }
     else {
       SetPrototypeHandlers(handler);
     }
     previousHandler = handler;
   } while (1);
 
+  if (mBinding) {
+    while (true) {
+      XBLBindingSerializeDetails type;
+      rv = aStream->Read8(&type);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      if (type != XBLBinding_Serialize_Attribute) {
+        break;
+      }
+
+      int32_t attrNamespace;
+      rv = ReadNamespace(aStream, attrNamespace);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsAutoString attrPrefix, attrName, attrValue;
+      rv = aStream->ReadString(attrPrefix);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = aStream->ReadString(attrName);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = aStream->ReadString(attrValue);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsCOMPtr<nsIAtom> atomPrefix = do_GetAtom(attrPrefix);
+      nsCOMPtr<nsIAtom> atomName = do_GetAtom(attrName);
+      mBinding->SetAttr(attrNamespace, atomName, atomPrefix, attrValue, false);
+    }
+  }
+
   // Finally, read in the resources.
-  do {
+  while (true) {
     XBLBindingSerializeDetails type;
     rv = aStream->Read8(&type);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (type == XBLBinding_Serialize_NoMoreItems)
       break;
 
     NS_ASSERTION((type & XBLBinding_Serialize_Mask) == XBLBinding_Serialize_Stylesheet ||
                  (type & XBLBinding_Serialize_Mask) == XBLBinding_Serialize_Image, "invalid resource type");
 
     nsAutoString src;
     rv = aStream->ReadString(src);
     NS_ENSURE_SUCCESS(rv, rv);
 
     AddResource(type == XBLBinding_Serialize_Stylesheet ? nsGkAtoms::stylesheet :
                                                           nsGkAtoms::image, src);
-  } while (1);
+  }
 
   if (isFirstBinding) {
     aDocInfo->SetFirstPrototypeBinding(this);
   }
 
   cleanup.Disconnect();
   return NS_OK;
 }
@@ -1121,16 +1151,49 @@ nsXBLPrototypeBinding::Write(nsIObjectOu
     NS_ENSURE_SUCCESS(rv, rv);
 
     handler = handler->GetNextHandler();
   }
 
   aStream->Write8(XBLBinding_Serialize_NoMoreItems);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  if (mBinding) {
+    uint32_t attributes = mBinding->GetAttrCount();
+    nsAutoString attrValue;
+    for (uint32_t i = 0; i < attributes; ++i) {
+      const nsAttrName* attr = mBinding->GetAttrNameAt(i);
+      nsDependentAtomString attrName = attr->LocalName();
+      mBinding->GetAttr(attr->NamespaceID(), attr->LocalName(), attrValue);
+      rv = aStream->Write8(XBLBinding_Serialize_Attribute);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = WriteNamespace(aStream, attr->NamespaceID());
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsIAtom* prefix = attr->GetPrefix();
+      nsAutoString prefixString;
+      if (prefix) {
+        prefix->ToString(prefixString);
+      }
+
+      rv = aStream->WriteWStringZ(prefixString.get());
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = aStream->WriteWStringZ(attrName.get());
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      rv = aStream->WriteWStringZ(attrValue.get());
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+  }
+
+  aStream->Write8(XBLBinding_Serialize_NoMoreItems);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   // Write out the resources
   if (mResources) {
     rv = mResources->Write(aStream);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Write out an end mark at the end.
   return aStream->Write8(XBLBinding_Serialize_NoMoreItems);
--- a/content/xbl/src/nsXBLSerialize.h
+++ b/content/xbl/src/nsXBLSerialize.h
@@ -10,17 +10,17 @@
 #include "nsIObjectOutputStream.h"
 #include "nsINameSpaceManager.h"
 #include "js/TypeDecls.h"
 
 typedef uint8_t XBLBindingSerializeDetails;
 
 // A version number to ensure we don't load cached data in a different
 // file format.
-#define XBLBinding_Serialize_Version 0x00000002
+#define XBLBinding_Serialize_Version 0x00000003
 
 // Set for the first binding in a document
 #define XBLBinding_Serialize_IsFirstBinding 1
 
 // Set to indicate that nsXBLPrototypeBinding::mInheritStyle should be true
 #define XBLBinding_Serialize_InheritStyle 2
 
 // Set to indicate that nsXBLPrototypeBinding::mChromeOnlyContent should be true
@@ -40,16 +40,17 @@ typedef uint8_t XBLBindingSerializeDetai
 #define XBLBinding_Serialize_SetterProperty 3
 #define XBLBinding_Serialize_GetterSetterProperty 4
 #define XBLBinding_Serialize_Method 5
 #define XBLBinding_Serialize_Constructor 6
 #define XBLBinding_Serialize_Destructor 7
 #define XBLBinding_Serialize_Handler 8
 #define XBLBinding_Serialize_Image 9
 #define XBLBinding_Serialize_Stylesheet 10
+#define XBLBinding_Serialize_Attribute 0xA
 #define XBLBinding_Serialize_Mask 0x0F
 #define XBLBinding_Serialize_ReadOnly 0x80
 
 // Appears at the end of the list of insertion points to indicate that there
 // are no more. 
 #define XBLBinding_Serialize_NoMoreInsertionPoints 0xFFFFFFFF
 
 // When serializing content nodes, a single-byte namespace id is written out