Make CacheStorageBlobToDiskCache cancel requests at RequestContextGetter deletion
[chromium-blink-merge.git] / mandoline / tab / frame.h
blobcd81d20c558dabf1f465c8e61c51b67d7d92d08d
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.
30 class Frame : public mojo::ViewObserver, public FrameTreeServer {
31 public:
32 Frame(FrameTree* tree,
33 mojo::View* view,
34 ViewOwnership view_ownership,
35 FrameTreeClient* frame_tree_client,
36 scoped_ptr<FrameUserData> user_data);
37 ~Frame() override;
39 void Init(Frame* parent);
41 // Walks the View tree starting at |view| going up returning the first
42 // Frame that is associated with a view. For example, if |view|
43 // has a Frame associated with it, then that is returned. Otherwise
44 // this checks view->parent() and so on.
45 static Frame* FindFirstFrameAncestor(mojo::View* view);
47 FrameTree* tree() { return tree_; }
49 Frame* parent() { return parent_; }
50 const Frame* parent() const { return parent_; }
52 mojo::View* view() { return view_; }
53 const mojo::View* view() const { return view_; }
55 // Finds the descendant with the specified id.
56 Frame* FindFrame(uint32_t id) {
57 return const_cast<Frame*>(const_cast<const Frame*>(this)->FindFrame(id));
59 const Frame* FindFrame(uint32_t id) const;
61 FrameUserData* user_data();
63 private:
64 friend class FrameTree;
66 // Adds this to |frames| and recurses through the children calling the
67 // same function.
68 void BuildFrameTree(std::vector<const Frame*>* frames) const;
70 void Add(Frame* node);
71 void Remove(Frame* node);
73 // Notifies the client and all descendants as appropriate.
74 void NotifyAdded(const Frame* source, const Frame* added_node);
75 void NotifyRemoved(const Frame* source, const Frame* removed_node);
77 // mojo::ViewObserver:
78 void OnViewDestroying(mojo::View* view) override;
80 // FrameTreeServer:
81 void PostMessageEventToFrame(uint32_t frame_id,
82 MessageEventPtr event) override;
83 void NavigateFrame(uint32_t frame_id) override;
84 void ReloadFrame(uint32_t frame_id) override;
86 FrameTree* const tree_;
87 mojo::View* view_;
88 Frame* parent_;
89 ViewOwnership view_ownership_;
90 std::vector<Frame*> children_;
91 scoped_ptr<FrameUserData> frame_user_data_;
93 FrameTreeClient* frame_tree_client_;
95 mojo::Binding<FrameTreeServer> frame_tree_server_binding_;
97 DISALLOW_COPY_AND_ASSIGN(Frame);
100 } // namespace mandoline
102 #endif // MANDOLINE_TAB_FRAME_H_