Merge latest green inbound changeset and mozilla-central
authorEd Morley <emorley@mozilla.com>
Mon, 14 Oct 2013 17:39:02 +0100
changeset 164489 493c89ba8da401e4d8d4133533641d3f732d7719
parent 164488 68547b9ec03edaee78a54c8d94ba2dd3b419caf7 (current diff)
parent 164466 871fa1724684722ff7dcbd2a5f6d771f9e6039f3 (diff)
child 164490 30afbcdcec4d488a9954b3f269ca04d2101e546e
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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
Merge latest green inbound changeset and mozilla-central
dom/bindings/Codegen.py
dom/bindings/test/TestBindingHeader.h
--- a/b2g/config/gaia.json
+++ b/b2g/config/gaia.json
@@ -1,4 +1,4 @@
 {
-    "revision": "47d1ef9819810cecf9ce8cdcfd7f211530e43668", 
+    "revision": "4cdfe9307db3882da00e49361aa2f6788c9efe54", 
     "repo_path": "/integration/gaia-central"
 }
--- a/browser/base/content/browser-webrtcUI.js
+++ b/browser/base/content/browser-webrtcUI.js
@@ -19,19 +19,27 @@ let WebrtcIndicator = {
 
   updateButton: function () {
     this.button.hidden = !this.UIModule.showGlobalIndicator;
   },
 
   fillPopup: function (aPopup) {
     this._menuitemData = new WeakMap;
     for (let streamData of this.UIModule.activeStreams) {
+      let pageURI = Services.io.newURI(streamData.uri, null, null);
       let menuitem = document.createElement("menuitem");
-      menuitem.setAttribute("label", streamData.uri);
+      menuitem.setAttribute("class", "menuitem-iconic");
+      menuitem.setAttribute("label", streamData.browser.contentTitle || streamData.uri);
       menuitem.setAttribute("tooltiptext", streamData.uri);
+      PlacesUtils.favicons.getFaviconURLForPage(pageURI, function (aURI) {
+        if (aURI) {
+          let iconURL = PlacesUtils.favicons.getFaviconLinkForIcon(aURI).spec;
+          menuitem.setAttribute("image", iconURL);
+        }
+      });
 
       this._menuitemData.set(menuitem, streamData);
 
       aPopup.appendChild(menuitem);
     }
   },
 
   clearPopup: function (aPopup) {
--- a/browser/devtools/tilt/test/browser_tilt_02_notifications-seq.js
+++ b/browser/devtools/tilt/test/browser_tilt_02_notifications-seq.js
@@ -89,12 +89,13 @@ function cleanup() {
   info("Cleaning up the notifications test.");
 
   Services.obs.removeObserver(finalize, DESTROYED);
   Services.obs.removeObserver(obs_INITIALIZING, INITIALIZING);
   Services.obs.removeObserver(obs_INITIALIZED, INITIALIZED);
   Services.obs.removeObserver(obs_DESTROYING, DESTROYING);
   Services.obs.removeObserver(obs_BEFORE_DESTROYED, BEFORE_DESTROYED);
   Services.obs.removeObserver(obs_DESTROYED, DESTROYED);
+  Services.obs.removeObserver(obs_STARTUP, STARTUP);
 
   gBrowser.removeCurrentTab();
   finish();
 }
--- a/browser/devtools/tilt/test/browser_tilt_02_notifications.js
+++ b/browser/devtools/tilt/test/browser_tilt_02_notifications.js
@@ -113,16 +113,17 @@ function cleanup() {
   tab0 = null;
   tab1 = null;
 
   Services.obs.removeObserver(finalize, DESTROYED);
   Services.obs.removeObserver(tab_INITIALIZING, INITIALIZING);
   Services.obs.removeObserver(tab_DESTROYING, DESTROYING);
   Services.obs.removeObserver(tab_SHOWN, SHOWN);
   Services.obs.removeObserver(tab_HIDDEN, HIDDEN);
+  Services.obs.removeObserver(tab_STARTUP, STARTUP);
 
   gBrowser.tabContainer.removeEventListener("TabSelect", tabSelect);
   gBrowser.removeCurrentTab();
   finish();
 }
 
 function tabSelect() {
   if (testStep !== -1) {
--- a/content/base/src/nsXMLHttpRequest.h
+++ b/content/base/src/nsXMLHttpRequest.h
@@ -277,23 +277,16 @@ public:
 
   // event handler
   IMPL_EVENT_HANDLER(readystatechange)
 
   // states
   uint16_t ReadyState();
 
   // request
-  void Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv)
-  {
-    Open(aMethod, aUrl, true,
-         mozilla::dom::Optional<nsAString>(),
-         mozilla::dom::Optional<nsAString>(),
-         aRv);
-  }
   void Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
             const mozilla::dom::Optional<nsAString>& aUser,
             const mozilla::dom::Optional<nsAString>& aPassword,
             ErrorResult& aRv)
   {
     aRv = Open(aMethod, NS_ConvertUTF16toUTF8(aUrl),
                aAsync, aUser, aPassword);
   }
--- a/content/base/test/test_createHTMLDocument.html
+++ b/content/base/test/test_createHTMLDocument.html
@@ -22,33 +22,29 @@ function checkDoc(title, expectedtitle, 
   // Opera doesn't have a doctype: DSK-311092
   ok(doc.doctype, "Need a doctype");
   is(doc.doctype.name, "html");
   is(doc.doctype.publicId, "");
   is(doc.doctype.systemId, "");
   is(doc.doctype.internalSubset, null, "internalSubset should be null!");
   isElement(doc.documentElement, "html");
   isElement(doc.documentElement.firstChild, "head");
-  if (title !== undefined) {
-    is(doc.documentElement.firstChild.childNodes.length, 1);
-    isElement(doc.documentElement.firstChild.firstChild, "title");
-    // Doesn't always work out in WebKit.
-    ok(doc.documentElement.firstChild.firstChild.firstChild, "Need a text node.");
-    is(doc.documentElement.firstChild.firstChild.firstChild.data, expectedtitle);
-  } else {
-    is(doc.documentElement.firstChild.childNodes.length, 0);
-  }
+  is(doc.documentElement.firstChild.childNodes.length, 1);
+  isElement(doc.documentElement.firstChild.firstChild, "title");
+  // Doesn't always work out in WebKit.
+  ok(doc.documentElement.firstChild.firstChild.firstChild, "Need a text node.");
+  is(doc.documentElement.firstChild.firstChild.firstChild.data, expectedtitle);
   isElement(doc.documentElement.lastChild, "body");
   is(doc.documentElement.lastChild.childNodes.length, 0);
   ((!title || title.indexOf("\f") === -1) ? is : todo_is)
     (doc.title, normalizedtitle);
   doc.body.innerHTML = "foo";
   is(doc.body.innerHTML, "foo", "innerHTML should work in HTML data documents!");
 }
 checkDoc("", "", "");
 checkDoc(null, "null", "null");
-checkDoc(undefined, "", "");
+checkDoc(undefined, "undefined", "undefined");
 checkDoc("foo  bar baz", "foo  bar baz", "foo bar baz");
 checkDoc("foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz");
 checkDoc("foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz");
 checkDoc("foo\f\fbar baz", "foo\f\fbar baz", "foo bar baz");
 checkDoc("foo\r\rbar baz", "foo\r\rbar baz", "foo bar baz");
 </script>
--- a/content/media/MediaDecoderReader.h
+++ b/content/media/MediaDecoderReader.h
@@ -442,16 +442,18 @@ public:
   virtual nsresult Init(MediaDecoderReader* aCloneDonor) = 0;
 
   // True if this reader is waiting media resource allocation
   virtual bool IsWaitingMediaResources() { return false; }
   // True when this reader need to become dormant state
   virtual bool IsDormantNeeded() { return false; }
   // Release media resources they should be released in dormant state
   virtual void ReleaseMediaResources() {};
+  // Release the decoder during shutdown
+  virtual void ReleaseDecoder() {};
 
   // Resets all state related to decoding, emptying all buffers etc.
   virtual nsresult ResetDecode();
 
   // Decodes an unspecified amount of audio data, enqueuing the audio data
   // in mAudioQueue. Returns true when there's more audio to decode,
   // false if the audio is finished, end of file has been reached,
   // or an un-recoverable read error has occured.
--- a/content/media/MediaDecoderStateMachine.h
+++ b/content/media/MediaDecoderStateMachine.h
@@ -315,17 +315,23 @@ public:
 
   // Timer function to implement ScheduleStateMachine(aUsecs).
   void TimeoutExpired();
 
   // Set the media fragment end time. aEndTime is in microseconds.
   void SetFragmentEndTime(int64_t aEndTime);
 
   // Drop reference to decoder.  Only called during shutdown dance.
-  void ReleaseDecoder() { mDecoder = nullptr; }
+  void ReleaseDecoder() {
+    MOZ_ASSERT(mReader);
+    if (mReader) {
+      mReader->ReleaseDecoder();
+    }
+    mDecoder = nullptr;
+  }
 
    // Called when a "MozAudioAvailable" event listener is added to the media
    // element. Called on the main thread.
    void NotifyAudioAvailableListener();
 
   // Copy queued audio/video data in the reader to any output MediaStreams that
   // need it.
   void SendStreamData();
--- a/content/media/omx/MediaOmxReader.cpp
+++ b/content/media/omx/MediaOmxReader.cpp
@@ -64,16 +64,23 @@ bool MediaOmxReader::IsDormantNeeded()
 void MediaOmxReader::ReleaseMediaResources()
 {
   ResetDecode();
   if (mOmxDecoder.get()) {
     mOmxDecoder->ReleaseMediaResources();
   }
 }
 
+void MediaOmxReader::ReleaseDecoder()
+{
+  if (mOmxDecoder.get()) {
+    mOmxDecoder->ReleaseDecoder();
+  }
+}
+
 nsresult MediaOmxReader::ReadMetadata(MediaInfo* aInfo,
                                       MetadataTags** aTags)
 {
   NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
 
   *aTags = nullptr;
 
   if (!mOmxDecoder.get()) {
--- a/content/media/omx/MediaOmxReader.h
+++ b/content/media/omx/MediaOmxReader.h
@@ -57,16 +57,18 @@ public:
     return mHasVideo;
   }
 
   virtual bool IsWaitingMediaResources();
 
   virtual bool IsDormantNeeded();
   virtual void ReleaseMediaResources();
 
+  virtual void ReleaseDecoder() MOZ_OVERRIDE;
+
   virtual nsresult ReadMetadata(MediaInfo* aInfo,
                                 MetadataTags** aTags);
   virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime);
   virtual nsresult GetBuffered(mozilla::dom::TimeRanges* aBuffered, int64_t aStartTime);
 
   virtual void OnDecodeThreadStart() MOZ_OVERRIDE;
 
   virtual void OnDecodeThreadFinish() MOZ_OVERRIDE;
--- a/content/media/omx/OmxDecoder.cpp
+++ b/content/media/omx/OmxDecoder.cpp
@@ -57,84 +57,95 @@ public:
   }
 
 private:
   android::sp<android::OmxDecoder> mOmxDecoder;
   int64_t                          mOffset;
 };
 
 // When loading an MP3 stream from a file, we need to parse the file's
-// content to find its duration. Reading files of 100 Mib or more can
-// delay the player app noticably, so the file os read and decoded in
+// content to find its duration. Reading files of 100 MiB or more can
+// delay the player app noticably, so the file is read and decoded in
 // smaller chunks.
 //
 // We first read on the decode thread, but parsing must be done on the
 // main thread. After we read the file's initial MiBs in the decode
 // thread, an instance of this class is scheduled to the main thread for
 // parsing the MP3 stream. The decode thread waits until it has finished.
 //
 // If there is more data available from the file, the runnable dispatches
 // a task to the IO thread for retrieving the next chunk of data, and
 // the IO task dispatches a runnable to the main thread for parsing the
 // data. This goes on until all of the MP3 file has been parsed.
 
 class OmxDecoderNotifyDataArrivedRunnable : public nsRunnable
 {
 public:
-  OmxDecoderNotifyDataArrivedRunnable(android::OmxDecoder* aOmxDecoder, const char* aBuffer, uint64_t aLength, int64_t aOffset, uint64_t aFullLength)
+  OmxDecoderNotifyDataArrivedRunnable(android::OmxDecoder* aOmxDecoder,
+                                      const char* aBuffer, uint64_t aLength,
+                                      int64_t aOffset, uint64_t aFullLength)
   : mOmxDecoder(aOmxDecoder),
     mBuffer(aBuffer),
     mLength(aLength),
     mOffset(aOffset),
     mFullLength(aFullLength),
     mCompletedMonitor("OmxDecoderNotifyDataArrived.mCompleted"),
     mCompleted(false)
   {
     MOZ_ASSERT(mOmxDecoder.get());
     MOZ_ASSERT(mBuffer.get() || !mLength);
   }
 
   NS_IMETHOD Run()
   {
     NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
 
-    const char* buffer = mBuffer.get();
-
-    while (mLength) {
-      uint32_t length = std::min<uint64_t>(mLength, UINT32_MAX);
-      mOmxDecoder->NotifyDataArrived(mBuffer.get(), mLength, mOffset);
-
-      buffer  += length;
-      mLength -= length;
-      mOffset += length;
-    }
-
-    if (mOffset < mFullLength) {
-      // We cannot read data in the main thread because it
-      // might block for too long. Instead we post an IO task
-      // to the IO thread if there is more data available.
-      XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new OmxDecoderProcessCachedDataTask(mOmxDecoder.get(), mOffset));
-    }
-
+    NotifyDataArrived();
     Completed();
 
     return NS_OK;
   }
 
   void WaitForCompletion()
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
     MonitorAutoLock mon(mCompletedMonitor);
     if (!mCompleted) {
       mCompletedMonitor.Wait();
     }
   }
 
 private:
+  void NotifyDataArrived()
+  {
+    const char* buffer = mBuffer.get();
+
+    while (mLength) {
+      uint32_t length = std::min<uint64_t>(mLength, UINT32_MAX);
+      bool success = mOmxDecoder->NotifyDataArrived(buffer, mLength,
+                                                    mOffset);
+      if (!success) {
+        return;
+      }
+
+      buffer  += length;
+      mLength -= length;
+      mOffset += length;
+    }
+
+    if (mOffset < mFullLength) {
+      // We cannot read data in the main thread because it
+      // might block for too long. Instead we post an IO task
+      // to the IO thread if there is more data available.
+      XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
+          new OmxDecoderProcessCachedDataTask(mOmxDecoder.get(), mOffset));
+    }
+  }
+
   // Call this function at the end of Run() to notify waiting
   // threads.
   void Completed()
   {
     MonitorAutoLock mon(mCompletedMonitor);
     MOZ_ASSERT(!mCompleted);
     mCompleted = true;
     mCompletedMonitor.Notify();
@@ -395,17 +406,17 @@ bool OmxDecoder::TryLoad() {
     if (durationUs > totalDurationUs)
       totalDurationUs = durationUs;
   }
   if (mAudioTrack.get()) {
     durationUs = -1;
     const char* audioMime;
     sp<MetaData> meta = mAudioTrack->getFormat();
 
-    if (meta->findCString(kKeyMIMEType, &audioMime) && !strcasecmp(audioMime, AUDIO_MP3)) {
+    if (mIsMp3) {
       // Feed MP3 parser with cached data. Local files will be fully
       // cached already, network streams will update with sucessive
       // calls to NotifyDataArrived.
       if (ProcessCachedData(0, true)) {
         durationUs = mMP3FrameParser.GetDuration();
         if (durationUs > totalDurationUs) {
           totalDurationUs = durationUs;
         }
@@ -623,33 +634,40 @@ bool OmxDecoder::SetAudioFormat() {
   }
 
   LOG(PR_LOG_DEBUG, "channelCount: %d sampleRate: %d",
       mAudioChannels, mAudioSampleRate);
 
   return true;
 }
 
-void OmxDecoder::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
+void OmxDecoder::ReleaseDecoder()
 {
-  if (!mAudioTrack.get() || !mIsMp3 || !mMP3FrameParser.IsMP3()) {
-    return;
+  mDecoder = nullptr;
+}
+
+bool OmxDecoder::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset)
+{
+  if (!mAudioTrack.get() || !mIsMp3 || !mMP3FrameParser.IsMP3() || !mDecoder) {
+    return false;
   }
 
   mMP3FrameParser.Parse(aBuffer, aLength, aOffset);
 
   int64_t durationUs = mMP3FrameParser.GetDuration();
 
   if (durationUs != mDurationUs) {
     mDurationUs = durationUs;
 
     MOZ_ASSERT(mDecoder);
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
     mDecoder->UpdateEstimatedMediaDuration(mDurationUs);
   }
+
+  return true;
 }
 
 void OmxDecoder::ReleaseVideoBuffer() {
   if (mVideoBuffer) {
     mVideoBuffer->release();
     mVideoBuffer = nullptr;
   }
 }
--- a/content/media/omx/OmxDecoder.h
+++ b/content/media/omx/OmxDecoder.h
@@ -176,17 +176,19 @@ public:
   bool TryLoad();
   bool IsDormantNeeded();
   bool IsWaitingMediaResources();
   bool AllocateMediaResources();
   void ReleaseMediaResources();
   bool SetVideoFormat();
   bool SetAudioFormat();
 
-  void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
+  void ReleaseDecoder();
+
+  bool NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
 
   void GetDuration(int64_t *durationUs) {
     *durationUs = mDurationUs;
   }
 
   void GetVideoParameters(int32_t *width, int32_t *height) {
     *width = mVideoWidth;
     *height = mVideoHeight;
--- a/content/xbl/src/nsXBLPrototypeBinding.cpp
+++ b/content/xbl/src/nsXBLPrototypeBinding.cpp
@@ -993,61 +993,35 @@ 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 attrName, attrValue;
-      rv = aStream->ReadString(attrName);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = aStream->ReadString(attrValue);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      nsCOMPtr<nsIAtom> atomName = do_GetAtom(attrName);
-      mBinding->SetAttr(attrNamespace, atomName, attrValue, false);
-    }
-  }
-
   // Finally, read in the resources.
-  while (true) {
+  do {
     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;
 }
@@ -1147,40 +1121,16 @@ 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->Atom();
-      mBinding->GetAttr(attr->NamespaceID(), attr->Atom(), attrValue);
-      rv = aStream->Write8(XBLBinding_Serialize_Attribute);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      rv = WriteNamespace(aStream, attr->NamespaceID());
-      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 0x00000003
+#define XBLBinding_Serialize_Version 0x00000002
 
 // 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,17 +40,16 @@ 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
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -698,18 +698,23 @@ AudioChannelService::Observe(nsISupports
     if (keyStr.EqualsLiteral("audio.volume.content")) {
       audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_CONTENT, index);
     } else if (keyStr.EqualsLiteral("audio.volume.notification")) {
       audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_NOTIFICATION, index);
     } else if (keyStr.EqualsLiteral("audio.volume.alarm")) {
       audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_ALARM, index);
     } else if (keyStr.EqualsLiteral("audio.volume.telephony")) {
       audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_TELEPHONY, index);
-    } else {
-      MOZ_ASSUME_UNREACHABLE("unexpected audio channel for volume control");
+    } else if (!keyStr.EqualsLiteral("audio.volume.bt_sco")) {
+      // bt_sco is not a valid audio channel so we manipulate it in
+      // AudioManager.cpp. And the others should not be used.
+      // We didn't use MOZ_ASSUME_UNREACHABLE here because any web content who
+      // has permission of mozSettings can set any names then it can be easy to
+      // crash the B2G.
+      NS_WARNING("unexpected audio channel for volume control");
     }
   }
 #endif
 
   return NS_OK;
 }
 
 AudioChannelService::AudioChannelInternalType
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -2709,17 +2709,18 @@ def getJSToNativeConversionInfo(type, de
         if (defaultValue is not None and
             not isinstance(defaultValue, IDLNullValue)):
             raise TypeError("Can't handle non-null default value here")
         return handleDefault(template, codeToSetNull)
 
     # A helper function for wrapping up the template body for
     # possibly-nullable objecty stuff
     def wrapObjectTemplate(templateBody, type, codeToSetNull, failureCode=None):
-        if isNullOrUndefined and type.nullable():
+        if isNullOrUndefined:
+            assert type.nullable()
             # Just ignore templateBody and set ourselves to null.
             # Note that we don't have to worry about default values
             # here either, since we already examined this value.
             return "%s;" % codeToSetNull
 
         if not isDefinitelyObject:
             # Handle the non-object cases by wrapping up the whole
             # thing in an if cascade.
@@ -3326,16 +3327,19 @@ for (uint32_t i = 0; i < length; ++i) {
 
     if type.isDOMString():
         assert not isEnforceRange and not isClamp
 
         treatAs = {
             "Default": "eStringify",
             "EmptyString": "eEmpty",
             "Null": "eNull",
+            # For Missing it doesn't matter what we use here, since we'll never
+            # call ConvertJSValueToString on undefined in that case.
+            "Missing": "eStringify"
         }
         if type.nullable():
             # For nullable strings null becomes a null string.
             treatNullAs = "Null"
             # For nullable strings undefined becomes a null string unless
             # specified otherwise.
             if treatUndefinedAs == "Default":
                 treatUndefinedAs = "Null"
@@ -3845,18 +3849,21 @@ class CGArgumentConverter(CGThing):
             "declName" : "arg%d" % index,
             "holderName" : ("arg%d" % index) + "_holder",
             "obj" : "obj"
             }
         self.replacementVariables["val"] = string.Template(
             "args[${index}]"
             ).substitute(replacer)
         self.replacementVariables["mutableVal"] = self.replacementVariables["val"]
-        haveValueCheck = string.Template(
-            "args.hasDefined(${index})").substitute(replacer)
+        if argument.treatUndefinedAs == "Missing":
+            haveValueCheck = "args.hasDefined(${index})"
+        else:
+            haveValueCheck = "${index} < args.length()"
+        haveValueCheck = string.Template(haveValueCheck).substitute(replacer)
         self.replacementVariables["haveValue"] = haveValueCheck
         self.descriptorProvider = descriptorProvider
         if self.argument.optional and not self.argument.defaultValue:
             self.argcAndIndex = replacer
         else:
             self.argcAndIndex = None
         self.invalidEnumValueFatal = invalidEnumValueFatal
         self.lenientFloatCode = lenientFloatCode
@@ -4987,16 +4994,25 @@ class CGMethodCall(CGThing):
                 code = (
                     "if (args.length() < %d) {\n"
                     '  return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "%s");\n'
                     "}" % (requiredArgs, methodName))
                 self.cgRoot.prepend(
                     CGWrapper(CGIndenter(CGGeneric(code)), pre="\n", post="\n"))
             return
 
+        # We don't handle [TreatUndefinedAs=Missing] arguments in overload
+        # resolution yet.
+        for (_, sigArgs) in signatures:
+            for arg in sigArgs:
+                if arg.treatUndefinedAs == "Missing":
+                    raise TypeError("No support for [TreatUndefinedAs=Missing] "
+                                    "handling in overload resolution yet: %s" %
+                                    arg.location)
+
         # Need to find the right overload
         maxArgCount = method.maxArgCount
         allowedArgCounts = method.allowedArgCounts
 
         argCountCases = []
         for argCount in allowedArgCounts:
             possibleSignatures = method.signaturesForArgCount(argCount)
             if len(possibleSignatures) == 1:
@@ -5076,119 +5092,59 @@ class CGMethodCall(CGThing):
                         isNullOrUndefined=False):
                 assert not isDefinitelyObject or not isNullOrUndefined
                 assert isDefinitelyObject or isNullOrUndefined
                 if isDefinitelyObject:
                     failureCode = "break;"
                 else:
                     failureCode = None
                 type = distinguishingType(signature)
-                # The argument at index distinguishingIndex can't possibly be
-                # unset here, because we've already checked that argc is large
-                # enough that we can examine this argument.  But note that we
-                # still want to claim that optional arguments are optional, in
-                # case undefined was passed in.
-                argIsOptional = (distinguishingArgument(signature).optional and
-                                 not distinguishingArgument(signature).defaultValue)
+                # The argument at index distinguishingIndex can't possibly
+                # be unset here, because we've already checked that argc is
+                # large enough that we can examine this argument.
                 testCode = instantiateJSToNativeConversion(
                     getJSToNativeConversionInfo(type, descriptor,
                                                 failureCode=failureCode,
                                                 isDefinitelyObject=isDefinitelyObject,
                                                 isNullOrUndefined=isNullOrUndefined,
-                                                isOptional=argIsOptional,
                                                 sourceDescription=(argDesc % (distinguishingIndex + 1))),
                     {
                         "declName" : "arg%d" % distinguishingIndex,
                         "holderName" : ("arg%d" % distinguishingIndex) + "_holder",
                         "val" : distinguishingArg,
                         "mutableVal" : distinguishingArg,
-                        "obj" : "obj",
-                        "haveValue": "args.hasDefined(%d)" % distinguishingIndex
-                        },
-                    checkForValue=argIsOptional
-                    )
+                        "obj" : "obj"
+                        })
                 caseBody.append(CGIndenter(testCode, indent));
                 # If we got this far, we know we unwrapped to the right
                 # C++ type, so just do the call.  Start conversion with
                 # distinguishingIndex + 1, since we already converted
                 # distinguishingIndex.
                 caseBody.append(CGIndenter(
                         getPerSignatureCall(signature, distinguishingIndex + 1),
                         indent))
 
-            def hasConditionalConversion(type):
-                """
-                Return whether the argument conversion for this type will be
-                conditional on the type of incoming JS value.  For example, for
-                interface types the conversion is conditional on the incoming
-                value being isObject().
-
-                For the types for which this returns false, we do not have to
-                output extra isUndefined() or isNullOrUndefined() cases, because
-                null/undefined values will just fall through into our
-                unconditional conversion.
-                """
-                if type.isString() or type.isEnum():
-                    return False
-                if type.isBoolean():
-                    distinguishingTypes = (distinguishingType(s) for s in
-                                           possibleSignatures)
-                    return any(t.isString() or t.isEnum() or t.isNumeric()
-                               for t in distinguishingTypes)
-                if type.isNumeric():
-                    distinguishingTypes = (distinguishingType(s) for s in
-                                           possibleSignatures)
-                    return any(t.isString() or t.isEnum()
-                               for t in distinguishingTypes)
-                return True
-
-            def needsNullOrUndefinedCase(type):
-                """
-                Return true if the type needs a special isNullOrUndefined() case
-                """
-                return ((type.nullable() and
-                        hasConditionalConversion(type)) or
-                        type.isDictionary())
-
-            # First check for undefined and optional distinguishing arguments
-            # and output a special branch for that case.  Note that we don't
-            # use distinguishingArgument here because we actualy want to
-            # exclude variadic arguments.  Also note that we skip this check if
-            # we plan to output a isNullOrUndefined() special case for this
-            # argument anyway, since that will subsume our isUndefined() check.
-            # This is safe, because there can be at most one nullable
-            # distinguishing argument, so if we're it we'll definitely get
-            # picked up by the nullable handling.  Also, we can skip this check
-            # if the argument has an unconditional conversion later on.
-            undefSigs = [s for s in possibleSignatures if
-                         distinguishingIndex < len(s[1]) and
-                         s[1][distinguishingIndex].optional and
-                         hasConditionalConversion(s[1][distinguishingIndex].type) and
-                         not needsNullOrUndefinedCase(s[1][distinguishingIndex].type)]
-            # Can't have multiple signatures with an optional argument at the
-            # same index.
-            assert len(undefSigs) < 2
-            if len(undefSigs) > 0:
-                caseBody.append(CGGeneric("if (%s.isUndefined()) {" %
-                                          distinguishingArg))
-                tryCall(undefSigs[0], 2, isNullOrUndefined=True)
-                caseBody.append(CGGeneric("}"))
-
-            # Next, check for null or undefined.  That means looking for
+            # First check for null or undefined.  That means looking for
             # nullable arguments at the distinguishing index and outputting a
-            # separate branch for them.  But if the nullable argument has an
-            # unconditional conversion, we don't need to do that.  The reason
+            # separate branch for them.  But if the nullable argument is a
+            # primitive, string, or enum, we don't need to do that.  The reason
             # for that is that at most one argument at the distinguishing index
             # is nullable (since two nullable arguments are not
-            # distinguishable), and null/undefined values will always fall
-            # through to the unconditional conversion we have, if any, since
-            # they will fail whatever the conditions on the input value are for
-            # our other conversions.
+            # distinguishable), and all the argument types other than
+            # primitive/string/enum end up inside isObject() checks.  So if our
+            # nullable is a primitive/string/enum it's safe to not output the
+            # extra branch: we'll fall through to conversion for those types,
+            # which correctly handles null as needed, because isObject() will be
+            # false for null and undefined.
             nullOrUndefSigs = [s for s in possibleSignatures
-                               if needsNullOrUndefinedCase(distinguishingType(s))]
+                               if ((distinguishingType(s).nullable() and not
+                                    distinguishingType(s).isString() and not
+                                    distinguishingType(s).isEnum() and not
+                                   distinguishingType(s).isPrimitive()) or
+                                   distinguishingType(s).isDictionary())]
             # Can't have multiple nullable types here
             assert len(nullOrUndefSigs) < 2
             if len(nullOrUndefSigs) > 0:
                 caseBody.append(CGGeneric("if (%s.isNullOrUndefined()) {" %
                                           distinguishingArg))
                 tryCall(nullOrUndefSigs[0], 2, isNullOrUndefined=True)
                 caseBody.append(CGGeneric("}"))
 
--- a/dom/bindings/Nullable.h
+++ b/dom/bindings/Nullable.h
@@ -76,16 +76,21 @@ public:
     return Equals(aOtherNullable);
   }
 
   bool operator!=(const Nullable<T>& aOtherNullable) const
   {
     return !Equals(aOtherNullable);
   }
 
+  operator bool() const
+  {
+    return !mIsNull;
+  }
+
   // Make it possible to use a const Nullable of an array type with other
   // array types.
   template<typename U>
   operator const Nullable< nsTArray<U> >&() const {
     // Make sure that T is ok to reinterpret to nsTArray<U>
     const nsTArray<U>& arr = mValue;
     (void)arr;
     return *reinterpret_cast<const Nullable< nsTArray<U> >*>(this);
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -396,17 +396,22 @@ class IDLObjectWithIdentifier(IDLObject)
                     raise WebIDLError("[TreatNullAs] must take the identifier "
                                       "'EmptyString', not '%s'" % value,
                                       [self.location])
                 self.treatNullAs = value
             elif identifier == "TreatUndefinedAs":
                 if isDictionaryMember:
                     raise WebIDLError("[TreatUndefinedAs] is not allowed for "
                                       "dictionary members", [self.location])
-                if value == 'Null':
+                if value == 'Missing':
+                    if not isOptional:
+                        raise WebIDLError("[TreatUndefinedAs=Missing] is only "
+                                          "allowed on optional arguments",
+                                          [self.location])
+                elif value == 'Null':
                     if not self.type.isDOMString():
                         raise WebIDLError("[TreatUndefinedAs=Null] is only "
                                           "allowed on arguments or "
                                           "attributes whose type is "
                                           "DOMString or DOMString?",
                                           [self.location])
                     if not self.type.nullable():
                         raise WebIDLError("[TreatUndefinedAs=Null] is only "
@@ -416,18 +421,18 @@ class IDLObjectWithIdentifier(IDLObject)
                     if not self.type.isDOMString():
                         raise WebIDLError("[TreatUndefinedAs=EmptyString] "
                                           "is only allowed on arguments or "
                                           "attributes whose type is "
                                           "DOMString or DOMString?",
                                           [self.location])
                 else:
                     raise WebIDLError("[TreatUndefinedAs] must take the "
-                                      "identifiers EmptyString or Null",
-                                      [self.location])
+                                      "identifiers EmptyString or Null or "
+                                      "Missing", [self.location])
                 self.treatUndefinedAs = value
             else:
                 unhandledAttrs.append(attr)
 
         return unhandledAttrs
 
 class IDLObjectWithScope(IDLObjectWithIdentifier, IDLScope):
     def __init__(self, location, parentScope, identifier):
@@ -3133,32 +3138,35 @@ class IDLMethod(IDLInterfaceMember, IDLS
         return self
 
     def signatures(self):
         return [(overload.returnType, overload.arguments) for overload in
                 self._overloads]
 
     def finish(self, scope):
         for overload in self._overloads:
+            inOptionalArguments = False
             variadicArgument = None
 
             arguments = overload.arguments
             for (idx, argument) in enumerate(arguments):
-                if not argument.isComplete():
-                    argument.complete(scope)
+                if argument.isComplete():
+                    continue
+
+                argument.complete(scope)
                 assert argument.type.isComplete()
 
                 if (argument.type.isDictionary() or
                     (argument.type.isUnion() and
                      argument.type.unroll().hasDictionaryType)):
                     # Dictionaries and unions containing dictionaries at the
                     # end of the list or followed by optional arguments must be
                     # optional.
                     if (not argument.optional and
-                        all(arg.optional for arg in arguments[idx+1:])):
+                        (idx == len(arguments) - 1 or arguments[idx+1].optional)):
                         raise WebIDLError("Dictionary argument or union "
                                           "argument containing a dictionary "
                                           "not followed by a required argument "
                                           "must be optional",
                                           [argument.location])
 
                     # An argument cannot be a Nullable Dictionary
                     if argument.type.nullable():
@@ -3166,16 +3174,23 @@ class IDLMethod(IDLInterfaceMember, IDLS
                                           "dictionary or nullable union "
                                           "containing a dictionary",
                                           [argument.location])
 
                 # Only the last argument can be variadic
                 if variadicArgument:
                     raise WebIDLError("Variadic argument is not last argument",
                                       [variadicArgument.location])
+                # Once we see an optional argument, there can't be any non-optional
+                # arguments.
+                if inOptionalArguments and not argument.optional:
+                    raise WebIDLError("Non-optional argument after optional "
+                                      "arguments",
+                                      [argument.location])
+                inOptionalArguments = argument.optional
                 if argument.variadic:
                     variadicArgument = argument
 
             returnType = overload.returnType
             if returnType.isComplete():
                 continue
 
             type = returnType.complete(scope)
@@ -3210,17 +3225,17 @@ class IDLMethod(IDLInterfaceMember, IDLS
                             (self.identifier.name, argCount, idx,
                              distinguishingIndex),
                             [self.location, overload.location])
 
     def overloadsForArgCount(self, argc):
         return [overload for overload in self._overloads if
                 len(overload.arguments) == argc or
                 (len(overload.arguments) > argc and
-                 all(arg.optional for arg in overload.arguments[argc:])) or
+                 overload.arguments[argc].optional) or
                 (len(overload.arguments) < argc and
                  len(overload.arguments) > 0 and
                  overload.arguments[-1].variadic)]
 
     def signaturesForArgCount(self, argc):
         return [(overload.returnType, overload.arguments) for overload
                 in self.overloadsForArgCount(argc)]
 
@@ -4040,16 +4055,31 @@ class Parser(Tokenizer):
         if stringifier:
             if len(arguments) != 0:
                 raise WebIDLError("stringifier has wrong number of arguments",
                                   [self.getLocation(p, 2)])
             if not returnType.isDOMString():
                 raise WebIDLError("stringifier must have DOMString return type",
                                   [self.getLocation(p, 2)])
 
+        inOptionalArguments = False
+        variadicArgument = False
+        for argument in arguments:
+            # Only the last argument can be variadic
+            if variadicArgument:
+                raise WebIDLError("Only the last argument can be variadic",
+                                  [variadicArgument.location])
+            # Once we see an optional argument, there can't be any non-optional
+            # arguments.
+            if inOptionalArguments and not argument.optional:
+                raise WebIDLError("Cannot have a non-optional argument following an optional argument",
+                                  [argument.location])
+            inOptionalArguments = argument.optional
+            variadicArgument = argument if argument.variadic else None
+
         # identifier might be None.  This is only permitted for special methods.
         if not identifier:
             if not getter and not setter and not creator and \
                not deleter and not legacycaller and not stringifier:
                 raise WebIDLError("Identifier required for non-special methods",
                                   [self.getLocation(p, 2)])
 
             location = BuiltinLocation("<auto-generated-identifier>")
--- a/dom/bindings/parser/tests/test_dictionary.py
+++ b/dom/bindings/parser/tests/test_dictionary.py
@@ -173,33 +173,16 @@ def WebIDLTest(parser, harness):
 
     parser = parser.reset()
     threw = False
     try:
         parser.parse("""
             dictionary A {
             };
             interface X {
-              void doFoo(A arg1, optional long arg2, long arg3);
-            };
-        """)
-        results = parser.finish()
-    except:
-        threw = True
-
-    harness.ok(not threw,
-               "Dictionary arg followed by non-optional arg doesn't have to be optional")
-
-    parser = parser.reset()
-    threw = False
-    try:
-        parser.parse("""
-            dictionary A {
-            };
-            interface X {
               void doFoo((A or DOMString) arg1, optional long arg2);
             };
         """)
         results = parser.finish()
     except:
         threw = True
 
     harness.ok(threw,
--- a/dom/bindings/parser/tests/test_optional_constraints.py
+++ b/dom/bindings/parser/tests/test_optional_constraints.py
@@ -6,19 +6,19 @@ def WebIDLTest(parser, harness):
               void foo(optional byte arg1, byte arg2);
             };
         """)
 
         results = parser.finish()
     except:
         threw = True
 
-    harness.ok(not threw,
-               "Should not have thrown on non-optional argument following "
-               "optional argument.")
+    harness.ok(threw,
+               "Should have thrown on non-optional argument following optional "
+               "argument.")
 
     parser = parser.reset()
     parser.parse("""
         interface OptionalConstraints2 {
           void foo(optional byte arg1 = 1, optional byte arg2 = 2,
                    optional byte arg3, optional byte arg4 = 4,
                    optional byte arg5, optional byte arg6 = 9);
         };
--- a/dom/bindings/parser/tests/test_overload.py
+++ b/dom/bindings/parser/tests/test_overload.py
@@ -6,31 +6,29 @@ def WebIDLTest(parser, harness):
           void basic();
           void basic(long arg1);
           boolean abitharder(TestOverloads foo);
           boolean abitharder(boolean foo);
           void abitharder(ArrayBuffer? foo);
           void withVariadics(long... numbers);
           void withVariadics(TestOverloads iface);
           void withVariadics(long num, TestOverloads iface);
-          void optionalTest();
-          void optionalTest(optional long num1, long num2);
         };
     """)
 
     results = parser.finish()
 
     harness.ok(True, "TestOverloads interface parsed without error.")
     harness.check(len(results), 1, "Should be one production.")
     iface = results[0]
     harness.ok(isinstance(iface, WebIDL.IDLInterface),
                "Should be an IDLInterface")
     harness.check(iface.identifier.QName(), "::TestOverloads", "Interface has the right QName")
     harness.check(iface.identifier.name, "TestOverloads", "Interface has the right name")
-    harness.check(len(iface.members), 4, "Expect %s members" % 4)
+    harness.check(len(iface.members), 3, "Expect %s members" % 3)
 
     member = iface.members[0]
     harness.check(member.identifier.QName(), "::TestOverloads::basic", "Method has the right QName")
     harness.check(member.identifier.name, "basic", "Method has the right name")
     harness.check(member.hasOverloads(), True, "Method has overloads")
 
     signatures = member.signatures()
     harness.check(len(signatures), 2, "Method should have 2 signatures")
@@ -45,16 +43,8 @@ def WebIDLTest(parser, harness):
     harness.check(len(argumentSet), 1, "Expect an argument set with one argument")
 
     argument = argumentSet[0]
     harness.ok(isinstance(argument, WebIDL.IDLArgument),
                "Should be an IDLArgument")
     harness.check(argument.identifier.QName(), "::TestOverloads::basic::arg1", "Argument has the right QName")
     harness.check(argument.identifier.name, "arg1", "Argument has the right name")
     harness.check(str(argument.type), "Long", "Argument has the right type")
-
-    member = iface.members[3]
-    harness.check(len(member.overloadsForArgCount(0)), 1,
-                  "Only one overload for no args")
-    harness.check(len(member.overloadsForArgCount(1)), 0,
-                  "No overloads for one arg")
-    harness.check(len(member.overloadsForArgCount(2)), 1,
-                  "Only one overload for two args")
--- a/dom/bindings/parser/tests/test_variadic_constraints.py
+++ b/dom/bindings/parser/tests/test_variadic_constraints.py
@@ -1,63 +1,52 @@
 def WebIDLTest(parser, harness):
     threw = False
     try:
-        parser.parse("""
+        results = parser.parse("""
             interface VariadicConstraints1 {
               void foo(byte... arg1, byte arg2);
             };
         """)
-        results = parser.finish()
 
     except:
         threw = True
 
-    harness.ok(threw,
-               "Should have thrown on variadic argument followed by required "
-               "argument.")
+    harness.ok(threw, "Should have thrown.")
 
-    parser = parser.reset()
     threw = False
     try:
-        parser.parse("""
+        results = parser.parse("""
             interface VariadicConstraints2 {
               void foo(byte... arg1, optional byte arg2);
             };
         """)
-        results = parser.finish();
+
     except:
         threw = True
 
-    harness.ok(threw,
-               "Should have thrown on variadic argument followed by optional "
-               "argument.")
+    harness.ok(threw, "Should have thrown.")
 
-    parser = parser.reset()
     threw = False
     try:
-        parser.parse("""
+        results = parser.parse("""
             interface VariadicConstraints3 {
               void foo(optional byte... arg1);
             };
         """)
-        results = parser.finish()
 
     except:
         threw = True
 
-    harness.ok(threw,
-               "Should have thrown on variadic argument explicitly flagged as "
-               "optional.")
+    harness.ok(threw, "Should have thrown.")
 
-    parser = parser.reset()
     threw = False
     try:
-        parser.parse("""
+        results = parser.parse("""
             interface VariadicConstraints4 {
               void foo(byte... arg1 = 0);
             };
         """)
-        results = parser.finish()
+
     except:
         threw = True
 
     harness.ok(threw, "Should have thrown on variadic argument with default value.")
--- a/dom/bindings/test/TestBindingHeader.h
+++ b/dom/bindings/test/TestBindingHeader.h
@@ -157,19 +157,19 @@ public:
 
   // Integer types
   int8_t ReadonlyByte();
   int8_t WritableByte();
   void SetWritableByte(int8_t);
   void PassByte(int8_t);
   int8_t ReceiveByte();
   void PassOptionalByte(const Optional<int8_t>&);
-  void PassOptionalByteBeforeRequired(const Optional<int8_t>&, int8_t);
+  void PassOptionalUndefinedMissingByte(const Optional<int8_t>&);
   void PassOptionalByteWithDefault(int8_t);
-  void PassOptionalByteWithDefaultBeforeRequired(int8_t, int8_t);
+  void PassOptionalUndefinedMissingByteWithDefault(int8_t);
   void PassNullableByte(const Nullable<int8_t>&);
   void PassOptionalNullableByte(const Optional< Nullable<int8_t> >&);
   void PassVariadicByte(const Sequence<int8_t>&);
 
   int16_t ReadonlyShort();
   int16_t WritableShort();
   void SetWritableShort(int16_t);
   void PassShort(int16_t);
@@ -406,17 +406,19 @@ public:
   void PassVariadicTypedArray(const Sequence<Float32Array>&);
   void PassVariadicNullableTypedArray(const Sequence<Nullable<Float32Array> >&);
   JSObject* ReceiveUint8Array(JSContext*);
 
   // DOMString types
   void PassString(const nsAString&);
   void PassNullableString(const nsAString&);
   void PassOptionalString(const Optional<nsAString>&);
+  void PassOptionalUndefinedMissingString(const Optional<nsAString>&);
   void PassOptionalStringWithDefaultValue(const nsAString&);
+  void PassOptionalUndefinedMissingStringWithDefaultValue(const nsAString&);
   void PassOptionalNullableString(const Optional<nsAString>&);
   void PassOptionalNullableStringWithDefaultValue(const nsAString&);
   void PassVariadicString(const Sequence<nsString>&);
 
   // ByteString types
   void PassByteString(const nsCString&);
   void PassNullableByteString(const nsCString&);
   void PassOptionalByteString(const Optional<nsCString>&);
@@ -625,32 +627,16 @@ public:
   void Overload5(TestEnum);
   void Overload6(int32_t);
   void Overload6(bool);
   void Overload7(int32_t);
   void Overload7(bool);
   void Overload7(const nsCString&);
   void Overload8(int32_t);
   void Overload8(TestInterface&);
-  void Overload9(const Nullable<int32_t>&);
-  void Overload9(const nsAString&);
-  void Overload10(const Nullable<int32_t>&);
-  void Overload10(JSContext*, JS::Handle<JSObject*>);
-  void Overload11(int32_t);
-  void Overload11(const nsAString&);
-  void Overload12(int32_t);
-  void Overload12(const Nullable<bool>&);
-  void Overload13(const Nullable<int32_t>&);
-  void Overload13(bool);
-  void Overload14(const Optional<int32_t>&);
-  void Overload14(TestInterface&);
-  void Overload15(int32_t);
-  void Overload15(const Optional<NonNull<TestInterface> >&);
-  void Overload16(int32_t);
-  void Overload16(const Optional<TestInterface*>&);
 
   // Variadic handling
   void PassVariadicThirdArg(const nsAString&, int32_t,
                             const Sequence<OwningNonNull<TestInterface> >&);
 
   // Conditionally exposed methods/attributes
   bool Prefable1();
   bool Prefable2();
--- a/dom/bindings/test/TestCodeGen.webidl
+++ b/dom/bindings/test/TestCodeGen.webidl
@@ -113,19 +113,19 @@ interface OnlyForUseInConstructor {
 interface TestInterface {
   // Integer types
   // XXXbz add tests for throwing versions of all the integer stuff
   readonly attribute byte readonlyByte;
   attribute byte writableByte;
   void passByte(byte arg);
   byte receiveByte();
   void passOptionalByte(optional byte arg);
-  void passOptionalByteBeforeRequired(optional byte arg1, byte arg2);
+  void passOptionalUndefinedMissingByte([TreatUndefinedAs=Missing] optional byte arg);
   void passOptionalByteWithDefault(optional byte arg = 0);
-  void passOptionalByteWithDefaultBeforeRequired(optional byte arg1 = 0, byte arg2);
+  void passOptionalUndefinedMissingByteWithDefault([TreatUndefinedAs=Missing] optional byte arg = 0);
   void passNullableByte(byte? arg);
   void passOptionalNullableByte(optional byte? arg);
   void passVariadicByte(byte... arg);
 
   readonly attribute short readonlyShort;
   attribute short writableShort;
   void passShort(short arg);
   short receiveShort();
@@ -360,17 +360,19 @@ interface TestInterface {
   void passVariadicTypedArray(Float32Array... arg);
   void passVariadicNullableTypedArray(Float32Array?... arg);
   Uint8Array receiveUint8Array();
 
   // DOMString types
   void passString(DOMString arg);
   void passNullableString(DOMString? arg);
   void passOptionalString(optional DOMString arg);
+  void passOptionalUndefinedMissingString([TreatUndefinedAs=Missing] optional DOMString arg);
   void passOptionalStringWithDefaultValue(optional DOMString arg = "abc");
+  void passOptionalUndefinedMissingStringWithDefaultValue([TreatUndefinedAs=Missing] optional DOMString arg = "abc");
   void passOptionalNullableString(optional DOMString? arg);
   void passOptionalNullableStringWithDefaultValue(optional DOMString? arg = null);
   void passVariadicString(DOMString... arg);
 
   // ByteString types
   void passByteString(ByteString arg);
   void passNullableByteString(ByteString? arg);
   void passOptionalByteString(optional ByteString arg);
@@ -574,32 +576,16 @@ interface TestInterface {
   void overload5(TestEnum arg);
   void overload6(long arg);
   void overload6(boolean arg);
   void overload7(long arg);
   void overload7(boolean arg);
   void overload7(ByteString arg);
   void overload8(long arg);
   void overload8(TestInterface arg);
-  void overload9(long? arg);
-  void overload9(DOMString arg);
-  void overload10(long? arg);
-  void overload10(object arg);
-  void overload11(long arg);
-  void overload11(DOMString? arg);
-  void overload12(long arg);
-  void overload12(boolean? arg);
-  void overload13(long? arg);
-  void overload13(boolean arg);
-  void overload14(optional long arg);
-  void overload14(TestInterface arg);
-  void overload15(long arg);
-  void overload15(optional TestInterface arg);
-  void overload16(long arg);
-  void overload16(optional TestInterface? arg);
 
   // Variadic handling
   void passVariadicThirdArg(DOMString arg1, long arg2, TestInterface... arg3);
 
   // Conditionally exposed methods/attributes
   [Pref="abc.def"]
   readonly attribute boolean prefable1;
   [Pref="abc.def"]
--- a/dom/bindings/test/TestExampleGen.webidl
+++ b/dom/bindings/test/TestExampleGen.webidl
@@ -18,19 +18,19 @@
 interface TestExampleInterface {
   // Integer types
   // XXXbz add tests for throwing versions of all the integer stuff
   readonly attribute byte readonlyByte;
   attribute byte writableByte;
   void passByte(byte arg);
   byte receiveByte();
   void passOptionalByte(optional byte arg);
-  void passOptionalByteBeforeRequired(optional byte arg1, byte arg2);
+  void passOptionalUndefinedMissingByte([TreatUndefinedAs=Missing] optional byte arg);
   void passOptionalByteWithDefault(optional byte arg = 0);
-  void passOptionalByteWithDefaultBeforeRequired(optional byte arg1 = 0, byte arg2);
+  void passOptionalUndefinedMissingByteWithDefault([TreatUndefinedAs=Missing] optional byte arg = 0);
   void passNullableByte(byte? arg);
   void passOptionalNullableByte(optional byte? arg);
   void passVariadicByte(byte... arg);
 
   readonly attribute short readonlyShort;
   attribute short writableShort;
   void passShort(short arg);
   short receiveShort();
@@ -258,17 +258,19 @@ interface TestExampleInterface {
   void passVariadicTypedArray(Float32Array... arg);
   void passVariadicNullableTypedArray(Float32Array?... arg);
   Uint8Array receiveUint8Array();
 
   // DOMString types
   void passString(DOMString arg);
   void passNullableString(DOMString? arg);
   void passOptionalString(optional DOMString arg);
+  void passOptionalUndefinedMissingString([TreatUndefinedAs=Missing] optional DOMString arg);
   void passOptionalStringWithDefaultValue(optional DOMString arg = "abc");
+  void passOptionalUndefinedMissingStringWithDefaultValue([TreatUndefinedAs=Missing] optional DOMString arg = "abc");
   void passOptionalNullableString(optional DOMString? arg);
   void passOptionalNullableStringWithDefaultValue(optional DOMString? arg = null);
   void passVariadicString(DOMString... arg);
 
   // ByteString types
   void passByteString(ByteString arg);
   void passNullableByteString(ByteString? arg);
   void passOptionalByteString(optional ByteString arg);
@@ -471,32 +473,16 @@ interface TestExampleInterface {
   void overload5(TestEnum arg);
   void overload6(long arg);
   void overload6(boolean arg);
   void overload7(long arg);
   void overload7(boolean arg);
   void overload7(ByteString arg);
   void overload8(long arg);
   void overload8(TestInterface arg);
-  void overload9(long? arg);
-  void overload9(DOMString arg);
-  void overload10(long? arg);
-  void overload10(object arg);
-  void overload11(long arg);
-  void overload11(DOMString? arg);
-  void overload12(long arg);
-  void overload12(boolean? arg);
-  void overload13(long? arg);
-  void overload13(boolean arg);
-  void overload14(optional long arg);
-  void overload14(TestInterface arg);
-  void overload15(long arg);
-  void overload15(optional TestInterface arg);
-  void overload16(long arg);
-  void overload16(optional TestInterface? arg);
 
   // Variadic handling
   void passVariadicThirdArg(DOMString arg1, long arg2, TestInterface... arg3);
 
   // Conditionally exposed methods/attributes
   [Pref="abc.def"]
   readonly attribute boolean prefable1;
   [Pref="abc.def"]
--- a/dom/bindings/test/TestJSImplGen.webidl
+++ b/dom/bindings/test/TestJSImplGen.webidl
@@ -30,19 +30,19 @@ enum MyTestEnum {
 interface TestJSImplInterface {
   // Integer types
   // XXXbz add tests for throwing versions of all the integer stuff
   readonly attribute byte readonlyByte;
   attribute byte writableByte;
   void passByte(byte arg);
   byte receiveByte();
   void passOptionalByte(optional byte arg);
-  void passOptionalByteBeforeRequired(optional byte arg1, byte arg2);
+  void passOptionalUndefinedMissingByte([TreatUndefinedAs=Missing] optional byte arg);
   void passOptionalByteWithDefault(optional byte arg = 0);
-  void passOptionalByteWithDefaultBeforeRequired(optional byte arg1 = 0, byte arg2);
+  void passOptionalUndefinedMissingByteWithDefault([TreatUndefinedAs=Missing] optional byte arg = 0);
   void passNullableByte(byte? arg);
   void passOptionalNullableByte(optional byte? arg);
   void passVariadicByte(byte... arg);
 
   readonly attribute short readonlyShort;
   attribute short writableShort;
   void passShort(short arg);
   short receiveShort();
@@ -280,17 +280,19 @@ interface TestJSImplInterface {
   //void passVariadicTypedArray(Float32Array... arg);
   //void passVariadicNullableTypedArray(Float32Array?... arg);
   //Uint8Array receiveUint8Array();
 
   // DOMString types
   void passString(DOMString arg);
   void passNullableString(DOMString? arg);
   void passOptionalString(optional DOMString arg);
+  void passOptionalUndefinedMissingString([TreatUndefinedAs=Missing] optional DOMString arg);
   void passOptionalStringWithDefaultValue(optional DOMString arg = "abc");
+  void passOptionalUndefinedMissingStringWithDefaultValue([TreatUndefinedAs=Missing] optional DOMString arg = "abc");
   void passOptionalNullableString(optional DOMString? arg);
   void passOptionalNullableStringWithDefaultValue(optional DOMString? arg = null);
   void passVariadicString(DOMString... arg);
 
   // ByteString types
   void passByteString(ByteString arg);
   void passNullableByteString(ByteString? arg);
   void passOptionalByteString(optional ByteString arg);
@@ -499,32 +501,16 @@ interface TestJSImplInterface {
   void overload5(MyTestEnum arg);
   void overload6(long arg);
   void overload6(boolean arg);
   void overload7(long arg);
   void overload7(boolean arg);
   void overload7(ByteString arg);
   void overload8(long arg);
   void overload8(TestJSImplInterface arg);
-  void overload9(long? arg);
-  void overload9(DOMString arg);
-  void overload10(long? arg);
-  void overload10(object arg);
-  void overload11(long arg);
-  void overload11(DOMString? arg);
-  void overload12(long arg);
-  void overload12(boolean? arg);
-  void overload13(long? arg);
-  void overload13(boolean arg);
-  void overload14(optional long arg);
-  void overload14(TestInterface arg);
-  void overload15(long arg);
-  void overload15(optional TestInterface arg);
-  void overload16(long arg);
-  void overload16(optional TestInterface? arg);
 
   // Variadic handling
   void passVariadicThirdArg(DOMString arg1, long arg2, TestJSImplInterface... arg3);
 
   // Miscellania
   [LenientThis] attribute long attrWithLenientThis;
   // FIXME: Bug 863954 Unforgeable things get all confused when
   // non-JS-implemented interfaces inherit from JS-implemented ones or vice
--- a/dom/bluetooth/BluetoothHfpManager.cpp
+++ b/dom/bluetooth/BluetoothHfpManager.cpp
@@ -984,28 +984,21 @@ BluetoothHfpManager::Connect(const nsASt
     if (mDeviceAddress == aDeviceAddress) {
       aController->OnConnect(NS_LITERAL_STRING(ERR_ALREADY_CONNECTED));
     } else {
       aController->OnConnect(NS_LITERAL_STRING(ERR_REACHED_CONNECTION_LIMIT));
     }
     return;
   }
 
-  mNeedsUpdatingSdpRecords = true;
-  mIsHandsfree = !IS_HEADSET(aController->GetCod());
-
   nsString uuid;
-  if (mIsHandsfree) {
-    BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
-  } else {
-    BluetoothUuidHelper::GetString(BluetoothServiceClass::HEADSET, uuid);
-  }
+  BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
 
   if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
-    aController->OnConnect(NS_LITERAL_STRING(ERR_SERVICE_CHANNEL_NOT_FOUND));
+    aController->OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
     return;
   }
 
   // Stop listening because currently we only support one connection at a time.
   if (mHandsfreeSocket) {
     mHandsfreeSocket->Disconnect();
     mHandsfreeSocket = nullptr;
   }
@@ -1504,56 +1497,43 @@ BluetoothHfpManager::OnSocketDisconnect(
   OnDisconnect(EmptyString());
 
   Reset();
 }
 
 void
 BluetoothHfpManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress)
 {
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!aDeviceAddress.IsEmpty());
-  MOZ_ASSERT(mRunnable);
-
-  BluetoothService* bs = BluetoothService::Get();
-  NS_ENSURE_TRUE_VOID(bs);
-
-  nsString uuid;
-  if (mIsHandsfree) {
-    BluetoothUuidHelper::GetString(BluetoothServiceClass::HANDSFREE, uuid);
-  } else {
-    BluetoothUuidHelper::GetString(BluetoothServiceClass::HEADSET, uuid);
-  }
-
-  // Since we have updated SDP records of the target device, we should
-  // try to get the channel of target service again.
-  if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) {
-    OnConnect(NS_LITERAL_STRING(ERR_SERVICE_CHANNEL_NOT_FOUND));
-  }
+  // UpdateSdpRecord() is not called so this callback function should not
+  // be invoked.
+  MOZ_ASSUME_UNREACHABLE("UpdateSdpRecords() should be called somewhere");
 }
 
 void
 BluetoothHfpManager::OnGetServiceChannel(const nsAString& aDeviceAddress,
                                          const nsAString& aServiceUuid,
                                          int aChannel)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!aDeviceAddress.IsEmpty());
 
   BluetoothService* bs = BluetoothService::Get();
   NS_ENSURE_TRUE_VOID(bs);
 
-  BluetoothValue v;
+  if (aChannel < 0) {
+    // If we can't find Handsfree server channel number on the remote device,
+    // try to create HSP connection instead.
+    nsString hspUuid;
+    BluetoothUuidHelper::GetString(BluetoothServiceClass::HEADSET, hspUuid);
 
-  if (aChannel < 0) {
-    if (mNeedsUpdatingSdpRecords) {
-      mNeedsUpdatingSdpRecords = false;
-      bs->UpdateSdpRecords(aDeviceAddress, this);
-    } else {
+    if (aServiceUuid.Equals(hspUuid)) {
       OnConnect(NS_LITERAL_STRING(ERR_SERVICE_CHANNEL_NOT_FOUND));
+    } else if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress,
+                                               hspUuid, this))) {
+      OnConnect(NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE));
     }
 
     return;
   }
 
   if (!mSocket->Connect(NS_ConvertUTF16toUTF8(aDeviceAddress), aChannel)) {
     OnConnect(NS_LITERAL_STRING("SocketConnectionError"));
   }
--- a/dom/bluetooth/BluetoothHfpManager.h
+++ b/dom/bluetooth/BluetoothHfpManager.h
@@ -142,18 +142,16 @@ private:
   bool mCCWA;
   bool mCLIP;
   bool mCMEE;
   bool mCMER;
   bool mFirstCKPD;
   int mNetworkSelectionMode;
   bool mReceiveVgsFlag;
   bool mDialingRequestProcessed;
-  bool mIsHandsfree;
-  bool mNeedsUpdatingSdpRecords;
   nsString mDeviceAddress;
   nsString mMsisdn;
   nsString mOperatorName;
 
   nsTArray<Call> mCurrentCallArray;
   nsAutoPtr<BluetoothRilListener> mListener;
   nsRefPtr<BluetoothReplyRunnable> mRunnable;
   nsRefPtr<BluetoothProfileController> mController;
--- a/dom/bluetooth/BluetoothProfileController.h
+++ b/dom/bluetooth/BluetoothProfileController.h
@@ -41,21 +41,16 @@ BEGIN_BLUETOOTH_NAMESPACE
 #define HAS_OBJECT_TRANSFER(cod)     (cod & 0x100000)
 
 // Bit 18: Major service class = 0x20, Rendering
 #define HAS_RENDERING(cod)           (cod & 0x40000)
 
 // Major device class = 0xA, Peripheral
 #define IS_PERIPHERAL(cod)           (GET_MAJOR_DEVICE_CLASS(cod) == 0xa)
 
-// Major device class = 0x4, Audio/Video
-// Minor device class = 0x1, Wearable Headset device
-#define IS_HEADSET(cod)              ((GET_MAJOR_DEVICE_CLASS(cod) == 0x4) && \
-                                     (GET_MINOR_DEVICE_CLASS(cod) == 0x1))
-
 class BluetoothProfileManagerBase;
 class BluetoothReplyRunnable;
 typedef void (*BluetoothProfileControllerCallback)();
 
 class BluetoothProfileController : public RefCounted<BluetoothProfileController>
 {
 public:
   BluetoothProfileController(const nsAString& aDeviceAddress,
--- a/dom/imptests/html/dom/nodes/test_DOMImplementation-createHTMLDocument.html
+++ b/dom/imptests/html/dom/nodes/test_DOMImplementation-createHTMLDocument.html
@@ -13,31 +13,27 @@
 function checkDoc(title, expectedtitle, normalizedtitle) {
   test(function() {
     var doc = document.implementation.createHTMLDocument(title);
     assert_equals(doc.doctype.name, "html")
     assert_equals(doc.doctype.publicId, "")
     assert_equals(doc.doctype.systemId, "")
     assert_equals(doc.documentElement.localName, "html")
     assert_equals(doc.documentElement.firstChild.localName, "head")
-    if (title !== undefined) {
-      assert_equals(doc.documentElement.firstChild.childNodes.length, 1)
-      assert_equals(doc.documentElement.firstChild.firstChild.localName, "title")
-      assert_equals(doc.documentElement.firstChild.firstChild.firstChild.data,
-                    expectedtitle)
-    } else {
-      assert_equals(doc.documentElement.firstChild.childNodes.length, 0)
-    }
+    assert_equals(doc.documentElement.firstChild.childNodes.length, 1)
+    assert_equals(doc.documentElement.firstChild.firstChild.localName, "title")
+    assert_equals(doc.documentElement.firstChild.firstChild.firstChild.data,
+    expectedtitle)
     assert_equals(doc.documentElement.lastChild.localName, "body")
     assert_equals(doc.documentElement.lastChild.childNodes.length, 0)
   })
 }
 checkDoc("", "", "")
 checkDoc(null, "null", "null")
-checkDoc(undefined, "", "")
+checkDoc(undefined, "undefined", "undefined")
 checkDoc("foo  bar baz", "foo  bar baz", "foo bar baz")
 checkDoc("foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz")
 checkDoc("foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz")
 checkDoc("foo\f\fbar baz", "foo\f\fbar baz", "foo bar baz")
 checkDoc("foo\r\rbar baz", "foo\r\rbar baz", "foo bar baz")
 
 test(function() {
   var doc = document.implementation.createHTMLDocument();
--- a/dom/imptests/html/html/dom/documents/dta/test_document.title-07.html
+++ b/dom/imptests/html/html/dom/documents/dta/test_document.title-07.html
@@ -7,15 +7,15 @@
 function checkDoc(title, expectedtitle, normalizedtitle) {
   test(function() {
     var doc = document.implementation.createHTMLDocument(title);
     assert_equals(doc.title, normalizedtitle)
   })
 }
 checkDoc("", "", "")
 checkDoc(null, "null", "null")
-checkDoc(undefined, "", "")
+checkDoc(undefined, "undefined", "undefined")
 checkDoc("foo  bar baz", "foo  bar baz", "foo bar baz")
 checkDoc("foo\t\tbar baz", "foo\t\tbar baz", "foo bar baz")
 checkDoc("foo\n\nbar baz", "foo\n\nbar baz", "foo bar baz")
 checkDoc("foo\f\fbar baz", "foo\f\fbar baz", "foo bar baz")
 checkDoc("foo\r\rbar baz", "foo\r\rbar baz", "foo bar baz")
 </script>
--- a/dom/quota/QuotaManager.cpp
+++ b/dom/quota/QuotaManager.cpp
@@ -2797,17 +2797,17 @@ QuotaManager::RunSynchronizedOp(nsIOffli
 SynchronizedOp*
 QuotaManager::FindSynchronizedOp(const nsACString& aPattern,
                                  Nullable<PersistenceType> aPersistenceType,
                                  nsISupports* aId)
 {
   for (uint32_t index = 0; index < mSynchronizedOps.Length(); index++) {
     const nsAutoPtr<SynchronizedOp>& currentOp = mSynchronizedOps[index];
     if (PatternMatchesOrigin(aPattern, currentOp->mOriginOrPattern) &&
-        (currentOp->mPersistenceType.IsNull() ||
+        (!currentOp->mPersistenceType ||
          currentOp->mPersistenceType == aPersistenceType) &&
         (!currentOp->mId || currentOp->mId == aId)) {
       return currentOp;
     }
   }
 
   return nullptr;
 }
@@ -3062,28 +3062,28 @@ QuotaManager::CollectOriginsForEviction(
   // Collect active origins first.
   OriginCollection originCollection;
 
   // Add patterns and origins that have running or pending synchronized ops.
   // (add patterns first to reduce redundancy in the origin collection).
   uint32_t index;
   for (index = 0; index < mSynchronizedOps.Length(); index++) {
     nsAutoPtr<SynchronizedOp>& op = mSynchronizedOps[index];
-    if (op->mPersistenceType.IsNull() ||
+    if (!op->mPersistenceType ||
         op->mPersistenceType.Value() == PERSISTENCE_TYPE_TEMPORARY) {
       if (op->mOriginOrPattern.IsPattern() &&
           !originCollection.ContainsPattern(op->mOriginOrPattern)) {
         originCollection.AddPattern(op->mOriginOrPattern);
       }
     }
   }
 
   for (index = 0; index < mSynchronizedOps.Length(); index++) {
     nsAutoPtr<SynchronizedOp>& op = mSynchronizedOps[index];
-    if (op->mPersistenceType.IsNull() ||
+    if (!op->mPersistenceType ||
         op->mPersistenceType.Value() == PERSISTENCE_TYPE_TEMPORARY) {
       if (op->mOriginOrPattern.IsOrigin() &&
           !originCollection.ContainsOrigin(op->mOriginOrPattern)) {
         originCollection.AddOrigin(op->mOriginOrPattern);
       }
     }
   }
 
--- a/dom/system/gonk/AudioManager.cpp
+++ b/dom/system/gonk/AudioManager.cpp
@@ -133,17 +133,18 @@ public:
     } else if (aName.EqualsLiteral("audio.volume.alarm")) {
       audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_ALARM, volIndex);
     } else if (aName.EqualsLiteral("audio.volume.telephony")) {
       audioManager->SetAudioChannelVolume(AUDIO_CHANNEL_TELEPHONY, volIndex);
     } else if (aName.EqualsLiteral("audio.volume.bt_sco")) {
       static_cast<AudioManager *>(audioManager.get())->SetStreamVolumeIndex(
         AUDIO_STREAM_BLUETOOTH_SCO, volIndex);
     } else {
-      MOZ_ASSUME_UNREACHABLE("unexpected audio channel for volume control");
+      MOZ_ASSUME_UNREACHABLE("unexpected audio channel for initializing "
+                             "volume control");
     }
 
     return NS_OK;
   }
 
   NS_IMETHOD HandleError(const nsAString& aName)
   {
     LOG("AudioChannelVolInitCallback::HandleError: %s\n",
@@ -309,17 +310,17 @@ AudioManager::Observe(nsISupports* aSubj
       return NS_OK;
     }
 
     JS::RootedString jsKey(cx, JS_ValueToString(cx, key));
     if (!jsKey) {
       return NS_OK;
     }
     nsDependentJSString keyStr;
-    if (!keyStr.init(cx, jsKey) || keyStr.EqualsLiteral("audio.volume.bt_sco")) {
+    if (!keyStr.init(cx, jsKey) || !keyStr.EqualsLiteral("audio.volume.bt_sco")) {
       return NS_OK;
     }
 
     JS::Rooted<JS::Value> value(cx);
     if (!JS_GetProperty(cx, obj, "value", &value) || !value.isInt32()) {
       return NS_OK;
     }
 
--- a/dom/system/gonk/SystemWorkerManager.cpp
+++ b/dom/system/gonk/SystemWorkerManager.cpp
@@ -26,16 +26,17 @@
 #include "mozilla/dom/workers/Workers.h"
 #ifdef MOZ_WIDGET_GONK
 #include "mozilla/ipc/Netd.h"
 #include "AutoMounter.h"
 #include "TimeZoneSettingObserver.h"
 #include "AudioManager.h"
 #endif
 #include "mozilla/ipc/Ril.h"
+#include "mozilla/ipc/KeyStore.h"
 #include "nsIObserverService.h"
 #include "nsCxPusher.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "nsRadioInterfaceLayer.h"
 #include "WifiWorker.h"
 
 USING_WORKERS_NAMESPACE
@@ -336,16 +337,18 @@ SystemWorkerManager::Init()
   mozilla::AutoSafeJSContext cx;
 
   nsresult rv = InitWifi(cx);
   if (NS_FAILED(rv)) {
     NS_WARNING("Failed to initialize WiFi Networking!");
     return rv;
   }
 
+  InitKeyStore(cx);
+
 #ifdef MOZ_WIDGET_GONK
   InitAutoMounter();
   InitializeTimeZoneSettingObserver();
   rv = InitNetd(cx);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIAudioManager> audioManager =
     do_GetService(NS_AUDIOMANAGER_CONTRACTID);
 #endif
@@ -540,16 +543,23 @@ SystemWorkerManager::InitWifi(JSContext 
 {
   nsCOMPtr<nsIWorkerHolder> worker = do_CreateInstance(kWifiWorkerCID);
   NS_ENSURE_TRUE(worker, NS_ERROR_FAILURE);
 
   mWifiWorker = worker;
   return NS_OK;
 }
 
+nsresult
+SystemWorkerManager::InitKeyStore(JSContext *cx)
+{
+  mKeyStore = new KeyStore();
+  return NS_OK;
+}
+
 NS_IMPL_ISUPPORTS3(SystemWorkerManager,
                    nsIObserver,
                    nsIInterfaceRequestor,
                    nsISystemWorkerManager)
 
 NS_IMETHODIMP
 SystemWorkerManager::Observe(nsISupports *aSubject, const char *aTopic,
                              const PRUnichar *aData)
--- a/dom/system/gonk/SystemWorkerManager.h
+++ b/dom/system/gonk/SystemWorkerManager.h
@@ -30,16 +30,17 @@
 
 class nsIWorkerHolder;
 
 namespace mozilla {
 
 namespace ipc {
   class RilConsumer;
   class UnixSocketRawData;
+  class KeyStore;
 }
 
 namespace dom {
 namespace gonk {
 
 class SystemWorkerManager : public nsIObserver,
                             public nsIInterfaceRequestor,
                             public nsISystemWorkerManager
@@ -65,23 +66,25 @@ public:
 private:
   SystemWorkerManager();
   ~SystemWorkerManager();
 
 #ifdef MOZ_WIDGET_GONK
   nsresult InitNetd(JSContext *cx);
 #endif
   nsresult InitWifi(JSContext *cx);
+  nsresult InitKeyStore(JSContext *cx);
 
 #ifdef MOZ_WIDGET_GONK
   nsCOMPtr<nsIWorkerHolder> mNetdWorker;
 #endif
   nsCOMPtr<nsIWorkerHolder> mWifiWorker;
 
   nsTArray<nsRefPtr<ipc::RilConsumer> > mRilConsumers;
+  nsRefPtr<ipc::KeyStore> mKeyStore;
 
   bool mShutdown;
 };
 
 }
 }
 }
 
--- a/dom/system/gonk/tests/marionette/manifest.ini
+++ b/dom/system/gonk/tests/marionette/manifest.ini
@@ -2,8 +2,9 @@
 b2g = true
 browser = false
 qemu = true
 
 [test_geolocation.js]
 disabled = Bug 808783
 [test_fakevolume.js]
 [test_ril_code_quality.py]
+[test_screen_state.js]
--- a/dom/webidl/CanvasRenderingContext2D.webidl
+++ b/dom/webidl/CanvasRenderingContext2D.webidl
@@ -69,30 +69,30 @@ interface CanvasRenderingContext2D {
   void clearRect(double x, double y, double w, double h);
   [LenientFloat]
   void fillRect(double x, double y, double w, double h);
   [LenientFloat]
   void strokeRect(double x, double y, double w, double h);
 
   // path API (see also CanvasPathMethods)
   void beginPath();
-  void fill(optional CanvasWindingRule winding = "nonzero");
+  void fill([TreatUndefinedAs=Missing] optional CanvasWindingRule winding = "nonzero");
 // NOT IMPLEMENTED  void fill(Path path);
   void stroke();
 // NOT IMPLEMENTED  void stroke(Path path);
 // NOT IMPLEMENTED  void drawSystemFocusRing(Element element);
 // NOT IMPLEMENTED  void drawSystemFocusRing(Path path, Element element);
 // NOT IMPLEMENTED  boolean drawCustomFocusRing(Element element);
 // NOT IMPLEMENTED  boolean drawCustomFocusRing(Path path, Element element);
 // NOT IMPLEMENTED  void scrollPathIntoView();
 // NOT IMPLEMENTED  void scrollPathIntoView(Path path);
-  void clip(optional CanvasWindingRule winding = "nonzero");
+  void clip([TreatUndefinedAs=Missing] optional CanvasWindingRule winding = "nonzero");
 // NOT IMPLEMENTED  void clip(Path path);
 // NOT IMPLEMENTED  void resetClip();
-  boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
+  boolean isPointInPath(unrestricted double x, unrestricted double y, [TreatUndefinedAs=Missing] optional CanvasWindingRule winding = "nonzero");
 // NOT IMPLEMENTED  boolean isPointInPath(Path path, unrestricted double x, unrestricted double y);
   boolean isPointInStroke(double x, double y);
 
   // text (see also the CanvasDrawingStyles interface)
   [Throws, LenientFloat]
   void fillText(DOMString text, double x, double y, optional double maxWidth);
   [Throws, LenientFloat]
   void strokeText(DOMString text, double x, double y, optional double maxWidth);
--- a/dom/webidl/Promise.webidl
+++ b/dom/webidl/Promise.webidl
@@ -23,14 +23,14 @@ interface Promise {
   // Promise object in this scope without having resolved the interface object
   // first.
   [Creator, Throws, Func="mozilla::dom::Promise::EnabledForScope"]
   static Promise resolve(any value); // same as any(value)
   [Creator, Throws, Func="mozilla::dom::Promise::EnabledForScope"]
   static Promise reject(any value);
 
   [Creator]
-  Promise then(optional AnyCallback fulfillCallback,
-               optional AnyCallback rejectCallback);
+  Promise then([TreatUndefinedAs=Missing] optional AnyCallback fulfillCallback,
+               [TreatUndefinedAs=Missing] optional AnyCallback rejectCallback);
 
   [Creator]
-  Promise catch(optional AnyCallback rejectCallback);
+  Promise catch([TreatUndefinedAs=Missing] optional AnyCallback rejectCallback);
 };
--- a/dom/webidl/XMLHttpRequest.webidl
+++ b/dom/webidl/XMLHttpRequest.webidl
@@ -66,19 +66,17 @@ interface XMLHttpRequest : XMLHttpReques
   const unsigned short HEADERS_RECEIVED = 2;
   const unsigned short LOADING = 3;
   const unsigned short DONE = 4;
 
   readonly attribute unsigned short readyState;
 
   // request
   [Throws]
-  void open(ByteString method, DOMString url);
-  [Throws]
-  void open(ByteString method, DOMString url, boolean async,
+  void open(ByteString method, DOMString url, optional boolean async = true,
             optional DOMString? user, optional DOMString? password);
   [Throws]
   void setRequestHeader(ByteString header, ByteString value);
 
   [SetterThrows]
   attribute unsigned long timeout;
 
   [SetterThrows]
--- a/dom/workers/XMLHttpRequest.h
+++ b/dom/workers/XMLHttpRequest.h
@@ -116,21 +116,16 @@ public:
 #undef IMPL_GETTER_AND_SETTER
 
   uint16_t
   ReadyState() const
   {
     return mStateData.mReadyState;
   }
 
-  void Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv)
-  {
-    Open(aMethod, aUrl, true, Optional<nsAString>(),
-         Optional<nsAString>(), aRv);
-  }
   void
   Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
        const Optional<nsAString>& aUser, const Optional<nsAString>& aPassword,
        ErrorResult& aRv);
 
   void
   SetRequestHeader(const nsACString& aHeader, const nsACString& aValue,
                    ErrorResult& aRv);
new file mode 100644
--- /dev/null
+++ b/ipc/keystore/KeyStore.cpp
@@ -0,0 +1,381 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim: set sw=4 ts=8 et ft=cpp: */
+/* 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 <fcntl.h>
+#include <sys/stat.h>
+
+#undef LOG
+#if defined(MOZ_WIDGET_GONK)
+#include <android/log.h>
+#define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
+#else
+#define LOG(args...)  printf(args);
+#endif
+
+#include "KeyStore.h"
+#include "jsfriendapi.h"
+#include "MainThreadUtils.h" // For NS_IsMainThread.
+
+#include "plbase64.h"
+#include "certdb.h"
+
+using namespace mozilla::ipc;
+
+namespace mozilla {
+namespace ipc {
+
+static const char* KEYSTORE_SOCKET_NAME = "keystore";
+static const char* KEYSTORE_SOCKET_PATH = "/dev/socket/keystore";
+
+int
+KeyStoreConnector::Create()
+{
+  MOZ_ASSERT(!NS_IsMainThread());
+
+  int fd;
+
+  unlink(KEYSTORE_SOCKET_PATH);
+
+  fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+
+  if (fd < 0) {
+    NS_WARNING("Could not open keystore socket!");
+    return -1;
+  }
+
+  // Allow access of wpa_supplicant(different user, differnt group)
+  chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+
+  return fd;
+}
+
+bool
+KeyStoreConnector::CreateAddr(bool aIsServer,
+                              socklen_t& aAddrSize,
+                              sockaddr_any& aAddr,
+                              const char* aAddress)
+{
+  // Keystore socket must be server
+  MOZ_ASSERT(aIsServer);
+
+  aAddr.un.sun_family = AF_LOCAL;
+  if(strlen(KEYSTORE_SOCKET_PATH) > sizeof(aAddr.un.sun_path)) {
+      NS_WARNING("Address too long for socket struct!");
+      return false;
+  }
+  strcpy((char*)&aAddr.un.sun_path, KEYSTORE_SOCKET_PATH);
+  aAddrSize = strlen(KEYSTORE_SOCKET_PATH) + offsetof(struct sockaddr_un, sun_path) + 1;
+
+  return true;
+}
+
+bool
+KeyStoreConnector::SetUp(int aFd)
+{
+  return true;
+}
+
+void
+KeyStoreConnector::GetSocketAddr(const sockaddr_any& aAddr,
+                                 nsAString& aAddrStr)
+{
+  // Unused.
+  MOZ_CRASH("This should never be called!");
+}
+
+static char *
+get_cert_db_filename(void *arg, int vers)
+{
+  static char keystoreDbPath[] = "/data/misc/wifi/keystore";
+  return keystoreDbPath;
+}
+
+KeyStore::KeyStore()
+{
+  // Initial NSS
+  certdb = CERT_GetDefaultCertDB();
+
+  Listen();
+}
+
+void
+KeyStore::Shutdown()
+{
+  mShutdown = true;
+  CloseSocket();
+}
+
+void
+KeyStore::Listen()
+{
+  ListenSocket(new KeyStoreConnector());
+
+  ResetHandlerInfo();
+}
+
+void
+KeyStore::ResetHandlerInfo()
+{
+  mHandlerInfo.state = STATE_IDLE;
+  mHandlerInfo.command = 0;
+  mHandlerInfo.paramCount = 0;
+  mHandlerInfo.commandPattern = NULL;
+  for (int i = 0; i < MAX_PARAM; i++) {
+    mHandlerInfo.param[i].length = 0;
+    memset(mHandlerInfo.param[i].data, 0, VALUE_SIZE);
+  }
+}
+
+bool
+KeyStore::CheckSize(UnixSocketRawData *aMessage, size_t aExpectSize)
+{
+  return (aMessage->mSize - aMessage->mCurrentWriteOffset >= aExpectSize) ?
+         true : false;
+}
+
+bool
+KeyStore::ReadCommand(UnixSocketRawData *aMessage)
+{
+  if (mHandlerInfo.state != STATE_IDLE) {
+    NS_WARNING("Wrong state in ReadCommand()!");
+    return false;
+  }
+
+  if (!CheckSize(aMessage, 1)) {
+    NS_WARNING("Data size error in ReadCommand()!");
+    return false;
+  }
+
+  mHandlerInfo.command = aMessage->mData[aMessage->mCurrentWriteOffset];
+  aMessage->mCurrentWriteOffset++;
+
+  // Find corrsponding command pattern
+  const struct ProtocolCommand *command = commands;
+  while (command->command && command->command != mHandlerInfo.command) {
+    command++;
+  }
+
+  if (!command->command) {
+    NS_WARNING("Unsupported command!");
+    return false;
+  }
+
+  // Get command pattern.
+  mHandlerInfo.commandPattern = command;
+  if (command->paramNum) {
+    // Read command parameter if needed.
+    mHandlerInfo.state = STATE_READ_PARAM_LEN;
+  } else {
+    mHandlerInfo.state = STATE_PROCESSING;
+  }
+
+  return true;
+}
+
+bool
+KeyStore::ReadLength(UnixSocketRawData *aMessage)
+{
+  if (mHandlerInfo.state != STATE_READ_PARAM_LEN) {
+    NS_WARNING("Wrong state in ReadLength()!");
+    return false;
+  }
+
+  if (!CheckSize(aMessage, 2)) {
+    NS_WARNING("Data size error in ReadLength()!");
+    return false;
+  }
+
+  // Read length of command parameter.
+  unsigned short dataLength;
+  memcpy(&dataLength, &aMessage->mData[aMessage->mCurrentWriteOffset], 2);
+  aMessage->mCurrentWriteOffset += 2;
+  mHandlerInfo.param[mHandlerInfo.paramCount].length = ntohs(dataLength);
+
+  mHandlerInfo.state = STATE_READ_PARAM_DATA;
+
+  return true;
+}
+
+bool
+KeyStore::ReadData(UnixSocketRawData *aMessage)
+{
+  if (mHandlerInfo.state != STATE_READ_PARAM_DATA) {
+    NS_WARNING("Wrong state in ReadData()!");
+    return false;
+  }
+
+  if (!CheckSize(aMessage, mHandlerInfo.param[mHandlerInfo.paramCount].length)) {
+    NS_WARNING("Data size error in ReadData()!");
+    return false;
+  }
+
+  // Read command parameter.
+  memcpy(mHandlerInfo.param[mHandlerInfo.paramCount].data,
+         &aMessage->mData[aMessage->mCurrentWriteOffset],
+         mHandlerInfo.param[mHandlerInfo.paramCount].length);
+  aMessage->mCurrentWriteOffset += mHandlerInfo.param[mHandlerInfo.paramCount].length;
+  mHandlerInfo.paramCount++;
+
+  if (mHandlerInfo.paramCount == mHandlerInfo.commandPattern->paramNum) {
+    mHandlerInfo.state = STATE_PROCESSING;
+  } else {
+    mHandlerInfo.state = STATE_READ_PARAM_LEN;
+  }
+
+  return true;
+}
+
+// Transform base64 certification data into DER format
+void
+KeyStore::FormatCaData(const uint8_t *aCaData, int aCaDataLength,
+                       const char *aName, const uint8_t **aFormatData,
+                       int &aFormatDataLength)
+{
+  int bufSize = strlen(CA_BEGIN) + strlen(CA_END) + strlen(CA_TAILER) * 2 +
+                strlen(aName) * 2 + aCaDataLength + aCaDataLength/CA_LINE_SIZE + 2;
+  char *buf = (char *)malloc(bufSize);
+
+  aFormatDataLength = bufSize;
+  *aFormatData = (const uint8_t *)buf;
+
+  char *ptr = buf;
+  int len;
+
+  // Create DER header.
+  len = snprintf(ptr, bufSize, "%s%s%s", CA_BEGIN, aName, CA_TAILER);
+  ptr += len;
+  bufSize -= len;
+
+  // Split base64 data in lines.
+  int copySize;
+  while (aCaDataLength > 0) {
+    copySize = (aCaDataLength > CA_LINE_SIZE) ? CA_LINE_SIZE : aCaDataLength;
+
+    memcpy(ptr, aCaData, copySize);
+    ptr += copySize;
+    aCaData += copySize;
+    aCaDataLength -= copySize;
+    bufSize -= copySize;
+
+    *ptr = '\n';
+    ptr++;
+    bufSize--;
+  }
+
+  // Create DEA tailer.
+  snprintf(ptr, bufSize, "%s%s%s", CA_END, aName, CA_TAILER);
+}
+
+// Status response
+void
+KeyStore::SendResponse(ResponseCode aResponse)
+{
+  if (aResponse == NO_RESPONSE)
+    return;
+
+  uint8_t response = (uint8_t)aResponse;
+  UnixSocketRawData* data = new UnixSocketRawData((const void *)&response, 1);
+  SendSocketData(data);
+}
+
+// Data response
+void
+KeyStore::SendData(const uint8_t *aData, int aLength)
+{
+  unsigned short dataLength = htons(aLength);
+
+  UnixSocketRawData* length = new UnixSocketRawData((const void *)&dataLength, 2);
+  SendSocketData(length);
+
+  UnixSocketRawData* data = new UnixSocketRawData((const void *)aData, aLength);
+  SendSocketData(data);
+}
+
+void
+KeyStore::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+
+  bool success = true;
+  while (aMessage->mCurrentWriteOffset < aMessage->mSize ||
+         mHandlerInfo.state == STATE_PROCESSING) {
+    switch (mHandlerInfo.state) {
+      case STATE_IDLE:
+        success = ReadCommand(aMessage);
+        break;
+      case STATE_READ_PARAM_LEN:
+        success = ReadLength(aMessage);
+        break;
+      case STATE_READ_PARAM_DATA:
+        success = ReadData(aMessage);
+        break;
+      case STATE_PROCESSING:
+        success = false;
+        if (mHandlerInfo.command == 'g') {
+          // Get CA
+          const uint8_t *certData;
+          int certDataLength;
+          const char *certName = (const char *)mHandlerInfo.param[0].data;
+
+          // Get cert from NSS by name
+          CERTCertificate *cert = CERT_FindCertByNickname(certdb, certName);
+          if (!cert) {
+            break;
+          }
+
+          char *certDER = PL_Base64Encode((const char *)cert->derCert.data,
+                                          cert->derCert.len, nullptr);
+          if (!certDER) {
+            break;
+          }
+
+          FormatCaData((const uint8_t *)certDER, strlen(certDER), "CERTIFICATE",
+                       &certData, certDataLength);
+          PL_strfree(certDER);
+
+          SendResponse(SUCCESS);
+          SendData(certData, certDataLength);
+          success = true;
+
+          free((void *)certData);
+        }
+
+        ResetHandlerInfo();
+        break;
+    }
+
+    if (!success) {
+      SendResponse(PROTOCOL_ERROR);
+      ResetHandlerInfo();
+      return;
+    }
+  }
+}
+
+void
+KeyStore::OnConnectSuccess()
+{
+  mShutdown = false;
+}
+
+void
+KeyStore::OnConnectError()
+{
+  if (!mShutdown) {
+    Listen();
+  }
+}
+
+void
+KeyStore::OnDisconnect()
+{
+  if (!mShutdown) {
+    Listen();
+  }
+}
+
+} // namespace ipc
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/ipc/keystore/KeyStore.h
@@ -0,0 +1,131 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=8 et ft=cpp: */
+/* 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_ipc_KeyStore_h
+#define mozilla_ipc_KeyStore_h 1
+
+#include "mozilla/ipc/UnixSocket.h"
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "cert.h"
+
+namespace mozilla {
+namespace ipc {
+
+enum ResponseCode {
+  SUCCESS           =  1,
+  LOCKED            =  2,
+  UNINITIALIZED     =  3,
+  SYSTEM_ERROR      =  4,
+  PROTOCOL_ERROR    =  5,
+  PERMISSION_DENIED =  6,
+  KEY_NOT_FOUND     =  7,
+  VALUE_CORRUPTED   =  8,
+  UNDEFINED_ACTION  =  9,
+  WRONG_PASSWORD_0  = 10,
+  WRONG_PASSWORD_1  = 11,
+  WRONG_PASSWORD_2  = 12,
+  WRONG_PASSWORD_3  = 13, // MAX_RETRY = 4
+  NO_RESPONSE
+};
+
+static const int MAX_PARAM = 2;
+static const int KEY_SIZE = ((NAME_MAX - 15) / 2);
+static const int VALUE_SIZE = 32768;
+static const int PASSWORD_SIZE = VALUE_SIZE;
+
+static const char *CA_BEGIN = "-----BEGIN ",
+                  *CA_END   = "-----END ",
+                  *CA_TAILER = "-----\n";
+static const int CA_LINE_SIZE = 64;
+
+struct ProtocolCommand {
+  int8_t  command;
+  int     paramNum;
+};
+
+static const struct ProtocolCommand commands[] = {
+  {'g', 1}, // Get CA, command "g CERT_NAME"
+  { 0,  0}
+};
+
+struct ProtocolParam{
+  uint    length;
+  int8_t  data[VALUE_SIZE];
+};
+
+typedef enum {
+  STATE_IDLE,
+  STATE_READ_PARAM_LEN,
+  STATE_READ_PARAM_DATA,
+  STATE_PROCESSING
+} ProtocolHandlerState;
+
+class KeyStoreConnector : public mozilla::ipc::UnixSocketConnector
+{
+public:
+  KeyStoreConnector()
+  {}
+
+  virtual ~KeyStoreConnector()
+  {}
+
+  virtual int Create();
+  virtual bool CreateAddr(bool aIsServer,
+                          socklen_t& aAddrSize,
+                          sockaddr_any& aAddr,
+                          const char* aAddress);
+  virtual bool SetUp(int aFd);
+  virtual void GetSocketAddr(const sockaddr_any& aAddr,
+                             nsAString& aAddrStr);
+};
+
+class KeyStore : public mozilla::ipc::UnixSocketConsumer
+{
+public:
+  KeyStore();
+  virtual ~KeyStore() {}
+
+  void Shutdown();
+
+private:
+  virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage);
+
+  virtual void OnConnectSuccess();
+  virtual void OnConnectError();
+  virtual void OnDisconnect();
+
+private:
+  struct {
+    ProtocolHandlerState          state;
+    uint8_t                       command;
+    struct ProtocolParam          param[MAX_PARAM];
+    int                           paramCount;
+    const struct ProtocolCommand  *commandPattern;
+  } mHandlerInfo;
+  void ResetHandlerInfo();
+  void Listen();
+
+  void FormatCaData(const uint8_t *caData, int caDataLength, const char *name,
+                    const uint8_t **formatData, int &formatDataLength);
+
+  bool CheckSize(UnixSocketRawData *aMessage, size_t aExpectSize);
+  bool ReadCommand(UnixSocketRawData *aMessage);
+  bool ReadLength(UnixSocketRawData *aMessage);
+  bool ReadData(UnixSocketRawData *aMessage);
+  void SendResponse(ResponseCode response);
+  void SendData(const uint8_t *data, int length);
+
+  bool mShutdown;
+
+  CERTCertDBHandle *certdb;
+};
+
+} // namespace ipc
+} // namespace mozilla
+
+#endif // mozilla_ipc_KeyStore_h
new file mode 100644
--- /dev/null
+++ b/ipc/keystore/Makefile.in
@@ -0,0 +1,7 @@
+# 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/.
+
+EXPORT_LIBRARY = 1
+include $(topsrcdir)/config/rules.mk
+include $(topsrcdir)/ipc/chromium/chromium-config.mk
new file mode 100644
--- /dev/null
+++ b/ipc/keystore/moz.build
@@ -0,0 +1,21 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+MODULE = 'ipc'
+
+EXPORTS.mozilla.ipc += [
+  'KeyStore.h'
+]
+
+CPP_SOURCES += [
+  'KeyStore.cpp'
+]
+
+FAIL_ON_WARNINGS = True
+
+LIBXUL_LIBRARY = True
+
+LIBRARY_NAME = 'mozkeystore_s'
--- a/ipc/moz.build
+++ b/ipc/moz.build
@@ -13,14 +13,14 @@ DIRS += [
 
 if CONFIG['MOZ_B2G_RIL']:
     DIRS += ['ril']
 
 if CONFIG['MOZ_B2G_BT']:
     DIRS += ['dbus']
 
 if CONFIG['MOZ_B2G_RIL'] or CONFIG['MOZ_B2G_BT']:
-    DIRS += ['unixsocket']
+    DIRS += ['unixsocket', 'keystore']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     DIRS += ['netd']
 
 TOOL_DIRS += ['app']
--- a/js/xpconnect/tests/unit/test_allowedDomainsXHR.js
+++ b/js/xpconnect/tests/unit/test_allowedDomainsXHR.js
@@ -47,17 +47,17 @@ function run_test()
   httpserver.start(4444);
 
   httpserver2.registerPathHandler(negativetestpath, serverHandler);
   httpserver2.start(4445);
 
   // Test sync XHR sending
   cu.evalInSandbox('var createXHR = ' + createXHR.toString(), sb);
   var res = cu.evalInSandbox('var sync = createXHR("4444/simple"); sync.send(null); sync', sb);
-  do_check_true(checkResults(res));
+  checkResults(res);
 
   // negative test sync XHR sending (to ensure that the xhr do not have chrome caps, see bug 779821)
   try {
     cu.evalInSandbox('var createXHR = ' + createXHR.toString(), sb);
     var res = cu.evalInSandbox('var sync = createXHR("4445/negative"); sync.send(null); sync', sb);
     do_check_false(true, "XHR created from sandbox should not have chrome caps");
   } catch (e) {
     do_check_true(true);
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -92,17 +92,17 @@ endif #}
 ifdef MOZ_B2G_BT #{
 STATIC_LIBS += mozdbus_s
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 OS_LIBS += -ldbus
 endif
 endif #}
 
 ifneq ($(strip $(MOZ_B2G_RIL)$(MOZ_B2G_BT)),) #{
-STATIC_LIBS += mozipcunixsocket_s
+STATIC_LIBS += mozipcunixsocket_s mozkeystore_s
 endif #}
 
 ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
 STATIC_LIBS += moznetd_s
 endif
 
 ifdef MOZ_B2G_CAMERA #{
 OS_LIBS += -lstagefright -lstagefright_omx