File: FrameTree.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (126 lines) | stat: -rw-r--r-- 4,615 bytes parent folder | download
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
/*
 * Copyright (C) 2006 Apple Computer, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef FrameTree_h
#define FrameTree_h

#include "core/CoreExport.h"
#include "platform/heap/Handle.h"
#include "wtf/text/AtomicString.h"

namespace blink {

class Frame;

class CORE_EXPORT FrameTree final {
  WTF_MAKE_NONCOPYABLE(FrameTree);
  DISALLOW_NEW();

 public:
  explicit FrameTree(Frame* thisFrame);
  ~FrameTree();

  const AtomicString& name() const { return m_name; }
  void setName(const AtomicString&);

  // Unique name of a frame (unique per page).  Mainly used to identify the
  // frame for session history purposes, but also used in expected results
  // of layout tests.
  //
  // The value should be treated as an unstructured, opaque string.
  const AtomicString& uniqueName() const { return m_uniqueName; }

  // Directly assigns both the name and uniqueName.  Can be used when
  // |uniqueName| is already known (i.e. when it has been precalculated by
  // calculateUniqueNameForNewChildFrame OR when replicating the name between
  // LocalFrames and RemoteFrames for the same logical frame).
  void setPrecalculatedName(const AtomicString& name,
                            const AtomicString& uniqueName);

  Frame* parent() const;
  Frame* top() const;
  Frame* nextSibling() const;
  Frame* firstChild() const;

  bool isDescendantOf(const Frame* ancestor) const;
  Frame* traverseNext(const Frame* stayWithin = nullptr) const;

  Frame* find(const AtomicString& name) const;
  unsigned childCount() const;

  Frame* scopedChild(unsigned index) const;
  Frame* scopedChild(const AtomicString& name) const;
  unsigned scopedChildCount() const;
  void invalidateScopedChildCount();

  DECLARE_TRACE();

  AtomicString calculateUniqueNameForNewChildFrame(
      const AtomicString& name,
      const AtomicString& fallbackName = nullAtom) const;

 private:
  // Returns true if one of frames in the tree already has unique name equal
  // to |uniqueNameCandidate|.
  bool uniqueNameExists(const String& uniqueNameCandidate) const;

  // Generates a hopefully-but-not-necessarily unique name based on frame's
  // relative position in the tree and on unique names of ancestors.
  String generateUniqueNameCandidate(bool existingChildFrame) const;

  // Generates a hopefully-but-not-necessarily unique suffix based on |child|
  // absolute position in the tree.  If |child| is nullptr, calculations are
  // made for a position that a new child of |this| would have.
  String generateFramePosition(Frame* child) const;

  // Concatenates |prefix|, |likelyUniqueSuffix| (and additional, internally
  // generated suffix) until the result is a unique name, that doesn't exist
  // elsewhere in the frame tree.  Returns the unique name built in this way.
  AtomicString appendUniqueSuffix(const String& prefix,
                                  const String& likelyUniqueSuffix) const;

  // Calculates a unique name for |child| frame (which might be nullptr if the
  // child has not yet been created - i.e. when we need unique name for a new
  // frame).  Tries to use the |assignedName| or |fallbackName| if possible,
  // otherwise falls back to generating a deterministic,
  // stable-across-page-reloads string based on |child| position in the tree.
  AtomicString calculateUniqueNameForChildFrame(
      Frame* child,
      const AtomicString& assignedName,
      const AtomicString& fallbackName = nullAtom) const;

  // Sets |m_uniqueName| and asserts its uniqueness.
  void setUniqueName(const AtomicString&);

  Member<Frame> m_thisFrame;

  AtomicString m_name;  // The actual frame name (may be empty).
  AtomicString m_uniqueName;

  mutable unsigned m_scopedChildCount;
};

}  // namespace blink

#ifndef NDEBUG
// Outside the WebCore namespace for ease of invocation from gdb.
void showFrameTree(const blink::Frame*);
#endif

#endif  // FrameTree_h