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