backout bug 1356277 due to failing test_localStorageSessionPrefOverride.html on try
authorMichael Layzell <michael@thelayzells.com>
Mon, 17 Apr 2017 15:23:23 -0400
changeset 404015 208114b8113ec8606d208c16642eb508cf4b7468
parent 404014 47318b7a82c08a1e77091377a1cd1639d4725450
child 404016 208be342247943db550927536f03bfb5f0f2ef31
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1356277
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
backout bug 1356277 due to failing test_localStorageSessionPrefOverride.html on try I looked at the wrong try push before pushing this change to inbound. Backing it out hopefully before it turns too many pushes orange. MozReview-Commit-ID: 5cREsyfWrmb
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/tests/mochitest/localstorage/file_tryAccessSessionStorage.html
dom/tests/mochitest/localstorage/mochitest.ini
dom/tests/mochitest/localstorage/test_firstPartyOnlyPermission.html
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -8774,54 +8774,16 @@ nsContentUtils::StorageAllowedForWindow(
 // static, public
 nsContentUtils::StorageAccess
 nsContentUtils::StorageAllowedForPrincipal(nsIPrincipal* aPrincipal)
 {
   return InternalStorageAllowedForPrincipal(aPrincipal, nullptr);
 }
 
 // static, private
-void
-nsContentUtils::GetCookieBehaviorForPrincipal(nsIPrincipal* aPrincipal,
-                                              uint32_t* aLifetimePolicy,
-                                              uint32_t* aBehavior)
-{
-  *aLifetimePolicy = sCookiesLifetimePolicy;
-  *aBehavior = sCookiesBehavior;
-
-  // Any permissions set for the given principal will override our default
-  // settings from preferences.
-  nsCOMPtr<nsIPermissionManager> permissionManager =
-    services::GetPermissionManager();
-  if (!permissionManager) {
-    return;
-  }
-
-  uint32_t perm;
-  permissionManager->TestPermissionFromPrincipal(aPrincipal, "cookie", &perm);
-  switch (perm) {
-    case nsICookiePermission::ACCESS_ALLOW:
-      *aBehavior = nsICookieService::BEHAVIOR_ACCEPT;
-      break;
-    case nsICookiePermission::ACCESS_DENY:
-      *aBehavior = nsICookieService::BEHAVIOR_REJECT;
-      break;
-    case nsICookiePermission::ACCESS_SESSION:
-      *aLifetimePolicy = nsICookieService::ACCEPT_SESSION;
-      break;
-    case nsICookiePermission::ACCESS_ALLOW_FIRST_PARTY_ONLY:
-      *aBehavior = nsICookieService::BEHAVIOR_REJECT_FOREIGN;
-      break;
-    case nsICookiePermission::ACCESS_LIMIT_THIRD_PARTY:
-      *aBehavior = nsICookieService::BEHAVIOR_LIMIT_FOREIGN;
-      break;
-  }
-}
-
-// static, private
 nsContentUtils::StorageAccess
 nsContentUtils::InternalStorageAllowedForPrincipal(nsIPrincipal* aPrincipal,
                                                    nsPIDOMWindowInner* aWindow)
 {
   MOZ_ASSERT(aPrincipal);
   MOZ_ASSERT(!aWindow || aWindow->IsInnerWindow());
 
   StorageAccess access = StorageAccess::eAllow;
@@ -8840,22 +8802,38 @@ nsContentUtils::InternalStorageAllowedFo
     }
 
     // Check if we are in private browsing, and record that fact
     if (IsInPrivateBrowsing(document)) {
       access = StorageAccess::ePrivateBrowsing;
     }
   }
 
-  uint32_t lifetimePolicy;
-  uint32_t behavior;
-  GetCookieBehaviorForPrincipal(aPrincipal, &lifetimePolicy, &behavior);
+  nsCOMPtr<nsIPermissionManager> permissionManager =
+    services::GetPermissionManager();
+  if (!permissionManager) {
+    return StorageAccess::eDeny;
+  }
+
+  // check the permission manager for any allow or deny permissions
+  // for cookies for the window.
+  uint32_t perm;
+  permissionManager->TestPermissionFromPrincipal(aPrincipal, "cookie", &perm);
+  if (perm == nsIPermissionManager::DENY_ACTION) {
+    return StorageAccess::eDeny;
+  }
+  if (perm == nsICookiePermission::ACCESS_SESSION) {
+    return std::min(access, StorageAccess::eSessionScoped);
+  }
+  if (perm == nsIPermissionManager::ALLOW_ACTION) {
+    return access;
+  }
 
   // Check if we should only allow storage for the session, and record that fact
-  if (lifetimePolicy == nsICookieService::ACCEPT_SESSION) {
+  if (sCookiesLifetimePolicy == nsICookieService::ACCEPT_SESSION) {
     // Storage could be StorageAccess::ePrivateBrowsing or StorageAccess::eAllow
     // so perform a std::min comparison to make sure we preserve ePrivateBrowsing
     // if it has been set.
     access = std::min(StorageAccess::eSessionScoped, access);
   }
 
   // About URIs are allowed to access storage, even if they don't have chrome
   // privileges. If this is not desired, than the consumer will have to
@@ -8886,23 +8864,23 @@ nsContentUtils::InternalStorageAllowedFo
     bool isAbout = false;
     MOZ_ALWAYS_SUCCEEDS(uri->SchemeIs("about", &isAbout));
     if (isAbout) {
       return access;
     }
   }
 
   // We don't want to prompt for every attempt to access permissions.
-  if (behavior == nsICookieService::BEHAVIOR_REJECT) {
+  if (sCookiesBehavior == nsICookieService::BEHAVIOR_REJECT) {
     return StorageAccess::eDeny;
   }
 
   // In the absense of a window, we assume that we are first-party.
-  if (aWindow && (behavior == nsICookieService::BEHAVIOR_REJECT_FOREIGN ||
-                  behavior == nsICookieService::BEHAVIOR_LIMIT_FOREIGN)) {
+  if (aWindow && (sCookiesBehavior == nsICookieService::BEHAVIOR_REJECT_FOREIGN ||
+                  sCookiesBehavior == nsICookieService::BEHAVIOR_LIMIT_FOREIGN)) {
     nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
       do_GetService(THIRDPARTYUTIL_CONTRACTID);
     MOZ_ASSERT(thirdPartyUtil);
 
     bool thirdPartyWindow = false;
     if (NS_SUCCEEDED(thirdPartyUtil->IsThirdPartyWindow(
           aWindow->GetOuterWindow(), nullptr, &thirdPartyWindow)) && thirdPartyWindow) {
       // XXX For non-cookie forms of storage, we handle BEHAVIOR_LIMIT_FOREIGN by
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2899,26 +2899,16 @@ private:
   // Fills in aInfo with the tokens from the supplied autocomplete attribute.
   static AutocompleteAttrState InternalSerializeAutocompleteAttribute(const nsAttrValue* aAttrVal,
                                                                       mozilla::dom::AutocompleteInfo& aInfo);
 
   static bool CallOnAllRemoteChildren(nsIMessageBroadcaster* aManager,
                                       CallOnRemoteChildFunction aCallback,
                                       void* aArg);
 
-  /**
-   * Gets the current cookie lifetime policy and cookie behavior for a given
-   * principal by checking with preferences and the permission manager.
-   *
-   * Used in the implementation of InternalStorageAllowedForPrincipal.
-   */
-  static void GetCookieBehaviorForPrincipal(nsIPrincipal* aPrincipal,
-                                            uint32_t* aLifetimePolicy,
-                                            uint32_t* aBehavior);
-
   /*
    * Checks if storage for a given principal is permitted by the user's
    * preferences. If aWindow is non-null, its principal must be passed as
    * aPrincipal, and the third-party iframe and sandboxing status of the window
    * are also checked.
    *
    * Used in the implementation of StorageAllowedForWindow and
    * StorageAllowedForPrincipal.
deleted file mode 100644
--- a/dom/tests/mochitest/localstorage/file_tryAccessSessionStorage.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<script>
-  try {
-    sessionStorage.setItem("am_i_blocked", "nope");
-    window.parent.postMessage('sessionStorage=true', '*');
-    document.body.innerHTML += 'yes';
-  } catch (ex) {
-    window.parent.postMessage('sessionStorage=false', '*');
-    document.body.innerHTML += 'no';
-  }
-</script>
--- a/dom/tests/mochitest/localstorage/mochitest.ini
+++ b/dom/tests/mochitest/localstorage/mochitest.ini
@@ -11,17 +11,16 @@ support-files =
   frameReplace.html
   frameSlaveEqual.html
   frameSlaveNotEqual.html
   interOriginFrame.js
   interOriginTest.js
   interOriginTest2.js
   localStorageCommon.js
   frameLocalStorageSessionOnly.html
-  file_tryAccessSessionStorage.html
 
 [test_brokenUTF-16.html]
 [test_bug600307-DBOps.html]
 [test_bug746272-1.html]
 [test_bug746272-2.html]
 skip-if = os == "android" # bug 962029
 [test_cookieBlock.html]
 [test_cookieSession.html]
@@ -46,9 +45,8 @@ skip-if = toolkit == 'android' #TIMED_OU
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_localStorageQuotaSessionOnly2.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_localStorageReplace.html]
 skip-if = toolkit == 'android'
 [test_lowDeviceStorage.html]
 [test_storageConstructor.html]
 [test_localStorageSessionPrefOverride.html]
-[test_firstPartyOnlyPermission.html]
deleted file mode 100644
--- a/dom/tests/mochitest/localstorage/test_firstPartyOnlyPermission.html
+++ /dev/null
@@ -1,62 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<title>first party storage permission test</title>
-
-<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
-<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-
-<script type="text/javascript">
-  TRY_ACCESS_SESSION_STORAGE =
-    'http://example.com/tests/dom/tests/mochitest/localstorage/file_tryAccessSessionStorage.html';
-
-  add_task(function*() {
-    yield SpecialPowers.pushPrefEnv({
-      set: [['network.cookie.cookieBehavior', SpecialPowers.Ci.nsICookieService.BEHAVIOR_REJECT]],
-    });
-
-    try {
-      sessionStorage.setItem("blocked", "blocked");
-      ok(false, "Shouldn't be avaliable yet");
-    } catch (ex) {
-      ok(true, "Shouldn't be avaliable yet");
-    }
-
-    yield new Promise(resolve => SpecialPowers.pushPermissions([{
-      type: 'cookie',
-      allow: SpecialPowers.Ci.nsICookiePermission.ACCESS_ALLOW_FIRST_PARTY_ONLY,
-      context: document,
-    }], resolve));
-
-    // With the permission set to ACCESS_ALLOW_FIRST_PARTY_ONLY, we should be
-    // able to run it from this iframe (as we are first party with the test
-    // runner parent document).
-    try {
-      sessionStorage.setItem("blocked", "blocked");
-      ok(true, "Should be avaliable");
-    } catch (ex) {
-      ok(false, "Should be avaliable");
-    }
-
-    // A third party iframe should not have access however.
-    yield new Promise(resolve => {
-      window.onmessage = evt => {
-        window.onmessage = null;
-        is(evt.data, "sessionStorage=false");
-        resolve();
-      };
-
-      let iframe = document.createElement('iframe');
-      iframe.setAttribute('src', TRY_ACCESS_SESSION_STORAGE);
-      document.body.appendChild(iframe);
-    });
-  });
-
-</script>
-
-</head>
-
-<body>
-
-</body>
-</html>