| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "view_manager/public/cpp/lib/view_manager_client_impl.h" | 5 #include "view_manager/public/cpp/lib/view_manager_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "mojo/public/cpp/application/application_impl.h" | 10 #include "mojo/public/cpp/application/application_impl.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 const std::string& name, | 188 const std::string& name, |
| 189 const std::vector<uint8_t>& data) { | 189 const std::vector<uint8_t>& data) { |
| 190 DCHECK(connected_); | 190 DCHECK(connected_); |
| 191 service_->SetViewProperty(view_id, | 191 service_->SetViewProperty(view_id, |
| 192 String(name), | 192 String(name), |
| 193 Array<uint8_t>::From(data), | 193 Array<uint8_t>::From(data), |
| 194 ActionCompletedCallback()); | 194 ActionCompletedCallback()); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { | 197 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { |
| 198 MessagePipe pipe; | 198 Embed(url, view_id, nullptr, nullptr); |
| 199 InterfaceRequest<ServiceProvider> request; | |
| 200 request.Bind(pipe.handle0.Pass()); | |
| 201 Embed(url, view_id, request.Pass()); | |
| 202 } | 199 } |
| 203 | 200 |
| 204 void ViewManagerClientImpl::Embed( | 201 void ViewManagerClientImpl::Embed( |
| 205 const String& url, | 202 const String& url, |
| 206 Id view_id, | 203 Id view_id, |
| 207 InterfaceRequest<ServiceProvider> service_provider) { | 204 InterfaceRequest<ServiceProvider> parent_services, |
| 205 ServiceProviderPtr parent_exposed_services) { |
| 208 DCHECK(connected_); | 206 DCHECK(connected_); |
| 209 service_->Embed(url, view_id, service_provider.Pass(), | 207 service_->Embed(url, view_id, parent_services.Pass(), |
| 210 ActionCompletedCallback()); | 208 parent_exposed_services.Pass(), ActionCompletedCallback()); |
| 211 } | 209 } |
| 212 | 210 |
| 213 void ViewManagerClientImpl::AddView(View* view) { | 211 void ViewManagerClientImpl::AddView(View* view) { |
| 214 DCHECK(views_.find(view->id()) == views_.end()); | 212 DCHECK(views_.find(view->id()) == views_.end()); |
| 215 views_[view->id()] = view; | 213 views_[view->id()] = view; |
| 216 } | 214 } |
| 217 | 215 |
| 218 void ViewManagerClientImpl::RemoveView(Id view_id) { | 216 void ViewManagerClientImpl::RemoveView(Id view_id) { |
| 219 IdToViewMap::iterator it = views_.find(view_id); | 217 IdToViewMap::iterator it = views_.find(view_id); |
| 220 if (it != views_.end()) | 218 if (it != views_.end()) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 } | 253 } |
| 256 | 254 |
| 257 //////////////////////////////////////////////////////////////////////////////// | 255 //////////////////////////////////////////////////////////////////////////////// |
| 258 // ViewManagerClientImpl, ViewManagerClient implementation: | 256 // ViewManagerClientImpl, ViewManagerClient implementation: |
| 259 | 257 |
| 260 void ViewManagerClientImpl::OnEmbed( | 258 void ViewManagerClientImpl::OnEmbed( |
| 261 ConnectionSpecificId connection_id, | 259 ConnectionSpecificId connection_id, |
| 262 const String& creator_url, | 260 const String& creator_url, |
| 263 ViewDataPtr root_data, | 261 ViewDataPtr root_data, |
| 264 InterfaceRequest<ServiceProvider> parent_services, | 262 InterfaceRequest<ServiceProvider> parent_services, |
| 263 ServiceProviderPtr parent_exposed_services, |
| 265 ScopedMessagePipeHandle window_manager_pipe) { | 264 ScopedMessagePipeHandle window_manager_pipe) { |
| 266 DCHECK(!connected_); | 265 DCHECK(!connected_); |
| 267 connected_ = true; | 266 connected_ = true; |
| 268 connection_id_ = connection_id; | 267 connection_id_ = connection_id; |
| 269 creator_url_ = String::From(creator_url); | 268 creator_url_ = String::From(creator_url); |
| 270 | 269 |
| 271 DCHECK(!root_); | 270 DCHECK(!root_); |
| 272 root_ = AddViewToViewManager(this, nullptr, root_data); | 271 root_ = AddViewToViewManager(this, nullptr, root_data); |
| 273 root_->AddObserver(new RootObserver(root_)); | 272 root_->AddObserver(new RootObserver(root_)); |
| 274 | 273 |
| 275 ServiceProviderImpl* exported_services = nullptr; | |
| 276 scoped_ptr<ServiceProvider> remote; | |
| 277 | |
| 278 // BindToRequest() binds the lifetime of |exported_services| to the pipe. | |
| 279 exported_services = new ServiceProviderImpl; | |
| 280 BindToRequest(exported_services, &parent_services); | |
| 281 remote.reset(exported_services->CreateRemoteServiceProvider()); | |
| 282 | |
| 283 window_manager_.Bind(window_manager_pipe.Pass()); | 274 window_manager_.Bind(window_manager_pipe.Pass()); |
| 284 window_manager_.set_client(this); | 275 window_manager_.set_client(this); |
| 285 // base::Unretained() is safe here as |window_manager_| is bound to our | 276 // base::Unretained() is safe here as |window_manager_| is bound to our |
| 286 // lifetime. | 277 // lifetime. |
| 287 window_manager_->GetFocusedAndActiveViews( | 278 window_manager_->GetFocusedAndActiveViews( |
| 288 base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews, | 279 base::Bind(&ViewManagerClientImpl::OnGotFocusedAndActiveViews, |
| 289 base::Unretained(this))); | 280 base::Unretained(this))); |
| 290 delegate_->OnEmbed(root_, exported_services, remote.Pass()); | 281 |
| 282 delegate_->OnEmbed(root_, parent_services.Pass(), |
| 283 parent_exposed_services.Pass()); |
| 291 } | 284 } |
| 292 | 285 |
| 293 void ViewManagerClientImpl::OnEmbeddedAppDisconnected(Id view_id) { | 286 void ViewManagerClientImpl::OnEmbeddedAppDisconnected(Id view_id) { |
| 294 View* view = GetViewById(view_id); | 287 View* view = GetViewById(view_id); |
| 295 if (view) { | 288 if (view) { |
| 296 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), | 289 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view).observers(), |
| 297 OnViewEmbeddedAppDisconnected(view)); | 290 OnViewEmbeddedAppDisconnected(view)); |
| 298 } | 291 } |
| 299 } | 292 } |
| 300 | 293 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 uint32 active_view_id) { | 470 uint32 active_view_id) { |
| 478 if (GetViewById(focused_view_id) != focused_view_) | 471 if (GetViewById(focused_view_id) != focused_view_) |
| 479 OnFocusChanged(focused_view_ ? focused_view_->id() : 0, focused_view_id); | 472 OnFocusChanged(focused_view_ ? focused_view_->id() : 0, focused_view_id); |
| 480 if (GetViewById(active_view_id) != activated_view_) { | 473 if (GetViewById(active_view_id) != activated_view_) { |
| 481 OnActiveWindowChanged(activated_view_ ? activated_view_->id() : 0, | 474 OnActiveWindowChanged(activated_view_ ? activated_view_->id() : 0, |
| 482 active_view_id); | 475 active_view_id); |
| 483 } | 476 } |
| 484 } | 477 } |
| 485 | 478 |
| 486 } // namespace mojo | 479 } // namespace mojo |
| OLD | NEW |