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 // |
| 29 // Changing the format of unique name is undesirable, because it breaks |
| 30 // backcompatibility of session history (which stores unique names |
| 31 // generated in the past on user's disk). This incremental, |
| 32 // backcompatibility-aware approach has resulted so far in the following |
| 33 // rather baroque format... : |
| 34 // |
| 35 // uniqueName ::= <nullForMainFrame> | <assignedName> | <generatedName> |
| 36 // (generatedName is used if assignedName is |
| 37 // non-unique / conflicts with other frame's unique name. |
| 38 // |
| 39 // assignedName ::= value of iframe's name attribute |
| 40 // or value assigned to window.name (*before* the first |
| 41 // real commit - afterwards unique name stays immutable). |
| 42 // |
| 43 // generatedName ::= oldGeneratedName newUniqueSuffix? |
| 44 // (newUniqueSuffix is only present if oldGeneratedName was |
| 45 // not unique after all) |
| 46 // |
| 47 // oldGeneratedName ::= "<!--framePath //" ancestorChain |
| 48 // "/<!--frame" childCount "-->-->" |
| 49 // (oldGeneratedName is generated by |
| 50 // generateUniqueNameCandidate method). |
| 51 // |
| 52 // childCount ::= current number of siblings |
| 53 // |
| 54 // ancestorChain ::= concatenated unique names of ancestor chain, |
| 55 // terminated on the first ancestor (if any) starting with |
| 56 // "<!--framePath"; each ancestor's unique name is |
| 57 // separated by "/" character |
| 58 // ancestorChain example1: "grandparent/parent" |
| 59 // (ancestor's unique names : #1--^ | #2-^ ) |
| 60 // ancestorChain example2: |
| 61 // "<!--framePath //foo/bar/<!--frame42-->-->/blah/foobar" |
| 62 // (ancestor's unique names: |
| 63 // ^--#1--^ | #2 | #3-^ ) |
| 64 // |
| 65 // newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber |
| 66 // "-->" |
| 67 // |
| 68 // framePosition ::= "-" numberOfSiblingsBeforeChild |
| 69 // [ framePosition-forParent? ] |
| 70 // |
| 71 // retryNumber ::= smallest non-negative integer resulting in unique name |
| 72 |
| 73 class UniqueNameHelper { |
| 74 public: |
| 75 explicit UniqueNameHelper(RenderFrameImpl* render_frame); |
| 76 ~UniqueNameHelper(); |
| 77 |
| 78 // Returns the generated unique name. |
| 79 const std::string& value() const { return unique_name_; } |
| 80 |
| 81 // Used to propagate an already calculated unique name. |
| 82 // |
| 83 // TODO(lukasza): It would be nice to assert uniqueness of the propagated |
| 84 // name here but: |
| 85 // 1) uniqueness is currently violated by provisional/old frame pairs. |
| 86 // 2) there is an unresolved race between 2 OOPIFs, that can result in a |
| 87 // non-unique unique name: see https://crbug.com/558680#c14. |
| 88 void set_propagated_name(const std::string& name) { unique_name_ = name; } |
| 89 |
| 90 // Note: when creating a new child frame, the unique name needs to be |
| 91 // calculated before the RenderFrameImpl is created. To avoid this chicken and |
| 92 // egg problem, this method is static, which means that |parent| needs to be |
| 93 // passed as a parameter. |
| 94 static std::string GenerateNameForNewChildFrame(blink::WebFrame* parent, |
| 95 const std::string& name); |
| 96 |
| 97 // Called after a browsing context name change to generate a new name. Note |
| 98 // that this should not be called if the frame is no longer displaying the |
| 99 // initial empty document, as unique name changes after that point will break |
| 100 // history navigations. See https://crbug.com/607205. |
| 101 void UpdateName(const std::string& name); |
| 102 |
| 103 private: |
| 104 blink::WebLocalFrame* GetWebFrame() const; |
| 105 |
| 106 RenderFrameImpl* const render_frame_; |
| 107 std::string unique_name_; |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(UniqueNameHelper); |
| 110 }; |
| 111 |
| 112 } // namespace content |
| 113 |
| 114 #endif // CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ |
OLD | NEW |