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