summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_object_avail.h
blob: f593ea21590ef28f1010b9a87661771481571cd7 (plain)
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
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CORE_FPDFAPI_PARSER_CPDF_OBJECT_AVAIL_H_
#define CORE_FPDFAPI_PARSER_CPDF_OBJECT_AVAIL_H_

#include <memory>
#include <set>
#include <stack>

#include "core/fpdfapi/parser/cpdf_data_avail.h"
#include "core/fxcrt/maybe_owned.h"
#include "core/fxcrt/unowned_ptr.h"

class CPDF_Object;
class CPDF_Reference;
class CPDF_IndirectObjectHolder;
class CPDF_ReadValidator;

// Helper for check availability of object tree.
class CPDF_ObjectAvail {
 public:
  CPDF_ObjectAvail(CPDF_ReadValidator* validator,
                   CPDF_IndirectObjectHolder* holder,
                   const CPDF_Object* root);
  CPDF_ObjectAvail(CPDF_ReadValidator* validator,
                   CPDF_IndirectObjectHolder* holder,
                   uint32_t obj_num);
  virtual ~CPDF_ObjectAvail();

  CPDF_DataAvail::DocAvailStatus CheckAvail();

 protected:
  virtual bool ExcludeObject(const CPDF_Object* object) const;

 private:
  bool LoadRootObject();
  bool CheckObjects();
  bool AppendObjectSubRefs(const CPDF_Object* object,
                           std::stack<uint32_t>* refs) const;
  void CleanMemory();
  bool HasObjectParsed(uint32_t obj_num) const;

  UnownedPtr<CPDF_ReadValidator> validator_;
  // TODO(art-snake): Make it UnownedPtr<, after fix document owning issue.
  CPDF_IndirectObjectHolder* holder_;
  MaybeOwned<const CPDF_Object> root_;
  std::set<uint32_t> parsed_objnums_;
  std::stack<uint32_t> non_parsed_objects_;
};

#endif  // CORE_FPDFAPI_PARSER_CPDF_OBJECT_AVAIL_H_