コード例 #1
0
bool
nsSMILParserUtils::ParseKeySplines(const nsAString& aSpec,
                                   FallibleTArray<nsSMILKeySpline>& aKeySplines)
{
  nsCharSeparatedTokenizerTemplate<IsSVGWhitespace> controlPointTokenizer(aSpec, ';');
  while (controlPointTokenizer.hasMoreTokens()) {

    nsCharSeparatedTokenizerTemplate<IsSVGWhitespace> 
      tokenizer(controlPointTokenizer.nextToken(), ',',
                nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);

    double values[4];
    for (int i = 0 ; i < 4; i++) {
      if (!tokenizer.hasMoreTokens() ||
          !SVGContentUtils::ParseNumber(tokenizer.nextToken(), values[i]) ||
          values[i] > 1.0 || values[i] < 0.0) {
        return false;
      }
    }
    if (tokenizer.hasMoreTokens() ||
        tokenizer.separatorAfterCurrentToken() ||
        !aKeySplines.AppendElement(nsSMILKeySpline(values[0],
                                                   values[1],
                                                   values[2],
                                                   values[3]))) {
      return false;
    }
  }

  return !aKeySplines.IsEmpty();
}
コード例 #2
0
bool
nsSMILParserUtils::ParseSemicolonDelimitedProgressList(const nsAString& aSpec,
                                                       bool aNonDecreasing,
                                                       FallibleTArray<double>& aArray)
{
  nsCharSeparatedTokenizerTemplate<IsSVGWhitespace> tokenizer(aSpec, ';');

  double previousValue = -1.0;

  while (tokenizer.hasMoreTokens()) {
    double value;
    if (!SVGContentUtils::ParseNumber(tokenizer.nextToken(), value)) {
      return false;
    }

    if (value > 1.0 || value < 0.0 ||
        (aNonDecreasing && value < previousValue)) {
      return false;
    }

    if (!aArray.AppendElement(value)) {
      return false;
    }
    previousValue = value;
  }

  return !aArray.IsEmpty();
}
コード例 #3
0
ファイル: DocGroup.cpp プロジェクト: autonome/gecko-dev
PerformanceInfo
DocGroup::ReportPerformanceInfo()
{
  AssertIsOnMainThread();
  MOZ_ASSERT(mPerformanceCounter);
#if defined(XP_WIN)
  uint32_t pid = GetCurrentProcessId();
#else
  uint32_t pid = getpid();
#endif
  uint64_t wid = 0;
  uint64_t pwid = 0;
  uint16_t count = 0;
  uint64_t duration = 0;
  nsCString host = NS_LITERAL_CSTRING("None");

  for (const auto& document : *this) {
    // grabbing the host name of the first document
    nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
    MOZ_ASSERT(doc);
    nsCOMPtr<nsIURI> docURI = doc->GetDocumentURI();
    if (!docURI) {
      continue;
    }
    docURI->GetHost(host);
    wid = doc->OuterWindowID();

    // getting the top window id - if not possible
    // pwid gets the same value than wid
    pwid = wid;
    nsPIDOMWindowInner* win = doc->GetInnerWindow();
    if (win) {
      nsPIDOMWindowOuter* outer = win->GetOuterWindow();
      if (outer) {
        nsCOMPtr<nsPIDOMWindowOuter> top = outer->GetTop();
        if (top) {
          pwid = top->WindowID();
        }
      }
    }
  }

  duration = mPerformanceCounter->GetExecutionDuration();
  FallibleTArray<CategoryDispatch> items;

  // now that we have the host and window ids, let's look at the perf counters
  for (uint32_t index = 0; index < (uint32_t)TaskCategory::Count; index++) {
    TaskCategory category = static_cast<TaskCategory>(index);
    count = mPerformanceCounter->GetDispatchCount(DispatchCategory(category));
    CategoryDispatch item = CategoryDispatch(index, count);
    if (!items.AppendElement(item, fallible)) {
      NS_ERROR("Could not complete the operation");
      return PerformanceInfo(host, pid, wid, pwid, duration, false, items);
    }
  }

  // setting back all counters to zero
  mPerformanceCounter->ResetPerformanceCounters();
  return PerformanceInfo(host, pid, wid, pwid, duration, false, items);
}
コード例 #4
0
ファイル: ContentVerifier.cpp プロジェクト: MekliCZ/positron
/**
 * Implement nsIStreamListener
 * We buffer the entire content here and kick off verification
 */
NS_METHOD
AppendNextSegment(nsIInputStream* aInputStream, void* aClosure,
                  const char* aRawSegment, uint32_t aToOffset, uint32_t aCount,
                  uint32_t* outWrittenCount)
{
  FallibleTArray<nsCString>* decodedData =
    static_cast<FallibleTArray<nsCString>*>(aClosure);
  nsAutoCString segment(aRawSegment, aCount);
  if (!decodedData->AppendElement(segment, fallible)) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  *outWrittenCount = aCount;
  return NS_OK;
}
コード例 #5
0
// static
bool
SVGTransformListSMILType::GetTransforms(const nsSMILValue& aValue,
                                        FallibleTArray<nsSVGTransform>& aTransforms)
{
  NS_PRECONDITION(aValue.mType == Singleton(), "Unexpected SMIL value type");

  const TransformArray& smilTransforms =
    *static_cast<const TransformArray*>(aValue.mU.mPtr);

  aTransforms.Clear();
  if (!aTransforms.SetCapacity(smilTransforms.Length(), fallible))
      return false;

  for (uint32_t i = 0; i < smilTransforms.Length(); ++i) {
    // No need to check the return value below since we have already allocated
    // the necessary space
    aTransforms.AppendElement(smilTransforms[i].ToSVGTransform(), fallible);
  }
  return true;
}
コード例 #6
0
static inline bool
ConvertIndex(FallibleTArray<Index::Indice>& aDest,
             const nsTArray<stagefright::MediaSource::Indice>& aIndex,
             int64_t aMediaTime)
{
  if (!aDest.SetCapacity(aIndex.Length(), mozilla::fallible)) {
    return false;
  }
  for (size_t i = 0; i < aIndex.Length(); i++) {
    Index::Indice indice;
    const stagefright::MediaSource::Indice& s_indice = aIndex[i];
    indice.start_offset = s_indice.start_offset;
    indice.end_offset = s_indice.end_offset;
    indice.start_composition = s_indice.start_composition - aMediaTime;
    indice.end_composition = s_indice.end_composition - aMediaTime;
    indice.sync = s_indice.sync;
    // FIXME: Make this infallible after bug 968520 is done.
    MOZ_ALWAYS_TRUE(aDest.AppendElement(indice, mozilla::fallible));
  }
  return true;
}
コード例 #7
0
/* static */ bool
SharedMessagePortMessage::FromMessagesToSharedParent(
                      nsTArray<ClonedMessageData>& aArray,
                      FallibleTArray<RefPtr<SharedMessagePortMessage>>& aData)
{
  MOZ_ASSERT(aData.IsEmpty());

  if (NS_WARN_IF(!aData.SetCapacity(aArray.Length(), mozilla::fallible))) {
    return false;
  }

  for (auto& message : aArray) {
    RefPtr<SharedMessagePortMessage> data = new SharedMessagePortMessage();
    data->StealFromClonedMessageDataForBackgroundParent(message);

    if (!aData.AppendElement(data, mozilla::fallible)) {
      return false;
    }
  }

  return true;
}
コード例 #8
0
/* static */ bool
SharedMessagePortMessage::FromSharedToMessagesParent(
                      MessagePortParent* aActor,
                      const nsTArray<RefPtr<SharedMessagePortMessage>>& aData,
                      FallibleTArray<ClonedMessageData>& aArray)
{
  MOZ_ASSERT(aArray.IsEmpty());

  if (NS_WARN_IF(!aArray.SetCapacity(aData.Length(), mozilla::fallible))) {
    return false;
  }

  PBackgroundParent* backgroundManager = aActor->Manager();
  MOZ_ASSERT(backgroundManager);

  for (auto& data : aData) {
    ClonedMessageData* message = aArray.AppendElement(mozilla::fallible);
    data->BuildClonedMessageDataForBackgroundParent(backgroundManager,
                                                    *message);
  }

  return true;
}
コード例 #9
0
/* static */ bool
SharedMessagePortMessage::FromMessagesToSharedChild(
                      nsTArray<MessagePortMessage>& aArray,
                      FallibleTArray<nsRefPtr<SharedMessagePortMessage>>& aData)
{
  MOZ_ASSERT(aData.IsEmpty());

  if (NS_WARN_IF(!aData.SetCapacity(aArray.Length(), mozilla::fallible))) {
    return false;
  }

  for (auto& message : aArray) {
    nsRefPtr<SharedMessagePortMessage> data = new SharedMessagePortMessage();

    data->mData.SwapElements(message.data());

    const nsTArray<PBlobChild*>& blobs = message.blobsChild();
    if (!blobs.IsEmpty()) {
      data->mClosure.mBlobImpls.SetCapacity(blobs.Length());

      for (uint32_t i = 0, len = blobs.Length(); i < len; ++i) {
        nsRefPtr<BlobImpl> impl =
          static_cast<BlobChild*>(blobs[i])->GetBlobImpl();
        data->mClosure.mBlobImpls.AppendElement(impl);
      }
    }

    data->mClosure.mMessagePortIdentifiers.AppendElements(
      message.transferredPorts());

    if (!aData.AppendElement(data, mozilla::fallible)) {
      return false;
    }
  }

  return true;
}
コード例 #10
0
/* static */ bool
SharedMessagePortMessage::FromSharedToMessagesParent(
                      MessagePortParent* aActor,
                      const nsTArray<nsRefPtr<SharedMessagePortMessage>>& aData,
                      FallibleTArray<MessagePortMessage>& aArray)
{
  MOZ_ASSERT(aArray.IsEmpty());

  if (NS_WARN_IF(!aArray.SetCapacity(aData.Length(), mozilla::fallible))) {
    return false;
  }

  PBackgroundParent* backgroundManager = aActor->Manager();
  MOZ_ASSERT(backgroundManager);

  for (auto& data : aData) {
    MessagePortMessage* message = aArray.AppendElement(mozilla::fallible);
    message->data().SwapElements(data->mData);

    const nsTArray<nsRefPtr<BlobImpl>>& blobImpls = data->mClosure.mBlobImpls;
    if (!blobImpls.IsEmpty()) {
      message->blobsParent().SetCapacity(blobImpls.Length());

      for (uint32_t i = 0, len = blobImpls.Length(); i < len; ++i) {
        PBlobParent* blobParent =
          BackgroundParent::GetOrCreateActorForBlobImpl(backgroundManager,
                                                        blobImpls[i]);
        message->blobsParent().AppendElement(blobParent);
      }
    }

    message->transferredPorts().AppendElements(
      data->mClosure.mMessagePortIdentifiers);
  }

  return true;
}
コード例 #11
0
ファイル: DocGroup.cpp プロジェクト: Noctem/gecko-dev
RefPtr<PerformanceInfoPromise> DocGroup::ReportPerformanceInfo() {
  AssertIsOnMainThread();
  MOZ_ASSERT(mPerformanceCounter);
#if defined(XP_WIN)
  uint32_t pid = GetCurrentProcessId();
#else
  uint32_t pid = getpid();
#endif
  uint64_t windowID = 0;
  uint16_t count = 0;
  uint64_t duration = 0;
  bool isTopLevel = false;
  nsCString host;
  nsCOMPtr<nsPIDOMWindowOuter> top;
  RefPtr<AbstractThread> mainThread;

  // iterating on documents until we find the top window
  for (const auto& document : *this) {
    nsCOMPtr<Document> doc = document;
    MOZ_ASSERT(doc);
    nsCOMPtr<nsIURI> docURI = doc->GetDocumentURI();
    if (!docURI) {
      continue;
    }
    docURI->GetHost(host);
    // If the host is empty, using the url
    if (host.IsEmpty()) {
      host = docURI->GetSpecOrDefault();
    }
    // looking for the top level document URI
    nsPIDOMWindowOuter* win = doc->GetWindow();
    if (!win) {
      continue;
    }
    nsPIDOMWindowOuter* outer = win->GetOuterWindow();
    if (!outer) {
      continue;
    }
    top = outer->GetTop();
    if (!top) {
      continue;
    }
    windowID = top->WindowID();
    isTopLevel = outer->IsTopLevelWindow();
    mainThread = AbstractMainThreadFor(TaskCategory::Performance);
    break;
  }

  MOZ_ASSERT(!host.IsEmpty());
  duration = mPerformanceCounter->GetExecutionDuration();
  FallibleTArray<CategoryDispatch> items;

  // now that we have the host and window ids, let's look at the perf counters
  for (uint32_t index = 0; index < (uint32_t)TaskCategory::Count; index++) {
    TaskCategory category = static_cast<TaskCategory>(index);
    count = mPerformanceCounter->GetDispatchCount(DispatchCategory(category));
    CategoryDispatch item = CategoryDispatch(index, count);
    if (!items.AppendElement(item, fallible)) {
      NS_ERROR("Could not complete the operation");
      break;
    }
  }

  if (!isTopLevel) {
    return PerformanceInfoPromise::CreateAndResolve(
        PerformanceInfo(host, pid, windowID, duration,
                        mPerformanceCounter->GetID(), false, isTopLevel,
                        PerformanceMemoryInfo(),  // Empty memory info
                        items),
        __func__);
  }

  MOZ_ASSERT(mainThread);
  RefPtr<DocGroup> self = this;

  return CollectMemoryInfo(top, mainThread)
      ->Then(
          mainThread, __func__,
          [self, host, pid, windowID, duration, isTopLevel,
           items](const PerformanceMemoryInfo& aMemoryInfo) {
            PerformanceInfo info =
                PerformanceInfo(host, pid, windowID, duration,
                                self->mPerformanceCounter->GetID(), false,
                                isTopLevel, aMemoryInfo, items);

            return PerformanceInfoPromise::CreateAndResolve(std::move(info),
                                                            __func__);
          },
          [self](const nsresult rv) {
            return PerformanceInfoPromise::CreateAndReject(rv, __func__);
          });
}