Web Replay: add methods to encode a frame's index based on its FrameTree position
authorburg@cs.washington.edu <burg@cs.washington.edu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Apr 2014 21:51:34 +0000 (21:51 +0000)
committerburg@cs.washington.edu <burg@cs.washington.edu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Apr 2014 21:51:34 +0000 (21:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131281

Reviewed by Timothy Hatcher.

Given a frame, its encoded index is computed by traversing the frame tree
and saving how many nodes have been traversed to reach a given frame.

This is used to disambiguate frames when dispatching frame-specific event
loop inputs during replay, such as timers and resource loaders.

* replay/SerializationMethods.cpp:
(WebCore::frameIndexFromDocument): Added.
(WebCore::frameIndexFromFrame): Added.
(WebCore::documentFromFrameIndex): Added.
(WebCore::frameFromFrameIndex): Added.
* replay/SerializationMethods.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@166856 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/replay/SerializationMethods.cpp
Source/WebCore/replay/SerializationMethods.h

index 2816b2fc7ba4ecdf8e728e295fede10d13ed2b3d..8277498b1585fe5fe1b1476e7e12ad2b5e48c2e9 100644 (file)
@@ -1,3 +1,23 @@
+2014-04-06  Brian J. Burg  <burg@cs.washington.edu>
+
+        Web Replay: add methods to encode a frame's index based on its FrameTree position
+        https://bugs.webkit.org/show_bug.cgi?id=131281
+
+        Reviewed by Timothy Hatcher.
+
+        Given a frame, its encoded index is computed by traversing the frame tree
+        and saving how many nodes have been traversed to reach a given frame.
+
+        This is used to disambiguate frames when dispatching frame-specific event
+        loop inputs during replay, such as timers and resource loaders.
+
+        * replay/SerializationMethods.cpp:
+        (WebCore::frameIndexFromDocument): Added.
+        (WebCore::frameIndexFromFrame): Added.
+        (WebCore::documentFromFrameIndex): Added.
+        (WebCore::frameFromFrameIndex): Added.
+        * replay/SerializationMethods.h:
+
 2014-04-06  Alexey Proskuryakov  <ap@apple.com>
 
         iOS build fix.
index 72645b35760a37e6611ef34317990803c456838f..179b412b69bc997c7f1e0382d1342eeba54fbb20 100644 (file)
 #if ENABLE(WEB_REPLAY)
 
 #include "AllReplayInputs.h"
+#include "Document.h"
+#include "Frame.h"
+#include "FrameTree.h"
+#include "MainFrame.h"
+#include "Page.h"
 #include "PlatformKeyboardEvent.h"
 #include "PlatformMouseEvent.h"
 #include "PlatformWheelEvent.h"
@@ -61,6 +66,51 @@ using WebCore::name; \
 WEB_REPLAY_INPUT_NAMES_FOR_EACH(IMPORT_FROM_WEBCORE_NAMESPACE)
 #undef IMPORT_FROM_WEBCORE_NAMESPACE
 
+namespace WebCore {
+
+unsigned long frameIndexFromDocument(const Document* document)
+{
+    ASSERT(document);
+    ASSERT(document->frame());
+    return frameIndexFromFrame(document->frame());
+}
+
+unsigned long frameIndexFromFrame(const Frame* targetFrame)
+{
+    ASSERT(targetFrame);
+
+    unsigned long currentIndex = 0;
+    const Frame* mainFrame = &targetFrame->tree().top();
+    for (const Frame* frame = mainFrame; frame; ++currentIndex, frame = frame->tree().traverseNext(mainFrame)) {
+        if (frame == targetFrame)
+            return currentIndex;
+    }
+
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+Document* documentFromFrameIndex(Page* page, unsigned long frameIndex)
+{
+    Frame* frame = frameFromFrameIndex(page, frameIndex);
+    return frame ? frame->document() : nullptr;
+}
+
+Frame* frameFromFrameIndex(Page* page, unsigned long frameIndex)
+{
+    ASSERT(page);
+    ASSERT(frameIndex >= 0);
+
+    MainFrame* mainFrame = &page->mainFrame();
+    Frame* frame = mainFrame;
+    unsigned long currentIndex = 0;
+    for (; currentIndex < frameIndex && frame; ++currentIndex, frame = frame->tree().traverseNext(mainFrame)) { }
+
+    return frame;
+}
+
+} // namespace WebCore
+
 #define ENCODE_TYPE_WITH_KEY(_encodedValue, _type, _key, _value) \
     _encodedValue.put<_type>(ASCIILiteral(#_key), _value)
 
index 37895e5a823d46d89eeac8532ac0dc2391a65fa0..f75ed8264de0161007e166414edd643d8af607ad 100644 (file)
@@ -35,6 +35,7 @@
 #include <wtf/Vector.h>
 
 namespace WebCore {
+
 class Document;
 class Frame;
 class Page;
@@ -47,6 +48,12 @@ class URL;
 #if USE(APPKIT)
 struct KeypressCommand;
 #endif
+
+unsigned long frameIndexFromDocument(const Document*);
+unsigned long frameIndexFromFrame(const Frame*);
+Document* documentFromFrameIndex(Page*, unsigned long frameIndex);
+Frame* frameFromFrameIndex(Page*, unsigned long frameIndex);
+
 } // namespace WebCore
 
 // Template specializations must be defined in the same namespace as the template declaration.