Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / components / html_viewer / document_resource_waiter.cc
blobcbe50601c4b25dfb827ceee999fa8cd11247e349
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),
18 document_(document),
19 response_(response.Pass()),
20 root_(nullptr),
21 change_id_(0u),
22 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,
32 uint32_t* change_id) {
33 DCHECK(IsReady());
34 *frame_tree_client_request = frame_tree_client_request_.Pass();
35 *frame_tree_server = server_.Pass();
36 *frame_data = frame_data_.Pass();
37 *change_id = change_id_;
40 mojo::URLResponsePtr DocumentResourceWaiter::ReleaseURLResponse() {
41 return response_.Pass();
44 bool DocumentResourceWaiter::IsReady() const {
45 return root_ && root_->viewport_metrics().device_pixel_ratio != 0.0f &&
46 !frame_data_.is_null();
49 void DocumentResourceWaiter::Bind(
50 mojo::InterfaceRequest<mandoline::FrameTreeClient> request) {
51 if (frame_tree_client_binding_.is_bound() || !frame_data_.is_null()) {
52 DVLOG(1) << "Request for FrameTreeClient after already supplied one";
53 return;
55 frame_tree_client_binding_.Bind(request.Pass());
58 void DocumentResourceWaiter::OnConnect(
59 mandoline::FrameTreeServerPtr server,
60 uint32_t change_id,
61 mojo::Array<mandoline::FrameDataPtr> frame_data) {
62 DCHECK(frame_data_.is_null());
63 change_id_ = change_id;
64 server_ = server.Pass();
65 frame_data_ = frame_data.Pass();
66 CHECK(frame_data_.size() > 0u);
67 frame_tree_client_request_ = frame_tree_client_binding_.Unbind();
68 if (IsReady())
69 document_->LoadIfNecessary();
72 void DocumentResourceWaiter::OnFrameAdded(uint32_t change_id,
73 mandoline::FrameDataPtr frame_data) {
74 // It is assumed we receive OnConnect() (which unbinds) before anything else.
75 NOTREACHED();
78 void DocumentResourceWaiter::OnFrameRemoved(uint32_t change_id,
79 uint32_t frame_id) {
80 // It is assumed we receive OnConnect() (which unbinds) before anything else.
81 NOTREACHED();
84 void DocumentResourceWaiter::OnFrameClientPropertyChanged(
85 uint32_t frame_id,
86 const mojo::String& name,
87 mojo::Array<uint8_t> new_value) {
88 // It is assumed we receive OnConnect() (which unbinds) before anything else.
89 NOTREACHED();
92 void DocumentResourceWaiter::OnPostMessageEvent(
93 uint32_t source_frame_id,
94 uint32_t target_frame_id,
95 mandoline::HTMLMessageEventPtr event) {
96 // It is assumed we receive OnConnect() (which unbinds) before anything else.
97 NOTREACHED();
100 void DocumentResourceWaiter::OnWillNavigate(
101 uint32_t target_frame_id,
102 const OnWillNavigateCallback& callback) {
103 // It is assumed we receive OnConnect() (which unbinds) before anything else.
104 NOTIMPLEMENTED();
107 } // namespace html_viewer