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

Side by Side Diff: chrome/browser/automation/automation_provider.cc

Issue 164446: linux: More automation porting. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: automation ipc messages hack fix Created 11 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/message_box_flags.h" 8 #include "app/message_box_flags.h"
9 #include "base/file_version_info.h" 9 #include "base/file_version_info.h"
10 #include "base/json_reader.h" 10 #include "base/json_reader.h"
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 #if defined(OS_WIN) 966 #if defined(OS_WIN)
967 IPC_MESSAGE_HANDLER(AutomationMsg_WindowHWND, GetWindowHWND) 967 IPC_MESSAGE_HANDLER(AutomationMsg_WindowHWND, GetWindowHWND)
968 #endif // defined(OS_WIN) 968 #endif // defined(OS_WIN)
969 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, 969 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync,
970 ExecuteBrowserCommandAsync) 970 ExecuteBrowserCommandAsync)
971 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, 971 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand,
972 ExecuteBrowserCommand) 972 ExecuteBrowserCommand)
973 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) 973 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds)
974 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) 974 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds)
975 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) 975 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible)
976 #if defined(OS_WIN) 976 #if defined(OS_WIN) || defined(OS_LINUX)
977 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) 977 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick)
978 #endif // defined(OS_WIN)
979 #if defined(OS_WIN) || defined(OS_LINUX)
980 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) 978 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress)
981 #endif 979 #endif
982 #if defined(OS_WIN) 980 #if defined(OS_WIN)
983 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, 981 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag,
984 WindowSimulateDrag) 982 WindowSimulateDrag)
985 #endif // defined(OS_WIN) 983 #endif // defined(OS_WIN)
986 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) 984 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount)
987 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) 985 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab)
988 #if defined(OS_WIN) 986 #if defined(OS_WIN)
989 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) 987 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND)
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); 1481 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false);
1484 Send(reply_message); 1482 Send(reply_message);
1485 } 1483 }
1486 1484
1487 void AutomationProvider::WindowGetViewBounds(int handle, int view_id, 1485 void AutomationProvider::WindowGetViewBounds(int handle, int view_id,
1488 bool screen_coordinates, 1486 bool screen_coordinates,
1489 bool* success, 1487 bool* success,
1490 gfx::Rect* bounds) { 1488 gfx::Rect* bounds) {
1491 *success = false; 1489 *success = false;
1492 1490
1493 #if defined(OS_WIN) 1491 gfx::NativeWindow window = window_tracker_->GetResource(handle);
1494 void* iter = NULL; 1492 if (window) {
1495 if (window_tracker_->ContainsHandle(handle)) { 1493 #if defined(TOOLKIT_VIEWS)
1496 HWND hwnd = window_tracker_->GetResource(handle); 1494 views::RootView* root_view = views::WidgetWin::FindRootView(window);
1497 views::RootView* root_view = views::WidgetWin::FindRootView(hwnd);
1498 if (root_view) { 1495 if (root_view) {
1499 views::View* view = root_view->GetViewByID(view_id); 1496 views::View* view = root_view->GetViewByID(view_id);
1500 if (view) { 1497 if (view) {
1501 *success = true; 1498 *success = true;
1502 gfx::Point point; 1499 gfx::Point point;
1503 if (screen_coordinates) 1500 if (screen_coordinates)
1504 views::View::ConvertPointToScreen(view, &point); 1501 views::View::ConvertPointToScreen(view, &point);
1505 else 1502 else
1506 views::View::ConvertPointToView(view, root_view, &point); 1503 views::View::ConvertPointToView(view, root_view, &point);
1507 *bounds = view->GetLocalBounds(false); 1504 *bounds = view->GetLocalBounds(false);
1508 bounds->set_origin(point); 1505 bounds->set_origin(point);
1509 } 1506 }
1510 } 1507 }
1508 #else
1509 NOTIMPLEMENTED();
1510 #endif
1511 } 1511 }
1512 #else
1513 // TODO(port): Enable when window_tracker is ported.
1514 NOTIMPLEMENTED();
1515 #endif
1516 } 1512 }
1517 1513
1518 #if defined(OS_WIN) 1514 #if defined(OS_WIN)
1519 1515
1520 // This task enqueues a mouse event on the event loop, so that the view 1516 // This task enqueues a mouse event on the event loop, so that the view
1521 // that it's being sent to can do the requisite post-processing. 1517 // that it's being sent to can do the requisite post-processing.
1522 class MouseEventTask : public Task { 1518 class MouseEventTask : public Task {
1523 public: 1519 public:
1524 MouseEventTask(views::View* view, 1520 MouseEventTask(views::View* view,
1525 views::Event::EventType type, 1521 views::Event::EventType type,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true); 1609 AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true);
1614 provider_->Send(reply_message_); 1610 provider_->Send(reply_message_);
1615 } 1611 }
1616 1612
1617 private: 1613 private:
1618 AutomationProvider* provider_; 1614 AutomationProvider* provider_;
1619 IPC::Message* reply_message_; 1615 IPC::Message* reply_message_;
1620 1616
1621 DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask); 1617 DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask);
1622 }; 1618 };
1619 #endif // defined(OS_WIN)
1623 1620
1621 #if defined(OS_WIN) || defined(OS_LINUX)
1624 void AutomationProvider::WindowSimulateClick(const IPC::Message& message, 1622 void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
1625 int handle, 1623 int handle,
1626 POINT click, 1624 const gfx::Point& click,
1627 int flags) { 1625 int flags) {
1628 HWND hwnd = 0; 1626 gfx::NativeWindow window = window_tracker_->GetResource(handle);
1629 1627
1630 if (window_tracker_->ContainsHandle(handle)) { 1628 if (window) {
1631 hwnd = window_tracker_->GetResource(handle); 1629 ui_controls::SendMouseMove(click.x(), click.y());
1632
1633 ui_controls::SendMouseMove(click.x, click.y);
1634 1630
1635 ui_controls::MouseButton button = ui_controls::LEFT; 1631 ui_controls::MouseButton button = ui_controls::LEFT;
1636 if ((flags & views::Event::EF_LEFT_BUTTON_DOWN) == 1632 if ((flags & views::Event::EF_LEFT_BUTTON_DOWN) ==
1637 views::Event::EF_LEFT_BUTTON_DOWN) { 1633 views::Event::EF_LEFT_BUTTON_DOWN) {
1638 button = ui_controls::LEFT; 1634 button = ui_controls::LEFT;
1639 } else if ((flags & views::Event::EF_RIGHT_BUTTON_DOWN) == 1635 } else if ((flags & views::Event::EF_RIGHT_BUTTON_DOWN) ==
1640 views::Event::EF_RIGHT_BUTTON_DOWN) { 1636 views::Event::EF_RIGHT_BUTTON_DOWN) {
1641 button = ui_controls::RIGHT; 1637 button = ui_controls::RIGHT;
1642 } else if ((flags & views::Event::EF_MIDDLE_BUTTON_DOWN) == 1638 } else if ((flags & views::Event::EF_MIDDLE_BUTTON_DOWN) ==
1643 views::Event::EF_MIDDLE_BUTTON_DOWN) { 1639 views::Event::EF_MIDDLE_BUTTON_DOWN) {
1644 button = ui_controls::MIDDLE; 1640 button = ui_controls::MIDDLE;
1645 } else { 1641 } else {
1646 NOTREACHED(); 1642 NOTREACHED();
1647 } 1643 }
1648 ui_controls::SendMouseClick(button); 1644 ui_controls::SendMouseClick(window, click, button);
1649 } 1645 }
1650 } 1646 }
1647 #endif
1651 1648
1649 #if defined(OS_WIN)
1652 void AutomationProvider::WindowSimulateDrag(int handle, 1650 void AutomationProvider::WindowSimulateDrag(int handle,
1653 std::vector<POINT> drag_path, 1651 std::vector<POINT> drag_path,
1654 int flags, 1652 int flags,
1655 bool press_escape_en_route, 1653 bool press_escape_en_route,
1656 IPC::Message* reply_message) { 1654 IPC::Message* reply_message) {
1657 bool succeeded = false; 1655 bool succeeded = false;
1658 if (browser_tracker_->ContainsHandle(handle) && (drag_path.size() > 1)) { 1656 gfx::NativeWindow window = window_tracker_->GetResource(handle);
1657 if (window && (drag_path.size() > 1)) {
1659 succeeded = true; 1658 succeeded = true;
1660 1659
1661 UINT down_message = 0; 1660 UINT down_message = 0;
1662 UINT up_message = 0; 1661 UINT up_message = 0;
1663 WPARAM wparam_flags = 0; 1662 WPARAM wparam_flags = 0;
1664 if (flags & views::Event::EF_SHIFT_DOWN) 1663 if (flags & views::Event::EF_SHIFT_DOWN)
1665 wparam_flags |= MK_SHIFT; 1664 wparam_flags |= MK_SHIFT;
1666 if (flags & views::Event::EF_CONTROL_DOWN) 1665 if (flags & views::Event::EF_CONTROL_DOWN)
1667 wparam_flags |= MK_CONTROL; 1666 wparam_flags |= MK_CONTROL;
1668 if (flags & views::Event::EF_LEFT_BUTTON_DOWN) { 1667 if (flags & views::Event::EF_LEFT_BUTTON_DOWN) {
(...skipping 27 matching lines...) Expand all
1696 MoveMouse(temp); 1695 MoveMouse(temp);
1697 SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags, 1696 SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags,
1698 MAKELPARAM(drag_path[i].x, drag_path[i].y)); 1697 MAKELPARAM(drag_path[i].x, drag_path[i].y));
1699 } 1698 }
1700 POINT end = drag_path[drag_path.size() - 1]; 1699 POINT end = drag_path[drag_path.size() - 1];
1701 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1); 1700 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1);
1702 MoveMouse(end); 1701 MoveMouse(end);
1703 1702
1704 if (press_escape_en_route) { 1703 if (press_escape_en_route) {
1705 // Press Escape. 1704 // Press Escape.
1706 ui_controls::SendKeyPress(VK_ESCAPE, 1705 ui_controls::SendKeyPress(window, VK_ESCAPE,
1707 ((flags & views::Event::EF_CONTROL_DOWN) 1706 ((flags & views::Event::EF_CONTROL_DOWN)
1708 == views::Event::EF_CONTROL_DOWN), 1707 == views::Event::EF_CONTROL_DOWN),
1709 ((flags & views::Event::EF_SHIFT_DOWN) == 1708 ((flags & views::Event::EF_SHIFT_DOWN) ==
1710 views::Event::EF_SHIFT_DOWN), 1709 views::Event::EF_SHIFT_DOWN),
1711 ((flags & views::Event::EF_ALT_DOWN) == 1710 ((flags & views::Event::EF_ALT_DOWN) ==
1712 views::Event::EF_ALT_DOWN)); 1711 views::Event::EF_ALT_DOWN));
1713 } 1712 }
1714 SendMessage(top_level_hwnd, up_message, wparam_flags, 1713 SendMessage(top_level_hwnd, up_message, wparam_flags,
1715 MAKELPARAM(end.x, end.y)); 1714 MAKELPARAM(end.x, end.y));
1716 1715
1717 MessageLoop::current()->PostTask(FROM_HERE, new InvokeTaskLaterTask( 1716 MessageLoop::current()->PostTask(FROM_HERE, new InvokeTaskLaterTask(
1718 new WindowDragResponseTask(this, reply_message))); 1717 new WindowDragResponseTask(this, reply_message)));
1719 } else { 1718 } else {
1720 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true); 1719 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true);
1721 Send(reply_message); 1720 Send(reply_message);
1722 } 1721 }
1723 } 1722 }
1724 #endif // defined(OS_WIN) 1723 #endif // defined(OS_WIN)
1725 1724
1726 #if defined(OS_WIN) || defined(OS_LINUX) 1725 #if defined(OS_WIN) || defined(OS_LINUX)
1727 void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message, 1726 void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message,
1728 int handle, 1727 int handle,
1729 wchar_t key, 1728 wchar_t key,
1730 int flags) { 1729 int flags) {
1731 if (!window_tracker_->ContainsHandle(handle)) 1730 gfx::NativeWindow window = window_tracker_->GetResource(handle);
1731 if (!window)
1732 return; 1732 return;
1733 1733
1734 // The key event is sent to whatever window is active. 1734 // The key event is sent to whatever window is active.
1735 ui_controls::SendKeyPress(key, 1735 ui_controls::SendKeyPress(window, key,
1736 ((flags & views::Event::EF_CONTROL_DOWN) == 1736 ((flags & views::Event::EF_CONTROL_DOWN) ==
1737 views::Event::EF_CONTROL_DOWN), 1737 views::Event::EF_CONTROL_DOWN),
1738 ((flags & views::Event::EF_SHIFT_DOWN) == 1738 ((flags & views::Event::EF_SHIFT_DOWN) ==
1739 views::Event::EF_SHIFT_DOWN), 1739 views::Event::EF_SHIFT_DOWN),
1740 ((flags & views::Event::EF_ALT_DOWN) == 1740 ((flags & views::Event::EF_ALT_DOWN) ==
1741 views::Event::EF_ALT_DOWN)); 1741 views::Event::EF_ALT_DOWN));
1742 } 1742 }
1743 #endif 1743 #endif
1744 1744
1745 #if defined(OS_WIN) 1745 #if defined(OS_WIN)
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after
3096 NOTREACHED(); 3096 NOTREACHED();
3097 return NULL; 3097 return NULL;
3098 } 3098 }
3099 3099
3100 RenderViewHost* view_host = tab_contents->render_view_host(); 3100 RenderViewHost* view_host = tab_contents->render_view_host();
3101 return view_host; 3101 return view_host;
3102 } 3102 }
3103 3103
3104 return NULL; 3104 return NULL;
3105 } 3105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698