Bug 1363311 - Honor Set-Cookie headers in multipart/mixed response boundary headers in e10s mode. r=jdm, a=gchang
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 20 May 2017 00:47:59 -0400
changeset 396408 a9c5f2fbb7fbdef723b6d954aef9c21456a718c7
parent 396407 2b2e0bc442c77da9a2d19aeb6e72d679f7159668
child 396409 d3ce3e3812c9372a12b6416f0ceedd2e768b5277
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm, gchang
bugs1363311
milestone54.0
Bug 1363311 - Honor Set-Cookie headers in multipart/mixed response boundary headers in e10s mode. r=jdm, a=gchang
netwerk/cookie/CookieServiceChild.cpp
netwerk/cookie/CookieServiceChild.h
netwerk/cookie/CookieServiceParent.cpp
netwerk/cookie/CookieServiceParent.h
netwerk/cookie/PCookieService.ipdl
netwerk/test/unit/test_multipart_streamconv.js
netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js
netwerk/test/unit_ipc/xpcshell.ini
--- a/netwerk/cookie/CookieServiceChild.cpp
+++ b/netwerk/cookie/CookieServiceChild.cpp
@@ -139,17 +139,18 @@ CookieServiceChild::GetCookieStringInter
 
   return NS_OK;
 }
 
 nsresult
 CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI,
                                             nsIChannel *aChannel,
                                             const char *aCookieString,
-                                            const char *aServerTime)
+                                            const char *aServerTime,
+                                            bool aFromHttp)
 {
   NS_ENSURE_ARG(aHostURI);
   NS_ENSURE_ARG_POINTER(aCookieString);
 
   // Fast past: don't bother sending IPC messages about nullprincipal'd
   // documents.
   nsAutoCString scheme;
   aHostURI->GetScheme(scheme);
@@ -174,17 +175,17 @@ CookieServiceChild::SetCookieStringInter
     nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
     if (loadInfo) {
       attrs = loadInfo->GetOriginAttributes();
     }
   }
 
   // Synchronously call the parent.
   SendSetCookieString(uriParams, !!isForeign, cookieString, serverTime,
-                      attrs);
+                      attrs, aFromHttp);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CookieServiceChild::Observe(nsISupports     *aSubject,
                             const char      *aTopic,
                             const char16_t *aData)
 {
@@ -215,25 +216,27 @@ CookieServiceChild::GetCookieStringFromH
 }
 
 NS_IMETHODIMP
 CookieServiceChild::SetCookieString(nsIURI *aHostURI,
                                     nsIPrompt *aPrompt,
                                     const char *aCookieString,
                                     nsIChannel *aChannel)
 {
-  return SetCookieStringInternal(aHostURI, aChannel, aCookieString, nullptr);
+  return SetCookieStringInternal(aHostURI, aChannel, aCookieString,
+                                 nullptr, false);
 }
 
 NS_IMETHODIMP
 CookieServiceChild::SetCookieStringFromHttp(nsIURI     *aHostURI,
                                             nsIURI     *aFirstURI,
                                             nsIPrompt  *aPrompt,
                                             const char *aCookieString,
                                             const char *aServerTime,
                                             nsIChannel *aChannel) 
 {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  return SetCookieStringInternal(aHostURI, aChannel, aCookieString,
+                                 aServerTime, true);
 }
 
 } // namespace net
 } // namespace mozilla
 
--- a/netwerk/cookie/CookieServiceChild.h
+++ b/netwerk/cookie/CookieServiceChild.h
@@ -42,17 +42,18 @@ protected:
 
   nsresult GetCookieStringInternal(nsIURI *aHostURI,
                                    nsIChannel *aChannel,
                                    char **aCookieString);
 
   nsresult SetCookieStringInternal(nsIURI *aHostURI,
                                    nsIChannel *aChannel,
                                    const char *aCookieString,
-                                   const char *aServerTime);
+                                   const char *aServerTime,
+                                   bool aFromHttp);
 
   void PrefChanged(nsIPrefBranch *aPrefBranch);
 
   bool RequireThirdPartyCheck();
 
   nsCOMPtr<mozIThirdPartyUtil> mThirdPartyUtil;
   uint8_t mCookieBehavior;
   bool mThirdPartySession;
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -110,17 +110,18 @@ CookieServiceParent::RecvGetCookieString
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
                                          const bool& aIsForeign,
                                          const nsCString& aCookieString,
                                          const nsCString& aServerTime,
-                                         const OriginAttributes& aAttrs)
+                                         const OriginAttributes& aAttrs,
+                                         const bool& aFromHttp)
 {
   if (!mCookieService)
     return IPC_OK();
 
   // Deserialize URI. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
   nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
   if (!hostURI)
@@ -137,16 +138,16 @@ CookieServiceParent::RecvSetCookieString
   // to use the channel to inspect it.
   nsCOMPtr<nsIChannel> dummyChannel;
   CreateDummyChannel(hostURI, const_cast<OriginAttributes&>(aAttrs),
                      isPrivate, getter_AddRefs(dummyChannel));
 
   // NB: dummyChannel could be null if something failed in CreateDummyChannel.
   nsDependentCString cookieString(aCookieString, 0);
   mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
-                                          aServerTime, false, aAttrs,
+                                          aServerTime, aFromHttp, aAttrs,
                                           isPrivate, dummyChannel);
   return IPC_OK();
 }
 
 } // namespace net
 } // namespace mozilla
 
--- a/netwerk/cookie/CookieServiceParent.h
+++ b/netwerk/cookie/CookieServiceParent.h
@@ -27,17 +27,18 @@ protected:
                                                       const bool& aIsForeign,
                                                       const OriginAttributes& aAttrs,
                                                       nsCString* aResult) override;
 
   virtual mozilla::ipc::IPCResult RecvSetCookieString(const URIParams& aHost,
                                                       const bool& aIsForeign,
                                                       const nsCString& aCookieString,
                                                       const nsCString& aServerTime,
-                                                      const OriginAttributes& aAttrs) override;
+                                                      const OriginAttributes& aAttrs,
+                                                      const bool& aFromHttp) override;
 
   RefPtr<nsCookieService> mCookieService;
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // mozilla_net_CookieServiceParent_h
--- a/netwerk/cookie/PCookieService.ipdl
+++ b/netwerk/cookie/PCookieService.ipdl
@@ -92,16 +92,17 @@ parent:
    * @see nsICookieService.setCookieString
    * @see nsICookieService.setCookieStringFromHttp
    * @see mozIThirdPartyUtil.isThirdPartyChannel
    */
   nested(inside_cpow) async SetCookieString(URIParams host,
                                             bool isForeign,
                                             nsCString cookieString,
                                             nsCString serverTime,
-                                            OriginAttributes attrs);
+                                            OriginAttributes attrs,
+                                            bool aFromHttp);
 
   async __delete__();
 };
 
 }
 }
 
--- a/netwerk/test/unit/test_multipart_streamconv.js
+++ b/netwerk/test/unit/test_multipart_streamconv.js
@@ -6,17 +6,17 @@ var httpserver = null;
 XPCOMUtils.defineLazyGetter(this, "uri", function() {
   return "http://localhost:" + httpserver.identity.primaryPort + "/multipart";
 });
 
 function make_channel(url) {
   return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
 }
 
-var multipartBody = "--boundary\r\n\r\nSome text\r\n--boundary\r\nContent-Type: text/x-test\r\n\r\n<?xml version='1.1'?>\r\n<root/>\r\n--boundary\r\n\r\n<?xml version='1.0'?><root/>\r\n--boundary--";
+var multipartBody = "--boundary\r\nSet-Cookie: foo=bar\r\n\r\nSome text\r\n--boundary\r\nContent-Type: text/x-test\r\n\r\n<?xml version='1.1'?>\r\n<root/>\r\n--boundary\r\n\r\n<?xml version='1.0'?><root/>\r\n--boundary--";
 
 function contentHandler(metadata, response)
 {
   response.setHeader("Content-Type", 'multipart/mixed; boundary="boundary"');
   response.bodyOutputStream.write(multipartBody, multipartBody.length);
 }
 
 var numTests = 2;
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit_ipc/test_multipart_streamconv_wrap.js
@@ -0,0 +1,3 @@
+function run_test() {
+  run_test_in_child("../unit/test_multipart_streamconv.js");
+}
--- a/netwerk/test/unit_ipc/xpcshell.ini
+++ b/netwerk/test/unit_ipc/xpcshell.ini
@@ -51,16 +51,17 @@ support-files =
   !/netwerk/test/unit/data/test_readline5.txt
   !/netwerk/test/unit/data/test_readline6.txt
   !/netwerk/test/unit/data/test_readline7.txt
   !/netwerk/test/unit/data/test_readline8.txt
   !/netwerk/test/unit/data/signed_win.exe
   !/netwerk/test/unit/test_alt-data_simple.js
   !/netwerk/test/unit/test_alt-data_stream.js
   !/netwerk/test/unit/test_channel_priority.js
+  !/netwerk/test/unit/test_multipart_streamconv.js
 
 [test_bug528292_wrap.js]
 [test_bug248970_cookie_wrap.js]
 [test_cacheflags_wrap.js]
 [test_cache_jar_wrap.js]
 [test_channel_close_wrap.js]
 [test_cookie_header_wrap.js]
 [test_cookiejars_wrap.js]
@@ -96,8 +97,9 @@ skip-if = true
 [test_getHost_wrap.js]
 [test_alt-data_simple_wrap.js]
 [test_alt-data_stream_wrap.js]
 [test_original_sent_received_head_wrap.js]
 [test_channel_id.js]
 [test_trackingProtection_annotateChannels_wrap1.js]
 [test_trackingProtection_annotateChannels_wrap2.js]
 [test_channel_priority_wrap.js]
+[test_multipart_streamconv_wrap.js]