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