当前位置: 首页>>代码示例>>C++>>正文


C++ Blob::ToFile方法代码示例

本文整理汇总了C++中Blob::ToFile方法的典型用法代码示例。如果您正苦于以下问题:C++ Blob::ToFile方法的具体用法?C++ Blob::ToFile怎么用?C++ Blob::ToFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Blob的用法示例。


在下文中一共展示了Blob::ToFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Data

already_AddRefed<File>
DataTransferItem::GetAsFile(nsIPrincipal& aSubjectPrincipal,
                            ErrorResult& aRv)
{
  // This is done even if we have an mCachedFile, as it performs the necessary
  // permissions checks to ensure that we are allowed to access this type.
  nsCOMPtr<nsIVariant> data = Data(&aSubjectPrincipal, aRv);
  if (NS_WARN_IF(!data || aRv.Failed())) {
    return nullptr;
  }

  // We have to check our kind after getting the data, because if we have
  // external data and the OS lied to us (which unfortunately does happen
  // sometimes), then we might not have the same type of data as we did coming
  // into this function.
  if (NS_WARN_IF(mKind != KIND_FILE)) {
    return nullptr;
  }

  // Generate the dom::File from the stored data, caching it so that the
  // same object is returned in the future.
  if (!mCachedFile) {
    nsCOMPtr<nsISupports> supports;
    aRv = data->GetAsISupports(getter_AddRefs(supports));
    MOZ_ASSERT(!aRv.Failed() && supports,
               "File objects should be stored as nsISupports variants");
    if (aRv.Failed() || !supports) {
      return nullptr;
    }

    if (nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports)) {
      Blob* blob = static_cast<Blob*>(domBlob.get());
      mCachedFile = blob->ToFile();
    } else if (nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(supports)) {
      MOZ_ASSERT(blobImpl->IsFile());
      mCachedFile = File::Create(mDataTransfer, blobImpl);
    } else if (nsCOMPtr<nsIFile> ifile = do_QueryInterface(supports)) {
      mCachedFile = File::CreateFromFile(mDataTransfer, ifile);
    } else {
      MOZ_ASSERT(false, "One of the above code paths should be taken");
      return nullptr;
    }
  }

  RefPtr<File> file = mCachedFile;
  return file.forget();
}
开发者ID:,项目名称:,代码行数:47,代码来源:

示例2: Data

already_AddRefed<File>
DataTransferItem::GetAsFileWithPrincipal(nsIPrincipal* aPrincipal, ErrorResult& aRv)
{
  if (mKind != KIND_FILE) {
    return nullptr;
  }

  // This is done even if we have an mCachedFile, as it performs the necessary
  // permissions checks to ensure that we are allowed to access this type.
  nsCOMPtr<nsIVariant> data = Data(aPrincipal, aRv);
  if (NS_WARN_IF(!data || aRv.Failed())) {
    return nullptr;
  }

  // Generate the dom::File from the stored data, caching it so that the
  // same object is returned in the future.
  if (!mCachedFile) {
    nsCOMPtr<nsISupports> supports;
    aRv = data->GetAsISupports(getter_AddRefs(supports));
    MOZ_ASSERT(!aRv.Failed() && supports,
               "File objects should be stored as nsISupports variants");
    if (aRv.Failed() || !supports) {
      return nullptr;
    }

    if (nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports)) {
      Blob* blob = static_cast<Blob*>(domBlob.get());
      mCachedFile = blob->ToFile();
    } else if (nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(supports)) {
      MOZ_ASSERT(blobImpl->IsFile());
      mCachedFile = File::Create(mDataTransfer, blobImpl);
    } else if (nsCOMPtr<nsIFile> ifile = do_QueryInterface(supports)) {
      mCachedFile = File::CreateFromFile(mDataTransfer, ifile);
    } else {
      MOZ_ASSERT(false, "One of the above code paths should be taken");
    }
  }

  RefPtr<File> file = mCachedFile;
  return file.forget();
}
开发者ID:cstipkovic,项目名称:gecko-dev,代码行数:41,代码来源:DataTransferItem.cpp


注:本文中的Blob::ToFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。