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