Bug 1274376 - more mozilla::net namespaces r=dragana
authorPatrick McManus <mcmanus@ducksong.com>
Wed, 18 May 2016 22:02:57 -0400
changeset 369866 82092aed0171cf6f9073d224c8b766b7bce41c4f
parent 369865 c040302a52dc8c09a71944a6e0076e375e2d3630
child 369867 f4dff50367baf735c7fbeebbe889899d89e4138b
push id18942
push userdburns@mozilla.com
push dateMon, 23 May 2016 23:14:18 +0000
reviewersdragana
bugs1274376
milestone49.0a1
Bug 1274376 - more mozilla::net namespaces r=dragana
chrome/nsChromeProtocolHandler.cpp
dom/base/nsHostObjectProtocolHandler.cpp
dom/base/nsHostObjectURI.cpp
dom/base/nsHostObjectURI.h
dom/base/nsObjectLoadingContent.cpp
dom/jsurl/nsJSProtocolHandler.cpp
dom/jsurl/nsJSProtocolHandler.h
dom/network/TCPSocketParent.cpp
dom/network/UDPSocket.h
dom/network/UDPSocketChild.cpp
dom/network/UDPSocketParent.cpp
dom/security/nsCSPService.cpp
dom/xslt/base/txURIUtils.cpp
netwerk/base/LoadInfo.cpp
netwerk/base/LoadInfo.h
netwerk/base/nsAsyncRedirectVerifyHelper.cpp
netwerk/base/nsAsyncRedirectVerifyHelper.h
netwerk/base/nsChannelClassifier.cpp
netwerk/base/nsChannelClassifier.h
netwerk/base/nsIOService.cpp
netwerk/base/nsIOService.h
netwerk/base/nsInputStreamChannel.cpp
netwerk/base/nsInputStreamChannel.h
netwerk/base/nsLoadGroup.cpp
netwerk/base/nsLoadGroup.h
netwerk/base/nsNetSegmentUtils.h
netwerk/base/nsPACMan.cpp
netwerk/base/nsPACMan.h
netwerk/base/nsProtocolProxyService.cpp
netwerk/base/nsProtocolProxyService.h
netwerk/base/nsProxyInfo.cpp
netwerk/base/nsProxyInfo.h
netwerk/base/nsRequestObserverProxy.cpp
netwerk/base/nsRequestObserverProxy.h
netwerk/base/nsSecCheckWrapChannel.cpp
netwerk/base/nsSecCheckWrapChannel.h
netwerk/base/nsServerSocket.cpp
netwerk/base/nsServerSocket.h
netwerk/base/nsSimpleNestedURI.cpp
netwerk/base/nsSimpleNestedURI.h
netwerk/base/nsSimpleStreamListener.cpp
netwerk/base/nsSimpleStreamListener.h
netwerk/base/nsSimpleURI.cpp
netwerk/base/nsSimpleURI.h
netwerk/base/nsSocketTransport2.cpp
netwerk/base/nsSocketTransport2.h
netwerk/base/nsSocketTransportService2.cpp
netwerk/base/nsSocketTransportService2.h
netwerk/base/nsStandardURL.cpp
netwerk/base/nsStandardURL.h
netwerk/base/nsStreamListenerTee.cpp
netwerk/base/nsStreamListenerTee.h
netwerk/base/nsStreamListenerWrapper.cpp
netwerk/base/nsStreamListenerWrapper.h
netwerk/base/nsStreamLoader.cpp
netwerk/base/nsStreamLoader.h
netwerk/base/nsStreamTransportService.cpp
netwerk/base/nsStreamTransportService.h
netwerk/base/nsUDPSocket.cpp
netwerk/base/nsUDPSocket.h
netwerk/build/nsNetModule.cpp
netwerk/cache/nsCacheService.cpp
netwerk/protocol/about/nsAboutProtocolHandler.cpp
netwerk/protocol/about/nsAboutProtocolHandler.h
netwerk/protocol/device/nsDeviceProtocolHandler.cpp
netwerk/protocol/device/nsDeviceProtocolHandler.h
netwerk/protocol/http/AlternateServices.h
netwerk/protocol/http/Http2Stream.h
netwerk/protocol/http/NullHttpChannel.h
netwerk/protocol/http/nsHttpHandler.h
netwerk/protocol/res/ExtensionProtocolHandler.cpp
netwerk/protocol/res/ExtensionProtocolHandler.h
netwerk/protocol/res/SubstitutingProtocolHandler.cpp
netwerk/protocol/res/SubstitutingProtocolHandler.h
netwerk/protocol/viewsource/nsViewSourceHandler.cpp
netwerk/protocol/viewsource/nsViewSourceHandler.h
netwerk/standalone/nsNetModuleStandalone.cpp
netwerk/streamconv/converters/nsBinHexDecoder.cpp
netwerk/streamconv/converters/nsBinHexDecoder.h
--- a/chrome/nsChromeProtocolHandler.cpp
+++ b/chrome/nsChromeProtocolHandler.cpp
@@ -71,17 +71,17 @@ nsChromeProtocolHandler::NewURI(const ns
                                 const char *aCharset,
                                 nsIURI *aBaseURI,
                                 nsIURI **result)
 {
 
     // Chrome: URLs (currently) have no additional structure beyond that provided
     // by standard URLs, so there is no "outer" given to CreateInstance
 
-    RefPtr<nsStandardURL> surl = new nsStandardURL();
+    RefPtr<mozilla::net::nsStandardURL> surl = new mozilla::net::nsStandardURL();
 
     nsresult rv = surl->Init(nsIStandardURL::URLTYPE_STANDARD, -1, aSpec,
                              aCharset, aBaseURI);
     if (NS_FAILED(rv))
         return rv;
 
     // Canonify the "chrome:" URL; e.g., so that we collapse
     // "chrome://navigator/content/" and "chrome://navigator/content"
--- a/dom/base/nsHostObjectProtocolHandler.cpp
+++ b/dom/base/nsHostObjectProtocolHandler.cpp
@@ -19,17 +19,17 @@
 #include "nsHostObjectURI.h"
 #include "nsIMemoryReporter.h"
 #include "nsIPrincipal.h"
 #include "nsIUUIDGenerator.h"
 #include "nsNetUtil.h"
 
 using mozilla::dom::BlobImpl;
 using mozilla::ErrorResult;
-using mozilla::LoadInfo;
+using mozilla::net::LoadInfo;
 
 // -----------------------------------------------------------------------
 // Hash table
 struct DataInfo
 {
   // mObject is expected to be an nsIDOMBlob, DOMMediaStream, or MediaSource
   nsCOMPtr<nsISupports> mObject;
   nsCOMPtr<nsIPrincipal> mPrincipal;
@@ -715,17 +715,17 @@ nsFontTableProtocolHandler::NewURI(const
     NS_ENSURE_SUCCESS(rv, rv);
 
     uri->SetRef(aSpec);
   } else {
     // Relative URIs (other than #ref) are not meaningful within the
     // fonttable: scheme.
     // If aSpec is a relative URI -other- than a bare #ref,
     // this will leave uri empty, and we'll return a failure code below.
-    uri = new nsSimpleURI();
+    uri = new mozilla::net::nsSimpleURI();
     uri->SetSpec(aSpec);
   }
 
   bool schemeIs;
   if (NS_FAILED(uri->SchemeIs(FONTTABLEURI_SCHEME, &schemeIs)) || !schemeIs) {
     NS_WARNING("Non-fonttable spec in nsFontTableProtocolHander");
     return NS_ERROR_NOT_AVAILABLE;
   }
--- a/dom/base/nsHostObjectURI.cpp
+++ b/dom/base/nsHostObjectURI.cpp
@@ -13,32 +13,32 @@
 #include "mozilla/ipc/BackgroundUtils.h"
 #include "mozilla/ipc/URIUtils.h"
 
 static NS_DEFINE_CID(kHOSTOBJECTURICID, NS_HOSTOBJECTURI_CID);
 
 static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
                      NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
 
-NS_IMPL_ADDREF_INHERITED(nsHostObjectURI, nsSimpleURI)
-NS_IMPL_RELEASE_INHERITED(nsHostObjectURI, nsSimpleURI)
+NS_IMPL_ADDREF_INHERITED(nsHostObjectURI, mozilla::net::nsSimpleURI)
+NS_IMPL_RELEASE_INHERITED(nsHostObjectURI, mozilla::net::nsSimpleURI)
 
 NS_INTERFACE_MAP_BEGIN(nsHostObjectURI)
   NS_INTERFACE_MAP_ENTRY(nsIURIWithPrincipal)
   if (aIID.Equals(kHOSTOBJECTURICID))
     foundInterface = static_cast<nsIURI*>(this);
   else if (aIID.Equals(kThisSimpleURIImplementationCID)) {
     // Need to return explicitly here, because if we just set foundInterface
     // to null the NS_INTERFACE_MAP_END_INHERITING will end up calling into
     // nsSimplURI::QueryInterface and finding something for this CID.
     *aInstancePtr = nullptr;
     return NS_NOINTERFACE;
   }
   else
-NS_INTERFACE_MAP_END_INHERITING(nsSimpleURI)
+NS_INTERFACE_MAP_END_INHERITING(mozilla::net::nsSimpleURI)
 
 // nsIURIWithPrincipal methods:
 
 NS_IMETHODIMP
 nsHostObjectURI::GetPrincipal(nsIPrincipal** aPrincipal)
 {
   NS_IF_ADDREF(*aPrincipal = mPrincipal);
 
@@ -58,48 +58,48 @@ nsHostObjectURI::GetPrincipalUri(nsIURI*
   return NS_OK;
 }
 
 // nsISerializable methods:
 
 NS_IMETHODIMP
 nsHostObjectURI::Read(nsIObjectInputStream* aStream)
 {
-  nsresult rv = nsSimpleURI::Read(aStream);
+  nsresult rv = mozilla::net::nsSimpleURI::Read(aStream);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISupports> supports;
   rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
   NS_ENSURE_SUCCESS(rv, rv);
 
   mPrincipal = do_QueryInterface(supports, &rv);
   return rv;
 }
 
 NS_IMETHODIMP
 nsHostObjectURI::Write(nsIObjectOutputStream* aStream)
 {
-  nsresult rv = nsSimpleURI::Write(aStream);
+  nsresult rv = mozilla::net::nsSimpleURI::Write(aStream);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_WriteOptionalCompoundObject(aStream, mPrincipal,
                                         NS_GET_IID(nsIPrincipal),
                                         true);
 }
 
 // nsIIPCSerializableURI methods:
 void
 nsHostObjectURI::Serialize(mozilla::ipc::URIParams& aParams)
 {
   using namespace mozilla::ipc;
 
   HostObjectURIParams hostParams;
   URIParams simpleParams;
 
-  nsSimpleURI::Serialize(simpleParams);
+  mozilla::net::nsSimpleURI::Serialize(simpleParams);
   hostParams.simpleParams() = simpleParams;
 
   if (mPrincipal) {
     PrincipalInfo info;
     nsresult rv = PrincipalToPrincipalInfo(mPrincipal, &info);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return;
     }
@@ -119,17 +119,17 @@ nsHostObjectURI::Deserialize(const mozil
 
   if (aParams.type() != URIParams::THostObjectURIParams) {
       NS_ERROR("Received unknown parameters from the other process!");
       return false;
   }
 
   const HostObjectURIParams& hostParams = aParams.get_HostObjectURIParams();
 
-  if (!nsSimpleURI::Deserialize(hostParams.simpleParams())) {
+  if (!mozilla::net::nsSimpleURI::Deserialize(hostParams.simpleParams())) {
     return false;
   }
   if (hostParams.principal().type() == OptionalPrincipalInfo::Tvoid_t) {
     return true;
   }
 
   mPrincipal = PrincipalInfoToPrincipal(hostParams.principal().get_PrincipalInfo());
   return mPrincipal != nullptr;
@@ -141,22 +141,22 @@ nsHostObjectURI::SetScheme(const nsACStr
   // Disallow setting the scheme, since that could cause us to be associated
   // with a different protocol handler that doesn't expect us to be carrying
   // around a principal with nsIURIWithPrincipal.
   return NS_ERROR_FAILURE;
 }
 
 // nsIURI methods:
 nsresult
-nsHostObjectURI::CloneInternal(nsSimpleURI::RefHandlingEnum aRefHandlingMode,
+nsHostObjectURI::CloneInternal(mozilla::net::nsSimpleURI::RefHandlingEnum aRefHandlingMode,
                                nsIURI** aClone)
 {
   nsCOMPtr<nsIURI> simpleClone;
   nsresult rv =
-    nsSimpleURI::CloneInternal(aRefHandlingMode, getter_AddRefs(simpleClone));
+    mozilla::net::nsSimpleURI::CloneInternal(aRefHandlingMode, getter_AddRefs(simpleClone));
   NS_ENSURE_SUCCESS(rv, rv);
 
 #ifdef DEBUG
   RefPtr<nsHostObjectURI> uriCheck;
   rv = simpleClone->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(uriCheck));
   MOZ_ASSERT(NS_SUCCEEDED(rv) && uriCheck);
 #endif
 
@@ -165,33 +165,33 @@ nsHostObjectURI::CloneInternal(nsSimpleU
   u->mPrincipal = mPrincipal;
 
   simpleClone.forget(aClone);
   return NS_OK;
 }
 
 /* virtual */ nsresult
 nsHostObjectURI::EqualsInternal(nsIURI* aOther,
-                                nsSimpleURI::RefHandlingEnum aRefHandlingMode,
+                                mozilla::net::nsSimpleURI::RefHandlingEnum aRefHandlingMode,
                                 bool* aResult)
 {
   if (!aOther) {
     *aResult = false;
     return NS_OK;
   }
   
   RefPtr<nsHostObjectURI> otherUri;
   aOther->QueryInterface(kHOSTOBJECTURICID, getter_AddRefs(otherUri));
   if (!otherUri) {
     *aResult = false;
     return NS_OK;
   }
 
   // Compare the member data that our base class knows about.
-  if (!nsSimpleURI::EqualsInternal(otherUri, aRefHandlingMode)) {
+  if (!mozilla::net::nsSimpleURI::EqualsInternal(otherUri, aRefHandlingMode)) {
     *aResult = false;
     return NS_OK;
   }
 
   // Compare the piece of additional member data that we add to base class.
   if (mPrincipal && otherUri->mPrincipal) {
     // Both of us have mPrincipals. Compare them.
     return mPrincipal->Equals(otherUri->mPrincipal, aResult);
--- a/dom/base/nsHostObjectURI.h
+++ b/dom/base/nsHostObjectURI.h
@@ -16,26 +16,26 @@
 #include "nsSimpleURI.h"
 #include "nsIIPCSerializableURI.h"
 
 /**
  * These URIs refer to host objects: Blobs, with scheme "blob",
  * MediaStreams, with scheme "mediastream", and MediaSources, with scheme
  * "mediasource".
  */
-class nsHostObjectURI : public nsSimpleURI,
+class nsHostObjectURI : public mozilla::net::nsSimpleURI,
                         public nsIURIWithPrincipal
 {
 public:
   explicit nsHostObjectURI(nsIPrincipal* aPrincipal) :
-      nsSimpleURI(), mPrincipal(aPrincipal)
+      mozilla::net::nsSimpleURI(), mPrincipal(aPrincipal)
   {}
 
   // For use only from deserialization
-  nsHostObjectURI() : nsSimpleURI() {}
+  nsHostObjectURI() : mozilla::net::nsSimpleURI() {}
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIURIWITHPRINCIPAL
   NS_DECL_NSISERIALIZABLE
   NS_DECL_NSICLASSINFO
   NS_DECL_NSIIPCSERIALIZABLEURI
 
   NS_IMETHOD SetScheme(const nsACString &aProtocol) override;
@@ -43,17 +43,17 @@ public:
   // Override CloneInternal() and EqualsInternal()
   virtual nsresult CloneInternal(RefHandlingEnum aRefHandlingMode,
                                  nsIURI** aClone) override;
   virtual nsresult EqualsInternal(nsIURI* aOther,
                                   RefHandlingEnum aRefHandlingMode,
                                   bool* aResult) override;
 
   // Override StartClone to hand back a nsHostObjectURI
-  virtual nsSimpleURI* StartClone(RefHandlingEnum /* unused */) override
+  virtual mozilla::net::nsSimpleURI* StartClone(RefHandlingEnum /* unused */) override
   { return new nsHostObjectURI(); }
 
   nsCOMPtr<nsIPrincipal> mPrincipal;
 
 protected:
   virtual ~nsHostObjectURI() {}
 };
 
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -107,16 +107,17 @@
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 static const char *kPrefJavaMIME = "plugin.java.mime";
 static const char *kPrefYoutubeRewrite = "plugins.rewrite_youtube_embeds";
 static const char *kPrefBlockURIs = "browser.safebrowsing.blockedURIs.enabled";
 
 using namespace mozilla;
 using namespace mozilla::dom;
+using namespace mozilla::net;
 
 static LogModule*
 GetObjectLog()
 {
   static LazyLogModule sLog("objlc");
   return sLog;
 }
 
--- a/dom/jsurl/nsJSProtocolHandler.cpp
+++ b/dom/jsurl/nsJSProtocolHandler.cpp
@@ -1260,38 +1260,38 @@ nsJSProtocolHandler::AllowPort(int32_t p
 }
 
 ////////////////////////////////////////////////////////////
 // nsJSURI implementation
 static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
                      NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
 
 
-NS_IMPL_ADDREF_INHERITED(nsJSURI, nsSimpleURI)
-NS_IMPL_RELEASE_INHERITED(nsJSURI, nsSimpleURI)
+NS_IMPL_ADDREF_INHERITED(nsJSURI, mozilla::net::nsSimpleURI)
+NS_IMPL_RELEASE_INHERITED(nsJSURI, mozilla::net::nsSimpleURI)
 
 NS_INTERFACE_MAP_BEGIN(nsJSURI)
   if (aIID.Equals(kJSURICID))
       foundInterface = static_cast<nsIURI*>(this);
   else if (aIID.Equals(kThisSimpleURIImplementationCID)) {
       // Need to return explicitly here, because if we just set foundInterface
       // to null the NS_INTERFACE_MAP_END_INHERITING will end up calling into
       // nsSimplURI::QueryInterface and finding something for this CID.
       *aInstancePtr = nullptr;
       return NS_NOINTERFACE;
   }
   else
-NS_INTERFACE_MAP_END_INHERITING(nsSimpleURI)
+NS_INTERFACE_MAP_END_INHERITING(mozilla::net::nsSimpleURI)
 
 // nsISerializable methods:
 
 NS_IMETHODIMP
 nsJSURI::Read(nsIObjectInputStream* aStream)
 {
-    nsresult rv = nsSimpleURI::Read(aStream);
+    nsresult rv = mozilla::net::nsSimpleURI::Read(aStream);
     if (NS_FAILED(rv)) return rv;
 
     bool haveBase;
     rv = aStream->ReadBoolean(&haveBase);
     if (NS_FAILED(rv)) return rv;
 
     if (haveBase) {
         nsCOMPtr<nsISupports> supports;
@@ -1301,17 +1301,17 @@ nsJSURI::Read(nsIObjectInputStream* aStr
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJSURI::Write(nsIObjectOutputStream* aStream)
 {
-    nsresult rv = nsSimpleURI::Write(aStream);
+    nsresult rv = mozilla::net::nsSimpleURI::Write(aStream);
     if (NS_FAILED(rv)) return rv;
 
     rv = aStream->WriteBoolean(mBaseURI != nullptr);
     if (NS_FAILED(rv)) return rv;
 
     if (mBaseURI) {
         rv = aStream->WriteObject(mBaseURI, true);
         if (NS_FAILED(rv)) return rv;
@@ -1324,17 +1324,17 @@ nsJSURI::Write(nsIObjectOutputStream* aS
 void
 nsJSURI::Serialize(mozilla::ipc::URIParams& aParams)
 {
     using namespace mozilla::ipc;
 
     JSURIParams jsParams;
     URIParams simpleParams;
 
-    nsSimpleURI::Serialize(simpleParams);
+    mozilla::net::nsSimpleURI::Serialize(simpleParams);
 
     jsParams.simpleParams() = simpleParams;
     if (mBaseURI) {
         SerializeURI(mBaseURI, jsParams.baseURI());
     } else {
         jsParams.baseURI() = mozilla::void_t();
     }
 
@@ -1347,60 +1347,60 @@ nsJSURI::Deserialize(const mozilla::ipc:
     using namespace mozilla::ipc;
 
     if (aParams.type() != URIParams::TJSURIParams) {
         NS_ERROR("Received unknown parameters from the other process!");
         return false;
     }
 
     const JSURIParams& jsParams = aParams.get_JSURIParams();
-    nsSimpleURI::Deserialize(jsParams.simpleParams());
+    mozilla::net::nsSimpleURI::Deserialize(jsParams.simpleParams());
 
     if (jsParams.baseURI().type() != OptionalURIParams::Tvoid_t) {
         mBaseURI = DeserializeURI(jsParams.baseURI().get_URIParams());
     } else {
         mBaseURI = nullptr;
     }
     return true;
 }
 
 // nsSimpleURI methods:
-/* virtual */ nsSimpleURI*
-nsJSURI::StartClone(nsSimpleURI::RefHandlingEnum /* ignored */)
+/* virtual */ mozilla::net::nsSimpleURI*
+nsJSURI::StartClone(mozilla::net::nsSimpleURI::RefHandlingEnum /* ignored */)
 {
     nsCOMPtr<nsIURI> baseClone;
     if (mBaseURI) {
       // Note: We preserve ref on *base* URI, regardless of ref handling mode.
       nsresult rv = mBaseURI->Clone(getter_AddRefs(baseClone));
       if (NS_FAILED(rv)) {
         return nullptr;
       }
     }
 
     return new nsJSURI(baseClone);
 }
 
 /* virtual */ nsresult
 nsJSURI::EqualsInternal(nsIURI* aOther,
-                        nsSimpleURI::RefHandlingEnum aRefHandlingMode,
+                        mozilla::net::nsSimpleURI::RefHandlingEnum aRefHandlingMode,
                         bool* aResult)
 {
     NS_ENSURE_ARG_POINTER(aOther);
     NS_PRECONDITION(aResult, "null pointer for outparam");
 
     RefPtr<nsJSURI> otherJSURI;
     nsresult rv = aOther->QueryInterface(kJSURICID,
                                          getter_AddRefs(otherJSURI));
     if (NS_FAILED(rv)) {
         *aResult = false; // aOther is not a nsJSURI --> not equal.
         return NS_OK;
     }
 
     // Compare the member data that our base class knows about.
-    if (!nsSimpleURI::EqualsInternal(otherJSURI, aRefHandlingMode)) {
+    if (!mozilla::net::nsSimpleURI::EqualsInternal(otherJSURI, aRefHandlingMode)) {
         *aResult = false;
         return NS_OK;
     }
 
     // Compare the piece of additional member data that we add to base class.
     nsIURI* otherBaseURI = otherJSURI->GetBaseURI();
 
     if (mBaseURI) {
--- a/dom/jsurl/nsJSProtocolHandler.h
+++ b/dom/jsurl/nsJSProtocolHandler.h
@@ -56,35 +56,35 @@ protected:
 
     nsresult EnsureUTF8Spec(const nsAFlatCString &aSpec, const char *aCharset, 
                             nsACString &aUTF8Spec);
 
     nsCOMPtr<nsITextToSubURI>  mTextToSubURI;
 };
 
 
-class nsJSURI : public nsSimpleURI
+class nsJSURI : public mozilla::net::nsSimpleURI
 {
 public:
-    using nsSimpleURI::Read;
-    using nsSimpleURI::Write;
+    using mozilla::net::nsSimpleURI::Read;
+    using mozilla::net::nsSimpleURI::Write;
 
     nsJSURI() {}
 
     explicit nsJSURI(nsIURI* aBaseURI) : mBaseURI(aBaseURI) {}
 
     nsIURI* GetBaseURI() const
     {
         return mBaseURI;
     }
 
     NS_DECL_ISUPPORTS_INHERITED
 
     // nsIURI overrides
-    virtual nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode) override;
+    virtual mozilla::net::nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode) override;
 
     // nsISerializable overrides
     NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
     NS_IMETHOD Write(nsIObjectOutputStream* aStream) override;
 
     // nsIIPCSerializableURI overrides
     NS_DECL_NSIIPCSERIALIZABLEURI
 
--- a/dom/network/TCPSocketParent.cpp
+++ b/dom/network/TCPSocketParent.cpp
@@ -16,34 +16,37 @@
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/HoldDropJSObjects.h"
 #include "nsISocketTransportService.h"
 #include "nsISocketTransport.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsNetUtil.h"
 
-//
-// set NSPR_LOG_MODULES=TCPSocket:5
-//
-extern mozilla::LazyLogModule gTCPSocketLog;
-#define TCPSOCKET_LOG(args)     MOZ_LOG(gTCPSocketLog, mozilla::LogLevel::Debug, args)
-#define TCPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gTCPSocketLog, mozilla::LogLevel::Debug)
-
 namespace IPC {
 
 //Defined in TCPSocketChild.cpp
 extern bool
 DeserializeArrayBuffer(JSContext* aCx,
                        const InfallibleTArray<uint8_t>& aBuffer,
                        JS::MutableHandle<JS::Value> aVal);
 
 } // namespace IPC
 
 namespace mozilla {
+
+namespace net {
+//
+// set NSPR_LOG_MODULES=TCPSocket:5
+//
+extern LazyLogModule gTCPSocketLog;
+#define TCPSOCKET_LOG(args)     MOZ_LOG(gTCPSocketLog, LogLevel::Debug, args)
+#define TCPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gTCPSocketLog, LogLevel::Debug)
+} // namespace net
+
 namespace dom {
 
 static void
 FireInteralError(mozilla::net::PTCPSocketParent* aActor, uint32_t aLineNo)
 {
   mozilla::Unused <<
       aActor->SendCallback(NS_LITERAL_STRING("onerror"),
                            TCPError(NS_LITERAL_STRING("InvalidStateError"), NS_LITERAL_STRING("Internal error")),
--- a/dom/network/UDPSocket.h
+++ b/dom/network/UDPSocket.h
@@ -16,21 +16,24 @@
 #include "nsIUDPSocketChild.h"
 #include "nsTArray.h"
 
 struct JSContext;
 
 //
 // set NSPR_LOG_MODULES=UDPSocket:5
 //
-extern mozilla::LazyLogModule gUDPSocketLog;
-#define UDPSOCKET_LOG(args)     MOZ_LOG(gUDPSocketLog, mozilla::LogLevel::Debug, args)
-#define UDPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gUDPSocketLog, mozilla::LogLevel::Debug)
 
 namespace mozilla {
+namespace net {
+extern LazyLogModule gUDPSocketLog;
+#define UDPSOCKET_LOG(args)     MOZ_LOG(gUDPSocketLog, LogLevel::Debug, args)
+#define UDPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gUDPSocketLog, LogLevel::Debug)
+} // namespace net
+
 namespace dom {
 
 struct UDPOptions;
 class StringOrBlobOrArrayBufferOrArrayBufferView;
 
 class UDPSocket final : public DOMEventTargetHelper
                       , public nsIUDPSocketListener
                       , public nsIUDPSocketInternal
--- a/dom/network/UDPSocketChild.cpp
+++ b/dom/network/UDPSocketChild.cpp
@@ -12,23 +12,16 @@
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/ipc/BackgroundUtils.h"
 #include "mozilla/ipc/PBackgroundSharedTypes.h"
 #include "nsIIPCBackgroundChildCreateCallback.h"
 
 using mozilla::net::gNeckoChild;
 
-//
-// set NSPR_LOG_MODULES=UDPSocket:5
-//
-extern mozilla::LazyLogModule gUDPSocketLog;
-#define UDPSOCKET_LOG(args)     MOZ_LOG(gUDPSocketLog, mozilla::LogLevel::Debug, args)
-#define UDPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gUDPSocketLog, mozilla::LogLevel::Debug)
-
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_ISUPPORTS(UDPSocketChildBase, nsIUDPSocketChild)
 
 UDPSocketChildBase::UDPSocketChildBase()
 : mIPCOpen(false)
 {
--- a/dom/network/UDPSocketParent.cpp
+++ b/dom/network/UDPSocketParent.cpp
@@ -18,23 +18,16 @@
 #include "nsNetUtil.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/TabParent.h"
 #include "nsIPermissionManager.h"
 #include "nsIScriptSecurityManager.h"
 #include "mozilla/ipc/PBackgroundParent.h"
 #include "mtransport/runnable_utils.h"
 
-//
-// set NSPR_LOG_MODULES=UDPSocket:5
-//
-extern mozilla::LazyLogModule gUDPSocketLog;
-#define UDPSOCKET_LOG(args)     MOZ_LOG(gUDPSocketLog, mozilla::LogLevel::Debug, args)
-#define UDPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gUDPSocketLog, mozilla::LogLevel::Debug)
-
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_ISUPPORTS(UDPSocketParent, nsIUDPSocketListener)
 
 UDPSocketParent::UDPSocketParent(PBackgroundParent* aManager)
   : mBackgroundManager(aManager)
   , mNeckoManager(nullptr)
--- a/dom/security/nsCSPService.cpp
+++ b/dom/security/nsCSPService.cpp
@@ -241,17 +241,17 @@ CSPService::ShouldProcess(uint32_t      
 
 /* nsIChannelEventSink implementation */
 NS_IMETHODIMP
 CSPService::AsyncOnChannelRedirect(nsIChannel *oldChannel,
                                    nsIChannel *newChannel,
                                    uint32_t flags,
                                    nsIAsyncVerifyRedirectCallback *callback)
 {
-  nsAsyncRedirectAutoCallback autoCallback(callback);
+  net::nsAsyncRedirectAutoCallback autoCallback(callback);
 
   nsCOMPtr<nsIURI> newUri;
   nsresult rv = newChannel->GetURI(getter_AddRefs(newUri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsILoadInfo> loadInfo = oldChannel->GetLoadInfo();
 
   // if no loadInfo on the channel, nothing for us to do
--- a/dom/xslt/base/txURIUtils.cpp
+++ b/dom/xslt/base/txURIUtils.cpp
@@ -5,17 +5,17 @@
 
 #include "txURIUtils.h"
 #include "nsNetUtil.h"
 #include "nsIDocument.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIPrincipal.h"
 #include "mozilla/LoadInfo.h"
 
-using mozilla::LoadInfo;
+using mozilla::net::LoadInfo;
 
 /**
  * URIUtils
  * A set of utilities for handling URIs
 **/
 
 /**
  * Resolves the given href argument, using the given documentBase
--- a/netwerk/base/LoadInfo.cpp
+++ b/netwerk/base/LoadInfo.cpp
@@ -19,16 +19,17 @@
 #include "nsISupportsUtils.h"
 #include "nsContentUtils.h"
 #include "nsDocShell.h"
 #include "nsGlobalWindow.h"
 
 using namespace mozilla::dom;
 
 namespace mozilla {
+namespace net {
 
 static void
 InheritOriginAttributes(nsIPrincipal* aLoadingPrincipal, NeckoOriginAttributes& aAttrs)
 {
   const PrincipalOriginAttributes attrs =
     BasePrincipal::Cast(aLoadingPrincipal)->OriginAttributesRef();
   aAttrs.InheritFromDocToNecko(attrs);
 }
@@ -720,9 +721,10 @@ LoadInfo::MaybeIncreaseTainting(uint32_t
   NS_ENSURE_ARG(aTainting <= TAINTING_OPAQUE);
   LoadTainting tainting = static_cast<LoadTainting>(aTainting);
   if (tainting > mTainting) {
     mTainting = tainting;
   }
   return NS_OK;
 }
 
+} // namespace net
 } // namespace mozilla
--- a/netwerk/base/LoadInfo.h
+++ b/netwerk/base/LoadInfo.h
@@ -28,16 +28,18 @@ class OptionalLoadInfoArgs;
 
 namespace ipc {
 // we have to forward declare that function so we can use it as a friend.
 nsresult
 LoadInfoArgsToLoadInfo(const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs,
                        nsILoadInfo** outLoadInfo);
 } // namespace ipc
 
+namespace net {
+
 /**
  * Class that provides an nsILoadInfo implementation.
  *
  * Note that there is no reason why this class should be MOZ_EXPORT, but
  * Thunderbird relies on some insane hacks which require this, so we'll leave it
  * as is for now, but hopefully we'll be able to remove the MOZ_EXPORT keyword
  * from this class at some point.  See bug 1149127 for the discussion.
  */
@@ -130,12 +132,13 @@ private:
   NeckoOriginAttributes            mOriginAttributes;
   nsTArray<nsCOMPtr<nsIPrincipal>> mRedirectChainIncludingInternalRedirects;
   nsTArray<nsCOMPtr<nsIPrincipal>> mRedirectChain;
   nsTArray<nsCString>              mCorsUnsafeHeaders;
   bool                             mForcePreflight;
   bool                             mIsPreflight;
 };
 
+} // namespace net
 } // namespace mozilla
 
 #endif // mozilla_LoadInfo_h
 
--- a/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
+++ b/netwerk/base/nsAsyncRedirectVerifyHelper.cpp
@@ -9,25 +9,28 @@
 #include "nsNetUtil.h"
 
 #include "nsIOService.h"
 #include "nsIChannel.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsILoadInfo.h"
 
-static mozilla::LazyLogModule gRedirectLog("nsRedirect");
+namespace mozilla {
+namespace net {
+
+static LazyLogModule gRedirectLog("nsRedirect");
 #undef LOG
-#define LOG(args) MOZ_LOG(gRedirectLog, mozilla::LogLevel::Debug, args)
+#define LOG(args) MOZ_LOG(gRedirectLog, LogLevel::Debug, args)
 
 NS_IMPL_ISUPPORTS(nsAsyncRedirectVerifyHelper,
                   nsIAsyncVerifyRedirectCallback,
                   nsIRunnable)
 
-class nsAsyncVerifyRedirectCallbackEvent : public mozilla::Runnable {
+class nsAsyncVerifyRedirectCallbackEvent : public Runnable {
 public:
     nsAsyncVerifyRedirectCallbackEvent(nsIAsyncVerifyRedirectCallback *cb,
                                        nsresult result)
         : mCallback(cb), mResult(result) {
     }
 
     NS_IMETHOD Run()
     {
@@ -267,8 +270,11 @@ nsAsyncRedirectVerifyHelper::IsOldChanne
         mOldChan->GetStatus(&status);
         if (NS_FAILED(status)) {
             return true;
         }
     }
 
     return false;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsAsyncRedirectVerifyHelper.h
+++ b/netwerk/base/nsAsyncRedirectVerifyHelper.h
@@ -13,16 +13,19 @@
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "mozilla/Attributes.h"
 
 class nsIChannel;
 
+namespace mozilla {
+namespace net {
+
 /**
  * This class simplifies call of OnChannelRedirect of IOService and
  * the sink bound with the channel being redirected while the result of
  * redirect decision is returned through the callback.
  */
 class nsAsyncRedirectVerifyHelper final : public nsIRunnable,
                                           public nsIAsyncVerifyRedirectCallback
 {
@@ -116,9 +119,11 @@ public:
     {
         mCallback = nullptr;
     }
 private:
     nsIAsyncVerifyRedirectCallback* mCallback;
     nsresult mResult;
 };
 
+} // namespace net
+} // namespace mozilla
 #endif
--- a/netwerk/base/nsChannelClassifier.cpp
+++ b/netwerk/base/nsChannelClassifier.cpp
@@ -30,27 +30,27 @@
 #include "nsNetUtil.h"
 #include "nsPIDOMWindow.h"
 #include "nsXULAppAPI.h"
 
 #include "mozilla/ErrorNames.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Preferences.h"
 
-using mozilla::ArrayLength;
-using mozilla::Preferences;
+namespace mozilla {
+namespace net {
 
 //
 // NSPR_LOG_MODULES=nsChannelClassifier:5
 //
-static mozilla::LazyLogModule gChannelClassifierLog("nsChannelClassifier");
+static LazyLogModule gChannelClassifierLog("nsChannelClassifier");
 
 #undef LOG
-#define LOG(args)     MOZ_LOG(gChannelClassifierLog, mozilla::LogLevel::Debug, args)
-#define LOG_ENABLED() MOZ_LOG_TEST(gChannelClassifierLog, mozilla::LogLevel::Debug)
+#define LOG(args)     MOZ_LOG(gChannelClassifierLog, LogLevel::Debug, args)
+#define LOG_ENABLED() MOZ_LOG_TEST(gChannelClassifierLog, LogLevel::Debug)
 
 NS_IMPL_ISUPPORTS(nsChannelClassifier,
                   nsIURIClassifierCallback)
 
 nsChannelClassifier::nsChannelClassifier()
   : mIsAllowListed(false),
     mSuspendedChannel(false)
 {
@@ -419,17 +419,17 @@ nsChannelClassifier::MarkEntryClassified
 
     // Don't cache tracking classifications because we support allowlisting.
     if (status == NS_ERROR_TRACKING_URI || mIsAllowListed) {
         return;
     }
 
     if (LOG_ENABLED()) {
       nsAutoCString errorName;
-      mozilla::GetErrorName(status, errorName);
+      GetErrorName(status, errorName);
       nsCOMPtr<nsIURI> uri;
       mChannel->GetURI(getter_AddRefs(uri));
       nsAutoCString spec;
       uri->GetAsciiSpec(spec);
       LOG(("nsChannelClassifier::MarkEntryClassified[%s] %s",
            errorName.get(), spec.get()));
     }
 
@@ -661,17 +661,17 @@ nsChannelClassifier::OnClassifyComplete(
       LOG(("nsChannelClassifier[%p]:OnClassifyComplete tracker found "
            "in whitelist so we won't block it", this));
       aErrorCode = NS_OK;
     }
 
     if (mSuspendedChannel) {
       nsAutoCString errorName;
       if (LOG_ENABLED()) {
-        mozilla::GetErrorName(aErrorCode, errorName);
+        GetErrorName(aErrorCode, errorName);
         LOG(("nsChannelClassifier[%p]:OnClassifyComplete %s (suspended channel)",
              this, errorName.get()));
       }
       MarkEntryClassified(aErrorCode);
 
       if (NS_FAILED(aErrorCode)) {
         if (LOG_ENABLED()) {
           nsCOMPtr<nsIURI> uri;
@@ -696,8 +696,11 @@ nsChannelClassifier::OnClassifyComplete(
            "OnClassifyComplete", this, mChannel.get()));
       mChannel->Resume();
     }
 
     mChannel = nullptr;
 
     return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsChannelClassifier.h
+++ b/netwerk/base/nsChannelClassifier.h
@@ -8,16 +8,19 @@
 #include "nsIURIClassifier.h"
 #include "nsCOMPtr.h"
 #include "mozilla/Attributes.h"
 
 class nsIChannel;
 class nsIHttpChannelInternal;
 class nsIDocument;
 
+namespace mozilla {
+namespace net {
+
 class nsChannelClassifier final : public nsIURIClassifierCallback
 {
 public:
     nsChannelClassifier();
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIURICLASSIFIERCALLBACK
 
@@ -51,9 +54,12 @@ private:
 
 public:
     // If we are blocking tracking content, update the corresponding flag in
     // the respective docshell and call nsISecurityEventSink::onSecurityChange.
     static nsresult SetBlockedTrackingContent(nsIChannel *channel);
     static nsresult NotifyTrackingProtectionDisabled(nsIChannel *aChannel);
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif
--- a/netwerk/base/nsIOService.cpp
+++ b/netwerk/base/nsIOService.cpp
@@ -57,19 +57,18 @@
 #include "nsContentSecurityManager.h"
 #include "nsContentUtils.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include "nsINetworkManager.h"
 #include "nsINetworkInterface.h"
 #endif
 
-using namespace mozilla;
-using mozilla::net::IsNeckoChild;
-using mozilla::net::CaptivePortalService;
+namespace mozilla {
+namespace net {
 
 #define PORT_PREF_PREFIX           "network.security.ports."
 #define PORT_PREF(x)               PORT_PREF_PREFIX x
 #define MANAGE_OFFLINE_STATUS_PREF "network.manage-offline-status"
 #define OFFLINE_MIRRORS_CONNECTIVITY "network.offline-mirrors-connectivity"
 
 // Nb: these have been misnomers since bug 715770 removed the buffer cache.
 // "network.segment.count" and "network.segment.size" would be better names,
@@ -79,19 +78,19 @@ using mozilla::net::CaptivePortalService
 #define NETWORK_NOTIFY_CHANGED_PREF   "network.notify.changed"
 #define NETWORK_CAPTIVE_PORTAL_PREF   "network.captive-portal-service.enabled"
 
 #define MAX_RECURSION_COUNT 50
 
 nsIOService* gIOService = nullptr;
 static bool gHasWarnedUploadChannel2;
 
-static mozilla::LazyLogModule gIOServiceLog("nsIOService");
+static LazyLogModule gIOServiceLog("nsIOService");
 #undef LOG
-#define LOG(args)     MOZ_LOG(gIOServiceLog, mozilla::LogLevel::Debug, args)
+#define LOG(args)     MOZ_LOG(gIOServiceLog, LogLevel::Debug, args)
 
 // A general port blacklist.  Connections to these ports will not be allowed
 // unless the protocol overrides.
 //
 // TODO: I am sure that there are more ports to be added.  
 //       This cut is based on the classic mozilla codebase
 
 int16_t gBadPortList[] = {
@@ -236,18 +235,17 @@ nsIOService::Init()
         prefBranch->AddObserver(NECKO_BUFFER_CACHE_COUNT_PREF, this, true);
         prefBranch->AddObserver(NECKO_BUFFER_CACHE_SIZE_PREF, this, true);
         prefBranch->AddObserver(NETWORK_NOTIFY_CHANGED_PREF, this, true);
         prefBranch->AddObserver(NETWORK_CAPTIVE_PORTAL_PREF, this, true);
         PrefsChanged(prefBranch);
     }
     
     // Register for profile change notifications
-    nsCOMPtr<nsIObserverService> observerService =
-        mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
     if (observerService) {
         observerService->AddObserver(this, kProfileChangeNetTeardownTopic, true);
         observerService->AddObserver(this, kProfileChangeNetRestoreTopic, true);
         observerService->AddObserver(this, kProfileDoChange, true);
         observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
         observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
         observerService->AddObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC, true);
         observerService->AddObserver(this, kNetworkActiveChanged, true);
@@ -402,17 +400,17 @@ nsIOService::RecheckCaptivePortalIfLocal
 
     PRNetAddr prAddr;
     if (PR_StringToNetAddr(host.BeginReading(), &prAddr) != PR_SUCCESS) {
         // The redirect wasn't to an IP literal, so there's probably no need
         // to trigger the captive portal detection right now. It can wait.
         return NS_OK;
     }
 
-    mozilla::net::NetAddr netAddr;
+    NetAddr netAddr;
     PRNetAddrToNetAddr(&prAddr, &netAddr);
     if (IsIPAddrLocal(&netAddr)) {
         // Redirects to local IP addresses are probably captive portals
         mCaptivePortalService->RecheckCaptivePortal();
     }
 
     return NS_OK;
 }
@@ -875,21 +873,21 @@ nsIOService::NewChannelFromURIWithProxyF
     // loadingNode and loadingPrincipal are allowed to have null values.
     nsCOMPtr<nsILoadInfo> loadInfo;
 
     // TYPE_DOCUMENT loads don't require a loadingNode or principal, but other
     // types do.
     if (aLoadingNode || aLoadingPrincipal ||
         aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) {
       nsCOMPtr<nsINode> loadingNode(do_QueryInterface(aLoadingNode));
-      loadInfo = new mozilla::LoadInfo(aLoadingPrincipal,
-                                       aTriggeringPrincipal,
-                                       loadingNode,
-                                       aSecurityFlags,
-                                       aContentPolicyType);
+      loadInfo = new LoadInfo(aLoadingPrincipal,
+                              aTriggeringPrincipal,
+                              loadingNode,
+                              aSecurityFlags,
+                              aContentPolicyType);
     }
     NS_ASSERTION(loadInfo, "Please pass security info when creating a channel");
     return NewChannelFromURIWithProxyFlagsInternal(aURI,
                                                    aProxyURI,
                                                    aProxyFlags,
                                                    loadInfo,
                                                    result);
 }
@@ -1043,18 +1041,17 @@ nsIOService::SetOffline(bool offline)
     // down the service.
     mSetOfflineValue = offline;
     if (mSettingOffline) {
         return NS_OK;
     }
 
     mSettingOffline = true;
 
-    nsCOMPtr<nsIObserverService> observerService =
-        mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
 
     NS_ASSERTION(observerService, "The observer service should not be null");
 
     if (XRE_IsParentProcess()) {
         if (observerService) {
             (void)observerService->NotifyObservers(nullptr,
                 NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC, offline ? 
                 MOZ_UTF16("true") :
@@ -1157,18 +1154,17 @@ nsIOService::SetConnectivityInternal(boo
         return NS_OK;
     }
     mConnectivity = aConnectivity;
 
     // This is used for PR_Connect PR_Close telemetry so it is important that
     // we have statistic about network change event even if we are offline.
     mLastConnectivityChange = PR_IntervalNow();
 
-    nsCOMPtr<nsIObserverService> observerService =
-        mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
     if (!observerService) {
         return NS_OK;
     }
     // This notification sends the connectivity to the child processes
     if (XRE_IsParentProcess()) {
         observerService->NotifyObservers(nullptr,
             NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC, aConnectivity ?
             MOZ_UTF16("true") :
@@ -1422,18 +1418,17 @@ public:
 private:
     virtual ~nsWakeupNotifier() { }
     nsCOMPtr<nsIIOServiceInternal> mIOService;
 };
 
 NS_IMETHODIMP
 nsIOService::NotifyWakeup()
 {
-    nsCOMPtr<nsIObserverService> observerService =
-        mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
 
     NS_ASSERTION(observerService, "The observer service should not be null");
 
     if (observerService && mNetworkNotifyChanged) {
         (void)observerService->
             NotifyObservers(nullptr,
                             NS_NETWORK_LINK_TOPIC,
                             MOZ_UTF16(NS_NETWORK_LINK_DATA_CHANGED));
@@ -1781,17 +1776,17 @@ nsIOService::ExtractCharsetFromContentTy
 }
 
 // parse policyString to policy enum value (see ReferrerPolicy.h)
 NS_IMETHODIMP
 nsIOService::ParseAttributePolicyString(const nsAString& policyString,
                                                 uint32_t *outPolicyEnum)
 {
   NS_ENSURE_ARG(outPolicyEnum);
-  *outPolicyEnum = (uint32_t)mozilla::net::AttributeReferrerPolicyFromString(policyString);
+  *outPolicyEnum = (uint32_t)AttributeReferrerPolicyFromString(policyString);
   return NS_OK;
 }
 
 // nsISpeculativeConnect
 class IOServiceProxyCallback final : public nsIProtocolProxyCallback
 {
     ~IOServiceProxyCallback() {}
 
@@ -1933,18 +1928,17 @@ nsIOService::SpeculativeAnonymousConnect
 }
 
 void
 nsIOService::NotifyAppOfflineStatus(uint32_t appId, int32_t state)
 {
     MOZ_RELEASE_ASSERT(NS_IsMainThread(),
             "Should be called on the main thread");
 
-    nsCOMPtr<nsIObserverService> observerService =
-        mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
     MOZ_ASSERT(observerService, "The observer service should not be null");
 
     if (observerService) {
         RefPtr<nsAppOfflineInfo> info = new nsAppOfflineInfo(appId, state);
         observerService->NotifyObservers(
             info,
             NS_IOSERVICE_APP_OFFLINE_STATUS_TOPIC,
             MOZ_UTF16("all data in nsIAppOfflineInfo subject argument"));
@@ -2090,8 +2084,11 @@ nsIOService::IsAppOffline(uint32_t aAppI
         default:
             // The app is online by default
             break;
         }
     }
 
     return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsIOService.h
+++ b/netwerk/base/nsIOService.h
@@ -29,29 +29,27 @@
 // Intended internal use only for remoting offline/inline events.
 // See Bug 552829
 #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
 #define NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC "ipc:network:set-connectivity"
 
 static const char gScheme[][sizeof("moz-safe-about")] =
     {"chrome", "file", "http", "https", "jar", "data", "about", "moz-safe-about", "resource"};
 
-class nsAsyncRedirectVerifyHelper;
 class nsINetworkLinkService;
 class nsIPrefBranch;
 class nsIProtocolProxyService2;
 class nsIProxyInfo;
 class nsPIDNSService;
 class nsPISocketTransportService;
 
 namespace mozilla {
 namespace net {
-    class NeckoChild;
-} // namespace net
-} // namespace mozilla
+class NeckoChild;
+class nsAsyncRedirectVerifyHelper;
 
 class nsIOService final : public nsIIOService2
                         , public nsIObserver
                         , public nsINetUtil
                         , public nsISpeculativeConnect
                         , public nsSupportsWeakReference
                         , public nsIIOServiceInternal
 {
@@ -237,9 +235,12 @@ private:
     int32_t mMode;
 };
 
 /**
  * Reference to the IO service singleton. May be null.
  */
 extern nsIOService* gIOService;
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsIOService_h__
--- a/netwerk/base/nsInputStreamChannel.cpp
+++ b/netwerk/base/nsInputStreamChannel.cpp
@@ -3,16 +3,19 @@
  * 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 "nsInputStreamChannel.h"
 
 //-----------------------------------------------------------------------------
 // nsInputStreamChannel
 
+namespace mozilla {
+namespace net {
+
 nsresult
 nsInputStreamChannel::OpenContentStream(bool async, nsIInputStream **result,
                                         nsIChannel** channel)
 {
   NS_ENSURE_TRUE(mContentStream, NS_ERROR_NOT_INITIALIZED);
 
   // If content length is unknown, then we must guess.  In this case, we assume
   // the stream can tell us.  If the stream is a pipe, then this will not work.
@@ -99,8 +102,11 @@ nsInputStreamChannel::GetBaseURI(nsIURI*
 }
 
 NS_IMETHODIMP
 nsInputStreamChannel::SetBaseURI(nsIURI* aBaseURI)
 {
   mBaseURI = aBaseURI;
   return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsInputStreamChannel.h
+++ b/netwerk/base/nsInputStreamChannel.h
@@ -6,16 +6,19 @@
 #ifndef nsInputStreamChannel_h__
 #define nsInputStreamChannel_h__
 
 #include "nsBaseChannel.h"
 #include "nsIInputStreamChannel.h"
 
 //-----------------------------------------------------------------------------
 
+namespace mozilla {
+namespace net {
+
 class nsInputStreamChannel : public nsBaseChannel
                            , public nsIInputStreamChannel
 {
 public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSIINPUTSTREAMCHANNEL
 
     nsInputStreamChannel() :
@@ -33,9 +36,12 @@ protected:
 
 private:
     nsCOMPtr<nsIInputStream> mContentStream;
     nsCOMPtr<nsIURI> mBaseURI;
     nsString mSrcdocData;
     bool mIsSrcdocChannel;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // !nsInputStreamChannel_h__
--- a/netwerk/base/nsLoadGroup.cpp
+++ b/netwerk/base/nsLoadGroup.cpp
@@ -19,18 +19,18 @@
 #include "nsIInterfaceRequestor.h"
 #include "nsIRequestObserver.h"
 #include "nsIRequestContext.h"
 #include "CacheObserver.h"
 #include "MainThreadUtils.h"
 
 #include "mozilla/net/NeckoChild.h"
 
-using namespace mozilla;
-using namespace mozilla::net;
+namespace mozilla {
+namespace net {
 
 //
 // Log module for nsILoadGroup logging...
 //
 // To enable logging (see prlog.h for full details):
 //
 //    set NSPR_LOG_MODULES=LoadGroup:5
 //    set NSPR_LOG_FILE=nspr.log
@@ -1076,9 +1076,12 @@ nsresult nsLoadGroup::Init()
             mRequestContextService->GetRequestContext(requestContextID,
                                                       getter_AddRefs(mRequestContext));
         }
     }
 
     return NS_OK;
 }
 
+} // namespace net
+} // namespace mozilla
+
 #undef LOG
--- a/netwerk/base/nsLoadGroup.h
+++ b/netwerk/base/nsLoadGroup.h
@@ -16,16 +16,19 @@
 #include "nsISupportsPriority.h"
 #include "PLDHashTable.h"
 #include "mozilla/TimeStamp.h"
 
 class nsIRequestContext;
 class nsIRequestContextService;
 class nsITimedChannel;
 
+namespace mozilla {
+namespace net {
+
 class nsLoadGroup : public nsILoadGroup,
                     public nsILoadGroupChild,
                     public nsISupportsPriority,
                     public nsSupportsWeakReference,
                     public nsPILoadGroupInternal
 {
 public:
     NS_DECL_AGGREGATED
@@ -91,9 +94,12 @@ protected:
     uint32_t                        mCachedRequests;
 
     /* For nsPILoadGroupInternal */
     uint32_t                        mTimedNonCachedRequestsUntilOnEndPageLoad;
 
     nsCString                       mUserAgentOverrideCache;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsLoadGroup_h__
--- a/netwerk/base/nsNetSegmentUtils.h
+++ b/netwerk/base/nsNetSegmentUtils.h
@@ -9,15 +9,15 @@
 
 /**
  * applies defaults to segment params in a consistent way.
  */
 static inline void
 net_ResolveSegmentParams(uint32_t &segsize, uint32_t &segcount)
 {
     if (!segsize)
-        segsize = nsIOService::gDefaultSegmentSize;
+        segsize = mozilla::net::nsIOService::gDefaultSegmentSize;
 
     if (!segcount)
-        segcount = nsIOService::gDefaultSegmentCount;
+        segcount = mozilla::net::nsIOService::gDefaultSegmentCount;
 }
 
 #endif // !nsNetSegmentUtils_h__
--- a/netwerk/base/nsPACMan.cpp
+++ b/netwerk/base/nsPACMan.cpp
@@ -17,27 +17,24 @@
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsISystemProxySettings.h"
 #include "nsContentUtils.h"
 #ifdef MOZ_NUWA_PROCESS
 #include "ipc/Nuwa.h"
 #endif
 
 //-----------------------------------------------------------------------------
-using namespace mozilla;
-using namespace mozilla::net;
 
 namespace mozilla {
 namespace net {
+
 LazyLogModule gProxyLog("proxy");
-} // namespace net
-} // namespace mozilla
 
 #undef LOG
-#define LOG(args) MOZ_LOG(mozilla::net::gProxyLog, mozilla::LogLevel::Debug, args)
+#define LOG(args) MOZ_LOG(gProxyLog, LogLevel::Debug, args)
 
 // The PAC thread does evaluations of both PAC files and
 // nsISystemProxySettings because they can both block the calling thread and we
 // don't want that on the main thread
 
 // Check to see if the underlying request was not an error page in the case of
 // a HTTP request.  For other types of channels, just return true.
 static bool
@@ -783,8 +780,11 @@ nsPACMan::Init(nsISystemProxySettings *s
     return rv;
 
   // don't check return value as it is not a big deal for this to fail.
   mPACThread->Dispatch(NewRunnableMethod(this, &nsPACMan::NamePACThread),
                        nsIEventTarget::DISPATCH_NORMAL);
 
   return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsPACMan.h
+++ b/netwerk/base/nsPACMan.h
@@ -17,19 +17,23 @@
 #include "nsString.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/LinkedList.h"
 #include "nsAutoPtr.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Atomics.h"
 
-class nsPACMan;
 class nsISystemProxySettings;
 class nsIThread;
+
+namespace mozilla {
+namespace net {
+
+class nsPACMan;
 class WaitForThreadShutdown;
 
 /**
  * This class defines a callback interface used by AsyncGetProxyForURI.
  */
 class NS_NO_VTABLE nsPACManCallback : public nsISupports
 {
 public:
@@ -46,18 +50,18 @@ public:
    *        before the query is evaluated again. At least one of pacString and
    *        newPACURL should be 0 length.
    */
   virtual void OnQueryComplete(nsresult status,
                                const nsCString &pacString,
                                const nsCString &newPACURL) = 0;
 };
 
-class PendingPACQuery final : public mozilla::Runnable,
-                              public mozilla::LinkedListElement<PendingPACQuery>
+class PendingPACQuery final : public Runnable,
+                              public LinkedListElement<PendingPACQuery>
 {
 public:
   PendingPACQuery(nsPACMan *pacMan, nsIURI *uri, uint32_t appId,
                   bool isInIsolatedMozBrowser, nsPACManCallback *callback,
                   bool mainThreadResponse);
 
   // can be called from either thread
   void Complete(nsresult status, const nsCString &pacString);
@@ -213,37 +217,36 @@ private:
 
   // PAC thread operations only
   void PostProcessPendingQ();
   void PostCancelPendingQ(nsresult);
   bool ProcessPending();
   void NamePACThread();
 
 private:
-  mozilla::net::ProxyAutoConfig mPAC;
+  ProxyAutoConfig mPAC;
   nsCOMPtr<nsIThread>           mPACThread;
   nsCOMPtr<nsISystemProxySettings> mSystemProxySettings;
 
-  mozilla::LinkedList<PendingPACQuery> mPendingQ; /* pac thread only */
+  LinkedList<PendingPACQuery> mPendingQ; /* pac thread only */
 
   // These specs are not nsIURI so that they can be used off the main thread.
   // The non-normalized versions are directly from the configuration, the
   // normalized version has been extracted from an nsIURI
   nsCString                    mPACURISpec;
   nsCString                    mPACURIRedirectSpec;
   nsCString                    mNormalPACURISpec;
 
   nsCOMPtr<nsIStreamLoader>    mLoader;
   bool                         mLoadPending;
-  mozilla::Atomic<bool, mozilla::Relaxed> mShutdown;
-  mozilla::TimeStamp           mScheduledReload;
+  Atomic<bool, Relaxed>        mShutdown;
+  TimeStamp                    mScheduledReload;
   uint32_t                     mLoadFailureCount;
 
   bool                         mInProgress;
 };
 
-namespace mozilla {
-namespace net {
 extern LazyLogModule gProxyLog;
+
 } // namespace net
 } // namespace mozilla
 
 #endif  // nsPACMan_h__
--- a/netwerk/base/nsProtocolProxyService.cpp
+++ b/netwerk/base/nsProtocolProxyService.cpp
@@ -29,33 +29,32 @@
 #include "prnetdb.h"
 #include "nsPACMan.h"
 #include "nsProxyRelease.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/CondVar.h"
 #include "nsISystemProxySettings.h"
 #include "nsINetworkLinkService.h"
 #include "nsIHttpChannelInternal.h"
+#include "mozilla/Logging.h"
 
 //----------------------------------------------------------------------------
 
 namespace mozilla {
+namespace net {
+
   extern const char kProxyType_HTTP[];
   extern const char kProxyType_HTTPS[];
   extern const char kProxyType_SOCKS[];
   extern const char kProxyType_SOCKS4[];
   extern const char kProxyType_SOCKS5[];
   extern const char kProxyType_DIRECT[];
-} // namespace mozilla
 
-using namespace mozilla;
-
-#include "mozilla/Logging.h"
 #undef LOG
-#define LOG(args) MOZ_LOG(net::gProxyLog, mozilla::LogLevel::Debug, args)
+#define LOG(args) MOZ_LOG(gProxyLog, LogLevel::Debug, args)
 
 //----------------------------------------------------------------------------
 
 #define PROXY_PREF_BRANCH  "network.proxy"
 #define PROXY_PREF(x)      PROXY_PREF_BRANCH "." x
 
 #define WPAD_URL "http://wpad/wpad.dat"
 
@@ -453,17 +452,17 @@ nsProtocolProxyService::Init()
     if (prefBranch) {
         // monitor proxy prefs
         prefBranch->AddObserver(PROXY_PREF_BRANCH, this, false);
 
         // read all prefs
         PrefsChanged(prefBranch, nullptr);
     }
 
-    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+    nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
     if (obs) {
         // register for shutdown notification so we can clean ourselves up
         // properly.
         obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
         obs->AddObserver(this, NS_NETWORK_LINK_TOPIC, false);
     }
 
     return NS_OK;
@@ -531,17 +530,17 @@ nsProtocolProxyService::Observe(nsISuppo
             delete mFilters;
             mFilters = nullptr;
         }
         if (mPACMan) {
             mPACMan->Shutdown();
             mPACMan = nullptr;
         }
 
-        nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+        nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
         if (obs) {
             obs->RemoveObserver(this, NS_NETWORK_LINK_TOPIC);
             obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
         }
 
     } else if (strcmp(aTopic, NS_NETWORK_LINK_TOPIC) == 0) {
         nsCString converted = NS_ConvertUTF16toUTF8(aData);
         const char *state = converted.get();
@@ -800,25 +799,23 @@ nsProtocolProxyService::CanUseProxy(nsIU
             }
         }
     }
     return true;
 }
 
 // kProxyType\* may be referred to externally in
 // nsProxyInfo in order to compare by string pointer
-namespace mozilla {
 const char kProxyType_HTTP[]    = "http";
 const char kProxyType_HTTPS[]   = "https";
 const char kProxyType_PROXY[]   = "proxy";
 const char kProxyType_SOCKS[]   = "socks";
 const char kProxyType_SOCKS4[]  = "socks4";
 const char kProxyType_SOCKS5[]  = "socks5";
 const char kProxyType_DIRECT[]  = "direct";
-} // namespace mozilla
 
 const char *
 nsProtocolProxyService::ExtractProxyInfo(const char *start,
                                          uint32_t aResolveFlags,
                                          nsProxyInfo **result)
 {
     *result = nullptr;
     uint32_t flags = 0;
@@ -2083,8 +2080,11 @@ nsProtocolProxyService::PruneProxyInfo(c
     }
 
     // if only DIRECT was specified then return no proxy info, and we're done.
     if (head && !head->mNext && head->mType == kProxyType_DIRECT)
         NS_RELEASE(head);
 
     *list = head;  // Transfer ownership
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsProtocolProxyService.h
+++ b/netwerk/base/nsProtocolProxyService.h
@@ -14,23 +14,27 @@
 #include "nsIProtocolProxyFilter.h"
 #include "nsIProxyInfo.h"
 #include "nsIObserver.h"
 #include "nsDataHashtable.h"
 #include "nsHashKeys.h"
 #include "prio.h"
 #include "mozilla/Attributes.h"
 
+class nsIPrefBranch;
+class nsISystemProxySettings;
+
+namespace mozilla {
+namespace net {
+
 typedef nsDataHashtable<nsCStringHashKey, uint32_t> nsFailedProxyTable;
 
+class nsPACMan;
 class nsProxyInfo;
 struct nsProtocolInfo;
-class nsIPrefBranch;
-class nsISystemProxySettings;
-class nsPACMan;
 
 // CID for the nsProtocolProxyService class
 // 091eedd8-8bae-4fe3-ad62-0c87351e640d
 #define NS_PROTOCOL_PROXY_SERVICE_IMPL_CID        \
 { 0x091eedd8, 0x8bae, 0x4fe3, \
         { 0xad, 0x62, 0x0c, 0x87, 0x35, 0x1e, 0x64, 0x0d } }
 
 class nsProtocolProxyService final : public nsIProtocolProxyService2
@@ -401,9 +405,12 @@ private:
                                   nsIProtocolProxyCallback *callback,
                                   nsICancelable **result,
                                   bool isSyncOK);
 
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsProtocolProxyService, NS_PROTOCOL_PROXY_SERVICE_IMPL_CID)
 
+} // namespace net
+} // namespace mozilla
+
 #endif // !nsProtocolProxyService_h__
--- a/netwerk/base/nsProxyInfo.cpp
+++ b/netwerk/base/nsProxyInfo.cpp
@@ -2,21 +2,22 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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 "nsProxyInfo.h"
 #include "nsCOMPtr.h"
 
+namespace mozilla {
+namespace net {
+
 // Yes, we support QI to nsProxyInfo
 NS_IMPL_ISUPPORTS(nsProxyInfo, nsProxyInfo, nsIProxyInfo) 
 
-using namespace mozilla;
-
 NS_IMETHODIMP
 nsProxyInfo::GetHost(nsACString &result)
 {
   result = mHost;
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -82,24 +83,22 @@ nsProxyInfo::SetFailoverProxy(nsIProxyIn
   NS_ENSURE_ARG(pi);
 
   pi.swap(mNext);
   return NS_OK;
 }
 
 // These pointers are declared in nsProtocolProxyService.cpp and
 // comparison of mType by string pointer is valid within necko
-namespace mozilla {
   extern const char kProxyType_HTTP[];
   extern const char kProxyType_HTTPS[];
   extern const char kProxyType_SOCKS[];
   extern const char kProxyType_SOCKS4[];
   extern const char kProxyType_SOCKS5[];
   extern const char kProxyType_DIRECT[];
-} // namespace mozilla
 
 bool
 nsProxyInfo::IsDirect()
 {
   if (!mType)
     return true;
   return mType == kProxyType_DIRECT;
 }
@@ -118,8 +117,10 @@ nsProxyInfo::IsHTTPS()
 
 bool
 nsProxyInfo::IsSOCKS()
 {
   return mType == kProxyType_SOCKS ||
     mType == kProxyType_SOCKS4 || mType == kProxyType_SOCKS5;
 }
 
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsProxyInfo.h
+++ b/netwerk/base/nsProxyInfo.h
@@ -15,16 +15,19 @@
 #define NS_PROXYINFO_IID \
 { /* ed42f751-825e-4cc2-abeb-3670711a8b85 */         \
     0xed42f751,                                      \
     0x825e,                                          \
     0x4cc2,                                          \
     {0xab, 0xeb, 0x36, 0x70, 0x71, 0x1a, 0x8b, 0x85} \
 }
 
+namespace mozilla {
+namespace net {
+
 // This class is exposed to other classes inside Necko for fast access
 // to the nsIProxyInfo attributes.
 class nsProxyInfo final : public nsIProxyInfo
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_PROXYINFO_IID)
 
   NS_DECL_THREADSAFE_ISUPPORTS
@@ -68,9 +71,12 @@ private:
   uint32_t     mFlags;
   uint32_t     mResolveFlags;
   uint32_t     mTimeout;
   nsProxyInfo *mNext;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsProxyInfo, NS_PROXYINFO_IID)
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsProxyInfo_h__
--- a/netwerk/base/nsRequestObserverProxy.cpp
+++ b/netwerk/base/nsRequestObserverProxy.cpp
@@ -6,22 +6,23 @@
 #include "mozilla/DebugOnly.h"
 
 #include "nscore.h"
 #include "nsRequestObserverProxy.h"
 #include "nsIRequest.h"
 #include "nsAutoPtr.h"
 #include "mozilla/Logging.h"
 
-using namespace mozilla;
+namespace mozilla {
+namespace net {
 
 static LazyLogModule gRequestObserverProxyLog("nsRequestObserverProxy");
 
 #undef LOG
-#define LOG(args) MOZ_LOG(gRequestObserverProxyLog, mozilla::LogLevel::Debug, args)
+#define LOG(args) MOZ_LOG(gRequestObserverProxyLog, LogLevel::Debug, args)
 
 //-----------------------------------------------------------------------------
 // nsARequestObserverEvent internal class...
 //-----------------------------------------------------------------------------
 
 nsARequestObserverEvent::nsARequestObserverEvent(nsIRequest *request)
     : mRequest(request)
 {
@@ -184,8 +185,11 @@ nsRequestObserverProxy::Init(nsIRequestO
 //-----------------------------------------------------------------------------
 
 nsresult
 nsRequestObserverProxy::FireEvent(nsARequestObserverEvent *event)
 {
     nsCOMPtr<nsIEventTarget> mainThread(do_GetMainThread());
     return mainThread->Dispatch(event, NS_DISPATCH_NORMAL);
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsRequestObserverProxy.h
+++ b/netwerk/base/nsRequestObserverProxy.h
@@ -8,16 +8,19 @@
 
 #include "nsIRequestObserver.h"
 #include "nsIRequestObserverProxy.h"
 #include "nsIRequest.h"
 #include "nsThreadUtils.h"
 #include "nsCOMPtr.h"
 #include "nsProxyRelease.h"
 
+namespace mozilla {
+namespace net {
+
 class nsARequestObserverEvent;
 
 class nsRequestObserverProxy final : public nsIRequestObserverProxy
 {
     ~nsRequestObserverProxy() {}
 
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
@@ -33,20 +36,23 @@ public:
 protected:
     nsMainThreadPtrHandle<nsIRequestObserver> mObserver;
     nsMainThreadPtrHandle<nsISupports>        mContext;
 
     friend class nsOnStartRequestEvent;
     friend class nsOnStopRequestEvent;
 };
 
-class nsARequestObserverEvent : public mozilla::Runnable
+class nsARequestObserverEvent : public Runnable
 {
 public:
     explicit nsARequestObserverEvent(nsIRequest *);
 
 protected:
     virtual ~nsARequestObserverEvent() {}
 
     nsCOMPtr<nsIRequest>  mRequest;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsRequestObserverProxy_h__
--- a/netwerk/base/nsSecCheckWrapChannel.cpp
+++ b/netwerk/base/nsSecCheckWrapChannel.cpp
@@ -5,18 +5,21 @@
 
 #include "nsContentSecurityManager.h"
 #include "nsSecCheckWrapChannel.h"
 #include "nsIForcePendingChannel.h"
 #include "nsIStreamListener.h"
 #include "mozilla/Logging.h"
 #include "nsCOMPtr.h"
 
-static mozilla::LazyLogModule gChannelWrapperLog("ChannelWrapper");
-#define CHANNELWRAPPERLOG(args) MOZ_LOG(gChannelWrapperLog, mozilla::LogLevel::Debug, args)
+namespace mozilla {
+namespace net {
+
+static LazyLogModule gChannelWrapperLog("ChannelWrapper");
+#define CHANNELWRAPPERLOG(args) MOZ_LOG(gChannelWrapperLog, LogLevel::Debug, args)
 
 NS_IMPL_ADDREF(nsSecCheckWrapChannelBase)
 NS_IMPL_RELEASE(nsSecCheckWrapChannelBase)
 
 NS_INTERFACE_MAP_BEGIN(nsSecCheckWrapChannelBase)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, mHttpChannelInternal)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIHttpChannel)
@@ -186,8 +189,11 @@ nsSecCheckWrapChannel::AsyncOpen2(nsIStr
 NS_IMETHODIMP
 nsSecCheckWrapChannel::Open2(nsIInputStream** aStream)
 {
   nsCOMPtr<nsIStreamListener> listener;
   nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
   NS_ENSURE_SUCCESS(rv, rv);
   return Open(aStream);
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsSecCheckWrapChannel.h
+++ b/netwerk/base/nsSecCheckWrapChannel.h
@@ -9,16 +9,19 @@
 #include "nsIHttpChannel.h"
 #include "nsIHttpChannelInternal.h"
 #include "nsIUploadChannel.h"
 #include "nsIUploadChannel2.h"
 #include "nsISecCheckWrapChannel.h"
 #include "nsIWyciwygChannel.h"
 #include "mozilla/LoadInfo.h"
 
+namespace mozilla {
+namespace net {
+
 /*
  * The nsSecCheckWrapChannelBase wraps channels that do *not*
  *  * provide a newChannel2() implementation
  *  * provide get/setLoadInfo functions
  *
  * In order to perform security checks for channels
  *   a) before opening the channel, and
  *   b) after redirects
@@ -92,9 +95,12 @@ public:
                                                 nsILoadInfo* aLoadInfo);
 
 protected:
   virtual ~nsSecCheckWrapChannel();
 
   nsCOMPtr<nsILoadInfo> mLoadInfo;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsSecCheckWrapChannel_h__
--- a/netwerk/base/nsServerSocket.cpp
+++ b/netwerk/base/nsServerSocket.cpp
@@ -13,18 +13,17 @@
 #include "prio.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Endian.h"
 #include "mozilla/net/DNS.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIFile.h"
 
-using namespace mozilla;
-using namespace mozilla::net;
+namespace mozilla { namespace net {
 
 static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
 
 //-----------------------------------------------------------------------------
 
 typedef void (nsServerSocket:: *nsServerSocketFunc)(void);
 
 static nsresult
@@ -551,8 +550,11 @@ nsServerSocket::GetPort(int32_t *aResult
 
 NS_IMETHODIMP
 nsServerSocket::GetAddress(PRNetAddr *aResult)
 {
   // no need to enter the lock here
   memcpy(aResult, &mAddr, sizeof(mAddr));
   return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsServerSocket.h
+++ b/netwerk/base/nsServerSocket.h
@@ -11,18 +11,16 @@
 #include "nsIServerSocket.h"
 #include "mozilla/Mutex.h"
 
 //-----------------------------------------------------------------------------
 
 class nsIEventTarget;
 namespace mozilla { namespace net {
 union NetAddr;
-} // namespace net
-} // namespace mozilla
 
 class nsServerSocket : public nsASocketHandler
                      , public nsIServerSocket
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSISERVERSOCKET
 
@@ -56,11 +54,14 @@ private:
   // lock protects access to mListener; so it is not cleared while being used.
   mozilla::Mutex                    mLock;
   PRNetAddr                         mAddr;
   nsCOMPtr<nsIEventTarget>          mListenerTarget;
   bool                              mAttached;
   bool                              mKeepWhenOffline;
 };
 
+} // namespace net
+} // namespace mozilla
+
 //-----------------------------------------------------------------------------
 
 #endif // nsServerSocket_h__
--- a/netwerk/base/nsSimpleNestedURI.cpp
+++ b/netwerk/base/nsSimpleNestedURI.cpp
@@ -8,16 +8,19 @@
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsSimpleNestedURI.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 
 #include "mozilla/ipc/URIUtils.h"
 
+namespace mozilla {
+namespace net {
+
 NS_IMPL_ISUPPORTS_INHERITED(nsSimpleNestedURI, nsSimpleURI, nsINestedURI)
 
 nsSimpleNestedURI::nsSimpleNestedURI(nsIURI* innerURI)
     : mInnerURI(innerURI)
 {
     NS_ASSERTION(innerURI, "Must have inner URI");
     NS_TryToSetImmutable(innerURI);
 }
@@ -170,8 +173,11 @@ nsSimpleNestedURI::StartClone(nsSimpleUR
 NS_IMETHODIMP 
 nsSimpleNestedURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
 {
     static NS_DEFINE_CID(kSimpleNestedURICID, NS_SIMPLENESTEDURI_CID);
 
     *aClassIDNoAlloc = kSimpleNestedURICID;
     return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsSimpleNestedURI.h
+++ b/netwerk/base/nsSimpleNestedURI.h
@@ -17,16 +17,19 @@
 #define nsSimpleNestedURI_h__
 
 #include "nsCOMPtr.h"
 #include "nsSimpleURI.h"
 #include "nsINestedURI.h"
 
 #include "nsIIPCSerializableURI.h"
 
+namespace mozilla {
+namespace net {
+
 class nsSimpleNestedURI : public nsSimpleURI,
                           public nsINestedURI
 {
 protected:
     ~nsSimpleNestedURI() {}
 
 public:
     // To be used by deserialization only.  Leaves this object in an
@@ -60,9 +63,12 @@ public:
     // Override the nsIClassInfo method GetClassIDNoAlloc to make sure our
     // nsISerializable impl works right.
     NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) override;  
 
 protected:
     nsCOMPtr<nsIURI> mInnerURI;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif /* nsSimpleNestedURI_h__ */
--- a/netwerk/base/nsSimpleStreamListener.cpp
+++ b/netwerk/base/nsSimpleStreamListener.cpp
@@ -1,15 +1,18 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsSimpleStreamListener.h"
 
+namespace mozilla {
+namespace net {
+
 //
 //----------------------------------------------------------------------------
 // nsISupports implementation...
 //----------------------------------------------------------------------------
 //
 NS_IMPL_ISUPPORTS(nsSimpleStreamListener,
                   nsISimpleStreamListener,
                   nsIStreamListener,
@@ -70,8 +73,11 @@ nsSimpleStreamListener::Init(nsIOutputSt
 {
     NS_PRECONDITION(aSink, "null output stream");
 
     mSink = aSink;
     mObserver = aObserver;
 
     return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsSimpleStreamListener.h
+++ b/netwerk/base/nsSimpleStreamListener.h
@@ -1,25 +1,36 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#ifndef nsSimpleStreamListener_h__
+#define nsSimpleStreamListener_h__
+
 #include "nsISimpleStreamListener.h"
 #include "nsIOutputStream.h"
 #include "nsCOMPtr.h"
 
+namespace mozilla {
+namespace net {
+
 class nsSimpleStreamListener : public nsISimpleStreamListener
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIREQUESTOBSERVER
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSISIMPLESTREAMLISTENER
 
     nsSimpleStreamListener() { }
 
 protected:
     virtual ~nsSimpleStreamListener() {}
 
     nsCOMPtr<nsIOutputStream>    mSink;
     nsCOMPtr<nsIRequestObserver> mObserver;
 };
+
+} // namespace net
+} // namespace mozilla
+
+#endif
--- a/netwerk/base/nsSimpleURI.cpp
+++ b/netwerk/base/nsSimpleURI.cpp
@@ -19,16 +19,19 @@
 #include "nsEscape.h"
 #include "nsError.h"
 #include "nsIIPCSerializableURI.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/ipc/URIUtils.h"
 
 using namespace mozilla::ipc;
 
+namespace mozilla {
+namespace net {
+
 static NS_DEFINE_CID(kThisSimpleURIImplementationCID,
                      NS_THIS_SIMPLEURI_IMPLEMENTATION_CID);
 static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsSimpleURI methods:
 
 nsSimpleURI::nsSimpleURI()
@@ -209,17 +212,17 @@ nsSimpleURI::SetSpec(const nsACString &a
     nsAutoCString spec;
     NS_EscapeURL(specPtr, specLen, esc_OnlyNonASCII|esc_AlwaysCopy, spec);
 
     int32_t colonPos = spec.FindChar(':');
     if (colonPos < 0 || !net_IsValidScheme(spec.get(), colonPos))
         return NS_ERROR_MALFORMED_URI;
 
     mScheme.Truncate();
-    mozilla::DebugOnly<int32_t> n = spec.Left(mScheme, colonPos);
+    DebugOnly<int32_t> n = spec.Left(mScheme, colonPos);
     NS_ASSERTION(n == colonPos, "Left failed");
     ToLowerCase(mScheme);
 
     // This sets both mPath and mRef.
     return SetPath(Substring(spec, colonPos + 1));
 }
 
 NS_IMETHODIMP
@@ -628,20 +631,22 @@ nsSimpleURI::SetMutable(bool value)
     return NS_OK;
 }
 
 //----------------------------------------------------------------------------
 // nsSimpleURI::nsISizeOf
 //----------------------------------------------------------------------------
 
 size_t 
-nsSimpleURI::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+nsSimpleURI::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   return mScheme.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
          mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
          mRef.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
 }
 
 size_t
-nsSimpleURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
+nsSimpleURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
   return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
 
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsSimpleURI.h
+++ b/netwerk/base/nsSimpleURI.h
@@ -10,16 +10,19 @@
 #include "nsIURI.h"
 #include "nsISerializable.h"
 #include "nsString.h"
 #include "nsIClassInfo.h"
 #include "nsIMutable.h"
 #include "nsISizeOf.h"
 #include "nsIIPCSerializableURI.h"
 
+namespace mozilla {
+namespace net {
+
 #define NS_THIS_SIMPLEURI_IMPLEMENTATION_CID         \
 { /* 0b9bb0c2-fee6-470b-b9b9-9fd9462b5e19 */         \
     0x0b9bb0c2,                                      \
     0xfee6,                                          \
     0x470b,                                          \
     {0xb9, 0xb9, 0x9f, 0xd9, 0x46, 0x2b, 0x5e, 0x19} \
 }
 
@@ -47,18 +50,18 @@ public:
 
     // nsISizeOf
     // Among the sub-classes that inherit (directly or indirectly) from
     // nsSimpleURI, measurement of the following members may be added later if
     // DMD finds it is worthwhile:
     // - nsJSURI: mBaseURI
     // - nsSimpleNestedURI: mInnerURI
     // - nsBlobURI: mPrincipal
-    virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
-    virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
+    virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
+    virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
 
 protected:
     // enum used in a few places to specify how .ref attribute should be handled
     enum RefHandlingEnum {
         eIgnoreRef,
         eHonorRef
     };
 
@@ -83,9 +86,12 @@ protected:
     
     nsCString mScheme;
     nsCString mPath; // NOTE: mPath does not include ref, as an optimization
     nsCString mRef;  // so that URIs with different refs can share string data.
     bool mMutable;
     bool mIsRefValid; // To distinguish between empty-ref and no-ref.
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsSimpleURI_h__
--- a/netwerk/base/nsSocketTransport2.cpp
+++ b/netwerk/base/nsSocketTransport2.cpp
@@ -53,26 +53,26 @@
 #endif
 /* End keepalive config inclusions. */
 
 #define SUCCESSFUL_CONNECTING_TO_IPV4_ADDRESS 0
 #define UNSUCCESSFUL_CONNECTING_TO_IPV4_ADDRESS 1
 #define SUCCESSFUL_CONNECTING_TO_IPV6_ADDRESS 2
 #define UNSUCCESSFUL_CONNECTING_TO_IPV6_ADDRESS 3
 
-using namespace mozilla;
-using namespace mozilla::net;
-
 //-----------------------------------------------------------------------------
 
 static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID);
 static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID);
 
 //-----------------------------------------------------------------------------
 
+namespace mozilla {
+namespace net {
+
 class nsSocketEvent : public Runnable
 {
 public:
     nsSocketEvent(nsSocketTransport *transport, uint32_t type,
                   nsresult status = NS_OK, nsISupports *param = nullptr)
         : mTransport(transport)
         , mType(type)
         , mStatus(status)
@@ -200,18 +200,18 @@ ErrorAccordingToNSPR(PRErrorCode errorCo
         break;
     case PR_NOT_DIRECTORY_ERROR:
         rv = NS_ERROR_FILE_NOT_DIRECTORY;
         break;
     case PR_READ_ONLY_FILESYSTEM_ERROR:
         rv = NS_ERROR_FILE_READ_ONLY;
         break;
     default:
-        if (mozilla::psm::IsNSSErrorCode(errorCode)) {
-            rv = mozilla::psm::GetXPCOMFromNSSError(errorCode);
+        if (psm::IsNSSErrorCode(errorCode)) {
+            rv = psm::GetXPCOMFromNSSError(errorCode);
         }
         break;
 
     // NSPR's socket code can return these, but they're not worth breaking out
     // into their own error codes, distinct from NS_ERROR_FAILURE:
     //
     // PR_BAD_DESCRIPTOR_ERROR
     // PR_INVALID_ARGUMENT_ERROR
@@ -1319,17 +1319,17 @@ nsSocketTransport::InitiateSocket()
 
     rv = BuildSocket(fd, proxyTransparent, usingSSL);
     if (NS_FAILED(rv)) {
         SOCKET_LOG(("  BuildSocket failed [rv=%x]\n", rv));
         return rv;
     }
 
     // Attach network activity monitor
-    mozilla::net::NetworkActivityMonitor::AttachIOLayer(fd);
+    NetworkActivityMonitor::AttachIOLayer(fd);
 
     PRStatus status;
 
     // Make the socket non-blocking...
     PRSocketOptionData opt;
     opt.option = PR_SockOpt_Nonblocking;
     opt.value.non_blocking = true;
     status = PR_SetSocketOption(fd, &opt);
@@ -1694,17 +1694,17 @@ nsSocketTransport::OnSocketConnected()
     {
         MutexAutoLock lock(mLock);
         NS_ASSERTION(mFD.IsInitialized(), "no socket");
         NS_ASSERTION(mFDref == 1, "wrong socket ref count");
         SetSocketName(mFD);
         mFDconnected = true;
 
 #ifdef XP_WIN
-        if (!mozilla::IsWin2003OrLater()) { // windows xp
+        if (!IsWin2003OrLater()) { // windows xp
             PRSocketOptionData opt;
             opt.option = PR_SockOpt_RecvBufferSize;
             if (PR_GetSocketOption(mFD, &opt) == PR_SUCCESS) {
                 SOCKET_LOG(("%p checking rwin on xp originally=%u\n",
                             this, opt.value.recv_buffer_size));
                 if (opt.value.recv_buffer_size < 65535) {
                     opt.value.recv_buffer_size = 65535;
                     PR_SetSocketOption(mFD, &opt);
@@ -3107,17 +3107,17 @@ nsSocketTransport::PRFileDescAutoLock::S
     return NS_ERROR_UNEXPECTED;
 #endif
 }
 
 void
 nsSocketTransport::CloseSocket(PRFileDesc *aFd, bool aTelemetryEnabled)
 {
 #if defined(XP_WIN)
-    mozilla::net::AttachShutdownLayer(aFd);
+    AttachShutdownLayer(aFd);
 #endif
 
     // We use PRIntervalTime here because we need
     // nsIOService::LastOfflineStateChange time and
     // nsIOService::LastConectivityChange time to be atomic.
     PRIntervalTime closeStarted;
     if (aTelemetryEnabled) {
         closeStarted = PR_IntervalNow();
@@ -3161,8 +3161,11 @@ nsSocketTransport::SendPRBlockingTelemet
                < 60) {
         Telemetry::Accumulate(aIDOffline,
                               PR_IntervalToMilliseconds(now - aStart));
     } else {
         Telemetry::Accumulate(aIDNormal,
                               PR_IntervalToMilliseconds(now - aStart));
     }
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsSocketTransport2.h
+++ b/netwerk/base/nsSocketTransport2.h
@@ -22,31 +22,35 @@
 #include "nsIClassInfo.h"
 #include "mozilla/net/DNS.h"
 #include "nsASocketHandler.h"
 #include "mozilla/Telemetry.h"
 
 #include "prerror.h"
 #include "nsAutoPtr.h"
 
-class nsSocketTransport;
 class nsICancelable;
 class nsIDNSRecord;
 class nsIInterfaceRequestor;
 
-nsresult
-ErrorAccordingToNSPR(PRErrorCode errorCode);
-
 //-----------------------------------------------------------------------------
 
 // after this short interval, we will return to PR_Poll
 #define NS_SOCKET_CONNECT_TIMEOUT PR_MillisecondsToInterval(20)
 
 //-----------------------------------------------------------------------------
 
+namespace mozilla {
+namespace net {
+
+nsresult
+ErrorAccordingToNSPR(PRErrorCode errorCode);
+
+class nsSocketTransport;
+
 class nsSocketInputStream : public nsIAsyncInputStream
 {
 public:
     NS_DECL_ISUPPORTS_INHERITED
     NS_DECL_NSIINPUTSTREAM
     NS_DECL_NSIASYNCINPUTSTREAM
 
     explicit nsSocketInputStream(nsSocketTransport *);
@@ -56,17 +60,17 @@ public:
     nsresult Condition()    { return mCondition; }
     uint64_t ByteCount()    { return mByteCount; }
 
     // called by the socket transport on the socket thread...
     void OnSocketReady(nsresult condition);
 
 private:
     nsSocketTransport               *mTransport;
-    mozilla::ThreadSafeAutoRefCnt    mReaderRefCnt;
+    ThreadSafeAutoRefCnt             mReaderRefCnt;
 
     // access to these is protected by mTransport->mLock
     nsresult                         mCondition;
     nsCOMPtr<nsIInputStreamCallback> mCallback;
     uint32_t                         mCallbackFlags;
     uint64_t                         mByteCount;
 };
 
@@ -90,35 +94,33 @@ public:
     void OnSocketReady(nsresult condition); 
 
 private:
     static NS_METHOD WriteFromSegments(nsIInputStream *, void *,
                                        const char *, uint32_t offset,
                                        uint32_t count, uint32_t *countRead);
 
     nsSocketTransport                *mTransport;
-    mozilla::ThreadSafeAutoRefCnt     mWriterRefCnt;
+    ThreadSafeAutoRefCnt              mWriterRefCnt;
 
     // access to these is protected by mTransport->mLock
     nsresult                          mCondition;
     nsCOMPtr<nsIOutputStreamCallback> mCallback;
     uint32_t                          mCallbackFlags;
     uint64_t                          mByteCount;
 };
 
 //-----------------------------------------------------------------------------
 
 class nsSocketTransport final : public nsASocketHandler
                               , public nsISocketTransport
                               , public nsIDNSListener
                               , public nsIClassInfo
                               , public nsIInterfaceRequestor
 {
-    typedef mozilla::Mutex Mutex;
-
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSITRANSPORT
     NS_DECL_NSISOCKETTRANSPORT
     NS_DECL_NSIDNSLISTENER
     NS_DECL_NSICLASSINFO
     NS_DECL_NSIINTERFACEREQUESTOR
 
@@ -129,22 +131,22 @@ public:
     nsresult Init(const char **socketTypes, uint32_t typeCount,
                   const nsACString &host, uint16_t port,
                   const nsACString &hostRoute, uint16_t portRoute,
                   nsIProxyInfo *proxyInfo);
 
     // this method instructs the socket transport to use an already connected
     // socket with the given address.
     nsresult InitWithConnectedSocket(PRFileDesc *socketFD,
-                                     const mozilla::net::NetAddr *addr);
+                                     const NetAddr *addr);
 
     // this method instructs the socket transport to use an already connected
     // socket with the given address, and additionally supplies security info.
     nsresult InitWithConnectedSocket(PRFileDesc* aSocketFD,
-                                     const mozilla::net::NetAddr* aAddr,
+                                     const NetAddr* aAddr,
                                      nsISupports* aSecInfo);
 
     // This method instructs the socket transport to open a socket
     // connected to the given Unix domain address. We can only create
     // unlayered, simple, stream sockets.
     nsresult InitWithFilename(const char *filename);
 
     // nsASocketHandler methods:
@@ -155,21 +157,21 @@ public:
 
     // called when a socket event is handled
     void OnSocketEvent(uint32_t type, nsresult status, nsISupports *param);
 
     uint64_t ByteCountReceived() override { return mInput.ByteCount(); }
     uint64_t ByteCountSent() override { return mOutput.ByteCount(); }
     static void CloseSocket(PRFileDesc *aFd, bool aTelemetryEnabled);
     static void SendPRBlockingTelemetry(PRIntervalTime aStart,
-        mozilla::Telemetry::ID aIDNormal,
-        mozilla::Telemetry::ID aIDShutdown,
-        mozilla::Telemetry::ID aIDConnectivityChange,
-        mozilla::Telemetry::ID aIDLinkChange,
-        mozilla::Telemetry::ID aIDOffline);
+        Telemetry::ID aIDNormal,
+        Telemetry::ID aIDShutdown,
+        Telemetry::ID aIDConnectivityChange,
+        Telemetry::ID aIDLinkChange,
+        Telemetry::ID aIDOffline);
 protected:
 
     virtual ~nsSocketTransport();
     void     CleanupTypes();
 
 private:
 
     // event types
@@ -192,18 +194,16 @@ private:
         STATE_CONNECTING,
         STATE_TRANSFERRING
     };
 
     // Safer way to get and automatically release PRFileDesc objects.
     class MOZ_STACK_CLASS PRFileDescAutoLock
     {
     public:
-      typedef mozilla::MutexAutoLock MutexAutoLock;
-
       explicit PRFileDescAutoLock(nsSocketTransport *aSocketTransport,
                                   nsresult *aConditionWhileLocked = nullptr)
         : mSocketTransport(aSocketTransport)
         , mFd(nullptr)
       {
         MOZ_ASSERT(aSocketTransport);
         MutexAutoLock lock(mSocketTransport->mLock);
         if (aConditionWhileLocked) {
@@ -317,22 +317,22 @@ private:
     bool mResolving;
 
     nsCOMPtr<nsICancelable> mDNSRequest;
     nsCOMPtr<nsIDNSRecord>  mDNSRecord;
 
     // mNetAddr/mSelfAddr is valid from GetPeerAddr()/GetSelfAddr() once we have
     // reached STATE_TRANSFERRING. It must not change after that.
     void                    SetSocketName(PRFileDesc *fd);
-    mozilla::net::NetAddr   mNetAddr;
-    mozilla::net::NetAddr   mSelfAddr; // getsockname()
-    mozilla::Atomic<bool, mozilla::Relaxed> mNetAddrIsSet;
-    mozilla::Atomic<bool, mozilla::Relaxed> mSelfAddrIsSet;
+    NetAddr                 mNetAddr;
+    NetAddr                 mSelfAddr; // getsockname()
+    Atomic<bool, Relaxed>   mNetAddrIsSet;
+    Atomic<bool, Relaxed>   mSelfAddrIsSet;
 
-    nsAutoPtr<mozilla::net::NetAddr> mBindAddr;
+    nsAutoPtr<NetAddr>      mBindAddr;
 
     // socket methods (these can only be called on the socket thread):
 
     void     SendStatus(nsresult status);
     nsresult ResolveHost();
     nsresult BuildSocket(PRFileDesc *&, bool &, bool &); 
     nsresult InitiateSocket();
     bool     RecoverFromError();
@@ -441,9 +441,12 @@ private:
     bool mKeepaliveEnabled;
 
     // Keepalive config (support varies by platform).
     int32_t mKeepaliveIdleTimeS;
     int32_t mKeepaliveRetryIntervalS;
     int32_t mKeepaliveProbeCount;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // !nsSocketTransport_h__
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -26,18 +26,18 @@
 #include "nsThreadUtils.h"
 #include "nsIFile.h"
 #include "nsIWidget.h"
 
 #if defined(XP_WIN)
 #include "mozilla/WindowsVersion.h"
 #endif
 
-using namespace mozilla;
-using namespace mozilla::net;
+namespace mozilla {
+namespace net {
 
 LazyLogModule gSocketTransportLog("nsSocketTransport");
 LazyLogModule gUDPSocketLog("UDPSocket");
 LazyLogModule gTCPSocketLog("TCPSocket");
 
 nsSocketTransportService *gSocketTransportService = nullptr;
 Atomic<PRThread*, Relaxed> gSocketThread;
 
@@ -639,17 +639,17 @@ nsSocketTransportService::Shutdown()
         obsSvc->RemoveObserver(this, NS_WIDGET_WAKE_OBSERVER_TOPIC);
     }
 
     if (mAfterWakeUpTimer) {
         mAfterWakeUpTimer->Cancel();
         mAfterWakeUpTimer = nullptr;
     }
 
-    mozilla::net::NetworkActivityMonitor::Shutdown();
+    NetworkActivityMonitor::Shutdown();
 
     mInitialized = false;
     mShuttingDown = false;
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1191,17 +1191,17 @@ nsSocketTransportService::UpdateSendBuff
     nsresult rv = pref->GetIntPref(SEND_BUFFER_PREF, &bufferSize);
     if (NS_SUCCEEDED(rv)) {
         mSendBufferSize = bufferSize;
         return;
     }
 
 #if defined(XP_WIN)
     // If the pref is not set but this is windows set it depending on windows version
-    if (!mozilla::IsWin2003OrLater()) { // windows xp
+    if (!IsWin2003OrLater()) { // windows xp
         mSendBufferSize = 131072;
     } else { // vista or later
         mSendBufferSize = 131072 * 4;
     }
 #endif
 }
 
 nsresult
@@ -1371,17 +1371,17 @@ nsSocketTransportService::ClosePrivateCo
         }
     }
     for (int32_t i = mIdleCount - 1; i >= 0; --i) {
         if (mIdleList[i].mHandler->mIsPrivate) {
             DetachSocket(mIdleList, &mIdleList[i]);
         }
     }
 
-    mozilla::ClearPrivateSSLState();
+    ClearPrivateSSLState();
 }
 
 NS_IMETHODIMP
 nsSocketTransportService::GetSendBufferSize(int32_t *value)
 {
     *value = mSendBufferSize;
     return NS_OK;
 }
@@ -1548,8 +1548,11 @@ void
 nsSocketTransportService::GetSocketConnections(nsTArray<SocketInfo> *data)
 {
     NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread");
     for (uint32_t i = 0; i < mActiveCount; i++)
         AnalyzeConnection(data, &mActiveList[i], true);
     for (uint32_t i = 0; i < mIdleCount; i++)
         AnalyzeConnection(data, &mIdleList[i], false);
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsSocketTransportService2.h
+++ b/netwerk/base/nsSocketTransportService2.h
@@ -24,63 +24,60 @@
 #include "PollableEvent.h"
 
 class nsASocketHandler;
 struct PRPollDesc;
 class nsIPrefBranch;
 
 //-----------------------------------------------------------------------------
 
+namespace mozilla {
+namespace net {
+
 //
 // set NSPR_LOG_MODULES=nsSocketTransport:5
 //
-extern mozilla::LazyLogModule gSocketTransportLog;
-#define SOCKET_LOG(args)     MOZ_LOG(gSocketTransportLog, mozilla::LogLevel::Debug, args)
-#define SOCKET_LOG_ENABLED() MOZ_LOG_TEST(gSocketTransportLog, mozilla::LogLevel::Debug)
+extern LazyLogModule gSocketTransportLog;
+#define SOCKET_LOG(args)     MOZ_LOG(gSocketTransportLog, LogLevel::Debug, args)
+#define SOCKET_LOG_ENABLED() MOZ_LOG_TEST(gSocketTransportLog, LogLevel::Debug)
 
 //
 // set NSPR_LOG_MODULES=UDPSocket:5
 //
-extern mozilla::LazyLogModule gUDPSocketLog;
-#define UDPSOCKET_LOG(args)     MOZ_LOG(gUDPSocketLog, mozilla::LogLevel::Debug, args)
-#define UDPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gUDPSocketLog, mozilla::LogLevel::Debug)
+extern LazyLogModule gUDPSocketLog;
+#define UDPSOCKET_LOG(args)     MOZ_LOG(gUDPSocketLog, LogLevel::Debug, args)
+#define UDPSOCKET_LOG_ENABLED() MOZ_LOG_TEST(gUDPSocketLog, LogLevel::Debug)
 
 //-----------------------------------------------------------------------------
 
 #define NS_SOCKET_POLL_TIMEOUT PR_INTERVAL_NO_TIMEOUT
 
 //-----------------------------------------------------------------------------
 
-namespace mozilla {
-namespace net {
 // These maximums are borrowed from the linux kernel.
 static const int32_t kMaxTCPKeepIdle  = 32767; // ~9 hours.
 static const int32_t kMaxTCPKeepIntvl = 32767;
 static const int32_t kMaxTCPKeepCount   = 127;
 static const int32_t kDefaultTCPKeepCount =
 #if defined (XP_WIN)
                                               10; // Hardcoded in Windows.
 #elif defined (XP_MACOSX)
                                               8;  // Hardcoded in OSX.
 #else
                                               4;  // Specifiable in Linux.
 #endif
-} // namespace net
-} // namespace mozilla
 
 //-----------------------------------------------------------------------------
 
 class nsSocketTransportService final : public nsPISocketTransportService
                                      , public nsIEventTarget
                                      , public nsIThreadObserver
                                      , public nsIRunnable
                                      , public nsIObserver
 {
-    typedef mozilla::Mutex Mutex;
-
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSPISOCKETTRANSPORTSERVICE
     NS_DECL_NSISOCKETTRANSPORTSERVICE
     NS_DECL_NSIROUTEDSOCKETTRANSPORTSERVICE
     NS_DECL_NSIEVENTTARGET
     NS_DECL_NSITHREADOBSERVER
     NS_DECL_NSIRUNNABLE
@@ -94,17 +91,17 @@ public:
     static uint32_t gMaxCount;
     static PRCallOnceType gMaxCountInitOnce;
     static PRStatus DiscoverMaxCount();
 
     bool CanAttachSocket();
 
     // Called by the networking dashboard on the socket thread only
     // Fills the passed array with socket information
-    void GetSocketConnections(nsTArray<mozilla::net::SocketInfo> *);
+    void GetSocketConnections(nsTArray<SocketInfo> *);
     uint64_t GetSentBytes() { return mSentBytesCount; }
     uint64_t GetReceivedBytes() { return mReceivedBytesCount; }
 
     // Returns true if keepalives are enabled in prefs.
     bool IsKeepaliveEnabled() { return mKeepaliveEnabledPref; }
 
     bool IsTelemetryEnabledAndNotSleepPhase() { return mTelemetryEnabledPref &&
                                                        !mSleepPhase; }
@@ -114,18 +111,18 @@ protected:
     virtual ~nsSocketTransportService();
 
 private:
 
     //-------------------------------------------------------------------------
     // misc (any thread)
     //-------------------------------------------------------------------------
 
-    nsCOMPtr<nsIThread> mThread;    // protected by mLock
-    mozilla::UniquePtr<mozilla::net::PollableEvent> mPollableEvent;
+    nsCOMPtr<nsIThread>      mThread;    // protected by mLock
+    UniquePtr<PollableEvent> mPollableEvent;
 
     // Returns mThread, protecting the get-and-addref with mLock
     already_AddRefed<nsIThread> GetThreadSafely();
 
     //-------------------------------------------------------------------------
     // initialization and shutdown (any thread)
     //-------------------------------------------------------------------------
 
@@ -187,72 +184,75 @@ private:
     //
     // first element of the poll list is mPollableEvent (or null if the pollable
     // event cannot be created).
     //-------------------------------------------------------------------------
 
     PRPollDesc *mPollList;                        /* mListSize + 1 entries */
 
     PRIntervalTime PollTimeout();            // computes ideal poll timeout
-    nsresult       DoPollIteration(mozilla::TimeDuration *pollDuration);
+    nsresult       DoPollIteration(TimeDuration *pollDuration);
                                              // perfoms a single poll iteration
     int32_t        Poll(uint32_t *interval,
-                        mozilla::TimeDuration *pollDuration);
+                        TimeDuration *pollDuration);
                                              // calls PR_Poll.  the out param
                                              // interval indicates the poll
                                              // duration in seconds.
                                              // pollDuration is used only for
                                              // telemetry
 
     //-------------------------------------------------------------------------
     // pending socket queue - see NotifyWhenCanAttachSocket
     //-------------------------------------------------------------------------
 
-    mozilla::Mutex mEventQueueLock;
+    Mutex        mEventQueueLock;
     nsEventQueue mPendingSocketQ; // queue of nsIRunnable objects
 
     // Preference Monitor for SendBufferSize and Keepalive prefs.
     nsresult    UpdatePrefs();
     void        UpdateSendBufferPref(nsIPrefBranch *);
     int32_t     mSendBufferSize;
     // Number of seconds of connection is idle before first keepalive ping.
     int32_t     mKeepaliveIdleTimeS;
     // Number of seconds between retries should keepalive pings fail.
     int32_t     mKeepaliveRetryIntervalS;
     // Number of keepalive probes to send.
     int32_t     mKeepaliveProbeCount;
     // True if TCP keepalive is enabled globally.
     bool        mKeepaliveEnabledPref;
 
-    mozilla::Atomic<bool>  mServingPendingQueue;
-    mozilla::Atomic<int32_t, mozilla::Relaxed> mMaxTimePerPollIter;
-    mozilla::Atomic<bool, mozilla::Relaxed>  mTelemetryEnabledPref;
-    mozilla::Atomic<PRIntervalTime, mozilla::Relaxed> mMaxTimeForPrClosePref;
+    Atomic<bool>                    mServingPendingQueue;
+    Atomic<int32_t, Relaxed>        mMaxTimePerPollIter;
+    Atomic<bool, Relaxed>           mTelemetryEnabledPref;
+    Atomic<PRIntervalTime, Relaxed> mMaxTimeForPrClosePref;
 
     // Between a computer going to sleep and waking up the PR_*** telemetry
     // will be corrupted - so do not record it.
-    mozilla::Atomic<bool, mozilla::Relaxed> mSleepPhase;
-    nsCOMPtr<nsITimer> mAfterWakeUpTimer;
+    Atomic<bool, Relaxed>           mSleepPhase;
+    nsCOMPtr<nsITimer>              mAfterWakeUpTimer;
 
     void OnKeepaliveEnabledPrefChange();
     void NotifyKeepaliveEnabledPrefChange(SocketContext *sock);
 
     // Socket thread only for dynamically adjusting max socket size
 #if defined(XP_WIN)
     void ProbeMaxCount();
 #endif
     bool mProbedMaxCount;
 
-    void AnalyzeConnection(nsTArray<mozilla::net::SocketInfo> *data,
+    void AnalyzeConnection(nsTArray<SocketInfo> *data,
                            SocketContext *context, bool aActive);
 
     void ClosePrivateConnections();
     void DetachSocketWithGuard(bool aGuardLocals,
                                SocketContext *socketList,
                                int32_t index);
 
     void MarkTheLastElementOfPendingQueue();
 };
 
 extern nsSocketTransportService *gSocketTransportService;
-extern mozilla::Atomic<PRThread*, mozilla::Relaxed> gSocketThread;
+extern Atomic<PRThread*, Relaxed> gSocketThread;
+
+} // namespace net
+} // namespace mozilla
 
 #endif // !nsSocketTransportService_h__
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -23,35 +23,38 @@
 #include "mozilla/ipc/URIUtils.h"
 #include <algorithm>
 #include "mozilla/dom/EncodingUtils.h"
 #include "nsContentUtils.h"
 
 using mozilla::dom::EncodingUtils;
 using namespace mozilla::ipc;
 
+namespace mozilla {
+namespace net {
+
 static NS_DEFINE_CID(kThisImplCID, NS_THIS_STANDARDURL_IMPL_CID);
 static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
 
 nsIIDNService *nsStandardURL::gIDN = nullptr;
 bool nsStandardURL::gInitialized = false;
 bool nsStandardURL::gEscapeUTF8 = true;
 bool nsStandardURL::gAlwaysEncodeInUTF8 = true;
 char nsStandardURL::gHostLimitDigits[] = { '/', '\\', '?', '#', 0 };
 
 //
 // setenv NSPR_LOG_MODULES nsStandardURL:5
 //
-static mozilla::LazyLogModule gStandardURLLog("nsStandardURL");
+static LazyLogModule gStandardURLLog("nsStandardURL");
 
 // The Chromium code defines its own LOG macro which we don't want
 #undef LOG
-#define LOG(args)     MOZ_LOG(gStandardURLLog, mozilla::LogLevel::Debug, args)
+#define LOG(args)     MOZ_LOG(gStandardURLLog, LogLevel::Debug, args)
 #undef LOG_ENABLED
-#define LOG_ENABLED() MOZ_LOG_TEST(gStandardURLLog, mozilla::LogLevel::Debug)
+#define LOG_ENABLED() MOZ_LOG_TEST(gStandardURLLog, LogLevel::Debug)
 
 //----------------------------------------------------------------------------
 
 #define ENSURE_MUTABLE() \
   PR_BEGIN_MACRO \
     if (!mMutable) { \
         NS_WARNING("attempt to modify an immutable nsStandardURL"); \
         return NS_ERROR_ABORT; \
@@ -617,17 +620,17 @@ nsStandardURL::BuildNormalizedSpec(const
     URLSegment extension(mExtension);
     URLSegment query(mQuery);
     URLSegment ref(mRef);
 
     //
     // generate the normalized URL string
     //
     // approxLen should be correct or 1 high
-    if (!mSpec.SetLength(approxLen+1, mozilla::fallible)) // buf needs a trailing '\0' below
+    if (!mSpec.SetLength(approxLen+1, fallible)) // buf needs a trailing '\0' below
         return NS_ERROR_OUT_OF_MEMORY;
     char *buf;
     mSpec.BeginWriting(buf);
     uint32_t i = 0;
     int32_t diff = 0;
 
     if (mScheme.mLen > 0) {
         i = AppendSegmentToBuf(buf, i, spec, mScheme, mScheme);
@@ -3254,25 +3257,25 @@ nsStandardURL::Write(nsIObjectOutputStre
     return NS_OK;
 }
 
 //---------------------------------------------------------------------------
 // nsStandardURL::nsIIPCSerializableURI
 //---------------------------------------------------------------------------
 
 inline
-mozilla::ipc::StandardURLSegment
+ipc::StandardURLSegment
 ToIPCSegment(const nsStandardURL::URLSegment& aSegment)
 {
-    return mozilla::ipc::StandardURLSegment(aSegment.mPos, aSegment.mLen);
+    return ipc::StandardURLSegment(aSegment.mPos, aSegment.mLen);
 }
 
 inline
 nsStandardURL::URLSegment
-FromIPCSegment(const mozilla::ipc::StandardURLSegment& aSegment)
+FromIPCSegment(const ipc::StandardURLSegment& aSegment)
 {
     return nsStandardURL::URLSegment(aSegment.position(), aSegment.length());
 }
 
 void
 nsStandardURL::Serialize(URIParams& aParams)
 {
     MOZ_ASSERT(mSpec.Length() <= (uint32_t) net_GetURLMaxLength(),
@@ -3421,24 +3424,27 @@ nsStandardURL::GetClassIDNoAlloc(nsCID *
     return NS_OK;
 }
 
 //----------------------------------------------------------------------------
 // nsStandardURL::nsISizeOf
 //----------------------------------------------------------------------------
 
 size_t
-nsStandardURL::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+nsStandardURL::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   return mSpec.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
          mOriginCharset.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
          aMallocSizeOf(mHostA);
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
   // - mParser
   // - mFile
 }
 
 size_t
-nsStandardURL::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
+nsStandardURL::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
   return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsStandardURL.h
+++ b/netwerk/base/nsStandardURL.h
@@ -28,16 +28,19 @@
 
 class nsIBinaryInputStream;
 class nsIBinaryOutputStream;
 class nsIIDNService;
 class nsIPrefBranch;
 class nsIFile;
 class nsIURLParser;
 
+namespace mozilla {
+namespace net {
+
 //-----------------------------------------------------------------------------
 // standard URL implementation
 //-----------------------------------------------------------------------------
 
 class nsStandardURL : public nsIFileURL
                     , public nsIStandardURL
                     , public nsISerializable
                     , public nsIClassInfo
@@ -56,18 +59,18 @@ public:
     NS_DECL_NSISTANDARDURL
     NS_DECL_NSISERIALIZABLE
     NS_DECL_NSICLASSINFO
     NS_DECL_NSIMUTABLE
     NS_DECL_NSIIPCSERIALIZABLEURI
     NS_DECL_NSISENSITIVEINFOHIDDENURI
 
     // nsISizeOf
-    virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
-    virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
+    virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
+    virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
 
     explicit nsStandardURL(bool aSupportsFileURL = false, bool aTrackURL = true);
 
     static void InitGlobalObjects();
     static void ShutdownGlobalObjects();
 
 public: /* internal -- HPUX compiler can't handle this being private */
     //
@@ -384,9 +387,12 @@ nsStandardURL::Filename()
         pos = mBasename.mPos;
         len = mBasename.mLen;
         if (mExtension.mLen >= 0)
             len += (mExtension.mLen + 1);
     }
     return Substring(mSpec, pos, len);
 }
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsStandardURL_h__
--- a/netwerk/base/nsStreamListenerTee.cpp
+++ b/netwerk/base/nsStreamListenerTee.cpp
@@ -1,15 +1,18 @@
 /* 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 "nsStreamListenerTee.h"
 #include "nsProxyRelease.h"
 
+namespace mozilla {
+namespace net {
+
 NS_IMPL_ISUPPORTS(nsStreamListenerTee,
                   nsIStreamListener,
                   nsIRequestObserver,
                   nsIStreamListenerTee,
                   nsIThreadRetargetableStreamListener)
 
 NS_IMETHODIMP
 nsStreamListenerTee::OnStartRequest(nsIRequest *request,
@@ -130,8 +133,11 @@ nsStreamListenerTee::InitAsync(nsIStream
                                nsIEventTarget *eventTarget,
                                nsIOutputStream *sink,
                                nsIRequestObserver *requestObserver)
 {
     NS_ENSURE_ARG_POINTER(eventTarget);
     mEventTarget = eventTarget;
     return Init(listener, sink, requestObserver);
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsStreamListenerTee.h
+++ b/netwerk/base/nsStreamListenerTee.h
@@ -7,16 +7,19 @@
 
 #include "nsIStreamListenerTee.h"
 #include "nsIThreadRetargetableStreamListener.h"
 #include "nsIInputStreamTee.h"
 #include "nsIOutputStream.h"
 #include "nsCOMPtr.h"
 #include "nsIEventTarget.h"
 
+namespace mozilla {
+namespace net {
+
 class nsStreamListenerTee : public nsIStreamListenerTee
                           , public nsIThreadRetargetableStreamListener
 {
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIREQUESTOBSERVER
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
@@ -29,9 +32,12 @@ private:
 
     nsCOMPtr<nsIInputStreamTee>  mInputTee;
     nsCOMPtr<nsIOutputStream>    mSink;
     nsCOMPtr<nsIStreamListener>  mListener;
     nsCOMPtr<nsIRequestObserver> mObserver;
     nsCOMPtr<nsIEventTarget>     mEventTarget;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif
--- a/netwerk/base/nsStreamListenerWrapper.cpp
+++ b/netwerk/base/nsStreamListenerWrapper.cpp
@@ -2,16 +2,19 @@
  * 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 "nsStreamListenerWrapper.h"
 #ifdef DEBUG
 #include "MainThreadUtils.h"
 #endif
 
+namespace mozilla {
+namespace net {
+
 NS_IMPL_ISUPPORTS(nsStreamListenerWrapper,
                   nsIStreamListener,
                   nsIRequestObserver,
                   nsIThreadRetargetableStreamListener)
 
 NS_IMETHODIMP
 nsStreamListenerWrapper::CheckListenerChain()
 {
@@ -19,8 +22,11 @@ nsStreamListenerWrapper::CheckListenerCh
     nsresult rv = NS_OK;
     nsCOMPtr<nsIThreadRetargetableStreamListener> retargetableListener =
         do_QueryInterface(mListener, &rv);
     if (retargetableListener) {
         rv = retargetableListener->CheckListenerChain();
     }
     return rv;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsStreamListenerWrapper.h
+++ b/netwerk/base/nsStreamListenerWrapper.h
@@ -6,16 +6,19 @@
 #define nsStreamListenerWrapper_h__
 
 #include "nsCOMPtr.h"
 #include "nsIStreamListener.h"
 #include "nsIRequestObserver.h"
 #include "nsIThreadRetargetableStreamListener.h"
 #include "mozilla/Attributes.h"
 
+namespace mozilla {
+namespace net {
+
 // Wrapper class to make replacement of nsHttpChannel's listener
 // from JavaScript possible. It is workaround for bug 433711 and 682305.
 class nsStreamListenerWrapper final : public nsIStreamListener
                                     , public nsIThreadRetargetableStreamListener
 {
 public:
   explicit nsStreamListenerWrapper(nsIStreamListener *listener)
     : mListener(listener)
@@ -42,10 +45,13 @@ public:
     return rv;
   }
 
 private:
   ~nsStreamListenerWrapper() {}
   nsCOMPtr<nsIStreamListener> mListener;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsStreamListenerWrapper_h__
 
--- a/netwerk/base/nsStreamLoader.cpp
+++ b/netwerk/base/nsStreamLoader.cpp
@@ -6,16 +6,19 @@
 #include "nsStreamLoader.h"
 #include "nsIInputStream.h"
 #include "nsIChannel.h"
 #include "nsError.h"
 #include "GeckoProfiler.h"
 
 #include <limits>
 
+namespace mozilla {
+namespace net {
+
 nsStreamLoader::nsStreamLoader()
   : mData()
 {
 }
 
 nsStreamLoader::~nsStreamLoader()
 {
 }
@@ -156,8 +159,11 @@ nsStreamLoader::ReleaseData()
   mData.clearAndFree();
 }
 
 NS_IMETHODIMP
 nsStreamLoader::CheckListenerChain()
 {
   return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsStreamLoader.h
+++ b/netwerk/base/nsStreamLoader.h
@@ -9,16 +9,19 @@
 #include "nsIThreadRetargetableStreamListener.h"
 #include "nsIStreamLoader.h"
 #include "nsCOMPtr.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Vector.h"
 
 class nsIRequest;
 
+namespace mozilla {
+namespace net {
+
 class nsStreamLoader final : public nsIStreamLoader
                            , public nsIThreadRetargetableStreamListener
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSISTREAMLOADER
   NS_DECL_NSIREQUESTOBSERVER
   NS_DECL_NSISTREAMLISTENER
@@ -44,9 +47,12 @@ protected:
   nsCOMPtr<nsIRequest>              mRequest;
   nsCOMPtr<nsIRequestObserver>      mRequestObserver;
 
   // Buffer to accumulate incoming data. We preallocate if contentSize is
   // available.
   mozilla::Vector<uint8_t, 0> mData;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsStreamLoader_h__
--- a/netwerk/base/nsStreamTransportService.cpp
+++ b/netwerk/base/nsStreamTransportService.cpp
@@ -14,16 +14,19 @@
 #include "nsIAsyncOutputStream.h"
 #include "nsISeekableStream.h"
 #include "nsIPipe.h"
 #include "nsITransport.h"
 #include "nsIObserverService.h"
 #include "nsIThreadPool.h"
 #include "mozilla/Services.h"
 
+namespace mozilla {
+namespace net {
+
 //-----------------------------------------------------------------------------
 // nsInputStreamTransport
 //
 // Implements nsIInputStream as a wrapper around the real input stream.  This
 // allows the transport to support seeking, range-limiting, progress reporting,
 // and close-when-done semantics while utilizing NS_AsyncCopy.
 //-----------------------------------------------------------------------------
 
@@ -589,8 +592,11 @@ nsStreamTransportService::Observe(nsISup
   }
 
   if (mPool) {
     mPool->Shutdown();
     mPool = nullptr;
   }
   return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsStreamTransportService.h
+++ b/netwerk/base/nsStreamTransportService.h
@@ -1,22 +1,28 @@
 /* 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 nsStreamTransportService_h__
+#define nsStreamTransportService_h__
+
 #include "nsIStreamTransportService.h"
 #include "nsIEventTarget.h"
 #include "nsIObserver.h"
 #include "nsCOMPtr.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 
 class nsIThreadPool;
 
+namespace mozilla {
+namespace net {
+
 class nsStreamTransportService final : public nsIStreamTransportService
                                      , public nsIEventTarget
                                      , public nsIObserver
 {
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSISTREAMTRANSPORTSERVICE
     NS_DECL_NSIEVENTTARGET
@@ -31,8 +37,12 @@ public:
 private:
     ~nsStreamTransportService();
 
     nsCOMPtr<nsIThreadPool> mPool;
 
     mozilla::Mutex mShutdownLock;
     bool mIsShutdown;
 };
+
+} // namespace net
+} // namespace mozilla
+#endif
--- a/netwerk/base/nsUDPSocket.cpp
+++ b/netwerk/base/nsUDPSocket.cpp
@@ -30,18 +30,18 @@
 #include "nsIDNSRecord.h"
 #include "nsIDNSService.h"
 #include "nsICancelable.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include "NetStatistics.h"
 #endif
 
-using namespace mozilla::net;
-using namespace mozilla;
+namespace mozilla {
+namespace net {
 
 static const uint32_t UDP_PACKET_CHUNK_SIZE = 1400;
 static NS_DEFINE_CID(kSocketTransportServiceCID2, NS_SOCKETTRANSPORTSERVICE_CID);
 
 //-----------------------------------------------------------------------------
 
 typedef void (nsUDPSocket:: *nsUDPSocketFunc)(void);
 
@@ -190,17 +190,17 @@ nsUDPMessage::nsUDPMessage(NetAddr* aAdd
   : mOutputStream(aOutputStream)
 {
   memcpy(&mAddr, aAddr, sizeof(NetAddr));
   aData.SwapElements(mData);
 }
 
 nsUDPMessage::~nsUDPMessage()
 {
-  mozilla::DropJSObjects(this);
+  DropJSObjects(this);
 }
 
 NS_IMETHODIMP
 nsUDPMessage::GetFromAddr(nsINetAddr * *aFromAddr)
 {
   NS_ENSURE_ARG_POINTER(aFromAddr);
 
   nsCOMPtr<nsINetAddr> result = new nsNetAddr(&mAddr);
@@ -224,18 +224,18 @@ nsUDPMessage::GetOutputStream(nsIOutputS
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsUDPMessage::GetRawData(JSContext* cx,
                          JS::MutableHandleValue aRawData)
 {
   if(!mJsobj){
-    mJsobj = mozilla::dom::Uint8Array::Create(cx, nullptr, mData.Length(), mData.Elements());
-    mozilla::HoldJSObjects(this);
+    mJsobj = dom::Uint8Array::Create(cx, nullptr, mData.Length(), mData.Elements());
+    HoldJSObjects(this);
   }
   aRawData.setObject(*mJsobj);
   return NS_OK;
 }
 
 FallibleTArray<uint8_t>&
 nsUDPMessage::GetDataAsTArray()
 {
@@ -1580,8 +1580,11 @@ nsUDPSocket::SetMulticastInterfaceIntern
 
   nsresult rv = SetSocketOption(opt);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/base/nsUDPSocket.h
+++ b/netwerk/base/nsUDPSocket.h
@@ -14,16 +14,19 @@
 
 #ifdef MOZ_WIDGET_GONK
 #include "nsINetworkInterface.h"
 #include "nsProxyRelease.h"
 #endif
 
 //-----------------------------------------------------------------------------
 
+namespace mozilla {
+namespace net {
+
 class nsUDPSocket final : public nsASocketHandler
                         , public nsIUDPSocket
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIUDPSOCKET
 
   // nsASocketHandler methods:
@@ -56,25 +59,25 @@ private:
   nsresult SetMulticastInterfaceInternal(const PRNetAddr& aIface);
 
   void SaveNetworkStats(bool aEnforce);
 
   void CloseSocket();
 
   // lock protects access to mListener;
   // so mListener is not cleared while being used/locked.
-  mozilla::Mutex                       mLock;
-  PRFileDesc                           *mFD;
-  mozilla::net::NetAddr                mAddr;
+  Mutex                                mLock;
+  PRFileDesc                          *mFD;
+  NetAddr                              mAddr;
   uint32_t                             mAppId;
   bool                                 mIsInIsolatedMozBrowserElement;
   nsCOMPtr<nsIUDPSocketListener>       mListener;
   nsCOMPtr<nsIEventTarget>             mListenerTarget;
   bool                                 mAttached;
-  RefPtr<nsSocketTransportService>   mSts;
+  RefPtr<nsSocketTransportService>     mSts;
 
   uint64_t   mByteReadCount;
   uint64_t   mByteWriteCount;
 #ifdef MOZ_WIDGET_GONK
   nsMainThreadPtrHandle<nsINetworkInfo> mActiveNetworkInfo;
 #endif
 };
 
@@ -82,24 +85,24 @@ private:
 
 class nsUDPMessage : public nsIUDPMessage
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsUDPMessage)
   NS_DECL_NSIUDPMESSAGE
 
-  nsUDPMessage(mozilla::net::NetAddr* aAddr,
+  nsUDPMessage(NetAddr* aAddr,
                nsIOutputStream* aOutputStream,
                FallibleTArray<uint8_t>& aData);
 
 private:
   virtual ~nsUDPMessage();
 
-  mozilla::net::NetAddr mAddr;
+  NetAddr mAddr;
   nsCOMPtr<nsIOutputStream> mOutputStream;
   FallibleTArray<uint8_t> mData;
   JS::Heap<JSObject*> mJsobj;
 };
 
 
 //-----------------------------------------------------------------------------
 
@@ -117,9 +120,12 @@ private:
   virtual ~nsUDPOutputStream();
 
   RefPtr<nsUDPSocket>       mSocket;
   PRFileDesc                  *mFD;
   PRNetAddr                   mPrClientAddr;
   bool                        mIsClosed;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif // nsUDPSocket_h__
--- a/netwerk/build/nsNetModule.cpp
+++ b/netwerk/build/nsNetModule.cpp
@@ -49,53 +49,60 @@
 
 typedef nsCategoryCache<nsIContentSniffer> ContentSnifferCache;
 ContentSnifferCache* gNetSniffers = nullptr;
 ContentSnifferCache* gDataSniffers = nullptr;
 
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "nsIOService.h"
+typedef mozilla::net::nsIOService nsIOService;
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIOService, nsIOService::GetInstance)
 
 #include "nsDNSService2.h"
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDNSService,
   nsDNSService::GetXPCOMSingleton)
 
 #include "nsProtocolProxyService.h"
+typedef mozilla::net::nsProtocolProxyService nsProtocolProxyService;
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsProtocolProxyService, Init)
 
 #include "nsStreamTransportService.h"
+typedef mozilla::net::nsStreamTransportService nsStreamTransportService;
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStreamTransportService, Init)
 
 #include "nsSocketTransportService2.h"
+typedef mozilla::net::nsSocketTransportService nsSocketTransportService;
 #undef LOG
 #undef LOG_ENABLED
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSocketTransportService, Init)
 
 #include "nsServerSocket.h"
+typedef mozilla::net::nsServerSocket nsServerSocket;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsServerSocket)
 
 #include "TLSServerSocket.h"
 typedef mozilla::net::TLSServerSocket TLSServerSocket;
 NS_GENERIC_FACTORY_CONSTRUCTOR(TLSServerSocket)
 
 #include "nsUDPSocket.h"
+typedef mozilla::net::nsUDPSocket nsUDPSocket;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsUDPSocket)
 
 #include "nsUDPSocketProvider.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsUDPSocketProvider)
 
 #include "nsAsyncStreamCopier.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAsyncStreamCopier)
 
 #include "nsInputStreamPump.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsInputStreamPump)
 
 #include "nsInputStreamChannel.h"
+typedef mozilla::net::nsInputStreamChannel nsInputStreamChannel;
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsInputStreamChannel, Init)
 
 #include "nsDownloader.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloader)
 
 #include "BackgroundFileSaver.h"
 namespace mozilla {
 namespace net {
@@ -108,16 +115,17 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(Back
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSyncStreamListener, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomicFileOutputStream)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSafeFileOutputStream)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFileStream)
 
+typedef mozilla::net::nsLoadGroup nsLoadGroup;
 NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT(nsLoadGroup, Init)
 
 #include "ArrayBufferInputStream.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(ArrayBufferInputStream)
 
 #include "nsEffectiveTLDService.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsEffectiveTLDService, Init)
 
@@ -169,24 +177,27 @@ net_NewIncrementalDownload(nsISupports *
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMIMEHeaderParamImpl)
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "nsRequestObserverProxy.h"
 #include "nsSimpleStreamListener.h"
 #include "nsDirIndexParser.h"
 #include "nsDirIndex.h"
 
+typedef mozilla::net::nsRequestObserverProxy nsRequestObserverProxy;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRequestObserverProxy)
+typedef mozilla::net::nsSimpleStreamListener nsSimpleStreamListener;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSimpleStreamListener)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDirIndexParser, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDirIndex)
 
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "nsStreamListenerTee.h"
+typedef mozilla::net::nsStreamListenerTee nsStreamListenerTee;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsStreamListenerTee)
 
 ///////////////////////////////////////////////////////////////////////////////
 
 #ifdef NECKO_COOKIES
 #include "nsCookieService.h"
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsICookieService,
   nsCookieService::GetXPCOMSingleton)
@@ -204,16 +215,19 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsWifiMon
 
 ///////////////////////////////////////////////////////////////////////////////
 // protocols
 ///////////////////////////////////////////////////////////////////////////////
 
 // about:blank is mandatory
 #include "nsAboutProtocolHandler.h"
 #include "nsAboutBlank.h"
+typedef mozilla::net::nsAboutProtocolHandler nsAboutProtocolHandler;
+typedef mozilla::net::nsSafeAboutProtocolHandler nsSafeAboutProtocolHandler;
+typedef mozilla::net::nsNestedAboutURI nsNestedAboutURI;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAboutProtocolHandler)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSafeAboutProtocolHandler)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNestedAboutURI)
 
 #ifdef NECKO_PROTOCOL_about
 // about
 #ifdef NS_BUILD_REFCNT_LOGGING
 #include "nsAboutBloat.h"
@@ -289,21 +303,23 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsRe
 namespace mozilla {
 NS_GENERIC_FACTORY_CONSTRUCTOR(ExtensionProtocolHandler)
 NS_GENERIC_FACTORY_CONSTRUCTOR(SubstitutingURL)
 } // namespace mozilla
 #endif
 
 #ifdef NECKO_PROTOCOL_device
 #include "nsDeviceProtocolHandler.h"
+typedef mozilla::net::nsDeviceProtocolHandler nsDeviceProtocolHandler;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceProtocolHandler)
 #endif
 
 #ifdef NECKO_PROTOCOL_viewsource
 #include "nsViewSourceHandler.h"
+typedef mozilla::net::nsViewSourceHandler nsViewSourceHandler;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsViewSourceHandler)
 #endif
 
 #ifdef NECKO_PROTOCOL_data
 #include "nsDataHandler.h"
 #endif
 
 #ifdef NECKO_PROTOCOL_wyciwyg
@@ -370,20 +386,22 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(RtspHandl
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "nsURLParsers.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNoAuthURLParser)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAuthURLParser)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsStdURLParser)
 
 #include "nsStandardURL.h"
+typedef mozilla::net::nsStandardURL nsStandardURL;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsStandardURL)
-
+typedef mozilla::net::nsSimpleURI nsSimpleURI;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSimpleURI)
 
+typedef mozilla::net::nsSimpleNestedURI nsSimpleNestedURI;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSimpleNestedURI)
 
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "nsIDNService.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsIDNService, Init)
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -471,16 +489,17 @@ static const mozilla::Module::CategoryEn
     { NS_ISTREAMCONVERTER_KEY, BINHEX_TO_WILD, "" },
 #endif
     { NS_ISTREAMCONVERTER_KEY, PLAIN_TO_HTML, "" },
     NS_BINARYDETECTOR_CATEGORYENTRY,
     { nullptr }
 };
 
 #ifdef BUILD_BINHEX_DECODER
+typedef mozilla::net::nsBinHexDecoder nsBinHexDecoder;
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinHexDecoder)
 #endif
 
 static nsresult
 CreateNewStreamConvServiceFactory(nsISupports* aOuter, REFNSIID aIID, void **aResult) 
 {
     if (!aResult) {                                                  
         return NS_ERROR_INVALID_POINTER;                             
@@ -850,17 +869,17 @@ static const mozilla::Module::CIDEntry k
     { &kNS_DNSSERVICE_CID, false, nullptr, nsIDNSServiceConstructor },
     { &kNS_IDNSERVICE_CID, false, nullptr, nsIDNServiceConstructor },
     { &kNS_EFFECTIVETLDSERVICE_CID, false, nullptr, nsEffectiveTLDServiceConstructor },
     { &kNS_SIMPLEURI_CID, false, nullptr, nsSimpleURIConstructor },
     { &kNS_SIMPLENESTEDURI_CID, false, nullptr, nsSimpleNestedURIConstructor },
     { &kNS_ASYNCSTREAMCOPIER_CID, false, nullptr, nsAsyncStreamCopierConstructor },
     { &kNS_INPUTSTREAMPUMP_CID, false, nullptr, nsInputStreamPumpConstructor },
     { &kNS_INPUTSTREAMCHANNEL_CID, false, nullptr, nsInputStreamChannelConstructor },
-    { &kNS_STREAMLOADER_CID, false, nullptr, nsStreamLoader::Create },
+    { &kNS_STREAMLOADER_CID, false, nullptr, mozilla::net::nsStreamLoader::Create },
     { &kNS_INCREMENTALSTREAMLOADER_CID, false, nullptr, nsIncrementalStreamLoader::Create },
     { &kNS_UNICHARSTREAMLOADER_CID, false, nullptr, nsUnicharStreamLoader::Create },
     { &kNS_DOWNLOADER_CID, false, nullptr, nsDownloaderConstructor },
     { &kNS_BACKGROUNDFILESAVEROUTPUTSTREAM_CID, false, nullptr,
       mozilla::net::BackgroundFileSaverOutputStreamConstructor },
     { &kNS_BACKGROUNDFILESAVERSTREAMLISTENER_CID, false, nullptr,
       mozilla::net::BackgroundFileSaverStreamListenerConstructor },
     { &kNS_SYNCSTREAMLISTENER_CID, false, nullptr, nsSyncStreamListenerConstructor },
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -39,16 +39,17 @@
 #include "mozilla/Services.h"
 #include "nsITimer.h"
 #include "mozIStorageService.h"
 
 #include "mozilla/net/NeckoCommon.h"
 #include <algorithm>
 
 using namespace mozilla;
+using namespace mozilla::net;
 
 /******************************************************************************
  * nsCacheProfilePrefObserver
  *****************************************************************************/
 #define DISK_CACHE_ENABLE_PREF      "browser.cache.disk.enable"
 #define DISK_CACHE_DIR_PREF         "browser.cache.disk.parent_directory"
 #define DISK_CACHE_SMART_SIZE_FIRST_RUN_PREF\
     "browser.cache.disk.smart_size.first_run"
--- a/netwerk/protocol/about/nsAboutProtocolHandler.cpp
+++ b/netwerk/protocol/about/nsAboutProtocolHandler.cpp
@@ -16,16 +16,19 @@
 #include "nsNetUtil.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsAutoPtr.h"
 #include "nsIWritablePropertyBag2.h"
 #include "nsIChannel.h"
 #include "nsIScriptError.h"
 
+namespace mozilla {
+namespace net {
+
 static NS_DEFINE_CID(kSimpleURICID,     NS_SIMPLEURI_CID);
 static NS_DEFINE_CID(kNestedAboutURICID, NS_NESTEDABOUTURI_CID);
 
 static bool IsSafeForUntrustedContent(nsIAboutModule *aModule, nsIURI *aURI) {
   uint32_t flags;
   nsresult rv = aModule->GetURIFlags(aURI, &flags);
   NS_ENSURE_SUCCESS(rv, false);
 
@@ -413,8 +416,11 @@ nsNestedAboutURI::StartClone(nsSimpleURI
 
 // nsIClassInfo
 NS_IMETHODIMP
 nsNestedAboutURI::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
 {
     *aClassIDNoAlloc = kNestedAboutURICID;
     return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/protocol/about/nsAboutProtocolHandler.h
+++ b/netwerk/protocol/about/nsAboutProtocolHandler.h
@@ -8,16 +8,19 @@
 
 #include "nsIProtocolHandler.h"
 #include "nsSimpleNestedURI.h"
 #include "nsWeakReference.h"
 #include "mozilla/Attributes.h"
 
 class nsIURI;
 
+namespace mozilla {
+namespace net {
+
 class nsAboutProtocolHandler : public nsIProtocolHandlerWithDynamicFlags
                              , public nsIProtocolHandler
                              , public nsSupportsWeakReference
 {
 public:
     NS_DECL_ISUPPORTS
 
     // nsIProtocolHandler methods:
@@ -75,9 +78,12 @@ public:
     nsIURI* GetBaseURI() const {
         return mBaseURI;
     }
 
 protected:
     nsCOMPtr<nsIURI> mBaseURI;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif /* nsAboutProtocolHandler_h___ */
--- a/netwerk/protocol/device/nsDeviceProtocolHandler.cpp
+++ b/netwerk/protocol/device/nsDeviceProtocolHandler.cpp
@@ -3,18 +3,20 @@
  * 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 "nsDeviceProtocolHandler.h"
 #include "nsDeviceChannel.h"
 #include "nsAutoPtr.h"
 #include "nsSimpleURI.h"
 
+namespace mozilla {
+namespace net {
+
 //-----------------------------------------------------------------------------
-
 NS_IMPL_ISUPPORTS(nsDeviceProtocolHandler,
                   nsIProtocolHandler)
 
 nsresult
 nsDeviceProtocolHandler::Init(){
   return NS_OK;
 }
 
@@ -81,8 +83,11 @@ NS_IMETHODIMP
 nsDeviceProtocolHandler::AllowPort(int32_t port,
                                    const char *scheme,
                                    bool *aResult)
 {
   // don't override anything.  
   *aResult = false;
   return NS_OK;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/protocol/device/nsDeviceProtocolHandler.h
+++ b/netwerk/protocol/device/nsDeviceProtocolHandler.h
@@ -4,16 +4,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsDeviceProtocolHandler_h_
 #define nsDeviceProtocolHandler_h_
 
 #include "nsIProtocolHandler.h"
 #include "mozilla/Attributes.h"
 
+namespace mozilla {
+namespace net {
+
 // {6b0ffe9e-d114-486b-aeb7-da62e7273ed5}
 #define NS_DEVICEPROTOCOLHANDLER_CID                      \
 { 0x60ffe9e, 0xd114, 0x486b,                              \
     {0xae, 0xb7, 0xda, 0x62, 0xe7, 0x27, 0x3e, 0xd5} }
 
 class nsDeviceProtocolHandler final : public nsIProtocolHandler {
   ~nsDeviceProtocolHandler() {}
 
@@ -21,9 +24,11 @@ public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIPROTOCOLHANDLER
 
   nsDeviceProtocolHandler() {}
 
   nsresult Init();
 };
 
+} // namespace net
+} // namespace mozilla
 #endif
--- a/netwerk/protocol/http/AlternateServices.h
+++ b/netwerk/protocol/http/AlternateServices.h
@@ -22,20 +22,19 @@ https://tools.ietf.org/html/draft-ietf-h
 #ifndef mozilla_net_AlternateServices_h
 #define mozilla_net_AlternateServices_h
 
 #include "nsRefPtrHashtable.h"
 #include "nsString.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsISpeculativeConnect.h"
 
-class nsProxyInfo;
-
 namespace mozilla { namespace net {
 
+class nsProxyInfo;
 class nsHttpConnectionInfo;
 
 class AltSvcMapping
 {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AltSvcMapping)
   friend class AltSvcCache;
 
 private: // ctor from ProcessHeader
--- a/netwerk/protocol/http/Http2Stream.h
+++ b/netwerk/protocol/http/Http2Stream.h
@@ -10,23 +10,23 @@
 // https://www.rfc-editor.org/rfc/rfc7540.txt
 
 #include "mozilla/Attributes.h"
 #include "mozilla/UniquePtr.h"
 #include "nsAHttpTransaction.h"
 #include "nsISupportsPriority.h"
 #include "SimpleBuffer.h"
 
-class nsStandardURL;
 class nsIInputStream;
 class nsIOutputStream;
 
 namespace mozilla {
 namespace net {
 
+class nsStandardURL;
 class Http2Session;
 class Http2Decompressor;
 
 class Http2Stream
   : public nsAHttpSegmentReader
   , public nsAHttpSegmentWriter
 {
 public:
--- a/netwerk/protocol/http/NullHttpChannel.h
+++ b/netwerk/protocol/http/NullHttpChannel.h
@@ -9,22 +9,21 @@
 #include "nsIHttpChannel.h"
 #include "nsITimedChannel.h"
 #include "nsIURI.h"
 #include "nsCOMPtr.h"
 #include "mozilla/TimeStamp.h"
 #include "nsString.h"
 #include "prtime.h"
 
-class nsProxyInfo;
-class nsHttpChannel;
-
 namespace mozilla {
 namespace net {
 
+class nsProxyInfo;
+
 class NullHttpChannel final
   : public nsINullChannel
   , public nsIHttpChannel
   , public nsITimedChannel
 {
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSINULLCHANNEL
   NS_DECL_NSIHTTPCHANNEL
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -24,20 +24,22 @@ class nsIPrefBranch;
 class nsICancelable;
 class nsICookieService;
 class nsIIOService;
 class nsIRequestContextService;
 class nsISiteSecurityService;
 class nsIStreamConverterService;
 class nsITimer;
 
-extern mozilla::Atomic<PRThread*, mozilla::Relaxed> gSocketThread;
 
 namespace mozilla {
 namespace net {
+
+extern Atomic<PRThread*, Relaxed> gSocketThread;
+
 class ATokenBucketEvent;
 class EventTokenBucket;
 class Tickler;
 class nsHttpConnection;
 class nsHttpConnectionInfo;
 class nsHttpTransaction;
 class AltSvcMapping;
 
--- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp
@@ -16,16 +16,17 @@
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsIStreamConverterService.h"
 #include "nsIPipe.h"
 #include "nsNetUtil.h"
 #include "LoadInfo.h"
 
 namespace mozilla {
+namespace net {
 
 NS_IMPL_QUERY_INTERFACE(ExtensionProtocolHandler, nsISubstitutingProtocolHandler,
                         nsIProtocolHandler, nsIProtocolHandlerWithDynamicFlags,
                         nsISupportsWeakReference)
 NS_IMPL_ADDREF_INHERITED(ExtensionProtocolHandler, SubstitutingProtocolHandler)
 NS_IMPL_RELEASE_INHERITED(ExtensionProtocolHandler, SubstitutingProtocolHandler)
 
 nsresult
@@ -119,17 +120,17 @@ ExtensionProtocolHandler::SubstituteChan
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIStreamListener> converter;
     rv = convService->AsyncConvertData(kFromType, kToType, listener,
                                        aURI, getter_AddRefs(converter));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsILoadInfo> loadInfo =
-      static_cast<mozilla::LoadInfo*>(aLoadInfo)->CloneForNewRequest();
+      static_cast<LoadInfo*>(aLoadInfo)->CloneForNewRequest();
     (*result)->SetLoadInfo(loadInfo);
 
     rv = (*result)->AsyncOpen2(converter);
   } else {
     // Stylesheet loads for extension content scripts require a sync channel.
 
     nsCOMPtr<nsIInputStream> sourceStream;
     if (aLoadInfo && aLoadInfo->GetEnforceSecurity()) {
@@ -150,9 +151,10 @@ ExtensionProtocolHandler::SubstituteChan
                                         NS_LITERAL_CSTRING("utf-8"),
                                         aLoadInfo);
   NS_ENSURE_SUCCESS(rv, rv);
 
   channel.swap(*result);
   return NS_OK;
 }
 
+} // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/res/ExtensionProtocolHandler.h
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.h
@@ -5,27 +5,28 @@
 
 #ifndef ExtensionProtocolHandler_h___
 #define ExtensionProtocolHandler_h___
 
 #include "SubstitutingProtocolHandler.h"
 #include "nsWeakReference.h"
 
 namespace mozilla {
+namespace net {
 
 class ExtensionProtocolHandler final : public nsISubstitutingProtocolHandler,
                                        public nsIProtocolHandlerWithDynamicFlags,
-                                       public mozilla::SubstitutingProtocolHandler,
+                                       public SubstitutingProtocolHandler,
                                        public nsSupportsWeakReference
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIPROTOCOLHANDLERWITHDYNAMICFLAGS
-  NS_FORWARD_NSIPROTOCOLHANDLER(mozilla::SubstitutingProtocolHandler::)
-  NS_FORWARD_NSISUBSTITUTINGPROTOCOLHANDLER(mozilla::SubstitutingProtocolHandler::)
+  NS_FORWARD_NSIPROTOCOLHANDLER(SubstitutingProtocolHandler::)
+  NS_FORWARD_NSISUBSTITUTINGPROTOCOLHANDLER(SubstitutingProtocolHandler::)
 
   ExtensionProtocolHandler() : SubstitutingProtocolHandler("moz-extension") {}
 
 protected:
   ~ExtensionProtocolHandler() {}
 
   bool ResolveSpecialCases(const nsACString& aHost, const nsACString& aPath, nsACString& aResult) override
   {
@@ -38,11 +39,12 @@ protected:
     }
 
     return false;
   }
 
   virtual nsresult SubstituteChannel(nsIURI* uri, nsILoadInfo* aLoadInfo, nsIChannel** result) override;
 };
 
+} // namespace net
 } // namespace mozilla
 
 #endif /* ExtensionProtocolHandler_h___ */
--- a/netwerk/protocol/res/SubstitutingProtocolHandler.cpp
+++ b/netwerk/protocol/res/SubstitutingProtocolHandler.cpp
@@ -15,16 +15,17 @@
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsURLHelper.h"
 #include "nsEscape.h"
 
 using mozilla::dom::ContentParent;
 
 namespace mozilla {
+namespace net {
 
 // Log module for Substituting Protocol logging. We keep the pre-existing module
 // name of "nsResProtocol" to avoid disruption.
 static LazyLogModule gResLog("nsResProtocol");
 
 static NS_DEFINE_CID(kSubstitutingURLCID, NS_SUBSTITUTINGURL_CID);
 
 //---------------------------------------------------------------------------------
@@ -391,9 +392,10 @@ SubstitutingProtocolHandler::ResolveURI(
   if (MOZ_LOG_TEST(gResLog, LogLevel::Debug)) {
     nsAutoCString spec;
     uri->GetAsciiSpec(spec);
     MOZ_LOG(gResLog, LogLevel::Debug, ("%s\n -> %s\n", spec.get(), PromiseFlatCString(result).get()));
   }
   return rv;
 }
 
+} // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/res/SubstitutingProtocolHandler.h
+++ b/netwerk/protocol/res/SubstitutingProtocolHandler.h
@@ -13,16 +13,17 @@
 #include "nsIOService.h"
 #include "nsStandardURL.h"
 #include "mozilla/chrome/RegistryMessageUtils.h"
 #include "mozilla/Maybe.h"
 
 class nsIIOService;
 
 namespace mozilla {
+namespace net {
 
 //
 // Base class for resource://-like substitution protocols.
 //
 // If you add a new protocol, make sure to change nsChromeRegistryChrome
 // to properly invoke CollectSubstitutions at the right time.
 class SubstitutingProtocolHandler
 {
@@ -92,11 +93,12 @@ class SubstitutingURL : public nsStandar
 {
 public:
   SubstitutingURL() : nsStandardURL(true) {}
   virtual nsStandardURL* StartClone();
   virtual nsresult EnsureFile();
   NS_IMETHOD GetClassIDNoAlloc(nsCID *aCID);
 };
 
+} // namespace net
 } // namespace mozilla
 
 #endif /* SubstitutingProtocolHandler_h___ */
--- a/netwerk/protocol/viewsource/nsViewSourceHandler.cpp
+++ b/netwerk/protocol/viewsource/nsViewSourceHandler.cpp
@@ -6,16 +6,19 @@
 
 #include "nsViewSourceHandler.h"
 #include "nsViewSourceChannel.h"
 #include "nsNetUtil.h"
 #include "nsSimpleNestedURI.h"
 
 #define VIEW_SOURCE "view-source"
 
+namespace mozilla {
+namespace net {
+
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMPL_ISUPPORTS(nsViewSourceHandler, nsIProtocolHandler)
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIProtocolHandler methods:
 
 NS_IMETHODIMP
@@ -162,8 +165,11 @@ nsViewSourceHandler::~nsViewSourceHandle
 
 nsViewSourceHandler* nsViewSourceHandler::gInstance = nullptr;
 
 nsViewSourceHandler*
 nsViewSourceHandler::GetInstance()
 {
     return gInstance;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/protocol/viewsource/nsViewSourceHandler.h
+++ b/netwerk/protocol/viewsource/nsViewSourceHandler.h
@@ -7,16 +7,19 @@
 #define nsViewSourceHandler_h___
 
 #include "nsIProtocolHandler.h"
 #include "nsNetUtil.h"
 #include "mozilla/Attributes.h"
 
 class nsILoadInfo;
 
+namespace mozilla {
+namespace net {
+
 class nsViewSourceHandler final : public nsIProtocolHandler
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIPROTOCOLHANDLER
 
     nsViewSourceHandler();
 
@@ -31,9 +34,12 @@ public:
     static nsViewSourceHandler* GetInstance();
 
 private:
     ~nsViewSourceHandler();
 
     static nsViewSourceHandler* gInstance;
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif /* !defined( nsViewSourceHandler_h___ ) */
--- a/netwerk/standalone/nsNetModuleStandalone.cpp
+++ b/netwerk/standalone/nsNetModuleStandalone.cpp
@@ -72,16 +72,17 @@ ShutdownNetModuleStandalone()
 
 } // namespace mozilla
 
 #include "nsDNSService2.h"
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDNSService,
   nsDNSService::GetXPCOMSingleton)
 
 #include "nsSocketTransportService2.h"
+typedef mozilla::net::nsSocketTransportService nsSocketTransportService;
 #undef LOG
 #undef LOG_ENABLED
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSocketTransportService, Init)
 
 // Net module startup hook
 static nsresult nsNetStartup()
 {
     return NS_OK;
--- a/netwerk/streamconv/converters/nsBinHexDecoder.cpp
+++ b/netwerk/streamconv/converters/nsBinHexDecoder.cpp
@@ -15,16 +15,19 @@
 #include "prnetdb.h"
 #include "nsIURI.h"
 #include "nsIURL.h"
 
 #include "nsIMIMEService.h"
 #include "nsMimeTypes.h"
 #include <algorithm>
 
+namespace mozilla {
+namespace net {
+
 nsBinHexDecoder::nsBinHexDecoder() :
   mState(0), mCRC(0), mFileCRC(0), mOctetin(26),
   mDonePos(3), mInCRC(0), mCount(0), mMarker(0), mPosInbuff(0),
   mPosOutputBuff(0)
 {
   mDataBuffer = nullptr;
   mOutgoingBuffer = nullptr;
 
@@ -503,8 +506,11 @@ nsBinHexDecoder::OnStopRequest(nsIReques
   nsresult rv = NS_OK;
 
   if (!mNextListener) return NS_ERROR_FAILURE;
   // don't do anything here...we'll fire our own on stop request when we are done
   // processing the data....
 
   return rv;
 }
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/streamconv/converters/nsBinHexDecoder.h
+++ b/netwerk/streamconv/converters/nsBinHexDecoder.h
@@ -28,16 +28,19 @@
 #include "nsString.h"
 
 #define NS_BINHEXDECODER_CID                         \
 { /* 301DEA42-6850-4cda-8945-81F7DBC2186B */         \
   0x301dea42, 0x6850, 0x4cda,                        \
   { 0x89, 0x45, 0x81, 0xf7, 0xdb, 0xc2, 0x18, 0x6b } \
 }
 
+namespace mozilla {
+namespace net {
+
 typedef struct _binhex_header
 {
   uint32_t type, creator;
   uint16_t flags;
   int32_t dlen, rlen;
 } binhex_header;
 
 typedef union
@@ -112,9 +115,12 @@ protected:
 
   uint32_t mCount;        /* generic counter */
   int16_t mMarker;        /* flag indicating maker */
 
   int32_t mPosInbuff;     /* the index of the inbuff.  */
   int32_t mPosOutputBuff; /* the position of the out buff.    */
 };
 
+} // namespace net
+} // namespace mozilla
+
 #endif /* nsBinHexDecoder_h__ */