OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/i18n/icu_util.h" | 11 #include "base/i18n/icu_util.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "mojo/aura/screen_mojo.h" | 15 #include "mojo/aura/screen_mojo.h" |
16 #include "mojo/aura/window_tree_host_mojo.h" | 16 #include "mojo/aura/window_tree_host_mojo.h" |
17 #include "mojo/examples/launcher/launcher.mojom.h" | 17 #include "mojo/examples/launcher/launcher.mojom.h" |
18 #include "mojo/public/cpp/bindings/allocation_scope.h" | 18 #include "mojo/public/cpp/bindings/allocation_scope.h" |
19 #include "mojo/public/cpp/bindings/remote_ptr.h" | |
20 #include "mojo/public/cpp/gles2/gles2.h" | 19 #include "mojo/public/cpp/gles2/gles2.h" |
21 #include "mojo/public/cpp/shell/application.h" | 20 #include "mojo/public/cpp/shell/application.h" |
22 #include "mojo/public/cpp/system/core.h" | 21 #include "mojo/public/cpp/system/core.h" |
23 #include "mojo/public/interfaces/shell/shell.mojom.h" | 22 #include "mojo/public/interfaces/shell/shell.mojom.h" |
24 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 23 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
25 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
26 #include "ui/aura/client/default_capture_client.h" | 25 #include "ui/aura/client/default_capture_client.h" |
27 #include "ui/aura/client/window_tree_client.h" | 26 #include "ui/aura/client/window_tree_client.h" |
28 #include "ui/aura/env.h" | 27 #include "ui/aura/env.h" |
29 #include "ui/aura/test/test_focus_client.h" | 28 #include "ui/aura/test/test_focus_client.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 url_receiver_->OnURLEntered(url.spec()); | 181 url_receiver_->OnURLEntered(url.spec()); |
183 } | 182 } |
184 return false; | 183 return false; |
185 } | 184 } |
186 | 185 |
187 URLReceiver* url_receiver_; | 186 URLReceiver* url_receiver_; |
188 | 187 |
189 DISALLOW_COPY_AND_ASSIGN(LauncherController); | 188 DISALLOW_COPY_AND_ASSIGN(LauncherController); |
190 }; | 189 }; |
191 | 190 |
192 class LauncherImpl : public Application, | 191 class LauncherImpl : public ServiceConnection<Launcher, LauncherImpl>, |
193 public Launcher, | |
194 public URLReceiver { | 192 public URLReceiver { |
195 public: | 193 public: |
196 explicit LauncherImpl(MojoHandle shell_handle) | 194 LauncherImpl() |
197 : Application(shell_handle), | 195 : launcher_controller_(this), |
198 launcher_controller_(this), | 196 launcher_client_(NULL), |
199 pending_show_(false) { | 197 pending_show_(false) { |
| 198 } |
| 199 |
| 200 void Initialize() { |
200 screen_.reset(ScreenMojo::Create()); | 201 screen_.reset(ScreenMojo::Create()); |
201 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 202 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
202 | 203 |
203 InterfacePipe<NativeViewport, AnyInterface> pipe; | 204 NativeViewportPtr viewport; |
204 | 205 ConnectTo(shell(), "mojo:mojo_native_viewport_service", &viewport); |
205 AllocationScope scope; | |
206 shell()->Connect("mojo:mojo_native_viewport_service", | |
207 pipe.handle_to_peer.Pass()); | |
208 | 206 |
209 window_tree_host_.reset(new WindowTreeHostMojo( | 207 window_tree_host_.reset(new WindowTreeHostMojo( |
210 pipe.handle_to_self.Pass(), gfx::Rect(50, 50, 450, 60), | 208 viewport.Pass(), gfx::Rect(50, 50, 450, 60), |
211 base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this)))); | 209 base::Bind(&LauncherImpl::HostContextCreated, base::Unretained(this)))); |
212 } | 210 } |
213 | 211 |
214 private: | 212 private: |
215 // Overridden from Application: | 213 // Overridden from Launcher: |
216 virtual void AcceptConnection(const mojo::String& url, | 214 virtual void SetClient(LauncherClient* client) OVERRIDE { |
217 ScopedMessagePipeHandle handle) OVERRIDE { | 215 launcher_client_ = client; |
218 launcher_client_.reset( | |
219 MakeScopedHandle(LauncherClientHandle(handle.release().value())).Pass(), | |
220 this); | |
221 } | 216 } |
222 | |
223 // Overridden from Launcher: | |
224 virtual void Show() OVERRIDE { | 217 virtual void Show() OVERRIDE { |
225 if (!window_tree_host_.get()) { | 218 if (!window_tree_host_.get()) { |
226 pending_show_ = true; | 219 pending_show_ = true; |
227 return; | 220 return; |
228 } | 221 } |
229 window_tree_host_->Show(); | 222 window_tree_host_->Show(); |
230 } | 223 } |
231 virtual void Hide() OVERRIDE { | 224 virtual void Hide() OVERRIDE { |
232 window_tree_host_->Hide(); | 225 window_tree_host_->Hide(); |
233 } | 226 } |
(...skipping 28 matching lines...) Expand all Loading... |
262 } | 255 } |
263 | 256 |
264 scoped_ptr<ScreenMojo> screen_; | 257 scoped_ptr<ScreenMojo> screen_; |
265 scoped_ptr<LauncherWindowTreeClient> window_tree_client_; | 258 scoped_ptr<LauncherWindowTreeClient> window_tree_client_; |
266 scoped_ptr<aura::client::FocusClient> focus_client_; | 259 scoped_ptr<aura::client::FocusClient> focus_client_; |
267 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | 260 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
268 scoped_ptr<ui::EventHandler> ime_filter_; | 261 scoped_ptr<ui::EventHandler> ime_filter_; |
269 | 262 |
270 LauncherController launcher_controller_; | 263 LauncherController launcher_controller_; |
271 | 264 |
272 RemotePtr<LauncherClient> launcher_client_; | 265 LauncherClient* launcher_client_; |
273 scoped_ptr<aura::WindowTreeHost> window_tree_host_; | 266 scoped_ptr<aura::WindowTreeHost> window_tree_host_; |
274 | 267 |
275 bool pending_show_; | 268 bool pending_show_; |
276 }; | 269 }; |
277 | 270 |
278 } // namespace examples | 271 } // namespace examples |
279 } // namespace mojo | 272 } // namespace mojo |
280 | 273 |
281 extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain( | 274 extern "C" LAUNCHER_EXPORT MojoResult CDECL MojoMain( |
282 MojoHandle shell_handle) { | 275 MojoHandle shell_handle) { |
283 CommandLine::Init(0, NULL); | 276 CommandLine::Init(0, NULL); |
284 base::AtExitManager at_exit; | 277 base::AtExitManager at_exit; |
285 base::i18n::InitializeICU(); | 278 base::i18n::InitializeICU(); |
286 | 279 |
287 base::FilePath pak_dir; | 280 base::FilePath pak_dir; |
288 PathService::Get(base::DIR_MODULE, &pak_dir); | 281 PathService::Get(base::DIR_MODULE, &pak_dir); |
289 base::FilePath pak_file; | 282 base::FilePath pak_file; |
290 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); | 283 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); |
291 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 284 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
292 | 285 |
293 base::MessageLoop loop; | 286 base::MessageLoop loop; |
294 mojo::GLES2Initializer gles2; | 287 mojo::GLES2Initializer gles2; |
295 | 288 |
296 // TODO(beng): This crashes in a DCHECK on X11 because this thread's | 289 // TODO(beng): This crashes in a DCHECK on X11 because this thread's |
297 // MessageLoop is not of TYPE_UI. I think we need a way to build | 290 // MessageLoop is not of TYPE_UI. I think we need a way to build |
298 // Aura that doesn't define platform-specific stuff. | 291 // Aura that doesn't define platform-specific stuff. |
299 aura::Env::CreateInstance(true); | 292 aura::Env::CreateInstance(true); |
300 mojo::examples::LauncherImpl launcher(shell_handle); | 293 |
| 294 mojo::Application app(shell_handle); |
| 295 app.AddServiceConnector( |
| 296 new mojo::ServiceConnector<mojo::examples::LauncherImpl>()); |
| 297 |
301 loop.Run(); | 298 loop.Run(); |
302 | |
303 return MOJO_RESULT_OK; | 299 return MOJO_RESULT_OK; |
304 } | 300 } |
OLD | NEW |