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