[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 1 | // Copyright (c) 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] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 7 | #include <set> |
| 8 | |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 9 | #include "app/l10n_util.h" |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 10 | #include "app/message_box_flags.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | c6cb199 | 2009-04-13 16:45:29 | [diff] [blame] | 12 | #include "base/file_version_info.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 13 | #include "base/json/json_reader.h" |
[email protected] | bc1407f | 2009-09-29 00:33:35 | [diff] [blame] | 14 | #include "base/keyboard_codes.h" |
[email protected] | 5fac962 | 2009-02-04 21:49:38 | [diff] [blame] | 15 | #include "base/message_loop.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "base/path_service.h" |
[email protected] | 201b273 | 2009-11-13 18:57:46 | [diff] [blame] | 17 | #include "base/process_util.h" |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 18 | #include "base/stl_util-inl.h" |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 19 | #include "base/string_util.h" |
[email protected] | 5fac962 | 2009-02-04 21:49:38 | [diff] [blame] | 20 | #include "base/thread.h" |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 21 | #include "base/utf_string_conversions.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 22 | #include "base/values.h" |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 23 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 24 | #include "chrome/browser/app_modal_dialog.h" |
[email protected] | 464146e | 2009-04-09 18:17:09 | [diff] [blame] | 25 | #include "chrome/browser/app_modal_dialog_queue.h" |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 26 | #include "chrome/browser/automation/automation_extension_function.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | #include "chrome/browser/automation/automation_provider_list.h" |
[email protected] | e12de87e | 2009-08-28 00:02:08 | [diff] [blame] | 28 | #include "chrome/browser/automation/automation_provider_observers.h" |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 29 | #include "chrome/browser/automation/extension_automation_constants.h" |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 30 | #include "chrome/browser/automation/extension_port_container.h" |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 31 | #include "chrome/browser/blocked_popup_container.h" |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 32 | #include "chrome/browser/bookmarks/bookmark_model.h" |
| 33 | #include "chrome/browser/bookmarks/bookmark_storage.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 34 | #include "chrome/browser/browser_process.h" |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 35 | #include "chrome/browser/browser_window.h" |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 36 | #include "chrome/browser/chrome_thread.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | #include "chrome/browser/dom_operation_notification_details.h" |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 38 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | cdaa865 | 2008-09-13 02:48:59 | [diff] [blame] | 39 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 40 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 41 | #include "chrome/browser/extensions/crx_installer.h" |
| 42 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_message_service.h" |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 44 | #include "chrome/browser/extensions/user_script_master.h" |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 45 | #include "chrome/browser/find_bar.h" |
| 46 | #include "chrome/browser/find_bar_controller.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | #include "chrome/browser/find_notification_details.h" |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 48 | #include "chrome/browser/host_content_settings_map.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 49 | #include "chrome/browser/io_thread.h" |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 50 | #include "chrome/browser/location_bar.h" |
[email protected] | 3fcac68 | 2009-08-13 02:28:01 | [diff] [blame] | 51 | #include "chrome/browser/login_prompt.h" |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 52 | #include "chrome/browser/net/url_request_context_getter.h" |
[email protected] | f732c1e | 2009-07-30 15:48:53 | [diff] [blame] | 53 | #include "chrome/browser/net/url_request_mock_util.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 54 | #include "chrome/browser/pref_service.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 55 | #include "chrome/browser/profile_manager.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 56 | #include "chrome/browser/renderer_host/render_process_host.h" |
[email protected] | 6524b5f9 | 2009-01-22 17:48:25 | [diff] [blame] | 57 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 3b073b2 | 2009-01-16 03:29:03 | [diff] [blame] | 58 | #include "chrome/browser/ssl/ssl_manager.h" |
| 59 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 60 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 81af939 | 2009-04-21 02:37:45 | [diff] [blame] | 61 | #include "chrome/browser/tab_contents/tab_contents_view.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 62 | #include "chrome/common/automation_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | #include "chrome/common/chrome_paths.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 64 | #include "chrome/common/json_value_serializer.h" |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 65 | #include "chrome/common/notification_service.h" |
[email protected] | 3753f52 | 2009-04-14 23:15:47 | [diff] [blame] | 66 | #include "chrome/common/platform_util.h" |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 67 | #include "chrome/common/pref_names.h" |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 68 | #include "chrome/common/url_constants.h" |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 69 | #include "chrome/test/automation/automation_messages.h" |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 70 | #include "chrome/test/automation/tab_proxy.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 71 | #include "net/proxy/proxy_service.h" |
| 72 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 73 | #include "net/url_request/url_request_context.h" |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame] | 74 | #include "views/event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 75 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 76 | #if defined(OS_WIN) |
| 77 | // TODO(port): Port these headers. |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 78 | #include "chrome/browser/character_encoding.h" |
| 79 | #include "chrome/browser/download/save_package.h" |
| 80 | #include "chrome/browser/external_tab_container.h" |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 81 | #include "chrome/browser/printing/print_job.h" |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 82 | #endif // defined(OS_WIN) |
| 83 | |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 84 | #if !defined(OS_MACOSX) |
[email protected] | e838217 | 2009-06-19 22:16:28 | [diff] [blame] | 85 | // TODO(port): Port these to the mac. |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame] | 86 | #include "chrome/browser/automation/ui_controls.h" |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 87 | #endif // !defined(OS_MACOSX) |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 88 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 89 | using base::Time; |
| 90 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 91 | class AutomationInterstitialPage : public InterstitialPage { |
| 92 | public: |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 93 | AutomationInterstitialPage(TabContents* tab, |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 94 | const GURL& url, |
| 95 | const std::string& contents) |
| 96 | : InterstitialPage(tab, true, url), |
| 97 | contents_(contents) { |
| 98 | } |
| 99 | |
| 100 | virtual std::string GetHTMLContents() { return contents_; } |
| 101 | |
| 102 | private: |
| 103 | std::string contents_; |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 104 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
| 106 | }; |
| 107 | |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 108 | #if !defined(OS_MACOSX) |
| 109 | class ClickTask : public Task { |
| 110 | public: |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 111 | explicit ClickTask(int flags) : flags_(flags) {} |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 112 | virtual ~ClickTask() {} |
| 113 | |
| 114 | virtual void Run() { |
| 115 | ui_controls::MouseButton button = ui_controls::LEFT; |
| 116 | if ((flags_ & views::Event::EF_LEFT_BUTTON_DOWN) == |
| 117 | views::Event::EF_LEFT_BUTTON_DOWN) { |
| 118 | button = ui_controls::LEFT; |
| 119 | } else if ((flags_ & views::Event::EF_RIGHT_BUTTON_DOWN) == |
| 120 | views::Event::EF_RIGHT_BUTTON_DOWN) { |
| 121 | button = ui_controls::RIGHT; |
| 122 | } else if ((flags_ & views::Event::EF_MIDDLE_BUTTON_DOWN) == |
| 123 | views::Event::EF_MIDDLE_BUTTON_DOWN) { |
| 124 | button = ui_controls::MIDDLE; |
| 125 | } else { |
| 126 | NOTREACHED(); |
| 127 | } |
| 128 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 129 | ui_controls::SendMouseClick(button); |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | private: |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 133 | int flags_; |
| 134 | |
| 135 | DISALLOW_COPY_AND_ASSIGN(ClickTask); |
| 136 | }; |
| 137 | #endif |
| 138 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 139 | AutomationProvider::AutomationProvider(Profile* profile) |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 140 | : redirect_query_(0), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 141 | profile_(profile), |
| 142 | reply_message_(NULL) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 143 | browser_tracker_.reset(new AutomationBrowserTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 144 | tab_tracker_.reset(new AutomationTabTracker(this)); |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 145 | window_tracker_.reset(new AutomationWindowTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 146 | autocomplete_edit_tracker_.reset( |
| 147 | new AutomationAutocompleteEditTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 148 | new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); |
| 149 | dom_operation_observer_.reset(new DomOperationNotificationObserver(this)); |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 150 | metric_event_duration_observer_.reset(new MetricEventDurationObserver()); |
[email protected] | 528211a | 2010-01-14 15:25:13 | [diff] [blame] | 151 | g_browser_process->AddRefModule(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | AutomationProvider::~AutomationProvider() { |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 155 | STLDeleteContainerPairSecondPointers(port_containers_.begin(), |
| 156 | port_containers_.end()); |
| 157 | port_containers_.clear(); |
| 158 | |
[email protected] | 0da050b9 | 2008-08-19 19:29:47 | [diff] [blame] | 159 | // Make sure that any outstanding NotificationObservers also get destroyed. |
| 160 | ObserverList<NotificationObserver>::Iterator it(notification_observer_list_); |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 161 | NotificationObserver* observer; |
[email protected] | 0da050b9 | 2008-08-19 19:29:47 | [diff] [blame] | 162 | while ((observer = it.GetNext()) != NULL) |
| 163 | delete observer; |
[email protected] | 528211a | 2010-01-14 15:25:13 | [diff] [blame] | 164 | |
| 165 | if (channel_.get()) { |
| 166 | channel_->Close(); |
| 167 | } |
| 168 | g_browser_process->ReleaseModule(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | 9a3a293b | 2009-06-04 22:28:16 | [diff] [blame] | 171 | void AutomationProvider::ConnectToChannel(const std::string& channel_id) { |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 172 | automation_resource_message_filter_ = new AutomationResourceMessageFilter; |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 173 | channel_.reset( |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 174 | new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, |
| 175 | automation_resource_message_filter_, |
| 176 | g_browser_process->io_thread()->message_loop(), |
| 177 | true, g_browser_process->shutdown_event())); |
[email protected] | 79e96683 | 2009-04-21 14:23:05 | [diff] [blame] | 178 | scoped_ptr<FileVersionInfo> file_version_info( |
| 179 | FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
[email protected] | cf62075 | 2009-04-24 17:05:40 | [diff] [blame] | 180 | std::string version_string; |
| 181 | if (file_version_info != NULL) { |
| 182 | version_string = WideToASCII(file_version_info->file_version()); |
| 183 | } |
[email protected] | c6cb199 | 2009-04-13 16:45:29 | [diff] [blame] | 184 | |
| 185 | // Send a hello message with our current automation protocol version. |
| 186 | channel_->Send(new AutomationMsg_Hello(0, version_string.c_str())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { |
| 190 | if (expected_tabs == 0) { |
| 191 | Send(new AutomationMsg_InitialLoadsComplete(0)); |
| 192 | } else { |
| 193 | initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | NotificationObserver* AutomationProvider::AddNavigationStatusListener( |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 198 | NavigationController* tab, IPC::Message* reply_message, |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 199 | int number_of_navigations, bool include_current_navigation) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 200 | NotificationObserver* observer = |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 201 | new NavigationNotificationObserver(tab, this, reply_message, |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 202 | number_of_navigations, |
| 203 | include_current_navigation); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 204 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 205 | notification_observer_list_.AddObserver(observer); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 206 | return observer; |
| 207 | } |
| 208 | |
| 209 | void AutomationProvider::RemoveNavigationStatusListener( |
| 210 | NotificationObserver* obs) { |
| 211 | notification_observer_list_.RemoveObserver(obs); |
| 212 | } |
| 213 | |
| 214 | NotificationObserver* AutomationProvider::AddTabStripObserver( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 215 | Browser* parent, |
| 216 | IPC::Message* reply_message) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 217 | NotificationObserver* observer = |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 218 | new TabAppendedNotificationObserver(parent, this, reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 219 | notification_observer_list_.AddObserver(observer); |
| 220 | |
| 221 | return observer; |
| 222 | } |
| 223 | |
| 224 | void AutomationProvider::RemoveTabStripObserver(NotificationObserver* obs) { |
| 225 | notification_observer_list_.RemoveObserver(obs); |
| 226 | } |
| 227 | |
| 228 | void AutomationProvider::AddLoginHandler(NavigationController* tab, |
| 229 | LoginHandler* handler) { |
| 230 | login_handler_map_[tab] = handler; |
| 231 | } |
| 232 | |
| 233 | void AutomationProvider::RemoveLoginHandler(NavigationController* tab) { |
| 234 | DCHECK(login_handler_map_[tab]); |
| 235 | login_handler_map_.erase(tab); |
| 236 | } |
| 237 | |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 238 | void AutomationProvider::AddPortContainer(ExtensionPortContainer* port) { |
| 239 | int port_id = port->port_id(); |
| 240 | DCHECK_NE(-1, port_id); |
| 241 | DCHECK(port_containers_.find(port_id) == port_containers_.end()); |
| 242 | |
| 243 | port_containers_[port_id] = port; |
| 244 | } |
| 245 | |
| 246 | void AutomationProvider::RemovePortContainer(ExtensionPortContainer* port) { |
| 247 | int port_id = port->port_id(); |
| 248 | DCHECK_NE(-1, port_id); |
| 249 | |
| 250 | PortContainerMap::iterator it = port_containers_.find(port_id); |
| 251 | DCHECK(it != port_containers_.end()); |
| 252 | |
| 253 | if (it != port_containers_.end()) { |
| 254 | delete it->second; |
| 255 | port_containers_.erase(it); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | ExtensionPortContainer* AutomationProvider::GetPortContainer( |
| 260 | int port_id) const { |
| 261 | PortContainerMap::const_iterator it = port_containers_.find(port_id); |
| 262 | if (it == port_containers_.end()) |
| 263 | return NULL; |
| 264 | |
| 265 | return it->second; |
| 266 | } |
| 267 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 268 | int AutomationProvider::GetIndexForNavigationController( |
| 269 | const NavigationController* controller, const Browser* parent) const { |
| 270 | DCHECK(parent); |
[email protected] | 902cdf77 | 2009-05-06 15:08:12 | [diff] [blame] | 271 | return parent->GetIndexOfController(controller); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void AutomationProvider::OnMessageReceived(const IPC::Message& message) { |
| 275 | IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 276 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 277 | IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync, |
| 278 | CloseBrowserAsync) |
| 279 | IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) |
| 280 | IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex) |
| 281 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) |
| 282 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab) |
| 283 | IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) |
| 284 | IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 285 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL) |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 286 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 287 | AutomationMsg_NavigateToURLBlockUntilNavigationsComplete, |
| 288 | NavigateToURLBlockUntilNavigationsComplete) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 289 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync) |
| 290 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack) |
| 291 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward) |
| 292 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload) |
| 293 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 294 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 295 | IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth) |
| 296 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom, |
| 297 | GetRedirectsFrom) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 298 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount) |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 299 | IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount, |
| 300 | GetNormalBrowserWindowCount) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 301 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow) |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 302 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBrowserLocale, GetBrowserLocale) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 303 | IPC_MESSAGE_HANDLER(AutomationMsg_LastActiveBrowserWindow, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | GetLastActiveBrowserWindow) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 305 | IPC_MESSAGE_HANDLER(AutomationMsg_ActiveWindow, GetActiveWindow) |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 306 | IPC_MESSAGE_HANDLER(AutomationMsg_FindNormalBrowserWindow, |
| 307 | FindNormalBrowserWindow) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 308 | IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActive, IsWindowActive) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 309 | IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow) |
[email protected] | 8dd404bb | 2009-09-22 19:57:24 | [diff] [blame] | 310 | IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowMaximized, IsWindowMaximized) |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 311 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 312 | ExecuteBrowserCommandAsync) |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 313 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 314 | ExecuteBrowserCommand) |
[email protected] | 8dd404bb | 2009-09-22 19:57:24 | [diff] [blame] | 315 | IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 316 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) |
[email protected] | 8dd404bb | 2009-09-22 19:57:24 | [diff] [blame] | 317 | IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) |
[email protected] | 8f04ff9 | 2009-07-08 02:37:15 | [diff] [blame] | 318 | IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 319 | IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 320 | #if !defined(OS_MACOSX) |
[email protected] | d1a5941e | 2009-08-13 23:34:24 | [diff] [blame] | 321 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) |
[email protected] | 60507b1 | 2009-11-02 23:51:35 | [diff] [blame] | 322 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 323 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 324 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, |
| 325 | WindowSimulateDrag) |
[email protected] | b2aa3ed7 | 2010-02-01 18:37:14 | [diff] [blame] | 326 | #endif |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 327 | IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 328 | IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 329 | IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) |
[email protected] | d7fa755 | 2009-03-20 21:06:37 | [diff] [blame] | 330 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 331 | IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 332 | #endif // defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 333 | IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) |
| 334 | IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 335 | IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 336 | IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 337 | IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility) |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 338 | IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen) |
| 339 | IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible, |
| 340 | GetFullscreenBubbleVisibility) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 341 | IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 342 | IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 343 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, |
| 344 | ExecuteJavascript) |
| 345 | IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 346 | GetConstrainedWindowCount) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 347 | IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest) |
| 348 | IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 349 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, |
| 350 | HandleInspectElementRequest) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 351 | IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory) |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 352 | IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 353 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 354 | OpenNewBrowserWindow) |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 355 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, |
| 356 | OpenNewBrowserWindowOfType) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 357 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 358 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 359 | GetAutocompleteEditForBrowser) |
| 360 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 361 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 362 | IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 363 | #endif |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 364 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | NavigateInExternalTab) |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 366 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigateExternalTabAtIndex, |
| 367 | NavigateExternalTabAtIndex) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 368 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 369 | ShowInterstitialPage) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 370 | IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 371 | HideInterstitialPage) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 372 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 373 | IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator, |
| 374 | ProcessUnhandledAccelerator) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 375 | #endif |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 376 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, |
| 377 | WaitForTabToBeRestored) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 378 | IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 379 | #if defined(OS_WIN) |
[email protected] | 5a970843 | 2009-09-23 22:15:04 | [diff] [blame] | 380 | IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition) |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 381 | IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome, |
| 382 | OnForwardContextMenuCommandToChrome) |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 383 | #endif |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 384 | IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState) |
| 385 | IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType) |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 386 | IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration, |
| 387 | GetMetricEventDuration) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 388 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage, |
| 389 | ActionOnSSLBlockingPage) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 390 | IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront) |
| 391 | IPC_MESSAGE_HANDLER(AutomationMsg_IsPageMenuCommandEnabled, |
| 392 | IsPageMenuCommandEnabled) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 393 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow) |
[email protected] | d301c95 | 2009-07-13 15:02:41 | [diff] [blame] | 394 | IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 395 | IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage) |
| 396 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 397 | GetAutocompleteEditText) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 398 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 399 | SetAutocompleteEditText) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 400 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 401 | AutocompleteEditIsQueryInProgress) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 402 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 403 | AutocompleteEditGetMatches) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 404 | IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 405 | HandleOpenFindInPageRequest) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 406 | IPC_MESSAGE_HANDLER(AutomationMsg_HandleMessageFromExternalHost, |
| 407 | OnMessageFromExternalHost) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 408 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 409 | IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility, |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 410 | GetFindWindowVisibility) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 411 | IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation, |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 412 | HandleFindWindowLocationRequest) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 413 | IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility, |
| 414 | GetBookmarkBarVisibility) |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 415 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBookmarksAsJSON, |
| 416 | GetBookmarksAsJSON) |
| 417 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForBookmarkModelToLoad, |
| 418 | WaitForBookmarkModelToLoad) |
| 419 | IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkGroup, |
| 420 | AddBookmarkGroup) |
| 421 | IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkURL, |
| 422 | AddBookmarkURL) |
| 423 | IPC_MESSAGE_HANDLER(AutomationMsg_ReparentBookmark, |
| 424 | ReparentBookmark) |
| 425 | IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkTitle, |
| 426 | SetBookmarkTitle) |
| 427 | IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkURL, |
| 428 | SetBookmarkURL) |
| 429 | IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBookmark, |
| 430 | RemoveBookmark) |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 431 | IPC_MESSAGE_HANDLER(AutomationMsg_GetInfoBarCount, GetInfoBarCount) |
| 432 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickInfoBarAccept, |
| 433 | ClickInfoBarAccept) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 434 | IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime, |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 435 | GetLastNavigationTime) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 436 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation, |
| 437 | WaitForNavigation) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 438 | IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference, SetIntPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 439 | IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog, |
[email protected] | c274acc | 2008-11-11 20:13:44 | [diff] [blame] | 440 | GetShowingAppModalDialog) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 441 | IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton, |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 442 | ClickAppModalDialogButton) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 443 | IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference, SetStringPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 444 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 445 | GetBooleanPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 446 | IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 447 | SetBooleanPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 448 | IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 449 | GetPageCurrentEncoding) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 450 | IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 451 | IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, |
| 452 | SavePackageShouldPromptUser) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 453 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) |
[email protected] | 4cfc1d92 | 2009-11-08 14:02:58 | [diff] [blame] | 454 | #if defined(OS_WIN) |
| 455 | // Depends on ExternalTabContainer, so Windows-only |
[email protected] | b83e460 | 2009-05-15 22:58:33 | [diff] [blame] | 456 | IPC_MESSAGE_HANDLER(AutomationMsg_SetEnableExtensionAutomation, |
| 457 | SetEnableExtensionAutomation) |
[email protected] | 4cfc1d92 | 2009-11-08 14:02:58 | [diff] [blame] | 458 | #endif |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 459 | IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 460 | IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 461 | IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) |
| 462 | IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) |
| 463 | IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) |
| 464 | IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) |
| 465 | IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) |
| 466 | IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) |
[email protected] | 2949e90d | 2009-08-21 15:32:52 | [diff] [blame] | 467 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 468 | AutomationMsg_WaitForBrowserWindowCountToBecome, |
| 469 | WaitForBrowserWindowCountToBecome) |
| 470 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 471 | AutomationMsg_WaitForAppModalDialogToBeShown, |
| 472 | WaitForAppModalDialogToBeShown) |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 473 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 474 | AutomationMsg_GoBackBlockUntilNavigationsComplete, |
| 475 | GoBackBlockUntilNavigationsComplete) |
| 476 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 477 | AutomationMsg_GoForwardBlockUntilNavigationsComplete, |
| 478 | GoForwardBlockUntilNavigationsComplete) |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 479 | #if defined(OS_WIN) |
| 480 | IPC_MESSAGE_HANDLER(AutomationMsg_ConnectExternalTab, ConnectExternalTab) |
| 481 | #endif |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 482 | IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 483 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension, |
| 484 | InstallExtension) |
| 485 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoadExpandedExtension, |
| 486 | LoadExpandedExtension) |
[email protected] | a1e62d1 | 2010-03-16 02:18:43 | [diff] [blame] | 487 | IPC_MESSAGE_HANDLER(AutomationMsg_GetEnabledExtensions, |
| 488 | GetEnabledExtensions) |
[email protected] | fedaa7d | 2010-01-26 20:34:57 | [diff] [blame] | 489 | IPC_MESSAGE_HANDLER(AutomationMsg_ShutdownSessionService, |
| 490 | ShutdownSessionService) |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 491 | IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync) |
[email protected] | 2b19e2fe | 2010-02-16 02:24:18 | [diff] [blame] | 492 | #if defined(OS_WIN) |
| 493 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserMove, OnBrowserMoved) |
| 494 | #endif |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 495 | IPC_MESSAGE_HANDLER(AutomationMsg_SetContentSetting, SetContentSetting) |
[email protected] | 566a0f76 | 2010-03-10 04:14:57 | [diff] [blame] | 496 | #if defined(OS_CHROMEOS) |
| 497 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoginWithUserAndPass, |
| 498 | LoginWithUserAndPass) |
| 499 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 500 | IPC_END_MESSAGE_MAP() |
| 501 | } |
| 502 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 503 | void AutomationProvider::ActivateTab(int handle, int at_index, int* status) { |
| 504 | *status = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 505 | if (browser_tracker_->ContainsHandle(handle) && at_index > -1) { |
| 506 | Browser* browser = browser_tracker_->GetResource(handle); |
| 507 | if (at_index >= 0 && at_index < browser->tab_count()) { |
| 508 | browser->SelectTabContentsAt(at_index, true); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 509 | *status = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 510 | } |
| 511 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 512 | } |
| 513 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 514 | void AutomationProvider::AppendTab(int handle, const GURL& url, |
| 515 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 516 | int append_tab_response = -1; // -1 is the error code |
| 517 | NotificationObserver* observer = NULL; |
| 518 | |
| 519 | if (browser_tracker_->ContainsHandle(handle)) { |
| 520 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 521 | observer = AddTabStripObserver(browser, reply_message); |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 522 | TabContents* tab_contents = browser->AddTabWithURL(url, GURL(), |
| 523 | PageTransition::TYPED, |
[email protected] | 5a4940be | 2009-05-06 06:44:39 | [diff] [blame] | 524 | true, -1, false, NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 525 | if (tab_contents) { |
| 526 | append_tab_response = |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 527 | GetIndexForNavigationController(&tab_contents->controller(), browser); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | if (append_tab_response < 0) { |
| 532 | // The append tab failed. Remove the TabStripObserver |
| 533 | if (observer) { |
| 534 | RemoveTabStripObserver(observer); |
| 535 | delete observer; |
| 536 | } |
| 537 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 538 | AutomationMsg_AppendTab::WriteReplyParams(reply_message, |
| 539 | append_tab_response); |
| 540 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 544 | void AutomationProvider::NavigateToURL(int handle, const GURL& url, |
| 545 | IPC::Message* reply_message) { |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 546 | NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message); |
| 547 | } |
| 548 | |
| 549 | void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete( |
| 550 | int handle, const GURL& url, int number_of_navigations, |
| 551 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 552 | if (tab_tracker_->ContainsHandle(handle)) { |
| 553 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 554 | |
| 555 | // Simulate what a user would do. Activate the tab and then navigate. |
| 556 | // We could allow navigating in a background tab in future. |
| 557 | Browser* browser = FindAndActivateTab(tab); |
| 558 | |
| 559 | if (browser) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 560 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 561 | false); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 562 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 563 | // TODO(darin): avoid conversion to GURL |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 564 | browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 568 | |
| 569 | AutomationMsg_NavigateToURL::WriteReplyParams( |
| 570 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 571 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 572 | } |
[email protected] | 2949e90d | 2009-08-21 15:32:52 | [diff] [blame] | 573 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 574 | void AutomationProvider::NavigationAsync(int handle, const GURL& url, |
| 575 | bool* status) { |
| 576 | *status = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 577 | |
| 578 | if (tab_tracker_->ContainsHandle(handle)) { |
| 579 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 580 | |
| 581 | // Simulate what a user would do. Activate the tab and then navigate. |
| 582 | // We could allow navigating in a background tab in future. |
| 583 | Browser* browser = FindAndActivateTab(tab); |
| 584 | |
| 585 | if (browser) { |
| 586 | // Don't add any listener unless a callback mechanism is desired. |
| 587 | // TODO(vibhor): Do this if such a requirement arises in future. |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 588 | browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 589 | *status = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 590 | } |
| 591 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 592 | } |
| 593 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 594 | void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 595 | if (tab_tracker_->ContainsHandle(handle)) { |
| 596 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 597 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 598 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 599 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 600 | browser->GoBack(CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 601 | return; |
| 602 | } |
| 603 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 604 | |
| 605 | AutomationMsg_GoBack::WriteReplyParams( |
| 606 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 607 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 608 | } |
| 609 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 610 | void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 611 | if (tab_tracker_->ContainsHandle(handle)) { |
| 612 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 613 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 614 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 615 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 616 | browser->GoForward(CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 617 | return; |
| 618 | } |
| 619 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 620 | |
| 621 | AutomationMsg_GoForward::WriteReplyParams( |
| 622 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 623 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 624 | } |
| 625 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 626 | void AutomationProvider::Reload(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 627 | if (tab_tracker_->ContainsHandle(handle)) { |
| 628 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 629 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 630 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 631 | AddNavigationStatusListener(tab, reply_message, 1, false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 632 | browser->Reload(); |
| 633 | return; |
| 634 | } |
| 635 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 636 | |
| 637 | AutomationMsg_Reload::WriteReplyParams( |
| 638 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 639 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 640 | } |
| 641 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 642 | void AutomationProvider::SetAuth(int tab_handle, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 643 | const std::wstring& username, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 644 | const std::wstring& password, |
| 645 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 646 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 647 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 648 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 649 | |
| 650 | if (iter != login_handler_map_.end()) { |
| 651 | // If auth is needed again after this, assume login has failed. This is |
| 652 | // not strictly correct, because a navigation can require both proxy and |
| 653 | // server auth, but it should be OK for now. |
| 654 | LoginHandler* handler = iter->second; |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 655 | AddNavigationStatusListener(tab, reply_message, 1, false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 656 | handler->SetAuth(username, password); |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 657 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 658 | } |
| 659 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 660 | |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 661 | AutomationMsg_SetAuth::WriteReplyParams( |
| 662 | reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); |
| 663 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 664 | } |
| 665 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 666 | void AutomationProvider::CancelAuth(int tab_handle, |
| 667 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 668 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 669 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 670 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 671 | |
| 672 | if (iter != login_handler_map_.end()) { |
| 673 | // If auth is needed again after this, something is screwy. |
| 674 | LoginHandler* handler = iter->second; |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 675 | AddNavigationStatusListener(tab, reply_message, 1, false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 676 | handler->CancelAuth(); |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 677 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 678 | } |
| 679 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 680 | |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 681 | AutomationMsg_CancelAuth::WriteReplyParams( |
| 682 | reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); |
| 683 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 684 | } |
| 685 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 686 | void AutomationProvider::NeedsAuth(int tab_handle, bool* needs_auth) { |
| 687 | *needs_auth = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 688 | |
| 689 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 690 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 691 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 692 | |
| 693 | if (iter != login_handler_map_.end()) { |
| 694 | // The LoginHandler will be in our map IFF the tab needs auth. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 695 | *needs_auth = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 696 | } |
| 697 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 698 | } |
| 699 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 700 | void AutomationProvider::GetRedirectsFrom(int tab_handle, |
| 701 | const GURL& source_url, |
| 702 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 703 | DCHECK(!redirect_query_) << "Can only handle one redirect query at once."; |
| 704 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 705 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 706 | HistoryService* history_service = |
| 707 | tab->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 708 | |
| 709 | DCHECK(history_service) << "Tab " << tab_handle << "'s profile " << |
| 710 | "has no history service"; |
| 711 | if (history_service) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 712 | DCHECK(reply_message_ == NULL); |
| 713 | reply_message_ = reply_message; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 714 | // Schedule a history query for redirects. The response will be sent |
| 715 | // asynchronously from the callback the history system uses to notify us |
| 716 | // that it's done: OnRedirectQueryComplete. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 717 | redirect_query_ = history_service->QueryRedirectsFrom( |
| 718 | source_url, &consumer_, |
| 719 | NewCallback(this, &AutomationProvider::OnRedirectQueryComplete)); |
| 720 | return; // Response will be sent when query completes. |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | // Send failure response. |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 725 | std::vector<GURL> empty; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 726 | AutomationMsg_RedirectsFrom::WriteReplyParams(reply_message, false, empty); |
| 727 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 728 | } |
| 729 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 730 | void AutomationProvider::GetActiveTabIndex(int handle, int* active_tab_index) { |
| 731 | *active_tab_index = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 732 | if (browser_tracker_->ContainsHandle(handle)) { |
| 733 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 734 | *active_tab_index = browser->selected_index(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 735 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 736 | } |
| 737 | |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 738 | void AutomationProvider::GetBrowserLocale(string16* locale) { |
| 739 | DCHECK(g_browser_process); |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 740 | *locale = ASCIIToUTF16(g_browser_process->GetApplicationLocale()); |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 741 | } |
| 742 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 743 | void AutomationProvider::GetBrowserWindowCount(int* window_count) { |
| 744 | *window_count = static_cast<int>(BrowserList::size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 747 | void AutomationProvider::GetNormalBrowserWindowCount(int* window_count) { |
| 748 | *window_count = static_cast<int>( |
| 749 | BrowserList::GetBrowserCountForType(profile_, Browser::TYPE_NORMAL)); |
| 750 | } |
| 751 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 752 | void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, |
| 753 | int* dialog_button) { |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 754 | AppModalDialog* dialog_delegate = |
| 755 | Singleton<AppModalDialogQueue>()->active_dialog(); |
[email protected] | b3a7033 | 2009-02-25 02:40:50 | [diff] [blame] | 756 | *showing_dialog = (dialog_delegate != NULL); |
| 757 | if (*showing_dialog) |
| 758 | *dialog_button = dialog_delegate->GetDialogButtons(); |
| 759 | else |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 760 | *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 761 | } |
| 762 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 763 | void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { |
| 764 | *success = false; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 765 | |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 766 | AppModalDialog* dialog_delegate = |
| 767 | Singleton<AppModalDialogQueue>()->active_dialog(); |
[email protected] | b3a7033 | 2009-02-25 02:40:50 | [diff] [blame] | 768 | if (dialog_delegate && |
| 769 | (dialog_delegate->GetDialogButtons() & button) == button) { |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 770 | if ((button & MessageBoxFlags::DIALOGBUTTON_OK) == |
| 771 | MessageBoxFlags::DIALOGBUTTON_OK) { |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 772 | dialog_delegate->AcceptWindow(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 773 | *success = true; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 774 | } |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 775 | if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) == |
| 776 | MessageBoxFlags::DIALOGBUTTON_CANCEL) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 777 | DCHECK(!*success) << "invalid param, OK and CANCEL specified"; |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 778 | dialog_delegate->CancelWindow(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 779 | *success = true; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 780 | } |
| 781 | } |
[email protected] | c274acc | 2008-11-11 20:13:44 | [diff] [blame] | 782 | } |
| 783 | |
[email protected] | fedaa7d | 2010-01-26 20:34:57 | [diff] [blame] | 784 | void AutomationProvider::ShutdownSessionService(int handle, bool* result) { |
| 785 | if (browser_tracker_->ContainsHandle(handle)) { |
| 786 | Browser* browser = browser_tracker_->GetResource(handle); |
| 787 | browser->profile()->ShutdownSessionService(); |
| 788 | *result = true; |
| 789 | } else { |
| 790 | *result = false; |
| 791 | } |
| 792 | } |
| 793 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 794 | void AutomationProvider::GetBrowserWindow(int index, int* handle) { |
| 795 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 796 | if (index >= 0) { |
| 797 | BrowserList::const_iterator iter = BrowserList::begin(); |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 798 | for (; (iter != BrowserList::end()) && (index > 0); ++iter, --index); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 799 | if (iter != BrowserList::end()) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 800 | *handle = browser_tracker_->Add(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 801 | } |
| 802 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 803 | } |
| 804 | |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 805 | void AutomationProvider::FindNormalBrowserWindow(int* handle) { |
| 806 | *handle = 0; |
| 807 | Browser* browser = BrowserList::FindBrowserWithType(profile_, |
| 808 | Browser::TYPE_NORMAL); |
| 809 | if (browser) |
| 810 | *handle = browser_tracker_->Add(browser); |
| 811 | } |
| 812 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 813 | void AutomationProvider::GetLastActiveBrowserWindow(int* handle) { |
| 814 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 815 | Browser* browser = BrowserList::GetLastActive(); |
| 816 | if (browser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 817 | *handle = browser_tracker_->Add(browser); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 818 | } |
| 819 | |
[email protected] | b2aa3ed7 | 2010-02-01 18:37:14 | [diff] [blame] | 820 | #if defined(OS_POSIX) |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame] | 821 | // TODO(estade): use this implementation for all platforms? |
| 822 | void AutomationProvider::GetActiveWindow(int* handle) { |
| 823 | gfx::NativeWindow window = |
| 824 | BrowserList::GetLastActive()->window()->GetNativeHandle(); |
| 825 | *handle = window_tracker_->Add(window); |
| 826 | } |
| 827 | #endif |
| 828 | |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 829 | void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command, |
| 830 | bool* success) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 831 | *success = false; |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 832 | if (browser_tracker_->ContainsHandle(handle)) { |
| 833 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 834 | if (browser->command_updater()->SupportsCommand(command) && |
| 835 | browser->command_updater()->IsCommandEnabled(command)) { |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 836 | browser->ExecuteCommand(command); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 837 | *success = true; |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 838 | } |
| 839 | } |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 840 | } |
| 841 | |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 842 | void AutomationProvider::ExecuteBrowserCommand( |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 843 | int handle, int command, IPC::Message* reply_message) { |
[email protected] | 12887da7 | 2009-09-16 19:15:53 | [diff] [blame] | 844 | // List of commands which just finish synchronously and don't require |
| 845 | // setting up an observer. |
| 846 | static const int kSynchronousCommands[] = { |
| 847 | IDC_HOME, |
| 848 | IDC_SELECT_NEXT_TAB, |
| 849 | IDC_SELECT_PREVIOUS_TAB, |
| 850 | IDC_SHOW_DOWNLOADS, |
| 851 | IDC_SHOW_HISTORY, |
| 852 | }; |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 853 | if (browser_tracker_->ContainsHandle(handle)) { |
| 854 | Browser* browser = browser_tracker_->GetResource(handle); |
| 855 | if (browser->command_updater()->SupportsCommand(command) && |
| 856 | browser->command_updater()->IsCommandEnabled(command)) { |
[email protected] | 12887da7 | 2009-09-16 19:15:53 | [diff] [blame] | 857 | // First check if we can handle the command without using an observer. |
| 858 | for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { |
| 859 | if (command == kSynchronousCommands[i]) { |
| 860 | browser->ExecuteCommand(command); |
| 861 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, |
| 862 | true); |
| 863 | Send(reply_message); |
| 864 | return; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | // Use an observer if we have one, otherwise fail. |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 869 | if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( |
| 870 | this, browser, command, reply_message)) { |
[email protected] | 4e41709d | 2009-04-08 00:04:27 | [diff] [blame] | 871 | browser->ExecuteCommand(command); |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 872 | return; |
| 873 | } |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 874 | } |
| 875 | } |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 876 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 877 | Send(reply_message); |
| 878 | } |
| 879 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 880 | // This task just adds another task to the event queue. This is useful if |
| 881 | // you want to ensure that any tasks added to the event queue after this one |
| 882 | // have already been processed by the time |task| is run. |
| 883 | class InvokeTaskLaterTask : public Task { |
| 884 | public: |
| 885 | explicit InvokeTaskLaterTask(Task* task) : task_(task) {} |
| 886 | virtual ~InvokeTaskLaterTask() {} |
| 887 | |
| 888 | virtual void Run() { |
| 889 | MessageLoop::current()->PostTask(FROM_HERE, task_); |
| 890 | } |
| 891 | |
| 892 | private: |
| 893 | Task* task_; |
| 894 | |
| 895 | DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); |
| 896 | }; |
| 897 | |
[email protected] | b2aa3ed7 | 2010-02-01 18:37:14 | [diff] [blame] | 898 | #if !defined(OS_MACOSX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 899 | void AutomationProvider::WindowSimulateClick(const IPC::Message& message, |
| 900 | int handle, |
[email protected] | d1a5941e | 2009-08-13 23:34:24 | [diff] [blame] | 901 | const gfx::Point& click, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 902 | int flags) { |
[email protected] | b410bc3 | 2009-08-14 01:11:14 | [diff] [blame] | 903 | if (window_tracker_->ContainsHandle(handle)) { |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 904 | ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(), |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 905 | new ClickTask(flags)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
[email protected] | 60507b1 | 2009-11-02 23:51:35 | [diff] [blame] | 909 | void AutomationProvider::WindowSimulateMouseMove(const IPC::Message& message, |
| 910 | int handle, |
| 911 | const gfx::Point& location) { |
| 912 | if (window_tracker_->ContainsHandle(handle)) |
| 913 | ui_controls::SendMouseMove(location.x(), location.y()); |
| 914 | } |
| 915 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 916 | void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message, |
| 917 | int handle, |
[email protected] | bc1407f | 2009-09-29 00:33:35 | [diff] [blame] | 918 | int key, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 919 | int flags) { |
[email protected] | b410bc3 | 2009-08-14 01:11:14 | [diff] [blame] | 920 | if (!window_tracker_->ContainsHandle(handle)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 921 | return; |
| 922 | |
[email protected] | b410bc3 | 2009-08-14 01:11:14 | [diff] [blame] | 923 | gfx::NativeWindow window = window_tracker_->GetResource(handle); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 924 | // The key event is sent to whatever window is active. |
[email protected] | bc1407f | 2009-09-29 00:33:35 | [diff] [blame] | 925 | ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key), |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 926 | ((flags & views::Event::EF_CONTROL_DOWN) == |
| 927 | views::Event::EF_CONTROL_DOWN), |
| 928 | ((flags & views::Event::EF_SHIFT_DOWN) == |
| 929 | views::Event::EF_SHIFT_DOWN), |
| 930 | ((flags & views::Event::EF_ALT_DOWN) == |
| 931 | views::Event::EF_ALT_DOWN)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 932 | } |
[email protected] | b2aa3ed7 | 2010-02-01 18:37:14 | [diff] [blame] | 933 | #endif // !defined(OS_MACOSX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 934 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 935 | void AutomationProvider::IsWindowActive(int handle, bool* success, |
| 936 | bool* is_active) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 937 | if (window_tracker_->ContainsHandle(handle)) { |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 938 | *is_active = |
| 939 | platform_util::IsWindowActive(window_tracker_->GetResource(handle)); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 940 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 941 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 942 | *success = false; |
| 943 | *is_active = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 947 | void AutomationProvider::GetTabCount(int handle, int* tab_count) { |
| 948 | *tab_count = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 949 | |
| 950 | if (browser_tracker_->ContainsHandle(handle)) { |
| 951 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 952 | *tab_count = browser->tab_count(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 953 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 954 | } |
| 955 | |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 956 | void AutomationProvider::GetType(int handle, int* type_as_int) { |
| 957 | *type_as_int = -1; // -1 is the error code |
| 958 | |
| 959 | if (browser_tracker_->ContainsHandle(handle)) { |
| 960 | Browser* browser = browser_tracker_->GetResource(handle); |
| 961 | *type_as_int = static_cast<int>(browser->type()); |
| 962 | } |
| 963 | } |
| 964 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 965 | void AutomationProvider::GetTab(int win_handle, int tab_index, |
| 966 | int* tab_handle) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 967 | *tab_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 968 | if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) { |
| 969 | Browser* browser = browser_tracker_->GetResource(win_handle); |
| 970 | if (tab_index < browser->tab_count()) { |
| 971 | TabContents* tab_contents = |
| 972 | browser->GetTabContentsAt(tab_index); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 973 | *tab_handle = tab_tracker_->Add(&tab_contents->controller()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 974 | } |
| 975 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 976 | } |
| 977 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 978 | void AutomationProvider::GetTabTitle(int handle, int* title_string_size, |
| 979 | std::wstring* title) { |
| 980 | *title_string_size = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 981 | if (tab_tracker_->ContainsHandle(handle)) { |
| 982 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | c100dbd | 2009-04-29 23:44:36 | [diff] [blame] | 983 | NavigationEntry* entry = tab->GetActiveEntry(); |
| 984 | if (entry != NULL) { |
| 985 | *title = UTF16ToWideHack(entry->title()); |
| 986 | } else { |
| 987 | *title = std::wstring(); |
| 988 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 989 | *title_string_size = static_cast<int>(title->size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 990 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 991 | } |
| 992 | |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 993 | void AutomationProvider::GetTabIndex(int handle, int* tabstrip_index) { |
| 994 | *tabstrip_index = -1; // -1 is the error code |
| 995 | |
| 996 | if (tab_tracker_->ContainsHandle(handle)) { |
| 997 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 998 | Browser* browser = Browser::GetBrowserForController(tab, NULL); |
[email protected] | 902cdf77 | 2009-05-06 15:08:12 | [diff] [blame] | 999 | *tabstrip_index = browser->tabstrip_model()->GetIndexOfController(tab); |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1003 | void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) { |
| 1004 | if (window_tracker_->ContainsHandle(handle)) { |
| 1005 | window_tracker_->Remove(window_tracker_->GetResource(handle)); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | void AutomationProvider::OnChannelError() { |
[email protected] | 2947cdcd | 2009-12-03 21:05:16 | [diff] [blame] | 1010 | LOG(INFO) << "AutomationProxy went away, shutting down app."; |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 1011 | AutomationProviderList::GetInstance()->RemoveProvider(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | // TODO(brettw) change this to accept GURLs when history supports it |
| 1015 | void AutomationProvider::OnRedirectQueryComplete( |
| 1016 | HistoryService::Handle request_handle, |
[email protected] | 3e377c5 | 2009-08-06 07:46:37 | [diff] [blame] | 1017 | GURL from_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1018 | bool success, |
[email protected] | 379c2b1 | 2009-07-01 21:50:33 | [diff] [blame] | 1019 | history::RedirectList* redirects) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1020 | DCHECK(request_handle == redirect_query_); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1021 | DCHECK(reply_message_ != NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1022 | |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1023 | std::vector<GURL> redirects_gurl; |
[email protected] | 0bc2448 | 2010-03-05 00:33:10 | [diff] [blame] | 1024 | reply_message_->WriteBool(success); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1025 | if (success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1026 | for (size_t i = 0; i < redirects->size(); i++) |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1027 | redirects_gurl.push_back(redirects->at(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1028 | } |
| 1029 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1030 | IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1031 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1032 | Send(reply_message_); |
[email protected] | 5a3b914 | 2009-08-28 21:03:17 | [diff] [blame] | 1033 | redirect_query_ = NULL; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1034 | reply_message_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | bool AutomationProvider::Send(IPC::Message* msg) { |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 1038 | DCHECK(channel_.get()); |
| 1039 | return channel_->Send(msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | Browser* AutomationProvider::FindAndActivateTab( |
| 1043 | NavigationController* controller) { |
| 1044 | int tab_index; |
| 1045 | Browser* browser = Browser::GetBrowserForController(controller, &tab_index); |
| 1046 | if (browser) |
| 1047 | browser->SelectTabContentsAt(tab_index, true); |
| 1048 | |
| 1049 | return browser; |
| 1050 | } |
| 1051 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1052 | void AutomationProvider::GetCookies(const GURL& url, int handle, |
| 1053 | int* value_size, |
| 1054 | std::string* value) { |
| 1055 | *value_size = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1056 | if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 1057 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1058 | |
| 1059 | // Since we are running on the UI thread don't call GetURLRequestContext(). |
[email protected] | 70daf0b | 2010-03-02 19:13:00 | [diff] [blame] | 1060 | scoped_refptr<URLRequestContextGetter> request_context = |
| 1061 | tab->tab_contents()->request_context(); |
| 1062 | if (!request_context.get()) |
| 1063 | request_context = tab->profile()->GetRequestContext(); |
| 1064 | |
| 1065 | net::CookieStore* cookie_store = request_context->GetCookieStore(); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1066 | |
| 1067 | *value = cookie_store->GetCookies(url); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1068 | *value_size = static_cast<int>(value->size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1069 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1070 | } |
| 1071 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1072 | void AutomationProvider::SetCookie(const GURL& url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1073 | const std::string value, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1074 | int handle, |
| 1075 | int* response_value) { |
| 1076 | *response_value = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1077 | |
| 1078 | if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 1079 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1080 | |
[email protected] | dfa46e5f | 2009-11-17 18:48:43 | [diff] [blame] | 1081 | scoped_refptr<URLRequestContextGetter> request_context = |
| 1082 | tab->tab_contents()->request_context(); |
| 1083 | if (!request_context.get()) |
| 1084 | request_context = tab->profile()->GetRequestContext(); |
| 1085 | |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1086 | // Since we are running on the UI thread don't call GetURLRequestContext(). |
| 1087 | scoped_refptr<net::CookieStore> cookie_store = |
[email protected] | dfa46e5f | 2009-11-17 18:48:43 | [diff] [blame] | 1088 | request_context->GetCookieStore(); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1089 | |
| 1090 | if (cookie_store->SetCookie(url, value)) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1091 | *response_value = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1092 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1093 | } |
| 1094 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1095 | void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { |
| 1096 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1097 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1098 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1099 | // Return what the user would see in the location bar. |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1100 | *url = tab->GetActiveEntry()->virtual_url(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1101 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1102 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1103 | } |
| 1104 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1105 | void AutomationProvider::GetTabProcessID(int handle, int* process_id) { |
| 1106 | *process_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1107 | |
| 1108 | if (tab_tracker_->ContainsHandle(handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1109 | *process_id = 0; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1110 | TabContents* tab_contents = |
| 1111 | tab_tracker_->GetResource(handle)->tab_contents(); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1112 | RenderProcessHost* rph = tab_contents->GetRenderProcessHost(); |
| 1113 | if (rph) |
| 1114 | *process_id = base::GetProcId(rph->GetHandle()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1115 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | void AutomationProvider::ApplyAccelerator(int handle, int id) { |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 1119 | NOTREACHED() << "This function has been deprecated. " |
| 1120 | << "Please use ExecuteBrowserCommandAsync instead."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1121 | } |
| 1122 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1123 | void AutomationProvider::ExecuteJavascript(int handle, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1124 | const std::wstring& frame_xpath, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1125 | const std::wstring& script, |
| 1126 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1127 | bool succeeded = false; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1128 | TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
| 1129 | if (tab_contents) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1130 | // Set the routing id of this message with the controller. |
| 1131 | // This routing id needs to be remembered for the reverse |
| 1132 | // communication while sending back the response of |
| 1133 | // this javascript execution. |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 1134 | std::wstring set_automation_id; |
| 1135 | SStringPrintf(&set_automation_id, |
| 1136 | L"window.domAutomationController.setAutomationId(%d);", |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1137 | reply_message->routing_id()); |
| 1138 | |
| 1139 | DCHECK(reply_message_ == NULL); |
| 1140 | reply_message_ = reply_message; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1141 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1142 | tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 1143 | frame_xpath, set_automation_id); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1144 | tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
[email protected] | 1f5af444 | 2008-09-25 22:11:06 | [diff] [blame] | 1145 | frame_xpath, script); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1146 | succeeded = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | if (!succeeded) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1150 | AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); |
| 1151 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1155 | void AutomationProvider::GetShelfVisibility(int handle, bool* visible) { |
| 1156 | *visible = false; |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1157 | |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1158 | if (browser_tracker_->ContainsHandle(handle)) { |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1159 | #if defined(OS_CHROMEOS) |
| 1160 | // Chromium OS shows FileBrowse ui rather than download shelf. So we |
| 1161 | // enumerate all browsers and look for a chrome://filebrowse... pop up. |
| 1162 | for (BrowserList::const_iterator it = BrowserList::begin(); |
| 1163 | it != BrowserList::end(); ++it) { |
| 1164 | if ((*it)->type() == Browser::TYPE_POPUP) { |
| 1165 | const GURL& url = |
| 1166 | (*it)->GetTabContentsAt((*it)->selected_index())->GetURL(); |
| 1167 | |
| 1168 | if (url.SchemeIs(chrome::kChromeUIScheme) && |
| 1169 | url.host() == chrome::kChromeUIFileBrowseHost) { |
| 1170 | *visible = true; |
| 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | #else |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1176 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1177 | if (browser) { |
| 1178 | *visible = browser->window()->IsDownloadShelfVisible(); |
| 1179 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1180 | #endif |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1181 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1182 | } |
| 1183 | |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1184 | void AutomationProvider::SetShelfVisibility(int handle, bool visible) { |
| 1185 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1186 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1187 | if (browser) { |
| 1188 | if (visible) |
| 1189 | browser->window()->GetDownloadShelf()->Show(); |
| 1190 | else |
| 1191 | browser->window()->GetDownloadShelf()->Close(); |
| 1192 | } |
| 1193 | } |
| 1194 | } |
| 1195 | |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 1196 | void AutomationProvider::IsFullscreen(int handle, bool* visible) { |
| 1197 | *visible = false; |
| 1198 | |
| 1199 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1200 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1201 | if (browser) |
| 1202 | *visible = browser->window()->IsFullscreen(); |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | void AutomationProvider::GetFullscreenBubbleVisibility(int handle, |
| 1207 | bool* visible) { |
| 1208 | *visible = false; |
| 1209 | |
| 1210 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1211 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1212 | if (browser) |
| 1213 | *visible = browser->window()->IsFullscreenBubbleVisible(); |
| 1214 | } |
| 1215 | } |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1216 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1217 | void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) { |
| 1218 | *count = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1219 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1220 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 1221 | TabContents* tab_contents = nav_controller->tab_contents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1222 | if (tab_contents) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1223 | *count = static_cast<int>(tab_contents->child_windows_.size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1224 | } |
| 1225 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1226 | } |
| 1227 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1228 | void AutomationProvider::HandleFindInPageRequest( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1229 | int handle, const std::wstring& find_request, |
| 1230 | int forward, int match_case, int* active_ordinal, int* matches_found) { |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 1231 | NOTREACHED() << "This function has been deprecated." |
| 1232 | << "Please use HandleFindRequest instead."; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1233 | *matches_found = -1; |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 1234 | return; |
| 1235 | } |
| 1236 | |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 1237 | void AutomationProvider::HandleFindRequest( |
| 1238 | int handle, |
| 1239 | const AutomationMsg_Find_Params& params, |
| 1240 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1241 | if (!tab_tracker_->ContainsHandle(handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1242 | AutomationMsg_FindInPage::WriteReplyParams(reply_message, -1, -1); |
| 1243 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1244 | return; |
| 1245 | } |
| 1246 | |
| 1247 | NavigationController* nav = tab_tracker_->GetResource(handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 1248 | TabContents* tab_contents = nav->tab_contents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1249 | |
| 1250 | find_in_page_observer_.reset(new |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1251 | FindInPageNotificationObserver(this, tab_contents, reply_message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1252 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1253 | tab_contents->set_current_find_request_id( |
| 1254 | FindInPageNotificationObserver::kFindInPageRequestId); |
| 1255 | tab_contents->render_view_host()->StartFinding( |
| 1256 | FindInPageNotificationObserver::kFindInPageRequestId, |
| 1257 | params.search_string, params.forward, params.match_case, |
| 1258 | params.find_next); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1259 | } |
| 1260 | |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 1261 | void AutomationProvider::HandleOpenFindInPageRequest( |
| 1262 | const IPC::Message& message, int handle) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1263 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1264 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1265 | browser->FindInPage(false, false); |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1269 | void AutomationProvider::GetFindWindowVisibility(int handle, bool* visible) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1270 | *visible = false; |
[email protected] | 855c014 | 2009-09-28 22:35:24 | [diff] [blame] | 1271 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1272 | if (browser) { |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1273 | FindBarTesting* find_bar = |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1274 | browser->GetFindBarController()->find_bar()->GetFindBarTesting(); |
[email protected] | 855c014 | 2009-09-28 22:35:24 | [diff] [blame] | 1275 | find_bar->GetFindBarWindowInfo(NULL, visible); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1276 | } |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1277 | } |
| 1278 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1279 | void AutomationProvider::HandleFindWindowLocationRequest(int handle, int* x, |
| 1280 | int* y) { |
[email protected] | 9e0534b | 2008-10-21 15:03:01 | [diff] [blame] | 1281 | gfx::Point position(0, 0); |
| 1282 | bool visible = false; |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1283 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1284 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1285 | FindBarTesting* find_bar = |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1286 | browser->GetFindBarController()->find_bar()->GetFindBarTesting(); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1287 | find_bar->GetFindBarWindowInfo(&position, &visible); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1288 | } |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1289 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1290 | *x = position.x(); |
| 1291 | *y = position.y(); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1292 | } |
| 1293 | |
[email protected] | c324072 | 2010-03-05 21:52:58 | [diff] [blame] | 1294 | void AutomationProvider::GetBookmarkBarVisibility(int handle, |
| 1295 | bool* visible, |
| 1296 | bool* animating) { |
| 1297 | *visible = false; |
| 1298 | *animating = false; |
| 1299 | |
| 1300 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1301 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1302 | if (browser) { |
| 1303 | *visible = browser->window()->IsBookmarkBarVisible(); |
| 1304 | *animating = browser->window()->IsBookmarkBarAnimating(); |
| 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 1309 | void AutomationProvider::GetBookmarksAsJSON(int handle, |
| 1310 | std::string* bookmarks_as_json, |
| 1311 | bool *success) { |
| 1312 | *success = false; |
| 1313 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1314 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1315 | if (browser) { |
| 1316 | if (!browser->profile()->GetBookmarkModel()->IsLoaded()) { |
| 1317 | return; |
| 1318 | } |
| 1319 | scoped_refptr<BookmarkStorage> storage = new BookmarkStorage( |
| 1320 | browser->profile(), |
| 1321 | browser->profile()->GetBookmarkModel()); |
| 1322 | *success = storage->SerializeData(bookmarks_as_json); |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | void AutomationProvider::WaitForBookmarkModelToLoad( |
| 1328 | int handle, |
| 1329 | IPC::Message* reply_message) { |
| 1330 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1331 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1332 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1333 | if (model->IsLoaded()) { |
| 1334 | AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( |
| 1335 | reply_message, true); |
| 1336 | Send(reply_message); |
| 1337 | } else { |
| 1338 | // The observer will delete itself when done. |
| 1339 | new AutomationProviderBookmarkModelObserver(this, reply_message, |
| 1340 | model); |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | void AutomationProvider::AddBookmarkGroup(int handle, |
| 1346 | int64 parent_id, int index, |
| 1347 | std::wstring title, |
| 1348 | bool* success) { |
| 1349 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1350 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1351 | if (browser) { |
| 1352 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1353 | if (!model->IsLoaded()) { |
| 1354 | *success = false; |
| 1355 | return; |
| 1356 | } |
| 1357 | const BookmarkNode* parent = model->GetNodeByID(parent_id); |
| 1358 | DCHECK(parent); |
| 1359 | if (parent) { |
| 1360 | const BookmarkNode* child = model->AddGroup(parent, index, |
| 1361 | WideToUTF16(title)); |
| 1362 | DCHECK(child); |
| 1363 | if (child) |
| 1364 | *success = true; |
| 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | *success = false; |
| 1369 | } |
| 1370 | |
| 1371 | void AutomationProvider::AddBookmarkURL(int handle, |
| 1372 | int64 parent_id, int index, |
| 1373 | std::wstring title, const GURL& url, |
| 1374 | bool* success) { |
| 1375 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1376 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1377 | if (browser) { |
| 1378 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1379 | if (!model->IsLoaded()) { |
| 1380 | *success = false; |
| 1381 | return; |
| 1382 | } |
| 1383 | const BookmarkNode* parent = model->GetNodeByID(parent_id); |
| 1384 | DCHECK(parent); |
| 1385 | if (parent) { |
| 1386 | const BookmarkNode* child = model->AddURL(parent, index, |
| 1387 | WideToUTF16(title), url); |
| 1388 | DCHECK(child); |
| 1389 | if (child) |
| 1390 | *success = true; |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | *success = false; |
| 1395 | } |
| 1396 | |
| 1397 | void AutomationProvider::ReparentBookmark(int handle, |
| 1398 | int64 id, int64 new_parent_id, |
| 1399 | int index, |
| 1400 | bool* success) { |
| 1401 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1402 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1403 | if (browser) { |
| 1404 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1405 | if (!model->IsLoaded()) { |
| 1406 | *success = false; |
| 1407 | return; |
| 1408 | } |
| 1409 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1410 | DCHECK(node); |
| 1411 | const BookmarkNode* new_parent = model->GetNodeByID(new_parent_id); |
| 1412 | DCHECK(new_parent); |
| 1413 | if (node && new_parent) { |
| 1414 | model->Move(node, new_parent, index); |
| 1415 | *success = true; |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | *success = false; |
| 1420 | } |
| 1421 | |
| 1422 | void AutomationProvider::SetBookmarkTitle(int handle, |
| 1423 | int64 id, std::wstring title, |
| 1424 | bool* success) { |
| 1425 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1426 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1427 | if (browser) { |
| 1428 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1429 | if (!model->IsLoaded()) { |
| 1430 | *success = false; |
| 1431 | return; |
| 1432 | } |
| 1433 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1434 | DCHECK(node); |
| 1435 | if (node) { |
| 1436 | model->SetTitle(node, WideToUTF16(title)); |
| 1437 | *success = true; |
| 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | *success = false; |
| 1442 | } |
| 1443 | |
| 1444 | void AutomationProvider::SetBookmarkURL(int handle, |
| 1445 | int64 id, const GURL& url, |
| 1446 | bool* success) { |
| 1447 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1448 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1449 | if (browser) { |
| 1450 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1451 | if (!model->IsLoaded()) { |
| 1452 | *success = false; |
| 1453 | return; |
| 1454 | } |
| 1455 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1456 | DCHECK(node); |
| 1457 | if (node) { |
| 1458 | model->SetURL(node, url); |
| 1459 | *success = true; |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | *success = false; |
| 1464 | } |
| 1465 | |
| 1466 | void AutomationProvider::RemoveBookmark(int handle, |
| 1467 | int64 id, |
| 1468 | bool* success) { |
| 1469 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1470 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1471 | if (browser) { |
| 1472 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1473 | if (!model->IsLoaded()) { |
| 1474 | *success = false; |
| 1475 | return; |
| 1476 | } |
| 1477 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1478 | DCHECK(node); |
| 1479 | if (node) { |
| 1480 | const BookmarkNode* parent = node->GetParent(); |
| 1481 | DCHECK(parent); |
| 1482 | model->Remove(parent, parent->IndexOfChild(node)); |
| 1483 | *success = true; |
| 1484 | } |
| 1485 | } |
| 1486 | } |
| 1487 | *success = false; |
| 1488 | } |
| 1489 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1490 | void AutomationProvider::HandleInspectElementRequest( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1491 | int handle, int x, int y, IPC::Message* reply_message) { |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1492 | TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
| 1493 | if (tab_contents) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1494 | DCHECK(reply_message_ == NULL); |
| 1495 | reply_message_ = reply_message; |
| 1496 | |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 1497 | DevToolsManager::GetInstance()->InspectElement( |
| 1498 | tab_contents->render_view_host(), x, y); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1499 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1500 | AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); |
| 1501 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void AutomationProvider::ReceivedInspectElementResponse(int num_resources) { |
[email protected] | 396c3b3 | 2009-03-12 22:26:09 | [diff] [blame] | 1506 | if (reply_message_) { |
| 1507 | AutomationMsg_InspectElement::WriteReplyParams(reply_message_, |
| 1508 | num_resources); |
| 1509 | Send(reply_message_); |
| 1510 | reply_message_ = NULL; |
| 1511 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1512 | } |
| 1513 | |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1514 | class SetProxyConfigTask : public Task { |
| 1515 | public: |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1516 | SetProxyConfigTask(URLRequestContextGetter* request_context_getter, |
| 1517 | const std::string& new_proxy_config) |
| 1518 | : request_context_getter_(request_context_getter), proxy_config_(new_proxy_config) {} |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1519 | virtual void Run() { |
| 1520 | // First, deserialize the JSON string. If this fails, log and bail. |
| 1521 | JSONStringValueSerializer deserializer(proxy_config_); |
| 1522 | std::string error_message; |
| 1523 | scoped_ptr<Value> root(deserializer.Deserialize(&error_message)); |
| 1524 | if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { |
| 1525 | DLOG(WARNING) << "Received bad JSON string for ProxyConfig: " |
| 1526 | << error_message; |
| 1527 | return; |
| 1528 | } |
| 1529 | |
| 1530 | scoped_ptr<DictionaryValue> dict( |
| 1531 | static_cast<DictionaryValue*>(root.release())); |
| 1532 | // Now put together a proxy configuration from the deserialized string. |
| 1533 | net::ProxyConfig pc; |
| 1534 | PopulateProxyConfig(*dict.get(), &pc); |
| 1535 | |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1536 | net::ProxyService* proxy_service = |
| 1537 | request_context_getter_->GetURLRequestContext()->proxy_service(); |
| 1538 | DCHECK(proxy_service); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1539 | scoped_ptr<net::ProxyConfigService> proxy_config_service( |
| 1540 | new net::ProxyConfigServiceFixed(pc)); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1541 | proxy_service->ResetConfigService(proxy_config_service.release()); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { |
| 1545 | DCHECK(pc); |
| 1546 | bool no_proxy = false; |
| 1547 | if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { |
| 1548 | // Make no changes to the ProxyConfig. |
| 1549 | return; |
| 1550 | } |
| 1551 | bool auto_config; |
| 1552 | if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1553 | pc->set_auto_detect(true); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1554 | } |
| 1555 | std::string pac_url; |
| 1556 | if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1557 | pc->set_pac_url(GURL(pac_url)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1558 | } |
| 1559 | std::string proxy_bypass_list; |
| 1560 | if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1561 | pc->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_list); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1562 | } |
| 1563 | std::string proxy_server; |
| 1564 | if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1565 | pc->proxy_rules().ParseFromString(proxy_server); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | private: |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1570 | scoped_refptr<URLRequestContextGetter> request_context_getter_; |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1571 | std::string proxy_config_; |
| 1572 | }; |
| 1573 | |
| 1574 | |
| 1575 | void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1576 | URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); |
| 1577 | if (!context_getter) { |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1578 | FilePath user_data_dir; |
| 1579 | PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 1580 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1581 | DCHECK(profile_manager); |
| 1582 | Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); |
| 1583 | DCHECK(profile); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1584 | context_getter = profile->GetRequestContext(); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1585 | } |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1586 | DCHECK(context_getter); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1587 | |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 1588 | ChromeThread::PostTask( |
| 1589 | ChromeThread::IO, FROM_HERE, |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1590 | new SetProxyConfigTask(context_getter, new_proxy_config)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1591 | } |
| 1592 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1593 | void AutomationProvider::GetDownloadDirectory( |
[email protected] | 1f733cf | 2009-09-30 20:46:33 | [diff] [blame] | 1594 | int handle, FilePath* download_directory) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1595 | DLOG(INFO) << "Handling download directory request"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1596 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1597 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1598 | DownloadManager* dlm = tab->profile()->GetDownloadManager(); |
| 1599 | DCHECK(dlm); |
[email protected] | 1f733cf | 2009-09-30 20:46:33 | [diff] [blame] | 1600 | *download_directory = dlm->download_path(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1601 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1602 | } |
| 1603 | |
[email protected] | 6a5670d2 | 2009-10-27 16:21:34 | [diff] [blame] | 1604 | void AutomationProvider::OpenNewBrowserWindow(bool show, |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 1605 | IPC::Message* reply_message) { |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 1606 | OpenNewBrowserWindowOfType(static_cast<int>(Browser::TYPE_NORMAL), show, |
| 1607 | reply_message); |
| 1608 | } |
| 1609 | |
| 1610 | void AutomationProvider::OpenNewBrowserWindowOfType( |
| 1611 | int type, bool show, IPC::Message* reply_message) { |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 1612 | new BrowserOpenedNotificationObserver(this, reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1613 | // We may have no current browser windows open so don't rely on |
| 1614 | // asking an existing browser to execute the IDC_NEWWINDOW command |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 1615 | Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_); |
| 1616 | browser->CreateBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1617 | browser->AddBlankTab(true); |
[email protected] | 3683cbb | 2009-04-09 21:46:15 | [diff] [blame] | 1618 | if (show) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1619 | browser->window()->Show(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1620 | } |
| 1621 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1622 | void AutomationProvider::GetWindowForBrowser(int browser_handle, |
| 1623 | bool* success, |
| 1624 | int* handle) { |
| 1625 | *success = false; |
| 1626 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1627 | |
| 1628 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1629 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 1630 | gfx::NativeWindow win = browser->window()->GetNativeHandle(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1631 | // Add() returns the existing handle for the resource if any. |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 1632 | *handle = window_tracker_->Add(win); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1633 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1634 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1635 | } |
| 1636 | |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 1637 | #if !defined(OS_MACOSX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1638 | void AutomationProvider::GetAutocompleteEditForBrowser( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1639 | int browser_handle, |
| 1640 | bool* success, |
| 1641 | int* autocomplete_edit_handle) { |
| 1642 | *success = false; |
| 1643 | *autocomplete_edit_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1644 | |
| 1645 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1646 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 1647 | LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 1648 | AutocompleteEditView* edit_view = loc_bar->location_entry(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1649 | // Add() returns the existing handle for the resource if any. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1650 | *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view); |
| 1651 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1652 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1653 | } |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 1654 | #endif // !defined(OS_MACOSX) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1655 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1656 | void AutomationProvider::ShowInterstitialPage(int tab_handle, |
| 1657 | const std::string& html_text, |
| 1658 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1659 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 1660 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 1661 | TabContents* tab_contents = controller->tab_contents(); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 1662 | |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 1663 | AddNavigationStatusListener(controller, reply_message, 1, false); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 1664 | AutomationInterstitialPage* interstitial = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1665 | new AutomationInterstitialPage(tab_contents, |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 1666 | GURL("about:interstitial"), |
| 1667 | html_text); |
| 1668 | interstitial->Show(); |
| 1669 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1670 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1671 | |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 1672 | AutomationMsg_ShowInterstitialPage::WriteReplyParams( |
| 1673 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1674 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1675 | } |
| 1676 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1677 | void AutomationProvider::HideInterstitialPage(int tab_handle, |
| 1678 | bool* success) { |
| 1679 | *success = false; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1680 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL); |
| 1681 | if (tab_contents && tab_contents->interstitial_page()) { |
| 1682 | tab_contents->interstitial_page()->DontProceed(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1683 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1684 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1685 | } |
| 1686 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1687 | void AutomationProvider::CloseTab(int tab_handle, |
| 1688 | bool wait_until_closed, |
| 1689 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1690 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 1691 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
| 1692 | int index; |
| 1693 | Browser* browser = Browser::GetBrowserForController(controller, &index); |
| 1694 | DCHECK(browser); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1695 | new TabClosedNotificationObserver(this, wait_until_closed, reply_message); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 1696 | browser->CloseContents(controller->tab_contents()); |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1697 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1698 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 1699 | |
| 1700 | AutomationMsg_CloseTab::WriteReplyParams(reply_message, false); |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 1701 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1702 | } |
| 1703 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1704 | void AutomationProvider::CloseBrowser(int browser_handle, |
| 1705 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1706 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1707 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1708 | new BrowserClosedNotificationObserver(browser, this, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1709 | reply_message); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1710 | browser->window()->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1711 | } else { |
| 1712 | NOTREACHED(); |
| 1713 | } |
| 1714 | } |
| 1715 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1716 | void AutomationProvider::CloseBrowserAsync(int browser_handle) { |
| 1717 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1718 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
| 1719 | browser->window()->Close(); |
| 1720 | } else { |
| 1721 | NOTREACHED(); |
| 1722 | } |
| 1723 | } |
| 1724 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1725 | void AutomationProvider::NavigateInExternalTab( |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 1726 | int handle, const GURL& url, const GURL& referrer, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1727 | AutomationMsg_NavigationResponseValues* status) { |
| 1728 | *status = AUTOMATION_MSG_NAVIGATION_ERROR; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1729 | |
| 1730 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1731 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 1732 | tab->LoadURL(url, referrer, PageTransition::TYPED); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1733 | *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1734 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1735 | } |
| 1736 | |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 1737 | void AutomationProvider::NavigateExternalTabAtIndex( |
| 1738 | int handle, int navigation_index, |
| 1739 | AutomationMsg_NavigationResponseValues* status) { |
| 1740 | *status = AUTOMATION_MSG_NAVIGATION_ERROR; |
| 1741 | |
| 1742 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1743 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1744 | tab->GoToIndex(navigation_index); |
| 1745 | *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; |
| 1746 | } |
| 1747 | } |
| 1748 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1749 | void AutomationProvider::WaitForTabToBeRestored(int tab_handle, |
| 1750 | IPC::Message* reply_message) { |
| 1751 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 1752 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 1753 | restore_tracker_.reset( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1754 | new NavigationControllerRestoredObserver(this, tab, reply_message)); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1755 | } |
| 1756 | } |
| 1757 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1758 | void AutomationProvider::GetSecurityState(int handle, bool* success, |
| 1759 | SecurityStyle* security_style, |
| 1760 | int* ssl_cert_status, |
| 1761 | int* mixed_content_status) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1762 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1763 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1764 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1765 | *success = true; |
| 1766 | *security_style = entry->ssl().security_style(); |
| 1767 | *ssl_cert_status = entry->ssl().cert_status(); |
| 1768 | *mixed_content_status = entry->ssl().content_status(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1769 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1770 | *success = false; |
| 1771 | *security_style = SECURITY_STYLE_UNKNOWN; |
| 1772 | *ssl_cert_status = 0; |
| 1773 | *mixed_content_status = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1774 | } |
| 1775 | } |
| 1776 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1777 | void AutomationProvider::GetPageType(int handle, bool* success, |
| 1778 | NavigationEntry::PageType* page_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1779 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1780 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1781 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1782 | *page_type = entry->page_type(); |
| 1783 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1784 | // In order to return the proper result when an interstitial is shown and |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1785 | // no navigation entry were created for it we need to ask the TabContents. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1786 | if (*page_type == NavigationEntry::NORMAL_PAGE && |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1787 | tab->tab_contents()->showing_interstitial_page()) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1788 | *page_type = NavigationEntry::INTERSTITIAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1789 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1790 | *success = false; |
| 1791 | *page_type = NavigationEntry::NORMAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 1795 | void AutomationProvider::GetMetricEventDuration(const std::string& event_name, |
| 1796 | int* duration_ms) { |
| 1797 | *duration_ms = metric_event_duration_observer_->GetEventDurationMs( |
| 1798 | event_name); |
| 1799 | } |
| 1800 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1801 | void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, |
| 1802 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1803 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1804 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1805 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 1806 | if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 1807 | TabContents* tab_contents = tab->tab_contents(); |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 1808 | InterstitialPage* ssl_blocking_page = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1809 | InterstitialPage::GetInterstitialPage(tab_contents); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1810 | if (ssl_blocking_page) { |
| 1811 | if (proceed) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 1812 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1813 | ssl_blocking_page->Proceed(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1814 | return; |
| 1815 | } |
| 1816 | ssl_blocking_page->DontProceed(); |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 1817 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| 1818 | reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1819 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1820 | return; |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | // We failed. |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 1825 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| 1826 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[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 | } |
| 1829 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1830 | void AutomationProvider::BringBrowserToFront(int browser_handle, |
| 1831 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1832 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1833 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | cd7ffc2 | 2008-11-12 00:26:06 | [diff] [blame] | 1834 | browser->window()->Activate(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1835 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1836 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1837 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1838 | } |
| 1839 | } |
| 1840 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1841 | void AutomationProvider::IsPageMenuCommandEnabled(int browser_handle, |
| 1842 | int message_num, |
| 1843 | bool* menu_item_enabled) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1844 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1845 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1846 | *menu_item_enabled = |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 1847 | browser->command_updater()->IsCommandEnabled(message_num); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1848 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1849 | *menu_item_enabled = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1850 | } |
| 1851 | } |
| 1852 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1853 | void AutomationProvider::PrintNow(int tab_handle, |
| 1854 | IPC::Message* reply_message) { |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 1855 | #if defined(OS_WIN) |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1856 | NavigationController* tab = NULL; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1857 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 1858 | if (tab_contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1859 | FindAndActivateTab(tab); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1860 | notification_observer_list_.AddObserver( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1861 | new DocumentPrintedNotificationObserver(this, reply_message)); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1862 | if (tab_contents->PrintNow()) |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1863 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1864 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1865 | AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); |
| 1866 | Send(reply_message); |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 1867 | #else |
| 1868 | // TODO(port): Remove once DocumentPrintedNotificationObserver is implemented. |
| 1869 | NOTIMPLEMENTED(); |
| 1870 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1871 | } |
[email protected] | d301c95 | 2009-07-13 15:02:41 | [diff] [blame] | 1872 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1873 | void AutomationProvider::SavePage(int tab_handle, |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 1874 | const FilePath& file_name, |
| 1875 | const FilePath& dir_path, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1876 | int type, |
| 1877 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1878 | if (!tab_tracker_->ContainsHandle(tab_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1879 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1880 | return; |
| 1881 | } |
| 1882 | |
| 1883 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 1884 | Browser* browser = FindAndActivateTab(nav); |
| 1885 | DCHECK(browser); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 1886 | if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1887 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1888 | return; |
| 1889 | } |
| 1890 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1891 | SavePackage::SavePackageType save_type = |
| 1892 | static_cast<SavePackage::SavePackageType>(type); |
| 1893 | DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML && |
| 1894 | save_type <= SavePackage::SAVE_AS_COMPLETE_HTML); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1895 | nav->tab_contents()->SavePage(file_name, dir_path, save_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1896 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1897 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1898 | } |
| 1899 | |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 1900 | #if !defined(OS_MACOSX) |
[email protected] | 3753f52 | 2009-04-14 23:15:47 | [diff] [blame] | 1901 | // TODO(port): Enable these. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1902 | void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle, |
| 1903 | bool* success, |
| 1904 | std::wstring* text) { |
| 1905 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1906 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1907 | *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 1908 | GetText(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1909 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1910 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1911 | } |
| 1912 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1913 | void AutomationProvider::SetAutocompleteEditText(int autocomplete_edit_handle, |
| 1914 | const std::wstring& text, |
| 1915 | bool* success) { |
| 1916 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1917 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 1918 | autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
| 1919 | SetUserText(text); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1920 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1921 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | void AutomationProvider::AutocompleteEditGetMatches( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1925 | int autocomplete_edit_handle, |
| 1926 | bool* success, |
| 1927 | std::vector<AutocompleteMatchData>* matches) { |
| 1928 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1929 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 8deeb95 | 2008-10-09 18:21:27 | [diff] [blame] | 1930 | const AutocompleteResult& result = autocomplete_edit_tracker_-> |
| 1931 | GetResource(autocomplete_edit_handle)->model()->result(); |
| 1932 | for (AutocompleteResult::const_iterator i = result.begin(); |
| 1933 | i != result.end(); ++i) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1934 | matches->push_back(AutocompleteMatchData(*i)); |
| 1935 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1936 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | void AutomationProvider::AutocompleteEditIsQueryInProgress( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1940 | int autocomplete_edit_handle, |
| 1941 | bool* success, |
| 1942 | bool* query_in_progress) { |
| 1943 | *success = false; |
| 1944 | *query_in_progress = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1945 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1946 | *query_in_progress = autocomplete_edit_tracker_-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 1947 | GetResource(autocomplete_edit_handle)->model()->query_in_progress(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1948 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1949 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1950 | } |
| 1951 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 1952 | void AutomationProvider::OnMessageFromExternalHost(int handle, |
| 1953 | const std::string& message, |
| 1954 | const std::string& origin, |
| 1955 | const std::string& target) { |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 1956 | RenderViewHost* view_host = GetViewForTab(handle); |
| 1957 | if (!view_host) { |
| 1958 | return; |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 1959 | } |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 1960 | |
| 1961 | if (AutomationExtensionFunction::InterceptMessageFromExternalHost( |
| 1962 | view_host, message, origin, target)) { |
| 1963 | // Message was diverted. |
| 1964 | return; |
| 1965 | } |
| 1966 | |
| 1967 | if (ExtensionPortContainer::InterceptMessageFromExternalHost(message, |
| 1968 | origin, target, this, view_host, handle)) { |
| 1969 | // Message was diverted. |
| 1970 | return; |
| 1971 | } |
| 1972 | |
| 1973 | if (InterceptBrowserEventMessageFromExternalHost(message, origin, target)) { |
| 1974 | // Message was diverted. |
| 1975 | return; |
| 1976 | } |
| 1977 | |
| 1978 | view_host->ForwardMessageFromExternalHost(message, origin, target); |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 1979 | } |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 1980 | |
| 1981 | bool AutomationProvider::InterceptBrowserEventMessageFromExternalHost( |
| 1982 | const std::string& message, const std::string& origin, |
| 1983 | const std::string& target) { |
| 1984 | if (target != |
| 1985 | extension_automation_constants::kAutomationBrowserEventRequestTarget) |
| 1986 | return false; |
| 1987 | |
| 1988 | if (origin != extension_automation_constants::kAutomationOrigin) { |
| 1989 | LOG(WARNING) << "Wrong origin on automation browser event " << origin; |
| 1990 | return false; |
| 1991 | } |
| 1992 | |
| 1993 | // The message is a JSON-encoded array with two elements, both strings. The |
| 1994 | // first is the name of the event to dispatch. The second is a JSON-encoding |
| 1995 | // of the arguments specific to that event. |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 1996 | scoped_ptr<Value> message_value(base::JSONReader::Read(message, false)); |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 1997 | if (!message_value.get() || !message_value->IsType(Value::TYPE_LIST)) { |
| 1998 | LOG(WARNING) << "Invalid browser event specified through automation"; |
| 1999 | return false; |
| 2000 | } |
| 2001 | |
| 2002 | const ListValue* args = static_cast<const ListValue*>(message_value.get()); |
| 2003 | |
| 2004 | std::string event_name; |
| 2005 | if (!args->GetString(0, &event_name)) { |
| 2006 | LOG(WARNING) << "No browser event name specified through automation"; |
| 2007 | return false; |
| 2008 | } |
| 2009 | |
| 2010 | std::string json_args; |
| 2011 | if (!args->GetString(1, &json_args)) { |
| 2012 | LOG(WARNING) << "No browser event args specified through automation"; |
| 2013 | return false; |
| 2014 | } |
| 2015 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 2016 | if (profile()->GetExtensionMessageService()) { |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 2017 | profile()->GetExtensionMessageService()->DispatchEventToRenderers( |
| 2018 | event_name, json_args, profile()->IsOffTheRecord()); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 2019 | } |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 2020 | |
| 2021 | return true; |
| 2022 | } |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 2023 | #endif // !defined(OS_MACOSX) |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 2024 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2025 | TabContents* AutomationProvider::GetTabContentsForHandle( |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2026 | int handle, NavigationController** tab) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2027 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2028 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2029 | if (tab) |
| 2030 | *tab = nav_controller; |
| 2031 | return nav_controller->tab_contents(); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2032 | } |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2033 | return NULL; |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2034 | } |
| 2035 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2036 | TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
| 2037 | : AutomationProvider(profile) { |
| 2038 | BrowserList::AddObserver(this); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2039 | registrar_.Add(this, NotificationType::SESSION_END, |
| 2040 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | TestingAutomationProvider::~TestingAutomationProvider() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2044 | BrowserList::RemoveObserver(this); |
| 2045 | } |
| 2046 | |
| 2047 | void TestingAutomationProvider::OnChannelError() { |
[email protected] | a932444 | 2009-10-12 04:32:14 | [diff] [blame] | 2048 | BrowserList::CloseAllBrowsersAndExit(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2049 | AutomationProvider::OnChannelError(); |
| 2050 | } |
| 2051 | |
| 2052 | void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) { |
| 2053 | // For backwards compatibility with the testing automation interface, we |
| 2054 | // want the automation provider (and hence the process) to go away when the |
| 2055 | // last browser goes away. |
| 2056 | if (BrowserList::size() == 1) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2057 | // If you change this, update Observer for NotificationType::SESSION_END |
| 2058 | // below. |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 2059 | MessageLoop::current()->PostTask(FROM_HERE, |
| 2060 | NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | void TestingAutomationProvider::Observe(NotificationType type, |
| 2065 | const NotificationSource& source, |
| 2066 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 2067 | DCHECK(type == NotificationType::SESSION_END); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2068 | // OnBrowserRemoving does a ReleaseLater. When session end is received we exit |
| 2069 | // before the task runs resulting in this object not being deleted. This |
| 2070 | // Release balance out the Release scheduled by OnBrowserRemoving. |
| 2071 | Release(); |
| 2072 | } |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 2073 | |
| 2074 | void TestingAutomationProvider::OnRemoveProvider() { |
| 2075 | AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 2076 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2077 | |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 2078 | void AutomationProvider::GetInfoBarCount(int handle, int* count) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2079 | *count = -1; // -1 means error. |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2080 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2081 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2082 | if (nav_controller) |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2083 | *count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2084 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2085 | } |
| 2086 | |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 2087 | void AutomationProvider::ClickInfoBarAccept(int handle, |
| 2088 | int info_bar_index, |
| 2089 | bool wait_for_navigation, |
| 2090 | IPC::Message* reply_message) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2091 | bool success = false; |
| 2092 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2093 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 2094 | if (nav_controller) { |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2095 | int count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2096 | if (info_bar_index >= 0 && info_bar_index < count) { |
| 2097 | if (wait_for_navigation) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2098 | AddNavigationStatusListener(nav_controller, reply_message, 1, false); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2099 | } |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2100 | InfoBarDelegate* delegate = |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2101 | nav_controller->tab_contents()->GetInfoBarDelegateAt( |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2102 | info_bar_index); |
| 2103 | if (delegate->AsConfirmInfoBarDelegate()) |
| 2104 | delegate->AsConfirmInfoBarDelegate()->Accept(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2105 | success = true; |
| 2106 | } |
| 2107 | } |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2108 | } |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 2109 | |
| 2110 | // This "!wait_for_navigation || !success condition" logic looks suspicious. |
| 2111 | // It will send a failure message when success is true but |
| 2112 | // |wait_for_navigation| is false. |
| 2113 | // TODO(phajdan.jr): investgate whether the reply param (currently |
| 2114 | // AUTOMATION_MSG_NAVIGATION_ERROR) should depend on success. |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2115 | if (!wait_for_navigation || !success) |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 2116 | AutomationMsg_ClickInfoBarAccept::WriteReplyParams( |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2117 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2118 | } |
| 2119 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2120 | void AutomationProvider::GetLastNavigationTime(int handle, |
| 2121 | int64* last_navigation_time) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2122 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2123 | *last_navigation_time = time.ToInternalValue(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2124 | } |
| 2125 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2126 | void AutomationProvider::WaitForNavigation(int handle, |
| 2127 | int64 last_navigation_time, |
| 2128 | IPC::Message* reply_message) { |
[email protected] | 5fa7acd | 2009-09-25 20:04:25 | [diff] [blame] | 2129 | NavigationController* controller = tab_tracker_->GetResource(handle); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2130 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
[email protected] | 5fa7acd | 2009-09-25 20:04:25 | [diff] [blame] | 2131 | |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2132 | if (time.ToInternalValue() > last_navigation_time || !controller) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2133 | AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message, |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2134 | controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR : |
| 2135 | AUTOMATION_MSG_NAVIGATION_SUCCESS); |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 2136 | Send(reply_message); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2137 | return; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2138 | } |
| 2139 | |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2140 | AddNavigationStatusListener(controller, reply_message, 1, true); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2141 | } |
| 2142 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2143 | void AutomationProvider::SetIntPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2144 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2145 | int value, |
| 2146 | bool* success) { |
| 2147 | *success = false; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2148 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2149 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2150 | browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2151 | *success = true; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2152 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2153 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2154 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2155 | void AutomationProvider::SetStringPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2156 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2157 | const std::wstring& value, |
| 2158 | bool* success) { |
| 2159 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2160 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2161 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2162 | browser->profile()->GetPrefs()->SetString(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2163 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2164 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2165 | } |
| 2166 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2167 | void AutomationProvider::GetBooleanPreference(int handle, |
| 2168 | const std::wstring& name, |
[email protected] | b8f48d1 | 2009-11-09 20:14:36 | [diff] [blame] | 2169 | bool* success, |
| 2170 | bool* value) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2171 | *success = false; |
| 2172 | *value = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2173 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2174 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2175 | *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str()); |
| 2176 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2177 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2178 | } |
| 2179 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2180 | void AutomationProvider::SetBooleanPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2181 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2182 | bool value, |
| 2183 | bool* success) { |
| 2184 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2185 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2186 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2187 | browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2188 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2189 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2193 | void AutomationProvider::GetPageCurrentEncoding( |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2194 | int tab_handle, std::string* current_encoding) { |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2195 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2196 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 2197 | Browser* browser = FindAndActivateTab(nav); |
| 2198 | DCHECK(browser); |
| 2199 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2200 | if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) |
| 2201 | *current_encoding = nav->tab_contents()->encoding(); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2202 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2203 | } |
| 2204 | |
[email protected] | b8f48d1 | 2009-11-09 20:14:36 | [diff] [blame] | 2205 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2206 | void AutomationProvider::OverrideEncoding(int tab_handle, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2207 | const std::string& encoding_name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2208 | bool* success) { |
| 2209 | *success = false; |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2210 | #if defined(OS_WIN) |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2211 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2212 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 2213 | Browser* browser = FindAndActivateTab(nav); |
| 2214 | DCHECK(browser); |
| 2215 | |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2216 | if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2217 | int selected_encoding_id = |
| 2218 | CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name); |
| 2219 | if (selected_encoding_id) { |
| 2220 | browser->OverrideEncoding(selected_encoding_id); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2221 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2225 | #else |
| 2226 | // TODO(port): Enable when encoding-related parts of Browser are ported. |
| 2227 | NOTIMPLEMENTED(); |
| 2228 | #endif |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2229 | } |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 2230 | |
[email protected] | 4d434a1a | 2009-02-11 21:06:57 | [diff] [blame] | 2231 | void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) { |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 2232 | SavePackage::SetShouldPromptUser(should_prompt); |
| 2233 | } |
[email protected] | 87eab22 | 2009-03-13 00:47:45 | [diff] [blame] | 2234 | |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 2235 | void AutomationProvider::GetBlockedPopupCount(int handle, int* count) { |
| 2236 | *count = -1; // -1 is the error code |
| 2237 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2238 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 2239 | TabContents* tab_contents = nav_controller->tab_contents(); |
| 2240 | if (tab_contents) { |
| 2241 | BlockedPopupContainer* container = |
| 2242 | tab_contents->blocked_popup_container(); |
| 2243 | if (container) { |
| 2244 | *count = static_cast<int>(container->GetBlockedPopupCount()); |
| 2245 | } else { |
| 2246 | // If we don't have a container, we don't have any blocked popups to |
| 2247 | // contain! |
| 2248 | *count = 0; |
| 2249 | } |
| 2250 | } |
| 2251 | } |
| 2252 | } |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2253 | |
| 2254 | void AutomationProvider::SelectAll(int tab_handle) { |
| 2255 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2256 | if (!view) { |
| 2257 | NOTREACHED(); |
| 2258 | return; |
| 2259 | } |
| 2260 | |
| 2261 | view->SelectAll(); |
| 2262 | } |
| 2263 | |
| 2264 | void AutomationProvider::Cut(int tab_handle) { |
| 2265 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2266 | if (!view) { |
| 2267 | NOTREACHED(); |
| 2268 | return; |
| 2269 | } |
| 2270 | |
| 2271 | view->Cut(); |
| 2272 | } |
| 2273 | |
| 2274 | void AutomationProvider::Copy(int tab_handle) { |
| 2275 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2276 | if (!view) { |
| 2277 | NOTREACHED(); |
| 2278 | return; |
| 2279 | } |
| 2280 | |
| 2281 | view->Copy(); |
| 2282 | } |
| 2283 | |
| 2284 | void AutomationProvider::Paste(int tab_handle) { |
| 2285 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2286 | if (!view) { |
| 2287 | NOTREACHED(); |
| 2288 | return; |
| 2289 | } |
| 2290 | |
| 2291 | view->Paste(); |
| 2292 | } |
| 2293 | |
| 2294 | void AutomationProvider::ReloadAsync(int tab_handle) { |
| 2295 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2296 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2297 | if (!tab) { |
| 2298 | NOTREACHED(); |
| 2299 | return; |
| 2300 | } |
| 2301 | |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 2302 | const bool check_for_repost = true; |
| 2303 | tab->Reload(check_for_repost); |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | void AutomationProvider::StopAsync(int tab_handle) { |
| 2308 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2309 | if (!view) { |
[email protected] | 8b2b331 | 2009-09-14 18:38:36 | [diff] [blame] | 2310 | // We tolerate StopAsync being called even before a view has been created. |
| 2311 | // So just log a warning instead of a NOTREACHED(). |
| 2312 | DLOG(WARNING) << "StopAsync: no view for handle " << tab_handle; |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | view->Stop(); |
| 2317 | } |
| 2318 | |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 2319 | void AutomationProvider::OnSetPageFontSize(int tab_handle, |
| 2320 | int font_size) { |
| 2321 | AutomationPageFontSize automation_font_size = |
| 2322 | static_cast<AutomationPageFontSize>(font_size); |
| 2323 | |
| 2324 | if (automation_font_size < SMALLEST_FONT || |
| 2325 | automation_font_size > LARGEST_FONT) { |
| 2326 | DLOG(ERROR) << "Invalid font size specified : " |
| 2327 | << font_size; |
| 2328 | return; |
| 2329 | } |
| 2330 | |
| 2331 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2332 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2333 | DCHECK(tab != NULL); |
| 2334 | if (tab && tab->tab_contents()) { |
| 2335 | DCHECK(tab->tab_contents()->profile() != NULL); |
| 2336 | tab->tab_contents()->profile()->GetPrefs()->SetInteger( |
| 2337 | prefs::kWebKitDefaultFontSize, font_size); |
| 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | |
[email protected] | 2949e90d | 2009-08-21 15:32:52 | [diff] [blame] | 2343 | void AutomationProvider::WaitForBrowserWindowCountToBecome( |
| 2344 | int target_count, IPC::Message* reply_message) { |
| 2345 | if (static_cast<int>(BrowserList::size()) == target_count) { |
| 2346 | AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( |
| 2347 | reply_message, true); |
| 2348 | Send(reply_message); |
| 2349 | return; |
| 2350 | } |
| 2351 | |
| 2352 | // Set up an observer (it will delete itself). |
| 2353 | new BrowserCountChangeNotificationObserver(target_count, this, reply_message); |
| 2354 | } |
| 2355 | |
| 2356 | void AutomationProvider::WaitForAppModalDialogToBeShown( |
| 2357 | IPC::Message* reply_message) { |
| 2358 | if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) { |
| 2359 | AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( |
| 2360 | reply_message, true); |
| 2361 | Send(reply_message); |
| 2362 | return; |
| 2363 | } |
| 2364 | |
| 2365 | // Set up an observer (it will delete itself). |
| 2366 | new AppModalDialogShownObserver(this, reply_message); |
| 2367 | } |
| 2368 | |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 2369 | void AutomationProvider::GoBackBlockUntilNavigationsComplete( |
| 2370 | int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 2371 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2372 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2373 | Browser* browser = FindAndActivateTab(tab); |
| 2374 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2375 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 2376 | false); |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 2377 | browser->GoBack(CURRENT_TAB); |
| 2378 | return; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams( |
| 2383 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 2384 | Send(reply_message); |
| 2385 | } |
| 2386 | |
| 2387 | void AutomationProvider::GoForwardBlockUntilNavigationsComplete( |
| 2388 | int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 2389 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2390 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2391 | Browser* browser = FindAndActivateTab(tab); |
| 2392 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2393 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 2394 | false); |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 2395 | browser->GoForward(CURRENT_TAB); |
| 2396 | return; |
| 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( |
| 2401 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 2402 | Send(reply_message); |
| 2403 | } |
| 2404 | |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2405 | RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { |
| 2406 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2407 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2408 | if (!tab) { |
| 2409 | NOTREACHED(); |
| 2410 | return NULL; |
| 2411 | } |
| 2412 | |
| 2413 | TabContents* tab_contents = tab->tab_contents(); |
| 2414 | if (!tab_contents) { |
| 2415 | NOTREACHED(); |
| 2416 | return NULL; |
| 2417 | } |
| 2418 | |
| 2419 | RenderViewHost* view_host = tab_contents->render_view_host(); |
| 2420 | return view_host; |
| 2421 | } |
| 2422 | |
| 2423 | return NULL; |
| 2424 | } |
[email protected] | 675595f | 2009-08-26 22:32:04 | [diff] [blame] | 2425 | |
| 2426 | void AutomationProvider::GetBrowserForWindow(int window_handle, |
| 2427 | bool* success, |
| 2428 | int* browser_handle) { |
| 2429 | *success = false; |
| 2430 | *browser_handle = 0; |
| 2431 | |
| 2432 | gfx::NativeWindow window = window_tracker_->GetResource(window_handle); |
| 2433 | if (!window) |
| 2434 | return; |
| 2435 | |
| 2436 | BrowserList::const_iterator iter = BrowserList::begin(); |
| 2437 | for (;iter != BrowserList::end(); ++iter) { |
| 2438 | gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle(); |
| 2439 | if (window == this_window) { |
| 2440 | // Add() returns the existing handle for the resource if any. |
| 2441 | *browser_handle = browser_tracker_->Add(*iter); |
| 2442 | *success = true; |
| 2443 | return; |
| 2444 | } |
| 2445 | } |
| 2446 | } |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2447 | |
| 2448 | void AutomationProvider::InstallExtension(const FilePath& crx_path, |
| 2449 | IPC::Message* reply_message) { |
| 2450 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2451 | if (service) { |
| 2452 | // The observer will delete itself when done. |
| 2453 | new ExtensionNotificationObserver(this, |
| 2454 | AutomationMsg_InstallExtension::ID, |
| 2455 | reply_message); |
| 2456 | |
| 2457 | const FilePath& install_dir = service->install_directory(); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2458 | scoped_refptr<CrxInstaller> installer( |
| 2459 | new CrxInstaller(install_dir, |
| 2460 | service, |
| 2461 | NULL)); // silent install, no UI |
| 2462 | installer->set_allow_privilege_increase(true); |
| 2463 | installer->InstallCrx(crx_path); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2464 | } else { |
| 2465 | AutomationMsg_InstallExtension::WriteReplyParams( |
| 2466 | reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); |
| 2467 | Send(reply_message); |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | void AutomationProvider::LoadExpandedExtension( |
| 2472 | const FilePath& extension_dir, |
| 2473 | IPC::Message* reply_message) { |
[email protected] | a437825 | 2010-02-09 08:14:38 | [diff] [blame] | 2474 | if (profile_->GetExtensionsService()) { |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2475 | // The observer will delete itself when done. |
| 2476 | new ExtensionNotificationObserver(this, |
| 2477 | AutomationMsg_LoadExpandedExtension::ID, |
| 2478 | reply_message); |
| 2479 | |
| 2480 | profile_->GetExtensionsService()->LoadExtension(extension_dir); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2481 | } else { |
| 2482 | AutomationMsg_LoadExpandedExtension::WriteReplyParams( |
| 2483 | reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); |
| 2484 | Send(reply_message); |
| 2485 | } |
| 2486 | } |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 2487 | |
[email protected] | a1e62d1 | 2010-03-16 02:18:43 | [diff] [blame] | 2488 | void AutomationProvider::GetEnabledExtensions( |
| 2489 | std::vector<FilePath>* result) { |
| 2490 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2491 | DCHECK(service); |
| 2492 | if (service->extensions_enabled()) { |
| 2493 | const ExtensionList* extensions = service->extensions(); |
| 2494 | DCHECK(extensions); |
| 2495 | for (size_t i = 0; i < extensions->size(); ++i) { |
| 2496 | Extension* extension = (*extensions)[i]; |
| 2497 | DCHECK(extension); |
| 2498 | result->push_back(extension->path()); |
| 2499 | } |
| 2500 | } |
| 2501 | } |
| 2502 | |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 2503 | void AutomationProvider::SaveAsAsync(int tab_handle) { |
| 2504 | NavigationController* tab = NULL; |
| 2505 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 2506 | if (tab_contents) |
| 2507 | tab_contents->OnSavePage(); |
| 2508 | } |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2509 | |
| 2510 | void AutomationProvider::SetContentSetting( |
| 2511 | int handle, |
| 2512 | const std::string& host, |
| 2513 | ContentSettingsType content_type, |
| 2514 | ContentSetting setting, |
| 2515 | bool* success) { |
| 2516 | *success = false; |
| 2517 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2518 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2519 | HostContentSettingsMap* map = |
| 2520 | browser->profile()->GetHostContentSettingsMap(); |
| 2521 | if (host.empty()) { |
| 2522 | map->SetDefaultContentSetting(content_type, setting); |
| 2523 | } else { |
| 2524 | map->SetContentSetting(host, content_type, setting); |
| 2525 | } |
| 2526 | *success = true; |
| 2527 | } |
| 2528 | } |