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"
11 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
17 namespace html_viewer
{
19 class HTMLDocumentOOPIF
;
22 // DocumentResourceWaiter waits for the necessary resources needed to load an
23 // HTMLDocument. Use IsReady() to determine when everything is available. Once
24 // ready it is assumed HTMLDocument will call back for the FrameTreeClient and
26 class DocumentResourceWaiter
: public mandoline::FrameTreeClient
{
28 DocumentResourceWaiter(GlobalState
* global_state
,
29 mojo::URLResponsePtr response
,
30 HTMLDocumentOOPIF
* document
);
31 ~DocumentResourceWaiter() override
;
33 // Releases all the resources that have been accumulated.
34 void Release(mojo::InterfaceRequest
<mandoline::FrameTreeClient
>*
35 frame_tree_client_request
,
36 mandoline::FrameTreeServerPtr
* frame_tree_server
,
37 mojo::Array
<mandoline::FrameDataPtr
>* frame_data
,
40 mojo::URLResponsePtr
ReleaseURLResponse();
42 // See class description.
45 void set_root(mojo::View
* root
) { root_
= root
; }
46 mojo::View
* root() { return root_
; }
48 void Bind(mojo::InterfaceRequest
<mandoline::FrameTreeClient
> request
);
51 // mandoline::FrameTreeClient:
52 void OnConnect(mandoline::FrameTreeServerPtr server
,
54 mojo::Array
<mandoline::FrameDataPtr
> frame_data
) override
;
55 void OnFrameAdded(uint32_t change_id
,
56 mandoline::FrameDataPtr frame_data
) override
;
57 void OnFrameRemoved(uint32_t change_id
, uint32_t frame_id
) override
;
58 void OnFrameClientPropertyChanged(uint32_t frame_id
,
59 const mojo::String
& name
,
60 mojo::Array
<uint8_t> new_value
) override
;
61 void OnPostMessageEvent(uint32_t source_frame_id
,
62 uint32_t target_frame_id
,
63 mandoline::HTMLMessageEventPtr event
) override
;
64 void OnWillNavigate(uint32_t target_frame_id
,
65 const OnWillNavigateCallback
& callback
) override
;
67 GlobalState
* global_state_
;
68 HTMLDocumentOOPIF
* document_
;
69 mojo::URLResponsePtr response_
;
71 mandoline::FrameTreeServerPtr server_
;
72 mojo::Array
<mandoline::FrameDataPtr
> frame_data_
;
75 // Once we get OnConnect() we unbind |frame_tree_client_binding_| and put it
77 mojo::InterfaceRequest
<mandoline::FrameTreeClient
> frame_tree_client_request_
;
78 mojo::Binding
<mandoline::FrameTreeClient
> frame_tree_client_binding_
;
80 DISALLOW_COPY_AND_ASSIGN(DocumentResourceWaiter
);
83 } // namespace html_viewer
85 #endif // COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_