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