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_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
19 class ApplicationImpl
;
23 namespace html_viewer
{
25 class DocumentResourceWaiter
;
28 class HTMLFrameDelegate
;
30 // HTMLFrameTreeManager is responsible for managing the frames that comprise a
31 // document. Some of the frames may be remote. HTMLFrameTreeManager updates its
32 // state in response to changes from the FrameTreeServer, as well as changes
33 // from the underlying frames. The frame tree has at least one local frame
34 // that is backed by a mojo::View.
35 class HTMLFrameTreeManager
{
37 // Creates a new HTMLFrame. The caller owns the return value and must call
39 static HTMLFrame
* CreateFrameAndAttachToTree(
40 GlobalState
* global_state
,
41 mojo::ApplicationImpl
* app
,
43 scoped_ptr
<DocumentResourceWaiter
> resource_waiter
,
44 HTMLFrameDelegate
* delegate
);
46 GlobalState
* global_state() { return global_state_
; }
48 blink::WebView
* GetWebView();
51 friend class HTMLFrame
;
52 using TreeMap
= std::map
<uint32_t, HTMLFrameTreeManager
*>;
54 explicit HTMLFrameTreeManager(GlobalState
* global_state
);
55 ~HTMLFrameTreeManager();
57 void Init(HTMLFrameDelegate
* delegate
,
58 mojo::View
* local_view
,
59 const mojo::Array
<mandoline::FrameDataPtr
>& frame_data
);
61 // Creates a Frame per FrameData element in |frame_data|. Returns the root.
62 HTMLFrame
* BuildFrameTree(
63 HTMLFrameDelegate
* delegate
,
64 const mojo::Array
<mandoline::FrameDataPtr
>& frame_data
,
65 uint32_t local_frame_id
,
66 mojo::View
* local_view
);
68 // Returns this HTMLFrameTreeManager from |instances_|.
69 void RemoveFromInstances();
71 // Invoked when a Frame is destroyed.
72 void OnFrameDestroyed(HTMLFrame
* frame
);
74 // Each HTMLFrame delegates FrameTreeClient methods to the
75 // HTMLFrameTreeManager the frame is in. HTMLFrameTreeManager only responds
76 // to changes from the |local_root_| (this is because each FrameTreeClient
77 // sees the same change, and a change only need be processed once).
78 void ProcessOnFrameAdded(HTMLFrame
* source
,
79 mandoline::FrameDataPtr frame_data
);
80 void ProcessOnFrameRemoved(HTMLFrame
* source
, uint32_t frame_id
);
81 void ProcessOnFrameClientPropertyChanged(HTMLFrame
* source
,
83 const mojo::String
& name
,
84 mojo::Array
<uint8_t> new_data
);
86 static TreeMap
* instances_
;
88 GlobalState
* global_state_
;
92 // The |local_root_| is the HTMLFrame that is the highest frame that is
94 HTMLFrame
* local_root_
;
96 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTreeManager
);
99 } // namespace html_viewer
101 #endif // COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_