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