Bug 1235657 - Session storage needs to handle origin attributes correctly - part 1 - createOriginAttributesWithUserContextId, r=huseby
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 06 Jan 2016 10:08:30 +0000
changeset 278814 384bf27d0f586f19b5b86b3ecee7cb188e682cd6
parent 278813 7bc312c15f1fd17866f6f177dfedb7e2a96880b0
child 278815 d540e9c1a4fd83a80dcac542fcd30f14506398d1
push id29860
push usercbook@mozilla.com
push dateThu, 07 Jan 2016 10:51:20 +0000
treeherdermozilla-central@e0bcd16e1d4b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershuseby
bugs1235657
milestone46.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
Bug 1235657 - Session storage needs to handle origin attributes correctly - part 1 - createOriginAttributesWithUserContextId, r=huseby
caps/tests/unit/test_origin.js
dom/base/ChromeUtils.cpp
dom/base/ChromeUtils.h
dom/webidl/ChromeUtils.webidl
--- a/caps/tests/unit/test_origin.js
+++ b/caps/tests/unit/test_origin.js
@@ -28,16 +28,19 @@ function checkOriginAttributes(prin, att
   do_check_eq(prin.originSuffix, suffix || '');
   do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), suffix || '');
   do_check_true(ChromeUtils.originAttributesMatchPattern(prin.originAttributes, attrs));
   if (!prin.isNullPrincipal && !prin.origin.startsWith('[')) {
     do_check_true(ssm.createCodebasePrincipalFromOrigin(prin.origin).equals(prin));
   } else {
     checkThrows(() => ssm.createCodebasePrincipalFromOrigin(prin.origin));
   }
+
+  do_check_eq(ChromeUtils.createOriginAttributesWithUserContextId("http://example.org", 2).userContextId, 2);
+  do_check_eq(ChromeUtils.createOriginAttributesWithUserContextId("https://www.example.com:123^userContextId=4", 2).userContextId, 2);
 }
 
 function run_test() {
   // Attributeless origins.
   do_check_eq(ssm.getSystemPrincipal().origin, '[System Principal]');
   checkOriginAttributes(ssm.getSystemPrincipal());
   var exampleOrg = ssm.createCodebasePrincipal(makeURI('http://example.org'), {});
   do_check_eq(exampleOrg.origin, 'http://example.org');
--- a/dom/base/ChromeUtils.cpp
+++ b/dom/base/ChromeUtils.cpp
@@ -65,10 +65,28 @@ ChromeUtils::OriginAttributesMatchPatter
                                           const dom::OriginAttributesDictionary& aAttrs,
                                           const dom::OriginAttributesPatternDictionary& aPattern)
 {
   GenericOriginAttributes attrs(aAttrs);
   OriginAttributesPattern pattern(aPattern);
   return pattern.Matches(attrs);
 }
 
+/* static */ void
+ChromeUtils::CreateOriginAttributesWithUserContextId(dom::GlobalObject& aGlobal,
+                                                     const nsAString& aOrigin,
+                                                     uint32_t aUserContextId,
+                                                     dom::OriginAttributesDictionary& aAttrs,
+                                                     ErrorResult& aRv)
+{
+  GenericOriginAttributes attrs;
+  nsAutoCString suffix;
+  if (!attrs.PopulateFromOrigin(NS_ConvertUTF16toUTF8(aOrigin), suffix)) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return;
+  }
+
+  attrs.mUserContextId = aUserContextId;
+  aAttrs = attrs;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/base/ChromeUtils.h
+++ b/dom/base/ChromeUtils.h
@@ -52,14 +52,21 @@ public:
   OriginAttributesToSuffix(dom::GlobalObject& aGlobal,
                            const dom::OriginAttributesDictionary& aAttrs,
                            nsCString& aSuffix);
 
   static bool
   OriginAttributesMatchPattern(dom::GlobalObject& aGlobal,
                                const dom::OriginAttributesDictionary& aAttrs,
                                const dom::OriginAttributesPatternDictionary& aPattern);
+
+  static void
+  CreateOriginAttributesWithUserContextId(dom::GlobalObject& aGlobal,
+                                          const nsAString& aOrigin,
+                                          uint32_t aUserContextId,
+                                          dom::OriginAttributesDictionary& aAttrs,
+                                          ErrorResult& aRv);
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_ChromeUtils__
--- a/dom/webidl/ChromeUtils.webidl
+++ b/dom/webidl/ChromeUtils.webidl
@@ -23,16 +23,25 @@ interface ChromeUtils : ThreadSafeChrome
    * of |pattern|.
    *
    * @param originAttrs       The originAttributes under consideration.
    * @param pattern           The pattern to use for matching.
    */
   static boolean
   originAttributesMatchPattern(optional OriginAttributesDictionary originAttrs,
                                optional OriginAttributesPatternDictionary pattern);
+
+  /**
+   * Returns an OriginAttributes dictionary using the origin URI but forcing
+   * the passed userContextId.
+   */
+  [Throws]
+  static OriginAttributesDictionary
+  createOriginAttributesWithUserContextId(DOMString origin,
+                                          unsigned long userContextId);
 };
 
 /**
  * Used by principals and the script security manager to represent origin
  * attributes. The first dictionary is designed to contain the full set of
  * OriginAttributes, the second is used for pattern-matching (i.e. does this
  * OriginAttributesDictionary match the non-empty attributes in this pattern).
  *