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

Unified Diff: content/renderer/unique_name_helper.h

Issue 2714943004: Move unique name generation and tracking into //content. (Closed)
Patch Set: Rebase again. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/render_view_browsertest.cc ('k') | content/renderer/unique_name_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/unique_name_helper.h
diff --git a/content/renderer/unique_name_helper.h b/content/renderer/unique_name_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..db8beb6f7ffa1d60f99a0a893f26303c142c295e
--- /dev/null
+++ b/content/renderer/unique_name_helper.h
@@ -0,0 +1,113 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_
+#define CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_
+
+#include <string>
+
+#include "base/macros.h"
+
+namespace blink {
+class WebFrame;
+class WebLocalFrame;
+} // namespace blink
+
+namespace content {
+
+class RenderFrameImpl;
+
+// Frame helper that manages the details of generating a quasi-stable unique
+// name for the frame. The name is unique within a page, and is used for:
+// - matching up session history items with recreated frames
+// - layout test results
+//
+// Description of the current unique name format
+// ---------------------------------------------
+// Changing the format of unique name has a high cost, because it breaks
+// backwards compatibility of session history (which stores unique names
+// generated in the past on user's disk). The evolution of unique name in a
+// mostly backwards-compatible way has resulted in the rather baroque format...
+//
+// uniqueName ::= <nullForMainFrame> | <assignedName> | <generatedName>
+// Note: generatedName is used if assignedName is non-unique / conflicts with
+// other frame's unique name.
+//
+// assignedName ::= value of iframe's name attribute
+// or value assigned to window.name
+// Note: The name must be assigned *before* the first real commit: afterwards,
+// the unique name is immutable.
+//
+// generatedName ::= oldGeneratedName newUniqueSuffix?
+// Note: newUniqueSuffix is only present if oldGeneratedName is not unique.
+//
+// oldGeneratedName ::= "<!--framePath //" ancestorChain
+// "/<!--frame" childCount "-->-->"
+// Note: oldGeneratedName is generated by the internal GenerateCandidate()
+// method.
+//
+// childCount ::= current number of siblings
+//
+// ancestorChain ::= concatenated unique names of ancestor chain,
+// terminated on the first ancestor (if any) starting with
+// "<!--framePath"; each ancestor's unique name is
+// separated by "/" character
+// Note: Two examples are provided below, with each portion of the name from a
+// distinct ancestor annotated.
+//
+// Example ancestor chain #1:
+// "grandparent/parent"
+// | #1 | #2 |
+// Example ancestor chain #2:
+// "<!--framePath //foo/bar/<!--frame42-->-->/blah/foobar"
+// | #1 | #2 | #3 |
+//
+// newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber "-->"
+//
+// framePosition ::= "-" numberOfSiblingsBeforeChild
+// [ framePosition-forParent? ]
+//
+// retryNumber ::= smallest non-negative integer resulting in unique name
+class UniqueNameHelper {
+ public:
+ explicit UniqueNameHelper(RenderFrameImpl* render_frame);
+ ~UniqueNameHelper();
+
+ // Returns the generated unique name.
+ const std::string& value() const { return unique_name_; }
+
+ // Used to propagate an already calculated unique name.
+ //
+ // TODO(lukasza): It would be nice to assert uniqueness of the propagated
+ // name here but:
+ // 1) uniqueness is currently violated by provisional/old frame pairs.
+ // 2) there is an unresolved race between 2 OOPIFs, that can result in a
+ // non-unique unique name: see https://crbug.com/558680#c14.
+ void set_propagated_name(const std::string& name) { unique_name_ = name; }
+
+ // Note: when creating a new child frame, the unique name needs to be
+ // calculated before the RenderFrameImpl is created. To avoid this chicken and
+ // egg problem, this method is static, which means that |parent| needs to be
+ // passed as a parameter.
+ static std::string GenerateNameForNewChildFrame(blink::WebFrame* parent,
+ const std::string& name);
+
+ // Called after a browsing context name change to generate a new name. Note
+ // that this should not be called if the frame is no longer displaying the
+ // initial empty document, as unique name changes after that point will break
+ // history navigations. See https://crbug.com/607205.
+ void UpdateName(const std::string& name);
+
+ private:
+ blink::WebLocalFrame* GetWebFrame() const;
+
+ RenderFrameImpl* const render_frame_;
+ std::string unique_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(UniqueNameHelper);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_UNIQUE_NAME_HELPER_H_
« no previous file with comments | « content/renderer/render_view_browsertest.cc ('k') | content/renderer/unique_name_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698