| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/services/view_manager/view_manager_app.h" | |
| 6 | |
| 7 #include "mojo/application/application_runner_chromium.h" | |
| 8 #include "mojo/public/c/system/main.h" | |
| 9 #include "mojo/public/cpp/application/application_connection.h" | |
| 10 #include "mojo/public/cpp/application/application_impl.h" | |
| 11 #include "mojo/services/view_manager/client_connection.h" | |
| 12 #include "mojo/services/view_manager/connection_manager.h" | |
| 13 #include "mojo/services/view_manager/display_manager.h" | |
| 14 #include "mojo/services/view_manager/view_manager_service_impl.h" | |
| 15 | |
| 16 namespace mojo { | |
| 17 namespace service { | |
| 18 | |
| 19 ViewManagerApp::ViewManagerApp() : wm_app_connection_(nullptr) { | |
| 20 } | |
| 21 ViewManagerApp::~ViewManagerApp() {} | |
| 22 | |
| 23 bool ViewManagerApp::ConfigureIncomingConnection( | |
| 24 ApplicationConnection* connection) { | |
| 25 if (connection_manager_.get()) { | |
| 26 VLOG(1) << "ViewManager allows only one window manager connection."; | |
| 27 return false; | |
| 28 } | |
| 29 wm_app_connection_ = connection; | |
| 30 // |connection| originates from the WindowManager. Let it connect directly | |
| 31 // to the ViewManager and WindowManagerInternalClient. | |
| 32 connection->AddService( | |
| 33 static_cast<InterfaceFactory<ViewManagerService>*>(this)); | |
| 34 connection->AddService( | |
| 35 static_cast<InterfaceFactory<WindowManagerInternalClient>*>(this)); | |
| 36 connection->ConnectToService(&wm_internal_); | |
| 37 // TODO(sky): add this back. It's causing tests to hang, figure out why. | |
| 38 // wm_internal_.set_error_handler(this); | |
| 39 | |
| 40 scoped_ptr<DefaultDisplayManager> display_manager(new DefaultDisplayManager( | |
| 41 connection, base::Bind(&ViewManagerApp::OnLostConnectionToWindowManager, | |
| 42 base::Unretained(this)))); | |
| 43 connection_manager_.reset( | |
| 44 new ConnectionManager(this, display_manager.Pass(), wm_internal_.get())); | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 void ViewManagerApp::OnLostConnectionToWindowManager() { | |
| 49 ApplicationImpl::Terminate(); | |
| 50 } | |
| 51 | |
| 52 ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView( | |
| 53 ConnectionManager* connection_manager, | |
| 54 ConnectionSpecificId creator_id, | |
| 55 const std::string& creator_url, | |
| 56 const std::string& url, | |
| 57 const ViewId& root_id) { | |
| 58 MessagePipe pipe; | |
| 59 | |
| 60 ServiceProvider* view_manager_service_provider = | |
| 61 wm_app_connection_->ConnectToApplication(url)->GetServiceProvider(); | |
| 62 view_manager_service_provider->ConnectToService( | |
| 63 ViewManagerServiceImpl::Client::Name_, pipe.handle1.Pass()); | |
| 64 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( | |
| 65 connection_manager, creator_id, creator_url, url, root_id)); | |
| 66 return new DefaultClientConnection(service.Pass(), connection_manager, | |
| 67 pipe.handle0.Pass()); | |
| 68 } | |
| 69 | |
| 70 void ViewManagerApp::Create(ApplicationConnection* connection, | |
| 71 InterfaceRequest<ViewManagerService> request) { | |
| 72 if (connection_manager_->has_window_manager_client_connection()) { | |
| 73 VLOG(1) << "ViewManager interface requested more than once."; | |
| 74 return; | |
| 75 } | |
| 76 | |
| 77 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( | |
| 78 connection_manager_.get(), kInvalidConnectionId, std::string(), | |
| 79 std::string("mojo:window_manager"), RootViewId())); | |
| 80 scoped_ptr<ClientConnection> client_connection(new DefaultClientConnection( | |
| 81 service.Pass(), connection_manager_.get(), request.PassMessagePipe())); | |
| 82 connection_manager_->SetWindowManagerClientConnection( | |
| 83 client_connection.Pass()); | |
| 84 } | |
| 85 | |
| 86 void ViewManagerApp::Create( | |
| 87 ApplicationConnection* connection, | |
| 88 InterfaceRequest<WindowManagerInternalClient> request) { | |
| 89 if (wm_internal_client_binding_.get()) { | |
| 90 VLOG(1) << "WindowManagerInternalClient requested more than once."; | |
| 91 return; | |
| 92 } | |
| 93 | |
| 94 // ConfigureIncomingConnection() must have been called before getting here. | |
| 95 DCHECK(connection_manager_.get()); | |
| 96 wm_internal_client_binding_.reset(new Binding<WindowManagerInternalClient>( | |
| 97 connection_manager_.get(), request.Pass())); | |
| 98 wm_internal_client_binding_->set_error_handler(this); | |
| 99 } | |
| 100 | |
| 101 void ViewManagerApp::OnConnectionError() { | |
| 102 ApplicationImpl::Terminate(); | |
| 103 } | |
| 104 | |
| 105 } // namespace service | |
| 106 } // namespace mojo | |
| OLD | NEW |