summaryrefslogtreecommitdiffstats
path: root/mandoline/tab/frame_tree.h
blob: 4422a2bb738e84044514684eba8979c14925e0be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2015 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 MANDOLINE_TAB_FRAME_TREE_H_
#define MANDOLINE_TAB_FRAME_TREE_H_

#include "mandoline/tab/frame.h"
#include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"

namespace mojo {
class String;
}

namespace mandoline {

class FrameTreeClient;
class FrameTreeDelegate;
class FrameUserData;

// FrameTree manages the set of Frames that comprise a single url. FrameTree
// owns the root Frame and each Frame owns its children. Frames are
// automatically deleted and removed from the tree if the corresponding view is
// deleted. This happens if the creator of the view deletes it (say an iframe is
// destroyed).
class FrameTree {
 public:
  // |view| is the view to do the initial embedding in. It is assumed |view|
  // outlives FrameTree.
  FrameTree(mojo::View* view,
            FrameTreeDelegate* delegate,
            FrameTreeClient* root_client,
            scoped_ptr<FrameUserData> user_data);
  ~FrameTree();

  Frame* root() { return &root_; }

  uint32_t change_id() const { return change_id_; }

  Frame* CreateAndAddFrame(mojo::View* view,
                           Frame* parent,
                           FrameTreeClient* client,
                           scoped_ptr<FrameUserData> user_data);

  // If frame->view() == |view|, then all of |frame|'s children are destroyed
  // and |frame| is reused. Otherwise a new Frame is created as a child of
  // |frame|. It is expected this is called from
  // ViewManagerDelegate::OnEmbedForDescendant().
  Frame* CreateOrReplaceFrame(Frame* frame,
                              mojo::View* view,
                              FrameTreeClient* frame_tree_client,
                              scoped_ptr<FrameUserData> user_data);

  // Creates a new Frame parented to |parent|. The Frame is considered shared in
  // that it is sharing the FrameTreeClient/FrameTreeServer of |parent|. There
  // may or may not be a View identified by |frame_id| yet. See Frame for
  // details.
  void CreateSharedFrame(Frame* parent,
                         uint32_t frame_id,
                         const Frame::ClientPropertyMap& client_properties);

 private:
  friend class Frame;

  // Increments the change id, returning the new value.
  uint32_t AdvanceChangeID();

  Frame* CreateAndAddFrameImpl(
      mojo::View* view,
      uint32_t frame_id,
      Frame* parent,
      FrameTreeClient* client,
      scoped_ptr<FrameUserData> user_data,
      const Frame::ClientPropertyMap& client_properties);

  void LoadingStateChanged();
  void ProgressChanged();
  void ClientPropertyChanged(const Frame* source,
                             const mojo::String& name,
                             const mojo::Array<uint8_t>& value);

  mojo::View* view_;

  FrameTreeDelegate* delegate_;

  Frame root_;

  double progress_;

  uint32_t change_id_;

  DISALLOW_COPY_AND_ASSIGN(FrameTree);
};

}  // namespace mandoline

#endif  // MANDOLINE_TAB_FRAME_TREE_H_