void
ThreadStackHelper::GetStack(HangStack& aStack, nsACString& aRunnableName, bool aStackWalk)
{
  aRunnableName.AssignLiteral("???");

  if (!PrepareStackBuffer(aStack)) {
    return;
  }

  Array<char, nsThread::kRunnableNameBufSize> runnableName;
  runnableName[0] = '\0';

  ScopedSetPtr<HangStack> _stackGuard(mStackToFill, &aStack);
  ScopedSetPtr<Array<char, nsThread::kRunnableNameBufSize>>
    _runnableGuard(mRunnableNameBuffer, &runnableName);

  // XXX: We don't need to pass in ProfilerFeature::StackWalk to trigger
  // stackwalking, as that is instead controlled by the last argument.
  profiler_suspend_and_sample_thread(
    mThreadId, ProfilerFeature::Privacy, *this, aStackWalk);

  // Copy the name buffer allocation into the output string. We explicitly set
  // the last byte to null in case we read in some corrupted data without a null
  // terminator.
  runnableName[nsThread::kRunnableNameBufSize - 1] = '\0';
  aRunnableName.AssignASCII(runnableName.cbegin());
}
static void SetProxyResult(const char* aType, const nsACString& aHostPort,
                           nsACString& aResult)
{
    aResult.AssignASCII(aType);
    aResult.Append(' ');
    aResult.Append(aHostPort);
}
Exemple #3
0
NS_IMETHODIMP
nsMediaSniffer::GetMIMETypeFromContent(nsIRequest* aRequest,
                                       const uint8_t* aData,
                                       const uint32_t aLength,
                                       nsACString& aSniffedType)
{
  // For media, we want to sniff only if the Content-Type is unknown, or if it
  // is application/octet-stream.
  nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
  if (channel) {
    nsAutoCString contentType;
    nsresult rv = channel->GetContentType(contentType);
    NS_ENSURE_SUCCESS(rv, rv);
    if (!contentType.IsEmpty() &&
        !contentType.EqualsLiteral(APPLICATION_OCTET_STREAM) &&
        !contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) {
      return NS_ERROR_NOT_AVAILABLE;
    }
  }

  const uint32_t clampedLength = std::min(aLength, MAX_BYTES_SNIFFED);

  for (uint32_t i = 0; i < mozilla::ArrayLength(sSnifferEntries); ++i) {
    const nsMediaSnifferEntry& currentEntry = sSnifferEntries[i];
    if (clampedLength < currentEntry.mLength || currentEntry.mLength == 0) {
      continue;
    }
    bool matched = true;
    for (uint32_t j = 0; j < currentEntry.mLength; ++j) {
      if ((currentEntry.mMask[j] & aData[j]) != currentEntry.mPattern[j]) {
        matched = false;
        break;
      }
    }
    if (matched) {
      aSniffedType.AssignASCII(currentEntry.mContentType);
      return NS_OK;
    }
  }

  if (MatchesMP4(aData, clampedLength)) {
    aSniffedType.AssignLiteral(VIDEO_MP4);
    return NS_OK;
  }

  if (MatchesWebM(aData, clampedLength)) {
    aSniffedType.AssignLiteral(VIDEO_WEBM);
    return NS_OK;
  }

  if (MatchesMP3(aData, clampedLength)) {
    aSniffedType.AssignLiteral(AUDIO_MP3);
    return NS_OK;
  }

  // Could not sniff the media type, we are required to set it to
  // application/octet-stream.
  aSniffedType.AssignLiteral(APPLICATION_OCTET_STREAM);
  return NS_ERROR_NOT_AVAILABLE;
}
  NS_DECL_ISUPPORTS

  NS_IMETHOD GetName(nsACString& aName)
  {
    aName.AssignASCII("dom-memory-file-data-owner");
    return NS_OK;
  }
static void SetProxyResult(const char* aType, const nsACString& aHost,
                           PRInt32 aPort, nsACString& aResult)
{
    aResult.AssignASCII(aType);
    aResult.Append(' ');
    aResult.Append(aHost);
    aResult.Append(':');
    aResult.Append(nsPrintfCString("%d", aPort));
}
Exemple #6
0
NS_IMETHODIMP
Runnable::GetName(nsACString& aName)
{
#ifdef RELEASE_OR_BETA
  aName.Truncate();
#else
  aName.AssignASCII(mName);
#endif
  return NS_OK;
}
static void SetProxyResult(const char* aType, const nsACString& aHostPort,
                           nsACString& aResult)
{
    nsCOMPtr<nsIURI> uri;
    nsCAutoString host;
    PRInt32 port;

    // Try parsing it as a URI.
    if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aHostPort)) &&
        NS_SUCCEEDED(uri->GetHost(host)) && !host.IsEmpty() &&
        NS_SUCCEEDED(uri->GetPort(&port))) {
        SetProxyResult(aType, host, port, aResult);
    } else {
        aResult.AssignASCII(aType);
        aResult.Append(' ');
        aResult.Append(aHostPort);
    }
}
Exemple #8
0
NS_IMETHODIMP
nsMediaSniffer::GetMIMETypeFromContent(nsIRequest* aRequest,
                                       const uint8_t* aData,
                                       const uint32_t aLength,
                                       nsACString& aSniffedType)
{
  const uint32_t clampedLength = NS_MIN(aLength, MAX_BYTES_SNIFFED);

  for (uint32_t i = 0; i < NS_ARRAY_LENGTH(sSnifferEntries); ++i) {
    const nsMediaSnifferEntry& currentEntry = sSnifferEntries[i];
    if (clampedLength < currentEntry.mLength || currentEntry.mLength == 0) {
      continue;
    }
    bool matched = true;
    for (uint32_t j = 0; j < currentEntry.mLength; ++j) {
      if ((currentEntry.mMask[j] & aData[j]) != currentEntry.mPattern[j]) {
        matched = false;
        break;
      }
    }
    if (matched) {
      aSniffedType.AssignASCII(currentEntry.mContentType);
      return NS_OK;
    }
  }

  if (MatchesMP4(aData, clampedLength)) {
    aSniffedType.AssignLiteral(VIDEO_MP4);
    return NS_OK;
  }

  // Could not sniff the media type, we are required to set it to
  // application/octet-stream.
  aSniffedType.AssignLiteral(APPLICATION_OCTET_STREAM);
  return NS_ERROR_NOT_AVAILABLE;
}
static void SetProxyResultDirect(nsACString& aResult)
{
    // For whatever reason, a proxy is not to be used.
    aResult.AssignASCII("DIRECT");
}
NS_IMETHODIMP
DecoderDoctorDocumentWatcher::GetName(nsACString& aName)
{
  aName.AssignASCII("DecoderDoctorDocumentWatcher_timer");
  return NS_OK;
}