| 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 #ifndef CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | |
| 6 #define CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 class WebFrame; | |
| 14 class WebLocalFrame; | |
| 15 } // namespace blink | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 class RenderFrameImpl; | |
| 20 | |
| 21 // Frame helper that manages the details of generating a quasi-stable unique | |
| 22 // name for the frame. The name is unique within a page, and is used for: | |
| 23 // - matching up session history items with recreated frames | |
| 24 // - layout test results | |
| 25 // | |
| 26 // Description of the current unique name format | |
| 27 // --------------------------------------------- | |
| 28 // Changing the format of unique name has a high cost, because it breaks | |
| 29 // backwards compatibility of session history (which stores unique names | |
| 30 // generated in the past on user's disk). The evolution of unique name in a | |
| 31 // mostly backwards-compatible way has resulted in the rather baroque format... | |
| 32 // | |
| 33 // uniqueName ::= <nullForMainFrame> | <assignedName> | <generatedName> | |
| 34 // Note: generatedName is used if assignedName is non-unique / conflicts with | |
| 35 // other frame's unique name. | |
| 36 // | |
| 37 // assignedName ::= value of iframe's name attribute | |
| 38 // or value assigned to window.name | |
| 39 // Note: The name must be assigned *before* the first real commit: afterwards, | |
| 40 // the unique name is immutable. | |
| 41 // | |
| 42 // generatedName ::= oldGeneratedName newUniqueSuffix? | |
| 43 // Note: newUniqueSuffix is only present if oldGeneratedName is not unique. | |
| 44 // | |
| 45 // oldGeneratedName ::= "<!--framePath //" ancestorChain | |
| 46 // "/<!--frame" childCount "-->-->" | |
| 47 // Note: oldGeneratedName is generated by the internal GenerateCandidate() | |
| 48 // method. | |
| 49 // | |
| 50 // childCount ::= current number of siblings | |
| 51 // | |
| 52 // ancestorChain ::= concatenated unique names of ancestor chain, | |
| 53 // terminated on the first ancestor (if any) starting with | |
| 54 // "<!--framePath"; each ancestor's unique name is | |
| 55 // separated by "/" character | |
| 56 // Note: Two examples are provided below, with each portion of the name from a | |
| 57 // distinct ancestor annotated. | |
| 58 // | |
| 59 // Example ancestor chain #1: | |
| 60 // "grandparent/parent" | |
| 61 // | #1 | #2 | | |
| 62 // Example ancestor chain #2: | |
| 63 // "<!--framePath //foo/bar/<!--frame42-->-->/blah/foobar" | |
| 64 // | #1 | #2 | #3 | | |
| 65 // | |
| 66 // newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber "-->" | |
| 67 // | |
| 68 // framePosition ::= "-" numberOfSiblingsBeforeChild | |
| 69 // [ framePosition-forParent? ] | |
| 70 // | |
| 71 // retryNumber ::= smallest non-negative integer resulting in unique name | |
| 72 class UniqueNameHelper { | |
| 73 public: | |
| 74 explicit UniqueNameHelper(RenderFrameImpl* render_frame); | |
| 75 ~UniqueNameHelper(); | |
| 76 | |
| 77 // Returns the generated unique name. | |
| 78 const std::string& value() const { return unique_name_; } | |
| 79 | |
| 80 // Used to propagate an already calculated unique name. | |
| 81 // | |
| 82 // TODO(lukasza): It would be nice to assert uniqueness of the propagated | |
| 83 // name here but: | |
| 84 // 1) uniqueness is currently violated by provisional/old frame pairs. | |
| 85 // 2) there is an unresolved race between 2 OOPIFs, that can result in a | |
| 86 // non-unique unique name: see https://crbug.com/558680#c14. | |
| 87 void set_propagated_name(const std::string& name) { unique_name_ = name; } | |
| 88 | |
| 89 // Note: when creating a new child frame, the unique name needs to be | |
| 90 // calculated before the RenderFrameImpl is created. To avoid this chicken and | |
| 91 // egg problem, this method is static, which means that |parent| needs to be | |
| 92 // passed as a parameter. | |
| 93 static std::string GenerateNameForNewChildFrame(blink::WebFrame* parent, | |
| 94 const std::string& name); | |
| 95 | |
| 96 // Called after a browsing context name change to generate a new name. Note | |
| 97 // that this should not be called if the frame is no longer displaying the | |
| 98 // initial empty document, as unique name changes after that point will break | |
| 99 // history navigations. See https://crbug.com/607205. | |
| 100 void UpdateName(const std::string& name); | |
| 101 | |
| 102 private: | |
| 103 blink::WebLocalFrame* GetWebFrame() const; | |
| 104 | |
| 105 RenderFrameImpl* const render_frame_; | |
| 106 std::string unique_name_; | |
| 107 | |
| 108 DISALLOW_COPY_AND_ASSIGN(UniqueNameHelper); | |
| 109 }; | |
| 110 | |
| 111 } // namespace content | |
| 112 | |
| 113 #endif // CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | |
| OLD | NEW |