Bug 1298823 - Make Request constructor throw less often, r=qdot
☠☠ backed out by 8a5b7f743d66 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 01 Mar 2017 11:44:38 +0100
changeset 374314 6d0ac4c74fd5a4e2f53e83c00ff8ca24abe5e1d7
parent 374313 f73f900fab1c6e320786647327204cce7ba31bcb
child 374315 e9dcba1a87af814aa7bb81f8233bb5461f8b84a1
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1298823
milestone54.0a1
Bug 1298823 - Make Request constructor throw less often, r=qdot
dom/fetch/Request.cpp
testing/web-platform/meta/fetch/api/policies/referrer-origin-service-worker.https.html.ini
testing/web-platform/meta/fetch/api/policies/referrer-origin-worker.html.ini
testing/web-platform/meta/fetch/api/policies/referrer-origin.html.ini
testing/web-platform/meta/fetch/api/request/request-init-001.sub.html.ini
--- a/dom/fetch/Request.cpp
+++ b/dom/fetch/Request.cpp
@@ -333,18 +333,17 @@ Request::Constructor(const GlobalObject&
 
   RequestMode mode = aInit.mMode.WasPassed() ? aInit.mMode.Value() : fallbackMode;
   RequestCredentials credentials =
     aInit.mCredentials.WasPassed() ? aInit.mCredentials.Value()
                                    : fallbackCredentials;
 
   if (mode == RequestMode::Navigate ||
       (aInit.IsAnyMemberPresent() && request->Mode() == RequestMode::Navigate)) {
-    aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>(NS_LITERAL_STRING("navigate"));
-    return nullptr;
+    mode = RequestMode::Same_origin;
   }
 
   if (aInit.IsAnyMemberPresent()) {
     request->SetReferrer(NS_LITERAL_STRING(kFETCH_CLIENT_REFERRER_STR));
     request->SetReferrerPolicy(ReferrerPolicy::_empty);
   }
   if (aInit.mReferrer.WasPassed()) {
     const nsString& referrer = aInit.mReferrer.Value();
@@ -369,21 +368,17 @@ Request::Constructor(const GlobalObject&
         uri->GetSpec(spec);
         CopyUTF8toUTF16(spec, referrerURL);
         if (!referrerURL.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) {
           nsCOMPtr<nsIPrincipal> principal = global->PrincipalOrNull();
           if (principal) {
             nsresult rv = principal->CheckMayLoad(uri, /* report */ false,
                                                   /* allowIfInheritsPrincipal */ false);
             if (NS_FAILED(rv)) {
-              nsAutoCString globalOrigin;
-              principal->GetOrigin(globalOrigin);
-              aRv.ThrowTypeError<MSG_CROSS_ORIGIN_REFERRER_URL>(referrer,
-                                                                NS_ConvertUTF8toUTF16(globalOrigin));
-              return nullptr;
+              referrerURL.AssignLiteral(kFETCH_CLIENT_REFERRER_STR);
             }
           }
         }
       } else {
         RefPtr<URL> url = ParseURLFromWorker(aGlobal, referrer, aRv);
         if (NS_WARN_IF(aRv.Failed())) {
           aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(referrer);
           return nullptr;
@@ -398,21 +393,20 @@ Request::Constructor(const GlobalObject&
           nsresult rv = NS_OK;
           // ReferrerSameOriginChecker uses a sync loop to get the main thread
           // to perform the same-origin check.  Overall, on Workers this method
           // can create 3 sync loops (two for constructing URLs and one here) so
           // in the future we may want to optimize it all by off-loading all of
           // this work in a single sync loop.
           RefPtr<ReferrerSameOriginChecker> checker =
             new ReferrerSameOriginChecker(worker, referrerURL, rv);
-          checker->Dispatch(Terminating, aRv);
-          if (aRv.Failed() || NS_FAILED(rv)) {
-            aRv.ThrowTypeError<MSG_CROSS_ORIGIN_REFERRER_URL>(referrer,
-                                                              worker->GetLocationInfo().mOrigin);
-            return nullptr;
+          IgnoredErrorResult error;
+          checker->Dispatch(Terminating, error);
+          if (error.Failed() || NS_FAILED(rv)) {
+            referrerURL.AssignLiteral(kFETCH_CLIENT_REFERRER_STR);
           }
         }
       }
       request->SetReferrer(referrerURL);
     }
   }
 
   if (aInit.mReferrerPolicy.WasPassed()) {
deleted file mode 100644
--- a/testing/web-platform/meta/fetch/api/policies/referrer-origin-service-worker.https.html.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[referrer-origin-service-worker.https.html]
-  type: testharness
-  [Cross-origin referrer is overridden by client origin]
-    expected: FAIL
-    bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1341223
-
deleted file mode 100644
--- a/testing/web-platform/meta/fetch/api/policies/referrer-origin-worker.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[referrer-origin-worker.html]
-  type: testharness
-  [Cross-origin referrer is overridden by client origin]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/fetch/api/policies/referrer-origin.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[referrer-origin.html]
-  type: testharness
-  [Cross-origin referrer is overridden by client origin]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/fetch/api/request/request-init-001.sub.html.ini
+++ /dev/null
@@ -1,8 +0,0 @@
-[request-init-001.sub.html]
-  type: testharness
-  [Check referrer init value of http://test.url and associated getter]
-    expected: FAIL
-
-  [Check mode init value of navigate and associated getter]
-    expected: FAIL
-