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

Unified Diff: content/renderer/unique_name_helper.h

Issue 2714943004: Move unique name generation and tracking into //content. (Closed)
Patch Set: Revert back to original check in didUpdateName Created 3 years, 10 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
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..2bf6b931d9f1a7cc4db20c78e16f11f0037183a5
--- /dev/null
+++ b/content/renderer/unique_name_helper.h
@@ -0,0 +1,101 @@
+// 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.
+//
+// Description of the current unique name format
+// ---------------------------------------------
+//
+// Changing the format of unique name is undesirable, because it breaks
+// backcompatibility of session history (which stores unique names
+// generated in the past on user's disk). This incremental,
+// backcompatibility-aware approach has resulted so far in the following
+// rather baroque format... :
+//
+// uniqueName ::= <nullForMainFrame> | <assignedName> | <generatedName>
+// (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 (*before* the first
+// real commit - afterwards unique name stays immutable).
+//
+// generatedName ::= oldGeneratedName newUniqueSuffix?
+// (newUniqueSuffix is only present if oldGeneratedName was
+// not unique after all)
+//
+// oldGeneratedName ::= "<!--framePath //" ancestorChain
+// "/<!--frame" childCount "-->-->"
+// (oldGeneratedName is generated by
+// generateUniqueNameCandidate 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
+// ancestorChain example1: "grandparent/parent"
+// (ancestor's unique names : #1--^ | #2-^ )
+// ancestorChain example2:
+// "<!--framePath //foo/bar/<!--frame42-->-->/blah/foobar"
+// (ancestor's unique names:
+// ^--#1--^ | #2 | #3-^ )
+//
+// newUniqueSuffix ::= "<!--framePosition" framePosition "/" retryNumber
+// "-->"
+//
+// framePosition ::= "-" numberOfSiblingsBeforeChild
+// [ framePosition-forParent? ]
+//
+// retryNumber ::= smallest non-negative integer resulting in unique name
+
+#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;
+
+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
+ public:
+ explicit UniqueNameHelper(RenderFrameImpl* render_frame);
+ ~UniqueNameHelper();
+
+ const std::string& value() const { return unique_name_; }
+
+ // Used to propagate an already calculated unique name.
+ void set_propagated_name(const std::string& name) { unique_name_ = name; }
+
+ // Note: |parent| needs to be plumbed in for new child frames, since the
+ // unique name needs to be calculated before the new child RenderFrameImpl is
+ // created.
+ 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
+ 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_

Powered by Google App Engine
This is Rietveld 408576698