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_DOCUMENT_RESOURCE_WAITER_H_
6 #define COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_
8 #include "base/basictypes.h"
9 #include "mandoline/tab/public/interfaces/frame_tree.mojom.h"
10 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
16 namespace html_viewer
{
18 class HTMLDocumentOOPIF
;
21 // DocumentResourceWaiter waits for the necessary resources needed to load an
22 // HTMLDocument. Use IsReady() to determine when everything is available. Once
23 // ready it is assumed HTMLDocument will call back for the FrameTreeClient and
25 class DocumentResourceWaiter
: public mandoline::FrameTreeClient
{
27 DocumentResourceWaiter(GlobalState
* global_state
,
28 mojo::URLResponsePtr response
,
29 HTMLDocumentOOPIF
* document
);
30 ~DocumentResourceWaiter() override
;
32 // Releases all the resources that have been accumulated.
33 void Release(mojo::InterfaceRequest
<mandoline::FrameTreeClient
>*
34 frame_tree_client_request
,
35 mandoline::FrameTreeServerPtr
* frame_tree_server
,
36 mojo::Array
<mandoline::FrameDataPtr
>* frame_data
,
37 mojo::URLResponsePtr
* response
);
39 // See class description.
42 void set_root(mojo::View
* root
) { root_
= root
; }
43 mojo::View
* root() { return root_
; }
45 void Bind(mojo::InterfaceRequest
<mandoline::FrameTreeClient
> request
);
48 // mandoline::FrameTreeClient:
49 void OnConnect(mandoline::FrameTreeServerPtr server
,
50 mojo::Array
<mandoline::FrameDataPtr
> frame_data
) override
;
51 void OnFrameAdded(mandoline::FrameDataPtr frame_data
) override
;
52 void OnFrameRemoved(uint32_t frame_id
) override
;
54 GlobalState
* global_state_
;
55 HTMLDocumentOOPIF
* document_
;
56 mojo::URLResponsePtr response_
;
58 mandoline::FrameTreeServerPtr server_
;
59 mojo::Array
<mandoline::FrameDataPtr
> frame_data_
;
61 // Once we get OnConnect() we unbind |frame_tree_client_binding_| and put it
63 mojo::InterfaceRequest
<mandoline::FrameTreeClient
> frame_tree_client_request_
;
64 mojo::Binding
<mandoline::FrameTreeClient
> frame_tree_client_binding_
;
66 DISALLOW_COPY_AND_ASSIGN(DocumentResourceWaiter
);
69 } // namespace html_viewer
71 #endif // COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_