OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/automation/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
6 | 6 |
7 #include "chrome/browser/automation/ui_controls.h" | 7 #include "chrome/browser/automation/ui_controls.h" |
8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/external_tab_container.h" | 9 #include "chrome/browser/external_tab_container.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 reinterpret_cast<LPARAM>(window))) { | 67 reinterpret_cast<LPARAM>(window))) { |
68 // We enumerated all the windows and did not find the foreground window, | 68 // We enumerated all the windows and did not find the foreground window, |
69 // it is not our window, ignore it. | 69 // it is not our window, ignore it. |
70 *handle = 0; | 70 *handle = 0; |
71 return; | 71 return; |
72 } | 72 } |
73 | 73 |
74 *handle = window_tracker_->Add(window); | 74 *handle = window_tracker_->Add(window); |
75 } | 75 } |
76 | 76 |
77 void AutomationProvider::GetWindowHWND(int handle, HWND* win32_handle) { | |
78 *win32_handle = window_tracker_->GetResource(handle); | |
79 } | |
80 | |
81 void AutomationProvider::WindowGetViewBounds(int handle, int view_id, | 77 void AutomationProvider::WindowGetViewBounds(int handle, int view_id, |
82 bool screen_coordinates, | 78 bool screen_coordinates, |
83 bool* success, | 79 bool* success, |
84 gfx::Rect* bounds) { | 80 gfx::Rect* bounds) { |
85 *success = false; | 81 *success = false; |
86 if (window_tracker_->ContainsHandle(handle)) { | 82 if (window_tracker_->ContainsHandle(handle)) { |
87 gfx::NativeWindow window = window_tracker_->GetResource(handle); | 83 gfx::NativeWindow window = window_tracker_->GetResource(handle); |
88 views::RootView* root_view = views::WidgetWin::FindRootView(window); | 84 views::RootView* root_view = views::WidgetWin::FindRootView(window); |
89 if (root_view) { | 85 if (root_view) { |
90 views::View* view = root_view->GetViewByID(view_id); | 86 views::View* view = root_view->GetViewByID(view_id); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 173 } |
178 | 174 |
179 private: | 175 private: |
180 AutomationProvider* provider_; | 176 AutomationProvider* provider_; |
181 IPC::Message* reply_message_; | 177 IPC::Message* reply_message_; |
182 | 178 |
183 DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask); | 179 DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask); |
184 }; | 180 }; |
185 | 181 |
186 void AutomationProvider::WindowSimulateDrag(int handle, | 182 void AutomationProvider::WindowSimulateDrag(int handle, |
187 std::vector<POINT> drag_path, | 183 std::vector<gfx::Point> drag_path, |
188 int flags, | 184 int flags, |
189 bool press_escape_en_route, | 185 bool press_escape_en_route, |
190 IPC::Message* reply_message) { | 186 IPC::Message* reply_message) { |
191 bool succeeded = false; | |
192 if (browser_tracker_->ContainsHandle(handle) && (drag_path.size() > 1)) { | 187 if (browser_tracker_->ContainsHandle(handle) && (drag_path.size() > 1)) { |
193 gfx::NativeWindow window = | 188 gfx::NativeWindow window = |
194 browser_tracker_->GetResource(handle)->window()->GetNativeHandle(); | 189 browser_tracker_->GetResource(handle)->window()->GetNativeHandle(); |
195 succeeded = true; | |
196 | 190 |
197 UINT down_message = 0; | 191 UINT down_message = 0; |
198 UINT up_message = 0; | 192 UINT up_message = 0; |
199 WPARAM wparam_flags = 0; | 193 WPARAM wparam_flags = 0; |
200 if (flags & views::Event::EF_SHIFT_DOWN) | 194 if (flags & views::Event::EF_SHIFT_DOWN) |
201 wparam_flags |= MK_SHIFT; | 195 wparam_flags |= MK_SHIFT; |
202 if (flags & views::Event::EF_CONTROL_DOWN) | 196 if (flags & views::Event::EF_CONTROL_DOWN) |
203 wparam_flags |= MK_CONTROL; | 197 wparam_flags |= MK_CONTROL; |
204 if (flags & views::Event::EF_LEFT_BUTTON_DOWN) { | 198 if (flags & views::Event::EF_LEFT_BUTTON_DOWN) { |
205 wparam_flags |= MK_LBUTTON; | 199 wparam_flags |= MK_LBUTTON; |
206 down_message = WM_LBUTTONDOWN; | 200 down_message = WM_LBUTTONDOWN; |
207 up_message = WM_LBUTTONUP; | 201 up_message = WM_LBUTTONUP; |
208 } | 202 } |
209 if (flags & views::Event::EF_MIDDLE_BUTTON_DOWN) { | 203 if (flags & views::Event::EF_MIDDLE_BUTTON_DOWN) { |
210 wparam_flags |= MK_MBUTTON; | 204 wparam_flags |= MK_MBUTTON; |
211 down_message = WM_MBUTTONDOWN; | 205 down_message = WM_MBUTTONDOWN; |
212 up_message = WM_MBUTTONUP; | 206 up_message = WM_MBUTTONUP; |
213 } | 207 } |
214 if (flags & views::Event::EF_RIGHT_BUTTON_DOWN) { | 208 if (flags & views::Event::EF_RIGHT_BUTTON_DOWN) { |
215 wparam_flags |= MK_RBUTTON; | 209 wparam_flags |= MK_RBUTTON; |
216 down_message = WM_LBUTTONDOWN; | 210 down_message = WM_LBUTTONDOWN; |
217 up_message = WM_LBUTTONUP; | 211 up_message = WM_LBUTTONUP; |
218 } | 212 } |
219 | 213 |
220 Browser* browser = browser_tracker_->GetResource(handle); | 214 Browser* browser = browser_tracker_->GetResource(handle); |
221 DCHECK(browser); | 215 DCHECK(browser); |
222 HWND top_level_hwnd = | 216 HWND top_level_hwnd = |
223 reinterpret_cast<HWND>(browser->window()->GetNativeHandle()); | 217 reinterpret_cast<HWND>(browser->window()->GetNativeHandle()); |
224 POINT temp = drag_path[0]; | 218 POINT temp = drag_path[0].ToPOINT(); |
225 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1); | 219 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1); |
226 MoveMouse(temp); | 220 MoveMouse(temp); |
227 SendMessage(top_level_hwnd, down_message, wparam_flags, | 221 SendMessage(top_level_hwnd, down_message, wparam_flags, |
228 MAKELPARAM(drag_path[0].x, drag_path[0].y)); | 222 MAKELPARAM(drag_path[0].x(), drag_path[0].y())); |
229 for (int i = 1; i < static_cast<int>(drag_path.size()); ++i) { | 223 for (int i = 1; i < static_cast<int>(drag_path.size()); ++i) { |
230 temp = drag_path[i]; | 224 temp = drag_path[i].ToPOINT(); |
231 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1); | 225 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1); |
232 MoveMouse(temp); | 226 MoveMouse(temp); |
233 SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags, | 227 SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags, |
234 MAKELPARAM(drag_path[i].x, drag_path[i].y)); | 228 MAKELPARAM(drag_path[i].x(), drag_path[i].y())); |
235 } | 229 } |
236 POINT end = drag_path[drag_path.size() - 1]; | 230 POINT end = drag_path[drag_path.size() - 1].ToPOINT(); |
237 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1); | 231 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1); |
238 MoveMouse(end); | 232 MoveMouse(end); |
239 | 233 |
240 if (press_escape_en_route) { | 234 if (press_escape_en_route) { |
241 // Press Escape. | 235 // Press Escape. |
242 ui_controls::SendKeyPress(window, VK_ESCAPE, | 236 ui_controls::SendKeyPress(window, VK_ESCAPE, |
243 ((flags & views::Event::EF_CONTROL_DOWN) | 237 ((flags & views::Event::EF_CONTROL_DOWN) |
244 == views::Event::EF_CONTROL_DOWN), | 238 == views::Event::EF_CONTROL_DOWN), |
245 ((flags & views::Event::EF_SHIFT_DOWN) == | 239 ((flags & views::Event::EF_SHIFT_DOWN) == |
246 views::Event::EF_SHIFT_DOWN), | 240 views::Event::EF_SHIFT_DOWN), |
247 ((flags & views::Event::EF_ALT_DOWN) == | 241 ((flags & views::Event::EF_ALT_DOWN) == |
248 views::Event::EF_ALT_DOWN)); | 242 views::Event::EF_ALT_DOWN)); |
249 } | 243 } |
250 SendMessage(top_level_hwnd, up_message, wparam_flags, | 244 SendMessage(top_level_hwnd, up_message, wparam_flags, |
251 MAKELPARAM(end.x, end.y)); | 245 MAKELPARAM(end.x, end.y)); |
252 | 246 |
253 MessageLoop::current()->PostTask(FROM_HERE, new InvokeTaskLaterTask( | 247 MessageLoop::current()->PostTask(FROM_HERE, new InvokeTaskLaterTask( |
254 new WindowDragResponseTask(this, reply_message))); | 248 new WindowDragResponseTask(this, reply_message))); |
255 } else { | 249 } else { |
256 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true); | 250 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, false); |
257 Send(reply_message); | 251 Send(reply_message); |
258 } | 252 } |
259 } | 253 } |
260 | 254 |
261 void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { | 255 void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { |
262 *view_id = -1; | 256 *view_id = -1; |
263 if (window_tracker_->ContainsHandle(handle)) { | 257 if (window_tracker_->ContainsHandle(handle)) { |
264 HWND hwnd = window_tracker_->GetResource(handle); | 258 HWND hwnd = window_tracker_->GetResource(handle); |
265 views::FocusManager* focus_manager = | 259 views::FocusManager* focus_manager = |
266 views::FocusManager::GetFocusManagerForNativeView(hwnd); | 260 views::FocusManager::GetFocusManagerForNativeView(hwnd); |
(...skipping 16 matching lines...) Expand all Loading... |
283 browser->window()->GetBrowserWindowTesting(); | 277 browser->window()->GetBrowserWindowTesting(); |
284 BookmarkBarView* bookmark_bar = testing->GetBookmarkBarView(); | 278 BookmarkBarView* bookmark_bar = testing->GetBookmarkBarView(); |
285 if (bookmark_bar) { | 279 if (bookmark_bar) { |
286 *animating = bookmark_bar->IsAnimating(); | 280 *animating = bookmark_bar->IsAnimating(); |
287 *visible = browser->window()->IsBookmarkBarVisible(); | 281 *visible = browser->window()->IsBookmarkBarVisible(); |
288 } | 282 } |
289 } | 283 } |
290 } | 284 } |
291 } | 285 } |
292 | 286 |
| 287 void AutomationProvider::GetWindowBounds(int handle, gfx::Rect* bounds, |
| 288 bool* success) { |
| 289 *success = false; |
| 290 HWND hwnd = window_tracker_->GetResource(handle); |
| 291 if (hwnd) { |
| 292 *success = true; |
| 293 WINDOWPLACEMENT window_placement; |
| 294 GetWindowPlacement(hwnd, &window_placement); |
| 295 *bounds = window_placement.rcNormalPosition; |
| 296 } |
| 297 } |
| 298 |
293 void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, | 299 void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, |
294 bool* success) { | 300 bool* success) { |
295 *success = false; | 301 *success = false; |
296 if (window_tracker_->ContainsHandle(handle)) { | 302 if (window_tracker_->ContainsHandle(handle)) { |
297 HWND hwnd = window_tracker_->GetResource(handle); | 303 HWND hwnd = window_tracker_->GetResource(handle); |
298 if (::MoveWindow(hwnd, bounds.x(), bounds.y(), bounds.width(), | 304 if (::MoveWindow(hwnd, bounds.x(), bounds.y(), bounds.width(), |
299 bounds.height(), true)) { | 305 bounds.height(), true)) { |
300 *success = true; | 306 *success = true; |
301 } | 307 } |
302 } | 308 } |
303 } | 309 } |
304 | 310 |
305 void AutomationProvider::SetWindowVisible(int handle, bool visible, | 311 void AutomationProvider::SetWindowVisible(int handle, bool visible, |
306 bool* result) { | 312 bool* result) { |
307 if (window_tracker_->ContainsHandle(handle)) { | 313 if (window_tracker_->ContainsHandle(handle)) { |
308 HWND hwnd = window_tracker_->GetResource(handle); | 314 HWND hwnd = window_tracker_->GetResource(handle); |
309 ::ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE); | 315 ::ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE); |
310 *result = true; | 316 *result = true; |
311 } else { | 317 } else { |
312 *result = false; | 318 *result = false; |
313 } | 319 } |
314 } | 320 } |
315 | 321 |
316 void AutomationProvider::ActivateWindow(int handle) { | 322 void AutomationProvider::ActivateWindow(int handle) { |
317 if (window_tracker_->ContainsHandle(handle)) { | 323 if (window_tracker_->ContainsHandle(handle)) { |
318 ::SetActiveWindow(window_tracker_->GetResource(handle)); | 324 ::SetActiveWindow(window_tracker_->GetResource(handle)); |
319 } | 325 } |
320 } | 326 } |
321 | 327 |
| 328 void AutomationProvider::IsWindowMaximized(int handle, bool* is_maximized, |
| 329 bool* success) { |
| 330 *success = false; |
| 331 |
| 332 HWND hwnd = window_tracker_->GetResource(handle); |
| 333 if (hwnd) { |
| 334 *success = true; |
| 335 WINDOWPLACEMENT window_placement; |
| 336 GetWindowPlacement(hwnd, &window_placement); |
| 337 *is_maximized = (window_placement.showCmd == SW_MAXIMIZE); |
| 338 } |
| 339 } |
| 340 |
322 void AutomationProvider::GetTabHWND(int handle, HWND* tab_hwnd) { | 341 void AutomationProvider::GetTabHWND(int handle, HWND* tab_hwnd) { |
323 *tab_hwnd = NULL; | 342 *tab_hwnd = NULL; |
324 | 343 |
325 if (tab_tracker_->ContainsHandle(handle)) { | 344 if (tab_tracker_->ContainsHandle(handle)) { |
326 NavigationController* tab = tab_tracker_->GetResource(handle); | 345 NavigationController* tab = tab_tracker_->GetResource(handle); |
327 *tab_hwnd = tab->tab_contents()->GetNativeView(); | 346 *tab_hwnd = tab->tab_contents()->GetNativeView(); |
328 } | 347 } |
329 } | 348 } |
330 | 349 |
331 void AutomationProvider::CreateExternalTab( | 350 void AutomationProvider::CreateExternalTab( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { | 420 ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { |
402 if (tab_tracker_->ContainsHandle(handle)) { | 421 if (tab_tracker_->ContainsHandle(handle)) { |
403 NavigationController* tab = tab_tracker_->GetResource(handle); | 422 NavigationController* tab = tab_tracker_->GetResource(handle); |
404 return ExternalTabContainer::GetContainerForTab( | 423 return ExternalTabContainer::GetContainerForTab( |
405 tab->tab_contents()->GetNativeView()); | 424 tab->tab_contents()->GetNativeView()); |
406 } | 425 } |
407 | 426 |
408 return NULL; | 427 return NULL; |
409 } | 428 } |
410 | 429 |
411 void AutomationProvider::OnTabReposition( | |
412 int tab_handle, const IPC::Reposition_Params& params) { | |
413 if (!tab_tracker_->ContainsHandle(tab_handle)) | |
414 return; | |
415 | |
416 if (!IsWindow(params.window)) | |
417 return; | |
418 | |
419 unsigned long process_id = 0; | |
420 unsigned long thread_id = 0; | |
421 | |
422 thread_id = GetWindowThreadProcessId(params.window, &process_id); | |
423 | |
424 if (thread_id != GetCurrentThreadId()) { | |
425 NOTREACHED(); | |
426 return; | |
427 } | |
428 | |
429 SetWindowPos(params.window, params.window_insert_after, params.left, | |
430 params.top, params.width, params.height, params.flags); | |
431 | |
432 if (params.set_parent) { | |
433 if (IsWindow(params.parent_window)) { | |
434 if (!SetParent(params.window, params.parent_window)) | |
435 DLOG(WARNING) << "SetParent failed. Error 0x%x" << GetLastError(); | |
436 } | |
437 } | |
438 } | |
439 | |
440 void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle, | 430 void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle, |
441 int command) { | 431 int command) { |
442 if (tab_tracker_->ContainsHandle(tab_handle)) { | 432 if (tab_tracker_->ContainsHandle(tab_handle)) { |
443 NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 433 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
444 if (!tab) { | 434 if (!tab) { |
445 NOTREACHED(); | 435 NOTREACHED(); |
446 return; | 436 return; |
447 } | 437 } |
448 | 438 |
449 TabContents* tab_contents = tab->tab_contents(); | 439 TabContents* tab_contents = tab->tab_contents(); |
(...skipping 28 matching lines...) Expand all Loading... |
478 TabContents* tab_contents = external_tab_container->tab_contents(); | 468 TabContents* tab_contents = external_tab_container->tab_contents(); |
479 *tab_handle = external_tab_container->tab_handle(); | 469 *tab_handle = external_tab_container->tab_handle(); |
480 external_tab_container->set_tab_handle(*tab_handle); | 470 external_tab_container->set_tab_handle(*tab_handle); |
481 *tab_container_window = external_tab_container->GetNativeView(); | 471 *tab_container_window = external_tab_container->GetNativeView(); |
482 *tab_window = tab_contents->GetNativeView(); | 472 *tab_window = tab_contents->GetNativeView(); |
483 } else { | 473 } else { |
484 external_tab_container->Uninitialize(); | 474 external_tab_container->Uninitialize(); |
485 } | 475 } |
486 } | 476 } |
487 | 477 |
| 478 void AutomationProvider::TerminateSession(int handle, bool* success) { |
| 479 *success = false; |
| 480 |
| 481 if (browser_tracker_->ContainsHandle(handle)) { |
| 482 Browser* browser = browser_tracker_->GetResource(handle); |
| 483 HWND window = browser->window()->GetNativeHandle(); |
| 484 *success = (::PostMessageW(window, WM_ENDSESSION, 0, 0) == TRUE); |
| 485 } |
| 486 } |
OLD | NEW |