Пример #1
0
cubeb* GetCubebContextUnlocked()
{
  sMutex.AssertCurrentThreadOwns();
  if (sCubebState != CubebState::Uninitialized) {
    // If we have already passed the initialization point (below), just return
    // the current context, which may be null (e.g., after error or shutdown.)
    return sCubebContext;
  }

  if (!sBrandName && NS_IsMainThread()) {
    InitBrandName();
  } else {
    NS_WARNING_ASSERTION(
      sBrandName, "Did not initialize sbrandName, and not on the main thread?");
  }

  int rv = cubeb_init(&sCubebContext, sBrandName);
  NS_WARNING_ASSERTION(rv == CUBEB_OK, "Could not get a cubeb context.");
  sCubebState = (rv == CUBEB_OK) ? CubebState::Initialized : CubebState::Uninitialized;

  if (MOZ_LOG_TEST(gCubebLog, LogLevel::Verbose)) {
    cubeb_set_log_callback(CUBEB_LOG_VERBOSE, CubebLogCallback);
  } else if (MOZ_LOG_TEST(gCubebLog, LogLevel::Error)) {
    cubeb_set_log_callback(CUBEB_LOG_NORMAL, CubebLogCallback);
  }

  return sCubebContext;
}
Пример #2
0
void
UDPSocket::LeaveMulticastGroup(const nsAString& aMulticastGroupAddress,
                               ErrorResult& aRv)
{
  if (mReadyState == SocketReadyState::Closed) {
    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
    return;
  }

  if (mReadyState == SocketReadyState::Opening) {
    MulticastCommand leaveCommand(MulticastCommand::Leave, aMulticastGroupAddress);
    mPendingMcastCommands.AppendElement(leaveCommand);
    return;
  }

  MOZ_ASSERT(mSocket || mSocketChild);

  nsCString address = NS_ConvertUTF16toUTF8(aMulticastGroupAddress);
  if (mSocket) {
    MOZ_ASSERT(!mSocketChild);

    aRv = mSocket->LeaveMulticast(address, EmptyCString());
    NS_WARNING_ASSERTION(!aRv.Failed(), "mSocket->LeaveMulticast failed");
    return;
  }

  MOZ_ASSERT(mSocketChild);

  aRv = mSocketChild->LeaveMulticast(address, EmptyCString());
  NS_WARNING_ASSERTION(!aRv.Failed(), "mSocketChild->LeaveMulticast failed");
}
Пример #3
0
void InitBrandName()
{
  if (sBrandName) {
    return;
  }
  nsXPIDLString brandName;
  nsCOMPtr<nsIStringBundleService> stringBundleService =
    mozilla::services::GetStringBundleService();
  if (stringBundleService) {
    nsCOMPtr<nsIStringBundle> brandBundle;
    nsresult rv = stringBundleService->CreateBundle(kBrandBundleURL,
                                           getter_AddRefs(brandBundle));
    if (NS_SUCCEEDED(rv)) {
      rv = brandBundle->GetStringFromName(u"brandShortName",
                                          getter_Copies(brandName));
      NS_WARNING_ASSERTION(
        NS_SUCCEEDED(rv), "Could not get the program name for a cubeb stream.");
    }
  }
  /* cubeb expects a c-string. */
  const char* ascii = NS_LossyConvertUTF16toASCII(brandName).get();
  sBrandName = new char[brandName.Length() + 1];
  PodCopy(sBrandName.get(), ascii, brandName.Length());
  sBrandName[brandName.Length()] = 0;
}
Пример #4
0
void
nsPicoService::RegisterVoices()
{
  nsSynthVoiceRegistry* registry = nsSynthVoiceRegistry::GetInstance();

  for (auto iter = mVoices.Iter(); !iter.Done(); iter.Next()) {
    const nsAString& uri = iter.Key();
    RefPtr<PicoVoice>& voice = iter.Data();

    // If we are missing either a language or a voice resource, it is invalid.
    if (voice->mTaFile.IsEmpty() || voice->mSgFile.IsEmpty()) {
      iter.Remove();
      continue;
    }

    nsAutoString name;
    name.AssignLiteral("Pico ");
    name.Append(voice->mLanguage);

    // This service is multi-threaded and can handle more than one utterance at a
    // time before previous utterances end. So, aQueuesUtterances == false
    DebugOnly<nsresult> rv =
      registry->AddVoice(this, uri, name, voice->mLanguage, true, false);
    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to add voice");
  }

  mInitialized = true;
}
void
DeviceStorageFileSystem::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
                                          ErrorResult& aRv) const
{
  AssertIsOnOwningThread();
  MOZ_ASSERT(aFile);

  nsCOMPtr<nsIFile> rootPath;
  aRv = NS_NewLocalFile(LocalOrDeviceStorageRootPath(), false,
                        getter_AddRefs(rootPath));
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }

  bool equal = false;
  aRv = aFile->Equals(rootPath, &equal);
  if (NS_WARN_IF(aRv.Failed())) {
    return;
  }

  if (equal) {
    aRetval = mStorageName;
    return;
  }

  FileSystemBase::GetDirectoryName(aFile, aRetval, aRv);
  NS_WARNING_ASSERTION(!aRv.Failed(), "GetDirectoryName failed");
}
Пример #6
0
void
AudioStream::GetUnprocessed(AudioBufferWriter& aWriter)
{
  mMonitor.AssertCurrentThreadOwns();

  // Flush the timestretcher pipeline, if we were playing using a playback rate
  // other than 1.0.
  if (mTimeStretcher && mTimeStretcher->numSamples()) {
    auto timeStretcher = mTimeStretcher;
    aWriter.Write([timeStretcher] (AudioDataValue* aPtr, uint32_t aFrames) {
      return timeStretcher->receiveSamples(aPtr, aFrames);
    }, aWriter.Available());

    // TODO: There might be still unprocessed samples in the stretcher.
    // We should either remove or flush them so they won't be in the output
    // next time we switch a playback rate other than 1.0.
    NS_WARNING_ASSERTION(
      mTimeStretcher->numUnprocessedSamples() == 0, "no samples");
  }

  while (aWriter.Available() > 0) {
    UniquePtr<Chunk> c = mDataSource.PopFrames(aWriter.Available());
    if (c->Frames() == 0) {
      break;
    }
    MOZ_ASSERT(c->Frames() <= aWriter.Available());
    if (IsValidAudioFormat(c.get())) {
      aWriter.Write(c->Data(), c->Frames());
    } else {
      // Write silence if invalid format.
      aWriter.WriteZeros(c->Frames());
    }
  }
}
Пример #7
0
LazyIdleThread::Release()
{
  nsrefcnt count = --mRefCnt;
  NS_LOG_RELEASE(this, count, "LazyIdleThread");

  if (!count) {
    // Stabilize refcount.
    mRefCnt = 1;

    nsCOMPtr<nsIRunnable> runnable =
      NewNonOwningRunnableMethod(this, &LazyIdleThread::SelfDestruct);
    NS_WARNING_ASSERTION(runnable, "Couldn't make runnable!");

    if (NS_FAILED(NS_DispatchToCurrentThread(runnable))) {
      MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
      // The only way this could fail is if we're in shutdown, and in that case
      // threads should have been joined already. Deleting here isn't dangerous
      // anymore because we won't spin the event loop waiting to join the
      // thread.
      SelfDestruct();
    }
  }

  return count;
}
Пример #8
0
 NS_IMETHOD Run() override
 {
   ErrorResult rv;
   mCallback->Call(mStringData, rv);
   NS_WARNING_ASSERTION(!rv.Failed(), "callback failed");
   return rv.StealNSResult();
 }
Пример #9
0
void
nsSpeechTask::Cancel()
{
  MOZ_ASSERT(XRE_IsParentProcess());

  LOG(LogLevel::Debug, ("nsSpeechTask::Cancel"));

  if (mCallback) {
    DebugOnly<nsresult> rv = mCallback->OnCancel();
    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                         "Unable to call onCancel() callback");
  }

  if (mStream) {
    mStream->Suspend();
  }

  if (!mInited) {
    mPreCanceled = true;
  }

  if (!mIndirectAudio) {
    DispatchEndInner(GetCurrentTime(), GetCurrentCharOffset());
  }
}
Пример #10
0
void
DelayBuffer::UpdateUpmixChannels(int aNewReadChunk, uint32_t aChannelCount,
                                 ChannelInterpretation aChannelInterpretation)
{
  if (aNewReadChunk == mLastReadChunk) {
    MOZ_ASSERT(mUpmixChannels.Length() == aChannelCount);
    return;
  }

  NS_WARNING_ASSERTION(mHaveWrittenBlock || aNewReadChunk != mCurrentChunk,
                       "Smoothing is making feedback delay too small.");

  mLastReadChunk = aNewReadChunk;
  mUpmixChannels = mChunks[aNewReadChunk].ChannelData<float>();
  MOZ_ASSERT(mUpmixChannels.Length() <= aChannelCount);
  if (mUpmixChannels.Length() < aChannelCount) {
    if (aChannelInterpretation == ChannelInterpretation::Speakers) {
      AudioChannelsUpMix(&mUpmixChannels,
                         aChannelCount, SilentChannel::ZeroChannel<float>());
      MOZ_ASSERT(mUpmixChannels.Length() == aChannelCount,
                 "We called GetAudioChannelsSuperset to avoid this");
    } else {
      // Fill up the remaining channels with zeros
      for (uint32_t channel = mUpmixChannels.Length();
           channel < aChannelCount; ++channel) {
        mUpmixChannels.AppendElement(SilentChannel::ZeroChannel<float>());
      }
    }
  }
}
Пример #11
0
NS_IMETHODIMP
InsertNodeTransaction::DoTransaction()
{
  if (NS_WARN_IF(!mEditorBase) ||
      NS_WARN_IF(!mContentToInsert) ||
      NS_WARN_IF(!mPointToInsert.IsSet())) {
    return NS_ERROR_NOT_INITIALIZED;
  }

  if (!mPointToInsert.IsSetAndValid()) {
    // It seems that DOM tree has been changed after first DoTransaction()
    // and current RedoTranaction() call.
    if (mPointToInsert.GetChild()) {
      EditorDOMPoint newPointToInsert(mPointToInsert.GetChild());
      if (!newPointToInsert.IsSet()) {
        // The insertion point has been removed from the DOM tree.
        // In this case, we should append the node to the container instead.
        newPointToInsert.SetToEndOf(mPointToInsert.GetContainer());
        if (NS_WARN_IF(!newPointToInsert.IsSet())) {
          return NS_ERROR_FAILURE;
        }
      }
      mPointToInsert = newPointToInsert;
    } else {
      mPointToInsert.SetToEndOf(mPointToInsert.GetContainer());
      if (NS_WARN_IF(!mPointToInsert.IsSet())) {
        return NS_ERROR_FAILURE;
      }
    }
  }

  mEditorBase->MarkNodeDirty(GetAsDOMNode(mContentToInsert));

  ErrorResult error;
  mPointToInsert.GetContainer()->InsertBefore(*mContentToInsert,
                                              mPointToInsert.GetChild(),
                                              error);
  error.WouldReportJSException();
  if (NS_WARN_IF(error.Failed())) {
    return error.StealNSResult();
  }

  // Only set selection to insertion point if editor gives permission
  if (mEditorBase->GetShouldTxnSetSelection()) {
    RefPtr<Selection> selection = mEditorBase->GetSelection();
    if (NS_WARN_IF(!selection)) {
      return NS_ERROR_FAILURE;
    }
    // Place the selection just after the inserted element
    EditorRawDOMPoint afterInsertedNode(mContentToInsert);
    DebugOnly<bool> advanced = afterInsertedNode.AdvanceOffset();
    NS_WARNING_ASSERTION(advanced,
      "Failed to advance offset after the inserted node");
    selection->Collapse(afterInsertedNode, error);
    if (NS_WARN_IF(error.Failed())) {
      error.SuppressException();
    }
  }
  return NS_OK;
}
Пример #12
0
NS_IMETHODIMP
InsertPlaintextCommand::DoCommandParams(const char* aCommandName,
                                        nsICommandParams* aParams,
                                        nsISupports* aCommandRefCon) {
  if (NS_WARN_IF(!aParams)) {
    return NS_ERROR_INVALID_ARG;
  }

  nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
  if (NS_WARN_IF(!editor)) {
    return NS_ERROR_FAILURE;
  }

  // Get text to insert from command params
  nsAutoString text;
  nsresult rv = aParams->AsCommandParams()->GetString(STATE_DATA, text);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  TextEditor* textEditor = editor->AsTextEditor();
  MOZ_ASSERT(textEditor);
  // XXX InsertTextAsAction() is not same as OnInputText().  However, other
  //     commands to insert line break or paragraph separator use OnInput*().
  //     According to the semantics of those methods, using *AsAction() is
  //     better, however, this may not cause two or more placeholder
  //     transactions to the top transaction since its name may not be
  //     nsGkAtoms::TypingTxnName.
  rv = textEditor->InsertTextAsAction(text);
  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to insert the text");
  return NS_OK;
}
Пример #13
0
void
FileSystemTaskParentBase::Start()
{
  AssertIsOnBackgroundThread();
  mFileSystem->AssertIsOnOwningThread();

  DebugOnly<nsresult> rv = DispatchToIOThread(this);
  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "DispatchToIOThread failed");
}
Пример #14
0
void
FileSystemFileEntry::GetFile(FileCallback& aSuccessCallback,
                             const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const
{
  RefPtr<FileCallbackRunnable> runnable =
    new FileCallbackRunnable(&aSuccessCallback, mFile);
  DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
}
mozilla::ipc::IPCResult
GamepadEventChannelChild::RecvGamepadUpdate(
                                       const GamepadChangeEvent& aGamepadEvent)
{
  DebugOnly<nsresult> rv =
    NS_DispatchToMainThread(new GamepadUpdateRunnable(aGamepadEvent));
  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
  return IPC_OK();
}
Пример #16
0
/* static */ void
PeerIdentity::GetNormalizedHost(const nsCOMPtr<nsIIDNService>& aIdnService,
                                const nsAString& aHost,
                                nsACString& aNormalizedHost)
{
  const nsCString chost = NS_ConvertUTF16toUTF8(aHost);
  DebugOnly<nsresult> rv = aIdnService->ConvertUTF8toACE(chost, aNormalizedHost);
  NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                       "Failed to convert UTF-8 host to ASCII");
}
Пример #17
0
void
FileSystemBase::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
                                 ErrorResult& aRv) const
{
  AssertIsOnOwningThread();
  MOZ_ASSERT(aFile);

  aRv = aFile->GetLeafName(aRetval);
  NS_WARNING_ASSERTION(!aRv.Failed(), "GetLeafName failed");
}
bool
SpeechSynthesisVoice::LocalService() const
{
  bool isLocal;
  DebugOnly<nsresult> rv =
    nsSynthVoiceRegistry::GetInstance()->IsLocalVoice(mUri, &isLocal);
  NS_WARNING_ASSERTION(
    NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.localService");

  return isLocal;
}
bool
SpeechSynthesisVoice::Default() const
{
  bool isDefault;
  DebugOnly<nsresult> rv =
    nsSynthVoiceRegistry::GetInstance()->IsDefaultVoice(mUri, &isDefault);
  NS_WARNING_ASSERTION(
    NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.default");

  return isDefault;
}
void
CreateDirectoryTaskChild::SetSuccessRequestResult(const FileSystemResponseValue& aValue,
                                                  ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");

  const FileSystemDirectoryResponse& r =
    aValue.get_FileSystemDirectoryResponse();

  aRv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(r.realPath()), true,
                              getter_AddRefs(mTargetPath));
  NS_WARNING_ASSERTION(!aRv.Failed(), "NS_NewNativeLocalFile failed");
}
Пример #21
0
void
GetEntryHelper::Error(nsresult aError)
{
  MOZ_ASSERT(NS_FAILED(aError));

  if (mErrorCallback) {
    RefPtr<ErrorCallbackRunnable> runnable =
      new ErrorCallbackRunnable(mParentEntry->GetParentObject(),
                                mErrorCallback, aError);
    DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
  }
}
Пример #22
0
void
nsSMILCompositor::UpdateCachedBaseValue(const nsSMILValue& aBaseValue)
{
  if (!mCachedBaseValue) {
    // We don't have last sample's base value cached. Assume it's changed.
    mCachedBaseValue = new nsSMILValue(aBaseValue);
    NS_WARNING_ASSERTION(mCachedBaseValue, "failed to cache base value (OOM?)");
    mForceCompositing = true;
  } else if (*mCachedBaseValue != aBaseValue) {
    // Base value has changed since last sample.
    *mCachedBaseValue = aBaseValue;
    mForceCompositing = true;
  }
}
Пример #23
0
NS_IMETHODIMP
nsScriptErrorBase::GetIsFromPrivateWindow(bool* aIsFromPrivateWindow)
{
    NS_WARNING_ASSERTION(NS_IsMainThread() || mInitializedOnMainThread,
                         "This can't be safely determined off the main thread, "
                         "returning an inaccurate value!");

    if (!mInitializedOnMainThread && NS_IsMainThread()) {
        InitializeOnMainThread();
    }

    *aIsFromPrivateWindow = mIsFromPrivateWindow;
    return NS_OK;
}
Пример #24
0
/* static */ void
FileSystemEntryCallbackHelper::Call(const Optional<OwningNonNull<FileSystemEntryCallback>>& aEntryCallback,
                                    FileSystemEntry* aEntry)
{
  MOZ_ASSERT(aEntry);

  if (aEntryCallback.WasPassed()) {
    RefPtr<EntryCallbackRunnable> runnable =
      new EntryCallbackRunnable(&aEntryCallback.Value(), aEntry);

    DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
  }
}
Пример #25
0
NS_IMETHODIMP
LocalStoreImpl::Flush()
{
	nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
    // FIXME Bug 340242: Temporarily make this a warning rather than an
    // assertion until we sort out the ordering of how we write
    // everything to the localstore, flush it, and disconnect it when
    // we're getting profile-change notifications.
    NS_WARNING_ASSERTION(remote != nullptr, "not an nsIRDFRemoteDataSource");
	if (! remote)
        return NS_ERROR_UNEXPECTED;

    return remote->Flush();
}
Пример #26
0
void
URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
{
  MOZ_ASSERT(mSearchParams);
  MOZ_ASSERT(mSearchParams == aSearchParams);

  nsAutoString search;
  mSearchParams->Serialize(search);

  ErrorResult rv;
  SetSearchInternal(search, rv);
  NS_WARNING_ASSERTION(!rv.Failed(), "SetSearchInternal failed");
  rv.SuppressException();
}
Пример #27
0
NS_IMETHODIMP
nsScriptErrorBase::GetOuterWindowID(uint64_t* aOuterWindowID)
{
    NS_WARNING_ASSERTION(NS_IsMainThread() || mInitializedOnMainThread,
                         "This can't be safely determined off the main thread, "
                         "returning an inaccurate value!");

    if (!mInitializedOnMainThread && NS_IsMainThread()) {
        InitializeOnMainThread();
    }

    *aOuterWindowID = mOuterWindowID;
    return NS_OK;
}
nsresult
convertResultCode(int aSQLiteResultCode)
{
  // Drop off the extended result bits of the result code.
  int rc = aSQLiteResultCode & 0xFF;

  switch (rc) {
    case SQLITE_OK:
    case SQLITE_ROW:
    case SQLITE_DONE:
      return NS_OK;
    case SQLITE_CORRUPT:
    case SQLITE_NOTADB:
      return NS_ERROR_FILE_CORRUPTED;
    case SQLITE_PERM:
    case SQLITE_CANTOPEN:
      return NS_ERROR_FILE_ACCESS_DENIED;
    case SQLITE_BUSY:
      return NS_ERROR_STORAGE_BUSY;
    case SQLITE_LOCKED:
      return NS_ERROR_FILE_IS_LOCKED;
    case SQLITE_READONLY:
      return NS_ERROR_FILE_READ_ONLY;
    case SQLITE_IOERR:
      return NS_ERROR_STORAGE_IOERR;
    case SQLITE_FULL:
    case SQLITE_TOOBIG:
      return NS_ERROR_FILE_NO_DEVICE_SPACE;
    case SQLITE_NOMEM:
      return NS_ERROR_OUT_OF_MEMORY;
    case SQLITE_MISUSE:
      return NS_ERROR_UNEXPECTED;
    case SQLITE_ABORT:
    case SQLITE_INTERRUPT:
      return NS_ERROR_ABORT;
    case SQLITE_CONSTRAINT:
      return NS_ERROR_STORAGE_CONSTRAINT;
  }

  // generic error
#ifdef DEBUG
  nsAutoCString message;
  message.AppendLiteral("SQLite returned error code ");
  message.AppendInt(rc);
  message.AppendLiteral(" , Storage will convert it to NS_ERROR_FAILURE");
  NS_WARNING_ASSERTION(rc == SQLITE_ERROR, message.get());
#endif
  return NS_ERROR_FAILURE;
}
Пример #29
0
/* static */ void
ErrorCallbackHelper::Call(nsIGlobalObject* aGlobal,
                          const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback,
                          nsresult aError)
{
  MOZ_ASSERT(aGlobal);
  MOZ_ASSERT(NS_FAILED(aError));

  if (aErrorCallback.WasPassed()) {
    RefPtr<ErrorCallbackRunnable> runnable =
      new ErrorCallbackRunnable(aGlobal, &aErrorCallback.Value(), aError);
    DebugOnly<nsresult> rv = NS_DispatchToMainThread(runnable);
    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
  }
}
Пример #30
0
ScopedXErrorHandler::ScopedXErrorHandler(bool aAllowOffMainThread)
{
    if (!aAllowOffMainThread) {
      // Off main thread usage is not safe in general, but OMTC GL layers uses this
      // with the main thread blocked, which makes it safe.
      NS_WARNING_ASSERTION(
        NS_IsMainThread(),
        "ScopedXErrorHandler being called off main thread, may cause issues");
    }
    // let sXErrorPtr point to this object's mXError object, but don't reset this mXError object!
    // think of the case of nested ScopedXErrorHandler's.
    mOldXErrorPtr = sXErrorPtr;
    sXErrorPtr = &mXError;
    mOldErrorHandler = XSetErrorHandler(ErrorHandler);
}