| 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/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 14 matching lines...) Expand all Loading... |
| 25 namespace web_view { | 25 namespace web_view { |
| 26 | 26 |
| 27 // Used to find the Frame associated with a View. | 27 // Used to find the Frame associated with a View. |
| 28 DEFINE_LOCAL_VIEW_PROPERTY_KEY(Frame*, kFrame, nullptr); | 28 DEFINE_LOCAL_VIEW_PROPERTY_KEY(Frame*, kFrame, nullptr); |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const uint32_t kNoParentId = 0u; | 32 const uint32_t kNoParentId = 0u; |
| 33 const mus::ConnectionSpecificId kInvalidConnectionId = 0u; | 33 const mus::ConnectionSpecificId kInvalidConnectionId = 0u; |
| 34 | 34 |
| 35 FrameDataPtr FrameToFrameData(const Frame* frame) { | 35 mojom::FrameDataPtr FrameToFrameData(const Frame* frame) { |
| 36 FrameDataPtr frame_data(FrameData::New()); | 36 mojom::FrameDataPtr frame_data(mojom::FrameData::New()); |
| 37 frame_data->frame_id = frame->id(); | 37 frame_data->frame_id = frame->id(); |
| 38 frame_data->parent_id = frame->parent() ? frame->parent()->id() : kNoParentId; | 38 frame_data->parent_id = frame->parent() ? frame->parent()->id() : kNoParentId; |
| 39 frame_data->client_properties = | 39 frame_data->client_properties = |
| 40 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From( | 40 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From( |
| 41 frame->client_properties()); | 41 frame->client_properties()); |
| 42 return frame_data.Pass(); | 42 return frame_data.Pass(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 struct Frame::FrameTreeServerBinding { | 47 struct Frame::FrameUserDataAndBinding { |
| 48 scoped_ptr<FrameUserData> user_data; | 48 scoped_ptr<FrameUserData> user_data; |
| 49 scoped_ptr<mojo::Binding<FrameTreeServer>> frame_tree_server_binding; | 49 scoped_ptr<mojo::Binding<mojom::Frame>> frame_binding; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 Frame::Frame(FrameTree* tree, | 52 Frame::Frame(FrameTree* tree, |
| 53 View* view, | 53 View* view, |
| 54 uint32_t frame_id, | 54 uint32_t frame_id, |
| 55 uint32_t app_id, | 55 uint32_t app_id, |
| 56 ViewOwnership view_ownership, | 56 ViewOwnership view_ownership, |
| 57 FrameTreeClient* frame_tree_client, | 57 mojom::FrameClient* frame_client, |
| 58 scoped_ptr<FrameUserData> user_data, | 58 scoped_ptr<FrameUserData> user_data, |
| 59 const ClientPropertyMap& client_properties) | 59 const ClientPropertyMap& client_properties) |
| 60 : tree_(tree), | 60 : tree_(tree), |
| 61 view_(nullptr), | 61 view_(nullptr), |
| 62 embedded_connection_id_(kInvalidConnectionId), | 62 embedded_connection_id_(kInvalidConnectionId), |
| 63 id_(frame_id), | 63 id_(frame_id), |
| 64 app_id_(app_id), | 64 app_id_(app_id), |
| 65 parent_(nullptr), | 65 parent_(nullptr), |
| 66 view_ownership_(view_ownership), | 66 view_ownership_(view_ownership), |
| 67 user_data_(user_data.Pass()), | 67 user_data_(user_data.Pass()), |
| 68 frame_tree_client_(frame_tree_client), | 68 frame_client_(frame_client), |
| 69 loading_(false), | 69 loading_(false), |
| 70 progress_(0.f), | 70 progress_(0.f), |
| 71 client_properties_(client_properties), | 71 client_properties_(client_properties), |
| 72 embed_weak_ptr_factory_(this), | 72 embed_weak_ptr_factory_(this), |
| 73 navigate_weak_ptr_factory_(this) { | 73 navigate_weak_ptr_factory_(this) { |
| 74 if (view) | 74 if (view) |
| 75 SetView(view); | 75 SetView(view); |
| 76 } | 76 } |
| 77 | 77 |
| 78 Frame::~Frame() { | 78 Frame::~Frame() { |
| 79 if (view_) | 79 if (view_) |
| 80 view_->RemoveObserver(this); | 80 view_->RemoveObserver(this); |
| 81 while (!children_.empty()) | 81 while (!children_.empty()) |
| 82 delete children_[0]; | 82 delete children_[0]; |
| 83 if (parent_) | 83 if (parent_) |
| 84 parent_->Remove(this); | 84 parent_->Remove(this); |
| 85 if (view_) { | 85 if (view_) { |
| 86 view_->ClearLocalProperty(kFrame); | 86 view_->ClearLocalProperty(kFrame); |
| 87 if (view_ownership_ == ViewOwnership::OWNS_VIEW) | 87 if (view_ownership_ == ViewOwnership::OWNS_VIEW) |
| 88 view_->Destroy(); | 88 view_->Destroy(); |
| 89 } | 89 } |
| 90 tree_->delegate_->DidDestroyFrame(this); | 90 tree_->delegate_->DidDestroyFrame(this); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void Frame::Init(Frame* parent, | 93 void Frame::Init(Frame* parent, |
| 94 mojo::ViewTreeClientPtr view_tree_client, | 94 mojo::ViewTreeClientPtr view_tree_client, |
| 95 mojo::InterfaceRequest<FrameTreeServer> server_request) { | 95 mojo::InterfaceRequest<mojom::Frame> frame_request) { |
| 96 { | 96 { |
| 97 // Set the FrameTreeClient to null so that we don't notify the client of the | 97 // Set the FrameClient to null so that we don't notify the client of the |
| 98 // add before OnConnect(). | 98 // add before OnConnect(). |
| 99 base::AutoReset<FrameTreeClient*> frame_tree_client_resetter( | 99 base::AutoReset<mojom::FrameClient*> frame_client_resetter(&frame_client_, |
| 100 &frame_tree_client_, nullptr); | 100 nullptr); |
| 101 if (parent) | 101 if (parent) |
| 102 parent->Add(this); | 102 parent->Add(this); |
| 103 } | 103 } |
| 104 | 104 |
| 105 const ClientType client_type = server_request.is_pending() | 105 const ClientType client_type = frame_request.is_pending() |
| 106 ? ClientType::NEW_CHILD_FRAME | 106 ? ClientType::NEW_CHILD_FRAME |
| 107 : ClientType::EXISTING_FRAME_NEW_APP; | 107 : ClientType::EXISTING_FRAME_NEW_APP; |
| 108 InitClient(client_type, nullptr, view_tree_client.Pass(), | 108 InitClient(client_type, nullptr, view_tree_client.Pass(), |
| 109 server_request.Pass()); | 109 frame_request.Pass()); |
| 110 | 110 |
| 111 tree_->delegate_->DidCreateFrame(this); | 111 tree_->delegate_->DidCreateFrame(this); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // static | 114 // static |
| 115 Frame* Frame::FindFirstFrameAncestor(View* view) { | 115 Frame* Frame::FindFirstFrameAncestor(View* view) { |
| 116 while (view && !view->GetLocalProperty(kFrame)) | 116 while (view && !view->GetLocalProperty(kFrame)) |
| 117 view = view->parent(); | 117 view = view->parent(); |
| 118 return view ? view->GetLocalProperty(kFrame) : nullptr; | 118 return view ? view->GetLocalProperty(kFrame) : nullptr; |
| 119 } | 119 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 148 } | 148 } |
| 149 | 149 |
| 150 double Frame::GatherProgress(int* frame_count) const { | 150 double Frame::GatherProgress(int* frame_count) const { |
| 151 ++(*frame_count); | 151 ++(*frame_count); |
| 152 double progress = progress_; | 152 double progress = progress_; |
| 153 for (const Frame* child : children_) | 153 for (const Frame* child : children_) |
| 154 progress += child->GatherProgress(frame_count); | 154 progress += child->GatherProgress(frame_count); |
| 155 return progress_; | 155 return progress_; |
| 156 } | 156 } |
| 157 | 157 |
| 158 void Frame::InitClient( | 158 void Frame::InitClient(ClientType client_type, |
| 159 ClientType client_type, | 159 scoped_ptr<FrameUserDataAndBinding> data_and_binding, |
| 160 scoped_ptr<FrameTreeServerBinding> frame_tree_server_binding, | 160 mojo::ViewTreeClientPtr view_tree_client, |
| 161 mojo::ViewTreeClientPtr view_tree_client, | 161 mojo::InterfaceRequest<mojom::Frame> frame_request) { |
| 162 mojo::InterfaceRequest<FrameTreeServer> server_request) { | |
| 163 if (client_type == ClientType::EXISTING_FRAME_NEW_APP && | 162 if (client_type == ClientType::EXISTING_FRAME_NEW_APP && |
| 164 view_tree_client.get()) { | 163 view_tree_client.get()) { |
| 165 embedded_connection_id_ = kInvalidConnectionId; | 164 embedded_connection_id_ = kInvalidConnectionId; |
| 166 embed_weak_ptr_factory_.InvalidateWeakPtrs(); | 165 embed_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 167 view_->Embed( | 166 view_->Embed( |
| 168 view_tree_client.Pass(), mojo::ViewTree::ACCESS_POLICY_DEFAULT, | 167 view_tree_client.Pass(), mojo::ViewTree::ACCESS_POLICY_DEFAULT, |
| 169 base::Bind(&Frame::OnEmbedAck, embed_weak_ptr_factory_.GetWeakPtr())); | 168 base::Bind(&Frame::OnEmbedAck, embed_weak_ptr_factory_.GetWeakPtr())); |
| 170 } | 169 } |
| 171 | 170 |
| 172 if (client_type == ClientType::NEW_CHILD_FRAME) { | 171 if (client_type == ClientType::NEW_CHILD_FRAME) { |
| 173 // Don't install an error handler. We allow for the target to only | 172 // Don't install an error handler. We allow for the target to only |
| 174 // implement ViewTreeClient. | 173 // implement ViewTreeClient. |
| 175 // This frame (and client) was created by an existing FrameTreeClient. There | 174 // This frame (and client) was created by an existing FrameClient. There |
| 176 // is no need to send it OnConnect(). | 175 // is no need to send it OnConnect(). |
| 177 frame_tree_server_binding_.reset( | 176 frame_binding_.reset( |
| 178 new mojo::Binding<FrameTreeServer>(this, server_request.Pass())); | 177 new mojo::Binding<mojom::Frame>(this, frame_request.Pass())); |
| 179 frame_tree_client_->OnConnect( | 178 frame_client_->OnConnect( |
| 180 nullptr, tree_->change_id(), id_, VIEW_CONNECT_TYPE_USE_NEW, | 179 nullptr, tree_->change_id(), id_, mojom::VIEW_CONNECT_TYPE_USE_NEW, |
| 181 mojo::Array<FrameDataPtr>(), | 180 mojo::Array<mojom::FrameDataPtr>(), |
| 182 base::Bind(&OnConnectAck, base::Passed(&frame_tree_server_binding))); | 181 base::Bind(&OnConnectAck, base::Passed(&data_and_binding))); |
| 183 } else { | 182 } else { |
| 184 std::vector<const Frame*> frames; | 183 std::vector<const Frame*> frames; |
| 185 tree_->root()->BuildFrameTree(&frames); | 184 tree_->root()->BuildFrameTree(&frames); |
| 186 | 185 |
| 187 mojo::Array<FrameDataPtr> array(frames.size()); | 186 mojo::Array<mojom::FrameDataPtr> array(frames.size()); |
| 188 for (size_t i = 0; i < frames.size(); ++i) | 187 for (size_t i = 0; i < frames.size(); ++i) |
| 189 array[i] = FrameToFrameData(frames[i]).Pass(); | 188 array[i] = FrameToFrameData(frames[i]).Pass(); |
| 190 | 189 |
| 191 FrameTreeServerPtr frame_tree_server_ptr; | 190 mojom::FramePtr frame_ptr; |
| 192 // Don't install an error handler. We allow for the target to only | 191 // Don't install an error handler. We allow for the target to only |
| 193 // implement ViewTreeClient. | 192 // implement ViewTreeClient. |
| 194 frame_tree_server_binding_.reset(new mojo::Binding<FrameTreeServer>( | 193 frame_binding_.reset( |
| 195 this, GetProxy(&frame_tree_server_ptr).Pass())); | 194 new mojo::Binding<mojom::Frame>(this, GetProxy(&frame_ptr).Pass())); |
| 196 frame_tree_client_->OnConnect( | 195 frame_client_->OnConnect( |
| 197 frame_tree_server_ptr.Pass(), tree_->change_id(), id_, | 196 frame_ptr.Pass(), tree_->change_id(), id_, |
| 198 client_type == ClientType::EXISTING_FRAME_SAME_APP | 197 client_type == ClientType::EXISTING_FRAME_SAME_APP |
| 199 ? VIEW_CONNECT_TYPE_USE_EXISTING | 198 ? mojom::VIEW_CONNECT_TYPE_USE_EXISTING |
| 200 : VIEW_CONNECT_TYPE_USE_NEW, | 199 : mojom::VIEW_CONNECT_TYPE_USE_NEW, |
| 201 array.Pass(), | 200 array.Pass(), |
| 202 base::Bind(&OnConnectAck, base::Passed(&frame_tree_server_binding))); | 201 base::Bind(&OnConnectAck, base::Passed(&data_and_binding))); |
| 203 tree_->delegate_->DidStartNavigation(this); | 202 tree_->delegate_->DidStartNavigation(this); |
| 204 } | 203 } |
| 205 } | 204 } |
| 206 | 205 |
| 207 // static | 206 // static |
| 208 void Frame::OnConnectAck( | 207 void Frame::OnConnectAck(scoped_ptr<FrameUserDataAndBinding> data_and_binding) { |
| 209 scoped_ptr<FrameTreeServerBinding> frame_tree_server_binding) {} | 208 } |
| 210 | 209 |
| 211 void Frame::ChangeClient(FrameTreeClient* frame_tree_client, | 210 void Frame::ChangeClient(mojom::FrameClient* frame_client, |
| 212 scoped_ptr<FrameUserData> user_data, | 211 scoped_ptr<FrameUserData> user_data, |
| 213 mojo::ViewTreeClientPtr view_tree_client, | 212 mojo::ViewTreeClientPtr view_tree_client, |
| 214 uint32_t app_id) { | 213 uint32_t app_id) { |
| 215 while (!children_.empty()) | 214 while (!children_.empty()) |
| 216 delete children_[0]; | 215 delete children_[0]; |
| 217 | 216 |
| 218 ClientType client_type = view_tree_client.get() == nullptr | 217 ClientType client_type = view_tree_client.get() == nullptr |
| 219 ? ClientType::EXISTING_FRAME_SAME_APP | 218 ? ClientType::EXISTING_FRAME_SAME_APP |
| 220 : ClientType::EXISTING_FRAME_NEW_APP; | 219 : ClientType::EXISTING_FRAME_NEW_APP; |
| 221 scoped_ptr<FrameTreeServerBinding> frame_tree_server_binding; | 220 scoped_ptr<FrameUserDataAndBinding> data_and_binding; |
| 222 | 221 |
| 223 if (client_type == ClientType::EXISTING_FRAME_SAME_APP) { | 222 if (client_type == ClientType::EXISTING_FRAME_SAME_APP) { |
| 224 // See comment in InitClient() for details. | 223 // See comment in InitClient() for details. |
| 225 frame_tree_server_binding.reset(new FrameTreeServerBinding); | 224 data_and_binding.reset(new FrameUserDataAndBinding); |
| 226 frame_tree_server_binding->user_data = user_data_.Pass(); | 225 data_and_binding->user_data = user_data_.Pass(); |
| 227 frame_tree_server_binding->frame_tree_server_binding = | 226 data_and_binding->frame_binding = frame_binding_.Pass(); |
| 228 frame_tree_server_binding_.Pass(); | |
| 229 } else { | 227 } else { |
| 230 loading_ = false; | 228 loading_ = false; |
| 231 progress_ = 0.f; | 229 progress_ = 0.f; |
| 232 } | 230 } |
| 233 | 231 |
| 234 user_data_ = user_data.Pass(); | 232 user_data_ = user_data.Pass(); |
| 235 frame_tree_client_ = frame_tree_client; | 233 frame_client_ = frame_client; |
| 236 frame_tree_server_binding_.reset(); | 234 frame_binding_.reset(); |
| 237 app_id_ = app_id; | 235 app_id_ = app_id; |
| 238 | 236 |
| 239 InitClient(client_type, frame_tree_server_binding.Pass(), | 237 InitClient(client_type, data_and_binding.Pass(), view_tree_client.Pass(), |
| 240 view_tree_client.Pass(), nullptr); | 238 nullptr); |
| 241 } | 239 } |
| 242 | 240 |
| 243 void Frame::OnEmbedAck(bool success, mus::ConnectionSpecificId connection_id) { | 241 void Frame::OnEmbedAck(bool success, mus::ConnectionSpecificId connection_id) { |
| 244 if (success) | 242 if (success) |
| 245 embedded_connection_id_ = connection_id; | 243 embedded_connection_id_ = connection_id; |
| 246 } | 244 } |
| 247 | 245 |
| 248 void Frame::SetView(mus::View* view) { | 246 void Frame::SetView(mus::View* view) { |
| 249 DCHECK(!view_); | 247 DCHECK(!view_); |
| 250 DCHECK_EQ(id_, view->id()); | 248 DCHECK_EQ(id_, view->id()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 // Drop any pending navigation requests. | 291 // Drop any pending navigation requests. |
| 294 navigate_weak_ptr_factory_.InvalidateWeakPtrs(); | 292 navigate_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 295 | 293 |
| 296 tree_->delegate_->CanNavigateFrame( | 294 tree_->delegate_->CanNavigateFrame( |
| 297 this, request.Pass(), | 295 this, request.Pass(), |
| 298 base::Bind(&Frame::OnCanNavigateFrame, | 296 base::Bind(&Frame::OnCanNavigateFrame, |
| 299 navigate_weak_ptr_factory_.GetWeakPtr())); | 297 navigate_weak_ptr_factory_.GetWeakPtr())); |
| 300 } | 298 } |
| 301 | 299 |
| 302 void Frame::OnCanNavigateFrame(uint32_t app_id, | 300 void Frame::OnCanNavigateFrame(uint32_t app_id, |
| 303 FrameTreeClient* frame_tree_client, | 301 mojom::FrameClient* frame_client, |
| 304 scoped_ptr<FrameUserData> user_data, | 302 scoped_ptr<FrameUserData> user_data, |
| 305 mojo::ViewTreeClientPtr view_tree_client) { | 303 mojo::ViewTreeClientPtr view_tree_client) { |
| 306 if (AreAppIdsEqual(app_id, app_id_)) { | 304 if (AreAppIdsEqual(app_id, app_id_)) { |
| 307 // The app currently rendering the frame will continue rendering it. In this | 305 // The app currently rendering the frame will continue rendering it. In this |
| 308 // case we do not use the ViewTreeClient (because the app has a View already | 306 // case we do not use the ViewTreeClient (because the app has a View already |
| 309 // and ends up reusing it). | 307 // and ends up reusing it). |
| 310 DCHECK(!view_tree_client.get()); | 308 DCHECK(!view_tree_client.get()); |
| 311 } else { | 309 } else { |
| 312 frame_tree_client_->OnWillNavigate(); | 310 frame_client_->OnWillNavigate(); |
| 313 DCHECK(view_tree_client.get()); | 311 DCHECK(view_tree_client.get()); |
| 314 } | 312 } |
| 315 ChangeClient(frame_tree_client, user_data.Pass(), view_tree_client.Pass(), | 313 ChangeClient(frame_client, user_data.Pass(), view_tree_client.Pass(), app_id); |
| 316 app_id); | |
| 317 } | 314 } |
| 318 | 315 |
| 319 void Frame::NotifyAdded(const Frame* source, | 316 void Frame::NotifyAdded(const Frame* source, |
| 320 const Frame* added_node, | 317 const Frame* added_node, |
| 321 uint32_t change_id) { | 318 uint32_t change_id) { |
| 322 // |frame_tree_client_| may be null during initial frame creation and | 319 // |frame_client_| may be null during initial frame creation and parenting. |
| 323 // parenting. | 320 if (frame_client_) |
| 324 if (frame_tree_client_) | 321 frame_client_->OnFrameAdded(change_id, FrameToFrameData(added_node)); |
| 325 frame_tree_client_->OnFrameAdded(change_id, FrameToFrameData(added_node)); | |
| 326 | 322 |
| 327 for (Frame* child : children_) | 323 for (Frame* child : children_) |
| 328 child->NotifyAdded(source, added_node, change_id); | 324 child->NotifyAdded(source, added_node, change_id); |
| 329 } | 325 } |
| 330 | 326 |
| 331 void Frame::NotifyRemoved(const Frame* source, | 327 void Frame::NotifyRemoved(const Frame* source, |
| 332 const Frame* removed_node, | 328 const Frame* removed_node, |
| 333 uint32_t change_id) { | 329 uint32_t change_id) { |
| 334 frame_tree_client_->OnFrameRemoved(change_id, removed_node->id()); | 330 frame_client_->OnFrameRemoved(change_id, removed_node->id()); |
| 335 | 331 |
| 336 for (Frame* child : children_) | 332 for (Frame* child : children_) |
| 337 child->NotifyRemoved(source, removed_node, change_id); | 333 child->NotifyRemoved(source, removed_node, change_id); |
| 338 } | 334 } |
| 339 | 335 |
| 340 void Frame::NotifyClientPropertyChanged(const Frame* source, | 336 void Frame::NotifyClientPropertyChanged(const Frame* source, |
| 341 const mojo::String& name, | 337 const mojo::String& name, |
| 342 const mojo::Array<uint8_t>& value) { | 338 const mojo::Array<uint8_t>& value) { |
| 343 if (this != source) | 339 if (this != source) |
| 344 frame_tree_client_->OnFrameClientPropertyChanged(source->id(), name, | 340 frame_client_->OnFrameClientPropertyChanged(source->id(), name, |
| 345 value.Clone()); | 341 value.Clone()); |
| 346 | 342 |
| 347 for (Frame* child : children_) | 343 for (Frame* child : children_) |
| 348 child->NotifyClientPropertyChanged(source, name, value); | 344 child->NotifyClientPropertyChanged(source, name, value); |
| 349 } | 345 } |
| 350 | 346 |
| 351 void Frame::NotifyFrameLoadingStateChanged(const Frame* frame, bool loading) { | 347 void Frame::NotifyFrameLoadingStateChanged(const Frame* frame, bool loading) { |
| 352 frame_tree_client_->OnFrameLoadingStateChanged(frame->id(), loading); | 348 frame_client_->OnFrameLoadingStateChanged(frame->id(), loading); |
| 353 } | 349 } |
| 354 | 350 |
| 355 void Frame::NotifyDispatchFrameLoadEvent(const Frame* frame) { | 351 void Frame::NotifyDispatchFrameLoadEvent(const Frame* frame) { |
| 356 frame_tree_client_->OnDispatchFrameLoadEvent(frame->id()); | 352 frame_client_->OnDispatchFrameLoadEvent(frame->id()); |
| 357 } | 353 } |
| 358 | 354 |
| 359 void Frame::OnTreeChanged(const TreeChangeParams& params) { | 355 void Frame::OnTreeChanged(const TreeChangeParams& params) { |
| 360 if (params.new_parent && this == tree_->root()) { | 356 if (params.new_parent && this == tree_->root()) { |
| 361 Frame* child_frame = FindFrame(params.target->id()); | 357 Frame* child_frame = FindFrame(params.target->id()); |
| 362 if (child_frame && !child_frame->view_) | 358 if (child_frame && !child_frame->view_) |
| 363 child_frame->SetView(params.target); | 359 child_frame->SetView(params.target); |
| 364 } | 360 } |
| 365 } | 361 } |
| 366 | 362 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 386 // this happens. | 382 // this happens. |
| 387 // | 383 // |
| 388 // Currently we have no way to distinguish between the cases that lead to this | 384 // Currently we have no way to distinguish between the cases that lead to this |
| 389 // being called, so we assume we can continue on. Continuing on is important | 385 // being called, so we assume we can continue on. Continuing on is important |
| 390 // for html as it's entirely possible for a page to create a frame, navigate | 386 // for html as it's entirely possible for a page to create a frame, navigate |
| 391 // to a bogus url and expect the frame to still exist. | 387 // to a bogus url and expect the frame to still exist. |
| 392 tree_->delegate_->OnViewEmbeddedInFrameDisconnected(this); | 388 tree_->delegate_->OnViewEmbeddedInFrameDisconnected(this); |
| 393 } | 389 } |
| 394 | 390 |
| 395 void Frame::PostMessageEventToFrame(uint32_t target_frame_id, | 391 void Frame::PostMessageEventToFrame(uint32_t target_frame_id, |
| 396 HTMLMessageEventPtr event) { | 392 mojom::HTMLMessageEventPtr event) { |
| 397 // NOTE: |target_frame_id| is allowed to be from another connection. | 393 // NOTE: |target_frame_id| is allowed to be from another connection. |
| 398 Frame* target = tree_->root()->FindFrame(target_frame_id); | 394 Frame* target = tree_->root()->FindFrame(target_frame_id); |
| 399 if (!target || target == this || | 395 if (!target || target == this || |
| 400 !tree_->delegate_->CanPostMessageEventToFrame(this, target, event.get())) | 396 !tree_->delegate_->CanPostMessageEventToFrame(this, target, event.get())) |
| 401 return; | 397 return; |
| 402 | 398 |
| 403 target->frame_tree_client_->OnPostMessageEvent(id_, target_frame_id, | 399 target->frame_client_->OnPostMessageEvent(id_, target_frame_id, event.Pass()); |
| 404 event.Pass()); | |
| 405 } | 400 } |
| 406 | 401 |
| 407 void Frame::LoadingStateChanged(bool loading, double progress) { | 402 void Frame::LoadingStateChanged(bool loading, double progress) { |
| 408 bool loading_state_changed = loading_ != loading; | 403 bool loading_state_changed = loading_ != loading; |
| 409 loading_ = loading; | 404 loading_ = loading; |
| 410 progress_ = progress; | 405 progress_ = progress; |
| 411 tree_->LoadingStateChanged(); | 406 tree_->LoadingStateChanged(); |
| 412 | 407 |
| 413 if (loading_state_changed && parent_ && | 408 if (loading_state_changed && parent_ && |
| 414 !AreAppIdsEqual(app_id_, parent_->app_id_)) { | 409 !AreAppIdsEqual(app_id_, parent_->app_id_)) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 441 } else { | 436 } else { |
| 442 std::vector<uint8_t> as_vector(value.To<std::vector<uint8_t>>()); | 437 std::vector<uint8_t> as_vector(value.To<std::vector<uint8_t>>()); |
| 443 if (already_in_map && iter->second == as_vector) | 438 if (already_in_map && iter->second == as_vector) |
| 444 return; | 439 return; |
| 445 client_properties_[name] = as_vector; | 440 client_properties_[name] = as_vector; |
| 446 } | 441 } |
| 447 tree_->ClientPropertyChanged(this, name, value); | 442 tree_->ClientPropertyChanged(this, name, value); |
| 448 } | 443 } |
| 449 | 444 |
| 450 void Frame::OnCreatedFrame( | 445 void Frame::OnCreatedFrame( |
| 451 mojo::InterfaceRequest<FrameTreeServer> server_request, | 446 mojo::InterfaceRequest<mojom::Frame> frame_request, |
| 452 FrameTreeClientPtr client, | 447 mojom::FrameClientPtr client, |
| 453 uint32_t frame_id, | 448 uint32_t frame_id, |
| 454 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) { | 449 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) { |
| 455 if ((frame_id >> 16) != embedded_connection_id_) { | 450 if ((frame_id >> 16) != embedded_connection_id_) { |
| 456 // TODO(sky): kill connection here? | 451 // TODO(sky): kill connection here? |
| 457 // TODO(sky): there is a race in that there is no guarantee we received the | 452 // TODO(sky): there is a race in that there is no guarantee we received the |
| 458 // connection id before the frame tries to create a new frame. Ideally we | 453 // connection id before the frame tries to create a new frame. Ideally we |
| 459 // could pause the frame until we get the connection id, but bindings don't | 454 // could pause the frame until we get the connection id, but bindings don't |
| 460 // offer such an API. | 455 // offer such an API. |
| 461 DVLOG(1) << "OnCreatedFrame supplied invalid frame id, expecting" | 456 DVLOG(1) << "OnCreatedFrame supplied invalid frame id, expecting" |
| 462 << embedded_connection_id_; | 457 << embedded_connection_id_; |
| 463 return; | 458 return; |
| 464 } | 459 } |
| 465 | 460 |
| 466 if (FindFrame(frame_id)) { | 461 if (FindFrame(frame_id)) { |
| 467 // TODO(sky): kill connection here? | 462 // TODO(sky): kill connection here? |
| 468 DVLOG(1) << "OnCreatedFrame supplied id of existing frame."; | 463 DVLOG(1) << "OnCreatedFrame supplied id of existing frame."; |
| 469 return; | 464 return; |
| 470 } | 465 } |
| 471 | 466 |
| 472 Frame* child_frame = tree_->CreateChildFrame( | 467 Frame* child_frame = tree_->CreateChildFrame( |
| 473 this, server_request.Pass(), client.Pass(), frame_id, app_id_, | 468 this, frame_request.Pass(), client.Pass(), frame_id, app_id_, |
| 474 client_properties.To<ClientPropertyMap>()); | 469 client_properties.To<ClientPropertyMap>()); |
| 475 child_frame->embedded_connection_id_ = embedded_connection_id_; | 470 child_frame->embedded_connection_id_ = embedded_connection_id_; |
| 476 } | 471 } |
| 477 | 472 |
| 478 void Frame::RequestNavigate(NavigationTargetType target_type, | 473 void Frame::RequestNavigate(mojom::NavigationTargetType target_type, |
| 479 uint32_t target_frame_id, | 474 uint32_t target_frame_id, |
| 480 mojo::URLRequestPtr request) { | 475 mojo::URLRequestPtr request) { |
| 481 if (target_type == NAVIGATION_TARGET_TYPE_EXISTING_FRAME) { | 476 if (target_type == mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME) { |
| 482 // |target_frame| is allowed to come from another connection. | 477 // |target_frame| is allowed to come from another connection. |
| 483 Frame* target_frame = tree_->root()->FindFrame(target_frame_id); | 478 Frame* target_frame = tree_->root()->FindFrame(target_frame_id); |
| 484 if (!target_frame) { | 479 if (!target_frame) { |
| 485 DVLOG(1) << "RequestNavigate EXISTING_FRAME with no matching frame"; | 480 DVLOG(1) << "RequestNavigate EXISTING_FRAME with no matching frame"; |
| 486 return; | 481 return; |
| 487 } | 482 } |
| 488 if (target_frame != tree_->root()) { | 483 if (target_frame != tree_->root()) { |
| 489 target_frame->StartNavigate(request.Pass()); | 484 target_frame->StartNavigate(request.Pass()); |
| 490 return; | 485 return; |
| 491 } | 486 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 502 if (parent_ && !AreAppIdsEqual(app_id_, parent_->app_id_)) { | 497 if (parent_ && !AreAppIdsEqual(app_id_, parent_->app_id_)) { |
| 503 // Send notification to fire a load event in the parent, if the parent is in | 498 // Send notification to fire a load event in the parent, if the parent is in |
| 504 // a different app. If the parent is in the same app, we assume that the app | 499 // a different app. If the parent is in the same app, we assume that the app |
| 505 // itself handles firing load event directly and no notification is needed | 500 // itself handles firing load event directly and no notification is needed |
| 506 // from our side. | 501 // from our side. |
| 507 parent_->NotifyDispatchFrameLoadEvent(this); | 502 parent_->NotifyDispatchFrameLoadEvent(this); |
| 508 } | 503 } |
| 509 } | 504 } |
| 510 | 505 |
| 511 } // namespace web_view | 506 } // namespace web_view |
| OLD | NEW |