[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1 | // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/browser/automation/automation_provider.h" |
| 6 | |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 7 | #include "app/l10n_util.h" |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 8 | #include "app/message_box_flags.h" |
[email protected] | c6cb199 | 2009-04-13 16:45:29 | [diff] [blame] | 9 | #include "base/file_version_info.h" |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 10 | #include "base/json_reader.h" |
[email protected] | 5fac962 | 2009-02-04 21:49:38 | [diff] [blame] | 11 | #include "base/message_loop.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/path_service.h" |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 13 | #include "base/stl_util-inl.h" |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 5fac962 | 2009-02-04 21:49:38 | [diff] [blame] | 15 | #include "base/thread.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 16 | #include "base/values.h" |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 17 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 18 | #include "chrome/browser/app_modal_dialog.h" |
[email protected] | 464146e | 2009-04-09 18:17:09 | [diff] [blame] | 19 | #include "chrome/browser/app_modal_dialog_queue.h" |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 20 | #include "chrome/browser/automation/automation_extension_function.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "chrome/browser/automation/automation_provider_list.h" |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 22 | #include "chrome/browser/automation/extension_automation_constants.h" |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 23 | #include "chrome/browser/automation/extension_port_container.h" |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 24 | #include "chrome/browser/blocked_popup_container.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 25 | #include "chrome/browser/browser_process.h" |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 26 | #include "chrome/browser/browser_window.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | #include "chrome/browser/dom_operation_notification_details.h" |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 28 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | cdaa865 | 2008-09-13 02:48:59 | [diff] [blame] | 29 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 30 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_message_service.h" |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 32 | #include "chrome/browser/find_bar.h" |
| 33 | #include "chrome/browser/find_bar_controller.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | #include "chrome/browser/find_notification_details.h" |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 35 | #include "chrome/browser/location_bar.h" |
[email protected] | f732c1e | 2009-07-30 15:48:53 | [diff] [blame] | 36 | #include "chrome/browser/net/url_request_mock_util.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 37 | #include "chrome/browser/profile_manager.h" |
[email protected] | 6524b5f9 | 2009-01-22 17:48:25 | [diff] [blame] | 38 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 3b073b2 | 2009-01-16 03:29:03 | [diff] [blame] | 39 | #include "chrome/browser/ssl/ssl_manager.h" |
| 40 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 41 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 81af939 | 2009-04-21 02:37:45 | [diff] [blame] | 42 | #include "chrome/browser/tab_contents/tab_contents_view.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 43 | #include "chrome/common/automation_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | #include "chrome/common/chrome_paths.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 45 | #include "chrome/common/json_value_serializer.h" |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 46 | #include "chrome/common/notification_service.h" |
[email protected] | 3753f52 | 2009-04-14 23:15:47 | [diff] [blame] | 47 | #include "chrome/common/platform_util.h" |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 48 | #include "chrome/common/pref_service.h" |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 49 | #include "chrome/test/automation/automation_messages.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 50 | #include "net/proxy/proxy_service.h" |
| 51 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 52 | #include "net/url_request/url_request_context.h" |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 53 | #include "views/event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 55 | #if defined(OS_WIN) |
| 56 | // TODO(port): Port these headers. |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 57 | #include "chrome/browser/character_encoding.h" |
| 58 | #include "chrome/browser/download/save_package.h" |
| 59 | #include "chrome/browser/external_tab_container.h" |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 60 | #include "chrome/browser/printing/print_job.h" |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 61 | #endif // defined(OS_WIN) |
| 62 | |
[email protected] | e838217 | 2009-06-19 22:16:28 | [diff] [blame] | 63 | #if defined(OS_WIN) || defined(OS_LINUX) |
| 64 | // TODO(port): Port these to the mac. |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 65 | #include "chrome/browser/automation/ui_controls.h" |
[email protected] | e838217 | 2009-06-19 22:16:28 | [diff] [blame] | 66 | #include "chrome/browser/login_prompt.h" |
| 67 | #endif |
| 68 | |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 69 | #if defined(OS_WIN) |
| 70 | #include "chrome/browser/views/bookmark_bar_view.h" |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 71 | #include "views/widget/root_view.h" |
[email protected] | 2362e4f | 2009-05-08 00:34:05 | [diff] [blame] | 72 | #include "views/widget/widget_win.h" |
| 73 | #include "views/window/window.h" |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 74 | #endif |
| 75 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 76 | using base::Time; |
| 77 | |
[email protected] | f544609 | 2009-07-30 21:10:01 | [diff] [blame] | 78 | #if defined(OS_WIN) |
| 79 | static void MoveMouse(const POINT& point) { |
| 80 | SetCursorPos(point.x, point.y); |
| 81 | |
| 82 | // Now, make sure that GetMessagePos returns the values we just set by |
| 83 | // simulating a mouse move. The value returned by GetMessagePos is updated |
| 84 | // when a mouse move event is removed from the event queue. |
| 85 | PostMessage(NULL, WM_MOUSEMOVE, 0, MAKELPARAM(point.x, point.y)); |
| 86 | MSG msg; |
| 87 | while (PeekMessage(&msg, NULL, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)) |
| 88 | ; |
| 89 | |
| 90 | // Verify |
| 91 | #ifndef NDEBUG |
| 92 | DWORD pos = GetMessagePos(); |
| 93 | DCHECK_EQ(point.x, GET_X_LPARAM(pos)); |
| 94 | DCHECK_EQ(point.y, GET_Y_LPARAM(pos)); |
| 95 | #endif |
| 96 | } |
| 97 | #endif |
| 98 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | class InitialLoadObserver : public NotificationObserver { |
| 100 | public: |
| 101 | InitialLoadObserver(size_t tab_count, AutomationProvider* automation) |
[email protected] | 66791d2 | 2009-02-24 20:11:33 | [diff] [blame] | 102 | : automation_(automation), |
| 103 | outstanding_tab_count_(tab_count) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 104 | if (outstanding_tab_count_ > 0) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 105 | registrar_.Add(this, NotificationType::LOAD_START, |
[email protected] | 6a02963e | 2009-01-06 16:58:03 | [diff] [blame] | 106 | NotificationService::AllSources()); |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 107 | registrar_.Add(this, NotificationType::LOAD_STOP, |
[email protected] | 6a02963e | 2009-01-06 16:58:03 | [diff] [blame] | 108 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | ~InitialLoadObserver() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void ConditionMet() { |
[email protected] | 6a02963e | 2009-01-06 16:58:03 | [diff] [blame] | 116 | registrar_.RemoveAll(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 117 | automation_->Send(new AutomationMsg_InitialLoadsComplete(0)); |
| 118 | } |
| 119 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | virtual void Observe(NotificationType type, |
| 121 | const NotificationSource& source, |
| 122 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 123 | if (type == NotificationType::LOAD_START) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 124 | if (outstanding_tab_count_ > loading_tabs_.size()) |
| 125 | loading_tabs_.insert(source.map_key()); |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 126 | } else if (type == NotificationType::LOAD_STOP) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 127 | if (outstanding_tab_count_ > finished_tabs_.size()) { |
| 128 | if (loading_tabs_.find(source.map_key()) != loading_tabs_.end()) |
| 129 | finished_tabs_.insert(source.map_key()); |
| 130 | if (outstanding_tab_count_ == finished_tabs_.size()) |
| 131 | ConditionMet(); |
| 132 | } |
| 133 | } else { |
| 134 | NOTREACHED(); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | private: |
| 139 | typedef std::set<uintptr_t> TabSet; |
| 140 | |
[email protected] | 6a02963e | 2009-01-06 16:58:03 | [diff] [blame] | 141 | NotificationRegistrar registrar_; |
| 142 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 143 | AutomationProvider* automation_; |
| 144 | size_t outstanding_tab_count_; |
| 145 | TabSet loading_tabs_; |
| 146 | TabSet finished_tabs_; |
| 147 | }; |
| 148 | |
| 149 | // Watches for NewTabUI page loads for performance timing purposes. |
| 150 | class NewTabUILoadObserver : public NotificationObserver { |
| 151 | public: |
| 152 | explicit NewTabUILoadObserver(AutomationProvider* automation) |
| 153 | : automation_(automation) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 154 | registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD, |
| 155 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | ~NewTabUILoadObserver() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | virtual void Observe(NotificationType type, |
| 162 | const NotificationSource& source, |
| 163 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 164 | if (type == NotificationType::INITIAL_NEW_TAB_UI_LOAD) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 165 | Details<int> load_time(details); |
| 166 | automation_->Send( |
| 167 | new AutomationMsg_InitialNewTabUILoadComplete(0, *load_time.ptr())); |
| 168 | } else { |
| 169 | NOTREACHED(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | private: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 174 | NotificationRegistrar registrar_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 175 | AutomationProvider* automation_; |
| 176 | }; |
| 177 | |
| 178 | class NavigationControllerRestoredObserver : public NotificationObserver { |
| 179 | public: |
| 180 | NavigationControllerRestoredObserver(AutomationProvider* automation, |
| 181 | NavigationController* controller, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 182 | IPC::Message* reply_message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 183 | : automation_(automation), |
| 184 | controller_(controller), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 185 | reply_message_(reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 186 | if (FinishedRestoring()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | SendDone(); |
| 188 | } else { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 189 | registrar_.Add(this, NotificationType::LOAD_STOP, |
| 190 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
| 194 | ~NavigationControllerRestoredObserver() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | virtual void Observe(NotificationType type, |
| 198 | const NotificationSource& source, |
| 199 | const NotificationDetails& details) { |
| 200 | if (FinishedRestoring()) { |
| 201 | SendDone(); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 202 | registrar_.RemoveAll(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | private: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 207 | bool FinishedRestoring() { |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 208 | return (!controller_->needs_reload() && !controller_->pending_entry() && |
| 209 | !controller_->tab_contents()->is_loading()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void SendDone() { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 213 | DCHECK(reply_message_ != NULL); |
| 214 | automation_->Send(reply_message_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 215 | } |
| 216 | |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 217 | NotificationRegistrar registrar_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 218 | AutomationProvider* automation_; |
| 219 | NavigationController* controller_; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 220 | IPC::Message* reply_message_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 221 | |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 222 | DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 223 | }; |
| 224 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 225 | template<class NavigationCodeType> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 226 | class NavigationNotificationObserver : public NotificationObserver { |
| 227 | public: |
| 228 | NavigationNotificationObserver(NavigationController* controller, |
| 229 | AutomationProvider* automation, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 230 | IPC::Message* reply_message, |
| 231 | NavigationCodeType success_code, |
| 232 | NavigationCodeType auth_needed_code, |
| 233 | NavigationCodeType failed_code) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 234 | : automation_(automation), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 235 | reply_message_(reply_message), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 236 | controller_(controller), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 237 | navigation_started_(false), |
| 238 | success_code_(success_code), |
| 239 | auth_needed_code_(auth_needed_code), |
| 240 | failed_code_(failed_code) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 241 | Source<NavigationController> source(controller_); |
| 242 | registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source); |
| 243 | registrar_.Add(this, NotificationType::LOAD_START, source); |
| 244 | registrar_.Add(this, NotificationType::LOAD_STOP, source); |
| 245 | registrar_.Add(this, NotificationType::AUTH_NEEDED, source); |
| 246 | registrar_.Add(this, NotificationType::AUTH_SUPPLIED, source); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | ~NavigationNotificationObserver() { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 250 | if (reply_message_) { |
| 251 | // This means we did not receive a notification for this navigation. |
| 252 | // Send over a failed navigation status back to the caller to ensure that |
| 253 | // the caller does not hang waiting for the response. |
| 254 | IPC::ParamTraits<NavigationCodeType>::Write(reply_message_, |
| 255 | failed_code_); |
| 256 | automation_->Send(reply_message_); |
| 257 | reply_message_ = NULL; |
| 258 | } |
| 259 | |
| 260 | automation_->RemoveNavigationStatusListener(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 261 | } |
| 262 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 263 | void ConditionMet(NavigationCodeType navigation_result) { |
| 264 | DCHECK(reply_message_ != NULL); |
| 265 | |
| 266 | IPC::ParamTraits<NavigationCodeType>::Write(reply_message_, |
| 267 | navigation_result); |
| 268 | automation_->Send(reply_message_); |
| 269 | reply_message_ = NULL; |
| 270 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 271 | delete this; |
| 272 | } |
| 273 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 274 | virtual void Observe(NotificationType type, |
| 275 | const NotificationSource& source, |
| 276 | const NotificationDetails& details) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 277 | // We listen for 2 events to determine when the navigation started because: |
| 278 | // - when this is used by the WaitForNavigation method, we might be invoked |
| 279 | // afer the load has started (but not after the entry was committed, as |
| 280 | // WaitForNavigation compares times of the last navigation). |
| 281 | // - when this is used with a page requiring authentication, we will not get |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 282 | // a NotificationType::NAV_ENTRY_COMMITTED until after we authenticate, so |
| 283 | // we need the NotificationType::LOAD_START. |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 284 | if (type == NotificationType::NAV_ENTRY_COMMITTED || |
| 285 | type == NotificationType::LOAD_START) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | navigation_started_ = true; |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 287 | } else if (type == NotificationType::LOAD_STOP) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 288 | if (navigation_started_) { |
| 289 | navigation_started_ = false; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 290 | ConditionMet(success_code_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | } |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 292 | } else if (type == NotificationType::AUTH_SUPPLIED) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 293 | // The LoginHandler for this tab is no longer valid. |
| 294 | automation_->RemoveLoginHandler(controller_); |
| 295 | |
| 296 | // Treat this as if navigation started again, since load start/stop don't |
| 297 | // occur while authentication is ongoing. |
| 298 | navigation_started_ = true; |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 299 | } else if (type == NotificationType::AUTH_NEEDED) { |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 300 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 301 | if (navigation_started_) { |
| 302 | // Remember the login handler that wants authentication. |
| 303 | LoginHandler* handler = |
| 304 | Details<LoginNotificationDetails>(details)->handler(); |
| 305 | automation_->AddLoginHandler(controller_, handler); |
| 306 | |
| 307 | // Respond that authentication is needed. |
| 308 | navigation_started_ = false; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 309 | ConditionMet(auth_needed_code_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 310 | } else { |
| 311 | NOTREACHED(); |
| 312 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 313 | #else |
| 314 | // TODO(port): Enable when we have LoginNotificationDetails etc. |
| 315 | NOTIMPLEMENTED(); |
| 316 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 317 | } else { |
| 318 | NOTREACHED(); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | private: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 323 | NotificationRegistrar registrar_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 324 | AutomationProvider* automation_; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 325 | IPC::Message* reply_message_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 326 | NavigationController* controller_; |
| 327 | bool navigation_started_; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 328 | NavigationCodeType success_code_; |
| 329 | NavigationCodeType auth_needed_code_; |
| 330 | NavigationCodeType failed_code_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | class TabStripNotificationObserver : public NotificationObserver { |
| 334 | public: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 335 | TabStripNotificationObserver(NotificationType notification, |
| 336 | AutomationProvider* automation) |
| 337 | : automation_(automation), |
| 338 | notification_(notification) { |
| 339 | registrar_.Add(this, notification_, NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | virtual ~TabStripNotificationObserver() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | virtual void Observe(NotificationType type, |
| 346 | const NotificationSource& source, |
| 347 | const NotificationDetails& details) { |
| 348 | if (type == notification_) { |
| 349 | ObserveTab(Source<NavigationController>(source).ptr()); |
| 350 | |
| 351 | // If verified, no need to observe anymore |
| 352 | automation_->RemoveTabStripObserver(this); |
| 353 | delete this; |
| 354 | } else { |
| 355 | NOTREACHED(); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | virtual void ObserveTab(NavigationController* controller) = 0; |
| 360 | |
| 361 | protected: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 362 | NotificationRegistrar registrar_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 363 | AutomationProvider* automation_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 364 | NotificationType notification_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | class TabAppendedNotificationObserver : public TabStripNotificationObserver { |
| 368 | public: |
| 369 | TabAppendedNotificationObserver(Browser* parent, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 370 | AutomationProvider* automation, |
| 371 | IPC::Message* reply_message) |
| 372 | : TabStripNotificationObserver(NotificationType::TAB_PARENTED, |
| 373 | automation), |
| 374 | parent_(parent), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 375 | reply_message_(reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | virtual void ObserveTab(NavigationController* controller) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 379 | if (automation_->GetIndexForNavigationController(controller, parent_) == |
| 380 | TabStripModel::kNoTab) { |
| 381 | // This tab notification doesn't belong to the parent_. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 382 | return; |
| 383 | } |
| 384 | |
| 385 | // Give the same response even if auth is needed, since it doesn't matter. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 386 | automation_->AddNavigationStatusListener<int>( |
| 387 | controller, reply_message_, AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 388 | AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, AUTOMATION_MSG_NAVIGATION_ERROR); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 389 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 390 | |
| 391 | protected: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 392 | Browser* parent_; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 393 | IPC::Message* reply_message_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 394 | }; |
| 395 | |
| 396 | class TabClosedNotificationObserver : public TabStripNotificationObserver { |
| 397 | public: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 398 | TabClosedNotificationObserver(AutomationProvider* automation, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 399 | bool wait_until_closed, |
| 400 | IPC::Message* reply_message) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 401 | : TabStripNotificationObserver(wait_until_closed ? |
| 402 | NotificationType::TAB_CLOSED : NotificationType::TAB_CLOSING, |
| 403 | automation), |
| 404 | reply_message_(reply_message), |
| 405 | for_browser_command_(false) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | virtual void ObserveTab(NavigationController* controller) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 409 | if (for_browser_command_) { |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 410 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, |
| 411 | true); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 412 | } else { |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 413 | AutomationMsg_CloseTab::WriteReplyParams(reply_message_, true); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 414 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 415 | automation_->Send(reply_message_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 416 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 417 | |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 418 | void set_for_browser_command(bool for_browser_command) { |
| 419 | for_browser_command_ = for_browser_command; |
| 420 | } |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 421 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 422 | protected: |
| 423 | IPC::Message* reply_message_; |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 424 | bool for_browser_command_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 425 | }; |
| 426 | |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 427 | class BrowserOpenedNotificationObserver : public NotificationObserver { |
| 428 | public: |
| 429 | BrowserOpenedNotificationObserver(AutomationProvider* automation, |
| 430 | IPC::Message* reply_message) |
| 431 | : automation_(automation), |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 432 | reply_message_(reply_message), |
| 433 | for_browser_command_(false) { |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 434 | registrar_.Add(this, NotificationType::BROWSER_OPENED, |
| 435 | NotificationService::AllSources()); |
| 436 | } |
| 437 | |
| 438 | ~BrowserOpenedNotificationObserver() { |
| 439 | } |
| 440 | |
| 441 | virtual void Observe(NotificationType type, |
| 442 | const NotificationSource& source, |
| 443 | const NotificationDetails& details) { |
| 444 | if (type == NotificationType::BROWSER_OPENED) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 445 | if (for_browser_command_) { |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 446 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, |
| 447 | true); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 448 | } |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 449 | automation_->Send(reply_message_); |
| 450 | delete this; |
| 451 | } else { |
| 452 | NOTREACHED(); |
| 453 | } |
| 454 | } |
| 455 | |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 456 | void set_for_browser_command(bool for_browser_command) { |
| 457 | for_browser_command_ = for_browser_command; |
| 458 | } |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 459 | |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 460 | private: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 461 | NotificationRegistrar registrar_; |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 462 | AutomationProvider* automation_; |
| 463 | IPC::Message* reply_message_; |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 464 | bool for_browser_command_; |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 465 | }; |
| 466 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 467 | class BrowserClosedNotificationObserver : public NotificationObserver { |
| 468 | public: |
| 469 | BrowserClosedNotificationObserver(Browser* browser, |
| 470 | AutomationProvider* automation, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 471 | IPC::Message* reply_message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 472 | : automation_(automation), |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 473 | reply_message_(reply_message), |
| 474 | for_browser_command_(false) { |
[email protected] | c300deb3 | 2009-05-08 21:26:07 | [diff] [blame] | 475 | registrar_.Add(this, NotificationType::BROWSER_CLOSED, |
| 476 | Source<Browser>(browser)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | virtual void Observe(NotificationType type, |
| 480 | const NotificationSource& source, |
| 481 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 482 | DCHECK(type == NotificationType::BROWSER_CLOSED); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 483 | Details<bool> close_app(details); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 484 | DCHECK(reply_message_ != NULL); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 485 | if (for_browser_command_) { |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 486 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, |
| 487 | true); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 488 | } else { |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 489 | AutomationMsg_CloseBrowser::WriteReplyParams(reply_message_, true, |
| 490 | *(close_app.ptr())); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 491 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 492 | automation_->Send(reply_message_); |
| 493 | reply_message_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 494 | delete this; |
| 495 | } |
| 496 | |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 497 | void set_for_browser_command(bool for_browser_command) { |
| 498 | for_browser_command_ = for_browser_command; |
| 499 | } |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 500 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 501 | private: |
[email protected] | c300deb3 | 2009-05-08 21:26:07 | [diff] [blame] | 502 | NotificationRegistrar registrar_; |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 503 | AutomationProvider* automation_; |
| 504 | IPC::Message* reply_message_; |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 505 | bool for_browser_command_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 506 | }; |
| 507 | |
[email protected] | 4e41709d | 2009-04-08 00:04:27 | [diff] [blame] | 508 | namespace { |
| 509 | |
| 510 | // Define mapping from command to notification |
| 511 | struct CommandNotification { |
| 512 | int command; |
| 513 | NotificationType::Type notification_type; |
| 514 | }; |
| 515 | |
| 516 | const struct CommandNotification command_notifications[] = { |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 517 | {IDC_DUPLICATE_TAB, NotificationType::TAB_PARENTED}, |
[email protected] | f8fc588 | 2009-05-06 04:23:43 | [diff] [blame] | 518 | {IDC_NEW_TAB, NotificationType::TAB_PARENTED}, |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 519 | // Returns as soon as the restored tab is created. To further wait until |
| 520 | // the content page is loaded, use WaitForTabToBeRestored. |
[email protected] | f8fc588 | 2009-05-06 04:23:43 | [diff] [blame] | 521 | {IDC_RESTORE_TAB, NotificationType::TAB_PARENTED} |
[email protected] | 4e41709d | 2009-04-08 00:04:27 | [diff] [blame] | 522 | }; |
| 523 | |
| 524 | } // namespace |
| 525 | |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 526 | class ExecuteBrowserCommandObserver : public NotificationObserver { |
| 527 | public: |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 528 | ~ExecuteBrowserCommandObserver() { |
| 529 | } |
| 530 | |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 531 | static bool CreateAndRegisterObserver(AutomationProvider* automation, |
| 532 | Browser* browser, |
| 533 | int command, |
| 534 | IPC::Message* reply_message) { |
| 535 | bool result = true; |
| 536 | switch (command) { |
| 537 | case IDC_NEW_WINDOW: |
| 538 | case IDC_NEW_INCOGNITO_WINDOW: { |
| 539 | BrowserOpenedNotificationObserver* observer = |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 540 | new BrowserOpenedNotificationObserver(automation, reply_message); |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 541 | observer->set_for_browser_command(true); |
| 542 | break; |
| 543 | } |
| 544 | case IDC_CLOSE_WINDOW: { |
| 545 | BrowserClosedNotificationObserver* observer = |
| 546 | new BrowserClosedNotificationObserver(browser, automation, |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 547 | reply_message); |
| 548 | observer->set_for_browser_command(true); |
| 549 | break; |
| 550 | } |
| 551 | case IDC_CLOSE_TAB: { |
| 552 | TabClosedNotificationObserver* observer = |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 553 | new TabClosedNotificationObserver(automation, true, reply_message); |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 554 | observer->set_for_browser_command(true); |
| 555 | break; |
| 556 | } |
[email protected] | 27e1c9e0 | 2009-05-13 18:41:39 | [diff] [blame] | 557 | case IDC_BACK: |
| 558 | case IDC_FORWARD: |
| 559 | case IDC_RELOAD: { |
| 560 | automation-> |
| 561 | AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>( |
| 562 | &browser->GetSelectedTabContents()->controller(), |
| 563 | reply_message, |
| 564 | AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 565 | AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, |
| 566 | AUTOMATION_MSG_NAVIGATION_ERROR); |
| 567 | break; |
| 568 | } |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 569 | default: { |
| 570 | ExecuteBrowserCommandObserver* observer = |
| 571 | new ExecuteBrowserCommandObserver(automation, reply_message); |
| 572 | if (!observer->Register(command)) { |
| 573 | delete observer; |
| 574 | result = false; |
| 575 | } |
| 576 | break; |
| 577 | } |
| 578 | } |
| 579 | return result; |
[email protected] | 4e41709d | 2009-04-08 00:04:27 | [diff] [blame] | 580 | } |
| 581 | |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 582 | virtual void Observe(NotificationType type, |
| 583 | const NotificationSource& source, |
| 584 | const NotificationDetails& details) { |
| 585 | if (type == notification_type_) { |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 586 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message_, |
| 587 | true); |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 588 | automation_->Send(reply_message_); |
| 589 | delete this; |
| 590 | } else { |
| 591 | NOTREACHED(); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | private: |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 596 | ExecuteBrowserCommandObserver(AutomationProvider* automation, |
| 597 | IPC::Message* reply_message) |
| 598 | : automation_(automation), |
| 599 | reply_message_(reply_message) { |
| 600 | } |
| 601 | |
| 602 | bool Register(int command) { |
| 603 | if (!GetNotificationType(command, ¬ification_type_)) |
| 604 | return false; |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 605 | registrar_.Add(this, notification_type_, NotificationService::AllSources()); |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 606 | return true; |
| 607 | } |
| 608 | |
[email protected] | 4e41709d | 2009-04-08 00:04:27 | [diff] [blame] | 609 | bool GetNotificationType(int command, NotificationType::Type* type) { |
| 610 | if (!type) |
| 611 | return false; |
| 612 | bool found = false; |
| 613 | for (unsigned int i = 0; i < arraysize(command_notifications); i++) { |
| 614 | if (command_notifications[i].command == command) { |
| 615 | *type = command_notifications[i].notification_type; |
| 616 | found = true; |
| 617 | break; |
| 618 | } |
| 619 | } |
| 620 | return found; |
| 621 | } |
| 622 | |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 623 | NotificationRegistrar registrar_; |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 624 | AutomationProvider* automation_; |
| 625 | NotificationType::Type notification_type_; |
| 626 | IPC::Message* reply_message_; |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 627 | }; |
| 628 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 629 | class FindInPageNotificationObserver : public NotificationObserver { |
| 630 | public: |
| 631 | FindInPageNotificationObserver(AutomationProvider* automation, |
| 632 | TabContents* parent_tab, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 633 | IPC::Message* reply_message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 634 | : automation_(automation), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 635 | active_match_ordinal_(-1), |
| 636 | reply_message_(reply_message) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 637 | registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, |
| 638 | Source<TabContents>(parent_tab)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | ~FindInPageNotificationObserver() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 642 | } |
| 643 | |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 644 | virtual void Observe(NotificationType type, |
| 645 | const NotificationSource& source, |
| 646 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 647 | if (type == NotificationType::FIND_RESULT_AVAILABLE) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 648 | Details<FindNotificationDetails> find_details(details); |
| 649 | if (find_details->request_id() == kFindInPageRequestId) { |
[email protected] | aedd85a | 2008-12-04 19:32:49 | [diff] [blame] | 650 | // We get multiple responses and one of those will contain the ordinal. |
| 651 | // This message comes to us before the final update is sent. |
| 652 | if (find_details->active_match_ordinal() > -1) |
| 653 | active_match_ordinal_ = find_details->active_match_ordinal(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 654 | if (find_details->final_update()) { |
[email protected] | d97a564 | 2009-07-16 19:33:26 | [diff] [blame] | 655 | if (reply_message_ != NULL) { |
| 656 | AutomationMsg_FindInPage::WriteReplyParams(reply_message_, |
| 657 | active_match_ordinal_, find_details->number_of_matches()); |
| 658 | automation_->Send(reply_message_); |
| 659 | reply_message_ = NULL; |
| 660 | } else { |
| 661 | DLOG(WARNING) << "Multiple final Find messages observed."; |
| 662 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 663 | } else { |
| 664 | DLOG(INFO) << "Ignoring, since we only care about the final message"; |
| 665 | } |
| 666 | } |
| 667 | } else { |
| 668 | NOTREACHED(); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | // The Find mechanism is over asynchronous IPC, so a search is kicked off and |
| 673 | // we wait for notification to find out what the results are. As the user is |
| 674 | // typing, new search requests can be issued and the Request ID helps us make |
| 675 | // sense of whether this is the current request or an old one. The unit tests, |
| 676 | // however, which uses this constant issues only one search at a time, so we |
| 677 | // don't need a rolling id to identify each search. But, we still need to |
| 678 | // specify one, so we just use a fixed one - its value does not matter. |
| 679 | static const int kFindInPageRequestId; |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 680 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 681 | private: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 682 | NotificationRegistrar registrar_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 683 | AutomationProvider* automation_; |
[email protected] | aedd85a | 2008-12-04 19:32:49 | [diff] [blame] | 684 | // We will at some point (before final update) be notified of the ordinal and |
| 685 | // we need to preserve it so we can send it later. |
| 686 | int active_match_ordinal_; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 687 | IPC::Message* reply_message_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 688 | }; |
| 689 | |
| 690 | const int FindInPageNotificationObserver::kFindInPageRequestId = -1; |
| 691 | |
| 692 | class DomOperationNotificationObserver : public NotificationObserver { |
| 693 | public: |
| 694 | explicit DomOperationNotificationObserver(AutomationProvider* automation) |
| 695 | : automation_(automation) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 696 | registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, |
| 697 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | ~DomOperationNotificationObserver() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | } |
| 702 | |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 703 | virtual void Observe(NotificationType type, |
| 704 | const NotificationSource& source, |
| 705 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 706 | if (NotificationType::DOM_OPERATION_RESPONSE == type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 707 | Details<DomOperationNotificationDetails> dom_op_details(details); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 708 | |
| 709 | IPC::Message* reply_message = automation_->reply_message_release(); |
| 710 | DCHECK(reply_message != NULL); |
| 711 | |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 712 | AutomationMsg_DomOperation::WriteReplyParams(reply_message, |
| 713 | dom_op_details->json()); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 714 | automation_->Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 715 | } |
| 716 | } |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 717 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 718 | private: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 719 | NotificationRegistrar registrar_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 720 | AutomationProvider* automation_; |
| 721 | }; |
| 722 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 723 | #if defined(OS_WIN) |
| 724 | // TODO(port): Enable when printing is ported. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 725 | class DocumentPrintedNotificationObserver : public NotificationObserver { |
| 726 | public: |
| 727 | DocumentPrintedNotificationObserver(AutomationProvider* automation, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 728 | IPC::Message* reply_message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 729 | : automation_(automation), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 730 | success_(false), |
| 731 | reply_message_(reply_message) { |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 732 | registrar_.Add(this, NotificationType::PRINT_JOB_EVENT, |
| 733 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | ~DocumentPrintedNotificationObserver() { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 737 | DCHECK(reply_message_ != NULL); |
| 738 | AutomationMsg_PrintNow::WriteReplyParams(reply_message_, success_); |
| 739 | automation_->Send(reply_message_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 740 | automation_->RemoveNavigationStatusListener(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | virtual void Observe(NotificationType type, const NotificationSource& source, |
| 744 | const NotificationDetails& details) { |
| 745 | using namespace printing; |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 746 | DCHECK(type == NotificationType::PRINT_JOB_EVENT); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 747 | switch (Details<JobEventDetails>(details)->type()) { |
| 748 | case JobEventDetails::JOB_DONE: { |
| 749 | // Succeeded. |
| 750 | success_ = true; |
| 751 | delete this; |
| 752 | break; |
| 753 | } |
| 754 | case JobEventDetails::USER_INIT_CANCELED: |
| 755 | case JobEventDetails::FAILED: { |
| 756 | // Failed. |
| 757 | delete this; |
| 758 | break; |
| 759 | } |
| 760 | case JobEventDetails::NEW_DOC: |
| 761 | case JobEventDetails::USER_INIT_DONE: |
| 762 | case JobEventDetails::DEFAULT_INIT_DONE: |
| 763 | case JobEventDetails::NEW_PAGE: |
| 764 | case JobEventDetails::PAGE_DONE: |
| 765 | case JobEventDetails::DOC_DONE: |
| 766 | case JobEventDetails::ALL_PAGES_REQUESTED: { |
| 767 | // Don't care. |
| 768 | break; |
| 769 | } |
| 770 | default: { |
| 771 | NOTREACHED(); |
| 772 | break; |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | private: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 778 | NotificationRegistrar registrar_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 779 | scoped_refptr<AutomationProvider> automation_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 780 | bool success_; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 781 | IPC::Message* reply_message_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 782 | }; |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 783 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 784 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 785 | class AutomationInterstitialPage : public InterstitialPage { |
| 786 | public: |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 787 | AutomationInterstitialPage(TabContents* tab, |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 788 | const GURL& url, |
| 789 | const std::string& contents) |
| 790 | : InterstitialPage(tab, true, url), |
| 791 | contents_(contents) { |
| 792 | } |
| 793 | |
| 794 | virtual std::string GetHTMLContents() { return contents_; } |
| 795 | |
| 796 | private: |
| 797 | std::string contents_; |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 798 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 799 | DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
| 800 | }; |
| 801 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 802 | AutomationProvider::AutomationProvider(Profile* profile) |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 803 | : redirect_query_(0), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 804 | profile_(profile), |
| 805 | reply_message_(NULL) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 806 | browser_tracker_.reset(new AutomationBrowserTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 807 | tab_tracker_.reset(new AutomationTabTracker(this)); |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 808 | window_tracker_.reset(new AutomationWindowTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 809 | autocomplete_edit_tracker_.reset( |
| 810 | new AutomationAutocompleteEditTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 811 | new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); |
| 812 | dom_operation_observer_.reset(new DomOperationNotificationObserver(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | AutomationProvider::~AutomationProvider() { |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 816 | STLDeleteContainerPairSecondPointers(port_containers_.begin(), |
| 817 | port_containers_.end()); |
| 818 | port_containers_.clear(); |
| 819 | |
[email protected] | 0da050b9 | 2008-08-19 19:29:47 | [diff] [blame] | 820 | // Make sure that any outstanding NotificationObservers also get destroyed. |
| 821 | ObserverList<NotificationObserver>::Iterator it(notification_observer_list_); |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 822 | NotificationObserver* observer; |
[email protected] | 0da050b9 | 2008-08-19 19:29:47 | [diff] [blame] | 823 | while ((observer = it.GetNext()) != NULL) |
| 824 | delete observer; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 825 | } |
| 826 | |
[email protected] | 9a3a293b | 2009-06-04 22:28:16 | [diff] [blame] | 827 | void AutomationProvider::ConnectToChannel(const std::string& channel_id) { |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 828 | automation_resource_message_filter_ = new AutomationResourceMessageFilter; |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 829 | channel_.reset( |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 830 | new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, |
| 831 | automation_resource_message_filter_, |
| 832 | g_browser_process->io_thread()->message_loop(), |
| 833 | true, g_browser_process->shutdown_event())); |
[email protected] | 79e96683 | 2009-04-21 14:23:05 | [diff] [blame] | 834 | scoped_ptr<FileVersionInfo> file_version_info( |
| 835 | FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
[email protected] | cf62075 | 2009-04-24 17:05:40 | [diff] [blame] | 836 | std::string version_string; |
| 837 | if (file_version_info != NULL) { |
| 838 | version_string = WideToASCII(file_version_info->file_version()); |
| 839 | } |
[email protected] | c6cb199 | 2009-04-13 16:45:29 | [diff] [blame] | 840 | |
| 841 | // Send a hello message with our current automation protocol version. |
| 842 | channel_->Send(new AutomationMsg_Hello(0, version_string.c_str())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { |
| 846 | if (expected_tabs == 0) { |
| 847 | Send(new AutomationMsg_InitialLoadsComplete(0)); |
| 848 | } else { |
| 849 | initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); |
| 850 | } |
| 851 | } |
| 852 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 853 | template<class NavigationCodeType> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 854 | NotificationObserver* AutomationProvider::AddNavigationStatusListener( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 855 | NavigationController* tab, IPC::Message* reply_message, |
| 856 | NavigationCodeType success_code, |
| 857 | NavigationCodeType auth_needed_code, |
| 858 | NavigationCodeType failed_code) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 859 | NotificationObserver* observer = |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 860 | new NavigationNotificationObserver<NavigationCodeType>( |
| 861 | tab, this, reply_message, success_code, auth_needed_code, |
| 862 | failed_code); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 863 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 864 | notification_observer_list_.AddObserver(observer); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 865 | return observer; |
| 866 | } |
| 867 | |
| 868 | void AutomationProvider::RemoveNavigationStatusListener( |
| 869 | NotificationObserver* obs) { |
| 870 | notification_observer_list_.RemoveObserver(obs); |
| 871 | } |
| 872 | |
| 873 | NotificationObserver* AutomationProvider::AddTabStripObserver( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 874 | Browser* parent, |
| 875 | IPC::Message* reply_message) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 876 | NotificationObserver* observer = |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 877 | new TabAppendedNotificationObserver(parent, this, reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 878 | notification_observer_list_.AddObserver(observer); |
| 879 | |
| 880 | return observer; |
| 881 | } |
| 882 | |
| 883 | void AutomationProvider::RemoveTabStripObserver(NotificationObserver* obs) { |
| 884 | notification_observer_list_.RemoveObserver(obs); |
| 885 | } |
| 886 | |
| 887 | void AutomationProvider::AddLoginHandler(NavigationController* tab, |
| 888 | LoginHandler* handler) { |
| 889 | login_handler_map_[tab] = handler; |
| 890 | } |
| 891 | |
| 892 | void AutomationProvider::RemoveLoginHandler(NavigationController* tab) { |
| 893 | DCHECK(login_handler_map_[tab]); |
| 894 | login_handler_map_.erase(tab); |
| 895 | } |
| 896 | |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 897 | void AutomationProvider::AddPortContainer(ExtensionPortContainer* port) { |
| 898 | int port_id = port->port_id(); |
| 899 | DCHECK_NE(-1, port_id); |
| 900 | DCHECK(port_containers_.find(port_id) == port_containers_.end()); |
| 901 | |
| 902 | port_containers_[port_id] = port; |
| 903 | } |
| 904 | |
| 905 | void AutomationProvider::RemovePortContainer(ExtensionPortContainer* port) { |
| 906 | int port_id = port->port_id(); |
| 907 | DCHECK_NE(-1, port_id); |
| 908 | |
| 909 | PortContainerMap::iterator it = port_containers_.find(port_id); |
| 910 | DCHECK(it != port_containers_.end()); |
| 911 | |
| 912 | if (it != port_containers_.end()) { |
| 913 | delete it->second; |
| 914 | port_containers_.erase(it); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | ExtensionPortContainer* AutomationProvider::GetPortContainer( |
| 919 | int port_id) const { |
| 920 | PortContainerMap::const_iterator it = port_containers_.find(port_id); |
| 921 | if (it == port_containers_.end()) |
| 922 | return NULL; |
| 923 | |
| 924 | return it->second; |
| 925 | } |
| 926 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 927 | int AutomationProvider::GetIndexForNavigationController( |
| 928 | const NavigationController* controller, const Browser* parent) const { |
| 929 | DCHECK(parent); |
[email protected] | 902cdf77 | 2009-05-06 15:08:12 | [diff] [blame] | 930 | return parent->GetIndexOfController(controller); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | void AutomationProvider::OnMessageReceived(const IPC::Message& message) { |
| 934 | IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 935 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 936 | IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync, |
| 937 | CloseBrowserAsync) |
| 938 | IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) |
| 939 | IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex) |
| 940 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) |
| 941 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab) |
| 942 | IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) |
| 943 | IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 944 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 945 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync) |
| 946 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack) |
| 947 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward) |
| 948 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload) |
| 949 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 950 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 951 | IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth) |
| 952 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom, |
| 953 | GetRedirectsFrom) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 954 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount) |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 955 | IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount, |
| 956 | GetNormalBrowserWindowCount) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 957 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow) |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 958 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBrowserLocale, GetBrowserLocale) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 959 | IPC_MESSAGE_HANDLER(AutomationMsg_LastActiveBrowserWindow, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 960 | GetLastActiveBrowserWindow) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 961 | IPC_MESSAGE_HANDLER(AutomationMsg_ActiveWindow, GetActiveWindow) |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 962 | IPC_MESSAGE_HANDLER(AutomationMsg_FindNormalBrowserWindow, |
| 963 | FindNormalBrowserWindow) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 964 | IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActive, IsWindowActive) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 965 | IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 966 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 967 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowHWND, GetWindowHWND) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 968 | #endif // defined(OS_WIN) |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 969 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 970 | ExecuteBrowserCommandAsync) |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 971 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 972 | ExecuteBrowserCommand) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 973 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) |
[email protected] | 8f04ff9 | 2009-07-08 02:37:15 | [diff] [blame] | 974 | IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 975 | IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 976 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 977 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 978 | #endif // defined(OS_WIN) |
| 979 | #if defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 980 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 981 | #endif |
| 982 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 983 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, |
| 984 | WindowSimulateDrag) |
[email protected] | d7fa755 | 2009-03-20 21:06:37 | [diff] [blame] | 985 | #endif // defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 986 | IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) |
| 987 | IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) |
[email protected] | d7fa755 | 2009-03-20 21:06:37 | [diff] [blame] | 988 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 989 | IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 990 | #endif // defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 991 | IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) |
| 992 | IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 993 | IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 994 | IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 995 | IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 996 | IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 997 | IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 998 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, |
| 999 | ExecuteJavascript) |
| 1000 | IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1001 | GetConstrainedWindowCount) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1002 | IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest) |
| 1003 | IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1004 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, |
| 1005 | HandleInspectElementRequest) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1006 | IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory) |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1007 | IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 1008 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1009 | OpenNewBrowserWindow) |
| 1010 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1011 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1012 | GetAutocompleteEditForBrowser) |
| 1013 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1014 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1015 | IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1016 | #endif |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1017 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1018 | NavigateInExternalTab) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1019 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1020 | ShowInterstitialPage) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1021 | IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1022 | HideInterstitialPage) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1023 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1024 | IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator, |
| 1025 | ProcessUnhandledAccelerator) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1026 | #endif |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1027 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, |
| 1028 | WaitForTabToBeRestored) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1029 | IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1030 | #if defined(OS_WIN) |
[email protected] | 87eab22 | 2009-03-13 00:47:45 | [diff] [blame] | 1031 | IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition) |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 1032 | IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome, |
| 1033 | OnForwardContextMenuCommandToChrome) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1034 | #endif |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1035 | IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState) |
| 1036 | IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1037 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage, |
| 1038 | ActionOnSSLBlockingPage) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1039 | IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront) |
| 1040 | IPC_MESSAGE_HANDLER(AutomationMsg_IsPageMenuCommandEnabled, |
| 1041 | IsPageMenuCommandEnabled) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1042 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow) |
[email protected] | d301c95 | 2009-07-13 15:02:41 | [diff] [blame] | 1043 | IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1044 | IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage) |
| 1045 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1046 | GetAutocompleteEditText) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1047 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1048 | SetAutocompleteEditText) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1049 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1050 | AutocompleteEditIsQueryInProgress) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1051 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1052 | AutocompleteEditGetMatches) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1053 | IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 1054 | HandleOpenFindInPageRequest) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1055 | IPC_MESSAGE_HANDLER(AutomationMsg_HandleMessageFromExternalHost, |
| 1056 | OnMessageFromExternalHost) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1057 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1058 | IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility, |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1059 | GetFindWindowVisibility) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1060 | IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation, |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1061 | HandleFindWindowLocationRequest) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1062 | IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility, |
| 1063 | GetBookmarkBarVisibility) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1064 | IPC_MESSAGE_HANDLER(AutomationMsg_GetSSLInfoBarCount, GetSSLInfoBarCount) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1065 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickSSLInfoBarLink, |
| 1066 | ClickSSLInfoBarLink) |
| 1067 | IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime, |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 1068 | GetLastNavigationTime) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1069 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation, |
| 1070 | WaitForNavigation) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1071 | IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference, SetIntPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1072 | IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog, |
[email protected] | c274acc | 2008-11-11 20:13:44 | [diff] [blame] | 1073 | GetShowingAppModalDialog) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1074 | IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton, |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 1075 | ClickAppModalDialogButton) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1076 | IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference, SetStringPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1077 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 1078 | GetBooleanPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1079 | IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 1080 | SetBooleanPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1081 | IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 1082 | GetPageCurrentEncoding) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1083 | IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 1084 | IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, |
| 1085 | SavePackageShouldPromptUser) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1086 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 1087 | IPC_MESSAGE_HANDLER(AutomationMsg_SetEnableExtensionAutomation, |
| 1088 | SetEnableExtensionAutomation) |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1089 | IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 1090 | IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 1091 | IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) |
| 1092 | IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) |
| 1093 | IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) |
| 1094 | IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) |
| 1095 | IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) |
| 1096 | IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1097 | IPC_END_MESSAGE_MAP() |
| 1098 | } |
| 1099 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1100 | void AutomationProvider::ActivateTab(int handle, int at_index, int* status) { |
| 1101 | *status = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1102 | if (browser_tracker_->ContainsHandle(handle) && at_index > -1) { |
| 1103 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1104 | if (at_index >= 0 && at_index < browser->tab_count()) { |
| 1105 | browser->SelectTabContentsAt(at_index, true); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1106 | *status = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1107 | } |
| 1108 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1109 | } |
| 1110 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1111 | void AutomationProvider::AppendTab(int handle, const GURL& url, |
| 1112 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1113 | int append_tab_response = -1; // -1 is the error code |
| 1114 | NotificationObserver* observer = NULL; |
| 1115 | |
| 1116 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1117 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1118 | observer = AddTabStripObserver(browser, reply_message); |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 1119 | TabContents* tab_contents = browser->AddTabWithURL(url, GURL(), |
| 1120 | PageTransition::TYPED, |
[email protected] | 5a4940be | 2009-05-06 06:44:39 | [diff] [blame] | 1121 | true, -1, false, NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1122 | if (tab_contents) { |
| 1123 | append_tab_response = |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1124 | GetIndexForNavigationController(&tab_contents->controller(), browser); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | if (append_tab_response < 0) { |
| 1129 | // The append tab failed. Remove the TabStripObserver |
| 1130 | if (observer) { |
| 1131 | RemoveTabStripObserver(observer); |
| 1132 | delete observer; |
| 1133 | } |
| 1134 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1135 | AutomationMsg_AppendTab::WriteReplyParams(reply_message, |
| 1136 | append_tab_response); |
| 1137 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1141 | void AutomationProvider::NavigateToURL(int handle, const GURL& url, |
| 1142 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1143 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1144 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1145 | |
| 1146 | // Simulate what a user would do. Activate the tab and then navigate. |
| 1147 | // We could allow navigating in a background tab in future. |
| 1148 | Browser* browser = FindAndActivateTab(tab); |
| 1149 | |
| 1150 | if (browser) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1151 | AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>( |
| 1152 | tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 1153 | AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, |
| 1154 | AUTOMATION_MSG_NAVIGATION_ERROR); |
| 1155 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1156 | // TODO(darin): avoid conversion to GURL |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1157 | browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1158 | return; |
| 1159 | } |
| 1160 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1161 | |
| 1162 | AutomationMsg_NavigateToURL::WriteReplyParams( |
| 1163 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 1164 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1165 | } |
| 1166 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1167 | void AutomationProvider::NavigationAsync(int handle, const GURL& url, |
| 1168 | bool* status) { |
| 1169 | *status = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1170 | |
| 1171 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1172 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1173 | |
| 1174 | // Simulate what a user would do. Activate the tab and then navigate. |
| 1175 | // We could allow navigating in a background tab in future. |
| 1176 | Browser* browser = FindAndActivateTab(tab); |
| 1177 | |
| 1178 | if (browser) { |
| 1179 | // Don't add any listener unless a callback mechanism is desired. |
| 1180 | // TODO(vibhor): Do this if such a requirement arises in future. |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1181 | browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1182 | *status = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1183 | } |
| 1184 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1185 | } |
| 1186 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1187 | void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1188 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1189 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1190 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 1191 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1192 | AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>( |
| 1193 | tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 1194 | AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, |
| 1195 | AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1196 | browser->GoBack(CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1197 | return; |
| 1198 | } |
| 1199 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1200 | |
| 1201 | AutomationMsg_GoBack::WriteReplyParams( |
| 1202 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 1203 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1204 | } |
| 1205 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1206 | void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1207 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1208 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1209 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 1210 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1211 | AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>( |
| 1212 | tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 1213 | AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, |
| 1214 | AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1215 | browser->GoForward(CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1216 | return; |
| 1217 | } |
| 1218 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1219 | |
| 1220 | AutomationMsg_GoForward::WriteReplyParams( |
| 1221 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 1222 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1223 | } |
| 1224 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1225 | void AutomationProvider::Reload(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1226 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1227 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1228 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 1229 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1230 | AddNavigationStatusListener<AutomationMsg_NavigationResponseValues>( |
| 1231 | tab, reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 1232 | AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, |
| 1233 | AUTOMATION_MSG_NAVIGATION_ERROR); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1234 | browser->Reload(); |
| 1235 | return; |
| 1236 | } |
| 1237 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1238 | |
| 1239 | AutomationMsg_Reload::WriteReplyParams( |
| 1240 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 1241 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1242 | } |
| 1243 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1244 | void AutomationProvider::SetAuth(int tab_handle, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1245 | const std::wstring& username, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1246 | const std::wstring& password, |
| 1247 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1248 | int status = -1; |
| 1249 | |
| 1250 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 1251 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 1252 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 1253 | |
| 1254 | if (iter != login_handler_map_.end()) { |
| 1255 | // If auth is needed again after this, assume login has failed. This is |
| 1256 | // not strictly correct, because a navigation can require both proxy and |
| 1257 | // server auth, but it should be OK for now. |
| 1258 | LoginHandler* handler = iter->second; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1259 | AddNavigationStatusListener<int>(tab, reply_message, 0, -1, -1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1260 | handler->SetAuth(username, password); |
| 1261 | status = 0; |
| 1262 | } |
| 1263 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1264 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1265 | if (status < 0) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1266 | AutomationMsg_SetAuth::WriteReplyParams(reply_message, status); |
| 1267 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1271 | void AutomationProvider::CancelAuth(int tab_handle, |
| 1272 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1273 | int status = -1; |
| 1274 | |
| 1275 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 1276 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 1277 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 1278 | |
| 1279 | if (iter != login_handler_map_.end()) { |
| 1280 | // If auth is needed again after this, something is screwy. |
| 1281 | LoginHandler* handler = iter->second; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1282 | AddNavigationStatusListener<int>(tab, reply_message, 0, -1, -1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1283 | handler->CancelAuth(); |
| 1284 | status = 0; |
| 1285 | } |
| 1286 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1287 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1288 | if (status < 0) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1289 | AutomationMsg_CancelAuth::WriteReplyParams(reply_message, status); |
| 1290 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1294 | void AutomationProvider::NeedsAuth(int tab_handle, bool* needs_auth) { |
| 1295 | *needs_auth = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1296 | |
| 1297 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 1298 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 1299 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 1300 | |
| 1301 | if (iter != login_handler_map_.end()) { |
| 1302 | // The LoginHandler will be in our map IFF the tab needs auth. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1303 | *needs_auth = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1304 | } |
| 1305 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1306 | } |
| 1307 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1308 | void AutomationProvider::GetRedirectsFrom(int tab_handle, |
| 1309 | const GURL& source_url, |
| 1310 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1311 | DCHECK(!redirect_query_) << "Can only handle one redirect query at once."; |
| 1312 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 1313 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 1314 | HistoryService* history_service = |
| 1315 | tab->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 1316 | |
| 1317 | DCHECK(history_service) << "Tab " << tab_handle << "'s profile " << |
| 1318 | "has no history service"; |
| 1319 | if (history_service) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1320 | DCHECK(reply_message_ == NULL); |
| 1321 | reply_message_ = reply_message; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1322 | // Schedule a history query for redirects. The response will be sent |
| 1323 | // asynchronously from the callback the history system uses to notify us |
| 1324 | // that it's done: OnRedirectQueryComplete. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1325 | redirect_query_ = history_service->QueryRedirectsFrom( |
| 1326 | source_url, &consumer_, |
| 1327 | NewCallback(this, &AutomationProvider::OnRedirectQueryComplete)); |
| 1328 | return; // Response will be sent when query completes. |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | // Send failure response. |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1333 | std::vector<GURL> empty; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1334 | AutomationMsg_RedirectsFrom::WriteReplyParams(reply_message, false, empty); |
| 1335 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1336 | } |
| 1337 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1338 | void AutomationProvider::GetActiveTabIndex(int handle, int* active_tab_index) { |
| 1339 | *active_tab_index = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1340 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1341 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1342 | *active_tab_index = browser->selected_index(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1343 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1344 | } |
| 1345 | |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 1346 | void AutomationProvider::GetBrowserLocale(string16* locale) { |
| 1347 | DCHECK(g_browser_process); |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 1348 | *locale = ASCIIToUTF16(g_browser_process->GetApplicationLocale()); |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 1349 | } |
| 1350 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1351 | void AutomationProvider::GetBrowserWindowCount(int* window_count) { |
| 1352 | *window_count = static_cast<int>(BrowserList::size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1353 | } |
| 1354 | |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 1355 | void AutomationProvider::GetNormalBrowserWindowCount(int* window_count) { |
| 1356 | *window_count = static_cast<int>( |
| 1357 | BrowserList::GetBrowserCountForType(profile_, Browser::TYPE_NORMAL)); |
| 1358 | } |
| 1359 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1360 | void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, |
| 1361 | int* dialog_button) { |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 1362 | AppModalDialog* dialog_delegate = |
| 1363 | Singleton<AppModalDialogQueue>()->active_dialog(); |
[email protected] | b3a7033 | 2009-02-25 02:40:50 | [diff] [blame] | 1364 | *showing_dialog = (dialog_delegate != NULL); |
| 1365 | if (*showing_dialog) |
| 1366 | *dialog_button = dialog_delegate->GetDialogButtons(); |
| 1367 | else |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 1368 | *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 1369 | } |
| 1370 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1371 | void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { |
| 1372 | *success = false; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 1373 | |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 1374 | AppModalDialog* dialog_delegate = |
| 1375 | Singleton<AppModalDialogQueue>()->active_dialog(); |
[email protected] | b3a7033 | 2009-02-25 02:40:50 | [diff] [blame] | 1376 | if (dialog_delegate && |
| 1377 | (dialog_delegate->GetDialogButtons() & button) == button) { |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 1378 | if ((button & MessageBoxFlags::DIALOGBUTTON_OK) == |
| 1379 | MessageBoxFlags::DIALOGBUTTON_OK) { |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 1380 | dialog_delegate->AcceptWindow(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1381 | *success = true; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 1382 | } |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 1383 | if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) == |
| 1384 | MessageBoxFlags::DIALOGBUTTON_CANCEL) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1385 | DCHECK(!*success) << "invalid param, OK and CANCEL specified"; |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 1386 | dialog_delegate->CancelWindow(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1387 | *success = true; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 1388 | } |
| 1389 | } |
[email protected] | c274acc | 2008-11-11 20:13:44 | [diff] [blame] | 1390 | } |
| 1391 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1392 | void AutomationProvider::GetBrowserWindow(int index, int* handle) { |
| 1393 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1394 | if (index >= 0) { |
| 1395 | BrowserList::const_iterator iter = BrowserList::begin(); |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 1396 | for (; (iter != BrowserList::end()) && (index > 0); ++iter, --index); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1397 | if (iter != BrowserList::end()) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1398 | *handle = browser_tracker_->Add(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1399 | } |
| 1400 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1401 | } |
| 1402 | |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 1403 | void AutomationProvider::FindNormalBrowserWindow(int* handle) { |
| 1404 | *handle = 0; |
| 1405 | Browser* browser = BrowserList::FindBrowserWithType(profile_, |
| 1406 | Browser::TYPE_NORMAL); |
| 1407 | if (browser) |
| 1408 | *handle = browser_tracker_->Add(browser); |
| 1409 | } |
| 1410 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1411 | void AutomationProvider::GetLastActiveBrowserWindow(int* handle) { |
| 1412 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1413 | Browser* browser = BrowserList::GetLastActive(); |
| 1414 | if (browser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1415 | *handle = browser_tracker_->Add(browser); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1416 | } |
| 1417 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1418 | #if defined(OS_WIN) |
| 1419 | // TODO(port): Remove windowsisms. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1420 | BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM l_param) { |
| 1421 | if (hwnd == reinterpret_cast<HWND>(l_param)) { |
| 1422 | return FALSE; |
| 1423 | } |
| 1424 | return TRUE; |
| 1425 | } |
| 1426 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1427 | void AutomationProvider::GetActiveWindow(int* handle) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1428 | HWND window = GetForegroundWindow(); |
| 1429 | |
| 1430 | // Let's make sure this window belongs to our process. |
| 1431 | if (EnumThreadWindows(::GetCurrentThreadId(), |
| 1432 | EnumThreadWndProc, |
| 1433 | reinterpret_cast<LPARAM>(window))) { |
| 1434 | // We enumerated all the windows and did not find the foreground window, |
| 1435 | // it is not our window, ignore it. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1436 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1437 | return; |
| 1438 | } |
| 1439 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1440 | *handle = window_tracker_->Add(window); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1441 | } |
| 1442 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1443 | void AutomationProvider::GetWindowHWND(int handle, HWND* win32_handle) { |
| 1444 | *win32_handle = window_tracker_->GetResource(handle); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1445 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1446 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1447 | |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 1448 | #if defined(OS_LINUX) |
| 1449 | // TODO(estade): use this implementation for all platforms? |
| 1450 | void AutomationProvider::GetActiveWindow(int* handle) { |
| 1451 | gfx::NativeWindow window = |
| 1452 | BrowserList::GetLastActive()->window()->GetNativeHandle(); |
| 1453 | *handle = window_tracker_->Add(window); |
| 1454 | } |
| 1455 | #endif |
| 1456 | |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 1457 | void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command, |
| 1458 | bool* success) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1459 | *success = false; |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 1460 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1461 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 1462 | if (browser->command_updater()->SupportsCommand(command) && |
| 1463 | browser->command_updater()->IsCommandEnabled(command)) { |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 1464 | browser->ExecuteCommand(command); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1465 | *success = true; |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 1466 | } |
| 1467 | } |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 1468 | } |
| 1469 | |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 1470 | void AutomationProvider::ExecuteBrowserCommand( |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 1471 | int handle, int command, IPC::Message* reply_message) { |
| 1472 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1473 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1474 | if (browser->command_updater()->SupportsCommand(command) && |
| 1475 | browser->command_updater()->IsCommandEnabled(command)) { |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 1476 | if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( |
| 1477 | this, browser, command, reply_message)) { |
[email protected] | 4e41709d | 2009-04-08 00:04:27 | [diff] [blame] | 1478 | browser->ExecuteCommand(command); |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 1479 | return; |
| 1480 | } |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 1481 | } |
| 1482 | } |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 1483 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 1484 | Send(reply_message); |
| 1485 | } |
| 1486 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1487 | void AutomationProvider::WindowGetViewBounds(int handle, int view_id, |
| 1488 | bool screen_coordinates, |
| 1489 | bool* success, |
| 1490 | gfx::Rect* bounds) { |
| 1491 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1492 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1493 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1494 | void* iter = NULL; |
| 1495 | if (window_tracker_->ContainsHandle(handle)) { |
| 1496 | HWND hwnd = window_tracker_->GetResource(handle); |
[email protected] | a0dde12 | 2008-11-21 20:51:20 | [diff] [blame] | 1497 | views::RootView* root_view = views::WidgetWin::FindRootView(hwnd); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1498 | if (root_view) { |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1499 | views::View* view = root_view->GetViewByID(view_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1500 | if (view) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1501 | *success = true; |
[email protected] | 96b667d | 2008-10-14 20:58:44 | [diff] [blame] | 1502 | gfx::Point point; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1503 | if (screen_coordinates) |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1504 | views::View::ConvertPointToScreen(view, &point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1505 | else |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1506 | views::View::ConvertPointToView(view, root_view, &point); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1507 | *bounds = view->GetLocalBounds(false); |
| 1508 | bounds->set_origin(point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1512 | #else |
| 1513 | // TODO(port): Enable when window_tracker is ported. |
| 1514 | NOTIMPLEMENTED(); |
| 1515 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1516 | } |
| 1517 | |
[email protected] | 1299c6e | 2009-07-25 00:27:18 | [diff] [blame] | 1518 | #if defined(OS_WIN) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1519 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1520 | // 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. |
| 1522 | class MouseEventTask : public Task { |
| 1523 | public: |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1524 | MouseEventTask(views::View* view, |
| 1525 | views::Event::EventType type, |
[email protected] | 0e80dfe | 2009-08-07 01:22:58 | [diff] [blame] | 1526 | const gfx::Point& point, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1527 | int flags) |
| 1528 | : view_(view), type_(type), point_(point), flags_(flags) {} |
| 1529 | virtual ~MouseEventTask() {} |
| 1530 | |
| 1531 | virtual void Run() { |
[email protected] | 0e80dfe | 2009-08-07 01:22:58 | [diff] [blame] | 1532 | views::MouseEvent event(type_, point_.x(), point_.y(), flags_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1533 | // We need to set the cursor position before we process the event because |
| 1534 | // some code (tab dragging, for instance) queries the actual cursor location |
| 1535 | // rather than the location of the mouse event. Note that the reason why |
| 1536 | // the drag code moved away from using mouse event locations was because |
| 1537 | // our conversion to screen location doesn't work well with multiple |
| 1538 | // monitors, so this only works reliably in a single monitor setup. |
[email protected] | 0e80dfe | 2009-08-07 01:22:58 | [diff] [blame] | 1539 | gfx::Point screen_location(point_.x(), point_.y()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1540 | view_->ConvertPointToScreen(view_, &screen_location); |
[email protected] | f544609 | 2009-07-30 21:10:01 | [diff] [blame] | 1541 | MoveMouse(screen_location.ToPOINT()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1542 | switch (type_) { |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1543 | case views::Event::ET_MOUSE_PRESSED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1544 | view_->OnMousePressed(event); |
| 1545 | break; |
| 1546 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1547 | case views::Event::ET_MOUSE_DRAGGED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1548 | view_->OnMouseDragged(event); |
| 1549 | break; |
| 1550 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1551 | case views::Event::ET_MOUSE_RELEASED: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1552 | view_->OnMouseReleased(event, false); |
| 1553 | break; |
| 1554 | |
| 1555 | default: |
| 1556 | NOTREACHED(); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | private: |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1561 | views::View* view_; |
| 1562 | views::Event::EventType type_; |
[email protected] | 0e80dfe | 2009-08-07 01:22:58 | [diff] [blame] | 1563 | gfx::Point point_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1564 | int flags_; |
| 1565 | |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 1566 | DISALLOW_COPY_AND_ASSIGN(MouseEventTask); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1567 | }; |
| 1568 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1569 | void AutomationProvider::ScheduleMouseEvent(views::View* view, |
| 1570 | views::Event::EventType type, |
[email protected] | 0e80dfe | 2009-08-07 01:22:58 | [diff] [blame] | 1571 | const gfx::Point& point, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1572 | int flags) { |
| 1573 | MessageLoop::current()->PostTask(FROM_HERE, |
| 1574 | new MouseEventTask(view, type, point, flags)); |
| 1575 | } |
[email protected] | 0e80dfe | 2009-08-07 01:22:58 | [diff] [blame] | 1576 | |
[email protected] | 1299c6e | 2009-07-25 00:27:18 | [diff] [blame] | 1577 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1578 | |
| 1579 | // This task just adds another task to the event queue. This is useful if |
| 1580 | // you want to ensure that any tasks added to the event queue after this one |
| 1581 | // have already been processed by the time |task| is run. |
| 1582 | class InvokeTaskLaterTask : public Task { |
| 1583 | public: |
| 1584 | explicit InvokeTaskLaterTask(Task* task) : task_(task) {} |
| 1585 | virtual ~InvokeTaskLaterTask() {} |
| 1586 | |
| 1587 | virtual void Run() { |
| 1588 | MessageLoop::current()->PostTask(FROM_HERE, task_); |
| 1589 | } |
| 1590 | |
| 1591 | private: |
| 1592 | Task* task_; |
| 1593 | |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 1594 | DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1595 | }; |
| 1596 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1597 | #if defined(OS_WIN) |
| 1598 | // TODO(port): Replace POINT and other windowsisms. |
| 1599 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1600 | // This task sends a WindowDragResponse message with the appropriate |
| 1601 | // routing ID to the automation proxy. This is implemented as a task so that |
| 1602 | // we know that the mouse events (and any tasks that they spawn on the message |
| 1603 | // loop) have been processed by the time this is sent. |
| 1604 | class WindowDragResponseTask : public Task { |
| 1605 | public: |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1606 | WindowDragResponseTask(AutomationProvider* provider, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1607 | IPC::Message* reply_message) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1608 | : provider_(provider), reply_message_(reply_message) {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1609 | virtual ~WindowDragResponseTask() {} |
| 1610 | |
| 1611 | virtual void Run() { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1612 | DCHECK(reply_message_ != NULL); |
| 1613 | AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true); |
| 1614 | provider_->Send(reply_message_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | private: |
| 1618 | AutomationProvider* provider_; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1619 | IPC::Message* reply_message_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1620 | |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 1621 | DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1622 | }; |
| 1623 | |
| 1624 | void AutomationProvider::WindowSimulateClick(const IPC::Message& message, |
| 1625 | int handle, |
| 1626 | POINT click, |
| 1627 | int flags) { |
| 1628 | HWND hwnd = 0; |
| 1629 | |
| 1630 | if (window_tracker_->ContainsHandle(handle)) { |
| 1631 | hwnd = window_tracker_->GetResource(handle); |
| 1632 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1633 | ui_controls::SendMouseMove(click.x, click.y); |
| 1634 | |
| 1635 | ui_controls::MouseButton button = ui_controls::LEFT; |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1636 | if ((flags & views::Event::EF_LEFT_BUTTON_DOWN) == |
| 1637 | views::Event::EF_LEFT_BUTTON_DOWN) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1638 | button = ui_controls::LEFT; |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1639 | } else if ((flags & views::Event::EF_RIGHT_BUTTON_DOWN) == |
| 1640 | views::Event::EF_RIGHT_BUTTON_DOWN) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1641 | button = ui_controls::RIGHT; |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1642 | } else if ((flags & views::Event::EF_MIDDLE_BUTTON_DOWN) == |
| 1643 | views::Event::EF_MIDDLE_BUTTON_DOWN) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1644 | button = ui_controls::MIDDLE; |
| 1645 | } else { |
| 1646 | NOTREACHED(); |
| 1647 | } |
| 1648 | ui_controls::SendMouseClick(button); |
| 1649 | } |
| 1650 | } |
| 1651 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1652 | void AutomationProvider::WindowSimulateDrag(int handle, |
[email protected] | fe92e4e | 2008-11-18 21:31:32 | [diff] [blame] | 1653 | std::vector<POINT> drag_path, |
[email protected] | 5e0f30c | 2008-08-14 22:52:44 | [diff] [blame] | 1654 | int flags, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1655 | bool press_escape_en_route, |
| 1656 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1657 | bool succeeded = false; |
[email protected] | fe92e4e | 2008-11-18 21:31:32 | [diff] [blame] | 1658 | if (browser_tracker_->ContainsHandle(handle) && (drag_path.size() > 1)) { |
| 1659 | succeeded = true; |
| 1660 | |
| 1661 | UINT down_message = 0; |
| 1662 | UINT up_message = 0; |
| 1663 | WPARAM wparam_flags = 0; |
| 1664 | if (flags & views::Event::EF_SHIFT_DOWN) |
| 1665 | wparam_flags |= MK_SHIFT; |
| 1666 | if (flags & views::Event::EF_CONTROL_DOWN) |
| 1667 | wparam_flags |= MK_CONTROL; |
| 1668 | if (flags & views::Event::EF_LEFT_BUTTON_DOWN) { |
| 1669 | wparam_flags |= MK_LBUTTON; |
| 1670 | down_message = WM_LBUTTONDOWN; |
| 1671 | up_message = WM_LBUTTONUP; |
| 1672 | } |
| 1673 | if (flags & views::Event::EF_MIDDLE_BUTTON_DOWN) { |
| 1674 | wparam_flags |= MK_MBUTTON; |
| 1675 | down_message = WM_MBUTTONDOWN; |
| 1676 | up_message = WM_MBUTTONUP; |
| 1677 | } |
| 1678 | if (flags & views::Event::EF_RIGHT_BUTTON_DOWN) { |
| 1679 | wparam_flags |= MK_RBUTTON; |
| 1680 | down_message = WM_LBUTTONDOWN; |
| 1681 | up_message = WM_LBUTTONUP; |
| 1682 | } |
| 1683 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1684 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1685 | DCHECK(browser); |
[email protected] | 0a6fb3f | 2008-11-18 21:39:55 | [diff] [blame] | 1686 | HWND top_level_hwnd = |
| 1687 | reinterpret_cast<HWND>(browser->window()->GetNativeHandle()); |
[email protected] | fe92e4e | 2008-11-18 21:31:32 | [diff] [blame] | 1688 | POINT temp = drag_path[0]; |
| 1689 | MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1); |
[email protected] | f544609 | 2009-07-30 21:10:01 | [diff] [blame] | 1690 | MoveMouse(temp); |
[email protected] | fe92e4e | 2008-11-18 21:31:32 | [diff] [blame] | 1691 | SendMessage(top_level_hwnd, down_message, wparam_flags, |
| 1692 | MAKELPARAM(drag_path[0].x, drag_path[0].y)); |
| 1693 | for (int i = 1; i < static_cast<int>(drag_path.size()); ++i) { |
| 1694 | temp = drag_path[i]; |
| 1695 | MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &temp, 1); |
[email protected] | f544609 | 2009-07-30 21:10:01 | [diff] [blame] | 1696 | MoveMouse(temp); |
[email protected] | fe92e4e | 2008-11-18 21:31:32 | [diff] [blame] | 1697 | SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags, |
| 1698 | MAKELPARAM(drag_path[i].x, drag_path[i].y)); |
[email protected] | f7a391a1 | 2008-11-10 21:29:34 | [diff] [blame] | 1699 | } |
[email protected] | fe92e4e | 2008-11-18 21:31:32 | [diff] [blame] | 1700 | POINT end = drag_path[drag_path.size() - 1]; |
| 1701 | MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1); |
[email protected] | f544609 | 2009-07-30 21:10:01 | [diff] [blame] | 1702 | MoveMouse(end); |
[email protected] | fe92e4e | 2008-11-18 21:31:32 | [diff] [blame] | 1703 | |
| 1704 | if (press_escape_en_route) { |
| 1705 | // Press Escape. |
| 1706 | ui_controls::SendKeyPress(VK_ESCAPE, |
| 1707 | ((flags & views::Event::EF_CONTROL_DOWN) |
| 1708 | == views::Event::EF_CONTROL_DOWN), |
| 1709 | ((flags & views::Event::EF_SHIFT_DOWN) == |
| 1710 | views::Event::EF_SHIFT_DOWN), |
| 1711 | ((flags & views::Event::EF_ALT_DOWN) == |
| 1712 | views::Event::EF_ALT_DOWN)); |
| 1713 | } |
| 1714 | SendMessage(top_level_hwnd, up_message, wparam_flags, |
| 1715 | MAKELPARAM(end.x, end.y)); |
| 1716 | |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1717 | MessageLoop::current()->PostTask(FROM_HERE, new InvokeTaskLaterTask( |
| 1718 | new WindowDragResponseTask(this, reply_message))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1719 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1720 | AutomationMsg_WindowDrag::WriteReplyParams(reply_message, true); |
| 1721 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1722 | } |
| 1723 | } |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 1724 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1725 | |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 1726 | #if defined(OS_WIN) || defined(OS_LINUX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1727 | void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message, |
| 1728 | int handle, |
| 1729 | wchar_t key, |
| 1730 | int flags) { |
| 1731 | if (!window_tracker_->ContainsHandle(handle)) |
| 1732 | return; |
| 1733 | |
| 1734 | // The key event is sent to whatever window is active. |
| 1735 | ui_controls::SendKeyPress(key, |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1736 | ((flags & views::Event::EF_CONTROL_DOWN) == |
| 1737 | views::Event::EF_CONTROL_DOWN), |
| 1738 | ((flags & views::Event::EF_SHIFT_DOWN) == |
| 1739 | views::Event::EF_SHIFT_DOWN), |
| 1740 | ((flags & views::Event::EF_ALT_DOWN) == |
| 1741 | views::Event::EF_ALT_DOWN)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1742 | } |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 1743 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1744 | |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame^] | 1745 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1746 | void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { |
| 1747 | *view_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1748 | if (window_tracker_->ContainsHandle(handle)) { |
| 1749 | HWND hwnd = window_tracker_->GetResource(handle); |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1750 | views::FocusManager* focus_manager = |
[email protected] | 82166b6 | 2009-06-30 18:48:00 | [diff] [blame] | 1751 | views::FocusManager::GetFocusManagerForNativeView(hwnd); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1752 | DCHECK(focus_manager); |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1753 | views::View* focused_view = focus_manager->GetFocusedView(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1754 | if (focused_view) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1755 | *view_id = focused_view->GetID(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1756 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1757 | } |
| 1758 | |
[email protected] | 8f04ff9 | 2009-07-08 02:37:15 | [diff] [blame] | 1759 | void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, |
| 1760 | bool* success) { |
| 1761 | *success = false; |
| 1762 | if (window_tracker_->ContainsHandle(handle)) { |
| 1763 | HWND hwnd = window_tracker_->GetResource(handle); |
| 1764 | if (::MoveWindow(hwnd, bounds.x(), bounds.y(), bounds.width(), |
| 1765 | bounds.height(), true)) { |
| 1766 | *success = true; |
| 1767 | } |
| 1768 | } |
| 1769 | } |
| 1770 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1771 | void AutomationProvider::SetWindowVisible(int handle, bool visible, |
| 1772 | bool* result) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1773 | if (window_tracker_->ContainsHandle(handle)) { |
| 1774 | HWND hwnd = window_tracker_->GetResource(handle); |
| 1775 | ::ShowWindow(hwnd, visible ? SW_SHOW : SW_HIDE); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1776 | *result = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1777 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1778 | *result = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1779 | } |
| 1780 | } |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1781 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1782 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1783 | void AutomationProvider::IsWindowActive(int handle, bool* success, |
| 1784 | bool* is_active) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1785 | if (window_tracker_->ContainsHandle(handle)) { |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1786 | *is_active = |
| 1787 | platform_util::IsWindowActive(window_tracker_->GetResource(handle)); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1788 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1789 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1790 | *success = false; |
| 1791 | *is_active = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1795 | // TODO(port): port this. |
| 1796 | #if defined(OS_WIN) |
[email protected] | 659d0e8 | 2009-02-13 22:43:28 | [diff] [blame] | 1797 | void AutomationProvider::ActivateWindow(int handle) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1798 | if (window_tracker_->ContainsHandle(handle)) { |
| 1799 | ::SetActiveWindow(window_tracker_->GetResource(handle)); |
| 1800 | } |
| 1801 | } |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1802 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1803 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1804 | void AutomationProvider::GetTabCount(int handle, int* tab_count) { |
| 1805 | *tab_count = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1806 | |
| 1807 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1808 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1809 | *tab_count = browser->tab_count(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1810 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1811 | } |
| 1812 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1813 | void AutomationProvider::GetTab(int win_handle, int tab_index, |
| 1814 | int* tab_handle) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1815 | *tab_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1816 | if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) { |
| 1817 | Browser* browser = browser_tracker_->GetResource(win_handle); |
| 1818 | if (tab_index < browser->tab_count()) { |
| 1819 | TabContents* tab_contents = |
| 1820 | browser->GetTabContentsAt(tab_index); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1821 | *tab_handle = tab_tracker_->Add(&tab_contents->controller()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1822 | } |
| 1823 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1824 | } |
| 1825 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1826 | void AutomationProvider::GetTabTitle(int handle, int* title_string_size, |
| 1827 | std::wstring* title) { |
| 1828 | *title_string_size = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1829 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1830 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | c100dbd | 2009-04-29 23:44:36 | [diff] [blame] | 1831 | NavigationEntry* entry = tab->GetActiveEntry(); |
| 1832 | if (entry != NULL) { |
| 1833 | *title = UTF16ToWideHack(entry->title()); |
| 1834 | } else { |
| 1835 | *title = std::wstring(); |
| 1836 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1837 | *title_string_size = static_cast<int>(title->size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1838 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1839 | } |
| 1840 | |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1841 | void AutomationProvider::GetTabIndex(int handle, int* tabstrip_index) { |
| 1842 | *tabstrip_index = -1; // -1 is the error code |
| 1843 | |
| 1844 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1845 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1846 | Browser* browser = Browser::GetBrowserForController(tab, NULL); |
[email protected] | 902cdf77 | 2009-05-06 15:08:12 | [diff] [blame] | 1847 | *tabstrip_index = browser->tabstrip_model()->GetIndexOfController(tab); |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1848 | } |
| 1849 | } |
| 1850 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1851 | void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) { |
| 1852 | if (window_tracker_->ContainsHandle(handle)) { |
| 1853 | window_tracker_->Remove(window_tracker_->GetResource(handle)); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | void AutomationProvider::OnChannelError() { |
| 1858 | LOG(ERROR) << "AutomationProxy went away, shutting down app."; |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 1859 | AutomationProviderList::GetInstance()->RemoveProvider(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | // TODO(brettw) change this to accept GURLs when history supports it |
| 1863 | void AutomationProvider::OnRedirectQueryComplete( |
| 1864 | HistoryService::Handle request_handle, |
[email protected] | 3e377c5 | 2009-08-06 07:46:37 | [diff] [blame] | 1865 | GURL from_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1866 | bool success, |
[email protected] | 379c2b1 | 2009-07-01 21:50:33 | [diff] [blame] | 1867 | history::RedirectList* redirects) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1868 | DCHECK(request_handle == redirect_query_); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1869 | DCHECK(reply_message_ != NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1870 | |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1871 | std::vector<GURL> redirects_gurl; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1872 | if (success) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1873 | reply_message_->WriteBool(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1874 | for (size_t i = 0; i < redirects->size(); i++) |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1875 | redirects_gurl.push_back(redirects->at(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1876 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1877 | reply_message_->WriteInt(-1); // Negative count indicates failure. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1878 | } |
| 1879 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1880 | IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1881 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1882 | Send(reply_message_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1883 | redirect_query_ = NULL; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1884 | reply_message_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | bool AutomationProvider::Send(IPC::Message* msg) { |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 1888 | DCHECK(channel_.get()); |
| 1889 | return channel_->Send(msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | Browser* AutomationProvider::FindAndActivateTab( |
| 1893 | NavigationController* controller) { |
| 1894 | int tab_index; |
| 1895 | Browser* browser = Browser::GetBrowserForController(controller, &tab_index); |
| 1896 | if (browser) |
| 1897 | browser->SelectTabContentsAt(tab_index, true); |
| 1898 | |
| 1899 | return browser; |
| 1900 | } |
| 1901 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1902 | void AutomationProvider::GetCookies(const GURL& url, int handle, |
| 1903 | int* value_size, |
| 1904 | std::string* value) { |
| 1905 | *value_size = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1906 | if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 1907 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1908 | *value = |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1909 | tab->profile()->GetRequestContext()->cookie_store()->GetCookies(url); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1910 | *value_size = static_cast<int>(value->size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1911 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1912 | } |
| 1913 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1914 | void AutomationProvider::SetCookie(const GURL& url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1915 | const std::string value, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1916 | int handle, |
| 1917 | int* response_value) { |
| 1918 | *response_value = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1919 | |
| 1920 | if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 1921 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1922 | URLRequestContext* context = tab->profile()->GetRequestContext(); |
| 1923 | if (context->cookie_store()->SetCookie(url, value)) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1924 | *response_value = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1925 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1926 | } |
| 1927 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1928 | void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { |
| 1929 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1930 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1931 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1932 | // Return what the user would see in the location bar. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1933 | *url = tab->GetActiveEntry()->display_url(); |
| 1934 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1935 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1936 | } |
| 1937 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1938 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1939 | void AutomationProvider::GetTabHWND(int handle, HWND* tab_hwnd) { |
| 1940 | *tab_hwnd = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1941 | |
| 1942 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1943 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 1944 | *tab_hwnd = tab->tab_contents()->GetNativeView(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1945 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1946 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1947 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1948 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1949 | void AutomationProvider::GetTabProcessID(int handle, int* process_id) { |
| 1950 | *process_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1951 | |
| 1952 | if (tab_tracker_->ContainsHandle(handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1953 | *process_id = 0; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1954 | TabContents* tab_contents = |
| 1955 | tab_tracker_->GetResource(handle)->tab_contents(); |
| 1956 | if (tab_contents->process()) |
| 1957 | *process_id = tab_contents->process()->process().pid(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1958 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | void AutomationProvider::ApplyAccelerator(int handle, int id) { |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 1962 | NOTREACHED() << "This function has been deprecated. " |
| 1963 | << "Please use ExecuteBrowserCommandAsync instead."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1964 | } |
| 1965 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1966 | void AutomationProvider::ExecuteJavascript(int handle, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1967 | const std::wstring& frame_xpath, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1968 | const std::wstring& script, |
| 1969 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1970 | bool succeeded = false; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1971 | TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
| 1972 | if (tab_contents) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1973 | // Set the routing id of this message with the controller. |
| 1974 | // This routing id needs to be remembered for the reverse |
| 1975 | // communication while sending back the response of |
| 1976 | // this javascript execution. |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 1977 | std::wstring set_automation_id; |
| 1978 | SStringPrintf(&set_automation_id, |
| 1979 | L"window.domAutomationController.setAutomationId(%d);", |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1980 | reply_message->routing_id()); |
| 1981 | |
| 1982 | DCHECK(reply_message_ == NULL); |
| 1983 | reply_message_ = reply_message; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1984 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1985 | tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 1986 | frame_xpath, set_automation_id); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1987 | tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
[email protected] | 1f5af444 | 2008-09-25 22:11:06 | [diff] [blame] | 1988 | frame_xpath, script); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1989 | succeeded = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | if (!succeeded) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1993 | AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); |
| 1994 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1995 | } |
| 1996 | } |
| 1997 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1998 | void AutomationProvider::GetShelfVisibility(int handle, bool* visible) { |
| 1999 | *visible = false; |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2000 | |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 2001 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2002 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2003 | if (browser) { |
| 2004 | *visible = browser->window()->IsDownloadShelfVisible(); |
| 2005 | } |
| 2006 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2007 | } |
| 2008 | |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 2009 | void AutomationProvider::SetShelfVisibility(int handle, bool visible) { |
| 2010 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2011 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2012 | if (browser) { |
| 2013 | if (visible) |
| 2014 | browser->window()->GetDownloadShelf()->Show(); |
| 2015 | else |
| 2016 | browser->window()->GetDownloadShelf()->Close(); |
| 2017 | } |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2022 | void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) { |
| 2023 | *count = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2024 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2025 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2026 | TabContents* tab_contents = nav_controller->tab_contents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2027 | if (tab_contents) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2028 | *count = static_cast<int>(tab_contents->child_windows_.size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2029 | } |
| 2030 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2031 | } |
| 2032 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2033 | void AutomationProvider::HandleFindInPageRequest( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2034 | int handle, const std::wstring& find_request, |
| 2035 | int forward, int match_case, int* active_ordinal, int* matches_found) { |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 2036 | NOTREACHED() << "This function has been deprecated." |
| 2037 | << "Please use HandleFindRequest instead."; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2038 | *matches_found = -1; |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 2039 | return; |
| 2040 | } |
| 2041 | |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 2042 | void AutomationProvider::HandleFindRequest( |
| 2043 | int handle, |
| 2044 | const AutomationMsg_Find_Params& params, |
| 2045 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2046 | if (!tab_tracker_->ContainsHandle(handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2047 | AutomationMsg_FindInPage::WriteReplyParams(reply_message, -1, -1); |
| 2048 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2049 | return; |
| 2050 | } |
| 2051 | |
| 2052 | NavigationController* nav = tab_tracker_->GetResource(handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2053 | TabContents* tab_contents = nav->tab_contents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2054 | |
| 2055 | find_in_page_observer_.reset(new |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2056 | FindInPageNotificationObserver(this, tab_contents, reply_message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2057 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2058 | tab_contents->set_current_find_request_id( |
| 2059 | FindInPageNotificationObserver::kFindInPageRequestId); |
| 2060 | tab_contents->render_view_host()->StartFinding( |
| 2061 | FindInPageNotificationObserver::kFindInPageRequestId, |
| 2062 | params.search_string, params.forward, params.match_case, |
| 2063 | params.find_next); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2064 | } |
| 2065 | |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 2066 | void AutomationProvider::HandleOpenFindInPageRequest( |
| 2067 | const IPC::Message& message, int handle) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2068 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2069 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2070 | browser->FindInPage(false, false); |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 2071 | } |
| 2072 | } |
| 2073 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2074 | void AutomationProvider::GetFindWindowVisibility(int handle, bool* visible) { |
[email protected] | 9e0534b | 2008-10-21 15:03:01 | [diff] [blame] | 2075 | gfx::Point position; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2076 | *visible = false; |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2077 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2078 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 2079 | FindBarTesting* find_bar = |
| 2080 | browser->find_bar()->find_bar()->GetFindBarTesting(); |
| 2081 | find_bar->GetFindBarWindowInfo(&position, visible); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2082 | } |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2083 | } |
| 2084 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2085 | void AutomationProvider::HandleFindWindowLocationRequest(int handle, int* x, |
| 2086 | int* y) { |
[email protected] | 9e0534b | 2008-10-21 15:03:01 | [diff] [blame] | 2087 | gfx::Point position(0, 0); |
| 2088 | bool visible = false; |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2089 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2090 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 2091 | FindBarTesting* find_bar = |
| 2092 | browser->find_bar()->find_bar()->GetFindBarTesting(); |
| 2093 | find_bar->GetFindBarWindowInfo(&position, &visible); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2094 | } |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2095 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2096 | *x = position.x(); |
| 2097 | *y = position.y(); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2098 | } |
| 2099 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2100 | void AutomationProvider::GetBookmarkBarVisibility(int handle, bool* visible, |
| 2101 | bool* animating) { |
| 2102 | *visible = false; |
| 2103 | *animating = false; |
[email protected] | c2cbeb9 | 2008-09-05 21:36:57 | [diff] [blame] | 2104 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2105 | #if defined(OS_WIN) |
[email protected] | c2cbeb9 | 2008-09-05 21:36:57 | [diff] [blame] | 2106 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2107 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2108 | if (browser) { |
[email protected] | 0ba1f530 | 2009-01-22 01:34:52 | [diff] [blame] | 2109 | BrowserWindowTesting* testing = |
| 2110 | browser->window()->GetBrowserWindowTesting(); |
| 2111 | BookmarkBarView* bookmark_bar = testing->GetBookmarkBarView(); |
[email protected] | c2cbeb9 | 2008-09-05 21:36:57 | [diff] [blame] | 2112 | if (bookmark_bar) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2113 | *animating = bookmark_bar->IsAnimating(); |
| 2114 | *visible = browser->window()->IsBookmarkBarVisible(); |
[email protected] | c2cbeb9 | 2008-09-05 21:36:57 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2118 | #else |
| 2119 | // TODO(port): Enable when bookmarks ui is ported. |
| 2120 | NOTIMPLEMENTED(); |
| 2121 | #endif |
[email protected] | c2cbeb9 | 2008-09-05 21:36:57 | [diff] [blame] | 2122 | } |
| 2123 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2124 | void AutomationProvider::HandleInspectElementRequest( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2125 | int handle, int x, int y, IPC::Message* reply_message) { |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2126 | TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
| 2127 | if (tab_contents) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2128 | DCHECK(reply_message_ == NULL); |
| 2129 | reply_message_ = reply_message; |
| 2130 | |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 2131 | DevToolsManager::GetInstance()->InspectElement( |
| 2132 | tab_contents->render_view_host(), x, y); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2133 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2134 | AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); |
| 2135 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | void AutomationProvider::ReceivedInspectElementResponse(int num_resources) { |
[email protected] | 396c3b3 | 2009-03-12 22:26:09 | [diff] [blame] | 2140 | if (reply_message_) { |
| 2141 | AutomationMsg_InspectElement::WriteReplyParams(reply_message_, |
| 2142 | num_resources); |
| 2143 | Send(reply_message_); |
| 2144 | reply_message_ = NULL; |
| 2145 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2146 | } |
| 2147 | |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2148 | class SetProxyConfigTask : public Task { |
| 2149 | public: |
| 2150 | explicit SetProxyConfigTask(net::ProxyService* proxy_service, |
| 2151 | const std::string& new_proxy_config) |
| 2152 | : proxy_service_(proxy_service), proxy_config_(new_proxy_config) {} |
| 2153 | virtual void Run() { |
| 2154 | // First, deserialize the JSON string. If this fails, log and bail. |
| 2155 | JSONStringValueSerializer deserializer(proxy_config_); |
| 2156 | std::string error_message; |
| 2157 | scoped_ptr<Value> root(deserializer.Deserialize(&error_message)); |
| 2158 | if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { |
| 2159 | DLOG(WARNING) << "Received bad JSON string for ProxyConfig: " |
| 2160 | << error_message; |
| 2161 | return; |
| 2162 | } |
| 2163 | |
| 2164 | scoped_ptr<DictionaryValue> dict( |
| 2165 | static_cast<DictionaryValue*>(root.release())); |
| 2166 | // Now put together a proxy configuration from the deserialized string. |
| 2167 | net::ProxyConfig pc; |
| 2168 | PopulateProxyConfig(*dict.get(), &pc); |
| 2169 | |
| 2170 | DCHECK(proxy_service_); |
| 2171 | scoped_ptr<net::ProxyConfigService> proxy_config_service( |
| 2172 | new net::ProxyConfigServiceFixed(pc)); |
| 2173 | proxy_service_->ResetConfigService(proxy_config_service.release()); |
| 2174 | } |
| 2175 | |
| 2176 | void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { |
| 2177 | DCHECK(pc); |
| 2178 | bool no_proxy = false; |
| 2179 | if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { |
| 2180 | // Make no changes to the ProxyConfig. |
| 2181 | return; |
| 2182 | } |
| 2183 | bool auto_config; |
| 2184 | if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) { |
| 2185 | pc->auto_detect = true; |
| 2186 | } |
| 2187 | std::string pac_url; |
| 2188 | if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) { |
| 2189 | pc->pac_url = GURL(pac_url); |
| 2190 | } |
| 2191 | std::string proxy_bypass_list; |
| 2192 | if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) { |
| 2193 | pc->ParseNoProxyList(proxy_bypass_list); |
| 2194 | } |
| 2195 | std::string proxy_server; |
| 2196 | if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) { |
| 2197 | pc->proxy_rules.ParseFromString(proxy_server); |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | private: |
| 2202 | net::ProxyService* proxy_service_; |
| 2203 | std::string proxy_config_; |
| 2204 | }; |
| 2205 | |
| 2206 | |
| 2207 | void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { |
| 2208 | URLRequestContext* context = Profile::GetDefaultRequestContext(); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2209 | if (!context) { |
| 2210 | FilePath user_data_dir; |
| 2211 | PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 2212 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 2213 | DCHECK(profile_manager); |
| 2214 | Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); |
| 2215 | DCHECK(profile); |
| 2216 | context = profile->GetRequestContext(); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2217 | } |
| 2218 | DCHECK(context); |
| 2219 | // Every URLRequestContext should have a proxy service. |
| 2220 | net::ProxyService* proxy_service = context->proxy_service(); |
| 2221 | DCHECK(proxy_service); |
| 2222 | |
[email protected] | 81ae0a9 | 2009-08-06 02:16:16 | [diff] [blame] | 2223 | g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, |
| 2224 | new SetProxyConfigTask(proxy_service, new_proxy_config)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2225 | } |
| 2226 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2227 | void AutomationProvider::GetDownloadDirectory( |
| 2228 | int handle, std::wstring* download_directory) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2229 | DLOG(INFO) << "Handling download directory request"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2230 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2231 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2232 | DownloadManager* dlm = tab->profile()->GetDownloadManager(); |
| 2233 | DCHECK(dlm); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2234 | *download_directory = dlm->download_path().ToWStringHack(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2235 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2236 | } |
| 2237 | |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 2238 | void AutomationProvider::OpenNewBrowserWindow(bool show, |
| 2239 | IPC::Message* reply_message) { |
| 2240 | new BrowserOpenedNotificationObserver(this, reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2241 | // We may have no current browser windows open so don't rely on |
| 2242 | // asking an existing browser to execute the IDC_NEWWINDOW command |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 2243 | Browser* browser = Browser::Create(profile_); |
| 2244 | browser->AddBlankTab(true); |
[email protected] | 3683cbb | 2009-04-09 21:46:15 | [diff] [blame] | 2245 | if (show) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 2246 | browser->window()->Show(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2247 | } |
| 2248 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2249 | void AutomationProvider::GetWindowForBrowser(int browser_handle, |
| 2250 | bool* success, |
| 2251 | int* handle) { |
| 2252 | *success = false; |
| 2253 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2254 | |
| 2255 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2256 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 2257 | gfx::NativeWindow win = browser->window()->GetNativeHandle(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2258 | // Add() returns the existing handle for the resource if any. |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 2259 | *handle = window_tracker_->Add(win); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2260 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2261 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2262 | } |
| 2263 | |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2264 | #if defined(OS_WIN) || defined(OS_LINUX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2265 | void AutomationProvider::GetAutocompleteEditForBrowser( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2266 | int browser_handle, |
| 2267 | bool* success, |
| 2268 | int* autocomplete_edit_handle) { |
| 2269 | *success = false; |
| 2270 | *autocomplete_edit_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2271 | |
| 2272 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2273 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2274 | LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 2275 | AutocompleteEditView* edit_view = loc_bar->location_entry(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2276 | // Add() returns the existing handle for the resource if any. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2277 | *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view); |
| 2278 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2279 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2280 | } |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2281 | #endif // defined(OS_WIN) || defined(OS_LINUX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2282 | |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2283 | #if defined(OS_WIN) |
| 2284 | // TODO(port): Remove windowsisms. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2285 | void AutomationProvider::GetBrowserForWindow(int window_handle, |
| 2286 | bool* success, |
| 2287 | int* browser_handle) { |
| 2288 | *success = false; |
| 2289 | *browser_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2290 | |
| 2291 | if (window_tracker_->ContainsHandle(window_handle)) { |
| 2292 | HWND window = window_tracker_->GetResource(window_handle); |
| 2293 | BrowserList::const_iterator iter = BrowserList::begin(); |
| 2294 | Browser* browser = NULL; |
| 2295 | for (;iter != BrowserList::end(); ++iter) { |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 2296 | HWND hwnd = reinterpret_cast<HWND>((*iter)->window()->GetNativeHandle()); |
| 2297 | if (window == hwnd) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2298 | browser = *iter; |
| 2299 | break; |
| 2300 | } |
| 2301 | } |
| 2302 | if (browser) { |
| 2303 | // Add() returns the existing handle for the resource if any. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2304 | *browser_handle = browser_tracker_->Add(browser); |
| 2305 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2306 | } |
| 2307 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2308 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2309 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2310 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2311 | void AutomationProvider::ShowInterstitialPage(int tab_handle, |
| 2312 | const std::string& html_text, |
| 2313 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2314 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2315 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2316 | TabContents* tab_contents = controller->tab_contents(); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2317 | |
| 2318 | AddNavigationStatusListener<bool>(controller, reply_message, true, |
| 2319 | false, false); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2320 | AutomationInterstitialPage* interstitial = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2321 | new AutomationInterstitialPage(tab_contents, |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2322 | GURL("about:interstitial"), |
| 2323 | html_text); |
| 2324 | interstitial->Show(); |
| 2325 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2326 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2327 | |
| 2328 | AutomationMsg_ShowInterstitialPage::WriteReplyParams(reply_message, false); |
| 2329 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2330 | } |
| 2331 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2332 | void AutomationProvider::HideInterstitialPage(int tab_handle, |
| 2333 | bool* success) { |
| 2334 | *success = false; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2335 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL); |
| 2336 | if (tab_contents && tab_contents->interstitial_page()) { |
| 2337 | tab_contents->interstitial_page()->DontProceed(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2338 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2339 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2340 | } |
| 2341 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2342 | void AutomationProvider::CloseTab(int tab_handle, |
| 2343 | bool wait_until_closed, |
| 2344 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2345 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2346 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
| 2347 | int index; |
| 2348 | Browser* browser = Browser::GetBrowserForController(controller, &index); |
| 2349 | DCHECK(browser); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2350 | new TabClosedNotificationObserver(this, wait_until_closed, reply_message); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2351 | browser->CloseContents(controller->tab_contents()); |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2352 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2353 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2354 | |
| 2355 | AutomationMsg_CloseTab::WriteReplyParams(reply_message, false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2356 | } |
| 2357 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2358 | void AutomationProvider::CloseBrowser(int browser_handle, |
| 2359 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2360 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2361 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2362 | new BrowserClosedNotificationObserver(browser, this, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2363 | reply_message); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 2364 | browser->window()->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2365 | } else { |
| 2366 | NOTREACHED(); |
| 2367 | } |
| 2368 | } |
| 2369 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2370 | void AutomationProvider::CloseBrowserAsync(int browser_handle) { |
| 2371 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2372 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
| 2373 | browser->window()->Close(); |
| 2374 | } else { |
| 2375 | NOTREACHED(); |
| 2376 | } |
| 2377 | } |
| 2378 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2379 | #if defined(OS_WIN) |
| 2380 | // TODO(port): Remove windowsisms. |
[email protected] | 95c3c59 | 2009-07-14 22:09:03 | [diff] [blame] | 2381 | void AutomationProvider::CreateExternalTab( |
| 2382 | const IPC::ExternalTabSettings& settings, |
| 2383 | gfx::NativeWindow* tab_container_window, gfx::NativeWindow* tab_window, |
| 2384 | int* tab_handle) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2385 | *tab_handle = 0; |
| 2386 | *tab_container_window = NULL; |
[email protected] | c4e944f | 2009-06-11 18:22:19 | [diff] [blame] | 2387 | *tab_window = NULL; |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2388 | ExternalTabContainer* external_tab_container = |
| 2389 | new ExternalTabContainer(this, automation_resource_message_filter_); |
[email protected] | 95c3c59 | 2009-07-14 22:09:03 | [diff] [blame] | 2390 | Profile* profile = settings.is_off_the_record ? |
| 2391 | profile_->GetOffTheRecordProfile() : profile_; |
| 2392 | external_tab_container->Init(profile, settings.parent, settings.dimensions, |
[email protected] | 5f450e5 | 2009-07-28 13:28:11 | [diff] [blame] | 2393 | settings.style, settings.load_requests_via_automation, |
| 2394 | settings.handle_top_level_requests); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2395 | TabContents* tab_contents = external_tab_container->tab_contents(); |
| 2396 | if (tab_contents) { |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2397 | *tab_handle = tab_tracker_->Add(&tab_contents->controller()); |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 2398 | external_tab_container->set_tab_handle(*tab_handle); |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 2399 | *tab_container_window = external_tab_container->GetNativeView(); |
[email protected] | c4e944f | 2009-06-11 18:22:19 | [diff] [blame] | 2400 | *tab_window = tab_contents->GetNativeView(); |
[email protected] | 31fb11052 | 2009-01-28 21:50:39 | [diff] [blame] | 2401 | } else { |
| 2402 | delete external_tab_container; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2403 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2404 | } |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 2405 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2406 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2407 | void AutomationProvider::NavigateInExternalTab( |
| 2408 | int handle, const GURL& url, |
| 2409 | AutomationMsg_NavigationResponseValues* status) { |
| 2410 | *status = AUTOMATION_MSG_NAVIGATION_ERROR; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2411 | |
| 2412 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2413 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 2414 | tab->LoadURL(url, GURL(), PageTransition::TYPED); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2415 | *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2416 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2417 | } |
| 2418 | |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 2419 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2420 | void AutomationProvider::ProcessUnhandledAccelerator( |
| 2421 | const IPC::Message& message, int handle, const MSG& msg) { |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 2422 | ExternalTabContainer* external_tab = GetExternalTabForHandle(handle); |
| 2423 | if (external_tab) { |
| 2424 | external_tab->ProcessUnhandledAccelerator(msg); |
| 2425 | } |
| 2426 | // This message expects no response. |
| 2427 | } |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 2428 | #endif |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 2429 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2430 | void AutomationProvider::WaitForTabToBeRestored(int tab_handle, |
| 2431 | IPC::Message* reply_message) { |
| 2432 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2433 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2434 | restore_tracker_.reset( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2435 | new NavigationControllerRestoredObserver(this, tab, reply_message)); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 2439 | void AutomationProvider::SetInitialFocus(const IPC::Message& message, |
| 2440 | int handle, bool reverse) { |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 2441 | #if defined(OS_WIN) |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 2442 | ExternalTabContainer* external_tab = GetExternalTabForHandle(handle); |
| 2443 | if (external_tab) { |
[email protected] | 90daadb4 | 2009-06-08 21:27:28 | [diff] [blame] | 2444 | external_tab->FocusThroughTabTraversal(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2445 | } |
| 2446 | // This message expects no response. |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 2447 | #elif defined(OS_POSIX) |
| 2448 | // TODO(port) enable this function. |
| 2449 | NOTIMPLEMENTED(); |
| 2450 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2451 | } |
| 2452 | |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 2453 | // TODO(port): enable these functions. |
| 2454 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2455 | void AutomationProvider::GetSecurityState(int handle, bool* success, |
| 2456 | SecurityStyle* security_style, |
| 2457 | int* ssl_cert_status, |
| 2458 | int* mixed_content_status) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2459 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2460 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2461 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2462 | *success = true; |
| 2463 | *security_style = entry->ssl().security_style(); |
| 2464 | *ssl_cert_status = entry->ssl().cert_status(); |
| 2465 | *mixed_content_status = entry->ssl().content_status(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2466 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2467 | *success = false; |
| 2468 | *security_style = SECURITY_STYLE_UNKNOWN; |
| 2469 | *ssl_cert_status = 0; |
| 2470 | *mixed_content_status = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2474 | void AutomationProvider::GetPageType(int handle, bool* success, |
| 2475 | NavigationEntry::PageType* page_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2476 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2477 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2478 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2479 | *page_type = entry->page_type(); |
| 2480 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2481 | // In order to return the proper result when an interstitial is shown and |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2482 | // no navigation entry were created for it we need to ask the TabContents. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2483 | if (*page_type == NavigationEntry::NORMAL_PAGE && |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2484 | tab->tab_contents()->showing_interstitial_page()) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2485 | *page_type = NavigationEntry::INTERSTITIAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2486 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2487 | *success = false; |
| 2488 | *page_type = NavigationEntry::NORMAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2489 | } |
| 2490 | } |
| 2491 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2492 | void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, |
| 2493 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2494 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2495 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2496 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 2497 | if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2498 | TabContents* tab_contents = tab->tab_contents(); |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 2499 | InterstitialPage* ssl_blocking_page = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2500 | InterstitialPage::GetInterstitialPage(tab_contents); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2501 | if (ssl_blocking_page) { |
| 2502 | if (proceed) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2503 | AddNavigationStatusListener<bool>(tab, reply_message, true, true, |
| 2504 | false); |
| 2505 | ssl_blocking_page->Proceed(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2506 | return; |
| 2507 | } |
| 2508 | ssl_blocking_page->DontProceed(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2509 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams(reply_message, |
| 2510 | true); |
| 2511 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2512 | return; |
| 2513 | } |
| 2514 | } |
| 2515 | } |
| 2516 | // We failed. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2517 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams(reply_message, |
| 2518 | false); |
| 2519 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2520 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2521 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2522 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2523 | void AutomationProvider::BringBrowserToFront(int browser_handle, |
| 2524 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2525 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2526 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | cd7ffc2 | 2008-11-12 00:26:06 | [diff] [blame] | 2527 | browser->window()->Activate(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2528 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2529 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2530 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2531 | } |
| 2532 | } |
| 2533 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2534 | void AutomationProvider::IsPageMenuCommandEnabled(int browser_handle, |
| 2535 | int message_num, |
| 2536 | bool* menu_item_enabled) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2537 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2538 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2539 | *menu_item_enabled = |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2540 | browser->command_updater()->IsCommandEnabled(message_num); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2541 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2542 | *menu_item_enabled = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2543 | } |
| 2544 | } |
| 2545 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2546 | #if defined(OS_WIN) |
[email protected] | 3753f52 | 2009-04-14 23:15:47 | [diff] [blame] | 2547 | // TODO(port): Enable this. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2548 | void AutomationProvider::PrintNow(int tab_handle, |
| 2549 | IPC::Message* reply_message) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2550 | NavigationController* tab = NULL; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2551 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 2552 | if (tab_contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2553 | FindAndActivateTab(tab); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2554 | notification_observer_list_.AddObserver( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2555 | new DocumentPrintedNotificationObserver(this, reply_message)); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2556 | if (tab_contents->PrintNow()) |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2557 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2558 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2559 | AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); |
| 2560 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2561 | } |
[email protected] | d301c95 | 2009-07-13 15:02:41 | [diff] [blame] | 2562 | |
| 2563 | void AutomationProvider::PrintAsync(int tab_handle) { |
| 2564 | NavigationController* tab = NULL; |
| 2565 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 2566 | if (tab_contents) { |
| 2567 | if (tab_contents->PrintNow()) |
| 2568 | return; |
| 2569 | } |
| 2570 | } |
[email protected] | 3753f52 | 2009-04-14 23:15:47 | [diff] [blame] | 2571 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2572 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2573 | void AutomationProvider::SavePage(int tab_handle, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2574 | const std::wstring& file_name, |
| 2575 | const std::wstring& dir_path, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2576 | int type, |
| 2577 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2578 | if (!tab_tracker_->ContainsHandle(tab_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2579 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2580 | return; |
| 2581 | } |
| 2582 | |
| 2583 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 2584 | Browser* browser = FindAndActivateTab(nav); |
| 2585 | DCHECK(browser); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2586 | if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2587 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2588 | return; |
| 2589 | } |
| 2590 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2591 | SavePackage::SavePackageType save_type = |
| 2592 | static_cast<SavePackage::SavePackageType>(type); |
| 2593 | DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML && |
| 2594 | save_type <= SavePackage::SAVE_AS_COMPLETE_HTML); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2595 | nav->tab_contents()->SavePage(file_name, dir_path, save_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2596 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2597 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2598 | } |
| 2599 | |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2600 | #if defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | 3753f52 | 2009-04-14 23:15:47 | [diff] [blame] | 2601 | // TODO(port): Enable these. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2602 | void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle, |
| 2603 | bool* success, |
| 2604 | std::wstring* text) { |
| 2605 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2606 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2607 | *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 2608 | GetText(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2609 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2610 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2611 | } |
| 2612 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2613 | void AutomationProvider::SetAutocompleteEditText(int autocomplete_edit_handle, |
| 2614 | const std::wstring& text, |
| 2615 | bool* success) { |
| 2616 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2617 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 2618 | autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
| 2619 | SetUserText(text); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2620 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2621 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | void AutomationProvider::AutocompleteEditGetMatches( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2625 | int autocomplete_edit_handle, |
| 2626 | bool* success, |
| 2627 | std::vector<AutocompleteMatchData>* matches) { |
| 2628 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2629 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 8deeb95 | 2008-10-09 18:21:27 | [diff] [blame] | 2630 | const AutocompleteResult& result = autocomplete_edit_tracker_-> |
| 2631 | GetResource(autocomplete_edit_handle)->model()->result(); |
| 2632 | for (AutocompleteResult::const_iterator i = result.begin(); |
| 2633 | i != result.end(); ++i) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2634 | matches->push_back(AutocompleteMatchData(*i)); |
| 2635 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2636 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | void AutomationProvider::AutocompleteEditIsQueryInProgress( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2640 | int autocomplete_edit_handle, |
| 2641 | bool* success, |
| 2642 | bool* query_in_progress) { |
| 2643 | *success = false; |
| 2644 | *query_in_progress = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2645 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2646 | *query_in_progress = autocomplete_edit_tracker_-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 2647 | GetResource(autocomplete_edit_handle)->model()->query_in_progress(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2648 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2649 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2650 | } |
| 2651 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 2652 | void AutomationProvider::OnMessageFromExternalHost(int handle, |
| 2653 | const std::string& message, |
| 2654 | const std::string& origin, |
| 2655 | const std::string& target) { |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2656 | RenderViewHost* view_host = GetViewForTab(handle); |
| 2657 | if (!view_host) { |
| 2658 | return; |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 2659 | } |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2660 | |
| 2661 | if (AutomationExtensionFunction::InterceptMessageFromExternalHost( |
| 2662 | view_host, message, origin, target)) { |
| 2663 | // Message was diverted. |
| 2664 | return; |
| 2665 | } |
| 2666 | |
| 2667 | if (ExtensionPortContainer::InterceptMessageFromExternalHost(message, |
| 2668 | origin, target, this, view_host, handle)) { |
| 2669 | // Message was diverted. |
| 2670 | return; |
| 2671 | } |
| 2672 | |
| 2673 | if (InterceptBrowserEventMessageFromExternalHost(message, origin, target)) { |
| 2674 | // Message was diverted. |
| 2675 | return; |
| 2676 | } |
| 2677 | |
| 2678 | view_host->ForwardMessageFromExternalHost(message, origin, target); |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 2679 | } |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 2680 | |
| 2681 | bool AutomationProvider::InterceptBrowserEventMessageFromExternalHost( |
| 2682 | const std::string& message, const std::string& origin, |
| 2683 | const std::string& target) { |
| 2684 | if (target != |
| 2685 | extension_automation_constants::kAutomationBrowserEventRequestTarget) |
| 2686 | return false; |
| 2687 | |
| 2688 | if (origin != extension_automation_constants::kAutomationOrigin) { |
| 2689 | LOG(WARNING) << "Wrong origin on automation browser event " << origin; |
| 2690 | return false; |
| 2691 | } |
| 2692 | |
| 2693 | // The message is a JSON-encoded array with two elements, both strings. The |
| 2694 | // first is the name of the event to dispatch. The second is a JSON-encoding |
| 2695 | // of the arguments specific to that event. |
| 2696 | scoped_ptr<Value> message_value(JSONReader::Read(message, false)); |
| 2697 | if (!message_value.get() || !message_value->IsType(Value::TYPE_LIST)) { |
| 2698 | LOG(WARNING) << "Invalid browser event specified through automation"; |
| 2699 | return false; |
| 2700 | } |
| 2701 | |
| 2702 | const ListValue* args = static_cast<const ListValue*>(message_value.get()); |
| 2703 | |
| 2704 | std::string event_name; |
| 2705 | if (!args->GetString(0, &event_name)) { |
| 2706 | LOG(WARNING) << "No browser event name specified through automation"; |
| 2707 | return false; |
| 2708 | } |
| 2709 | |
| 2710 | std::string json_args; |
| 2711 | if (!args->GetString(1, &json_args)) { |
| 2712 | LOG(WARNING) << "No browser event args specified through automation"; |
| 2713 | return false; |
| 2714 | } |
| 2715 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 2716 | if (profile()->GetExtensionMessageService()) { |
| 2717 | profile()->GetExtensionMessageService()-> |
| 2718 | DispatchEventToRenderers(event_name.c_str(), json_args); |
| 2719 | } |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 2720 | |
| 2721 | return true; |
| 2722 | } |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2723 | #endif // defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 2724 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2725 | TabContents* AutomationProvider::GetTabContentsForHandle( |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2726 | int handle, NavigationController** tab) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2727 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2728 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2729 | if (tab) |
| 2730 | *tab = nav_controller; |
| 2731 | return nav_controller->tab_contents(); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2732 | } |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2733 | return NULL; |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2734 | } |
| 2735 | |
[email protected] | 5cc06369 | 2009-04-07 23:21:31 | [diff] [blame] | 2736 | #if defined(OS_WIN) |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 2737 | ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { |
| 2738 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2739 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2740 | return ExternalTabContainer::GetContainerForTab( |
| 2741 | tab->tab_contents()->GetNativeView()); |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | return NULL; |
| 2745 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2746 | #endif // defined(OS_WIN) |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 2747 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2748 | TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
| 2749 | : AutomationProvider(profile) { |
| 2750 | BrowserList::AddObserver(this); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2751 | registrar_.Add(this, NotificationType::SESSION_END, |
| 2752 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | TestingAutomationProvider::~TestingAutomationProvider() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2756 | BrowserList::RemoveObserver(this); |
| 2757 | } |
| 2758 | |
| 2759 | void TestingAutomationProvider::OnChannelError() { |
| 2760 | BrowserList::CloseAllBrowsers(true); |
| 2761 | AutomationProvider::OnChannelError(); |
| 2762 | } |
| 2763 | |
| 2764 | void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) { |
| 2765 | // For backwards compatibility with the testing automation interface, we |
| 2766 | // want the automation provider (and hence the process) to go away when the |
| 2767 | // last browser goes away. |
| 2768 | if (BrowserList::size() == 1) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2769 | // If you change this, update Observer for NotificationType::SESSION_END |
| 2770 | // below. |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 2771 | MessageLoop::current()->PostTask(FROM_HERE, |
| 2772 | NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | |
| 2776 | void TestingAutomationProvider::Observe(NotificationType type, |
| 2777 | const NotificationSource& source, |
| 2778 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 2779 | DCHECK(type == NotificationType::SESSION_END); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2780 | // OnBrowserRemoving does a ReleaseLater. When session end is received we exit |
| 2781 | // before the task runs resulting in this object not being deleted. This |
| 2782 | // Release balance out the Release scheduled by OnBrowserRemoving. |
| 2783 | Release(); |
| 2784 | } |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 2785 | |
| 2786 | void TestingAutomationProvider::OnRemoveProvider() { |
| 2787 | AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 2788 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2789 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2790 | void AutomationProvider::GetSSLInfoBarCount(int handle, int* count) { |
| 2791 | *count = -1; // -1 means error. |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2792 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2793 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2794 | if (nav_controller) |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2795 | *count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2796 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2797 | } |
| 2798 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2799 | void AutomationProvider::ClickSSLInfoBarLink(int handle, |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2800 | int info_bar_index, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2801 | bool wait_for_navigation, |
| 2802 | IPC::Message* reply_message) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2803 | bool success = false; |
| 2804 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2805 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 2806 | if (nav_controller) { |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2807 | int count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2808 | if (info_bar_index >= 0 && info_bar_index < count) { |
| 2809 | if (wait_for_navigation) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2810 | AddNavigationStatusListener<bool>(nav_controller, reply_message, |
| 2811 | true, true, false); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2812 | } |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2813 | InfoBarDelegate* delegate = |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2814 | nav_controller->tab_contents()->GetInfoBarDelegateAt( |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2815 | info_bar_index); |
| 2816 | if (delegate->AsConfirmInfoBarDelegate()) |
| 2817 | delegate->AsConfirmInfoBarDelegate()->Accept(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2818 | success = true; |
| 2819 | } |
| 2820 | } |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2821 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2822 | if (!wait_for_navigation || !success) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2823 | AutomationMsg_ClickSSLInfoBarLink::WriteReplyParams(reply_message, |
| 2824 | success); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2825 | } |
| 2826 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2827 | void AutomationProvider::GetLastNavigationTime(int handle, |
| 2828 | int64* last_navigation_time) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2829 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2830 | *last_navigation_time = time.ToInternalValue(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2831 | } |
| 2832 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2833 | void AutomationProvider::WaitForNavigation(int handle, |
| 2834 | int64 last_navigation_time, |
| 2835 | IPC::Message* reply_message) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2836 | NavigationController* controller = NULL; |
| 2837 | if (tab_tracker_->ContainsHandle(handle)) |
| 2838 | controller = tab_tracker_->GetResource(handle); |
| 2839 | |
| 2840 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
| 2841 | if (time.ToInternalValue() > last_navigation_time || !controller) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2842 | AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message, |
| 2843 | controller != NULL); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2844 | return; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2845 | } |
| 2846 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2847 | AddNavigationStatusListener<bool>(controller, reply_message, true, true, |
| 2848 | false); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2849 | } |
| 2850 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2851 | void AutomationProvider::SetIntPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2852 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2853 | int value, |
| 2854 | bool* success) { |
| 2855 | *success = false; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2856 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2857 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2858 | browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2859 | *success = true; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2860 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2861 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2862 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2863 | void AutomationProvider::SetStringPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2864 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2865 | const std::wstring& value, |
| 2866 | bool* success) { |
| 2867 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2868 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2869 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2870 | browser->profile()->GetPrefs()->SetString(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2871 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2872 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2873 | } |
| 2874 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2875 | void AutomationProvider::GetBooleanPreference(int handle, |
| 2876 | const std::wstring& name, |
| 2877 | bool* success, |
| 2878 | bool* value) { |
| 2879 | *success = false; |
| 2880 | *value = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2881 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2882 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2883 | *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str()); |
| 2884 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2885 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2886 | } |
| 2887 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2888 | void AutomationProvider::SetBooleanPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2889 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2890 | bool value, |
| 2891 | bool* success) { |
| 2892 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2893 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2894 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2895 | browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2896 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2897 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2901 | void AutomationProvider::GetPageCurrentEncoding( |
| 2902 | int tab_handle, std::wstring* current_encoding) { |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2903 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2904 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 2905 | Browser* browser = FindAndActivateTab(nav); |
| 2906 | DCHECK(browser); |
| 2907 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2908 | if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) |
| 2909 | *current_encoding = nav->tab_contents()->encoding(); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2910 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2914 | void AutomationProvider::OverrideEncoding(int tab_handle, |
| 2915 | const std::wstring& encoding_name, |
| 2916 | bool* success) { |
| 2917 | *success = false; |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2918 | #if defined(OS_WIN) |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2919 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2920 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 2921 | Browser* browser = FindAndActivateTab(nav); |
| 2922 | DCHECK(browser); |
| 2923 | |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2924 | if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2925 | TabContents* tab_contents = nav->tab_contents(); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2926 | int selected_encoding_id = |
| 2927 | CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name); |
| 2928 | if (selected_encoding_id) { |
| 2929 | browser->OverrideEncoding(selected_encoding_id); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2930 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2931 | } |
| 2932 | } |
| 2933 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2934 | #else |
| 2935 | // TODO(port): Enable when encoding-related parts of Browser are ported. |
| 2936 | NOTIMPLEMENTED(); |
| 2937 | #endif |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2938 | } |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 2939 | |
[email protected] | 4d434a1a | 2009-02-11 21:06:57 | [diff] [blame] | 2940 | void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) { |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 2941 | SavePackage::SetShouldPromptUser(should_prompt); |
| 2942 | } |
[email protected] | 87eab22 | 2009-03-13 00:47:45 | [diff] [blame] | 2943 | |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 2944 | void AutomationProvider::SetEnableExtensionAutomation(bool automation_enabled) { |
| 2945 | AutomationExtensionFunction::SetEnabled(automation_enabled); |
| 2946 | } |
| 2947 | |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 2948 | #if defined(OS_WIN) |
| 2949 | // TODO(port): Reposition_Params is win-specific. We'll need to port it. |
[email protected] | 87eab22 | 2009-03-13 00:47:45 | [diff] [blame] | 2950 | void AutomationProvider::OnTabReposition( |
| 2951 | int tab_handle, const IPC::Reposition_Params& params) { |
| 2952 | if (!tab_tracker_->ContainsHandle(tab_handle)) |
| 2953 | return; |
| 2954 | |
| 2955 | if (!IsWindow(params.window)) |
| 2956 | return; |
| 2957 | |
| 2958 | unsigned long process_id = 0; |
| 2959 | unsigned long thread_id = 0; |
| 2960 | |
| 2961 | thread_id = GetWindowThreadProcessId(params.window, &process_id); |
| 2962 | |
| 2963 | if (thread_id != GetCurrentThreadId()) { |
| 2964 | NOTREACHED(); |
| 2965 | return; |
| 2966 | } |
| 2967 | |
[email protected] | a9233d0f | 2009-04-20 05:39:33 | [diff] [blame] | 2968 | SetWindowPos(params.window, params.window_insert_after, params.left, |
| 2969 | params.top, params.width, params.height, params.flags); |
| 2970 | |
[email protected] | a2c5a989 | 2009-04-07 16:13:45 | [diff] [blame] | 2971 | if (params.set_parent) { |
| 2972 | if (IsWindow(params.parent_window)) { |
| 2973 | if (!SetParent(params.window, params.parent_window)) |
| 2974 | DLOG(WARNING) << "SetParent failed. Error 0x%x" << GetLastError(); |
| 2975 | } |
| 2976 | } |
[email protected] | 87eab22 | 2009-03-13 00:47:45 | [diff] [blame] | 2977 | } |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 2978 | |
| 2979 | void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle, |
| 2980 | int command) { |
| 2981 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2982 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2983 | if (!tab) { |
| 2984 | NOTREACHED(); |
| 2985 | return; |
| 2986 | } |
| 2987 | |
| 2988 | TabContents* tab_contents = tab->tab_contents(); |
| 2989 | if (!tab_contents || !tab_contents->delegate()) { |
| 2990 | NOTREACHED(); |
| 2991 | return; |
| 2992 | } |
| 2993 | |
| 2994 | tab_contents->delegate()->ExecuteContextMenuCommand(command); |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | #endif // defined(OS_WIN) |
[email protected] | 3753f52 | 2009-04-14 23:15:47 | [diff] [blame] | 2999 | |
| 3000 | void AutomationProvider::GetWindowTitle(int handle, string16* text) { |
| 3001 | gfx::NativeWindow window = window_tracker_->GetResource(handle); |
| 3002 | text->assign(platform_util::GetWindowTitle(window)); |
| 3003 | } |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 3004 | |
| 3005 | void AutomationProvider::GetBlockedPopupCount(int handle, int* count) { |
| 3006 | *count = -1; // -1 is the error code |
| 3007 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3008 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 3009 | TabContents* tab_contents = nav_controller->tab_contents(); |
| 3010 | if (tab_contents) { |
| 3011 | BlockedPopupContainer* container = |
| 3012 | tab_contents->blocked_popup_container(); |
| 3013 | if (container) { |
| 3014 | *count = static_cast<int>(container->GetBlockedPopupCount()); |
| 3015 | } else { |
| 3016 | // If we don't have a container, we don't have any blocked popups to |
| 3017 | // contain! |
| 3018 | *count = 0; |
| 3019 | } |
| 3020 | } |
| 3021 | } |
| 3022 | } |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 3023 | |
| 3024 | void AutomationProvider::SelectAll(int tab_handle) { |
| 3025 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3026 | if (!view) { |
| 3027 | NOTREACHED(); |
| 3028 | return; |
| 3029 | } |
| 3030 | |
| 3031 | view->SelectAll(); |
| 3032 | } |
| 3033 | |
| 3034 | void AutomationProvider::Cut(int tab_handle) { |
| 3035 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3036 | if (!view) { |
| 3037 | NOTREACHED(); |
| 3038 | return; |
| 3039 | } |
| 3040 | |
| 3041 | view->Cut(); |
| 3042 | } |
| 3043 | |
| 3044 | void AutomationProvider::Copy(int tab_handle) { |
| 3045 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3046 | if (!view) { |
| 3047 | NOTREACHED(); |
| 3048 | return; |
| 3049 | } |
| 3050 | |
| 3051 | view->Copy(); |
| 3052 | } |
| 3053 | |
| 3054 | void AutomationProvider::Paste(int tab_handle) { |
| 3055 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3056 | if (!view) { |
| 3057 | NOTREACHED(); |
| 3058 | return; |
| 3059 | } |
| 3060 | |
| 3061 | view->Paste(); |
| 3062 | } |
| 3063 | |
| 3064 | void AutomationProvider::ReloadAsync(int tab_handle) { |
| 3065 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 3066 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 3067 | if (!tab) { |
| 3068 | NOTREACHED(); |
| 3069 | return; |
| 3070 | } |
| 3071 | |
| 3072 | tab->Reload(false); |
| 3073 | } |
| 3074 | } |
| 3075 | |
| 3076 | void AutomationProvider::StopAsync(int tab_handle) { |
| 3077 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3078 | if (!view) { |
| 3079 | NOTREACHED(); |
| 3080 | return; |
| 3081 | } |
| 3082 | |
| 3083 | view->Stop(); |
| 3084 | } |
| 3085 | |
| 3086 | RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { |
| 3087 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 3088 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 3089 | if (!tab) { |
| 3090 | NOTREACHED(); |
| 3091 | return NULL; |
| 3092 | } |
| 3093 | |
| 3094 | TabContents* tab_contents = tab->tab_contents(); |
| 3095 | if (!tab_contents) { |
| 3096 | NOTREACHED(); |
| 3097 | return NULL; |
| 3098 | } |
| 3099 | |
| 3100 | RenderViewHost* view_host = tab_contents->render_view_host(); |
| 3101 | return view_host; |
| 3102 | } |
| 3103 | |
| 3104 | return NULL; |
| 3105 | } |