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 #include "components/html_viewer/document_resource_waiter.h"
7 #include "components/html_viewer/global_state.h"
8 #include "components/html_viewer/html_document_oopif.h"
9 #include "components/html_viewer/html_frame_tree_manager.h"
10 #include "components/view_manager/public/cpp/view.h"
12 namespace html_viewer
{
14 DocumentResourceWaiter::DocumentResourceWaiter(GlobalState
* global_state
,
15 mojo::URLResponsePtr response
,
16 HTMLDocumentOOPIF
* document
)
17 : global_state_(global_state
),
19 response_(response
.Pass()),
21 frame_tree_client_binding_(this) {
24 DocumentResourceWaiter::~DocumentResourceWaiter() {
27 void DocumentResourceWaiter::Release(
28 mojo::InterfaceRequest
<mandoline::FrameTreeClient
>*
29 frame_tree_client_request
,
30 mandoline::FrameTreeServerPtr
* frame_tree_server
,
31 mojo::Array
<mandoline::FrameDataPtr
>* frame_data
) {
33 *frame_tree_client_request
= frame_tree_client_request_
.Pass();
34 *frame_tree_server
= server_
.Pass();
35 *frame_data
= frame_data_
.Pass();
38 mojo::URLResponsePtr
DocumentResourceWaiter::ReleaseURLResponse() {
39 return response_
.Pass();
42 bool DocumentResourceWaiter::IsReady() const {
43 return root_
&& root_
->viewport_metrics().device_pixel_ratio
!= 0.0f
&&
44 !frame_data_
.is_null();
47 void DocumentResourceWaiter::Bind(
48 mojo::InterfaceRequest
<mandoline::FrameTreeClient
> request
) {
49 if (frame_tree_client_binding_
.is_bound() || !frame_data_
.is_null()) {
50 DVLOG(1) << "Request for FrameTreeClient after already supplied one";
53 frame_tree_client_binding_
.Bind(request
.Pass());
56 void DocumentResourceWaiter::OnConnect(
57 mandoline::FrameTreeServerPtr server
,
58 mojo::Array
<mandoline::FrameDataPtr
> frame_data
) {
59 DCHECK(frame_data_
.is_null());
60 server_
= server
.Pass();
61 frame_data_
= frame_data
.Pass();
62 CHECK(frame_data_
.size() > 0u);
63 frame_tree_client_request_
= frame_tree_client_binding_
.Unbind();
65 document_
->LoadIfNecessary();
68 void DocumentResourceWaiter::OnFrameAdded(mandoline::FrameDataPtr frame_data
) {
69 // It is assumed we receive OnConnect() (which unbinds) before anything else.
73 void DocumentResourceWaiter::OnFrameRemoved(uint32_t frame_id
) {
74 // It is assumed we receive OnConnect() (which unbinds) before anything else.
78 void DocumentResourceWaiter::OnFrameClientPropertyChanged(
80 const mojo::String
& name
,
81 mojo::Array
<uint8_t> new_value
) {
82 // It is assumed we receive OnConnect() (which unbinds) before anything else.
86 } // namespace html_viewer