OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 // | |
5 // Description of the current unique name format | |
6 // --------------------------------------------- | |
7 // | |
8 // Changing the format of unique name is undesirable, because it breaks | |
9 // backcompatibility of session history (which stores unique names | |
10 // generated in the past on user's disk). This incremental, | |
11 // backcompatibility-aware approach has resulted so far in the following | |
12 // rather baroque format... : | |
13 // | |
14 // uniqueName ::= <nullForMainFrame> | <assignedName> | <generatedName> | |
15 // (generatedName is used if assignedName is | |
16 // non-unique / conflicts with other frame's unique name. | |
17 // | |
18 // assignedName ::= value of iframe's name attribute | |
19 // or value assigned to window.name (*before* the first | |
20 // real commit - afterwards unique name stays immutable). | |
21 // | |
22 // generatedName ::= oldGeneratedName newUniqueSuffix? | |
23 // (newUniqueSuffix is only present if oldGeneratedName was | |
24 // not unique after all) | |
25 // | |
26 // oldGeneratedName ::= "<!--framePath //" ancestorChain | |
27 // "/<!--frame" childCount "-->-->" | |
28 // (oldGeneratedName is generated by | |
29 // generateUniqueNameCandidate method). | |
30 // | |
31 // childCount ::= current number of siblings | |
32 // | |
33 // ancestorChain ::= concatenated unique names of ancestor chain, | |
34 // terminated on the first ancestor (if any) starting with | |
35 // "<!--framePath"; each ancestor's unique name is | |
36 // separated by "/" character | |
37 // ancestorChain example1: "grandparent/parent" | |
38 // (ancestor's unique names : #1--^ | #2-^ ) | |
39 // ancestorChain example2: | |
40 // "<!--framePath //foo/bar/<!--frame42-->-->/blah/foobar" | |
41 // (ancestor's unique names: | |
42 // ^--#1--^ | #2 | #3-^ ) | |
43 // | |
44 // newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber | |
45 // "-->" | |
46 // | |
47 // framePosition ::= "-" numberOfSiblingsBeforeChild | |
48 // [ framePosition-forParent? ] | |
49 // | |
50 // retryNumber ::= smallest non-negative integer resulting in unique name | |
51 | |
52 #ifndef CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | |
53 #define CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | |
54 | |
55 #include <string> | |
56 | |
57 #include "base/macros.h" | |
58 | |
59 namespace blink { | |
60 class WebFrame; | |
61 class WebLocalFrame; | |
62 } // namespace blink | |
63 | |
64 namespace content { | |
65 | |
66 class RenderFrameImpl; | |
67 | |
68 class UniqueNameHelper { | |
Charlie Reis
2017/03/02 23:59:18
Let's add a class level comment. Something like:
dcheng
2017/03/03 10:22:08
Done: I merged the comment documenting value() int
| |
69 public: | |
70 explicit UniqueNameHelper(RenderFrameImpl* render_frame); | |
71 ~UniqueNameHelper(); | |
72 | |
73 const std::string& value() const { return unique_name_; } | |
74 | |
75 // Used to propagate an already calculated unique name. | |
76 void set_propagated_name(const std::string& name) { unique_name_ = name; } | |
77 | |
78 // Note: |parent| needs to be plumbed in for new child frames, since the | |
79 // unique name needs to be calculated before the new child RenderFrameImpl is | |
80 // created. | |
81 static std::string GenerateNameForNewChildFrame(blink::WebFrame* parent, | |
Charlie Reis
2017/03/02 23:59:18
Why does this need to be static? Looks like it's
dcheng
2017/03/03 10:22:08
There's a chicken and egg problem here. We need to
| |
82 const std::string& name); | |
83 | |
84 // Called after a browsing context name change to generate a new name. Note | |
85 // that this should not be called if the frame is no longer displaying the | |
86 // initial empty document, as unique name changes after that point will break | |
87 // history navigations. See https://crbug.com/607205. | |
88 void UpdateName(const std::string& name); | |
89 | |
90 private: | |
91 blink::WebLocalFrame* GetWebFrame() const; | |
92 | |
93 RenderFrameImpl* const render_frame_; | |
94 std::string unique_name_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(UniqueNameHelper); | |
97 }; | |
98 | |
99 } // namespace content | |
100 | |
101 #endif // CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | |
OLD | NEW |