OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/html_viewer/document_resource_waiter.h" | 5 #include "components/html_viewer/document_resource_waiter.h" |
6 | 6 |
7 #include "components/html_viewer/global_state.h" | 7 #include "components/html_viewer/global_state.h" |
8 #include "components/html_viewer/html_document.h" | 8 #include "components/html_viewer/html_document.h" |
9 #include "components/html_viewer/html_frame_tree_manager.h" | 9 #include "components/html_viewer/html_frame_tree_manager.h" |
10 #include "components/mus/public/cpp/view.h" | 10 #include "components/mus/public/cpp/view.h" |
11 | 11 |
12 using web_view::ViewConnectType; | 12 using web_view::mojom::ViewConnectType; |
13 | 13 |
14 namespace html_viewer { | 14 namespace html_viewer { |
15 | 15 |
16 DocumentResourceWaiter::DocumentResourceWaiter(GlobalState* global_state, | 16 DocumentResourceWaiter::DocumentResourceWaiter(GlobalState* global_state, |
17 mojo::URLResponsePtr response, | 17 mojo::URLResponsePtr response, |
18 HTMLDocument* document) | 18 HTMLDocument* document) |
19 : global_state_(global_state), | 19 : global_state_(global_state), |
20 document_(document), | 20 document_(document), |
21 response_(response.Pass()), | 21 response_(response.Pass()), |
22 root_(nullptr), | 22 root_(nullptr), |
23 change_id_(0u), | 23 change_id_(0u), |
24 view_id_(0u), | 24 view_id_(0u), |
25 view_connect_type_(web_view::VIEW_CONNECT_TYPE_USE_NEW), | 25 view_connect_type_(web_view::mojom::VIEW_CONNECT_TYPE_USE_NEW), |
26 frame_tree_client_binding_(this), | 26 frame_client_binding_(this), |
27 is_ready_(false), | 27 is_ready_(false), |
28 waiting_for_change_id_(false), | 28 waiting_for_change_id_(false), |
29 target_frame_tree_(nullptr) {} | 29 target_frame_tree_(nullptr) {} |
30 | 30 |
31 DocumentResourceWaiter::~DocumentResourceWaiter() { | 31 DocumentResourceWaiter::~DocumentResourceWaiter() { |
32 if (root_) | 32 if (root_) |
33 root_->RemoveObserver(this); | 33 root_->RemoveObserver(this); |
34 if (target_frame_tree_) | 34 if (target_frame_tree_) |
35 target_frame_tree_->RemoveObserver(this); | 35 target_frame_tree_->RemoveObserver(this); |
36 } | 36 } |
37 | 37 |
38 void DocumentResourceWaiter::Release( | 38 void DocumentResourceWaiter::Release( |
39 mojo::InterfaceRequest<web_view::FrameTreeClient>* | 39 mojo::InterfaceRequest<web_view::mojom::FrameClient>* frame_client_request, |
40 frame_tree_client_request, | 40 web_view::mojom::FramePtr* frame, |
41 web_view::FrameTreeServerPtr* frame_tree_server, | 41 mojo::Array<web_view::mojom::FrameDataPtr>* frame_data, |
42 mojo::Array<web_view::FrameDataPtr>* frame_data, | |
43 uint32_t* change_id, | 42 uint32_t* change_id, |
44 uint32_t* view_id, | 43 uint32_t* view_id, |
45 ViewConnectType* view_connect_type, | 44 ViewConnectType* view_connect_type, |
46 OnConnectCallback* on_connect_callback) { | 45 OnConnectCallback* on_connect_callback) { |
47 DCHECK(is_ready_); | 46 DCHECK(is_ready_); |
48 *frame_tree_client_request = frame_tree_client_request_.Pass(); | 47 *frame_client_request = frame_client_request_.Pass(); |
49 *frame_tree_server = server_.Pass(); | 48 *frame = frame_.Pass(); |
50 *frame_data = frame_data_.Pass(); | 49 *frame_data = frame_data_.Pass(); |
51 *change_id = change_id_; | 50 *change_id = change_id_; |
52 *view_id = view_id_; | 51 *view_id = view_id_; |
53 *view_connect_type = view_connect_type_; | 52 *view_connect_type = view_connect_type_; |
54 *on_connect_callback = on_connect_callback_; | 53 *on_connect_callback = on_connect_callback_; |
55 } | 54 } |
56 | 55 |
57 mojo::URLResponsePtr DocumentResourceWaiter::ReleaseURLResponse() { | 56 mojo::URLResponsePtr DocumentResourceWaiter::ReleaseURLResponse() { |
58 return response_.Pass(); | 57 return response_.Pass(); |
59 } | 58 } |
60 | 59 |
61 void DocumentResourceWaiter::SetRoot(mus::View* root) { | 60 void DocumentResourceWaiter::SetRoot(mus::View* root) { |
62 DCHECK(!root_); | 61 DCHECK(!root_); |
63 root_ = root; | 62 root_ = root; |
64 root_->AddObserver(this); | 63 root_->AddObserver(this); |
65 UpdateIsReady(); | 64 UpdateIsReady(); |
66 } | 65 } |
67 | 66 |
68 void DocumentResourceWaiter::Bind( | 67 void DocumentResourceWaiter::Bind( |
69 mojo::InterfaceRequest<web_view::FrameTreeClient> request) { | 68 mojo::InterfaceRequest<web_view::mojom::FrameClient> request) { |
70 if (frame_tree_client_binding_.is_bound() || !frame_data_.is_null()) { | 69 if (frame_client_binding_.is_bound() || !frame_data_.is_null()) { |
71 DVLOG(1) << "Request for FrameTreeClient after already supplied one"; | 70 DVLOG(1) << "Request for FrameClient after already supplied one"; |
72 return; | 71 return; |
73 } | 72 } |
74 frame_tree_client_binding_.Bind(request.Pass()); | 73 frame_client_binding_.Bind(request.Pass()); |
75 } | 74 } |
76 | 75 |
77 void DocumentResourceWaiter::UpdateIsReady() { | 76 void DocumentResourceWaiter::UpdateIsReady() { |
78 if (is_ready_) | 77 if (is_ready_) |
79 return; | 78 return; |
80 | 79 |
81 // See description of |waiting_for_change_id_| for details. | 80 // See description of |waiting_for_change_id_| for details. |
82 if (waiting_for_change_id_) { | 81 if (waiting_for_change_id_) { |
83 if (target_frame_tree_->change_id() == change_id_) { | 82 if (target_frame_tree_->change_id() == change_id_) { |
84 is_ready_ = true; | 83 is_ready_ = true; |
85 waiting_for_change_id_ = false; | 84 waiting_for_change_id_ = false; |
86 document_->Load(); | 85 document_->Load(); |
87 } | 86 } |
88 return; | 87 return; |
89 } | 88 } |
90 | 89 |
91 // The first portion of ready is when we have received OnConnect() | 90 // The first portion of ready is when we have received OnConnect() |
92 // (|frame_data_| is valid) and we have a view with valid metrics. The view | 91 // (|frame_data_| is valid) and we have a view with valid metrics. The view |
93 // is not necessary is ViewConnectType is USE_EXISTING, which means the | 92 // is not necessary is ViewConnectType is USE_EXISTING, which means the |
94 // application is not asked for a ViewTreeClient. The metrics are necessary | 93 // application is not asked for a ViewTreeClient. The metrics are necessary |
95 // to initialize ResourceBundle. If USE_EXISTING is true, it means a View has | 94 // to initialize ResourceBundle. If USE_EXISTING is true, it means a View has |
96 // already been provided to another HTMLDocument and there is no need to wait | 95 // already been provided to another HTMLDocument and there is no need to wait |
97 // for metrics. | 96 // for metrics. |
98 bool is_ready = | 97 bool is_ready = |
99 (!frame_data_.is_null() && | 98 (!frame_data_.is_null() && |
100 ((view_connect_type_ == web_view::VIEW_CONNECT_TYPE_USE_EXISTING) || | 99 ((view_connect_type_ == |
| 100 web_view::mojom::VIEW_CONNECT_TYPE_USE_EXISTING) || |
101 (root_ && root_->viewport_metrics().device_pixel_ratio != 0.0f))); | 101 (root_ && root_->viewport_metrics().device_pixel_ratio != 0.0f))); |
102 if (is_ready) { | 102 if (is_ready) { |
103 HTMLFrameTreeManager* frame_tree = | 103 HTMLFrameTreeManager* frame_tree = |
104 HTMLFrameTreeManager::FindFrameTreeWithRoot(frame_data_[0]->frame_id); | 104 HTMLFrameTreeManager::FindFrameTreeWithRoot(frame_data_[0]->frame_id); |
105 // Once we've received OnConnect() and the view (if necessary), we determine | 105 // Once we've received OnConnect() and the view (if necessary), we determine |
106 // which HTMLFrameTreeManager the new frame ends up in. If there is an | 106 // which HTMLFrameTreeManager the new frame ends up in. If there is an |
107 // existing HTMLFrameTreeManager then we must wait for the change_id | 107 // existing HTMLFrameTreeManager then we must wait for the change_id |
108 // supplied to OnConnect() to be <= that of the HTMLFrameTreeManager's | 108 // supplied to OnConnect() to be <= that of the HTMLFrameTreeManager's |
109 // change_id. If we did not wait for the change id to be <= then the | 109 // change_id. If we did not wait for the change id to be <= then the |
110 // structure of the tree is not in the expected state and it's possible the | 110 // structure of the tree is not in the expected state and it's possible the |
111 // frame communicated in OnConnect() does not exist yet. | 111 // frame communicated in OnConnect() does not exist yet. |
112 if (frame_tree && change_id_ > frame_tree->change_id()) { | 112 if (frame_tree && change_id_ > frame_tree->change_id()) { |
113 waiting_for_change_id_ = true; | 113 waiting_for_change_id_ = true; |
114 target_frame_tree_ = frame_tree; | 114 target_frame_tree_ = frame_tree; |
115 target_frame_tree_->AddObserver(this); | 115 target_frame_tree_->AddObserver(this); |
116 } else { | 116 } else { |
117 is_ready_ = true; | 117 is_ready_ = true; |
118 document_->Load(); | 118 document_->Load(); |
119 } | 119 } |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 void DocumentResourceWaiter::OnConnect( | 123 void DocumentResourceWaiter::OnConnect( |
124 web_view::FrameTreeServerPtr server, | 124 web_view::mojom::FramePtr frame, |
125 uint32_t change_id, | 125 uint32_t change_id, |
126 uint32_t view_id, | 126 uint32_t view_id, |
127 ViewConnectType view_connect_type, | 127 ViewConnectType view_connect_type, |
128 mojo::Array<web_view::FrameDataPtr> frame_data, | 128 mojo::Array<web_view::mojom::FrameDataPtr> frame_data, |
129 const OnConnectCallback& callback) { | 129 const OnConnectCallback& callback) { |
130 DCHECK(frame_data_.is_null()); | 130 DCHECK(frame_data_.is_null()); |
131 change_id_ = change_id; | 131 change_id_ = change_id; |
132 view_id_ = view_id; | 132 view_id_ = view_id; |
133 view_connect_type_ = view_connect_type; | 133 view_connect_type_ = view_connect_type; |
134 server_ = server.Pass(); | 134 frame_ = frame.Pass(); |
135 frame_data_ = frame_data.Pass(); | 135 frame_data_ = frame_data.Pass(); |
136 on_connect_callback_ = callback; | 136 on_connect_callback_ = callback; |
137 CHECK(frame_data_.size() > 0u); | 137 CHECK(frame_data_.size() > 0u); |
138 frame_tree_client_request_ = frame_tree_client_binding_.Unbind(); | 138 frame_client_request_ = frame_client_binding_.Unbind(); |
139 UpdateIsReady(); | 139 UpdateIsReady(); |
140 } | 140 } |
141 | 141 |
142 void DocumentResourceWaiter::OnFrameAdded(uint32_t change_id, | 142 void DocumentResourceWaiter::OnFrameAdded( |
143 web_view::FrameDataPtr frame_data) { | 143 uint32_t change_id, |
| 144 web_view::mojom::FrameDataPtr frame_data) { |
144 // It is assumed we receive OnConnect() (which unbinds) before anything else. | 145 // It is assumed we receive OnConnect() (which unbinds) before anything else. |
145 NOTREACHED(); | 146 NOTREACHED(); |
146 } | 147 } |
147 | 148 |
148 void DocumentResourceWaiter::OnFrameRemoved(uint32_t change_id, | 149 void DocumentResourceWaiter::OnFrameRemoved(uint32_t change_id, |
149 uint32_t frame_id) { | 150 uint32_t frame_id) { |
150 // It is assumed we receive OnConnect() (which unbinds) before anything else. | 151 // It is assumed we receive OnConnect() (which unbinds) before anything else. |
151 NOTREACHED(); | 152 NOTREACHED(); |
152 } | 153 } |
153 | 154 |
154 void DocumentResourceWaiter::OnFrameClientPropertyChanged( | 155 void DocumentResourceWaiter::OnFrameClientPropertyChanged( |
155 uint32_t frame_id, | 156 uint32_t frame_id, |
156 const mojo::String& name, | 157 const mojo::String& name, |
157 mojo::Array<uint8_t> new_value) { | 158 mojo::Array<uint8_t> new_value) { |
158 // It is assumed we receive OnConnect() (which unbinds) before anything else. | 159 // It is assumed we receive OnConnect() (which unbinds) before anything else. |
159 NOTREACHED(); | 160 NOTREACHED(); |
160 } | 161 } |
161 | 162 |
162 void DocumentResourceWaiter::OnPostMessageEvent( | 163 void DocumentResourceWaiter::OnPostMessageEvent( |
163 uint32_t source_frame_id, | 164 uint32_t source_frame_id, |
164 uint32_t target_frame_id, | 165 uint32_t target_frame_id, |
165 web_view::HTMLMessageEventPtr event) { | 166 web_view::mojom::HTMLMessageEventPtr event) { |
166 // It is assumed we receive OnConnect() (which unbinds) before anything else. | 167 // It is assumed we receive OnConnect() (which unbinds) before anything else. |
167 NOTREACHED(); | 168 NOTREACHED(); |
168 } | 169 } |
169 | 170 |
170 void DocumentResourceWaiter::OnWillNavigate() { | 171 void DocumentResourceWaiter::OnWillNavigate() { |
171 // It is assumed we receive OnConnect() (which unbinds) before anything else. | 172 // It is assumed we receive OnConnect() (which unbinds) before anything else. |
172 NOTIMPLEMENTED(); | 173 NOTIMPLEMENTED(); |
173 } | 174 } |
174 | 175 |
175 void DocumentResourceWaiter::OnFrameLoadingStateChanged(uint32_t frame_id, | 176 void DocumentResourceWaiter::OnFrameLoadingStateChanged(uint32_t frame_id, |
(...skipping 21 matching lines...) Expand all Loading... |
197 | 198 |
198 void DocumentResourceWaiter::OnHTMLFrameTreeManagerChangeIdAdvanced() { | 199 void DocumentResourceWaiter::OnHTMLFrameTreeManagerChangeIdAdvanced() { |
199 UpdateIsReady(); | 200 UpdateIsReady(); |
200 } | 201 } |
201 | 202 |
202 void DocumentResourceWaiter::OnHTMLFrameTreeManagerDestroyed() { | 203 void DocumentResourceWaiter::OnHTMLFrameTreeManagerDestroyed() { |
203 document_->Destroy(); // This destroys us. | 204 document_->Destroy(); // This destroys us. |
204 } | 205 } |
205 | 206 |
206 } // namespace html_viewer | 207 } // namespace html_viewer |
OLD | NEW |