Reland of ll WebRTC 9687:9699, Libjingle 9690:9699 (patchset #1 id:1 of https://coder...
[chromium-blink-merge.git] / components / html_viewer / document_resource_waiter.cc
blobedf0b457150a7ce5957df8a6331fe3cdc0d21a0b
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 #if defined(OS_WIN) && defined(PostMessage)
13 #undef PostMessage
14 #endif
16 namespace html_viewer {
18 DocumentResourceWaiter::DocumentResourceWaiter(GlobalState* global_state,
19 mojo::URLResponsePtr response,
20 HTMLDocumentOOPIF* document)
21 : global_state_(global_state),
22 document_(document),
23 response_(response.Pass()),
24 root_(nullptr),
25 change_id_(0u),
26 frame_tree_client_binding_(this) {}
28 DocumentResourceWaiter::~DocumentResourceWaiter() {
31 void DocumentResourceWaiter::Release(
32 mojo::InterfaceRequest<mandoline::FrameTreeClient>*
33 frame_tree_client_request,
34 mandoline::FrameTreeServerPtr* frame_tree_server,
35 mojo::Array<mandoline::FrameDataPtr>* frame_data,
36 uint32_t* change_id) {
37 DCHECK(IsReady());
38 *frame_tree_client_request = frame_tree_client_request_.Pass();
39 *frame_tree_server = server_.Pass();
40 *frame_data = frame_data_.Pass();
41 *change_id = change_id_;
44 mojo::URLResponsePtr DocumentResourceWaiter::ReleaseURLResponse() {
45 return response_.Pass();
48 bool DocumentResourceWaiter::IsReady() const {
49 return root_ && root_->viewport_metrics().device_pixel_ratio != 0.0f &&
50 !frame_data_.is_null();
53 void DocumentResourceWaiter::Bind(
54 mojo::InterfaceRequest<mandoline::FrameTreeClient> request) {
55 if (frame_tree_client_binding_.is_bound() || !frame_data_.is_null()) {
56 DVLOG(1) << "Request for FrameTreeClient after already supplied one";
57 return;
59 frame_tree_client_binding_.Bind(request.Pass());
62 void DocumentResourceWaiter::OnConnect(
63 mandoline::FrameTreeServerPtr server,
64 uint32 change_id,
65 mojo::Array<mandoline::FrameDataPtr> frame_data) {
66 DCHECK(frame_data_.is_null());
67 change_id_ = change_id;
68 server_ = server.Pass();
69 frame_data_ = frame_data.Pass();
70 CHECK(frame_data_.size() > 0u);
71 frame_tree_client_request_ = frame_tree_client_binding_.Unbind();
72 if (IsReady())
73 document_->LoadIfNecessary();
76 void DocumentResourceWaiter::OnFrameAdded(uint32 change_id,
77 mandoline::FrameDataPtr frame_data) {
78 // It is assumed we receive OnConnect() (which unbinds) before anything else.
79 NOTREACHED();
82 void DocumentResourceWaiter::OnFrameRemoved(uint32 change_id,
83 uint32_t frame_id) {
84 // It is assumed we receive OnConnect() (which unbinds) before anything else.
85 NOTREACHED();
88 void DocumentResourceWaiter::OnFrameClientPropertyChanged(
89 uint32_t frame_id,
90 const mojo::String& name,
91 mojo::Array<uint8_t> new_value) {
92 // It is assumed we receive OnConnect() (which unbinds) before anything else.
93 NOTREACHED();
96 void DocumentResourceWaiter::PostMessage(uint32_t source_frame_id,
97 uint32_t target_frame_id,
98 mandoline::HTMLMessageEventPtr event) {
99 // It is assumed we receive OnConnect() (which unbinds) before anything else.
100 NOTREACHED();
103 } // namespace html_viewer