Rename GetIconID to GetIconId
[chromium-blink-merge.git] / components / html_viewer / document_resource_waiter.cc
blob47687cd17fa25a2ebe32517810b94bf3bae23035
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 using web_view::ViewConnectType;
14 namespace html_viewer {
16 DocumentResourceWaiter::DocumentResourceWaiter(GlobalState* global_state,
17 mojo::URLResponsePtr response,
18 HTMLDocumentOOPIF* document)
19 : global_state_(global_state),
20 document_(document),
21 response_(response.Pass()),
22 root_(nullptr),
23 change_id_(0u),
24 view_id_(0u),
25 view_connect_type_(web_view::VIEW_CONNECT_TYPE_USE_NEW),
26 frame_tree_client_binding_(this) {}
28 DocumentResourceWaiter::~DocumentResourceWaiter() {
31 void DocumentResourceWaiter::Release(
32 mojo::InterfaceRequest<web_view::FrameTreeClient>*
33 frame_tree_client_request,
34 web_view::FrameTreeServerPtr* frame_tree_server,
35 mojo::Array<web_view::FrameDataPtr>* frame_data,
36 uint32_t* change_id,
37 uint32_t* view_id,
38 ViewConnectType* view_connect_type,
39 OnConnectCallback* on_connect_callback) {
40 DCHECK(IsReady());
41 *frame_tree_client_request = frame_tree_client_request_.Pass();
42 *frame_tree_server = server_.Pass();
43 *frame_data = frame_data_.Pass();
44 *change_id = change_id_;
45 *view_id = view_id_;
46 *view_connect_type = view_connect_type_;
47 *on_connect_callback = on_connect_callback_;
50 mojo::URLResponsePtr DocumentResourceWaiter::ReleaseURLResponse() {
51 return response_.Pass();
54 bool DocumentResourceWaiter::IsReady() const {
55 return (!frame_data_.is_null() &&
56 ((view_connect_type_ == web_view::VIEW_CONNECT_TYPE_USE_EXISTING) ||
57 (root_ && root_->viewport_metrics().device_pixel_ratio != 0.0f)));
60 void DocumentResourceWaiter::Bind(
61 mojo::InterfaceRequest<web_view::FrameTreeClient> request) {
62 if (frame_tree_client_binding_.is_bound() || !frame_data_.is_null()) {
63 DVLOG(1) << "Request for FrameTreeClient after already supplied one";
64 return;
66 frame_tree_client_binding_.Bind(request.Pass());
69 void DocumentResourceWaiter::OnConnect(
70 web_view::FrameTreeServerPtr server,
71 uint32_t change_id,
72 uint32_t view_id,
73 ViewConnectType view_connect_type,
74 mojo::Array<web_view::FrameDataPtr> frame_data,
75 const OnConnectCallback& callback) {
76 DCHECK(frame_data_.is_null());
77 change_id_ = change_id;
78 view_id_ = view_id;
79 view_connect_type_ = view_connect_type;
80 server_ = server.Pass();
81 frame_data_ = frame_data.Pass();
82 on_connect_callback_ = callback;
83 CHECK(frame_data_.size() > 0u);
84 frame_tree_client_request_ = frame_tree_client_binding_.Unbind();
85 if (IsReady())
86 document_->LoadIfNecessary();
89 void DocumentResourceWaiter::OnFrameAdded(uint32_t change_id,
90 web_view::FrameDataPtr frame_data) {
91 // It is assumed we receive OnConnect() (which unbinds) before anything else.
92 NOTREACHED();
95 void DocumentResourceWaiter::OnFrameRemoved(uint32_t change_id,
96 uint32_t frame_id) {
97 // It is assumed we receive OnConnect() (which unbinds) before anything else.
98 NOTREACHED();
101 void DocumentResourceWaiter::OnFrameClientPropertyChanged(
102 uint32_t frame_id,
103 const mojo::String& name,
104 mojo::Array<uint8_t> new_value) {
105 // It is assumed we receive OnConnect() (which unbinds) before anything else.
106 NOTREACHED();
109 void DocumentResourceWaiter::OnPostMessageEvent(
110 uint32_t source_frame_id,
111 uint32_t target_frame_id,
112 web_view::HTMLMessageEventPtr event) {
113 // It is assumed we receive OnConnect() (which unbinds) before anything else.
114 NOTREACHED();
117 void DocumentResourceWaiter::OnWillNavigate(uint32_t target_frame_id) {
118 // It is assumed we receive OnConnect() (which unbinds) before anything else.
119 NOTIMPLEMENTED();
122 } // namespace html_viewer