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

Side by Side Diff: components/window_manager/window_manager_app.cc

Issue 1138073007: Nukes the windowmanager interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 7 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
OLDNEW
(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 "components/window_manager/window_manager_app.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/stl_util.h"
9 #include "components/view_manager/public/cpp/view.h"
10 #include "components/view_manager/public/cpp/view_manager.h"
11 #include "components/window_manager/window_manager_delegate.h"
12 #include "mojo/application/public/cpp/application_connection.h"
13 #include "mojo/application/public/cpp/application_impl.h"
14 #include "mojo/application/public/interfaces/shell.mojom.h"
15 #include "mojo/converters/geometry/geometry_type_converters.h"
16
17 using mojo::ApplicationConnection;
18 using mojo::Id;
19 using mojo::ServiceProvider;
20 using mojo::View;
21 using mojo::WindowManager;
22
23 namespace window_manager {
24
25 // Used for calls to Embed() that occur before we've connected to the
26 // ViewManager.
27 struct WindowManagerApp::PendingEmbed {
28 mojo::String url;
29 mojo::InterfaceRequest<ServiceProvider> services;
30 mojo::ServiceProviderPtr exposed_services;
31 };
32
33 ////////////////////////////////////////////////////////////////////////////////
34 // WindowManagerApp, public:
35
36 WindowManagerApp::WindowManagerApp(
37 ViewManagerDelegate* view_manager_delegate,
38 WindowManagerDelegate* window_manager_delegate)
39 : shell_(nullptr),
40 wrapped_view_manager_delegate_(view_manager_delegate),
41 window_manager_delegate_(window_manager_delegate),
42 root_(nullptr) {
43 }
44
45 WindowManagerApp::~WindowManagerApp() {
46 // TODO(msw|sky): Should this destructor explicitly delete the ViewManager?
47 if (root_)
48 root_->RemoveObserver(this);
49
50 STLDeleteElements(&connections_);
51 }
52
53 void WindowManagerApp::AddConnection(WindowManagerImpl* connection) {
54 DCHECK(connections_.find(connection) == connections_.end());
55 connections_.insert(connection);
56 }
57
58 void WindowManagerApp::RemoveConnection(WindowManagerImpl* connection) {
59 DCHECK(connections_.find(connection) != connections_.end());
60 connections_.erase(connection);
61 }
62
63 bool WindowManagerApp::IsReady() const {
64 return !!root_;
65 }
66
67 void WindowManagerApp::AddAccelerator(mojo::KeyboardCode keyboard_code,
68 mojo::EventFlags flags) {
69 window_manager_client_->AddAccelerator(keyboard_code, flags);
70 }
71
72 void WindowManagerApp::Embed(
73 const mojo::String& url,
74 mojo::InterfaceRequest<mojo::ServiceProvider> services,
75 mojo::ServiceProviderPtr exposed_services) {
76 if (view_manager()) {
77 window_manager_delegate_->Embed(url, services.Pass(),
78 exposed_services.Pass());
79 return;
80 }
81 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed);
82 pending_embed->url = url;
83 pending_embed->services = services.Pass();
84 pending_embed->exposed_services = exposed_services.Pass();
85 pending_embeds_.push_back(pending_embed.release());
86 }
87
88 ////////////////////////////////////////////////////////////////////////////////
89 // WindowManagerApp, ApplicationDelegate implementation:
90
91 void WindowManagerApp::Initialize(mojo::ApplicationImpl* impl) {
92 shell_ = impl->shell();
93 LaunchViewManager(impl);
94 }
95
96 bool WindowManagerApp::ConfigureIncomingConnection(
97 ApplicationConnection* connection) {
98 connection->AddService<WindowManager>(this);
99 return true;
100 }
101
102 ////////////////////////////////////////////////////////////////////////////////
103 // WindowManagerApp, ViewManagerDelegate implementation:
104
105 void WindowManagerApp::OnEmbed(
106 View* root,
107 mojo::InterfaceRequest<mojo::ServiceProvider> services,
108 mojo::ServiceProviderPtr exposed_services) {
109 DCHECK(!root_);
110 root_ = root;
111
112 root_->AddObserver(this);
113
114 if (wrapped_view_manager_delegate_) {
115 wrapped_view_manager_delegate_->OnEmbed(root, services.Pass(),
116 exposed_services.Pass());
117 }
118
119 for (PendingEmbed* pending_embed : pending_embeds_) {
120 Embed(pending_embed->url, pending_embed->services.Pass(),
121 pending_embed->exposed_services.Pass());
122 }
123 pending_embeds_.clear();
124 }
125
126 void WindowManagerApp::OnViewManagerDisconnected(
127 mojo::ViewManager* view_manager) {
128 if (wrapped_view_manager_delegate_)
129 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager);
130
131 base::MessageLoop* message_loop = base::MessageLoop::current();
132 if (message_loop && message_loop->is_running())
133 message_loop->Quit();
134 }
135
136 ////////////////////////////////////////////////////////////////////////////////
137 // WindowManagerApp, ViewObserver implementation:
138
139 void WindowManagerApp::OnViewDestroying(View* view) {
140 DCHECK_EQ(root_, view);
141 root_->RemoveObserver(this);
142 root_ = nullptr;
143 }
144
145 ////////////////////////////////////////////////////////////////////////////////
146 // WindowManagerApp, private:
147
148 void WindowManagerApp::DispatchInputEventToViewDEPRECATED(
149 View* view,
150 mojo::EventPtr event) {
151 window_manager_client_->DispatchInputEventToViewDEPRECATED(view->id(),
152 event.Pass());
153 }
154
155 void WindowManagerApp::SetViewportSize(const gfx::Size& size) {
156 window_manager_client_->SetViewportSize(mojo::Size::From(size));
157 }
158
159 void WindowManagerApp::LaunchViewManager(mojo::ApplicationImpl* app) {
160 // TODO(sky): figure out logic if this connection goes away.
161 view_manager_client_factory_.reset(
162 new mojo::ViewManagerClientFactory(shell_, this));
163
164 ApplicationConnection* view_manager_app =
165 app->ConnectToApplication("mojo:view_manager");
166 view_manager_app->ConnectToService(&view_manager_service_);
167
168 view_manager_app->AddService<WindowManagerInternal>(this);
169
170 view_manager_app->ConnectToService(&window_manager_client_);
171 }
172
173 void WindowManagerApp::Create(
174 ApplicationConnection* connection,
175 mojo::InterfaceRequest<WindowManagerInternal> request) {
176 if (wm_internal_binding_.get()) {
177 VLOG(1) <<
178 "WindowManager allows only one WindowManagerInternal connection.";
179 return;
180 }
181 wm_internal_binding_.reset(
182 new mojo::Binding<WindowManagerInternal>(this, request.Pass()));
183 }
184
185 void WindowManagerApp::Create(ApplicationConnection* connection,
186 mojo::InterfaceRequest<WindowManager> request) {
187 WindowManagerImpl* wm = new WindowManagerImpl(this, false);
188 wm->Bind(request.PassMessagePipe());
189 // WindowManagerImpl is deleted when the connection has an error, or from our
190 // destructor.
191 }
192
193 void WindowManagerApp::SetViewManagerClient(
194 mojo::ScopedMessagePipeHandle view_manager_client_request) {
195 view_manager_client_.reset(
196 mojo::ViewManagerClientFactory::WeakBindViewManagerToPipe(
197 mojo::MakeRequest<mojo::ViewManagerClient>(
198 view_manager_client_request.Pass()),
199 view_manager_service_.Pass(), shell_, this));
200 }
201
202 void WindowManagerApp::OnAccelerator(mojo::EventPtr event) {
203 window_manager_delegate_->OnAcceleratorPressed(
204 root_->view_manager()->GetFocusedView(),
205 event->key_data->windows_key_code, event->flags);
206 }
207
208 } // namespace window_manager
OLDNEW
« no previous file with comments | « components/window_manager/window_manager_app.h ('k') | components/window_manager/window_manager_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698