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