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