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