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 "components/html_viewer/html_frame_tree_manager_observer.h"
10 #include "components/view_manager/public/cpp/view_observer.h"
11 #include "components/web_view/public/interfaces/frame_tree.mojom.h"
12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
19 namespace html_viewer
{
21 class HTMLDocumentOOPIF
;
22 class HTMLFrameTreeManager
;
25 // DocumentResourceWaiter waits for the necessary resources needed to load an
26 // HTMLDocument. Once ready it calls to HTMLDocumentOOPIF::Load(). Once
27 // ready it is assumed HTMLDocument will call back for the FrameTreeClient and
29 class DocumentResourceWaiter
: public web_view::FrameTreeClient
,
30 public HTMLFrameTreeManagerObserver
,
31 public mojo::ViewObserver
{
33 DocumentResourceWaiter(GlobalState
* global_state
,
34 mojo::URLResponsePtr response
,
35 HTMLDocumentOOPIF
* document
);
36 ~DocumentResourceWaiter() override
;
38 // Releases all the resources that have been accumulated.
39 void Release(mojo::InterfaceRequest
<web_view::FrameTreeClient
>*
40 frame_tree_client_request
,
41 web_view::FrameTreeServerPtr
* frame_tree_server
,
42 mojo::Array
<web_view::FrameDataPtr
>* frame_data
,
45 web_view::ViewConnectType
* view_connect_type
,
46 OnConnectCallback
* on_connect_callback
);
48 uint32_t change_id() const { return change_id_
; }
50 mojo::URLResponsePtr
ReleaseURLResponse();
52 // See class description.
53 bool is_ready() const { return is_ready_
; }
55 void SetRoot(mojo::View
* root
);
56 mojo::View
* root() { return root_
; }
58 void Bind(mojo::InterfaceRequest
<web_view::FrameTreeClient
> request
);
61 // Updates |is_ready_|, and if ready starts the Load() in the document.
64 // web_view::FrameTreeClient:
65 void OnConnect(web_view::FrameTreeServerPtr server
,
68 web_view::ViewConnectType view_connect_type
,
69 mojo::Array
<web_view::FrameDataPtr
> frame_data
,
70 const OnConnectCallback
& callback
) override
;
71 void OnFrameAdded(uint32_t change_id
,
72 web_view::FrameDataPtr frame_data
) override
;
73 void OnFrameRemoved(uint32_t change_id
, uint32_t frame_id
) override
;
74 void OnFrameClientPropertyChanged(uint32_t frame_id
,
75 const mojo::String
& name
,
76 mojo::Array
<uint8_t> new_value
) override
;
77 void OnPostMessageEvent(uint32_t source_frame_id
,
78 uint32_t target_frame_id
,
79 web_view::HTMLMessageEventPtr event
) override
;
80 void OnWillNavigate(uint32_t target_frame_id
) override
;
83 void OnViewViewportMetricsChanged(
85 const mojo::ViewportMetrics
& old_metrics
,
86 const mojo::ViewportMetrics
& new_metrics
) override
;
87 void OnViewDestroyed(mojo::View
* view
) override
;
89 // HTMLFrameTreeManagerObserver:
90 void OnHTMLFrameTreeManagerChangeIdAdvanced() override
;
91 void OnHTMLFrameTreeManagerDestroyed() override
;
93 GlobalState
* global_state_
;
94 HTMLDocumentOOPIF
* document_
;
95 mojo::URLResponsePtr response_
;
97 web_view::FrameTreeServerPtr server_
;
98 mojo::Array
<web_view::FrameDataPtr
> frame_data_
;
101 web_view::ViewConnectType view_connect_type_
;
102 OnConnectCallback on_connect_callback_
;
104 // Once we get OnConnect() we unbind |frame_tree_client_binding_| and put it
106 mojo::InterfaceRequest
<web_view::FrameTreeClient
> frame_tree_client_request_
;
107 mojo::Binding
<web_view::FrameTreeClient
> frame_tree_client_binding_
;
111 // See comments in UpdateIsReady() for details of this.
113 // While |waiting_for_change_id_| is true DocumentResourceWaiter is an
114 // HTMLFrameTreeManagerObserver on |target_frame_tree_|.
115 bool waiting_for_change_id_
;
117 HTMLFrameTreeManager
* target_frame_tree_
;
119 DISALLOW_COPY_AND_ASSIGN(DocumentResourceWaiter
);
122 } // namespace html_viewer
124 #endif // COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_