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