Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: third_party/WebKit/Source/core/page/FrameTree.h

Issue 1968213002: Try harder to make sure that blink::FrameTree::m_uniqueName is truly unique. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR comments from dcheng@. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. 2 * Copyright (C) 2006 Apple Computer, Inc.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 19 matching lines...) Expand all
30 class TreeScope; 30 class TreeScope;
31 31
32 class CORE_EXPORT FrameTree final { 32 class CORE_EXPORT FrameTree final {
33 WTF_MAKE_NONCOPYABLE(FrameTree); 33 WTF_MAKE_NONCOPYABLE(FrameTree);
34 DISALLOW_NEW(); 34 DISALLOW_NEW();
35 public: 35 public:
36 explicit FrameTree(Frame* thisFrame); 36 explicit FrameTree(Frame* thisFrame);
37 ~FrameTree(); 37 ~FrameTree();
38 38
39 const AtomicString& name() const { return m_name; } 39 const AtomicString& name() const { return m_name; }
40 void setName(const AtomicString&);
41
42 // Unique name of a frame (unique per page). Mainly used to identify the
43 // frame for session history purposes, but also used in expected results
44 // of layout tests.
45 //
46 // The value should be treated as an unstructured, opaque string.
40 const AtomicString& uniqueName() const { return m_uniqueName; } 47 const AtomicString& uniqueName() const { return m_uniqueName; }
41 // If |name| is not empty, |fallbackName| is ignored. Otherwise,
42 // |fallbackName| is used as a source of uniqueName.
43 void setName(const AtomicString& name, const AtomicString& fallbackName = nu llAtom);
44 48
45 // Directly assigns both the name and uniqueName. Can be used when 49 // Directly assigns both the name and uniqueName. Can be used when
46 // |uniqueName| is already known (i.e. when it has been precalculated by 50 // |uniqueName| is already known (i.e. when it has been precalculated by
47 // calculateUniqueNameForNewChildFrame OR when replicating the name between 51 // calculateUniqueNameForNewChildFrame OR when replicating the name between
48 // LocalFrames and RemoteFrames for the same logical frame). 52 // LocalFrames and RemoteFrames for the same logical frame).
49 void setPrecalculatedName(const AtomicString& name, const AtomicString& uniq ueName); 53 void setPrecalculatedName(const AtomicString& name, const AtomicString& uniq ueName);
50 54
51 Frame* parent() const; 55 Frame* parent() const;
52 Frame* top() const; 56 Frame* top() const;
53 Frame* previousSibling() const; 57 Frame* previousSibling() const;
(...skipping 16 matching lines...) Expand all
70 void invalidateScopedChildCount(); 74 void invalidateScopedChildCount();
71 75
72 DECLARE_TRACE(); 76 DECLARE_TRACE();
73 77
74 AtomicString calculateUniqueNameForNewChildFrame( 78 AtomicString calculateUniqueNameForNewChildFrame(
75 const AtomicString& name, 79 const AtomicString& name,
76 const AtomicString& fallbackName = nullAtom) const; 80 const AtomicString& fallbackName = nullAtom) const;
77 81
78 private: 82 private:
79 Frame* deepLastChild() const; 83 Frame* deepLastChild() const;
84
85 // Returns true if one of frames in the tree already has unique name equal
86 // to |uniqueNameCandidate|.
87 bool uniqueNameExists(const String& uniqueNameCandidate) const;
88
89 // Generates a hopefully-but-not-necessarily unique name based on frame's
90 // relative position in the tree and on unique names of ancestors.
91 String generateUniqueNameCandidate(bool existingChildFrame) const;
92
93 // Generates a hopefully-but-not-necessarily unique suffix based on |child|
94 // absolute position in the tree. If |child| is nullptr, calculations are
95 // made for a position that a new child of |this| would have.
96 String generateFramePosition(Frame* child) const;
97
98 // Concatenates |prefix|, |likelyUniqueSuffix| (and additional, internally
99 // generated suffix) until the result is a unique name, that doesn't exist
100 // elsewhere in the frame tree. Returns the unique name built in this way.
101 AtomicString appendUniqueSuffix(
102 const String& prefix,
103 const String& likelyUniqueSuffix) const;
104
105 // Calculates a unique name for |child| frame (which might be nullptr if the
106 // child has not yet been created - i.e. when we need unique name for a new
107 // frame). Tries to use the |assignedName| or |fallbackName| if possible,
108 // otherwise falls back to generating a deterministic,
109 // stable-across-page-reloads string based on |child| position in the tree.
80 AtomicString calculateUniqueNameForChildFrame( 110 AtomicString calculateUniqueNameForChildFrame(
81 bool existingChildFrame, 111 Frame* child,
82 const AtomicString& name, 112 const AtomicString& assignedName,
83 const AtomicString& fallbackName = nullAtom) const; 113 const AtomicString& fallbackName = nullAtom) const;
84 bool uniqueNameExists(const AtomicString& name) const; 114
115 // Sets |m_uniqueName| and asserts its uniqueness.
116 void setUniqueName(const AtomicString&);
85 117
86 Member<Frame> m_thisFrame; 118 Member<Frame> m_thisFrame;
87 119
88 AtomicString m_name; // The actual frame name (may be empty). 120 AtomicString m_name; // The actual frame name (may be empty).
89 AtomicString m_uniqueName; 121 AtomicString m_uniqueName;
90 122
91 mutable unsigned m_scopedChildCount; 123 mutable unsigned m_scopedChildCount;
92 }; 124 };
93 125
94 } // namespace blink 126 } // namespace blink
95 127
96 #ifndef NDEBUG 128 #ifndef NDEBUG
97 // Outside the WebCore namespace for ease of invocation from gdb. 129 // Outside the WebCore namespace for ease of invocation from gdb.
98 void showFrameTree(const blink::Frame*); 130 void showFrameTree(const blink::Frame*);
99 #endif 131 #endif
100 132
101 #endif // FrameTree_h 133 #endif // FrameTree_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698