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/common/tracing_impl.h" |
| 9 #include "mojo/public/c/system/main.h" |
| 10 #include "mojo/public/cpp/application/application_connection.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" |
| 12 #include "mojo/services/view_manager/client_connection.h" |
| 13 #include "mojo/services/view_manager/connection_manager.h" |
| 14 #include "mojo/services/view_manager/display_manager.h" |
| 15 #include "mojo/services/view_manager/view_manager_service_impl.h" |
| 16 |
| 17 using mojo::ApplicationConnection; |
| 18 using mojo::ApplicationImpl; |
| 19 using mojo::InterfaceRequest; |
| 20 using mojo::ViewManagerService; |
| 21 using mojo::WindowManagerInternalClient; |
| 22 |
| 23 namespace view_manager { |
| 24 |
| 25 ViewManagerApp::ViewManagerApp() |
| 26 : app_impl_(nullptr), wm_app_connection_(nullptr) { |
| 27 } |
| 28 |
| 29 ViewManagerApp::~ViewManagerApp() {} |
| 30 |
| 31 void ViewManagerApp::Initialize(ApplicationImpl* app) { |
| 32 app_impl_ = app; |
| 33 tracing_.Initialize(app); |
| 34 } |
| 35 |
| 36 bool ViewManagerApp::ConfigureIncomingConnection( |
| 37 ApplicationConnection* connection) { |
| 38 if (connection_manager_.get()) { |
| 39 VLOG(1) << "ViewManager allows only one window manager connection."; |
| 40 return false; |
| 41 } |
| 42 wm_app_connection_ = connection; |
| 43 // |connection| originates from the WindowManager. Let it connect directly |
| 44 // to the ViewManager and WindowManagerInternalClient. |
| 45 connection->AddService<ViewManagerService>(this); |
| 46 connection->AddService<WindowManagerInternalClient>(this); |
| 47 connection->ConnectToService(&wm_internal_); |
| 48 // If no ServiceProvider has been sent, refuse the connection. |
| 49 if (!wm_internal_) |
| 50 return false; |
| 51 wm_internal_.set_error_handler(this); |
| 52 |
| 53 scoped_ptr<DefaultDisplayManager> display_manager(new DefaultDisplayManager( |
| 54 app_impl_, connection, |
| 55 base::Bind(&ViewManagerApp::OnLostConnectionToWindowManager, |
| 56 base::Unretained(this)))); |
| 57 connection_manager_.reset( |
| 58 new ConnectionManager(this, display_manager.Pass(), wm_internal_.get())); |
| 59 return true; |
| 60 } |
| 61 |
| 62 void ViewManagerApp::OnLostConnectionToWindowManager() { |
| 63 ApplicationImpl::Terminate(); |
| 64 } |
| 65 |
| 66 ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView( |
| 67 ConnectionManager* connection_manager, |
| 68 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, |
| 69 mojo::ConnectionSpecificId creator_id, |
| 70 const std::string& creator_url, |
| 71 const std::string& url, |
| 72 const ViewId& root_id) { |
| 73 mojo::ViewManagerClientPtr client; |
| 74 app_impl_->ConnectToService(url, &client); |
| 75 |
| 76 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( |
| 77 connection_manager, creator_id, creator_url, url, root_id)); |
| 78 return new DefaultClientConnection(service.Pass(), connection_manager, |
| 79 service_request.Pass(), client.Pass()); |
| 80 } |
| 81 |
| 82 ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView( |
| 83 ConnectionManager* connection_manager, |
| 84 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, |
| 85 mojo::ConnectionSpecificId creator_id, |
| 86 const std::string& creator_url, |
| 87 const ViewId& root_id, |
| 88 mojo::ViewManagerClientPtr view_manager_client) { |
| 89 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( |
| 90 connection_manager, creator_id, creator_url, std::string(), root_id)); |
| 91 return new DefaultClientConnection(service.Pass(), connection_manager, |
| 92 service_request.Pass(), |
| 93 view_manager_client.Pass()); |
| 94 } |
| 95 |
| 96 void ViewManagerApp::Create(ApplicationConnection* connection, |
| 97 InterfaceRequest<ViewManagerService> request) { |
| 98 if (connection_manager_->has_window_manager_client_connection()) { |
| 99 VLOG(1) << "ViewManager interface requested more than once."; |
| 100 return; |
| 101 } |
| 102 |
| 103 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( |
| 104 connection_manager_.get(), kInvalidConnectionId, std::string(), |
| 105 std::string("mojo:window_manager"), RootViewId())); |
| 106 mojo::ViewManagerClientPtr client; |
| 107 wm_internal_client_request_ = GetProxy(&client); |
| 108 scoped_ptr<ClientConnection> client_connection( |
| 109 new DefaultClientConnection(service.Pass(), connection_manager_.get(), |
| 110 request.Pass(), client.Pass())); |
| 111 connection_manager_->SetWindowManagerClientConnection( |
| 112 client_connection.Pass()); |
| 113 } |
| 114 |
| 115 void ViewManagerApp::Create( |
| 116 ApplicationConnection* connection, |
| 117 InterfaceRequest<WindowManagerInternalClient> request) { |
| 118 if (wm_internal_client_binding_.get()) { |
| 119 VLOG(1) << "WindowManagerInternalClient requested more than once."; |
| 120 return; |
| 121 } |
| 122 |
| 123 // ConfigureIncomingConnection() must have been called before getting here. |
| 124 DCHECK(connection_manager_.get()); |
| 125 wm_internal_client_binding_.reset( |
| 126 new mojo::Binding<WindowManagerInternalClient>(connection_manager_.get(), |
| 127 request.Pass())); |
| 128 wm_internal_client_binding_->set_error_handler(this); |
| 129 wm_internal_->SetViewManagerClient( |
| 130 wm_internal_client_request_.PassMessagePipe()); |
| 131 } |
| 132 |
| 133 void ViewManagerApp::OnConnectionError() { |
| 134 ApplicationImpl::Terminate(); |
| 135 } |
| 136 |
| 137 } // namespace view_manager |
OLD | NEW |