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/mus/public/cpp/view_observer.h"
11 #include "components/web_view/public/interfaces/frame.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
{
22 class HTMLFrameTreeManager
;
25 // DocumentResourceWaiter waits for the necessary resources needed to load an
26 // HTMLDocument. Once ready it calls to HTMLDocument::Load(). Once ready it is
27 // assumed HTMLDocument will call back for the FrameClient and FrameData.
28 class DocumentResourceWaiter
: public web_view::mojom::FrameClient
,
29 public HTMLFrameTreeManagerObserver
,
30 public mus::ViewObserver
{
32 DocumentResourceWaiter(GlobalState
* global_state
,
33 mojo::URLResponsePtr response
,
34 HTMLDocument
* document
);
35 ~DocumentResourceWaiter() override
;
37 // Releases all the resources that have been accumulated.
38 void Release(mojo::InterfaceRequest
<web_view::mojom::FrameClient
>*
40 web_view::mojom::FramePtr
* frame
,
41 mojo::Array
<web_view::mojom::FrameDataPtr
>* frame_data
,
44 web_view::mojom::ViewConnectType
* view_connect_type
,
45 OnConnectCallback
* on_connect_callback
);
47 uint32_t change_id() const { return change_id_
; }
49 mojo::URLResponsePtr
ReleaseURLResponse();
51 // See class description.
52 bool is_ready() const { return is_ready_
; }
54 void SetRoot(mus::View
* root
);
55 mus::View
* root() { return root_
; }
57 void Bind(mojo::InterfaceRequest
<web_view::mojom::FrameClient
> request
);
60 // Updates |is_ready_|, and if ready starts the Load() in the document.
63 // web_view::mojom::FrameClient:
64 void OnConnect(web_view::mojom::FramePtr frame
,
67 web_view::mojom::ViewConnectType view_connect_type
,
68 mojo::Array
<web_view::mojom::FrameDataPtr
> frame_data
,
69 const OnConnectCallback
& callback
) override
;
70 void OnFrameAdded(uint32_t change_id
,
71 web_view::mojom::FrameDataPtr frame_data
) override
;
72 void OnFrameRemoved(uint32_t change_id
, uint32_t frame_id
) override
;
73 void OnFrameClientPropertyChanged(uint32_t frame_id
,
74 const mojo::String
& name
,
75 mojo::Array
<uint8_t> new_value
) override
;
76 void OnPostMessageEvent(uint32_t source_frame_id
,
77 uint32_t target_frame_id
,
78 web_view::mojom::HTMLMessageEventPtr event
) override
;
79 void OnWillNavigate() override
;
80 void OnFrameLoadingStateChanged(uint32_t frame_id
, bool loading
) override
;
81 void OnDispatchFrameLoadEvent(uint32_t frame_id
) override
;
84 void OnViewViewportMetricsChanged(
86 const mojo::ViewportMetrics
& old_metrics
,
87 const mojo::ViewportMetrics
& new_metrics
) override
;
88 void OnViewDestroyed(mus::View
* view
) override
;
90 // HTMLFrameTreeManagerObserver:
91 void OnHTMLFrameTreeManagerChangeIdAdvanced() override
;
92 void OnHTMLFrameTreeManagerDestroyed() override
;
94 GlobalState
* global_state_
;
95 HTMLDocument
* document_
;
96 mojo::URLResponsePtr response_
;
98 web_view::mojom::FramePtr frame_
;
99 mojo::Array
<web_view::mojom::FrameDataPtr
> frame_data_
;
102 web_view::mojom::ViewConnectType view_connect_type_
;
103 OnConnectCallback on_connect_callback_
;
105 // Once we get OnConnect() we unbind |frame_client_binding_| and put it here.
106 mojo::InterfaceRequest
<web_view::mojom::FrameClient
> frame_client_request_
;
107 mojo::Binding
<web_view::mojom::FrameClient
> frame_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_