Chromium Code Reviews| 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 "mojo/shell/app_container.h" | 5 #include "mojo/shell/app_container.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/native_library.h" | 11 #include "base/native_library.h" |
| 12 #include "base/strings/stringprintf.h" | |
| 12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "mojo/public/system/core.h" | 15 #include "mojo/public/system/core.h" |
| 16 #include "mojo/services/native_viewport/native_viewport.h" | |
| 17 #include "mojo/services/native_viewport/native_viewport_delegate.h" | |
| 15 #include "mojo/shell/context.h" | 18 #include "mojo/shell/context.h" |
| 19 #include "ui/events/event.h" | |
| 16 | 20 |
| 17 typedef MojoResult (*MojoMainFunction)(mojo::Handle pipe); | 21 typedef MojoResult (*MojoMainFunction)(mojo::Handle pipe); |
| 18 | 22 |
| 19 namespace mojo { | 23 namespace mojo { |
| 20 namespace shell { | 24 namespace shell { |
| 21 | 25 |
| 26 // TODO(beng): This should move with the rest of the NativeViewportService | |
| 27 // once we have a specific pipe/API. | |
| 28 class ShellNativeViewportDelegate : public services::NativeViewportDelegate { | |
|
abarth-chromium
2013/10/29 21:48:44
Yeah, it's kind of lame to have this here. Can we
| |
| 29 public: | |
| 30 explicit ShellNativeViewportDelegate(Handle shell_handle) | |
| 31 : shell_handle_(shell_handle) {} | |
| 32 virtual ~ShellNativeViewportDelegate() {} | |
| 33 | |
| 34 private: | |
| 35 // Overridden from services::NativeViewportDelegate: | |
| 36 virtual bool OnEvent(ui::Event* event) OVERRIDE { | |
| 37 ui::LocatedEvent* located = static_cast<ui::LocatedEvent*>(event); | |
| 38 SendString(base::StringPrintf("Event @ %d,%d", | |
| 39 located->location().x(), | |
| 40 located->location().y())); | |
| 41 return false; | |
| 42 } | |
| 43 virtual void OnResized(const gfx::Size& size) OVERRIDE { | |
| 44 SendString(base::StringPrintf("Sized to: %d x %d", | |
| 45 size.width(), | |
| 46 size.height())); | |
| 47 } | |
| 48 | |
| 49 void SendString(const std::string& string) { | |
| 50 MojoResult result = WriteMessage( | |
| 51 shell_handle_, string.c_str(), string.size()+1, NULL, 0, | |
| 52 MOJO_WRITE_MESSAGE_FLAG_NONE); | |
| 53 if (result < MOJO_RESULT_OK) { | |
| 54 // Failure. | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 Handle shell_handle_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(ShellNativeViewportDelegate); | |
| 61 }; | |
| 62 | |
| 22 void LaunchAppOnThread( | 63 void LaunchAppOnThread( |
| 23 const base::FilePath& app_path, | 64 const base::FilePath& app_path, |
| 24 Handle app_handle) { | 65 Handle app_handle) { |
| 25 MojoResult result = MOJO_RESULT_OK; | 66 MojoResult result = MOJO_RESULT_OK; |
| 26 MojoMainFunction main_function = NULL; | 67 MojoMainFunction main_function = NULL; |
| 27 | 68 |
| 28 base::NativeLibrary app_library = base::LoadNativeLibrary(app_path, NULL); | 69 base::NativeLibrary app_library = base::LoadNativeLibrary(app_path, NULL); |
| 29 if (!app_library) { | 70 if (!app_library) { |
| 30 LOG(ERROR) << "Failed to load library: " << app_path.value().c_str(); | 71 LOG(ERROR) << "Failed to load library: " << app_path.value().c_str(); |
| 31 goto completed; | 72 goto completed; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 base::Bind(&LaunchAppOnThread, app_path, app_handle), | 123 base::Bind(&LaunchAppOnThread, app_path, app_handle), |
| 83 base::Bind(&AppContainer::AppCompleted, weak_factory_.GetWeakPtr())); | 124 base::Bind(&AppContainer::AppCompleted, weak_factory_.GetWeakPtr())); |
| 84 | 125 |
| 85 const char* hello_msg = "Hello"; | 126 const char* hello_msg = "Hello"; |
| 86 result = WriteMessage(shell_handle_, hello_msg, | 127 result = WriteMessage(shell_handle_, hello_msg, |
| 87 static_cast<uint32_t>(strlen(hello_msg)+1), | 128 static_cast<uint32_t>(strlen(hello_msg)+1), |
| 88 NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); | 129 NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 89 if (result < MOJO_RESULT_OK) { | 130 if (result < MOJO_RESULT_OK) { |
| 90 // Failure.. | 131 // Failure.. |
| 91 } | 132 } |
| 133 | |
| 134 // TODO(beng): This should be created on demand by the NativeViewportService | |
| 135 // when it is retrieved by the app. | |
| 136 ShellNativeViewportDelegate* delegate = | |
| 137 new ShellNativeViewportDelegate(shell_handle_); | |
| 138 services::NativeViewport* viewport = | |
| 139 services::NativeViewport::CreateNativeViewport(delegate); | |
|
abarth-chromium
2013/10/29 21:48:44
These leak, right? Maybe we should store them in
| |
| 92 } | 140 } |
| 93 | 141 |
| 94 void AppContainer::AppCompleted() { | 142 void AppContainer::AppCompleted() { |
| 95 thread_.reset(); | 143 thread_.reset(); |
| 96 Close(shell_handle_); | 144 Close(shell_handle_); |
| 97 | 145 |
| 98 // Probably want to do something more sophisticated here, like notify someone | 146 // Probably want to do something more sophisticated here, like notify someone |
| 99 // else to do this. | 147 // else to do this. |
| 100 base::MessageLoop::current()->Quit(); | 148 base::MessageLoop::current()->Quit(); |
| 101 } | 149 } |
| 102 | 150 |
| 103 } // namespace shell | 151 } // namespace shell |
| 104 } // namespace mojo | 152 } // namespace mojo |
| OLD | NEW |