OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <set> | 7 #include <set> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/message_box_flags.h" | 10 #include "app/message_box_flags.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 #include "chrome/common/json_value_serializer.h" | 73 #include "chrome/common/json_value_serializer.h" |
74 #include "chrome/common/notification_service.h" | 74 #include "chrome/common/notification_service.h" |
75 #include "chrome/common/platform_util.h" | 75 #include "chrome/common/platform_util.h" |
76 #include "chrome/common/pref_names.h" | 76 #include "chrome/common/pref_names.h" |
77 #include "chrome/common/url_constants.h" | 77 #include "chrome/common/url_constants.h" |
78 #include "chrome/test/automation/automation_messages.h" | 78 #include "chrome/test/automation/automation_messages.h" |
79 #include "chrome/test/automation/tab_proxy.h" | 79 #include "chrome/test/automation/tab_proxy.h" |
80 #include "net/proxy/proxy_service.h" | 80 #include "net/proxy/proxy_service.h" |
81 #include "net/proxy/proxy_config_service_fixed.h" | 81 #include "net/proxy/proxy_config_service_fixed.h" |
82 #include "net/url_request/url_request_context.h" | 82 #include "net/url_request/url_request_context.h" |
| 83 #include "chrome/browser/automation/ui_controls.h" |
83 #include "views/event.h" | 84 #include "views/event.h" |
84 | 85 |
85 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
86 // TODO(port): Port these headers. | 87 // TODO(port): Port these headers. |
87 #include "chrome/browser/character_encoding.h" | 88 #include "chrome/browser/character_encoding.h" |
88 #include "chrome/browser/download/save_package.h" | 89 #include "chrome/browser/download/save_package.h" |
89 #include "chrome/browser/external_tab_container.h" | 90 #include "chrome/browser/external_tab_container.h" |
90 #include "chrome/browser/printing/print_job.h" | 91 #include "chrome/browser/printing/print_job.h" |
91 #endif // defined(OS_WIN) | 92 #endif // defined(OS_WIN) |
92 | 93 |
93 #if !defined(OS_MACOSX) | |
94 // TODO(port): Port these to the mac. | |
95 #include "chrome/browser/automation/ui_controls.h" | |
96 #endif // !defined(OS_MACOSX) | |
97 | |
98 using base::Time; | 94 using base::Time; |
99 | 95 |
100 class AutomationInterstitialPage : public InterstitialPage { | 96 class AutomationInterstitialPage : public InterstitialPage { |
101 public: | 97 public: |
102 AutomationInterstitialPage(TabContents* tab, | 98 AutomationInterstitialPage(TabContents* tab, |
103 const GURL& url, | 99 const GURL& url, |
104 const std::string& contents) | 100 const std::string& contents) |
105 : InterstitialPage(tab, true, url), | 101 : InterstitialPage(tab, true, url), |
106 contents_(contents) { | 102 contents_(contents) { |
107 } | 103 } |
108 | 104 |
109 virtual std::string GetHTMLContents() { return contents_; } | 105 virtual std::string GetHTMLContents() { return contents_; } |
110 | 106 |
111 private: | 107 private: |
112 std::string contents_; | 108 std::string contents_; |
113 | 109 |
114 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); | 110 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
115 }; | 111 }; |
116 | 112 |
117 #if !defined(OS_MACOSX) | |
118 class ClickTask : public Task { | 113 class ClickTask : public Task { |
119 public: | 114 public: |
120 explicit ClickTask(int flags) : flags_(flags) {} | 115 explicit ClickTask(int flags) : flags_(flags) {} |
121 virtual ~ClickTask() {} | 116 virtual ~ClickTask() {} |
122 | 117 |
123 virtual void Run() { | 118 virtual void Run() { |
124 ui_controls::MouseButton button = ui_controls::LEFT; | 119 ui_controls::MouseButton button = ui_controls::LEFT; |
125 if ((flags_ & views::Event::EF_LEFT_BUTTON_DOWN) == | 120 if ((flags_ & views::Event::EF_LEFT_BUTTON_DOWN) == |
126 views::Event::EF_LEFT_BUTTON_DOWN) { | 121 views::Event::EF_LEFT_BUTTON_DOWN) { |
127 button = ui_controls::LEFT; | 122 button = ui_controls::LEFT; |
128 } else if ((flags_ & views::Event::EF_RIGHT_BUTTON_DOWN) == | 123 } else if ((flags_ & views::Event::EF_RIGHT_BUTTON_DOWN) == |
129 views::Event::EF_RIGHT_BUTTON_DOWN) { | 124 views::Event::EF_RIGHT_BUTTON_DOWN) { |
130 button = ui_controls::RIGHT; | 125 button = ui_controls::RIGHT; |
131 } else if ((flags_ & views::Event::EF_MIDDLE_BUTTON_DOWN) == | 126 } else if ((flags_ & views::Event::EF_MIDDLE_BUTTON_DOWN) == |
132 views::Event::EF_MIDDLE_BUTTON_DOWN) { | 127 views::Event::EF_MIDDLE_BUTTON_DOWN) { |
133 button = ui_controls::MIDDLE; | 128 button = ui_controls::MIDDLE; |
134 } else { | 129 } else { |
135 NOTREACHED(); | 130 NOTREACHED(); |
136 } | 131 } |
137 | 132 |
138 ui_controls::SendMouseClick(button); | 133 ui_controls::SendMouseClick(button); |
139 } | 134 } |
140 | 135 |
141 private: | 136 private: |
142 int flags_; | 137 int flags_; |
143 | 138 |
144 DISALLOW_COPY_AND_ASSIGN(ClickTask); | 139 DISALLOW_COPY_AND_ASSIGN(ClickTask); |
145 }; | 140 }; |
146 #endif | |
147 | 141 |
148 AutomationProvider::AutomationProvider(Profile* profile) | 142 AutomationProvider::AutomationProvider(Profile* profile) |
149 : redirect_query_(0), | 143 : redirect_query_(0), |
150 profile_(profile), | 144 profile_(profile), |
151 reply_message_(NULL), | 145 reply_message_(NULL), |
152 popup_menu_waiter_(NULL) { | 146 popup_menu_waiter_(NULL) { |
153 browser_tracker_.reset(new AutomationBrowserTracker(this)); | 147 browser_tracker_.reset(new AutomationBrowserTracker(this)); |
154 extension_tracker_.reset(new AutomationExtensionTracker(this)); | 148 extension_tracker_.reset(new AutomationExtensionTracker(this)); |
155 tab_tracker_.reset(new AutomationTabTracker(this)); | 149 tab_tracker_.reset(new AutomationTabTracker(this)); |
156 window_tracker_.reset(new AutomationWindowTracker(this)); | 150 window_tracker_.reset(new AutomationWindowTracker(this)); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowMaximized, IsWindowMaximized) | 348 IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowMaximized, IsWindowMaximized) |
355 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, | 349 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, |
356 ExecuteBrowserCommandAsync) | 350 ExecuteBrowserCommandAsync) |
357 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, | 351 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, |
358 ExecuteBrowserCommand) | 352 ExecuteBrowserCommand) |
359 IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) | 353 IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) |
360 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) | 354 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) |
361 IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) | 355 IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) |
362 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) | 356 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) |
363 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) | 357 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) |
364 #if !defined(OS_MACOSX) | |
365 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) | 358 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) |
366 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) | 359 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) |
367 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) | 360 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) |
| 361 #if !defined(OS_MACOSX) |
368 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, | 362 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, |
369 WindowSimulateDrag) | 363 WindowSimulateDrag) |
370 #endif | 364 #endif // !defined(OS_MACOSX) |
371 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) | 365 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) |
372 IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) | 366 IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) |
373 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) | 367 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) |
374 #if defined(OS_WIN) | 368 #if defined(OS_WIN) |
375 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) | 369 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) |
376 #endif // defined(OS_WIN) | 370 #endif // defined(OS_WIN) |
377 IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) | 371 IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) |
378 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) | 372 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) |
379 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) | 373 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) |
380 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) | 374 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 virtual void Run() { | 965 virtual void Run() { |
972 MessageLoop::current()->PostTask(FROM_HERE, task_); | 966 MessageLoop::current()->PostTask(FROM_HERE, task_); |
973 } | 967 } |
974 | 968 |
975 private: | 969 private: |
976 Task* task_; | 970 Task* task_; |
977 | 971 |
978 DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); | 972 DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); |
979 }; | 973 }; |
980 | 974 |
981 #if !defined(OS_MACOSX) | |
982 void AutomationProvider::WindowSimulateClick(const IPC::Message& message, | 975 void AutomationProvider::WindowSimulateClick(const IPC::Message& message, |
983 int handle, | 976 int handle, |
984 const gfx::Point& click, | 977 const gfx::Point& click, |
985 int flags) { | 978 int flags) { |
986 if (window_tracker_->ContainsHandle(handle)) { | 979 if (window_tracker_->ContainsHandle(handle)) { |
987 ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(), | 980 ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(), |
988 new ClickTask(flags)); | 981 new ClickTask(flags)); |
989 } | 982 } |
990 } | 983 } |
991 | 984 |
(...skipping 12 matching lines...) Expand all Loading... |
1004 return; | 997 return; |
1005 | 998 |
1006 gfx::NativeWindow window = window_tracker_->GetResource(handle); | 999 gfx::NativeWindow window = window_tracker_->GetResource(handle); |
1007 // The key event is sent to whatever window is active. | 1000 // The key event is sent to whatever window is active. |
1008 ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key), | 1001 ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key), |
1009 ((flags & views::Event::EF_CONTROL_DOWN) == | 1002 ((flags & views::Event::EF_CONTROL_DOWN) == |
1010 views::Event::EF_CONTROL_DOWN), | 1003 views::Event::EF_CONTROL_DOWN), |
1011 ((flags & views::Event::EF_SHIFT_DOWN) == | 1004 ((flags & views::Event::EF_SHIFT_DOWN) == |
1012 views::Event::EF_SHIFT_DOWN), | 1005 views::Event::EF_SHIFT_DOWN), |
1013 ((flags & views::Event::EF_ALT_DOWN) == | 1006 ((flags & views::Event::EF_ALT_DOWN) == |
1014 views::Event::EF_ALT_DOWN)); | 1007 views::Event::EF_ALT_DOWN), |
| 1008 ((flags & views::Event::EF_COMMAND_DOWN) == |
| 1009 views::Event::EF_COMMAND_DOWN)); |
1015 } | 1010 } |
1016 #endif // !defined(OS_MACOSX) | |
1017 | 1011 |
1018 void AutomationProvider::IsWindowActive(int handle, bool* success, | 1012 void AutomationProvider::IsWindowActive(int handle, bool* success, |
1019 bool* is_active) { | 1013 bool* is_active) { |
1020 if (window_tracker_->ContainsHandle(handle)) { | 1014 if (window_tracker_->ContainsHandle(handle)) { |
1021 *is_active = | 1015 *is_active = |
1022 platform_util::IsWindowActive(window_tracker_->GetResource(handle)); | 1016 platform_util::IsWindowActive(window_tracker_->GetResource(handle)); |
1023 *success = true; | 1017 *success = true; |
1024 } else { | 1018 } else { |
1025 *success = false; | 1019 *success = false; |
1026 *is_active = false; | 1020 *is_active = false; |
(...skipping 2091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3118 } | 3112 } |
3119 | 3113 |
3120 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 3114 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
3121 NOTIMPLEMENTED(); | 3115 NOTIMPLEMENTED(); |
3122 } | 3116 } |
3123 #endif // !defined(TOOLKIT_VIEWS) | 3117 #endif // !defined(TOOLKIT_VIEWS) |
3124 | 3118 |
3125 void AutomationProvider::ResetToDefaultTheme() { | 3119 void AutomationProvider::ResetToDefaultTheme() { |
3126 profile_->ClearTheme(); | 3120 profile_->ClearTheme(); |
3127 } | 3121 } |
OLD | NEW |