OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "win8/metro_driver/stdafx.h" | 5 #include "win8/metro_driver/stdafx.h" |
6 #include "win8/metro_driver/chrome_app_view_ash.h" | 6 #include "win8/metro_driver/chrome_app_view_ash.h" |
7 | 7 |
8 #include <corewindow.h> | 8 #include <corewindow.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <windows.foundation.h> | 10 #include <windows.foundation.h> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/single_thread_task_runner.h" |
17 #include "base/win/metro.h" | 18 #include "base/win/metro.h" |
18 #include "base/win/win_util.h" | 19 #include "base/win/win_util.h" |
19 #include "base/win/windows_version.h" | 20 #include "base/win/windows_version.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "ipc/ipc_channel.h" | 22 #include "ipc/ipc_channel.h" |
22 #include "ipc/ipc_channel_proxy.h" | 23 #include "ipc/ipc_channel_proxy.h" |
23 #include "ipc/ipc_sender.h" | 24 #include "ipc/ipc_sender.h" |
24 #include "ui/events/gesture_detection/motion_event.h" | 25 #include "ui/events/gesture_detection/motion_event.h" |
25 #include "ui/gfx/geometry/point_conversions.h" | 26 #include "ui/gfx/geometry/point_conversions.h" |
26 #include "ui/gfx/win/dpi.h" | 27 #include "ui/gfx/win/dpi.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 for (int i = key_count; i; i--) { | 137 for (int i = key_count; i; i--) { |
137 SendInput(1, &keys[ i - 1 ], sizeof(keys[0])); | 138 SendInput(1, &keys[ i - 1 ], sizeof(keys[0])); |
138 if (should_sleep) | 139 if (should_sleep) |
139 Sleep(10); | 140 Sleep(10); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 class ChromeChannelListener : public IPC::Listener { | 144 class ChromeChannelListener : public IPC::Listener { |
144 public: | 145 public: |
145 ChromeChannelListener(base::MessageLoop* ui_loop, ChromeAppViewAsh* app_view) | 146 ChromeChannelListener(base::MessageLoop* ui_loop, ChromeAppViewAsh* app_view) |
146 : ui_proxy_(ui_loop->message_loop_proxy()), | 147 : ui_task_runner_(ui_loop->task_runner()), app_view_(app_view) {} |
147 app_view_(app_view) {} | |
148 | 148 |
149 bool OnMessageReceived(const IPC::Message& message) override { | 149 bool OnMessageReceived(const IPC::Message& message) override { |
150 IPC_BEGIN_MESSAGE_MAP(ChromeChannelListener, message) | 150 IPC_BEGIN_MESSAGE_MAP(ChromeChannelListener, message) |
151 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktop, | 151 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktop, |
152 OnActivateDesktop) | 152 OnActivateDesktop) |
153 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MetroExit, OnMetroExit) | 153 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MetroExit, OnMetroExit) |
154 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURLOnDesktop, | 154 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURLOnDesktop, |
155 OnOpenURLOnDesktop) | 155 OnOpenURLOnDesktop) |
156 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursor, OnSetCursor) | 156 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursor, OnSetCursor) |
157 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileOpen, | 157 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileOpen, |
158 OnDisplayFileOpenDialog) | 158 OnDisplayFileOpenDialog) |
159 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileSaveAs, | 159 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileSaveAs, |
160 OnDisplayFileSaveAsDialog) | 160 OnDisplayFileSaveAsDialog) |
161 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplaySelectFolder, | 161 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplaySelectFolder, |
162 OnDisplayFolderPicker) | 162 OnDisplayFolderPicker) |
163 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPos, OnSetCursorPos) | 163 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPos, OnSetCursorPos) |
164 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCancelComposition, | 164 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCancelComposition, |
165 OnImeCancelComposition) | 165 OnImeCancelComposition) |
166 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeTextInputClientUpdated, | 166 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeTextInputClientUpdated, |
167 OnImeTextInputClientChanged) | 167 OnImeTextInputClientChanged) |
168 IPC_MESSAGE_UNHANDLED(__debugbreak()) | 168 IPC_MESSAGE_UNHANDLED(__debugbreak()) |
169 IPC_END_MESSAGE_MAP() | 169 IPC_END_MESSAGE_MAP() |
170 return true; | 170 return true; |
171 } | 171 } |
172 | 172 |
173 void OnChannelError() override { | 173 void OnChannelError() override { |
174 DVLOG(1) << "Channel error. Exiting."; | 174 DVLOG(1) << "Channel error. Exiting."; |
175 ui_proxy_->PostTask(FROM_HERE, | 175 ui_task_runner_->PostTask( |
| 176 FROM_HERE, |
176 base::Bind(&ChromeAppViewAsh::OnMetroExit, base::Unretained(app_view_), | 177 base::Bind(&ChromeAppViewAsh::OnMetroExit, base::Unretained(app_view_), |
177 TERMINATE_USING_KEY_SEQUENCE)); | 178 TERMINATE_USING_KEY_SEQUENCE)); |
178 | 179 |
179 // In early Windows 8 versions the code above sometimes fails so we call | 180 // In early Windows 8 versions the code above sometimes fails so we call |
180 // it a second time with a NULL window which just calls Exit(). | 181 // it a second time with a NULL window which just calls Exit(). |
181 ui_proxy_->PostDelayedTask(FROM_HERE, | 182 ui_task_runner_->PostDelayedTask( |
| 183 FROM_HERE, |
182 base::Bind(&ChromeAppViewAsh::OnMetroExit, base::Unretained(app_view_), | 184 base::Bind(&ChromeAppViewAsh::OnMetroExit, base::Unretained(app_view_), |
183 TERMINATE_USING_PROCESS_EXIT), | 185 TERMINATE_USING_PROCESS_EXIT), |
184 base::TimeDelta::FromMilliseconds(100)); | 186 base::TimeDelta::FromMilliseconds(100)); |
185 } | 187 } |
186 | 188 |
187 private: | 189 private: |
188 void OnActivateDesktop(const base::FilePath& shortcut, bool ash_exit) { | 190 void OnActivateDesktop(const base::FilePath& shortcut, bool ash_exit) { |
189 ui_proxy_->PostTask(FROM_HERE, | 191 ui_task_runner_->PostTask( |
190 base::Bind(&ChromeAppViewAsh::OnActivateDesktop, | 192 FROM_HERE, base::Bind(&ChromeAppViewAsh::OnActivateDesktop, |
191 base::Unretained(app_view_), | 193 base::Unretained(app_view_), shortcut, ash_exit)); |
192 shortcut, ash_exit)); | |
193 } | 194 } |
194 | 195 |
195 void OnMetroExit() { | 196 void OnMetroExit() { |
196 ui_proxy_->PostTask(FROM_HERE, | 197 ui_task_runner_->PostTask( |
197 base::Bind(&ChromeAppViewAsh::OnMetroExit, | 198 FROM_HERE, |
198 base::Unretained(app_view_), TERMINATE_USING_KEY_SEQUENCE)); | 199 base::Bind(&ChromeAppViewAsh::OnMetroExit, base::Unretained(app_view_), |
| 200 TERMINATE_USING_KEY_SEQUENCE)); |
199 } | 201 } |
200 | 202 |
201 void OnOpenURLOnDesktop(const base::FilePath& shortcut, | 203 void OnOpenURLOnDesktop(const base::FilePath& shortcut, |
202 const base::string16& url) { | 204 const base::string16& url) { |
203 ui_proxy_->PostTask(FROM_HERE, | 205 ui_task_runner_->PostTask( |
204 base::Bind(&ChromeAppViewAsh::OnOpenURLOnDesktop, | 206 FROM_HERE, base::Bind(&ChromeAppViewAsh::OnOpenURLOnDesktop, |
205 base::Unretained(app_view_), | 207 base::Unretained(app_view_), shortcut, url)); |
206 shortcut, url)); | |
207 } | 208 } |
208 | 209 |
209 void OnSetCursor(int64 cursor) { | 210 void OnSetCursor(int64 cursor) { |
210 ui_proxy_->PostTask(FROM_HERE, | 211 ui_task_runner_->PostTask( |
211 base::Bind(&ChromeAppViewAsh::OnSetCursor, | 212 FROM_HERE, |
212 base::Unretained(app_view_), | 213 base::Bind(&ChromeAppViewAsh::OnSetCursor, base::Unretained(app_view_), |
213 reinterpret_cast<HCURSOR>(cursor))); | 214 reinterpret_cast<HCURSOR>(cursor))); |
214 } | 215 } |
215 | 216 |
216 void OnDisplayFileOpenDialog(const base::string16& title, | 217 void OnDisplayFileOpenDialog(const base::string16& title, |
217 const base::string16& filter, | 218 const base::string16& filter, |
218 const base::FilePath& default_path, | 219 const base::FilePath& default_path, |
219 bool allow_multiple_files) { | 220 bool allow_multiple_files) { |
220 ui_proxy_->PostTask(FROM_HERE, | 221 ui_task_runner_->PostTask( |
221 base::Bind(&ChromeAppViewAsh::OnDisplayFileOpenDialog, | 222 FROM_HERE, base::Bind(&ChromeAppViewAsh::OnDisplayFileOpenDialog, |
222 base::Unretained(app_view_), | 223 base::Unretained(app_view_), title, filter, |
223 title, | 224 default_path, allow_multiple_files)); |
224 filter, | |
225 default_path, | |
226 allow_multiple_files)); | |
227 } | 225 } |
228 | 226 |
229 void OnDisplayFileSaveAsDialog( | 227 void OnDisplayFileSaveAsDialog( |
230 const MetroViewerHostMsg_SaveAsDialogParams& params) { | 228 const MetroViewerHostMsg_SaveAsDialogParams& params) { |
231 ui_proxy_->PostTask( | 229 ui_task_runner_->PostTask( |
232 FROM_HERE, | 230 FROM_HERE, base::Bind(&ChromeAppViewAsh::OnDisplayFileSaveAsDialog, |
233 base::Bind(&ChromeAppViewAsh::OnDisplayFileSaveAsDialog, | 231 base::Unretained(app_view_), params)); |
234 base::Unretained(app_view_), | |
235 params)); | |
236 } | 232 } |
237 | 233 |
238 void OnDisplayFolderPicker(const base::string16& title) { | 234 void OnDisplayFolderPicker(const base::string16& title) { |
239 ui_proxy_->PostTask( | 235 ui_task_runner_->PostTask( |
240 FROM_HERE, | 236 FROM_HERE, base::Bind(&ChromeAppViewAsh::OnDisplayFolderPicker, |
241 base::Bind(&ChromeAppViewAsh::OnDisplayFolderPicker, | 237 base::Unretained(app_view_), title)); |
242 base::Unretained(app_view_), | |
243 title)); | |
244 } | 238 } |
245 | 239 |
246 void OnSetCursorPos(int x, int y) { | 240 void OnSetCursorPos(int x, int y) { |
247 VLOG(1) << "In IPC OnSetCursorPos: " << x << ", " << y; | 241 VLOG(1) << "In IPC OnSetCursorPos: " << x << ", " << y; |
248 ui_proxy_->PostTask( | 242 ui_task_runner_->PostTask(FROM_HERE, |
249 FROM_HERE, | 243 base::Bind(&ChromeAppViewAsh::OnSetCursorPos, |
250 base::Bind(&ChromeAppViewAsh::OnSetCursorPos, | 244 base::Unretained(app_view_), x, y)); |
251 base::Unretained(app_view_), | |
252 x, y)); | |
253 } | 245 } |
254 | 246 |
255 void OnImeCancelComposition() { | 247 void OnImeCancelComposition() { |
256 ui_proxy_->PostTask( | 248 ui_task_runner_->PostTask( |
257 FROM_HERE, | 249 FROM_HERE, base::Bind(&ChromeAppViewAsh::OnImeCancelComposition, |
258 base::Bind(&ChromeAppViewAsh::OnImeCancelComposition, | 250 base::Unretained(app_view_))); |
259 base::Unretained(app_view_))); | |
260 } | 251 } |
261 | 252 |
262 void OnImeTextInputClientChanged( | 253 void OnImeTextInputClientChanged( |
263 const std::vector<int32>& input_scopes, | 254 const std::vector<int32>& input_scopes, |
264 const std::vector<metro_viewer::CharacterBounds>& character_bounds) { | 255 const std::vector<metro_viewer::CharacterBounds>& character_bounds) { |
265 ui_proxy_->PostTask( | 256 ui_task_runner_->PostTask( |
266 FROM_HERE, | 257 FROM_HERE, base::Bind(&ChromeAppViewAsh::OnImeUpdateTextInputClient, |
267 base::Bind(&ChromeAppViewAsh::OnImeUpdateTextInputClient, | 258 base::Unretained(app_view_), input_scopes, |
268 base::Unretained(app_view_), | 259 character_bounds)); |
269 input_scopes, | |
270 character_bounds)); | |
271 } | 260 } |
272 | 261 |
273 scoped_refptr<base::MessageLoopProxy> ui_proxy_; | 262 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
274 ChromeAppViewAsh* app_view_; | 263 ChromeAppViewAsh* app_view_; |
275 }; | 264 }; |
276 | 265 |
277 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { | 266 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { |
278 // We're entering a nested message loop, let's allow dispatching | 267 // We're entering a nested message loop, let's allow dispatching |
279 // tasks while we're in there. | 268 // tasks while we're in there. |
280 base::MessageLoop::current()->SetNestableTasksAllowed(true); | 269 base::MessageLoop::current()->SetNestableTasksAllowed(true); |
281 | 270 |
282 // Enter main core message loop. There are several ways to exit it | 271 // Enter main core message loop. There are several ways to exit it |
283 // Nicely: | 272 // Nicely: |
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1471 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; | 1460 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; |
1472 CheckHR(core_app.As(&app_exit)); | 1461 CheckHR(core_app.As(&app_exit)); |
1473 globals.app_exit = app_exit.Detach(); | 1462 globals.app_exit = app_exit.Detach(); |
1474 } | 1463 } |
1475 | 1464 |
1476 IFACEMETHODIMP | 1465 IFACEMETHODIMP |
1477 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 1466 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
1478 *view = mswr::Make<ChromeAppViewAsh>().Detach(); | 1467 *view = mswr::Make<ChromeAppViewAsh>().Detach(); |
1479 return (*view) ? S_OK : E_OUTOFMEMORY; | 1468 return (*view) ? S_OK : E_OUTOFMEMORY; |
1480 } | 1469 } |
OLD | NEW |