Exemple #1
0
bool
GMPStorageParent::RecvOpen(const nsCString& aRecordName)
{
  if (mShutdown) {
    return true;
  }

  if (mOrigin.EqualsASCII("null")) {
    // Refuse to open storage if the page is the "null" origin; if the page
    // is opened from disk.
    NS_WARNING("Refusing to open storage for null origin");
    unused << SendOpenComplete(aRecordName, GMPGenericErr);
    return true;
  }

  if (aRecordName.IsEmpty() || mFiles.Contains(aRecordName)) {
    unused << SendOpenComplete(aRecordName, GMPRecordInUse);
    return true;
  }

  PRFileDesc* fd = nullptr;
  nsresult rv = OpenStorageFile(aRecordName, mOrigin, ReadWrite, &fd);
  if (NS_FAILED(rv)) {
    NS_WARNING("Failed to open storage file.");
    unused << SendOpenComplete(aRecordName, GMPGenericErr);
    return true;
  }

  mFiles.Put(aRecordName, fd);
  unused << SendOpenComplete(aRecordName, GMPNoErr);

  return true;
}
bool
GMPStorageParent::RecvOpen(const nsCString& aRecordName)
{
  LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s')",
       this, aRecordName.get()));

  if (mShutdown) {
    return false;
  }

  if (mNodeId.EqualsLiteral("null")) {
    // Refuse to open storage if the page is opened from local disk,
    // or shared across origin.
    LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') failed; null nodeId",
          this, aRecordName.get()));
    Unused << SendOpenComplete(aRecordName, GMPGenericErr);
    return true;
  }

  if (aRecordName.IsEmpty()) {
    LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') failed; record name empty",
          this, aRecordName.get()));
    Unused << SendOpenComplete(aRecordName, GMPGenericErr);
    return true;
  }

  if (mStorage->IsOpen(aRecordName)) {
    LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') failed; record in use",
          this, aRecordName.get()));
    Unused << SendOpenComplete(aRecordName, GMPRecordInUse);
    return true;
  }

  auto err = mStorage->Open(aRecordName);
  MOZ_ASSERT(GMP_FAILED(err) || mStorage->IsOpen(aRecordName));
  LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') complete; rv=%d",
        this, aRecordName.get(), err));
  Unused << SendOpenComplete(aRecordName, err);

  return true;
}