DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_BaseBlobImpl_h
#define mozilla_dom_BaseBlobImpl_h

#include "mozilla/dom/BlobImpl.h"

namespace mozilla {
namespace dom {

class BaseBlobImpl : public BlobImpl {
 public:
  BaseBlobImpl(const nsAString& aBlobImplType, const nsAString& aName,
               const nsAString& aContentType, uint64_t aLength,
               int64_t aLastModifiedDate)
      : mBlobImplType(aBlobImplType),
        mIsFile(true),
        mImmutable(false),
        mContentType(aContentType),
        mName(aName),
        mStart(0),
        mLength(aLength),
        mLastModificationDate(aLastModifiedDate),
        mSerialNumber(NextSerialNumber()) {
    // Ensure non-null mContentType by default
    mContentType.SetIsVoid(false);
  }

  BaseBlobImpl(const nsAString& aBlobImplType, const nsAString& aName,
               const nsAString& aContentType, uint64_t aLength)
      : mBlobImplType(aBlobImplType),
        mIsFile(true),
        mImmutable(false),
        mContentType(aContentType),
        mName(aName),
        mStart(0),
        mLength(aLength),
        mLastModificationDate(INT64_MAX),
        mSerialNumber(NextSerialNumber()) {
    // Ensure non-null mContentType by default
    mContentType.SetIsVoid(false);
  }

  BaseBlobImpl(const nsAString& aBlobImplType, const nsAString& aContentType,
               uint64_t aLength)
      : mBlobImplType(aBlobImplType),
        mIsFile(false),
        mImmutable(false),
        mContentType(aContentType),
        mStart(0),
        mLength(aLength),
        mLastModificationDate(INT64_MAX),
        mSerialNumber(NextSerialNumber()) {
    // Ensure non-null mContentType by default
    mContentType.SetIsVoid(false);
  }

  BaseBlobImpl(const nsAString& aBlobImplType, const nsAString& aContentType,
               uint64_t aStart, uint64_t aLength)
      : mBlobImplType(aBlobImplType),
        mIsFile(false),
        mImmutable(false),
        mContentType(aContentType),
        mStart(aStart),
        mLength(aLength),
        mLastModificationDate(INT64_MAX),
        mSerialNumber(NextSerialNumber()) {
    MOZ_ASSERT(aLength != UINT64_MAX, "Must know length when creating slice");
    // Ensure non-null mContentType by default
    mContentType.SetIsVoid(false);
  }

  virtual void GetName(nsAString& aName) const override;

  virtual void GetDOMPath(nsAString& aName) const override;

  virtual void SetDOMPath(const nsAString& aName) override;

  virtual int64_t GetLastModified(ErrorResult& aRv) override;

  virtual void SetLastModified(int64_t aLastModified) override;

  virtual void GetMozFullPath(nsAString& aName,
                              SystemCallerGuarantee /* unused */,
                              ErrorResult& aRv) override;

  virtual void GetMozFullPathInternal(nsAString& aFileName,
                                      ErrorResult& aRv) override;

  virtual uint64_t GetSize(ErrorResult& aRv) override { return mLength; }

  virtual void GetType(nsAString& aType) override;

  size_t GetAllocationSize() const override { return 0; }

  size_t GetAllocationSize(
      FallibleTArray<BlobImpl*>& aVisitedBlobImpls) const override {
    return GetAllocationSize();
  }

  virtual uint64_t GetSerialNumber() const override { return mSerialNumber; }

  virtual already_AddRefed<BlobImpl> CreateSlice(uint64_t aStart,
                                                 uint64_t aLength,
                                                 const nsAString& aContentType,
                                                 ErrorResult& aRv) override {
    return nullptr;
  }

  virtual const nsTArray<RefPtr<BlobImpl>>* GetSubBlobImpls() const override {
    return nullptr;
  }

  virtual void CreateInputStream(nsIInputStream** aStream,
                                 ErrorResult& aRv) override {
    aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
  }

  virtual int64_t GetFileId() override;

  virtual nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
                               nsACString& aContentType,
                               nsACString& aCharset) override;

  virtual nsresult GetMutable(bool* aMutable) const override;

  virtual nsresult SetMutable(bool aMutable) override;

  virtual void SetLazyData(const nsAString& aName,
                           const nsAString& aContentType, uint64_t aLength,
                           int64_t aLastModifiedDate) override {
    mName = aName;
    mContentType = aContentType;
    mLength = aLength;
    mLastModificationDate = aLastModifiedDate;
    mIsFile = !aName.IsVoid();
  }

  virtual bool IsMemoryFile() const override { return false; }

  virtual bool IsDateUnknown() const override {
    return mIsFile && mLastModificationDate == INT64_MAX;
  }

  virtual bool IsFile() const override { return mIsFile; }

  virtual bool IsSizeUnknown() const override { return mLength == UINT64_MAX; }

  virtual void GetBlobImplType(nsAString& aBlobImplType) const override {
    aBlobImplType = mBlobImplType;
  }

 protected:
  virtual ~BaseBlobImpl() {}

  /**
   * Returns a new, effectively-unique serial number. This should be used
   * by implementations to obtain a serial number for GetSerialNumber().
   * The implementation is thread safe.
   */
  static uint64_t NextSerialNumber();

  const nsString mBlobImplType;

  bool mIsFile;
  bool mImmutable;

  nsString mContentType;
  nsString mName;
  nsString mPath;  // The path relative to a directory chosen by the user

  uint64_t mStart;
  uint64_t mLength;

  int64_t mLastModificationDate;

  const uint64_t mSerialNumber;
};

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_BaseBlobImpl_h