Example #1
0
already_AddRefed<nsIPersistentProperties>
AccessibleWrap::AttributeArrayToProperties(
    const nsTArray<Attribute>& aAttributes) {
  RefPtr<nsPersistentProperties> props = new nsPersistentProperties();
  nsAutoString unused;

  for (size_t i = 0; i < aAttributes.Length(); i++) {
    props->SetStringProperty(aAttributes.ElementAt(i).Name(),
                             aAttributes.ElementAt(i).Value(), unused);
  }

  return props.forget();
}
NS_IMETHODIMP
nsDOMMultipartBlob::GetSize(PRUint64* aLength)
{
    nsresult rv;
    *aLength = 0;

    if (mLength) {
        *aLength = mLength;
        return NS_OK;
    }

    CheckedUint64 length = 0;

    PRUint32 i;
    PRUint32 len = mBlobs.Length();
    for (i = 0; i < len; i++) {
        nsIDOMBlob* blob = mBlobs.ElementAt(i).get();
        PRUint64 l = 0;

        rv = blob->GetSize(&l);
        NS_ENSURE_SUCCESS(rv, rv);

        length += l;
    }

    if (!length.valid())
        return NS_ERROR_FAILURE;

    mLength = length.value();
    *aLength = mLength;
    return NS_OK;
}
bool
AndroidGraphicBuffer::IsBlacklisted()
{
  nsAutoString board;
  if (!AndroidBridge::Bridge()->GetStaticStringField("android/os/Build", "BOARD", board))
    return true;

  NS_ConvertUTF16toUTF8 boardUtf8(board);

  if (Preferences::GetBool("direct-texture.force.enabled", false)) {
    LOG("allowing board '%s' due to prefs override", boardUtf8.get());
    return false;
  }

  if (Preferences::GetBool("direct-texture.force.disabled", false)) {
    LOG("disallowing board '%s' due to prefs override", boardUtf8.get());
    return true;
  }

  static nsTArray<nsString> sListAllowed;
  if (sListAllowed.Length() == 0) {
    InitWhiteList(sListAllowed);
  }
  
  int i = -1;
  if ((i = sListAllowed.BinaryIndexOf(board)) >= 0) {
    nsString name = sListAllowed.ElementAt(i);
    LOG("allowing board '%s' based on '%s'\n", boardUtf8.get(), NS_ConvertUTF16toUTF8(name).get());
    return false;
  }

  LOG("disallowing board: %s\n", boardUtf8.get());
  return true;
}
Example #4
0
static void DumpLayerList(nsTArray<Layer*>& aLayers)
{
  for (PRUint32 i = 0; i < aLayers.Length(); i++) {
    fprintf(stderr, "%p, ", aLayers.ElementAt(i));
  }
  fprintf(stderr, "\n");
}
Example #5
0
NS_IMETHODIMP
nsDOMMultipartFile::GetSize(PRUint64* aLength)
{
  if (mLength == PR_UINT64_MAX) {
    CheckedUint64 length = 0;
  
    PRUint32 i;
    PRUint32 len = mBlobs.Length();
    for (i = 0; i < len; i++) {
      nsIDOMBlob* blob = mBlobs.ElementAt(i).get();
      PRUint64 l = 0;
  
      nsresult rv = blob->GetSize(&l);
      NS_ENSURE_SUCCESS(rv, rv);
  
      length += l;
    }
  
    NS_ENSURE_TRUE(length.valid(), NS_ERROR_FAILURE);

    mLength = length.value();
  }

  *aLength = mLength;
  return NS_OK;
}
Example #6
0
// Helper function that iterates over the list of dictionaries and sets the one
// that matches based on a given comparison type.
nsresult
nsEditorSpellCheck::TryDictionary(const nsAString& aDictName,
                                  nsTArray<nsString>& aDictList,
                                  enum dictCompare aCompareType)
{
  nsresult rv = NS_ERROR_NOT_AVAILABLE;

  for (uint32_t i = 0; i < aDictList.Length(); i++) {
    nsAutoString dictStr(aDictList.ElementAt(i));
    bool equals = false;
    switch (aCompareType) {
      case DICT_NORMAL_COMPARE:
        equals = aDictName.Equals(dictStr);
        break;
      case DICT_COMPARE_CASE_INSENSITIVE:
        equals = aDictName.Equals(dictStr, nsCaseInsensitiveStringComparator());
        break;
      case DICT_COMPARE_DASHMATCH:
        equals = nsStyleUtil::DashMatchCompare(dictStr, aDictName, nsCaseInsensitiveStringComparator());
        break;
    }
    if (equals) {
      rv = mSpellChecker->SetCurrentDictionary(dictStr);
#ifdef DEBUG_DICT
      if (NS_SUCCEEDED(rv))
        printf("***** Set |%s|.\n", NS_ConvertUTF16toUTF8(dictStr).get());
#endif
      // We always break here. We tried to set the dictionary to an existing
      // dictionary from the list. This must work, if it doesn't, there is
      // no point trying another one.
      break;
    }
  }
  return rv;
}
Example #7
0
static void DumpLayerList(nsTArray<Layer*>& aLayers)
{
  for (uint32_t i = 0; i < aLayers.Length(); i++) {
    print_layer(stderr, aLayers.ElementAt(i));
    fprintf(stderr, " ");
  }
  fprintf(stderr, "\n");
}
NS_IMETHODIMP
WorkerDebuggerEnumerator::GetNext(nsISupports** aResult)
{
  if (mIndex == mDebuggers.Length()) {
    return NS_ERROR_FAILURE;
  }

  mDebuggers.ElementAt(mIndex++).forget(aResult);
  return NS_OK;
};
Example #9
0
bool
JetpackActorCommon::RecvMessage(JSContext* cx,
                                const nsString& messageName,
                                const nsTArray<Variant>& data,
                                nsTArray<Variant>* results)
{
  if (results)
    results->Clear();

  RecList* list;
  if (!mReceivers.Get(messageName, &list))
    return true;
  nsAutoTArray<jsval, 4> snapshot;
  list->copyTo(snapshot);
  if (!snapshot.Length())
    return true;
  
  nsAutoTArray<jsval, 4> args;
  PRUint32 argc = data.Length() + 1;
  jsval* argv = args.AppendElements(argc);
  if (!argv)
    return false;
  for (PRUint32 i = 0; i < argc; ++i)
    argv[i] = JSVAL_VOID;
  js::AutoArrayRooter argvRooter(cx, argc, argv);

  JSString* msgNameStr =
    JS_NewUCStringCopyN(cx,
                        messageName.get(),
                        messageName.Length());
  if (!msgNameStr)
    return false;
  argv[0] = STRING_TO_JSVAL(msgNameStr);

  for (PRUint32 i = 0; i < data.Length(); ++i)
    if (!jsval_from_Variant(cx, data.ElementAt(i), argv + i + 1))
      return false;

  JSObject* implGlobal = JS_GetGlobalObject(cx);
  js::AutoValueRooter rval(cx);

  for (PRUint32 i = 0; i < snapshot.Length(); ++i) {
    Variant* vp = results ? results->AppendElement() : NULL;
    rval.set(JSVAL_VOID);
    if (!JS_CallFunctionValue(cx, implGlobal, snapshot[i], argc, argv,
                              rval.jsval_addr())) {
      (void) JS_ReportPendingException(cx);
      if (vp)
        *vp = void_t();
    } else if (vp && !jsval_to_Variant(cx, rval.jsval_value(), vp))
      *vp = void_t();
  }

  return true;
}
Example #10
0
nsresult
nsXPathEvaluatorParseContext::resolveFunctionCall(nsIAtom* aName,
                                                  int32_t aID,
                                                  FunctionCall** aFn)
{
    nsresult rv = NS_ERROR_XPATH_UNKNOWN_FUNCTION;

    uint32_t i, count = mNamespaceIDs ? mNamespaceIDs->Length() : 0;
    for (i = 0; i < count; ++i) {
        if (mNamespaceIDs->ElementAt(i) == aID) {
            nsISupports *state = mState ? mState->SafeObjectAt(i) : nullptr;
            rv = TX_ResolveFunctionCallXPCOM(mContractIDs->ElementAt(i), aID,
                                             aName, state, aFn);
            if (NS_SUCCEEDED(rv)) {
                break;
            }
        }
    }

    return rv;
}
nsresult
NameSpaceManagerImpl::GetNameSpaceURI(PRInt32 aNameSpaceID, nsAString& aURI)
{
  NS_PRECONDITION(aNameSpaceID >= 0, "Bogus namespace ID");
  
  PRInt32 index = aNameSpaceID - 1; // id is index + 1
  if (index < 0 || index >= PRInt32(mURIArray.Length())) {
    aURI.Truncate();

    return NS_ERROR_ILLEGAL_VALUE;
  }

  aURI = *mURIArray.ElementAt(index);

  return NS_OK;
}
Example #12
0
// Helper function for notifying permission granted
static nsresult
NotifyPermissionAllow(const nsAString &aCallID, nsTArray<nsCOMPtr<nsIMediaDevice> > &aDevices)
{
  nsresult rv;
  nsCOMPtr<nsISupportsArray> array;
  rv = NS_NewISupportsArray(getter_AddRefs(array));
  NS_ENSURE_SUCCESS(rv, rv);

  for (uint32_t i = 0; i < aDevices.Length(); ++i) {
    rv = array->AppendElement(aDevices.ElementAt(i));
    NS_ENSURE_SUCCESS(rv, rv);
  }

  nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
  NS_ENSURE_TRUE(obs, NS_ERROR_FAILURE);

  return obs->NotifyObservers(array, "getUserMedia:response:allow",
                              aCallID.BeginReading());
}
Example #13
0
void
gfxFontFeatureValueSet::AddFontFeatureValues(const nsAString& aFamily,
                 const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues)
{
    nsAutoString family(aFamily);
    ToLowerCase(family);

    uint32_t i, numFeatureValues = aValues.Length();
    for (i = 0; i < numFeatureValues; i++) {
        const FeatureValues& fv = aValues.ElementAt(i);
        uint32_t alternate = fv.alternate;
        uint32_t j, numValues = fv.valuelist.Length();
        for (j = 0; j < numValues; j++) {
            const ValueList& v = fv.valuelist.ElementAt(j);
            auto* array = AppendFeatureValueHashEntry(family, v.name, alternate);
            *array = v.featureSelectors;
        }
    }
}
nsresult
BluetoothDaemonConnectionIO::SendPendingData(int aFd)
{
  while (HasPendingData()) {
    BluetoothDaemonPDU* outgoing = mOutgoingQ.ElementAt(0);
    MOZ_ASSERT(outgoing);

    ssize_t res = outgoing->Send(aFd);
    if (res < 0) {
      /* an I/O error occured */
      return NS_ERROR_FAILURE;
    } else if (!res) {
      /* I/O is currently blocked; try again later */
      return NS_OK;
    }

    MOZ_ASSERT(!outgoing->GetSize());
    mOutgoingQ.RemoveElementAt(0);
    delete outgoing;
  }

  return NS_OK;
}
NS_IMETHODIMP
nsDOMMultipartBlob::GetInternalStream(nsIInputStream** aStream)
{
    nsresult rv;
    *aStream = nsnull;

    nsCOMPtr<nsIMultiplexInputStream> stream =
        do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1");
    NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);

    PRUint32 i;
    for (i = 0; i < mBlobs.Length(); i++) {
        nsCOMPtr<nsIInputStream> scratchStream;
        nsIDOMBlob* blob = mBlobs.ElementAt(i).get();

        rv = blob->GetInternalStream(getter_AddRefs(scratchStream));
        NS_ENSURE_SUCCESS(rv, rv);

        rv = stream->AppendStream(scratchStream);
        NS_ENSURE_SUCCESS(rv, rv);
    }

    return CallQueryInterface(stream, aStream);
}
NS_IMETHODIMP
nsDOMMultipartBlob::MozSlice(PRInt64 aStart, PRInt64 aEnd,
                             const nsAString& aContentType,
                             PRUint8 optional_argc,
                             nsIDOMBlob **aBlob)
{
    nsresult rv;
    *aBlob = nsnull;

    // Truncate aStart and aEnd so that we stay within this file.
    PRUint64 thisLength;
    rv = GetSize(&thisLength);
    NS_ENSURE_SUCCESS(rv, rv);

    if (!optional_argc) {
        aEnd = (PRInt64)thisLength;
    }

    // Modifies aStart and aEnd.
    ParseSize((PRInt64)thisLength, aStart, aEnd);

    // If we clamped to nothing we create an empty blob
    nsTArray<nsCOMPtr<nsIDOMBlob> > blobs;

    PRUint64 length = aEnd - aStart;
    PRUint64 skipStart = aStart;

    NS_ABORT_IF_FALSE(PRUint64(aStart) + length <= thisLength, "Er, what?");

    // Prune the list of blobs if we can
    PRUint32 i;
    for (i = 0; length && skipStart && i < mBlobs.Length(); i++) {
        nsIDOMBlob* blob = mBlobs[i].get();

        PRUint64 l;
        rv = blob->GetSize(&l);
        NS_ENSURE_SUCCESS(rv, rv);

        if (skipStart < l) {
            PRUint64 upperBound = NS_MIN<PRUint64>(l - skipStart, length);

            nsCOMPtr<nsIDOMBlob> firstBlob;
            rv = mBlobs.ElementAt(i)->MozSlice(skipStart, skipStart + upperBound,
                                               aContentType, 2,
                                               getter_AddRefs(firstBlob));
            NS_ENSURE_SUCCESS(rv, rv);

            // Avoid wrapping a single blob inside an nsDOMMultipartBlob
            if (length == upperBound) {
                firstBlob.forget(aBlob);
                return NS_OK;
            }

            blobs.AppendElement(firstBlob);
            length -= upperBound;
            i++;
            break;
        }
        skipStart -= l;
    }

    // Now append enough blobs until we're done
    for (; length && i < mBlobs.Length(); i++) {
        nsIDOMBlob* blob = mBlobs[i].get();

        PRUint64 l;
        rv = blob->GetSize(&l);
        NS_ENSURE_SUCCESS(rv, rv);

        if (length < l) {
            nsCOMPtr<nsIDOMBlob> lastBlob;
            rv = mBlobs.ElementAt(i)->MozSlice(0, length, aContentType, 2,
                                               getter_AddRefs(lastBlob));
            NS_ENSURE_SUCCESS(rv, rv);

            blobs.AppendElement(lastBlob);
        } else {
            blobs.AppendElement(blob);
        }
        length -= NS_MIN<PRUint64>(l, length);
    }

    // we can create our blob now
    nsCOMPtr<nsIDOMBlob> blob = new nsDOMMultipartBlob(blobs, aContentType);
    blob.forget(aBlob);
    return NS_OK;
}
Example #17
0
void SortLayersBy3DZOrder(nsTArray<Layer*>& aLayers)
{
  uint32_t nodeCount = aLayers.Length();
  if (nodeCount > MAX_SORTABLE_LAYERS) {
    return;
  }
  DirectedGraph<Layer*> graph;

#ifdef DEBUG
  if (gDumpLayerSortList) {
    for (uint32_t i = 0; i < nodeCount; i++) {
      if (aLayers.ElementAt(i)->GetDebugColorIndex() == 0) {
        aLayers.ElementAt(i)->SetDebugColorIndex(gColorIndex++);
        if (gColorIndex > 7) {
          gColorIndex = 1;
        }
      }
    }
    fprintf(stderr, " --- Layers before sorting: --- \n");
    DumpLayerList(aLayers);
  }
#endif

  // Iterate layers and determine edges.
  for (uint32_t i = 0; i < nodeCount; i++) {
    for (uint32_t j = i + 1; j < nodeCount; j++) {
      Layer* a = aLayers.ElementAt(i);
      Layer* b = aLayers.ElementAt(j);
      LayerSortOrder order = CompareDepth(a, b);
      if (order == ABeforeB) {
        graph.AddEdge(a, b);
      } else if (order == BBeforeA) {
        graph.AddEdge(b, a);
      }
    }
  }

#ifdef DEBUG
  if (gDumpLayerSortList) {
    fprintf(stderr, " --- Edge List: --- \n");
    DumpEdgeList(graph);
  }
#endif

  // Build a new array using the graph.
  nsTArray<Layer*> noIncoming;
  nsTArray<Layer*> sortedList;

  // Make a list of all layers with no incoming edges.
  noIncoming.AppendElements(aLayers);
  const nsTArray<DirectedGraph<Layer*>::Edge>& edges = graph.GetEdgeList();
  for (uint32_t i = 0; i < edges.Length(); i++) {
    noIncoming.RemoveElement(edges.ElementAt(i).mTo);
  }

  // Move each item without incoming edges into the sorted list,
  // and remove edges from it.
  do {
    if (!noIncoming.IsEmpty()) {
      uint32_t last = noIncoming.Length() - 1;

      Layer* layer = noIncoming.ElementAt(last);
      MOZ_ASSERT(layer); // don't let null layer pointers sneak into sortedList

      noIncoming.RemoveElementAt(last);
      sortedList.AppendElement(layer);

      nsTArray<DirectedGraph<Layer*>::Edge> outgoing;
      graph.GetEdgesFrom(layer, outgoing);
      for (uint32_t i = 0; i < outgoing.Length(); i++) {
        DirectedGraph<Layer*>::Edge edge = outgoing.ElementAt(i);
        graph.RemoveEdge(edge);
        if (!graph.NumEdgesTo(edge.mTo)) {
          // If this node also has no edges now, add it to the list
          noIncoming.AppendElement(edge.mTo);
        }
      }
    }

    // If there are no nodes without incoming edges, but there
    // are still edges, then we have a cycle.
    if (noIncoming.IsEmpty() && graph.GetEdgeCount()) {
      // Find the node with the least incoming edges.
      uint32_t minEdges = UINT_MAX;
      Layer* minNode = nullptr;
      for (uint32_t i = 0; i < aLayers.Length(); i++) {
        uint32_t edgeCount = graph.NumEdgesTo(aLayers.ElementAt(i));
        if (edgeCount && edgeCount < minEdges) {
          minEdges = edgeCount;
          minNode = aLayers.ElementAt(i);
          if (minEdges == 1) {
            break;
          }
        }
      }

      if (minNode) {
        // Remove all of them!
        graph.RemoveEdgesTo(minNode);
        noIncoming.AppendElement(minNode);
      }
    }
  } while (!noIncoming.IsEmpty());
  NS_ASSERTION(!graph.GetEdgeCount(), "Cycles detected!");
#ifdef DEBUG
  if (gDumpLayerSortList) {
    fprintf(stderr, " --- Layers after sorting: --- \n");
    DumpLayerList(sortedList);
  }
#endif

  aLayers.Clear();
  aLayers.AppendElements(sortedList);
}