Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / mandoline / tab / frame.h
blob5b87f6bc72f23c16453dd1d4a350be18f5385440
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MANDOLINE_TAB_FRAME_H_
6 #define MANDOLINE_TAB_FRAME_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/view_manager/public/cpp/view_observer.h"
13 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
16 namespace mandoline {
18 class FrameTree;
19 class FrameTreeClient;
20 class FrameUserData;
22 enum class ViewOwnership {
23 OWNS_VIEW,
24 DOESNT_OWN_VIEW,
27 // Frame represents an embedding in a frame. Frames own their children.
28 // Frames automatically delete themself if the View the frame is associated
29 // with is deleted.
31 // In general each Frame has a View. When a new Frame is created by a client
32 // there may be a small amount of time where the View is not yet known to us
33 // (separate pipes are used for the view and frame, resulting in undefined
34 // message ordering). In this case the view is null and will be set once we
35 // see the view (OnTreeChanged()).
37 // When the FrameTreeClient creates a new Frame there is no associated
38 // FrameTreeClient for the child Frame.
39 class Frame : public mojo::ViewObserver, public FrameTreeServer {
40 public:
41 Frame(FrameTree* tree,
42 mojo::View* view,
43 uint32_t id,
44 ViewOwnership view_ownership,
45 FrameTreeClient* frame_tree_client,
46 scoped_ptr<FrameUserData> user_data);
47 ~Frame() override;
49 void Init(Frame* parent);
51 // Deletes the children and initializes the new FrameTreeClient.
52 void Swap(FrameTreeClient* frame_tree_client,
53 scoped_ptr<FrameUserData> user_data);
55 // Walks the View tree starting at |view| going up returning the first
56 // Frame that is associated with |view|. For example, if |view|
57 // has a Frame associated with it, then that is returned. Otherwise
58 // this checks view->parent() and so on.
59 static Frame* FindFirstFrameAncestor(mojo::View* view);
61 FrameTree* tree() { return tree_; }
63 Frame* parent() { return parent_; }
64 const Frame* parent() const { return parent_; }
66 mojo::View* view() { return view_; }
67 const mojo::View* view() const { return view_; }
69 uint32_t id() const { return id_; }
71 // Finds the descendant with the specified id.
72 Frame* FindFrame(uint32_t id) {
73 return const_cast<Frame*>(const_cast<const Frame*>(this)->FindFrame(id));
75 const Frame* FindFrame(uint32_t id) const;
77 bool HasAncestor(const Frame* frame) const;
79 FrameUserData* user_data() { return user_data_.get(); }
81 const std::vector<Frame*>& children() { return children_; }
83 const mojo::String& name() const { return name_; }
85 // Returns true if this Frame or any child Frame is loading.
86 bool IsLoading() const;
88 // Returns the sum total of loading progress from this Frame and all of its
89 // children, as well as the number of Frames accumulated.
90 double GatherProgress(int* frame_count) const;
92 private:
93 friend class FrameTree;
95 // Initializes the client by sending it the state of the tree.
96 void InitClient();
98 void SetView(mojo::View* view);
100 // Adds this to |frames| and recurses through the children calling the
101 // same function.
102 void BuildFrameTree(std::vector<const Frame*>* frames) const;
104 void Add(Frame* node);
105 void Remove(Frame* node);
107 // The implementation of the various FrameTreeServer functions that take
108 // frame_id call into these.
109 void LoadingStartedImpl();
110 void LoadingStoppedImpl();
111 void ProgressChangedImpl(double progress);
112 void SetFrameNameImpl(const mojo::String& name);
114 // Returns the Frame whose id is |frame_id|. Returns nullptr if |frame_id| is
115 // not from the same connection as this.
116 Frame* FindTargetFrame(uint32_t frame_id);
118 // Notifies the client and all descendants as appropriate.
119 void NotifyAdded(const Frame* source, const Frame* added_node);
120 void NotifyRemoved(const Frame* source, const Frame* removed_node);
121 void NotifyFrameNameChanged(const Frame* source);
123 // mojo::ViewObserver:
124 void OnTreeChanged(const TreeChangeParams& params) override;
125 void OnViewDestroying(mojo::View* view) override;
127 // FrameTreeServer:
128 void PostMessageEventToFrame(uint32_t frame_id,
129 MessageEventPtr event) override;
130 void LoadingStarted(uint32_t frame_id) override;
131 void LoadingStopped(uint32_t frame_id) override;
132 void ProgressChanged(uint32_t frame_id, double progress) override;
133 void SetFrameName(uint32_t frame_id, const mojo::String& name) override;
134 void OnCreatedFrame(uint32_t parent_id, uint32_t frame_id) override;
135 void RequestNavigate(uint32_t frame_id,
136 NavigationTarget target,
137 mojo::URLRequestPtr request) override;
138 void DidNavigateLocally(uint32_t frame_id, const mojo::String& url) override;
140 FrameTree* const tree_;
141 // WARNING: this may be null. See class description for details.
142 mojo::View* view_;
143 const uint32_t id_;
144 Frame* parent_;
145 ViewOwnership view_ownership_;
146 std::vector<Frame*> children_;
147 scoped_ptr<FrameUserData> user_data_;
149 // WARNING: this may be null. See class description for details.
150 FrameTreeClient* frame_tree_client_;
152 bool loading_;
153 double progress_;
155 mojo::String name_;
157 mojo::Binding<FrameTreeServer> frame_tree_server_binding_;
159 DISALLOW_COPY_AND_ASSIGN(Frame);
162 } // namespace mandoline
164 #endif // MANDOLINE_TAB_FRAME_H_