Bug 1500791 - remove hardcoded restriction on bools that may be prio-encoded r=hsivonen
authorRobert Helmer <rhelmer@mozilla.com>
Fri, 26 Oct 2018 15:00:46 +0000
changeset 443196 ce8127ea1c4bc1d53304e7e91a2224991fe17659
parent 443195 8db8e74f328a25596a6f934b9ef66006217c3dc8
child 443197 f3cd65f621682f1e8d4061ea209c709f166872fb
push id34944
push userncsoregi@mozilla.com
push dateSat, 27 Oct 2018 09:49:55 +0000
treeherdermozilla-central@49d47a692ca4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1500791
milestone65.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 1500791 - remove hardcoded restriction on bools that may be prio-encoded r=hsivonen Differential Revision: https://phabricator.services.mozilla.com/D9555
dom/chrome-webidl/PrioEncoder.webidl
dom/prio/PrioEncoder.cpp
dom/prio/test/gtest/TestPrioEncoder.cpp
--- a/dom/chrome-webidl/PrioEncoder.webidl
+++ b/dom/chrome-webidl/PrioEncoder.webidl
@@ -6,17 +6,15 @@
 
 [ChromeOnly, Exposed=Window]
 namespace PrioEncoder {
   [Throws, NewObject]
   PrioEncodedData encode(ByteString batchID, PrioParams params);
 };
 
 dictionary PrioParams {
-  required boolean browserIsUserDefault;
-  required boolean newTabPageEnabled;
-  required boolean pdfViewerUsed;
+  required sequence<boolean> booleans;
 };
 
 dictionary PrioEncodedData {
   Uint8Array a;
   Uint8Array b;
 };
\ No newline at end of file
--- a/dom/prio/PrioEncoder.cpp
+++ b/dom/prio/PrioEncoder.cpp
@@ -100,23 +100,19 @@ PrioEncoder::Encode(GlobalObject& aGloba
       aRv.Throw(NS_ERROR_UNEXPECTED);
       return;
     }
 
     sSingleton = new PrioEncoder();
     ClearOnShutdown(&sSingleton);
   }
 
-  bool dataItems[] = {
-    aPrioParams.mBrowserIsUserDefault,
-    aPrioParams.mNewTabPageEnabled,
-    aPrioParams.mPdfViewerUsed,
-  };
+  nsTArray<bool> dataItems = aPrioParams.mBooleans;
 
-  PrioConfig prioConfig = PrioConfig_new(mozilla::ArrayLength(dataItems),
+  PrioConfig prioConfig = PrioConfig_new(dataItems.Length(),
                                          sPublicKeyA,
                                          sPublicKeyB,
                                          reinterpret_cast<const unsigned char*>(aBatchID.BeginReading()),
                                          aBatchID.Length());
 
   if (!prioConfig) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
@@ -127,17 +123,17 @@ PrioEncoder::Encode(GlobalObject& aGloba
   });
 
   unsigned char* forServerA = nullptr;
   unsigned int lenA = 0;
   unsigned char* forServerB = nullptr;
   unsigned int lenB = 0;
 
   prio_rv = PrioClient_encode(prioConfig,
-                              dataItems,
+                              dataItems.Elements(),
                               &forServerA,
                               &lenA,
                               &forServerB,
                               &lenB);
 
   nsTArray<uint8_t> arrayForServerA;
   nsTArray<uint8_t> arrayForServerB;
 
--- a/dom/prio/test/gtest/TestPrioEncoder.cpp
+++ b/dom/prio/test/gtest/TestPrioEncoder.cpp
@@ -23,20 +23,16 @@ TEST(PrioEncoder, BadPublicKeys)
   mozilla::Preferences::SetCString("prio.publicKeyB",
     nsCString(NS_LITERAL_CSTRING("badB")));
 
   mozilla::dom::GlobalObject global(cx, xpc::PrivilegedJunkScope());
 
   nsCString batchID = NS_LITERAL_CSTRING("abc123");
 
   mozilla::dom::PrioParams prioParams;
-  prioParams.mBrowserIsUserDefault = true;
-  prioParams.mNewTabPageEnabled = true;
-  prioParams.mPdfViewerUsed = false;
-
   mozilla::dom::RootedDictionary<mozilla::dom::PrioEncodedData> prioEncodedData(cx);
   mozilla::ErrorResult rv;
 
   mozilla::dom::PrioEncoder::Encode(global, batchID, prioParams, prioEncodedData, rv);
   ASSERT_TRUE(rv.Failed());
 
   // Call again to ensure that the singleton state is consistent.
   mozilla::dom::PrioEncoder::Encode(global, batchID, prioParams, prioEncodedData, rv);
@@ -167,19 +163,21 @@ TEST(PrioEncoder, VerifyFull)
     nsCString(reinterpret_cast<const char*>(pkHexB)));
 
   mozilla::dom::GlobalObject global(cx, xpc::PrivilegedJunkScope());
 
   nsCString batchID;
   batchID = (char*)(batchIDStr);
 
   mozilla::dom::PrioParams prioParams;
-  prioParams.mBrowserIsUserDefault = dataItems[0];
-  prioParams.mNewTabPageEnabled = dataItems[1];
-  prioParams.mPdfViewerUsed = dataItems[2];
+  FallibleTArray<bool> sequence;
+  *(sequence.AppendElement(mozilla::fallible)) = dataItems[0];
+  *(sequence.AppendElement(mozilla::fallible)) = dataItems[1];
+  *(sequence.AppendElement(mozilla::fallible)) = dataItems[2];
+  prioParams.mBooleans.Assign(sequence);
 
   mozilla::dom::RootedDictionary<mozilla::dom::PrioEncodedData> prioEncodedData(cx);
   mozilla::ErrorResult rv;
 
   mozilla::dom::PrioEncoder::Encode(global, batchID, prioParams, prioEncodedData, rv);
   ASSERT_FALSE(rv.Failed());
 
   prioEncodedData.mA.Value().ComputeLengthAndData();