Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: components/web_view/frame.cc

Issue 1406153004: components/mus/public/interfaces View => Window (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yet another rebase Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/web_view/frame.h ('k') | components/web_view/frame_apptest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/web_view/frame.h" 5 #include "components/web_view/frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 parent_->Remove(this); 88 parent_->Remove(this);
89 if (view_) { 89 if (view_) {
90 view_->ClearLocalProperty(kFrame); 90 view_->ClearLocalProperty(kFrame);
91 if (view_ownership_ == ViewOwnership::OWNS_VIEW) 91 if (view_ownership_ == ViewOwnership::OWNS_VIEW)
92 view_->Destroy(); 92 view_->Destroy();
93 } 93 }
94 tree_->delegate_->DidDestroyFrame(this); 94 tree_->delegate_->DidDestroyFrame(this);
95 } 95 }
96 96
97 void Frame::Init(Frame* parent, 97 void Frame::Init(Frame* parent,
98 mojo::ViewTreeClientPtr view_tree_client, 98 mus::mojom::WindowTreeClientPtr window_tree_client,
99 mojo::InterfaceRequest<mojom::Frame> frame_request, 99 mojo::InterfaceRequest<mojom::Frame> frame_request,
100 base::TimeTicks navigation_start_time) { 100 base::TimeTicks navigation_start_time) {
101 { 101 {
102 // Set the FrameClient to null so that we don't notify the client of the 102 // Set the FrameClient to null so that we don't notify the client of the
103 // add before OnConnect(). 103 // add before OnConnect().
104 base::AutoReset<mojom::FrameClient*> frame_client_resetter(&frame_client_, 104 base::AutoReset<mojom::FrameClient*> frame_client_resetter(&frame_client_,
105 nullptr); 105 nullptr);
106 if (parent) 106 if (parent)
107 parent->Add(this); 107 parent->Add(this);
108 } 108 }
109 109
110 const ClientType client_type = frame_request.is_pending() 110 const ClientType client_type = frame_request.is_pending()
111 ? ClientType::NEW_CHILD_FRAME 111 ? ClientType::NEW_CHILD_FRAME
112 : ClientType::EXISTING_FRAME_NEW_APP; 112 : ClientType::EXISTING_FRAME_NEW_APP;
113 InitClient(client_type, nullptr, view_tree_client.Pass(), 113 InitClient(client_type, nullptr, window_tree_client.Pass(),
114 frame_request.Pass(), navigation_start_time); 114 frame_request.Pass(), navigation_start_time);
115 115
116 tree_->delegate_->DidCreateFrame(this); 116 tree_->delegate_->DidCreateFrame(this);
117 117
118 DVLOG(2) << "Frame id=" << id_ << " parent=" << (parent_ ? parent_->id_ : 0) 118 DVLOG(2) << "Frame id=" << id_ << " parent=" << (parent_ ? parent_->id_ : 0)
119 << " app_id=" << app_id_ << " this=" << this; 119 << " app_id=" << app_id_ << " this=" << this;
120 } 120 }
121 121
122 // static 122 // static
123 Frame* Frame::FindFirstFrameAncestor(Window* view) { 123 Frame* Frame::FindFirstFrameAncestor(Window* view) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 frame_client_->HighlightFindResults(request_id, search_text, options.Pass(), 183 frame_client_->HighlightFindResults(request_id, search_text, options.Pass(),
184 reset); 184 reset);
185 } 185 }
186 186
187 void Frame::StopHighlightingFindResults() { 187 void Frame::StopHighlightingFindResults() {
188 frame_client_->StopHighlightingFindResults(); 188 frame_client_->StopHighlightingFindResults();
189 } 189 }
190 190
191 void Frame::InitClient(ClientType client_type, 191 void Frame::InitClient(ClientType client_type,
192 scoped_ptr<FrameUserDataAndBinding> data_and_binding, 192 scoped_ptr<FrameUserDataAndBinding> data_and_binding,
193 mojo::ViewTreeClientPtr view_tree_client, 193 mus::mojom::WindowTreeClientPtr window_tree_client,
194 mojo::InterfaceRequest<mojom::Frame> frame_request, 194 mojo::InterfaceRequest<mojom::Frame> frame_request,
195 base::TimeTicks navigation_start_time) { 195 base::TimeTicks navigation_start_time) {
196 if (client_type == ClientType::EXISTING_FRAME_NEW_APP && 196 if (client_type == ClientType::EXISTING_FRAME_NEW_APP &&
197 view_tree_client.get()) { 197 window_tree_client.get()) {
198 embedded_connection_id_ = kInvalidConnectionId; 198 embedded_connection_id_ = kInvalidConnectionId;
199 embed_weak_ptr_factory_.InvalidateWeakPtrs(); 199 embed_weak_ptr_factory_.InvalidateWeakPtrs();
200 view_->Embed( 200 view_->Embed(
201 view_tree_client.Pass(), mojo::ViewTree::ACCESS_POLICY_DEFAULT, 201 window_tree_client.Pass(),
202 mus::mojom::WindowTree::ACCESS_POLICY_DEFAULT,
202 base::Bind(&Frame::OnEmbedAck, embed_weak_ptr_factory_.GetWeakPtr())); 203 base::Bind(&Frame::OnEmbedAck, embed_weak_ptr_factory_.GetWeakPtr()));
203 } 204 }
204 205
205 if (client_type == ClientType::NEW_CHILD_FRAME) { 206 if (client_type == ClientType::NEW_CHILD_FRAME) {
206 // Don't install an error handler. We allow for the target to only 207 // Don't install an error handler. We allow for the target to only
207 // implement ViewTreeClient. 208 // implement WindowTreeClient.
208 // This frame (and client) was created by an existing FrameClient. There 209 // This frame (and client) was created by an existing FrameClient. There
209 // is no need to send it OnConnect(). 210 // is no need to send it OnConnect().
210 frame_binding_.reset( 211 frame_binding_.reset(
211 new mojo::Binding<mojom::Frame>(this, frame_request.Pass())); 212 new mojo::Binding<mojom::Frame>(this, frame_request.Pass()));
212 frame_client_->OnConnect( 213 frame_client_->OnConnect(
213 nullptr, tree_->change_id(), id_, mojom::VIEW_CONNECT_TYPE_USE_NEW, 214 nullptr, tree_->change_id(), id_, mojom::VIEW_CONNECT_TYPE_USE_NEW,
214 mojo::Array<mojom::FrameDataPtr>(), 215 mojo::Array<mojom::FrameDataPtr>(),
215 navigation_start_time.ToInternalValue(), 216 navigation_start_time.ToInternalValue(),
216 base::Bind(&OnConnectAck, base::Passed(&data_and_binding))); 217 base::Bind(&OnConnectAck, base::Passed(&data_and_binding)));
217 } else { 218 } else {
218 std::vector<const Frame*> frames; 219 std::vector<const Frame*> frames;
219 tree_->root()->BuildFrameTree(&frames); 220 tree_->root()->BuildFrameTree(&frames);
220 221
221 mojo::Array<mojom::FrameDataPtr> array(frames.size()); 222 mojo::Array<mojom::FrameDataPtr> array(frames.size());
222 for (size_t i = 0; i < frames.size(); ++i) 223 for (size_t i = 0; i < frames.size(); ++i)
223 array[i] = FrameToFrameData(frames[i]).Pass(); 224 array[i] = FrameToFrameData(frames[i]).Pass();
224 225
225 mojom::FramePtr frame_ptr; 226 mojom::FramePtr frame_ptr;
226 // Don't install an error handler. We allow for the target to only 227 // Don't install an error handler. We allow for the target to only
227 // implement ViewTreeClient. 228 // implement WindowTreeClient.
228 frame_binding_.reset( 229 frame_binding_.reset(
229 new mojo::Binding<mojom::Frame>(this, GetProxy(&frame_ptr).Pass())); 230 new mojo::Binding<mojom::Frame>(this, GetProxy(&frame_ptr).Pass()));
230 frame_client_->OnConnect( 231 frame_client_->OnConnect(
231 frame_ptr.Pass(), tree_->change_id(), id_, 232 frame_ptr.Pass(), tree_->change_id(), id_,
232 client_type == ClientType::EXISTING_FRAME_SAME_APP 233 client_type == ClientType::EXISTING_FRAME_SAME_APP
233 ? mojom::VIEW_CONNECT_TYPE_USE_EXISTING 234 ? mojom::VIEW_CONNECT_TYPE_USE_EXISTING
234 : mojom::VIEW_CONNECT_TYPE_USE_NEW, 235 : mojom::VIEW_CONNECT_TYPE_USE_NEW,
235 array.Pass(), navigation_start_time.ToInternalValue(), 236 array.Pass(), navigation_start_time.ToInternalValue(),
236 base::Bind(&OnConnectAck, base::Passed(&data_and_binding))); 237 base::Bind(&OnConnectAck, base::Passed(&data_and_binding)));
237 tree_->delegate_->DidStartNavigation(this); 238 tree_->delegate_->DidStartNavigation(this);
238 239
239 // We need |embedded_connection_id_| is order to validate requests to 240 // We need |embedded_connection_id_| is order to validate requests to
240 // create a child frame (OnCreatedFrame()). Pause incoming methods until 241 // create a child frame (OnCreatedFrame()). Pause incoming methods until
241 // we get the id to prevent race conditions. 242 // we get the id to prevent race conditions.
242 if (embedded_connection_id_ == kInvalidConnectionId) 243 if (embedded_connection_id_ == kInvalidConnectionId)
243 frame_binding_->PauseIncomingMethodCallProcessing(); 244 frame_binding_->PauseIncomingMethodCallProcessing();
244 } 245 }
245 } 246 }
246 247
247 // static 248 // static
248 void Frame::OnConnectAck(scoped_ptr<FrameUserDataAndBinding> data_and_binding) { 249 void Frame::OnConnectAck(scoped_ptr<FrameUserDataAndBinding> data_and_binding) {
249 } 250 }
250 251
251 void Frame::ChangeClient(mojom::FrameClient* frame_client, 252 void Frame::ChangeClient(mojom::FrameClient* frame_client,
252 scoped_ptr<FrameUserData> user_data, 253 scoped_ptr<FrameUserData> user_data,
253 mojo::ViewTreeClientPtr view_tree_client, 254 mus::mojom::WindowTreeClientPtr window_tree_client,
254 uint32_t app_id, 255 uint32_t app_id,
255 base::TimeTicks navigation_start_time) { 256 base::TimeTicks navigation_start_time) {
256 while (!children_.empty()) 257 while (!children_.empty())
257 delete children_[0]; 258 delete children_[0];
258 259
259 ClientType client_type = view_tree_client.get() == nullptr 260 ClientType client_type = window_tree_client.get() == nullptr
260 ? ClientType::EXISTING_FRAME_SAME_APP 261 ? ClientType::EXISTING_FRAME_SAME_APP
261 : ClientType::EXISTING_FRAME_NEW_APP; 262 : ClientType::EXISTING_FRAME_NEW_APP;
262 scoped_ptr<FrameUserDataAndBinding> data_and_binding; 263 scoped_ptr<FrameUserDataAndBinding> data_and_binding;
263 264
264 if (client_type == ClientType::EXISTING_FRAME_SAME_APP) { 265 if (client_type == ClientType::EXISTING_FRAME_SAME_APP) {
265 // See comment in InitClient() for details. 266 // See comment in InitClient() for details.
266 data_and_binding.reset(new FrameUserDataAndBinding); 267 data_and_binding.reset(new FrameUserDataAndBinding);
267 data_and_binding->user_data = user_data_.Pass(); 268 data_and_binding->user_data = user_data_.Pass();
268 data_and_binding->frame_binding = frame_binding_.Pass(); 269 data_and_binding->frame_binding = frame_binding_.Pass();
269 } else { 270 } else {
270 loading_ = false; 271 loading_ = false;
271 progress_ = 0.f; 272 progress_ = 0.f;
272 } 273 }
273 274
274 user_data_ = user_data.Pass(); 275 user_data_ = user_data.Pass();
275 frame_client_ = frame_client; 276 frame_client_ = frame_client;
276 frame_binding_.reset(); 277 frame_binding_.reset();
277 app_id_ = app_id; 278 app_id_ = app_id;
278 279
279 InitClient(client_type, data_and_binding.Pass(), view_tree_client.Pass(), 280 InitClient(client_type, data_and_binding.Pass(), window_tree_client.Pass(),
280 nullptr, navigation_start_time); 281 nullptr, navigation_start_time);
281 } 282 }
282 283
283 void Frame::OnEmbedAck(bool success, mus::ConnectionSpecificId connection_id) { 284 void Frame::OnEmbedAck(bool success, mus::ConnectionSpecificId connection_id) {
284 if (success) 285 if (success)
285 embedded_connection_id_ = connection_id; 286 embedded_connection_id_ = connection_id;
286 if (frame_binding_->is_bound()) 287 if (frame_binding_->is_bound())
287 frame_binding_->ResumeIncomingMethodCallProcessing(); 288 frame_binding_->ResumeIncomingMethodCallProcessing();
288 } 289 }
289 290
290 void Frame::OnWillNavigateAck(mojom::FrameClient* frame_client, 291 void Frame::OnWillNavigateAck(
291 scoped_ptr<FrameUserData> user_data, 292 mojom::FrameClient* frame_client,
292 mojo::ViewTreeClientPtr view_tree_client, 293 scoped_ptr<FrameUserData> user_data,
293 uint32 app_id, 294 mus::mojom::WindowTreeClientPtr window_tree_client,
294 base::TimeTicks navigation_start_time) { 295 uint32 app_id,
296 base::TimeTicks navigation_start_time) {
295 DCHECK(waiting_for_on_will_navigate_ack_); 297 DCHECK(waiting_for_on_will_navigate_ack_);
296 DVLOG(2) << "Frame::OnWillNavigateAck id=" << id_; 298 DVLOG(2) << "Frame::OnWillNavigateAck id=" << id_;
297 waiting_for_on_will_navigate_ack_ = false; 299 waiting_for_on_will_navigate_ack_ = false;
298 ChangeClient(frame_client, user_data.Pass(), view_tree_client.Pass(), app_id, 300 ChangeClient(frame_client, user_data.Pass(), window_tree_client.Pass(),
299 navigation_start_time); 301 app_id, navigation_start_time);
300 if (pending_navigate_.get()) 302 if (pending_navigate_.get())
301 StartNavigate(pending_navigate_.Pass()); 303 StartNavigate(pending_navigate_.Pass());
302 } 304 }
303 305
304 void Frame::SetView(mus::Window* view) { 306 void Frame::SetView(mus::Window* view) {
305 DCHECK(!view_); 307 DCHECK(!view_);
306 DCHECK_EQ(id_, view->id()); 308 DCHECK_EQ(id_, view->id());
307 view_ = view; 309 view_ = view;
308 view_->SetLocalProperty(kFrame, this); 310 view_->SetLocalProperty(kFrame, this);
309 view_->AddObserver(this); 311 view_->AddObserver(this);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 362
361 const GURL requested_url(request->url); 363 const GURL requested_url(request->url);
362 base::TimeTicks navigation_start_time = 364 base::TimeTicks navigation_start_time =
363 base::TimeTicks::FromInternalValue(request->originating_time_ticks); 365 base::TimeTicks::FromInternalValue(request->originating_time_ticks);
364 tree_->delegate_->CanNavigateFrame( 366 tree_->delegate_->CanNavigateFrame(
365 this, request.Pass(), base::Bind(&Frame::OnCanNavigateFrame, 367 this, request.Pass(), base::Bind(&Frame::OnCanNavigateFrame,
366 navigate_weak_ptr_factory_.GetWeakPtr(), 368 navigate_weak_ptr_factory_.GetWeakPtr(),
367 requested_url, navigation_start_time)); 369 requested_url, navigation_start_time));
368 } 370 }
369 371
370 void Frame::OnCanNavigateFrame(const GURL& url, 372 void Frame::OnCanNavigateFrame(
371 base::TimeTicks navigation_start_time, 373 const GURL& url,
372 uint32_t app_id, 374 base::TimeTicks navigation_start_time,
373 mojom::FrameClient* frame_client, 375 uint32_t app_id,
374 scoped_ptr<FrameUserData> user_data, 376 mojom::FrameClient* frame_client,
375 mojo::ViewTreeClientPtr view_tree_client) { 377 scoped_ptr<FrameUserData> user_data,
378 mus::mojom::WindowTreeClientPtr window_tree_client) {
376 DVLOG(2) << "Frame::OnCanNavigateFrame id=" << id_ 379 DVLOG(2) << "Frame::OnCanNavigateFrame id=" << id_
377 << " equal=" << (AreAppIdsEqual(app_id, app_id_) ? "true" : "false"); 380 << " equal=" << (AreAppIdsEqual(app_id, app_id_) ? "true" : "false");
378 if (AreAppIdsEqual(app_id, app_id_)) { 381 if (AreAppIdsEqual(app_id, app_id_)) {
379 // The app currently rendering the frame will continue rendering it. In this 382 // The app currently rendering the frame will continue rendering it. In this
380 // case we do not use the ViewTreeClient (because the app has a View already 383 // case we do not use the WindowTreeClient (because the app has a View
384 // already
381 // and ends up reusing it). 385 // and ends up reusing it).
382 DCHECK(!view_tree_client.get()); 386 DCHECK(!window_tree_client.get());
383 ChangeClient(frame_client, user_data.Pass(), view_tree_client.Pass(), 387 ChangeClient(frame_client, user_data.Pass(), window_tree_client.Pass(),
384 app_id, navigation_start_time); 388 app_id, navigation_start_time);
385 } else { 389 } else {
386 waiting_for_on_will_navigate_ack_ = true; 390 waiting_for_on_will_navigate_ack_ = true;
387 DCHECK(view_tree_client.get()); 391 DCHECK(window_tree_client.get());
388 // TODO(sky): url isn't correct here, it should be a security origin. 392 // TODO(sky): url isn't correct here, it should be a security origin.
389 frame_client_->OnWillNavigate( 393 frame_client_->OnWillNavigate(
390 url.spec(), 394 url.spec(),
391 base::Bind(&Frame::OnWillNavigateAck, base::Unretained(this), 395 base::Bind(&Frame::OnWillNavigateAck, base::Unretained(this),
392 frame_client, base::Passed(&user_data), 396 frame_client, base::Passed(&user_data),
393 base::Passed(&view_tree_client), app_id, 397 base::Passed(&window_tree_client), app_id,
394 navigation_start_time)); 398 navigation_start_time));
395 } 399 }
396 } 400 }
397 401
398 void Frame::NotifyAdded(const Frame* source, 402 void Frame::NotifyAdded(const Frame* source,
399 const Frame* added_node, 403 const Frame* added_node,
400 uint32_t change_id) { 404 uint32_t change_id) {
401 // |frame_client_| may be null during initial frame creation and parenting. 405 // |frame_client_| may be null during initial frame creation and parenting.
402 if (frame_client_) 406 if (frame_client_)
403 frame_client_->OnFrameAdded(change_id, FrameToFrameData(added_node)); 407 frame_client_->OnFrameAdded(change_id, FrameToFrameData(added_node));
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 final_update); 593 final_update);
590 } 594 }
591 595
592 void Frame::OnFindInPageSelectionUpdated(int32_t request_id, 596 void Frame::OnFindInPageSelectionUpdated(int32_t request_id,
593 int32_t active_match_ordinal) { 597 int32_t active_match_ordinal) {
594 tree_->delegate_->OnFindInPageSelectionUpdated(request_id, this, 598 tree_->delegate_->OnFindInPageSelectionUpdated(request_id, this,
595 active_match_ordinal); 599 active_match_ordinal);
596 } 600 }
597 601
598 } // namespace web_view 602 } // namespace web_view
OLDNEW
« no previous file with comments | « components/web_view/frame.h ('k') | components/web_view/frame_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698