Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / html_viewer / html_frame_tree_manager.h
blob12e86d629f0dabbf5131d08d34de15161683f68a
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 COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_
6 #define COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_
8 #include <map>
9 #include <set>
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
16 namespace blink {
17 class WebView;
20 namespace mojo {
21 class View;
24 namespace html_viewer {
26 class DocumentResourceWaiter;
27 class GlobalState;
28 class HTMLFrame;
29 class HTMLFrameDelegate;
31 // HTMLFrameTreeManager is responsible for managing the frames that comprise a
32 // document. Some of the frames may be remote. HTMLFrameTreeManager updates its
33 // state in response to changes from the FrameTreeServer, as well as changes
34 // from the underlying frames. The frame tree has at least one local frame
35 // that is backed by a mojo::View.
36 class HTMLFrameTreeManager {
37 public:
38 // Returns a new HTMLFrame or null if a HTMLFrame does not need to be created.
39 // If this returns non-null the caller owns the return value and must call
40 // Close() when done.
41 static HTMLFrame* CreateFrameAndAttachToTree(
42 GlobalState* global_state,
43 mojo::View* view,
44 scoped_ptr<DocumentResourceWaiter> resource_waiter,
45 HTMLFrameDelegate* delegate);
47 GlobalState* global_state() { return global_state_; }
49 blink::WebView* GetWebView();
51 private:
52 friend class HTMLFrame;
53 using TreeMap = std::map<uint32_t, HTMLFrameTreeManager*>;
54 using ChangeIDSet = std::set<uint32_t>;
56 explicit HTMLFrameTreeManager(GlobalState* global_state);
57 ~HTMLFrameTreeManager();
59 void Init(HTMLFrameDelegate* delegate,
60 mojo::View* local_view,
61 const mojo::Array<mandoline::FrameDataPtr>& frame_data,
62 uint32_t change_id);
64 // Creates a Frame per FrameData element in |frame_data|. Returns the root.
65 HTMLFrame* BuildFrameTree(
66 HTMLFrameDelegate* delegate,
67 const mojo::Array<mandoline::FrameDataPtr>& frame_data,
68 uint32_t local_frame_id,
69 mojo::View* local_view);
71 // Returns this HTMLFrameTreeManager from |instances_|.
72 void RemoveFromInstances();
74 // Invoked when a Frame is destroyed.
75 void OnFrameDestroyed(HTMLFrame* frame);
77 // Call before applying a structure change from the server. |source| is the
78 // the source of the change, and |change_id| the id from the server. Returns
79 // true if the change should be applied, false otherwise.
80 bool PrepareForStructureChange(HTMLFrame* source, uint32_t change_id);
82 // Each HTMLFrame delegates FrameTreeClient methods to the
83 // HTMLFrameTreeManager the frame is in. HTMLFrameTreeManager only responds
84 // to changes from the |local_root_| (this is because each FrameTreeClient
85 // sees the same change, and a change only need be processed once).
86 void ProcessOnFrameAdded(HTMLFrame* source,
87 uint32_t change_id,
88 mandoline::FrameDataPtr frame_data);
89 void ProcessOnFrameRemoved(HTMLFrame* source,
90 uint32_t change_id,
91 uint32_t frame_id);
92 void ProcessOnFrameClientPropertyChanged(HTMLFrame* source,
93 uint32_t frame_id,
94 const mojo::String& name,
95 mojo::Array<uint8_t> new_data);
97 static TreeMap* instances_;
99 GlobalState* global_state_;
101 HTMLFrame* root_;
103 // The |local_root_| is the HTMLFrame that is the highest frame that is
104 // local.
105 HTMLFrame* local_root_;
107 uint32_t change_id_;
109 // When a frame is locally removed the id is added here. When the server
110 // notifies us we remove from this set. This is done to ensure an add/remove
111 // followed by notification from the server doesn't attempt to add the frame
112 // back that was locally removed.
113 ChangeIDSet pending_remove_ids_;
115 // If true, we're in ProcessOnFrameRemoved().
116 bool in_process_on_frame_removed_;
118 base::WeakPtrFactory<HTMLFrameTreeManager> weak_factory_;
120 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTreeManager);
123 } // namespace html_viewer
125 #endif // COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_