Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | 5 #ifndef CONTENT_COMMON_UNIQUE_NAME_HELPER_H_ |
| 6 #define CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | 6 #define CONTENT_COMMON_UNIQUE_NAME_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 | 12 #include "base/strings/string_piece.h" |
| 12 namespace blink { | |
| 13 class WebFrame; | |
| 14 class WebLocalFrame; | |
| 15 } // namespace blink | |
| 16 | 13 |
| 17 namespace content { | 14 namespace content { |
| 18 | 15 |
| 19 class RenderFrameImpl; | |
| 20 | |
| 21 // Frame helper that manages the details of generating a quasi-stable unique | 16 // 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: | 17 // name for the frame. The name is unique within a page, and is used for: |
| 23 // - matching up session history items with recreated frames | 18 // - matching up session history items with recreated frames |
| 24 // - layout test results | 19 // - layout test results |
| 25 // | 20 // |
| 26 // Description of the current unique name format | 21 // Description of the current unique name format |
| 27 // --------------------------------------------- | 22 // --------------------------------------------- |
| 28 // Changing the format of unique name has a high cost, because it breaks | 23 // Changing the format of unique name has a high cost, because it breaks |
| 29 // backwards compatibility of session history (which stores unique names | 24 // 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 | 25 // generated in the past on user's disk). The evolution of unique name in a |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 // | #1 | #2 | #3 | | 59 // | #1 | #2 | #3 | |
| 65 // | 60 // |
| 66 // newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber "-->" | 61 // newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber "-->" |
| 67 // | 62 // |
| 68 // framePosition ::= "-" numberOfSiblingsBeforeChild | 63 // framePosition ::= "-" numberOfSiblingsBeforeChild |
| 69 // [ framePosition-forParent? ] | 64 // [ framePosition-forParent? ] |
| 70 // | 65 // |
| 71 // retryNumber ::= smallest non-negative integer resulting in unique name | 66 // retryNumber ::= smallest non-negative integer resulting in unique name |
| 72 class UniqueNameHelper { | 67 class UniqueNameHelper { |
| 73 public: | 68 public: |
| 74 explicit UniqueNameHelper(RenderFrameImpl* render_frame); | 69 // Adapter class so UniqueNameHelper can be used with both RenderFrameImpl and |
| 70 // ExplodedFrameState. | |
| 71 class FrameAdapter { | |
| 72 public: | |
| 73 FrameAdapter() {} | |
| 74 virtual ~FrameAdapter(); | |
| 75 | |
| 76 virtual bool IsMainFrame() const = 0; | |
| 77 virtual bool IsCandidateUnique(const std::string& name) const = 0; | |
| 78 virtual int GetSiblingCount() const = 0; | |
| 79 virtual int GetChildCount() const = 0; | |
| 80 // Sets the reference point for iterations that walk up the frame tree. | |
| 81 enum class BeginPoint { | |
| 82 // This should be the default: it indicates the logical iteration | |
| 83 // operation began on the current frame of this adapter and the walking | |
| 84 // logic should retrieve the parent frame as normal. | |
| 85 kParentFrame, | |
| 86 // For implementing the pending child frame adapter, which delegates to | |
| 87 // its future parent's FrameAdapter. Walking up the tree should not skip | |
| 88 // the currrent frame associated with this adapter; instead it should | |
| 89 // treat the adapter's current frame as the parent, as the logical | |
| 90 // iteration began with the pending child. | |
| 91 kThisFrame, | |
| 92 }; | |
| 93 // Returns a vector of the names of ancestor frames, ordered from root down. | |
| 94 // |begin_point| indicates the reference point for starting the collection, | |
| 95 // and |should_stop| is a boolean predicate that indicates when to stop | |
| 96 // collection of names. | |
| 97 virtual std::vector<base::StringPiece> CollectAncestorNames( | |
| 98 BeginPoint begin_point, | |
| 99 bool (*should_stop)(base::StringPiece)) const = 0; | |
| 100 // Returns a vector of ints representing the child index of each frame in | |
| 101 // the chain from this frame to the root (note that this order is opposite | |
| 102 // to that of CollectAncestorNames). | |
| 103 virtual std::vector<int> GetFramePosition(BeginPoint begin_point) const = 0; | |
| 104 | |
| 105 private: | |
| 106 DISALLOW_COPY_AND_ASSIGN(FrameAdapter); | |
| 107 }; | |
| 108 | |
| 109 explicit UniqueNameHelper(FrameAdapter* frame); | |
| 75 ~UniqueNameHelper(); | 110 ~UniqueNameHelper(); |
| 76 | 111 |
| 77 // Returns the generated unique name. | 112 // Returns the generated unique name. |
| 78 const std::string& value() const { return unique_name_; } | 113 const std::string& value() const { return unique_name_; } |
| 79 | 114 |
| 80 // Used to propagate an already calculated unique name. | 115 // Used to propagate an already calculated unique name. |
| 81 // | 116 // |
| 82 // TODO(lukasza): It would be nice to assert uniqueness of the propagated | 117 // TODO(lukasza): It would be nice to assert uniqueness of the propagated |
| 83 // name here but: | 118 // name here but: |
| 84 // 1) uniqueness is currently violated by provisional/old frame pairs. | 119 // 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 | 120 // 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. | 121 // non-unique unique name: see https://crbug.com/558680#c14. |
| 87 void set_propagated_name(const std::string& name) { unique_name_ = name; } | 122 void set_propagated_name(const std::string& name) { unique_name_ = name; } |
| 88 | 123 |
| 89 // Note: when creating a new child frame, the unique name needs to be | 124 // 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 | 125 // calculated before the child frame is created. To avoid this chicken and |
| 91 // egg problem, this method is static, which means that |parent| needs to be | 126 // egg problem, this method is designed to be call on the *parent* frame of |
|
Łukasz Anforowicz
2017/05/25 16:48:49
nit: s/call/called/ ?
dcheng
2017/05/25 18:25:03
Done.
| |
| 92 // passed as a parameter. | 127 // the future new child frame and return the value the new child frame should |
| 93 static std::string GenerateNameForNewChildFrame(blink::WebFrame* parent, | 128 // use. |
| 94 const std::string& name); | 129 std::string GenerateNameForNewChildFrame(const std::string& name) const; |
| 95 | 130 |
| 96 // Called after a browsing context name change to generate a new name. Note | 131 // 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 | 132 // 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 | 133 // initial empty document, as unique name changes after that point will break |
| 99 // history navigations. See https://crbug.com/607205. | 134 // history navigations. See https://crbug.com/607205. |
| 100 void UpdateName(const std::string& name); | 135 void UpdateName(const std::string& name); |
| 101 | 136 |
| 102 private: | 137 private: |
| 103 blink::WebLocalFrame* GetWebFrame() const; | 138 FrameAdapter* const frame_; |
| 104 | |
| 105 RenderFrameImpl* const render_frame_; | |
| 106 std::string unique_name_; | 139 std::string unique_name_; |
| 107 | 140 |
| 108 DISALLOW_COPY_AND_ASSIGN(UniqueNameHelper); | 141 DISALLOW_COPY_AND_ASSIGN(UniqueNameHelper); |
| 109 }; | 142 }; |
| 110 | 143 |
| 111 } // namespace content | 144 } // namespace content |
| 112 | 145 |
| 113 #endif // CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_ | 146 #endif // CONTENT_COMMON_UNIQUE_NAME_HELPER_H_ |
| OLD | NEW |