[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] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 12 | #include "base/file_path.h" |
[email protected] | c6cb199 | 2009-04-13 16:45:29 | [diff] [blame] | 13 | #include "base/file_version_info.h" |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 14 | #include "base/json/json_reader.h" |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 15 | #include "base/json/json_writer.h" |
[email protected] | 93364da | 2010-06-29 18:03:44 | [diff] [blame] | 16 | #include "base/json/string_escape.h" |
[email protected] | bc1407f | 2009-09-29 00:33:35 | [diff] [blame] | 17 | #include "base/keyboard_codes.h" |
[email protected] | 5fac962 | 2009-02-04 21:49:38 | [diff] [blame] | 18 | #include "base/message_loop.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | #include "base/path_service.h" |
[email protected] | 201b273 | 2009-11-13 18:57:46 | [diff] [blame] | 20 | #include "base/process_util.h" |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 21 | #include "base/stl_util-inl.h" |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 22 | #include "base/string_util.h" |
[email protected] | 9eaa18e | 2010-06-29 20:51:01 | [diff] [blame] | 23 | #include "base/task.h" |
[email protected] | 5fac962 | 2009-02-04 21:49:38 | [diff] [blame] | 24 | #include "base/thread.h" |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 25 | #include "base/utf_string_conversions.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 26 | #include "base/values.h" |
[email protected] | 9eaa18e | 2010-06-29 20:51:01 | [diff] [blame] | 27 | #include "base/waitable_event.h" |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 28 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | bcff05a | 2010-04-14 01:46:43 | [diff] [blame] | 29 | #include "chrome/app/chrome_version_info.h" |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 30 | #include "chrome/browser/app_modal_dialog.h" |
[email protected] | 464146e | 2009-04-09 18:17:09 | [diff] [blame] | 31 | #include "chrome/browser/app_modal_dialog_queue.h" |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 32 | #include "chrome/browser/autofill/autofill_manager.h" |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 33 | #include "chrome/browser/automation/automation_extension_tracker.h" |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 34 | #include "chrome/browser/automation/automation_provider_json.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 35 | #include "chrome/browser/automation/automation_provider_list.h" |
[email protected] | e12de87e | 2009-08-28 00:02:08 | [diff] [blame] | 36 | #include "chrome/browser/automation/automation_provider_observers.h" |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 37 | #include "chrome/browser/automation/extension_port_container.h" |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 38 | #include "chrome/browser/autocomplete/autocomplete_edit.h" |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 39 | #include "chrome/browser/blocked_popup_container.h" |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 40 | #include "chrome/browser/bookmarks/bookmark_model.h" |
| 41 | #include "chrome/browser/bookmarks/bookmark_storage.h" |
[email protected] | ef413ca | 2010-05-25 21:09:14 | [diff] [blame] | 42 | #include "chrome/browser/browser_list.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 43 | #include "chrome/browser/browser_process.h" |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 44 | #include "chrome/browser/browser_window.h" |
[email protected] | bc73b4e5 | 2010-03-26 04:16:20 | [diff] [blame] | 45 | #include "chrome/browser/browsing_data_remover.h" |
[email protected] | f83f910 | 2010-05-04 17:01:05 | [diff] [blame] | 46 | #include "chrome/browser/character_encoding.h" |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 47 | #include "chrome/browser/chrome_thread.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 48 | #include "chrome/browser/dom_operation_notification_details.h" |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 49 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | cdaa865 | 2008-09-13 02:48:59 | [diff] [blame] | 50 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 51 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | f83f910 | 2010-05-04 17:01:05 | [diff] [blame] | 52 | #include "chrome/browser/download/save_package.h" |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 53 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | ef413ca | 2010-05-25 21:09:14 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 57 | #include "chrome/browser/extensions/extension_message_service.h" |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 58 | #include "chrome/browser/extensions/extension_tabs_module.h" |
| 59 | #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 60 | #include "chrome/browser/extensions/extensions_service.h" |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 61 | #include "chrome/browser/extensions/user_script_master.h" |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 62 | #include "chrome/browser/find_bar.h" |
| 63 | #include "chrome/browser/find_bar_controller.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | #include "chrome/browser/find_notification_details.h" |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 65 | #include "chrome/browser/host_content_settings_map.h" |
[email protected] | c5aa532 | 2010-07-15 19:00:07 | [diff] [blame] | 66 | #include "chrome/browser/importer/importer.h" |
| 67 | #include "chrome/browser/importer/importer_data_types.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 68 | #include "chrome/browser/io_thread.h" |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 69 | #include "chrome/browser/location_bar.h" |
[email protected] | 3fcac68 | 2009-08-13 02:28:01 | [diff] [blame] | 70 | #include "chrome/browser/login_prompt.h" |
[email protected] | f732c1e | 2009-07-30 15:48:53 | [diff] [blame] | 71 | #include "chrome/browser/net/url_request_mock_util.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 72 | #include "chrome/browser/platform_util.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 73 | #include "chrome/browser/pref_service.h" |
[email protected] | f83f910 | 2010-05-04 17:01:05 | [diff] [blame] | 74 | #include "chrome/browser/printing/print_job.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 75 | #include "chrome/browser/profile_manager.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 76 | #include "chrome/browser/renderer_host/render_process_host.h" |
[email protected] | 6524b5f9 | 2009-01-22 17:48:25 | [diff] [blame] | 77 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 3b073b2 | 2009-01-16 03:29:03 | [diff] [blame] | 78 | #include "chrome/browser/ssl/ssl_manager.h" |
| 79 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | b5558cf2 | 2010-07-12 17:30:06 | [diff] [blame] | 80 | #include "chrome/browser/tab_contents/infobar_delegate.h" |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 81 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 81af939 | 2009-04-21 02:37:45 | [diff] [blame] | 82 | #include "chrome/browser/tab_contents/tab_contents_view.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 83 | #include "chrome/common/automation_constants.h" |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 84 | #include "chrome/common/chrome_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | #include "chrome/common/chrome_paths.h" |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 86 | #include "chrome/common/extensions/extension.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 87 | #include "chrome/common/json_value_serializer.h" |
[email protected] | 68d2a05f | 2010-05-07 21:39:55 | [diff] [blame] | 88 | #include "chrome/common/net/url_request_context_getter.h" |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 89 | #include "chrome/common/notification_service.h" |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 90 | #include "chrome/common/pref_names.h" |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 91 | #include "chrome/common/url_constants.h" |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 92 | #include "chrome/test/automation/automation_messages.h" |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 93 | #include "chrome/test/automation/tab_proxy.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 94 | #include "net/proxy/proxy_service.h" |
| 95 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 96 | #include "net/url_request/url_request_context.h" |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 97 | #include "chrome/browser/automation/ui_controls.h" |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame] | 98 | #include "views/event.h" |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 99 | #include "webkit/glue/plugins/plugin_list.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 101 | #if defined(OS_WIN) |
[email protected] | 4bdde60 | 2010-06-16 03:17:35 | [diff] [blame] | 102 | #include "chrome/browser/external_tab_container_win.h" |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 103 | #endif // defined(OS_WIN) |
| 104 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 105 | using base::Time; |
| 106 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 107 | class AutomationInterstitialPage : public InterstitialPage { |
| 108 | public: |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 109 | AutomationInterstitialPage(TabContents* tab, |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 110 | const GURL& url, |
| 111 | const std::string& contents) |
| 112 | : InterstitialPage(tab, true, url), |
| 113 | contents_(contents) { |
| 114 | } |
| 115 | |
| 116 | virtual std::string GetHTMLContents() { return contents_; } |
| 117 | |
| 118 | private: |
| 119 | std::string contents_; |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 120 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); |
| 122 | }; |
| 123 | |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 124 | class ClickTask : public Task { |
| 125 | public: |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 126 | explicit ClickTask(int flags) : flags_(flags) {} |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 127 | virtual ~ClickTask() {} |
| 128 | |
| 129 | virtual void Run() { |
| 130 | ui_controls::MouseButton button = ui_controls::LEFT; |
| 131 | if ((flags_ & views::Event::EF_LEFT_BUTTON_DOWN) == |
| 132 | views::Event::EF_LEFT_BUTTON_DOWN) { |
| 133 | button = ui_controls::LEFT; |
| 134 | } else if ((flags_ & views::Event::EF_RIGHT_BUTTON_DOWN) == |
| 135 | views::Event::EF_RIGHT_BUTTON_DOWN) { |
| 136 | button = ui_controls::RIGHT; |
| 137 | } else if ((flags_ & views::Event::EF_MIDDLE_BUTTON_DOWN) == |
| 138 | views::Event::EF_MIDDLE_BUTTON_DOWN) { |
| 139 | button = ui_controls::MIDDLE; |
| 140 | } else { |
| 141 | NOTREACHED(); |
| 142 | } |
| 143 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 144 | ui_controls::SendMouseClick(button); |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | private: |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 148 | int flags_; |
| 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(ClickTask); |
| 151 | }; |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 152 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 153 | AutomationProvider::AutomationProvider(Profile* profile) |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 154 | : redirect_query_(0), |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 155 | profile_(profile), |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 156 | reply_message_(NULL), |
| 157 | popup_menu_waiter_(NULL) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | browser_tracker_.reset(new AutomationBrowserTracker(this)); |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 159 | extension_tracker_.reset(new AutomationExtensionTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | tab_tracker_.reset(new AutomationTabTracker(this)); |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 161 | window_tracker_.reset(new AutomationWindowTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 162 | autocomplete_edit_tracker_.reset( |
| 163 | new AutomationAutocompleteEditTracker(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 164 | new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this)); |
| 165 | dom_operation_observer_.reset(new DomOperationNotificationObserver(this)); |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 166 | metric_event_duration_observer_.reset(new MetricEventDurationObserver()); |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 167 | extension_test_result_observer_.reset( |
| 168 | new ExtensionTestResultNotificationObserver(this)); |
[email protected] | 528211a | 2010-01-14 15:25:13 | [diff] [blame] | 169 | g_browser_process->AddRefModule(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | AutomationProvider::~AutomationProvider() { |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 173 | STLDeleteContainerPairSecondPointers(port_containers_.begin(), |
| 174 | port_containers_.end()); |
| 175 | port_containers_.clear(); |
| 176 | |
[email protected] | 0da050b9 | 2008-08-19 19:29:47 | [diff] [blame] | 177 | // Make sure that any outstanding NotificationObservers also get destroyed. |
| 178 | ObserverList<NotificationObserver>::Iterator it(notification_observer_list_); |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 179 | NotificationObserver* observer; |
[email protected] | 0da050b9 | 2008-08-19 19:29:47 | [diff] [blame] | 180 | while ((observer = it.GetNext()) != NULL) |
| 181 | delete observer; |
[email protected] | 528211a | 2010-01-14 15:25:13 | [diff] [blame] | 182 | |
| 183 | if (channel_.get()) { |
| 184 | channel_->Close(); |
| 185 | } |
| 186 | g_browser_process->ReleaseModule(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | 9a3a293b | 2009-06-04 22:28:16 | [diff] [blame] | 189 | void AutomationProvider::ConnectToChannel(const std::string& channel_id) { |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 190 | automation_resource_message_filter_ = new AutomationResourceMessageFilter; |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 191 | channel_.reset( |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 192 | new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, |
| 193 | automation_resource_message_filter_, |
| 194 | g_browser_process->io_thread()->message_loop(), |
| 195 | true, g_browser_process->shutdown_event())); |
[email protected] | bcff05a | 2010-04-14 01:46:43 | [diff] [blame] | 196 | scoped_ptr<FileVersionInfo> version_info( |
| 197 | chrome_app::GetChromeVersionInfo()); |
[email protected] | cf62075 | 2009-04-24 17:05:40 | [diff] [blame] | 198 | std::string version_string; |
[email protected] | bcff05a | 2010-04-14 01:46:43 | [diff] [blame] | 199 | if (version_info != NULL) { |
| 200 | version_string = WideToASCII(version_info->file_version()); |
[email protected] | cf62075 | 2009-04-24 17:05:40 | [diff] [blame] | 201 | } |
[email protected] | c6cb199 | 2009-04-13 16:45:29 | [diff] [blame] | 202 | |
| 203 | // Send a hello message with our current automation protocol version. |
| 204 | channel_->Send(new AutomationMsg_Hello(0, version_string.c_str())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { |
| 208 | if (expected_tabs == 0) { |
| 209 | Send(new AutomationMsg_InitialLoadsComplete(0)); |
| 210 | } else { |
| 211 | initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | NotificationObserver* AutomationProvider::AddNavigationStatusListener( |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 216 | NavigationController* tab, IPC::Message* reply_message, |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 217 | int number_of_navigations, bool include_current_navigation) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 218 | NotificationObserver* observer = |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 219 | new NavigationNotificationObserver(tab, this, reply_message, |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 220 | number_of_navigations, |
| 221 | include_current_navigation); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 222 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 223 | notification_observer_list_.AddObserver(observer); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 224 | return observer; |
| 225 | } |
| 226 | |
[email protected] | faf2ee4 | 2010-05-11 14:26:17 | [diff] [blame] | 227 | void AutomationProvider::RemoveNavigationStatusListener( |
| 228 | NotificationObserver* obs) { |
| 229 | notification_observer_list_.RemoveObserver(obs); |
| 230 | } |
| 231 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 232 | NotificationObserver* AutomationProvider::AddTabStripObserver( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 233 | Browser* parent, |
| 234 | IPC::Message* reply_message) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 235 | NotificationObserver* observer = |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 236 | new TabAppendedNotificationObserver(parent, this, reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 237 | notification_observer_list_.AddObserver(observer); |
| 238 | |
| 239 | return observer; |
| 240 | } |
| 241 | |
[email protected] | faf2ee4 | 2010-05-11 14:26:17 | [diff] [blame] | 242 | void AutomationProvider::RemoveTabStripObserver(NotificationObserver* obs) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 243 | notification_observer_list_.RemoveObserver(obs); |
| 244 | } |
| 245 | |
| 246 | void AutomationProvider::AddLoginHandler(NavigationController* tab, |
| 247 | LoginHandler* handler) { |
| 248 | login_handler_map_[tab] = handler; |
| 249 | } |
| 250 | |
| 251 | void AutomationProvider::RemoveLoginHandler(NavigationController* tab) { |
| 252 | DCHECK(login_handler_map_[tab]); |
| 253 | login_handler_map_.erase(tab); |
| 254 | } |
| 255 | |
[email protected] | f44265b | 2009-05-19 18:52:50 | [diff] [blame] | 256 | void AutomationProvider::AddPortContainer(ExtensionPortContainer* port) { |
| 257 | int port_id = port->port_id(); |
| 258 | DCHECK_NE(-1, port_id); |
| 259 | DCHECK(port_containers_.find(port_id) == port_containers_.end()); |
| 260 | |
| 261 | port_containers_[port_id] = port; |
| 262 | } |
| 263 | |
| 264 | void AutomationProvider::RemovePortContainer(ExtensionPortContainer* port) { |
| 265 | int port_id = port->port_id(); |
| 266 | DCHECK_NE(-1, port_id); |
| 267 | |
| 268 | PortContainerMap::iterator it = port_containers_.find(port_id); |
| 269 | DCHECK(it != port_containers_.end()); |
| 270 | |
| 271 | if (it != port_containers_.end()) { |
| 272 | delete it->second; |
| 273 | port_containers_.erase(it); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | ExtensionPortContainer* AutomationProvider::GetPortContainer( |
| 278 | int port_id) const { |
| 279 | PortContainerMap::const_iterator it = port_containers_.find(port_id); |
| 280 | if (it == port_containers_.end()) |
| 281 | return NULL; |
| 282 | |
| 283 | return it->second; |
| 284 | } |
| 285 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | int AutomationProvider::GetIndexForNavigationController( |
| 287 | const NavigationController* controller, const Browser* parent) const { |
| 288 | DCHECK(parent); |
[email protected] | 902cdf77 | 2009-05-06 15:08:12 | [diff] [blame] | 289 | return parent->GetIndexOfController(controller); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 290 | } |
| 291 | |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 292 | int AutomationProvider::AddExtension(Extension* extension) { |
| 293 | DCHECK(extension); |
| 294 | return extension_tracker_->Add(extension); |
| 295 | } |
| 296 | |
| 297 | Extension* AutomationProvider::GetExtension(int extension_handle) { |
| 298 | return extension_tracker_->GetResource(extension_handle); |
| 299 | } |
| 300 | |
| 301 | Extension* AutomationProvider::GetEnabledExtension(int extension_handle) { |
| 302 | Extension* extension = extension_tracker_->GetResource(extension_handle); |
| 303 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 304 | if (extension && service && |
| 305 | service->GetExtensionById(extension->id(), false)) |
| 306 | return extension; |
| 307 | return NULL; |
| 308 | } |
| 309 | |
| 310 | Extension* AutomationProvider::GetDisabledExtension(int extension_handle) { |
| 311 | Extension* extension = extension_tracker_->GetResource(extension_handle); |
| 312 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 313 | if (extension && service && |
| 314 | service->GetExtensionById(extension->id(), true) && |
| 315 | !service->GetExtensionById(extension->id(), false)) |
| 316 | return extension; |
| 317 | return NULL; |
| 318 | } |
| 319 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 320 | void AutomationProvider::OnMessageReceived(const IPC::Message& message) { |
| 321 | IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 322 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 323 | IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync, |
| 324 | CloseBrowserAsync) |
| 325 | IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) |
| 326 | IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex) |
| 327 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) |
| 328 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab) |
| 329 | IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) |
| 330 | IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie) |
[email protected] | 5fa5794 | 2010-04-21 23:07:22 | [diff] [blame] | 331 | IPC_MESSAGE_HANDLER(AutomationMsg_DeleteCookie, DeleteCookie) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 332 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL) |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 333 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 334 | AutomationMsg_NavigateToURLBlockUntilNavigationsComplete, |
| 335 | NavigateToURLBlockUntilNavigationsComplete) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 336 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync) |
[email protected] | c70f9b8 | 2010-04-21 07:31:11 | [diff] [blame] | 337 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsyncWithDisposition, |
| 338 | NavigationAsyncWithDisposition) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 339 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack) |
| 340 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward) |
| 341 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload) |
| 342 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 343 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 344 | IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth) |
| 345 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom, |
| 346 | GetRedirectsFrom) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 347 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount) |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 348 | IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount, |
| 349 | GetNormalBrowserWindowCount) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 350 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow) |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 351 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBrowserLocale, GetBrowserLocale) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 352 | IPC_MESSAGE_HANDLER(AutomationMsg_LastActiveBrowserWindow, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 353 | GetLastActiveBrowserWindow) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 354 | IPC_MESSAGE_HANDLER(AutomationMsg_ActiveWindow, GetActiveWindow) |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 355 | IPC_MESSAGE_HANDLER(AutomationMsg_FindNormalBrowserWindow, |
| 356 | FindNormalBrowserWindow) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 357 | IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActive, IsWindowActive) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 358 | IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow) |
[email protected] | 8dd404bb | 2009-09-22 19:57:24 | [diff] [blame] | 359 | IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowMaximized, IsWindowMaximized) |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 360 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 361 | ExecuteBrowserCommandAsync) |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 362 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 363 | ExecuteBrowserCommand) |
[email protected] | 8dd404bb | 2009-09-22 19:57:24 | [diff] [blame] | 364 | IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 365 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) |
[email protected] | 8dd404bb | 2009-09-22 19:57:24 | [diff] [blame] | 366 | IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) |
[email protected] | 8f04ff9 | 2009-07-08 02:37:15 | [diff] [blame] | 367 | IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 368 | IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) |
[email protected] | d1a5941e | 2009-08-13 23:34:24 | [diff] [blame] | 369 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) |
[email protected] | 60507b1 | 2009-11-02 23:51:35 | [diff] [blame] | 370 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 371 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 372 | #if !defined(OS_MACOSX) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 373 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, |
| 374 | WindowSimulateDrag) |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 375 | #endif // !defined(OS_MACOSX) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 376 | IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount) |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 377 | IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 378 | IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab) |
[email protected] | d7fa755 | 2009-03-20 21:06:37 | [diff] [blame] | 379 | #if defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 380 | IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND) |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 381 | #endif // defined(OS_WIN) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 382 | IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID) |
| 383 | IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle) |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 384 | IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 385 | IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 386 | IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility) |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 387 | IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen) |
| 388 | IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible, |
| 389 | GetFullscreenBubbleVisibility) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 390 | IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 391 | IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 392 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, |
| 393 | ExecuteJavascript) |
| 394 | IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 395 | GetConstrainedWindowCount) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 396 | IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest) |
| 397 | IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 398 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, |
| 399 | HandleInspectElementRequest) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 400 | IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory) |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 401 | IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig); |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 402 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 403 | OpenNewBrowserWindow) |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 404 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, |
| 405 | OpenNewBrowserWindowOfType) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 406 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 407 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 408 | GetAutocompleteEditForBrowser) |
| 409 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 410 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 411 | ShowInterstitialPage) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 412 | IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage, |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 413 | HideInterstitialPage) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 414 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, |
| 415 | WaitForTabToBeRestored) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 416 | IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState) |
| 417 | IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType) |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 418 | IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration, |
| 419 | GetMetricEventDuration) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 420 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage, |
| 421 | ActionOnSSLBlockingPage) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 422 | IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront) |
| 423 | IPC_MESSAGE_HANDLER(AutomationMsg_IsPageMenuCommandEnabled, |
| 424 | IsPageMenuCommandEnabled) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 425 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow) |
[email protected] | d301c95 | 2009-07-13 15:02:41 | [diff] [blame] | 426 | IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 427 | IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage) |
| 428 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 429 | GetAutocompleteEditText) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 430 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 431 | SetAutocompleteEditText) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 432 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 433 | AutocompleteEditIsQueryInProgress) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 434 | IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 435 | AutocompleteEditGetMatches) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 436 | IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage, |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 437 | HandleOpenFindInPageRequest) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 438 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 439 | IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility, |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 440 | GetFindWindowVisibility) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 441 | IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation, |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 442 | HandleFindWindowLocationRequest) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 443 | IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility, |
| 444 | GetBookmarkBarVisibility) |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 445 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBookmarksAsJSON, |
| 446 | GetBookmarksAsJSON) |
| 447 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForBookmarkModelToLoad, |
| 448 | WaitForBookmarkModelToLoad) |
| 449 | IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkGroup, |
| 450 | AddBookmarkGroup) |
| 451 | IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkURL, |
| 452 | AddBookmarkURL) |
| 453 | IPC_MESSAGE_HANDLER(AutomationMsg_ReparentBookmark, |
| 454 | ReparentBookmark) |
| 455 | IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkTitle, |
| 456 | SetBookmarkTitle) |
| 457 | IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkURL, |
| 458 | SetBookmarkURL) |
| 459 | IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBookmark, |
| 460 | RemoveBookmark) |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 461 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest, |
| 462 | SendJSONRequest) |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 463 | IPC_MESSAGE_HANDLER(AutomationMsg_GetInfoBarCount, GetInfoBarCount) |
| 464 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickInfoBarAccept, |
| 465 | ClickInfoBarAccept) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 466 | IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime, |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 467 | GetLastNavigationTime) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 468 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation, |
| 469 | WaitForNavigation) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 470 | IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference, SetIntPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 471 | IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog, |
[email protected] | c274acc | 2008-11-11 20:13:44 | [diff] [blame] | 472 | GetShowingAppModalDialog) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 473 | IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton, |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 474 | ClickAppModalDialogButton) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 475 | IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference, SetStringPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 476 | IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 477 | GetBooleanPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 478 | IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 479 | SetBooleanPreference) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 480 | IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 481 | GetPageCurrentEncoding) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 482 | IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding) |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 483 | IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser, |
| 484 | SavePackageShouldPromptUser) |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 485 | IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle) |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 486 | IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility) |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 487 | IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount) |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 488 | IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll) |
| 489 | IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut) |
| 490 | IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy) |
| 491 | IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste) |
| 492 | IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync) |
| 493 | IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync) |
[email protected] | 2949e90d | 2009-08-21 15:32:52 | [diff] [blame] | 494 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 495 | AutomationMsg_WaitForBrowserWindowCountToBecome, |
| 496 | WaitForBrowserWindowCountToBecome) |
| 497 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 498 | AutomationMsg_WaitForAppModalDialogToBeShown, |
| 499 | WaitForAppModalDialogToBeShown) |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 500 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 501 | AutomationMsg_GoBackBlockUntilNavigationsComplete, |
| 502 | GoBackBlockUntilNavigationsComplete) |
| 503 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 504 | AutomationMsg_GoForwardBlockUntilNavigationsComplete, |
| 505 | GoForwardBlockUntilNavigationsComplete) |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 506 | IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize) |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 507 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension, |
| 508 | InstallExtension) |
| 509 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoadExpandedExtension, |
| 510 | LoadExpandedExtension) |
[email protected] | a1e62d1 | 2010-03-16 02:18:43 | [diff] [blame] | 511 | IPC_MESSAGE_HANDLER(AutomationMsg_GetEnabledExtensions, |
| 512 | GetEnabledExtensions) |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 513 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForExtensionTestResult, |
| 514 | WaitForExtensionTestResult) |
| 515 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 516 | AutomationMsg_InstallExtensionAndGetHandle, |
| 517 | InstallExtensionAndGetHandle) |
| 518 | IPC_MESSAGE_HANDLER(AutomationMsg_UninstallExtension, |
| 519 | UninstallExtension) |
| 520 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EnableExtension, |
| 521 | EnableExtension) |
| 522 | IPC_MESSAGE_HANDLER(AutomationMsg_DisableExtension, |
| 523 | DisableExtension) |
| 524 | IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| 525 | AutomationMsg_ExecuteExtensionActionInActiveTabAsync, |
| 526 | ExecuteExtensionActionInActiveTabAsync) |
| 527 | IPC_MESSAGE_HANDLER(AutomationMsg_MoveExtensionBrowserAction, |
| 528 | MoveExtensionBrowserAction) |
| 529 | IPC_MESSAGE_HANDLER(AutomationMsg_GetExtensionProperty, |
| 530 | GetExtensionProperty) |
[email protected] | fedaa7d | 2010-01-26 20:34:57 | [diff] [blame] | 531 | IPC_MESSAGE_HANDLER(AutomationMsg_ShutdownSessionService, |
| 532 | ShutdownSessionService) |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 533 | IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync) |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 534 | IPC_MESSAGE_HANDLER(AutomationMsg_SetContentSetting, SetContentSetting) |
[email protected] | bc73b4e5 | 2010-03-26 04:16:20 | [diff] [blame] | 535 | IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData) |
[email protected] | bdd5a9c9 | 2010-06-14 18:21:00 | [diff] [blame] | 536 | IPC_MESSAGE_HANDLER(AutomationMsg_ResetToDefaultTheme, ResetToDefaultTheme) |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 537 | #if defined(TOOLKIT_VIEWS) |
| 538 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForFocusedViewIDToChange, |
| 539 | WaitForFocusedViewIDToChange) |
| 540 | IPC_MESSAGE_HANDLER(AutomationMsg_StartTrackingPopupMenus, |
| 541 | StartTrackingPopupMenus) |
| 542 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForPopupMenuToOpen, |
| 543 | WaitForPopupMenuToOpen) |
[email protected] | bdd5a9c9 | 2010-06-14 18:21:00 | [diff] [blame] | 544 | #endif // defined(TOOLKIT_VIEWS) |
[email protected] | 52415f84 | 2010-06-10 21:51:52 | [diff] [blame] | 545 | #if defined(OS_WIN) |
| 546 | // These are for use with external tabs. |
| 547 | IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab) |
| 548 | IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator, |
| 549 | ProcessUnhandledAccelerator) |
| 550 | IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus) |
| 551 | IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition) |
| 552 | IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome, |
| 553 | OnForwardContextMenuCommandToChrome) |
| 554 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab, |
| 555 | NavigateInExternalTab) |
| 556 | IPC_MESSAGE_HANDLER(AutomationMsg_NavigateExternalTabAtIndex, |
| 557 | NavigateExternalTabAtIndex) |
| 558 | IPC_MESSAGE_HANDLER(AutomationMsg_ConnectExternalTab, ConnectExternalTab) |
| 559 | IPC_MESSAGE_HANDLER(AutomationMsg_SetEnableExtensionAutomation, |
| 560 | SetEnableExtensionAutomation) |
| 561 | IPC_MESSAGE_HANDLER(AutomationMsg_HandleMessageFromExternalHost, |
| 562 | OnMessageFromExternalHost) |
[email protected] | bdd5a9c9 | 2010-06-14 18:21:00 | [diff] [blame] | 563 | IPC_MESSAGE_HANDLER(AutomationMsg_BrowserMove, OnBrowserMoved) |
[email protected] | 1f71d588 | 2010-07-15 20:39:07 | [diff] [blame] | 564 | IPC_MESSAGE_HANDLER(AutomationMsg_RunUnloadHandlers, OnRunUnloadHandlers) |
[email protected] | bdd5a9c9 | 2010-06-14 18:21:00 | [diff] [blame] | 565 | #endif // defined(OS_WIN) |
| 566 | #if defined(OS_CHROMEOS) |
| 567 | IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoginWithUserAndPass, |
| 568 | LoginWithUserAndPass) |
| 569 | #endif // defined(OS_CHROMEOS) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 570 | IPC_END_MESSAGE_MAP() |
| 571 | } |
| 572 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 573 | void AutomationProvider::ActivateTab(int handle, int at_index, int* status) { |
| 574 | *status = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 575 | if (browser_tracker_->ContainsHandle(handle) && at_index > -1) { |
| 576 | Browser* browser = browser_tracker_->GetResource(handle); |
| 577 | if (at_index >= 0 && at_index < browser->tab_count()) { |
| 578 | browser->SelectTabContentsAt(at_index, true); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 579 | *status = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 580 | } |
| 581 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 582 | } |
| 583 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 584 | void AutomationProvider::AppendTab(int handle, const GURL& url, |
| 585 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 586 | int append_tab_response = -1; // -1 is the error code |
| 587 | NotificationObserver* observer = NULL; |
| 588 | |
| 589 | if (browser_tracker_->ContainsHandle(handle)) { |
| 590 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 591 | observer = AddTabStripObserver(browser, reply_message); |
[email protected] | 715af7e | 2010-04-29 01:55:38 | [diff] [blame] | 592 | TabContents* tab_contents = browser->AddTabWithURL( |
[email protected] | 4a166544 | 2010-06-28 16:09:39 | [diff] [blame] | 593 | url, GURL(), PageTransition::TYPED, -1, TabStripModel::ADD_SELECTED, |
| 594 | NULL, std::string()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 595 | if (tab_contents) { |
| 596 | append_tab_response = |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 597 | GetIndexForNavigationController(&tab_contents->controller(), browser); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 598 | } |
| 599 | } |
| 600 | |
| 601 | if (append_tab_response < 0) { |
| 602 | // The append tab failed. Remove the TabStripObserver |
| 603 | if (observer) { |
[email protected] | faf2ee4 | 2010-05-11 14:26:17 | [diff] [blame] | 604 | RemoveTabStripObserver(observer); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 605 | delete observer; |
| 606 | } |
| 607 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 608 | AutomationMsg_AppendTab::WriteReplyParams(reply_message, |
| 609 | append_tab_response); |
| 610 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 614 | void AutomationProvider::NavigateToURL(int handle, const GURL& url, |
| 615 | IPC::Message* reply_message) { |
[email protected] | 2e028a08 | 2009-08-19 20:32:58 | [diff] [blame] | 616 | NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message); |
| 617 | } |
| 618 | |
| 619 | void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete( |
| 620 | int handle, const GURL& url, int number_of_navigations, |
| 621 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 622 | if (tab_tracker_->ContainsHandle(handle)) { |
| 623 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 624 | |
| 625 | // Simulate what a user would do. Activate the tab and then navigate. |
| 626 | // We could allow navigating in a background tab in future. |
| 627 | Browser* browser = FindAndActivateTab(tab); |
| 628 | |
| 629 | if (browser) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 630 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 631 | false); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 632 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 633 | // TODO(darin): avoid conversion to GURL |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 634 | browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 635 | return; |
| 636 | } |
| 637 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 638 | |
| 639 | AutomationMsg_NavigateToURL::WriteReplyParams( |
| 640 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 641 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 642 | } |
[email protected] | 2949e90d | 2009-08-21 15:32:52 | [diff] [blame] | 643 | |
[email protected] | c70f9b8 | 2010-04-21 07:31:11 | [diff] [blame] | 644 | void AutomationProvider::NavigationAsync(int handle, |
| 645 | const GURL& url, |
| 646 | bool* status) { |
| 647 | NavigationAsyncWithDisposition(handle, url, CURRENT_TAB, status); |
| 648 | } |
| 649 | |
| 650 | void AutomationProvider::NavigationAsyncWithDisposition( |
| 651 | int handle, |
| 652 | const GURL& url, |
| 653 | WindowOpenDisposition disposition, |
| 654 | bool* status) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 655 | *status = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 656 | |
| 657 | if (tab_tracker_->ContainsHandle(handle)) { |
| 658 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 659 | |
| 660 | // Simulate what a user would do. Activate the tab and then navigate. |
| 661 | // We could allow navigating in a background tab in future. |
| 662 | Browser* browser = FindAndActivateTab(tab); |
| 663 | |
| 664 | if (browser) { |
| 665 | // Don't add any listener unless a callback mechanism is desired. |
| 666 | // TODO(vibhor): Do this if such a requirement arises in future. |
[email protected] | c70f9b8 | 2010-04-21 07:31:11 | [diff] [blame] | 667 | browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 668 | *status = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 669 | } |
| 670 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 671 | } |
| 672 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 673 | void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 674 | if (tab_tracker_->ContainsHandle(handle)) { |
| 675 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 676 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 677 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 678 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 679 | browser->GoBack(CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 680 | return; |
| 681 | } |
| 682 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 683 | |
| 684 | AutomationMsg_GoBack::WriteReplyParams( |
| 685 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 686 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 687 | } |
| 688 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 689 | void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 690 | if (tab_tracker_->ContainsHandle(handle)) { |
| 691 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 692 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 693 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 694 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 695 | browser->GoForward(CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 696 | return; |
| 697 | } |
| 698 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 699 | |
| 700 | AutomationMsg_GoForward::WriteReplyParams( |
| 701 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 702 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 703 | } |
| 704 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 705 | void AutomationProvider::Reload(int handle, IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 706 | if (tab_tracker_->ContainsHandle(handle)) { |
| 707 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 708 | Browser* browser = FindAndActivateTab(tab); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 709 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 710 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 711 | browser->Reload(CURRENT_TAB); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 715 | |
| 716 | AutomationMsg_Reload::WriteReplyParams( |
| 717 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 718 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 719 | } |
| 720 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 721 | void AutomationProvider::SetAuth(int tab_handle, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 722 | const std::wstring& username, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 723 | const std::wstring& password, |
| 724 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 725 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 726 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 727 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 728 | |
| 729 | if (iter != login_handler_map_.end()) { |
| 730 | // If auth is needed again after this, assume login has failed. This is |
| 731 | // not strictly correct, because a navigation can require both proxy and |
| 732 | // server auth, but it should be OK for now. |
| 733 | LoginHandler* handler = iter->second; |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 734 | AddNavigationStatusListener(tab, reply_message, 1, false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 735 | handler->SetAuth(username, password); |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 736 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 737 | } |
| 738 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 739 | |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 740 | AutomationMsg_SetAuth::WriteReplyParams( |
| 741 | reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); |
| 742 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 743 | } |
| 744 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 745 | void AutomationProvider::CancelAuth(int tab_handle, |
| 746 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 747 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 748 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 749 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 750 | |
| 751 | if (iter != login_handler_map_.end()) { |
| 752 | // If auth is needed again after this, something is screwy. |
| 753 | LoginHandler* handler = iter->second; |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 754 | AddNavigationStatusListener(tab, reply_message, 1, false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 755 | handler->CancelAuth(); |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 756 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 757 | } |
| 758 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 759 | |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 760 | AutomationMsg_CancelAuth::WriteReplyParams( |
| 761 | reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); |
| 762 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 763 | } |
| 764 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 765 | void AutomationProvider::NeedsAuth(int tab_handle, bool* needs_auth) { |
| 766 | *needs_auth = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 767 | |
| 768 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 769 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 770 | LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
| 771 | |
| 772 | if (iter != login_handler_map_.end()) { |
| 773 | // The LoginHandler will be in our map IFF the tab needs auth. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 774 | *needs_auth = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 775 | } |
| 776 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 777 | } |
| 778 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 779 | void AutomationProvider::GetRedirectsFrom(int tab_handle, |
| 780 | const GURL& source_url, |
| 781 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 782 | DCHECK(!redirect_query_) << "Can only handle one redirect query at once."; |
| 783 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 784 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 785 | HistoryService* history_service = |
| 786 | tab->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 787 | |
| 788 | DCHECK(history_service) << "Tab " << tab_handle << "'s profile " << |
| 789 | "has no history service"; |
| 790 | if (history_service) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 791 | DCHECK(reply_message_ == NULL); |
| 792 | reply_message_ = reply_message; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 793 | // Schedule a history query for redirects. The response will be sent |
| 794 | // asynchronously from the callback the history system uses to notify us |
| 795 | // that it's done: OnRedirectQueryComplete. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 796 | redirect_query_ = history_service->QueryRedirectsFrom( |
| 797 | source_url, &consumer_, |
| 798 | NewCallback(this, &AutomationProvider::OnRedirectQueryComplete)); |
| 799 | return; // Response will be sent when query completes. |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | // Send failure response. |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 804 | std::vector<GURL> empty; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 805 | AutomationMsg_RedirectsFrom::WriteReplyParams(reply_message, false, empty); |
| 806 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 807 | } |
| 808 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 809 | void AutomationProvider::GetActiveTabIndex(int handle, int* active_tab_index) { |
| 810 | *active_tab_index = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 811 | if (browser_tracker_->ContainsHandle(handle)) { |
| 812 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 813 | *active_tab_index = browser->selected_index(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 814 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 815 | } |
| 816 | |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 817 | void AutomationProvider::GetBrowserLocale(string16* locale) { |
| 818 | DCHECK(g_browser_process); |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 819 | *locale = ASCIIToUTF16(g_browser_process->GetApplicationLocale()); |
[email protected] | 202e7a7 | 2009-06-15 03:48:36 | [diff] [blame] | 820 | } |
| 821 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 822 | void AutomationProvider::GetBrowserWindowCount(int* window_count) { |
| 823 | *window_count = static_cast<int>(BrowserList::size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 824 | } |
| 825 | |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 826 | void AutomationProvider::GetNormalBrowserWindowCount(int* window_count) { |
| 827 | *window_count = static_cast<int>( |
| 828 | BrowserList::GetBrowserCountForType(profile_, Browser::TYPE_NORMAL)); |
| 829 | } |
| 830 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 831 | void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, |
| 832 | int* dialog_button) { |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 833 | AppModalDialog* dialog_delegate = |
| 834 | Singleton<AppModalDialogQueue>()->active_dialog(); |
[email protected] | b3a7033 | 2009-02-25 02:40:50 | [diff] [blame] | 835 | *showing_dialog = (dialog_delegate != NULL); |
| 836 | if (*showing_dialog) |
| 837 | *dialog_button = dialog_delegate->GetDialogButtons(); |
| 838 | else |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 839 | *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 840 | } |
| 841 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 842 | void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { |
| 843 | *success = false; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 844 | |
[email protected] | 1f46007 | 2009-05-28 17:02:07 | [diff] [blame] | 845 | AppModalDialog* dialog_delegate = |
| 846 | Singleton<AppModalDialogQueue>()->active_dialog(); |
[email protected] | b3a7033 | 2009-02-25 02:40:50 | [diff] [blame] | 847 | if (dialog_delegate && |
| 848 | (dialog_delegate->GetDialogButtons() & button) == button) { |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 849 | if ((button & MessageBoxFlags::DIALOGBUTTON_OK) == |
| 850 | MessageBoxFlags::DIALOGBUTTON_OK) { |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 851 | dialog_delegate->AcceptWindow(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 852 | *success = true; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 853 | } |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 854 | if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) == |
| 855 | MessageBoxFlags::DIALOGBUTTON_CANCEL) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 856 | DCHECK(!*success) << "invalid param, OK and CANCEL specified"; |
[email protected] | 0bfa713f | 2009-04-07 20:18:28 | [diff] [blame] | 857 | dialog_delegate->CancelWindow(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 858 | *success = true; |
[email protected] | fad84eab | 2008-12-05 00:37:20 | [diff] [blame] | 859 | } |
| 860 | } |
[email protected] | c274acc | 2008-11-11 20:13:44 | [diff] [blame] | 861 | } |
| 862 | |
[email protected] | fedaa7d | 2010-01-26 20:34:57 | [diff] [blame] | 863 | void AutomationProvider::ShutdownSessionService(int handle, bool* result) { |
| 864 | if (browser_tracker_->ContainsHandle(handle)) { |
| 865 | Browser* browser = browser_tracker_->GetResource(handle); |
| 866 | browser->profile()->ShutdownSessionService(); |
| 867 | *result = true; |
| 868 | } else { |
| 869 | *result = false; |
| 870 | } |
| 871 | } |
| 872 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 873 | void AutomationProvider::GetBrowserWindow(int index, int* handle) { |
| 874 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 875 | if (index >= 0) { |
| 876 | BrowserList::const_iterator iter = BrowserList::begin(); |
[email protected] | f07467d | 2010-06-16 14:28:30 | [diff] [blame] | 877 | for (; (iter != BrowserList::end()) && (index > 0); ++iter, --index) {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 878 | if (iter != BrowserList::end()) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 879 | *handle = browser_tracker_->Add(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 880 | } |
| 881 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 882 | } |
| 883 | |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 884 | void AutomationProvider::FindNormalBrowserWindow(int* handle) { |
| 885 | *handle = 0; |
| 886 | Browser* browser = BrowserList::FindBrowserWithType(profile_, |
[email protected] | 62b0b53 | 2010-03-26 22:44:31 | [diff] [blame] | 887 | Browser::TYPE_NORMAL, |
| 888 | false); |
[email protected] | 2449703 | 2009-05-01 17:00:29 | [diff] [blame] | 889 | if (browser) |
| 890 | *handle = browser_tracker_->Add(browser); |
| 891 | } |
| 892 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 893 | void AutomationProvider::GetLastActiveBrowserWindow(int* handle) { |
| 894 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 895 | Browser* browser = BrowserList::GetLastActive(); |
| 896 | if (browser) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 897 | *handle = browser_tracker_->Add(browser); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | b2aa3ed7 | 2010-02-01 18:37:14 | [diff] [blame] | 900 | #if defined(OS_POSIX) |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame] | 901 | // TODO(estade): use this implementation for all platforms? |
| 902 | void AutomationProvider::GetActiveWindow(int* handle) { |
| 903 | gfx::NativeWindow window = |
| 904 | BrowserList::GetLastActive()->window()->GetNativeHandle(); |
| 905 | *handle = window_tracker_->Add(window); |
| 906 | } |
| 907 | #endif |
| 908 | |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 909 | void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command, |
| 910 | bool* success) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 911 | *success = false; |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 912 | if (browser_tracker_->ContainsHandle(handle)) { |
| 913 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 914 | if (browser->command_updater()->SupportsCommand(command) && |
| 915 | browser->command_updater()->IsCommandEnabled(command)) { |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 916 | browser->ExecuteCommand(command); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 917 | *success = true; |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 918 | } |
| 919 | } |
[email protected] | 4ae6275 | 2008-08-04 23:28:47 | [diff] [blame] | 920 | } |
| 921 | |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 922 | void AutomationProvider::ExecuteBrowserCommand( |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 923 | int handle, int command, IPC::Message* reply_message) { |
[email protected] | 12887da7 | 2009-09-16 19:15:53 | [diff] [blame] | 924 | // List of commands which just finish synchronously and don't require |
| 925 | // setting up an observer. |
| 926 | static const int kSynchronousCommands[] = { |
| 927 | IDC_HOME, |
| 928 | IDC_SELECT_NEXT_TAB, |
| 929 | IDC_SELECT_PREVIOUS_TAB, |
[email protected] | 2aa336e | 2010-04-06 21:05:25 | [diff] [blame] | 930 | IDC_SHOW_BOOKMARK_MANAGER, |
[email protected] | 12887da7 | 2009-09-16 19:15:53 | [diff] [blame] | 931 | }; |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 932 | if (browser_tracker_->ContainsHandle(handle)) { |
| 933 | Browser* browser = browser_tracker_->GetResource(handle); |
| 934 | if (browser->command_updater()->SupportsCommand(command) && |
| 935 | browser->command_updater()->IsCommandEnabled(command)) { |
[email protected] | 12887da7 | 2009-09-16 19:15:53 | [diff] [blame] | 936 | // First check if we can handle the command without using an observer. |
| 937 | for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { |
| 938 | if (command == kSynchronousCommands[i]) { |
| 939 | browser->ExecuteCommand(command); |
| 940 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, |
| 941 | true); |
| 942 | Send(reply_message); |
| 943 | return; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | // Use an observer if we have one, otherwise fail. |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 948 | if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( |
| 949 | this, browser, command, reply_message)) { |
[email protected] | 4e41709d | 2009-04-08 00:04:27 | [diff] [blame] | 950 | browser->ExecuteCommand(command); |
[email protected] | d79ffea | 2009-05-07 20:51:42 | [diff] [blame] | 951 | return; |
| 952 | } |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 953 | } |
| 954 | } |
[email protected] | 49a14a8 | 2009-03-31 04:16:44 | [diff] [blame] | 955 | AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); |
[email protected] | 56e71b7c | 2009-03-27 03:05:56 | [diff] [blame] | 956 | Send(reply_message); |
| 957 | } |
| 958 | |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 959 | // This task just adds another task to the event queue. This is useful if |
| 960 | // you want to ensure that any tasks added to the event queue after this one |
| 961 | // have already been processed by the time |task| is run. |
| 962 | class InvokeTaskLaterTask : public Task { |
| 963 | public: |
| 964 | explicit InvokeTaskLaterTask(Task* task) : task_(task) {} |
| 965 | virtual ~InvokeTaskLaterTask() {} |
| 966 | |
| 967 | virtual void Run() { |
| 968 | MessageLoop::current()->PostTask(FROM_HERE, task_); |
| 969 | } |
| 970 | |
| 971 | private: |
| 972 | Task* task_; |
| 973 | |
| 974 | DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask); |
| 975 | }; |
| 976 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 977 | void AutomationProvider::WindowSimulateClick(const IPC::Message& message, |
| 978 | int handle, |
[email protected] | d1a5941e | 2009-08-13 23:34:24 | [diff] [blame] | 979 | const gfx::Point& click, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 980 | int flags) { |
[email protected] | b410bc3 | 2009-08-14 01:11:14 | [diff] [blame] | 981 | if (window_tracker_->ContainsHandle(handle)) { |
[email protected] | c2cb854 | 2009-08-20 21:16:51 | [diff] [blame] | 982 | ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(), |
[email protected] | fc2e087 | 2009-08-21 22:14:41 | [diff] [blame] | 983 | new ClickTask(flags)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
[email protected] | 60507b1 | 2009-11-02 23:51:35 | [diff] [blame] | 987 | void AutomationProvider::WindowSimulateMouseMove(const IPC::Message& message, |
| 988 | int handle, |
| 989 | const gfx::Point& location) { |
| 990 | if (window_tracker_->ContainsHandle(handle)) |
| 991 | ui_controls::SendMouseMove(location.x(), location.y()); |
| 992 | } |
| 993 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 994 | void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message, |
| 995 | int handle, |
[email protected] | bc1407f | 2009-09-29 00:33:35 | [diff] [blame] | 996 | int key, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 997 | int flags) { |
[email protected] | b410bc3 | 2009-08-14 01:11:14 | [diff] [blame] | 998 | if (!window_tracker_->ContainsHandle(handle)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 999 | return; |
| 1000 | |
[email protected] | b410bc3 | 2009-08-14 01:11:14 | [diff] [blame] | 1001 | gfx::NativeWindow window = window_tracker_->GetResource(handle); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1002 | // The key event is sent to whatever window is active. |
[email protected] | bc1407f | 2009-09-29 00:33:35 | [diff] [blame] | 1003 | ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key), |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 1004 | ((flags & views::Event::EF_CONTROL_DOWN) == |
| 1005 | views::Event::EF_CONTROL_DOWN), |
| 1006 | ((flags & views::Event::EF_SHIFT_DOWN) == |
| 1007 | views::Event::EF_SHIFT_DOWN), |
| 1008 | ((flags & views::Event::EF_ALT_DOWN) == |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame] | 1009 | views::Event::EF_ALT_DOWN), |
| 1010 | ((flags & views::Event::EF_COMMAND_DOWN) == |
| 1011 | views::Event::EF_COMMAND_DOWN)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1012 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1013 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1014 | void AutomationProvider::IsWindowActive(int handle, bool* success, |
| 1015 | bool* is_active) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1016 | if (window_tracker_->ContainsHandle(handle)) { |
[email protected] | d2cc6ed | 2009-04-24 00:26:17 | [diff] [blame] | 1017 | *is_active = |
| 1018 | platform_util::IsWindowActive(window_tracker_->GetResource(handle)); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1019 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1020 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1021 | *success = false; |
| 1022 | *is_active = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1026 | void AutomationProvider::GetTabCount(int handle, int* tab_count) { |
| 1027 | *tab_count = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1028 | |
| 1029 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1030 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1031 | *tab_count = browser->tab_count(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1032 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1033 | } |
| 1034 | |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 1035 | void AutomationProvider::GetType(int handle, int* type_as_int) { |
| 1036 | *type_as_int = -1; // -1 is the error code |
| 1037 | |
| 1038 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1039 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1040 | *type_as_int = static_cast<int>(browser->type()); |
| 1041 | } |
| 1042 | } |
| 1043 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1044 | void AutomationProvider::GetTab(int win_handle, int tab_index, |
| 1045 | int* tab_handle) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1046 | *tab_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1047 | if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) { |
| 1048 | Browser* browser = browser_tracker_->GetResource(win_handle); |
| 1049 | if (tab_index < browser->tab_count()) { |
| 1050 | TabContents* tab_contents = |
| 1051 | browser->GetTabContentsAt(tab_index); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1052 | *tab_handle = tab_tracker_->Add(&tab_contents->controller()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1053 | } |
| 1054 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1055 | } |
| 1056 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1057 | void AutomationProvider::GetTabTitle(int handle, int* title_string_size, |
| 1058 | std::wstring* title) { |
| 1059 | *title_string_size = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1060 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1061 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | c100dbd | 2009-04-29 23:44:36 | [diff] [blame] | 1062 | NavigationEntry* entry = tab->GetActiveEntry(); |
| 1063 | if (entry != NULL) { |
| 1064 | *title = UTF16ToWideHack(entry->title()); |
| 1065 | } else { |
| 1066 | *title = std::wstring(); |
| 1067 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1068 | *title_string_size = static_cast<int>(title->size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1069 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1070 | } |
| 1071 | |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1072 | void AutomationProvider::GetTabIndex(int handle, int* tabstrip_index) { |
| 1073 | *tabstrip_index = -1; // -1 is the error code |
| 1074 | |
| 1075 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1076 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1077 | Browser* browser = Browser::GetBrowserForController(tab, NULL); |
[email protected] | 902cdf77 | 2009-05-06 15:08:12 | [diff] [blame] | 1078 | *tabstrip_index = browser->tabstrip_model()->GetIndexOfController(tab); |
[email protected] | 77bc673 | 2009-04-20 22:01:03 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1082 | void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) { |
| 1083 | if (window_tracker_->ContainsHandle(handle)) { |
| 1084 | window_tracker_->Remove(window_tracker_->GetResource(handle)); |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | void AutomationProvider::OnChannelError() { |
[email protected] | 2947cdcd | 2009-12-03 21:05:16 | [diff] [blame] | 1089 | LOG(INFO) << "AutomationProxy went away, shutting down app."; |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 1090 | AutomationProviderList::GetInstance()->RemoveProvider(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | // TODO(brettw) change this to accept GURLs when history supports it |
| 1094 | void AutomationProvider::OnRedirectQueryComplete( |
| 1095 | HistoryService::Handle request_handle, |
[email protected] | 3e377c5 | 2009-08-06 07:46:37 | [diff] [blame] | 1096 | GURL from_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1097 | bool success, |
[email protected] | 379c2b1 | 2009-07-01 21:50:33 | [diff] [blame] | 1098 | history::RedirectList* redirects) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1099 | DCHECK(request_handle == redirect_query_); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1100 | DCHECK(reply_message_ != NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1101 | |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1102 | std::vector<GURL> redirects_gurl; |
[email protected] | 0bc2448 | 2010-03-05 00:33:10 | [diff] [blame] | 1103 | reply_message_->WriteBool(success); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1104 | if (success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1105 | for (size_t i = 0; i < redirects->size(); i++) |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1106 | redirects_gurl.push_back(redirects->at(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1107 | } |
| 1108 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1109 | IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
[email protected] | deb5740 | 2009-02-06 01:35:30 | [diff] [blame] | 1110 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1111 | Send(reply_message_); |
[email protected] | 6a32946 | 2010-05-06 19:22:23 | [diff] [blame] | 1112 | redirect_query_ = 0; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1113 | reply_message_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | bool AutomationProvider::Send(IPC::Message* msg) { |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 1117 | DCHECK(channel_.get()); |
| 1118 | return channel_->Send(msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | Browser* AutomationProvider::FindAndActivateTab( |
| 1122 | NavigationController* controller) { |
| 1123 | int tab_index; |
| 1124 | Browser* browser = Browser::GetBrowserForController(controller, &tab_index); |
| 1125 | if (browser) |
| 1126 | browser->SelectTabContentsAt(tab_index, true); |
| 1127 | |
| 1128 | return browser; |
| 1129 | } |
| 1130 | |
[email protected] | 9eaa18e | 2010-06-29 20:51:01 | [diff] [blame] | 1131 | namespace { |
| 1132 | |
| 1133 | class GetCookiesTask : public Task { |
| 1134 | public: |
| 1135 | GetCookiesTask(const GURL& url, |
| 1136 | URLRequestContextGetter* context_getter, |
| 1137 | base::WaitableEvent* event, |
| 1138 | std::string* cookies) |
| 1139 | : url_(url), |
| 1140 | context_getter_(context_getter), |
| 1141 | event_(event), |
| 1142 | cookies_(cookies) {} |
| 1143 | |
| 1144 | virtual void Run() { |
| 1145 | *cookies_ = context_getter_->GetCookieStore()->GetCookies(url_); |
| 1146 | event_->Signal(); |
| 1147 | } |
| 1148 | |
| 1149 | private: |
| 1150 | const GURL& url_; |
| 1151 | URLRequestContextGetter* const context_getter_; |
| 1152 | base::WaitableEvent* const event_; |
| 1153 | std::string* const cookies_; |
| 1154 | |
| 1155 | DISALLOW_COPY_AND_ASSIGN(GetCookiesTask); |
| 1156 | }; |
| 1157 | |
| 1158 | std::string GetCookiesForURL( |
| 1159 | const GURL& url, |
| 1160 | URLRequestContextGetter* context_getter) { |
| 1161 | std::string cookies; |
| 1162 | base::WaitableEvent event(true /* manual reset */, |
| 1163 | false /* not initially signaled */); |
| 1164 | CHECK(ChromeThread::PostTask( |
| 1165 | ChromeThread::IO, FROM_HERE, |
| 1166 | new GetCookiesTask(url, context_getter, &event, &cookies))); |
| 1167 | event.Wait(); |
| 1168 | return cookies; |
| 1169 | } |
| 1170 | |
| 1171 | class SetCookieTask : public Task { |
| 1172 | public: |
| 1173 | SetCookieTask(const GURL& url, |
| 1174 | const std::string& value, |
| 1175 | URLRequestContextGetter* context_getter, |
| 1176 | base::WaitableEvent* event, |
| 1177 | bool* rv) |
| 1178 | : url_(url), |
| 1179 | value_(value), |
| 1180 | context_getter_(context_getter), |
| 1181 | event_(event), |
| 1182 | rv_(rv) {} |
| 1183 | |
| 1184 | virtual void Run() { |
| 1185 | *rv_ = context_getter_->GetCookieStore()->SetCookie(url_, value_); |
| 1186 | event_->Signal(); |
| 1187 | } |
| 1188 | |
| 1189 | private: |
| 1190 | const GURL& url_; |
| 1191 | const std::string& value_; |
| 1192 | URLRequestContextGetter* const context_getter_; |
| 1193 | base::WaitableEvent* const event_; |
| 1194 | bool* const rv_; |
| 1195 | |
| 1196 | DISALLOW_COPY_AND_ASSIGN(SetCookieTask); |
| 1197 | }; |
| 1198 | |
| 1199 | bool SetCookieForURL( |
| 1200 | const GURL& url, |
| 1201 | const std::string& value, |
| 1202 | URLRequestContextGetter* context_getter) { |
| 1203 | base::WaitableEvent event(true /* manual reset */, |
| 1204 | false /* not initially signaled */); |
| 1205 | bool rv = false; |
| 1206 | CHECK(ChromeThread::PostTask( |
| 1207 | ChromeThread::IO, FROM_HERE, |
| 1208 | new SetCookieTask(url, value, context_getter, &event, &rv))); |
| 1209 | event.Wait(); |
| 1210 | return rv; |
| 1211 | } |
| 1212 | |
| 1213 | class DeleteCookieTask : public Task { |
| 1214 | public: |
| 1215 | DeleteCookieTask(const GURL& url, |
| 1216 | const std::string& name, |
| 1217 | const scoped_refptr<URLRequestContextGetter>& context_getter) |
| 1218 | : url_(url), |
| 1219 | name_(name), |
| 1220 | context_getter_(context_getter) {} |
| 1221 | |
| 1222 | virtual void Run() { |
| 1223 | net::CookieStore* cookie_store = context_getter_->GetCookieStore(); |
| 1224 | cookie_store->DeleteCookie(url_, name_); |
| 1225 | } |
| 1226 | |
| 1227 | private: |
| 1228 | const GURL url_; |
| 1229 | const std::string name_; |
| 1230 | const scoped_refptr<URLRequestContextGetter> context_getter_; |
| 1231 | |
| 1232 | DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); |
| 1233 | }; |
| 1234 | |
| 1235 | } // namespace |
| 1236 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1237 | void AutomationProvider::GetCookies(const GURL& url, int handle, |
| 1238 | int* value_size, |
| 1239 | std::string* value) { |
| 1240 | *value_size = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1241 | if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 1242 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1243 | |
| 1244 | // Since we are running on the UI thread don't call GetURLRequestContext(). |
[email protected] | 70daf0b | 2010-03-02 19:13:00 | [diff] [blame] | 1245 | scoped_refptr<URLRequestContextGetter> request_context = |
| 1246 | tab->tab_contents()->request_context(); |
| 1247 | if (!request_context.get()) |
| 1248 | request_context = tab->profile()->GetRequestContext(); |
| 1249 | |
[email protected] | 9eaa18e | 2010-06-29 20:51:01 | [diff] [blame] | 1250 | *value = GetCookiesForURL(url, request_context.get()); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1251 | *value_size = static_cast<int>(value->size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1252 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1253 | } |
| 1254 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1255 | void AutomationProvider::SetCookie(const GURL& url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1256 | const std::string value, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1257 | int handle, |
| 1258 | int* response_value) { |
| 1259 | *response_value = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1260 | |
| 1261 | if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 1262 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1263 | |
[email protected] | dfa46e5f | 2009-11-17 18:48:43 | [diff] [blame] | 1264 | scoped_refptr<URLRequestContextGetter> request_context = |
| 1265 | tab->tab_contents()->request_context(); |
| 1266 | if (!request_context.get()) |
| 1267 | request_context = tab->profile()->GetRequestContext(); |
| 1268 | |
[email protected] | 9eaa18e | 2010-06-29 20:51:01 | [diff] [blame] | 1269 | if (SetCookieForURL(url, value, request_context.get())) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1270 | *response_value = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1271 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1272 | } |
| 1273 | |
[email protected] | 5fa5794 | 2010-04-21 23:07:22 | [diff] [blame] | 1274 | void AutomationProvider::DeleteCookie(const GURL& url, |
| 1275 | const std::string& cookie_name, |
| 1276 | int handle, bool* success) { |
| 1277 | *success = false; |
| 1278 | if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) { |
| 1279 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | 9eaa18e | 2010-06-29 20:51:01 | [diff] [blame] | 1280 | ChromeThread::PostTask( |
| 1281 | ChromeThread::IO, FROM_HERE, |
| 1282 | new DeleteCookieTask(url, cookie_name, |
| 1283 | tab->profile()->GetRequestContext())); |
[email protected] | 5fa5794 | 2010-04-21 23:07:22 | [diff] [blame] | 1284 | *success = true; |
| 1285 | } |
| 1286 | } |
| 1287 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1288 | void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) { |
| 1289 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1290 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1291 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1292 | // Return what the user would see in the location bar. |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1293 | *url = tab->GetActiveEntry()->virtual_url(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1294 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1295 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1296 | } |
| 1297 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1298 | void AutomationProvider::GetTabProcessID(int handle, int* process_id) { |
| 1299 | *process_id = -1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1300 | |
| 1301 | if (tab_tracker_->ContainsHandle(handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1302 | *process_id = 0; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1303 | TabContents* tab_contents = |
| 1304 | tab_tracker_->GetResource(handle)->tab_contents(); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1305 | RenderProcessHost* rph = tab_contents->GetRenderProcessHost(); |
| 1306 | if (rph) |
| 1307 | *process_id = base::GetProcId(rph->GetHandle()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1308 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | void AutomationProvider::ApplyAccelerator(int handle, int id) { |
[email protected] | 4f6381ee | 2009-04-16 02:46:33 | [diff] [blame] | 1312 | NOTREACHED() << "This function has been deprecated. " |
| 1313 | << "Please use ExecuteBrowserCommandAsync instead."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1314 | } |
| 1315 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1316 | void AutomationProvider::ExecuteJavascript(int handle, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1317 | const std::wstring& frame_xpath, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1318 | const std::wstring& script, |
| 1319 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1320 | bool succeeded = false; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1321 | TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
| 1322 | if (tab_contents) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1323 | // Set the routing id of this message with the controller. |
| 1324 | // This routing id needs to be remembered for the reverse |
| 1325 | // communication while sending back the response of |
| 1326 | // this javascript execution. |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 1327 | std::wstring set_automation_id; |
| 1328 | SStringPrintf(&set_automation_id, |
| 1329 | L"window.domAutomationController.setAutomationId(%d);", |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1330 | reply_message->routing_id()); |
| 1331 | |
| 1332 | DCHECK(reply_message_ == NULL); |
| 1333 | reply_message_ = reply_message; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1334 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1335 | tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 1336 | frame_xpath, set_automation_id); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1337 | tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
[email protected] | 1f5af444 | 2008-09-25 22:11:06 | [diff] [blame] | 1338 | frame_xpath, script); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1339 | succeeded = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | if (!succeeded) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1343 | AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); |
| 1344 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1348 | void AutomationProvider::GetShelfVisibility(int handle, bool* visible) { |
| 1349 | *visible = false; |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1350 | |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1351 | if (browser_tracker_->ContainsHandle(handle)) { |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1352 | #if defined(OS_CHROMEOS) |
| 1353 | // Chromium OS shows FileBrowse ui rather than download shelf. So we |
| 1354 | // enumerate all browsers and look for a chrome://filebrowse... pop up. |
| 1355 | for (BrowserList::const_iterator it = BrowserList::begin(); |
| 1356 | it != BrowserList::end(); ++it) { |
| 1357 | if ((*it)->type() == Browser::TYPE_POPUP) { |
| 1358 | const GURL& url = |
| 1359 | (*it)->GetTabContentsAt((*it)->selected_index())->GetURL(); |
| 1360 | |
| 1361 | if (url.SchemeIs(chrome::kChromeUIScheme) && |
| 1362 | url.host() == chrome::kChromeUIFileBrowseHost) { |
| 1363 | *visible = true; |
| 1364 | break; |
| 1365 | } |
| 1366 | } |
| 1367 | } |
| 1368 | #else |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1369 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1370 | if (browser) { |
| 1371 | *visible = browser->window()->IsDownloadShelfVisible(); |
| 1372 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1373 | #endif |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1374 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1375 | } |
| 1376 | |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1377 | void AutomationProvider::SetShelfVisibility(int handle, bool visible) { |
| 1378 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1379 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1380 | if (browser) { |
| 1381 | if (visible) |
| 1382 | browser->window()->GetDownloadShelf()->Show(); |
| 1383 | else |
| 1384 | browser->window()->GetDownloadShelf()->Close(); |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 1389 | void AutomationProvider::IsFullscreen(int handle, bool* visible) { |
| 1390 | *visible = false; |
| 1391 | |
| 1392 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1393 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1394 | if (browser) |
| 1395 | *visible = browser->window()->IsFullscreen(); |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | void AutomationProvider::GetFullscreenBubbleVisibility(int handle, |
| 1400 | bool* visible) { |
| 1401 | *visible = false; |
| 1402 | |
| 1403 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1404 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1405 | if (browser) |
| 1406 | *visible = browser->window()->IsFullscreenBubbleVisible(); |
| 1407 | } |
| 1408 | } |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1409 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1410 | void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) { |
| 1411 | *count = -1; // -1 is the error code |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1412 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1413 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 1414 | TabContents* tab_contents = nav_controller->tab_contents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1415 | if (tab_contents) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1416 | *count = static_cast<int>(tab_contents->child_windows_.size()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1417 | } |
| 1418 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1419 | } |
| 1420 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1421 | void AutomationProvider::HandleFindInPageRequest( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1422 | int handle, const std::wstring& find_request, |
| 1423 | int forward, int match_case, int* active_ordinal, int* matches_found) { |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 1424 | NOTREACHED() << "This function has been deprecated." |
| 1425 | << "Please use HandleFindRequest instead."; |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1426 | *matches_found = -1; |
[email protected] | 5a52f16 | 2008-08-27 04:15:31 | [diff] [blame] | 1427 | return; |
| 1428 | } |
| 1429 | |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 1430 | void AutomationProvider::HandleFindRequest( |
| 1431 | int handle, |
| 1432 | const AutomationMsg_Find_Params& params, |
| 1433 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1434 | if (!tab_tracker_->ContainsHandle(handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1435 | AutomationMsg_FindInPage::WriteReplyParams(reply_message, -1, -1); |
| 1436 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1437 | return; |
| 1438 | } |
| 1439 | |
| 1440 | NavigationController* nav = tab_tracker_->GetResource(handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 1441 | TabContents* tab_contents = nav->tab_contents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1442 | |
| 1443 | find_in_page_observer_.reset(new |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 1444 | FindInPageNotificationObserver(this, tab_contents, reply_message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1445 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1446 | tab_contents->set_current_find_request_id( |
| 1447 | FindInPageNotificationObserver::kFindInPageRequestId); |
| 1448 | tab_contents->render_view_host()->StartFinding( |
| 1449 | FindInPageNotificationObserver::kFindInPageRequestId, |
| 1450 | params.search_string, params.forward, params.match_case, |
| 1451 | params.find_next); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1452 | } |
| 1453 | |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 1454 | void AutomationProvider::HandleOpenFindInPageRequest( |
| 1455 | const IPC::Message& message, int handle) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1456 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1457 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1458 | browser->FindInPage(false, false); |
[email protected] | 5f8af2a | 2008-08-06 22:49:45 | [diff] [blame] | 1459 | } |
| 1460 | } |
| 1461 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1462 | void AutomationProvider::GetFindWindowVisibility(int handle, bool* visible) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1463 | *visible = false; |
[email protected] | 855c014 | 2009-09-28 22:35:24 | [diff] [blame] | 1464 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1465 | if (browser) { |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1466 | FindBarTesting* find_bar = |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1467 | browser->GetFindBarController()->find_bar()->GetFindBarTesting(); |
[email protected] | 855c014 | 2009-09-28 22:35:24 | [diff] [blame] | 1468 | find_bar->GetFindBarWindowInfo(NULL, visible); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1469 | } |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1470 | } |
| 1471 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1472 | void AutomationProvider::HandleFindWindowLocationRequest(int handle, int* x, |
| 1473 | int* y) { |
[email protected] | 9e0534b | 2008-10-21 15:03:01 | [diff] [blame] | 1474 | gfx::Point position(0, 0); |
| 1475 | bool visible = false; |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1476 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1477 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1478 | FindBarTesting* find_bar = |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1479 | browser->GetFindBarController()->find_bar()->GetFindBarTesting(); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1480 | find_bar->GetFindBarWindowInfo(&position, &visible); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1481 | } |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1482 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1483 | *x = position.x(); |
| 1484 | *y = position.y(); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 1485 | } |
| 1486 | |
[email protected] | 4512cb5 | 2010-04-05 19:50:25 | [diff] [blame] | 1487 | // Bookmark bar visibility is based on the pref (e.g. is it in the toolbar). |
| 1488 | // Presence in the NTP is NOT considered visible by this call. |
[email protected] | c324072 | 2010-03-05 21:52:58 | [diff] [blame] | 1489 | void AutomationProvider::GetBookmarkBarVisibility(int handle, |
| 1490 | bool* visible, |
| 1491 | bool* animating) { |
| 1492 | *visible = false; |
| 1493 | *animating = false; |
| 1494 | |
| 1495 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1496 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1497 | if (browser) { |
[email protected] | 472f099b | 2010-05-27 17:07:12 | [diff] [blame] | 1498 | #if 0 // defined(TOOLKIT_VIEWS) && defined(OS_LINUX) |
| 1499 | // TODO(jrg): Was removed in rev43789 for perf. Need to investigate. |
| 1500 | |
[email protected] | ab6ca39 | 2010-04-07 00:44:13 | [diff] [blame] | 1501 | // IsBookmarkBarVisible() line looks correct but is not |
| 1502 | // consistent across platforms. Specifically, on Mac/Linux, it |
| 1503 | // returns false if the bar is hidden in a pref (even if visible |
| 1504 | // on the NTP). On ChromeOS, it returned true if on NTP |
| 1505 | // independent of the pref. Making the code more consistent |
| 1506 | // caused a perf bot regression on Windows (which shares views). |
| 1507 | // See http://crbug.com/40225 |
[email protected] | 4512cb5 | 2010-04-05 19:50:25 | [diff] [blame] | 1508 | *visible = browser->profile()->GetPrefs()->GetBoolean( |
| 1509 | prefs::kShowBookmarkBar); |
[email protected] | 7e4cd4e8 | 2010-04-05 20:59:40 | [diff] [blame] | 1510 | #else |
| 1511 | *visible = browser->window()->IsBookmarkBarVisible(); |
| 1512 | #endif |
[email protected] | c324072 | 2010-03-05 21:52:58 | [diff] [blame] | 1513 | *animating = browser->window()->IsBookmarkBarAnimating(); |
| 1514 | } |
| 1515 | } |
| 1516 | } |
| 1517 | |
[email protected] | 6d8ffc9f | 2010-03-12 18:27:53 | [diff] [blame] | 1518 | void AutomationProvider::GetBookmarksAsJSON(int handle, |
| 1519 | std::string* bookmarks_as_json, |
| 1520 | bool *success) { |
| 1521 | *success = false; |
| 1522 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1523 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1524 | if (browser) { |
| 1525 | if (!browser->profile()->GetBookmarkModel()->IsLoaded()) { |
| 1526 | return; |
| 1527 | } |
| 1528 | scoped_refptr<BookmarkStorage> storage = new BookmarkStorage( |
| 1529 | browser->profile(), |
| 1530 | browser->profile()->GetBookmarkModel()); |
| 1531 | *success = storage->SerializeData(bookmarks_as_json); |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | void AutomationProvider::WaitForBookmarkModelToLoad( |
| 1537 | int handle, |
| 1538 | IPC::Message* reply_message) { |
| 1539 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1540 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1541 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1542 | if (model->IsLoaded()) { |
| 1543 | AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams( |
| 1544 | reply_message, true); |
| 1545 | Send(reply_message); |
| 1546 | } else { |
| 1547 | // The observer will delete itself when done. |
| 1548 | new AutomationProviderBookmarkModelObserver(this, reply_message, |
| 1549 | model); |
| 1550 | } |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | void AutomationProvider::AddBookmarkGroup(int handle, |
| 1555 | int64 parent_id, int index, |
| 1556 | std::wstring title, |
| 1557 | bool* success) { |
| 1558 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1559 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1560 | if (browser) { |
| 1561 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1562 | if (!model->IsLoaded()) { |
| 1563 | *success = false; |
| 1564 | return; |
| 1565 | } |
| 1566 | const BookmarkNode* parent = model->GetNodeByID(parent_id); |
| 1567 | DCHECK(parent); |
| 1568 | if (parent) { |
| 1569 | const BookmarkNode* child = model->AddGroup(parent, index, |
| 1570 | WideToUTF16(title)); |
| 1571 | DCHECK(child); |
| 1572 | if (child) |
| 1573 | *success = true; |
| 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | *success = false; |
| 1578 | } |
| 1579 | |
| 1580 | void AutomationProvider::AddBookmarkURL(int handle, |
| 1581 | int64 parent_id, int index, |
| 1582 | std::wstring title, const GURL& url, |
| 1583 | bool* success) { |
| 1584 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1585 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1586 | if (browser) { |
| 1587 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1588 | if (!model->IsLoaded()) { |
| 1589 | *success = false; |
| 1590 | return; |
| 1591 | } |
| 1592 | const BookmarkNode* parent = model->GetNodeByID(parent_id); |
| 1593 | DCHECK(parent); |
| 1594 | if (parent) { |
| 1595 | const BookmarkNode* child = model->AddURL(parent, index, |
| 1596 | WideToUTF16(title), url); |
| 1597 | DCHECK(child); |
| 1598 | if (child) |
| 1599 | *success = true; |
| 1600 | } |
| 1601 | } |
| 1602 | } |
| 1603 | *success = false; |
| 1604 | } |
| 1605 | |
| 1606 | void AutomationProvider::ReparentBookmark(int handle, |
| 1607 | int64 id, int64 new_parent_id, |
| 1608 | int index, |
| 1609 | bool* success) { |
| 1610 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1611 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1612 | if (browser) { |
| 1613 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1614 | if (!model->IsLoaded()) { |
| 1615 | *success = false; |
| 1616 | return; |
| 1617 | } |
| 1618 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1619 | DCHECK(node); |
| 1620 | const BookmarkNode* new_parent = model->GetNodeByID(new_parent_id); |
| 1621 | DCHECK(new_parent); |
| 1622 | if (node && new_parent) { |
| 1623 | model->Move(node, new_parent, index); |
| 1624 | *success = true; |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | *success = false; |
| 1629 | } |
| 1630 | |
| 1631 | void AutomationProvider::SetBookmarkTitle(int handle, |
| 1632 | int64 id, std::wstring title, |
| 1633 | bool* success) { |
| 1634 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1635 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1636 | if (browser) { |
| 1637 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1638 | if (!model->IsLoaded()) { |
| 1639 | *success = false; |
| 1640 | return; |
| 1641 | } |
| 1642 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1643 | DCHECK(node); |
| 1644 | if (node) { |
| 1645 | model->SetTitle(node, WideToUTF16(title)); |
| 1646 | *success = true; |
| 1647 | } |
| 1648 | } |
| 1649 | } |
| 1650 | *success = false; |
| 1651 | } |
| 1652 | |
| 1653 | void AutomationProvider::SetBookmarkURL(int handle, |
| 1654 | int64 id, const GURL& url, |
| 1655 | bool* success) { |
| 1656 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1657 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1658 | if (browser) { |
| 1659 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1660 | if (!model->IsLoaded()) { |
| 1661 | *success = false; |
| 1662 | return; |
| 1663 | } |
| 1664 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1665 | DCHECK(node); |
| 1666 | if (node) { |
| 1667 | model->SetURL(node, url); |
| 1668 | *success = true; |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | *success = false; |
| 1673 | } |
| 1674 | |
| 1675 | void AutomationProvider::RemoveBookmark(int handle, |
| 1676 | int64 id, |
| 1677 | bool* success) { |
| 1678 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1679 | Browser* browser = browser_tracker_->GetResource(handle); |
| 1680 | if (browser) { |
| 1681 | BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1682 | if (!model->IsLoaded()) { |
| 1683 | *success = false; |
| 1684 | return; |
| 1685 | } |
| 1686 | const BookmarkNode* node = model->GetNodeByID(id); |
| 1687 | DCHECK(node); |
| 1688 | if (node) { |
| 1689 | const BookmarkNode* parent = node->GetParent(); |
| 1690 | DCHECK(parent); |
| 1691 | model->Remove(parent, parent->IndexOfChild(node)); |
| 1692 | *success = true; |
| 1693 | } |
| 1694 | } |
| 1695 | } |
| 1696 | *success = false; |
| 1697 | } |
| 1698 | |
[email protected] | ef413ca | 2010-05-25 21:09:14 | [diff] [blame] | 1699 | // Sample json input: { "command": "SetWindowDimensions", |
| 1700 | // "x": 20, # optional |
| 1701 | // "y": 20, # optional |
| 1702 | // "width": 800, # optional |
| 1703 | // "height": 600 } # optional |
| 1704 | void AutomationProvider::SetWindowDimensions(Browser* browser, |
| 1705 | DictionaryValue* args, |
| 1706 | IPC::Message* reply_message) { |
| 1707 | gfx::Rect rect = browser->window()->GetRestoredBounds(); |
| 1708 | int x, y, width, height; |
| 1709 | if (args->GetInteger(L"x", &x)) |
| 1710 | rect.set_x(x); |
| 1711 | if (args->GetInteger(L"y", &y)) |
| 1712 | rect.set_y(y); |
| 1713 | if (args->GetInteger(L"width", &width)) |
| 1714 | rect.set_width(width); |
| 1715 | if (args->GetInteger(L"height", &height)) |
| 1716 | rect.set_height(height); |
| 1717 | browser->window()->SetBounds(rect); |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1718 | AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
[email protected] | ef413ca | 2010-05-25 21:09:14 | [diff] [blame] | 1719 | } |
| 1720 | |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 1721 | // Sample json input: { "command": "GetBrowserInfo" } |
| 1722 | // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for |
| 1723 | // sample json output. |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 1724 | void AutomationProvider::GetBrowserInfo(Browser* browser, |
| 1725 | DictionaryValue* args, |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 1726 | IPC::Message* reply_message) { |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 1727 | DictionaryValue* properties = new DictionaryValue; |
| 1728 | properties->SetString(L"ChromeVersion", chrome::kChromeVersion); |
| 1729 | properties->SetString(L"BrowserProcessExecutableName", |
| 1730 | chrome::kBrowserProcessExecutableName); |
| 1731 | properties->SetString(L"HelperProcessExecutableName", |
| 1732 | chrome::kHelperProcessExecutableName); |
| 1733 | properties->SetString(L"BrowserProcessExecutablePath", |
| 1734 | chrome::kBrowserProcessExecutablePath); |
| 1735 | properties->SetString(L"HelperProcessExecutablePath", |
| 1736 | chrome::kHelperProcessExecutablePath); |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 1737 | properties->SetString(L"command_line_string", |
| 1738 | CommandLine::ForCurrentProcess()->command_line_string()); |
[email protected] | 44eed9f | 2010-06-28 22:04:00 | [diff] [blame] | 1739 | |
| 1740 | std::string branding; |
| 1741 | #if defined(GOOGLE_CHROME_BUILD) |
| 1742 | branding = "Google Chrome"; |
| 1743 | #elif defined(CHROMIUM_BUILD) |
| 1744 | branding = "Chromium"; |
| 1745 | #else |
| 1746 | branding = "Unknown Branding"; |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 1747 | #endif |
[email protected] | 44eed9f | 2010-06-28 22:04:00 | [diff] [blame] | 1748 | properties->SetString(L"branding", branding); |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 1749 | |
| 1750 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1751 | return_value->Set(L"properties", properties); |
| 1752 | |
[email protected] | ef413ca | 2010-05-25 21:09:14 | [diff] [blame] | 1753 | return_value->SetInteger(L"browser_pid", base::GetCurrentProcId()); |
| 1754 | // Add info about all windows in a list of dictionaries, one dictionary |
| 1755 | // item per window. |
| 1756 | ListValue* windows = new ListValue; |
| 1757 | int windex = 0; |
| 1758 | for (BrowserList::const_iterator it = BrowserList::begin(); |
| 1759 | it != BrowserList::end(); |
| 1760 | ++it, ++windex) { |
| 1761 | DictionaryValue* browser_item = new DictionaryValue; |
| 1762 | browser = *it; |
| 1763 | browser_item->SetInteger(L"index", windex); |
| 1764 | // Window properties |
| 1765 | gfx::Rect rect = browser->window()->GetRestoredBounds(); |
| 1766 | browser_item->SetInteger(L"x", rect.x()); |
| 1767 | browser_item->SetInteger(L"y", rect.y()); |
| 1768 | browser_item->SetInteger(L"width", rect.width()); |
| 1769 | browser_item->SetInteger(L"height", rect.height()); |
| 1770 | browser_item->SetBoolean(L"fullscreen", |
| 1771 | browser->window()->IsFullscreen()); |
| 1772 | browser_item->SetInteger(L"selected_tab", browser->selected_index()); |
| 1773 | browser_item->SetBoolean(L"incognito", |
| 1774 | browser->profile()->IsOffTheRecord()); |
| 1775 | // For each window, add info about all tabs in a list of dictionaries, |
| 1776 | // one dictionary item per tab. |
| 1777 | ListValue* tabs = new ListValue; |
| 1778 | for (int i = 0; i < browser->tab_count(); ++i) { |
| 1779 | TabContents* tc = browser->GetTabContentsAt(i); |
| 1780 | DictionaryValue* tab = new DictionaryValue; |
| 1781 | tab->SetInteger(L"index", i); |
| 1782 | tab->SetString(L"url", tc->GetURL().spec()); |
| 1783 | tab->SetInteger(L"renderer_pid", |
| 1784 | base::GetProcId(tc->GetRenderProcessHost()->GetHandle())); |
| 1785 | tab->SetInteger(L"num_infobars", tc->infobar_delegate_count()); |
| 1786 | tabs->Append(tab); |
| 1787 | } |
| 1788 | browser_item->Set(L"tabs", tabs); |
| 1789 | |
| 1790 | windows->Append(browser_item); |
| 1791 | } |
| 1792 | return_value->Set(L"windows", windows); |
| 1793 | |
| 1794 | return_value->SetString(L"child_process_path", |
| 1795 | ChildProcessHost::GetChildPath(true).value()); |
| 1796 | // Child processes are the processes for plugins and other workers. |
| 1797 | // Add all child processes in a list of dictionaries, one dictionary item |
| 1798 | // per child process. |
| 1799 | ListValue* child_processes = new ListValue; |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 1800 | for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
[email protected] | ef413ca | 2010-05-25 21:09:14 | [diff] [blame] | 1801 | // Only add processes which are already started, since we need their handle. |
| 1802 | if ((*iter)->handle() != base::kNullProcessHandle) { |
| 1803 | ChildProcessInfo* info = *iter; |
| 1804 | DictionaryValue* item = new DictionaryValue; |
| 1805 | item->SetString(L"name", info->name()); |
| 1806 | item->SetString(L"type", |
| 1807 | ChildProcessInfo::GetTypeNameInEnglish(info->type())); |
| 1808 | item->SetInteger(L"pid", base::GetProcId(info->handle())); |
| 1809 | child_processes->Append(item); |
| 1810 | } |
| 1811 | } |
| 1812 | return_value->Set(L"child_processes", child_processes); |
| 1813 | |
| 1814 | // Add all extension processes in a list of dictionaries, one dictionary |
| 1815 | // item per extension process. |
| 1816 | ListValue* extension_processes = new ListValue; |
| 1817 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1818 | for (ProfileManager::const_iterator it = profile_manager->begin(); |
| 1819 | it != profile_manager->end(); ++it) { |
| 1820 | ExtensionProcessManager* process_manager = |
| 1821 | (*it)->GetExtensionProcessManager(); |
| 1822 | ExtensionProcessManager::const_iterator jt; |
| 1823 | for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) { |
| 1824 | ExtensionHost* ex_host = *jt; |
| 1825 | // Don't add dead extension processes. |
| 1826 | if (!ex_host->IsRenderViewLive()) |
| 1827 | continue; |
| 1828 | DictionaryValue* item = new DictionaryValue; |
| 1829 | item->SetString(L"name", ex_host->extension()->name()); |
| 1830 | item->SetInteger( |
| 1831 | L"pid", |
| 1832 | base::GetProcId(ex_host->render_process_host()->GetHandle())); |
| 1833 | extension_processes->Append(item); |
| 1834 | } |
| 1835 | } |
| 1836 | return_value->Set(L"extension_processes", extension_processes); |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1837 | AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 1838 | } |
| 1839 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1840 | // Sample json input: { "command": "GetHistoryInfo", |
| 1841 | // "search_text": "some text" } |
[email protected] | e6e376e | 2010-04-19 21:41:36 | [diff] [blame] | 1842 | // Refer chrome/test/pyautolib/history_info.py for sample json output. |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 1843 | void AutomationProvider::GetHistoryInfo(Browser* browser, |
| 1844 | DictionaryValue* args, |
| 1845 | IPC::Message* reply_message) { |
[email protected] | e6e376e | 2010-04-19 21:41:36 | [diff] [blame] | 1846 | consumer_.CancelAllRequests(); |
| 1847 | |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1848 | string16 search_text; |
| 1849 | args->GetString("search_text", &search_text); |
[email protected] | e6e376e | 2010-04-19 21:41:36 | [diff] [blame] | 1850 | |
| 1851 | // Fetch history. |
| 1852 | HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 1853 | history::QueryOptions options; |
| 1854 | // The observer owns itself. It deletes itself after it fetches history. |
| 1855 | AutomationProviderHistoryObserver* history_observer = |
| 1856 | new AutomationProviderHistoryObserver(this, reply_message); |
| 1857 | hs->QueryHistory( |
| 1858 | search_text, |
| 1859 | options, |
| 1860 | &consumer_, |
| 1861 | NewCallback(history_observer, |
| 1862 | &AutomationProviderHistoryObserver::HistoryQueryComplete)); |
| 1863 | } |
| 1864 | |
[email protected] | bbe6aa0 | 2010-05-07 17:27:29 | [diff] [blame] | 1865 | // Sample json input: { "command": "AddHistoryItem", |
| 1866 | // "item": { "URL": "http://www.google.com", |
| 1867 | // "title": "Google", # optional |
| 1868 | // "time": 12345 # optional (time_t) |
| 1869 | // } } |
| 1870 | // Refer chrome/test/pyautolib/pyauto.py for details on input. |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 1871 | void AutomationProvider::AddHistoryItem(Browser* browser, |
| 1872 | DictionaryValue* args, |
| 1873 | IPC::Message* reply_message) { |
[email protected] | bbe6aa0 | 2010-05-07 17:27:29 | [diff] [blame] | 1874 | DictionaryValue* item = NULL; |
| 1875 | args->GetDictionary(L"item", &item); |
| 1876 | string16 url_text; |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1877 | string16 title; |
[email protected] | bbe6aa0 | 2010-05-07 17:27:29 | [diff] [blame] | 1878 | base::Time time = base::Time::Now(); |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1879 | AutomationJSONReply reply(this, reply_message); |
[email protected] | bbe6aa0 | 2010-05-07 17:27:29 | [diff] [blame] | 1880 | |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1881 | if (!item->GetString("url", &url_text)) { |
| 1882 | reply.SendError("bad args (no URL in dict?)"); |
| 1883 | return; |
[email protected] | bbe6aa0 | 2010-05-07 17:27:29 | [diff] [blame] | 1884 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1885 | GURL gurl(url_text); |
| 1886 | item->GetString("title", &title); // Don't care if it fails. |
| 1887 | int it; |
| 1888 | double dt; |
| 1889 | if (item->GetInteger(L"time", &it)) |
| 1890 | time = base::Time::FromTimeT(it); |
| 1891 | else if (item->GetReal(L"time", &dt)) |
| 1892 | time = base::Time::FromDoubleT(dt); |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 1893 | |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1894 | // Ideas for "dummy" values (e.g. id_scope) came from |
| 1895 | // chrome/browser/autocomplete/history_contents_provider_unittest.cc |
| 1896 | HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 1897 | const void* id_scope = reinterpret_cast<void*>(1); |
| 1898 | hs->AddPage(gurl, time, |
| 1899 | id_scope, |
| 1900 | 0, |
| 1901 | GURL(), |
| 1902 | PageTransition::LINK, |
| 1903 | history::RedirectList(), |
| 1904 | false); |
| 1905 | if (title.length()) |
| 1906 | hs->SetPageTitle(gurl, title); |
| 1907 | reply.SendSuccess(NULL); |
[email protected] | bbe6aa0 | 2010-05-07 17:27:29 | [diff] [blame] | 1908 | } |
| 1909 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1910 | // Sample json input: { "command": "GetDownloadsInfo" } |
[email protected] | e6e376e | 2010-04-19 21:41:36 | [diff] [blame] | 1911 | // Refer chrome/test/pyautolib/download_info.py for sample json output. |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 1912 | void AutomationProvider::GetDownloadsInfo(Browser* browser, |
| 1913 | DictionaryValue* args, |
| 1914 | IPC::Message* reply_message) { |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1915 | AutomationProviderDownloadManagerObserver observer; |
| 1916 | std::vector<DownloadItem*> downloads; |
| 1917 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1918 | AutomationJSONReply reply(this, reply_message); |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1919 | |
| 1920 | if (!profile_->HasCreatedDownloadManager()) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1921 | reply.SendError("no download manager"); |
| 1922 | return; |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1923 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1924 | // Use DownloadManager's GetDownloads() method and not GetCurrentDownloads() |
| 1925 | // since that would be transient; a download might enter and empty out |
| 1926 | // the current download queue too soon to be noticed. |
| 1927 | profile_->GetDownloadManager()->GetDownloads(&observer, L""); |
| 1928 | downloads = observer.Downloads(); |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1929 | |
| 1930 | std::map<DownloadItem::DownloadState, std::string> state_to_string; |
| 1931 | state_to_string[DownloadItem::IN_PROGRESS] = std::string("IN_PROGRESS"); |
| 1932 | state_to_string[DownloadItem::CANCELLED] = std::string("CANCELLED"); |
| 1933 | state_to_string[DownloadItem::REMOVING] = std::string("REMOVING"); |
| 1934 | state_to_string[DownloadItem::COMPLETE] = std::string("COMPLETE"); |
| 1935 | |
| 1936 | std::map<DownloadItem::SafetyState, std::string> safety_state_to_string; |
| 1937 | safety_state_to_string[DownloadItem::SAFE] = std::string("SAFE"); |
| 1938 | safety_state_to_string[DownloadItem::DANGEROUS] = std::string("DANGEROUS"); |
| 1939 | safety_state_to_string[DownloadItem::DANGEROUS_BUT_VALIDATED] = |
| 1940 | std::string("DANGEROUS_BUT_VALIDATED"); |
| 1941 | |
| 1942 | ListValue* list_of_downloads = new ListValue; |
| 1943 | for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 1944 | it != downloads.end(); |
| 1945 | it++) { // Fill info about each download item. |
| 1946 | DictionaryValue* dl_item_value = new DictionaryValue; |
| 1947 | dl_item_value->SetInteger(L"id", static_cast<int>((*it)->id())); |
| 1948 | dl_item_value->SetString(L"url", (*it)->url().spec()); |
| 1949 | dl_item_value->SetString(L"referrer_url", (*it)->referrer_url().spec()); |
| 1950 | dl_item_value->SetString(L"file_name", (*it)->file_name().value()); |
| 1951 | dl_item_value->SetString(L"full_path", (*it)->full_path().value()); |
| 1952 | dl_item_value->SetBoolean(L"is_paused", (*it)->is_paused()); |
| 1953 | dl_item_value->SetBoolean(L"open_when_complete", |
| 1954 | (*it)->open_when_complete()); |
| 1955 | dl_item_value->SetBoolean(L"is_extension_install", |
| 1956 | (*it)->is_extension_install()); |
| 1957 | dl_item_value->SetBoolean(L"is_temporary", (*it)->is_temporary()); |
| 1958 | dl_item_value->SetBoolean(L"is_otr", (*it)->is_otr()); // off-the-record |
| 1959 | dl_item_value->SetString(L"state", state_to_string[(*it)->state()]); |
| 1960 | dl_item_value->SetString(L"safety_state", |
| 1961 | safety_state_to_string[(*it)->safety_state()]); |
| 1962 | dl_item_value->SetInteger(L"PercentComplete", (*it)->PercentComplete()); |
| 1963 | list_of_downloads->Append(dl_item_value); |
| 1964 | } |
| 1965 | return_value->Set(L"downloads", list_of_downloads); |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1966 | |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1967 | reply.SendSuccess(return_value.get()); |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1968 | // All value objects allocated above are owned by |return_value| |
| 1969 | // and get freed by it. |
| 1970 | } |
| 1971 | |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1972 | void AutomationProvider::WaitForDownloadsToComplete( |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 1973 | Browser* browser, |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1974 | DictionaryValue* args, |
| 1975 | IPC::Message* reply_message) { |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1976 | AutomationProviderDownloadManagerObserver observer; |
| 1977 | std::vector<DownloadItem*> downloads; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1978 | AutomationJSONReply reply(this, reply_message); |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1979 | |
| 1980 | // Look for a quick return. |
| 1981 | if (!profile_->HasCreatedDownloadManager()) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1982 | reply.SendSuccess(NULL); // No download manager. |
| 1983 | return; |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1984 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 1985 | profile_->GetDownloadManager()->GetCurrentDownloads(&observer, FilePath()); |
| 1986 | downloads = observer.Downloads(); |
| 1987 | if (downloads.size() == 0) { |
| 1988 | reply.SendSuccess(NULL); |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 1989 | return; |
| 1990 | } |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1991 | |
| 1992 | // The observer owns itself. When the last observed item pings, it |
| 1993 | // deletes itself. |
| 1994 | AutomationProviderDownloadItemObserver* item_observer = |
| 1995 | new AutomationProviderDownloadItemObserver( |
| 1996 | this, reply_message, downloads.size()); |
| 1997 | for (std::vector<DownloadItem*>::iterator i = downloads.begin(); |
| 1998 | i != downloads.end(); |
| 1999 | i++) { |
| 2000 | (*i)->AddObserver(item_observer); |
| 2001 | } |
| 2002 | } |
| 2003 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2004 | // Sample json input: { "command": "GetPrefsInfo" } |
| 2005 | // Refer chrome/test/pyautolib/prefs_info.py for sample json output. |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2006 | void AutomationProvider::GetPrefsInfo(Browser* browser, |
| 2007 | DictionaryValue* args, |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2008 | IPC::Message* reply_message) { |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2009 | const PrefService::PreferenceSet& prefs = |
| 2010 | profile_->GetPrefs()->preference_set(); |
| 2011 | DictionaryValue* items = new DictionaryValue; |
| 2012 | for (PrefService::PreferenceSet::const_iterator it = prefs.begin(); |
| 2013 | it != prefs.end(); ++it) { |
| 2014 | items->Set((*it)->name(), (*it)->GetValue()->DeepCopy()); |
| 2015 | } |
| 2016 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2017 | return_value->Set(L"prefs", items); // return_value owns items. |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2018 | AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | // Sample json input: { "command": "SetPrefs", "path": path, "value": value } |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2022 | void AutomationProvider::SetPrefs(Browser* browser, |
| 2023 | DictionaryValue* args, |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2024 | IPC::Message* reply_message) { |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2025 | std::wstring path; |
| 2026 | Value* val; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2027 | AutomationJSONReply reply(this, reply_message); |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2028 | if (args->GetString(L"path", &path) && args->Get(L"value", &val)) { |
| 2029 | PrefService* pref_service = profile_->GetPrefs(); |
| 2030 | const PrefService::Preference* pref = |
| 2031 | pref_service->FindPreference(path.c_str()); |
| 2032 | if (!pref) { // Not a registered pref. |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2033 | reply.SendError("pref not registered."); |
| 2034 | return; |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2035 | } else if (pref->IsManaged()) { // Do not attempt to change a managed pref. |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2036 | reply.SendError("pref is managed. cannot be changed."); |
| 2037 | return; |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2038 | } else { // Set the pref. |
| 2039 | pref_service->Set(path.c_str(), *val); |
| 2040 | } |
| 2041 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2042 | reply.SendError("no pref path or value given."); |
| 2043 | return; |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2044 | } |
| 2045 | |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2046 | reply.SendSuccess(NULL); |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2047 | } |
| 2048 | |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2049 | // Sample json input: { "command": "GetOmniboxInfo" } |
| 2050 | // Refer chrome/test/pyautolib/omnibox_info.py for sample json output. |
| 2051 | void AutomationProvider::GetOmniboxInfo(Browser* browser, |
| 2052 | DictionaryValue* args, |
| 2053 | IPC::Message* reply_message) { |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2054 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2055 | |
| 2056 | LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 2057 | AutocompleteEditView* edit_view = loc_bar->location_entry(); |
| 2058 | AutocompleteEditModel* model = edit_view->model(); |
| 2059 | |
| 2060 | // Fill up matches. |
| 2061 | ListValue* matches = new ListValue; |
| 2062 | const AutocompleteResult& result = model->result(); |
| 2063 | for (AutocompleteResult::const_iterator i = result.begin(); |
| 2064 | i != result.end(); ++i) { |
| 2065 | const AutocompleteMatch& match = *i; |
| 2066 | DictionaryValue* item = new DictionaryValue; // owned by return_value |
| 2067 | item->SetString(L"type", AutocompleteMatch::TypeToString(match.type)); |
| 2068 | item->SetBoolean(L"starred", match.starred); |
| 2069 | item->SetString(L"destination_url", match.destination_url.spec()); |
| 2070 | item->SetString(L"contents", match.contents); |
| 2071 | item->SetString(L"description", match.description); |
| 2072 | matches->Append(item); |
| 2073 | } |
| 2074 | return_value->Set(L"matches", matches); |
| 2075 | |
| 2076 | // Fill up other properties. |
| 2077 | DictionaryValue* properties = new DictionaryValue; // owned by return_value |
| 2078 | properties->SetBoolean(L"has_focus", model->has_focus()); |
| 2079 | properties->SetBoolean(L"query_in_progress", model->query_in_progress()); |
| 2080 | properties->SetString(L"keyword", model->keyword()); |
| 2081 | properties->SetString(L"text", edit_view->GetText()); |
| 2082 | return_value->Set(L"properties", properties); |
| 2083 | |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2084 | AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | // Sample json input: { "command": "SetOmniboxText", |
| 2088 | // "text": "goog" } |
| 2089 | void AutomationProvider::SetOmniboxText(Browser* browser, |
| 2090 | DictionaryValue* args, |
| 2091 | IPC::Message* reply_message) { |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2092 | std::wstring text; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2093 | AutomationJSONReply reply(this, reply_message); |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2094 | if (!args->GetString(L"text", &text)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2095 | reply.SendError("text missing"); |
| 2096 | return; |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2097 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2098 | browser->FocusLocationBar(); |
| 2099 | LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 2100 | AutocompleteEditView* edit_view = loc_bar->location_entry(); |
| 2101 | edit_view->model()->OnSetFocus(false); |
| 2102 | edit_view->SetUserText(text); |
| 2103 | reply.SendSuccess(NULL); |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | // Sample json input: { "command": "OmniboxMovePopupSelection", |
| 2107 | // "count": 1 } |
| 2108 | // Negative count implies up, positive implies down. Count values will be |
| 2109 | // capped by the size of the popup list. |
| 2110 | void AutomationProvider::OmniboxMovePopupSelection( |
| 2111 | Browser* browser, |
| 2112 | DictionaryValue* args, |
| 2113 | IPC::Message* reply_message) { |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2114 | int count; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2115 | AutomationJSONReply reply(this, reply_message); |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2116 | if (!args->GetInteger(L"count", &count)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2117 | reply.SendError("count missing"); |
| 2118 | return; |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2119 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2120 | LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 2121 | AutocompleteEditModel* model = loc_bar->location_entry()->model(); |
| 2122 | model->OnUpOrDownKeyPressed(count); |
| 2123 | reply.SendSuccess(NULL); |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | // Sample json input: { "command": "OmniboxAcceptInput" } |
| 2127 | void AutomationProvider::OmniboxAcceptInput(Browser* browser, |
| 2128 | DictionaryValue* args, |
| 2129 | IPC::Message* reply_message) { |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2130 | NavigationController& controller = |
| 2131 | browser->GetSelectedTabContents()->controller(); |
[email protected] | c165483 | 2010-05-17 23:22:12 | [diff] [blame] | 2132 | // Setup observer to wait until the selected item loads. |
| 2133 | NotificationObserver* observer = |
[email protected] | cb84d64 | 2010-06-10 00:56:28 | [diff] [blame] | 2134 | new OmniboxAcceptNotificationObserver(&controller, this, reply_message); |
[email protected] | c165483 | 2010-05-17 23:22:12 | [diff] [blame] | 2135 | notification_observer_list_.AddObserver(observer); |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2136 | |
| 2137 | browser->window()->GetLocationBar()->AcceptInput(); |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2138 | } |
| 2139 | |
[email protected] | a3cd502 | 2010-06-16 18:25:29 | [diff] [blame] | 2140 | // Sample json input: { "command": "GetInitialLoadTimes" } |
| 2141 | // Refer to InitialLoadObserver::GetTimingInformation() for sample output. |
| 2142 | void AutomationProvider::GetInitialLoadTimes( |
| 2143 | Browser*, |
| 2144 | DictionaryValue*, |
| 2145 | IPC::Message* reply_message) { |
| 2146 | scoped_ptr<DictionaryValue> return_value( |
| 2147 | initial_load_observer_->GetTimingInformation()); |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 2148 | |
| 2149 | std::string json_return; |
| 2150 | base::JSONWriter::Write(return_value.get(), false, &json_return); |
| 2151 | AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 2152 | reply_message, json_return, true); |
| 2153 | Send(reply_message); |
[email protected] | a3cd502 | 2010-06-16 18:25:29 | [diff] [blame] | 2154 | } |
| 2155 | |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2156 | // Sample json input: { "command": "GetPluginsInfo" } |
| 2157 | // Refer chrome/test/pyautolib/plugins_info.py for sample json output. |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2158 | void AutomationProvider::GetPluginsInfo(Browser* browser, |
| 2159 | DictionaryValue* args, |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2160 | IPC::Message* reply_message) { |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2161 | std::vector<WebPluginInfo> plugins; |
| 2162 | NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); |
| 2163 | ListValue* items = new ListValue; |
| 2164 | for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
| 2165 | it != plugins.end(); |
| 2166 | ++it) { |
| 2167 | DictionaryValue* item = new DictionaryValue; |
[email protected] | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 2168 | item->SetStringFromUTF16(L"name", it->name); |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2169 | item->SetString(L"path", it->path.value()); |
[email protected] | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 2170 | item->SetStringFromUTF16(L"version", it->version); |
| 2171 | item->SetStringFromUTF16(L"desc", it->desc); |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2172 | item->SetBoolean(L"enabled", it->enabled); |
| 2173 | // Add info about mime types. |
| 2174 | ListValue* mime_types = new ListValue(); |
| 2175 | for (std::vector<WebPluginMimeType>::const_iterator type_it = |
| 2176 | it->mime_types.begin(); |
| 2177 | type_it != it->mime_types.end(); |
| 2178 | ++type_it) { |
| 2179 | DictionaryValue* mime_type = new DictionaryValue(); |
| 2180 | mime_type->SetString(L"mimeType", type_it->mime_type); |
[email protected] | c9d81137 | 2010-06-23 21:44:57 | [diff] [blame] | 2181 | mime_type->SetStringFromUTF16(L"description", type_it->description); |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2182 | |
| 2183 | ListValue* file_extensions = new ListValue(); |
| 2184 | for (std::vector<std::string>::const_iterator ext_it = |
| 2185 | type_it->file_extensions.begin(); |
| 2186 | ext_it != type_it->file_extensions.end(); |
| 2187 | ++ext_it) { |
| 2188 | file_extensions->Append(new StringValue(*ext_it)); |
| 2189 | } |
| 2190 | mime_type->Set(L"fileExtensions", file_extensions); |
| 2191 | |
| 2192 | mime_types->Append(mime_type); |
| 2193 | } |
| 2194 | item->Set(L"mimeTypes", mime_types); |
| 2195 | items->Append(item); |
| 2196 | } |
| 2197 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2198 | return_value->Set(L"plugins", items); // return_value owns items. |
| 2199 | |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2200 | AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | // Sample json input: |
| 2204 | // { "command": "EnablePlugin", |
| 2205 | // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2206 | void AutomationProvider::EnablePlugin(Browser* browser, |
| 2207 | DictionaryValue* args, |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2208 | IPC::Message* reply_message) { |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2209 | FilePath::StringType path; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2210 | AutomationJSONReply reply(this, reply_message); |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 2211 | if (!args->GetString(L"path", &path)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2212 | reply.SendError("path not specified."); |
| 2213 | return; |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 2214 | } else if (!NPAPI::PluginList::Singleton()->EnablePlugin(FilePath(path))) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2215 | reply.SendError(StringPrintf("Could not enable plugin for path %s.", |
| 2216 | path.c_str())); |
| 2217 | return; |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 2218 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2219 | reply.SendSuccess(NULL); |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | // Sample json input: |
| 2223 | // { "command": "DisablePlugin", |
| 2224 | // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2225 | void AutomationProvider::DisablePlugin(Browser* browser, |
| 2226 | DictionaryValue* args, |
| 2227 | IPC::Message* reply_message) { |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2228 | FilePath::StringType path; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2229 | AutomationJSONReply reply(this, reply_message); |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 2230 | if (!args->GetString(L"path", &path)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2231 | reply.SendError("path not specified."); |
| 2232 | return; |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 2233 | } else if (!NPAPI::PluginList::Singleton()->DisablePlugin(FilePath(path))) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2234 | reply.SendError(StringPrintf("Could not disable plugin for path %s.", |
| 2235 | path.c_str())); |
| 2236 | return; |
[email protected] | f6ff0df | 2010-07-11 22:41:43 | [diff] [blame] | 2237 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2238 | reply.SendSuccess(NULL); |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2239 | } |
| 2240 | |
[email protected] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 2241 | // Sample json input: |
| 2242 | // { "command": "SaveTabContents", |
| 2243 | // "tab_index": 0, |
| 2244 | // "filename": <a full pathname> } |
| 2245 | // Sample json output: |
| 2246 | // {} |
| 2247 | void AutomationProvider::SaveTabContents(Browser* browser, |
| 2248 | DictionaryValue* args, |
| 2249 | IPC::Message* reply_message) { |
[email protected] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 2250 | int tab_index = 0; |
| 2251 | FilePath::StringType filename; |
| 2252 | FilePath::StringType parent_directory; |
| 2253 | TabContents* tab_contents = NULL; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2254 | AutomationJSONReply reply(this, reply_message); |
[email protected] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 2255 | |
| 2256 | if (!args->GetInteger(L"tab_index", &tab_index) || |
| 2257 | !args->GetString(L"filename", &filename)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2258 | reply.SendError("tab_index or filename param missing"); |
| 2259 | return; |
[email protected] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 2260 | } else { |
| 2261 | tab_contents = browser->GetTabContentsAt(tab_index); |
| 2262 | if (!tab_contents) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2263 | reply.SendError("no tab at tab_index"); |
[email protected] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 2264 | return; |
| 2265 | } |
| 2266 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2267 | // We're doing a SAVE_AS_ONLY_HTML so the the directory path isn't |
| 2268 | // used. Nevertheless, SavePackage requires it be valid. Sigh. |
| 2269 | parent_directory = FilePath(filename).DirName().value(); |
| 2270 | if (!tab_contents->SavePage(FilePath(filename), FilePath(parent_directory), |
| 2271 | SavePackage::SAVE_AS_ONLY_HTML)) { |
| 2272 | reply.SendError("Could not initiate SavePage"); |
| 2273 | return; |
| 2274 | } |
| 2275 | // The observer will delete itself when done. |
| 2276 | new SavePackageNotificationObserver(tab_contents->save_package(), |
| 2277 | this, reply_message); |
[email protected] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 2278 | } |
| 2279 | |
[email protected] | c5aa532 | 2010-07-15 19:00:07 | [diff] [blame] | 2280 | // Refer to ImportSettings() in chrome/test/pyautolib/pyauto.py for sample |
| 2281 | // json input. |
| 2282 | // Sample json output: "{}" |
| 2283 | void AutomationProvider::ImportSettings(Browser* browser, |
| 2284 | DictionaryValue* args, |
| 2285 | IPC::Message* reply_message) { |
[email protected] | c5aa532 | 2010-07-15 19:00:07 | [diff] [blame] | 2286 | // Map from the json string passed over to the import item masks. |
| 2287 | std::map<std::string, ImportItem> string_to_import_item; |
| 2288 | string_to_import_item["HISTORY"] = importer::HISTORY; |
| 2289 | string_to_import_item["FAVORITES"] = importer::FAVORITES; |
| 2290 | string_to_import_item["COOKIES"] = importer::COOKIES; |
| 2291 | string_to_import_item["PASSWORDS"] = importer::PASSWORDS; |
| 2292 | string_to_import_item["SEARCH_ENGINES"] = importer::SEARCH_ENGINES; |
| 2293 | string_to_import_item["HOME_PAGE"] = importer::HOME_PAGE; |
| 2294 | string_to_import_item["ALL"] = importer::ALL; |
| 2295 | |
| 2296 | std::wstring browser_name; |
| 2297 | int import_items = 0; |
| 2298 | ListValue* import_items_list = NULL; |
| 2299 | bool first_run; |
| 2300 | |
| 2301 | if (!args->GetString(L"import_from", &browser_name) || |
| 2302 | !args->GetBoolean(L"first_run", &first_run) || |
| 2303 | !args->GetList(L"import_items", &import_items_list)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2304 | AutomationJSONReply(this, reply_message).SendError( |
| 2305 | "Incorrect type for one or more of the arguments."); |
[email protected] | c5aa532 | 2010-07-15 19:00:07 | [diff] [blame] | 2306 | return; |
| 2307 | } |
| 2308 | |
| 2309 | int num_items = import_items_list->GetSize(); |
| 2310 | for (int i = 0; i < num_items; i++) { |
| 2311 | std::string item; |
| 2312 | import_items_list->GetString(i, &item); |
| 2313 | // If the provided string is not part of the map, error out. |
| 2314 | if (!ContainsKey(string_to_import_item, item)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2315 | AutomationJSONReply(this, reply_message).SendError( |
| 2316 | "Invalid item string found in import_items."); |
[email protected] | c5aa532 | 2010-07-15 19:00:07 | [diff] [blame] | 2317 | return; |
| 2318 | } |
| 2319 | import_items |= string_to_import_item[item]; |
| 2320 | } |
| 2321 | |
| 2322 | ImporterHost* importer_host = new ImporterHost(); |
| 2323 | // Get the correct ProfileInfo based on the browser they user provided. |
| 2324 | importer::ProfileInfo profile_info; |
| 2325 | int num_browsers = importer_host->GetAvailableProfileCount(); |
| 2326 | int i = 0; |
| 2327 | for ( ; i < num_browsers; i++) { |
| 2328 | std::wstring name = importer_host->GetSourceProfileNameAt(i); |
| 2329 | if (name == browser_name) { |
| 2330 | profile_info = importer_host->GetSourceProfileInfoAt(i); |
| 2331 | break; |
| 2332 | } |
| 2333 | } |
| 2334 | // If we made it to the end of the loop, then the input was bad. |
| 2335 | if (i == num_browsers) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2336 | AutomationJSONReply(this, reply_message).SendError( |
| 2337 | "Invalid browser name string found."); |
[email protected] | c5aa532 | 2010-07-15 19:00:07 | [diff] [blame] | 2338 | return; |
| 2339 | } |
| 2340 | |
| 2341 | Profile* profile = browser->profile(); |
| 2342 | |
| 2343 | importer_host->SetObserver( |
| 2344 | new AutomationProviderImportSettingsObserver(this, reply_message)); |
| 2345 | importer_host->StartImportSettings(profile_info, profile, import_items, |
| 2346 | new ProfileWriter(profile), first_run); |
| 2347 | } |
| 2348 | |
[email protected] | a0fc50d7 | 2010-07-14 21:14:19 | [diff] [blame] | 2349 | // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample |
| 2350 | // json input. |
| 2351 | // Sample json output: {} |
| 2352 | void AutomationProvider::ClearBrowsingData(Browser* browser, |
| 2353 | DictionaryValue* args, |
| 2354 | IPC::Message* reply_message) { |
[email protected] | a0fc50d7 | 2010-07-14 21:14:19 | [diff] [blame] | 2355 | std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period; |
| 2356 | string_to_time_period["LAST_HOUR"] = BrowsingDataRemover::LAST_HOUR; |
| 2357 | string_to_time_period["LAST_DAY"] = BrowsingDataRemover::LAST_DAY; |
| 2358 | string_to_time_period["LAST_WEEK"] = BrowsingDataRemover::LAST_WEEK; |
| 2359 | string_to_time_period["FOUR_WEEKS"] = BrowsingDataRemover::FOUR_WEEKS; |
| 2360 | string_to_time_period["EVERYTHING"] = BrowsingDataRemover::EVERYTHING; |
| 2361 | |
| 2362 | std::map<std::string, int> string_to_mask_value; |
| 2363 | string_to_mask_value["HISTORY"] = BrowsingDataRemover::REMOVE_HISTORY; |
| 2364 | string_to_mask_value["DOWNLOADS"] = BrowsingDataRemover::REMOVE_DOWNLOADS; |
| 2365 | string_to_mask_value["COOKIES"] = BrowsingDataRemover::REMOVE_COOKIES; |
| 2366 | string_to_mask_value["PASSWORDS"] = BrowsingDataRemover::REMOVE_PASSWORDS; |
| 2367 | string_to_mask_value["FORM_DATA"] = BrowsingDataRemover::REMOVE_FORM_DATA; |
| 2368 | string_to_mask_value["CACHE"] = BrowsingDataRemover::REMOVE_CACHE; |
| 2369 | |
| 2370 | std::string time_period; |
| 2371 | ListValue* to_remove; |
| 2372 | if (!args->GetString(L"time_period", &time_period) || |
| 2373 | !args->GetList(L"to_remove", &to_remove)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2374 | AutomationJSONReply(this, reply_message).SendError( |
| 2375 | "time_period must be a string and to_remove a list."); |
[email protected] | a0fc50d7 | 2010-07-14 21:14:19 | [diff] [blame] | 2376 | return; |
| 2377 | } |
| 2378 | |
| 2379 | int remove_mask = 0; |
| 2380 | int num_removals = to_remove->GetSize(); |
| 2381 | for (int i = 0; i < num_removals; i++) { |
| 2382 | std::string removal; |
| 2383 | to_remove->GetString(i, &removal); |
| 2384 | // If the provided string is not part of the map, then error out. |
| 2385 | if (!ContainsKey(string_to_mask_value, removal)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2386 | AutomationJSONReply(this, reply_message).SendError( |
| 2387 | "Invalid browsing data string found in to_remove."); |
[email protected] | a0fc50d7 | 2010-07-14 21:14:19 | [diff] [blame] | 2388 | return; |
| 2389 | } |
| 2390 | remove_mask |= string_to_mask_value[removal]; |
| 2391 | } |
| 2392 | |
| 2393 | if (!ContainsKey(string_to_time_period, time_period)) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2394 | AutomationJSONReply(this, reply_message).SendError( |
| 2395 | "Invalid string for time_period."); |
[email protected] | a0fc50d7 | 2010-07-14 21:14:19 | [diff] [blame] | 2396 | return; |
| 2397 | } |
| 2398 | |
| 2399 | BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 2400 | profile(), string_to_time_period[time_period], base::Time()); |
| 2401 | |
| 2402 | remover->AddObserver( |
| 2403 | new AutomationProviderBrowsingDataObserver(this, reply_message)); |
| 2404 | remover->Remove(remove_mask); |
| 2405 | // BrowsingDataRemover deletes itself using DeleteTask. |
| 2406 | // The observer also deletes itself after sending the reply. |
| 2407 | } |
| 2408 | |
[email protected] | 4d1929f1 | 2010-07-10 00:09:03 | [diff] [blame] | 2409 | // Sample json input: { "command": "GetThemeInfo" } |
| 2410 | // Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output. |
| 2411 | void AutomationProvider::GetThemeInfo(Browser* browser, |
| 2412 | DictionaryValue* args, |
| 2413 | IPC::Message* reply_message) { |
| 2414 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2415 | Extension* theme = browser->profile()->GetTheme(); |
| 2416 | if (theme) { |
| 2417 | return_value->SetString(L"name", theme->name()); |
| 2418 | return_value->Set(L"images", theme->GetThemeImages()->DeepCopy()); |
| 2419 | return_value->Set(L"colors", theme->GetThemeColors()->DeepCopy()); |
| 2420 | return_value->Set(L"tints", theme->GetThemeTints()->DeepCopy()); |
| 2421 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2422 | AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
[email protected] | 4d1929f1 | 2010-07-10 00:09:03 | [diff] [blame] | 2423 | } |
| 2424 | |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2425 | // Sample json input: |
| 2426 | // { "command": "GetAutoFillProfile" } |
| 2427 | // Refer to GetAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample |
| 2428 | // json output. |
| 2429 | void AutomationProvider::GetAutoFillProfile(Browser* browser, |
| 2430 | DictionaryValue* args, |
| 2431 | IPC::Message* reply_message) { |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2432 | // Get the AutoFillProfiles currently in the database. |
| 2433 | int tab_index = 0; |
| 2434 | args->GetInteger(L"tab_index", &tab_index); |
| 2435 | TabContents* tab_contents = browser->GetTabContentsAt(tab_index); |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2436 | AutomationJSONReply reply(this, reply_message); |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2437 | |
| 2438 | if (tab_contents) { |
| 2439 | PersonalDataManager* pdm = tab_contents->profile()->GetOriginalProfile() |
| 2440 | ->GetPersonalDataManager(); |
| 2441 | if (pdm) { |
| 2442 | std::vector<AutoFillProfile*> autofill_profiles = pdm->profiles(); |
| 2443 | std::vector<CreditCard*> credit_cards = pdm->credit_cards(); |
| 2444 | |
| 2445 | ListValue* profiles = GetListFromAutoFillProfiles(autofill_profiles); |
| 2446 | ListValue* cards = GetListFromCreditCards(credit_cards); |
| 2447 | |
| 2448 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2449 | |
| 2450 | return_value->Set(L"profiles", profiles); |
| 2451 | return_value->Set(L"credit_cards", cards); |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2452 | reply.SendSuccess(return_value.get()); |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2453 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2454 | reply.SendError("No PersonalDataManager."); |
| 2455 | return; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2456 | } |
| 2457 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2458 | reply.SendError("No tab at that index."); |
| 2459 | return; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2460 | } |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | // Refer to FillAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample |
| 2464 | // json input. |
| 2465 | // Sample json output: {} |
| 2466 | void AutomationProvider::FillAutoFillProfile(Browser* browser, |
| 2467 | DictionaryValue* args, |
| 2468 | IPC::Message* reply_message) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2469 | AutomationJSONReply reply(this, reply_message); |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2470 | ListValue* profiles = NULL; |
| 2471 | ListValue* cards = NULL; |
| 2472 | args->GetList(L"profiles", &profiles); |
| 2473 | args->GetList(L"credit_cards", &cards); |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2474 | std::string error_mesg; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2475 | |
| 2476 | std::vector<AutoFillProfile> autofill_profiles; |
| 2477 | std::vector<CreditCard> credit_cards; |
| 2478 | // Create an AutoFillProfile for each of the dictionary profiles. |
| 2479 | if (profiles) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2480 | autofill_profiles = GetAutoFillProfilesFromList(*profiles, &error_mesg); |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2481 | } |
| 2482 | // Create a CreditCard for each of the dictionary values. |
| 2483 | if (cards) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2484 | credit_cards = GetCreditCardsFromList(*cards, &error_mesg); |
| 2485 | } |
| 2486 | if (!error_mesg.empty()) { |
| 2487 | reply.SendError(error_mesg); |
| 2488 | return; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | // Save the AutoFillProfiles. |
| 2492 | int tab_index = 0; |
| 2493 | args->GetInteger(L"tab_index", &tab_index); |
| 2494 | TabContents* tab_contents = browser->GetTabContentsAt(tab_index); |
| 2495 | |
| 2496 | if (tab_contents) { |
| 2497 | PersonalDataManager* pdm = tab_contents->profile()->GetOriginalProfile() |
| 2498 | ->GetPersonalDataManager(); |
| 2499 | if (pdm) { |
| 2500 | pdm->OnAutoFillDialogApply(profiles? &autofill_profiles : NULL, |
| 2501 | cards? &credit_cards : NULL); |
| 2502 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2503 | reply.SendError("No PersonalDataManager."); |
| 2504 | return; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2505 | } |
| 2506 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2507 | reply.SendError("No tab at that index."); |
| 2508 | return; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2509 | } |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2510 | reply.SendSuccess(NULL); |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | /* static */ |
| 2514 | ListValue* AutomationProvider::GetListFromAutoFillProfiles( |
| 2515 | std::vector<AutoFillProfile*> autofill_profiles) { |
| 2516 | ListValue* profiles = new ListValue; |
| 2517 | |
| 2518 | std::map<AutoFillFieldType, std::wstring> autofill_type_to_string |
| 2519 | = GetAutoFillFieldToStringMap(); |
| 2520 | |
| 2521 | // For each AutoFillProfile, transform it to a dictionary object to return. |
| 2522 | for (std::vector<AutoFillProfile*>::iterator it = autofill_profiles.begin(); |
| 2523 | it != autofill_profiles.end(); ++it) { |
| 2524 | AutoFillProfile* profile = *it; |
| 2525 | DictionaryValue* profile_info = new DictionaryValue; |
| 2526 | profile_info->SetStringFromUTF16(L"label", profile->Label()); |
| 2527 | // For each of the types, if it has a value, add it to the dictionary. |
| 2528 | for (std::map<AutoFillFieldType, std::wstring>::iterator |
| 2529 | type_it = autofill_type_to_string.begin(); |
| 2530 | type_it != autofill_type_to_string.end(); ++type_it) { |
| 2531 | string16 value = profile->GetFieldText(AutoFillType(type_it->first)); |
| 2532 | if (value.length()) { // If there was something stored for that value. |
| 2533 | profile_info->SetStringFromUTF16(type_it->second, value); |
| 2534 | } |
| 2535 | } |
| 2536 | profiles->Append(profile_info); |
| 2537 | } |
| 2538 | return profiles; |
| 2539 | } |
| 2540 | |
| 2541 | /* static */ |
| 2542 | ListValue* AutomationProvider::GetListFromCreditCards( |
| 2543 | std::vector<CreditCard*> credit_cards) { |
| 2544 | ListValue* cards = new ListValue; |
| 2545 | |
| 2546 | std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string = |
| 2547 | GetCreditCardFieldToStringMap(); |
| 2548 | |
| 2549 | // For each AutoFillProfile, transform it to a dictionary object to return. |
| 2550 | for (std::vector<CreditCard*>::iterator it = credit_cards.begin(); |
| 2551 | it != credit_cards.end(); ++it) { |
| 2552 | CreditCard* card = *it; |
| 2553 | DictionaryValue* card_info = new DictionaryValue; |
| 2554 | card_info->SetStringFromUTF16(L"label", card->Label()); |
| 2555 | // For each of the types, if it has a value, add it to the dictionary. |
| 2556 | for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = |
| 2557 | credit_card_type_to_string.begin(); |
| 2558 | type_it != credit_card_type_to_string.end(); ++type_it) { |
| 2559 | string16 value = card->GetFieldText(AutoFillType(type_it->first)); |
| 2560 | // If there was something stored for that value. |
| 2561 | if (value.length()) { |
| 2562 | card_info->SetStringFromUTF16(type_it->second, value); |
| 2563 | } |
| 2564 | } |
| 2565 | cards->Append(card_info); |
| 2566 | } |
| 2567 | return cards; |
| 2568 | } |
| 2569 | |
| 2570 | /* static */ |
| 2571 | std::vector<AutoFillProfile> AutomationProvider::GetAutoFillProfilesFromList( |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2572 | const ListValue& profiles, std::string* error_message) { |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2573 | std::vector<AutoFillProfile> autofill_profiles; |
| 2574 | DictionaryValue* profile_info = NULL; |
| 2575 | string16 profile_label; |
| 2576 | string16 current_value; |
| 2577 | |
| 2578 | std::map<AutoFillFieldType, std::wstring> autofill_type_to_string = |
| 2579 | GetAutoFillFieldToStringMap(); |
| 2580 | |
| 2581 | int num_profiles = profiles.GetSize(); |
| 2582 | for (int i = 0; i < num_profiles; i++) { |
| 2583 | profiles.GetDictionary(i, &profile_info); |
| 2584 | profile_info->GetString("label", &profile_label); |
| 2585 | // Choose an id of 0 so that a unique id will be created. |
| 2586 | AutoFillProfile profile(profile_label, 0); |
| 2587 | // Loop through the possible profile types and add those provided. |
| 2588 | for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = |
| 2589 | autofill_type_to_string.begin(); |
| 2590 | type_it != autofill_type_to_string.end(); ++type_it) { |
| 2591 | if (profile_info->HasKey(type_it->second)) { |
| 2592 | if (profile_info->GetStringAsUTF16(type_it->second, ¤t_value)) { |
| 2593 | profile.SetInfo(AutoFillType(type_it->first), current_value); |
| 2594 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2595 | *error_message= "All values must be strings"; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2596 | break; |
| 2597 | } |
| 2598 | } |
| 2599 | } |
| 2600 | autofill_profiles.push_back(profile); |
| 2601 | } |
| 2602 | return autofill_profiles; |
| 2603 | } |
| 2604 | |
| 2605 | /* static */ |
| 2606 | std::vector<CreditCard> AutomationProvider::GetCreditCardsFromList( |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2607 | const ListValue& cards, std::string* error_message) { |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2608 | std::vector<CreditCard> credit_cards; |
| 2609 | DictionaryValue* card_info = NULL; |
| 2610 | string16 card_label; |
| 2611 | string16 current_value; |
| 2612 | |
| 2613 | std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string = |
| 2614 | GetCreditCardFieldToStringMap(); |
| 2615 | |
| 2616 | int num_credit_cards = cards.GetSize(); |
| 2617 | for (int i = 0; i < num_credit_cards; i++) { |
| 2618 | cards.GetDictionary(i, &card_info); |
| 2619 | card_info->GetString("label", &card_label); |
| 2620 | CreditCard card(card_label, 0); |
| 2621 | // Loop through the possible credit card fields and add those provided. |
| 2622 | for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = |
| 2623 | credit_card_type_to_string.begin(); |
| 2624 | type_it != credit_card_type_to_string.end(); ++type_it) { |
| 2625 | if (card_info->HasKey(type_it->second)) { |
| 2626 | if (card_info->GetStringAsUTF16(type_it->second, ¤t_value)) { |
| 2627 | card.SetInfo(AutoFillType(type_it->first), current_value); |
| 2628 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2629 | *error_message= "All values must be strings"; |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2630 | break; |
| 2631 | } |
| 2632 | } |
| 2633 | } |
| 2634 | credit_cards.push_back(card); |
| 2635 | } |
| 2636 | return credit_cards; |
| 2637 | } |
| 2638 | |
| 2639 | /* static */ |
| 2640 | std::map<AutoFillFieldType, std::wstring> |
| 2641 | AutomationProvider::GetAutoFillFieldToStringMap() { |
| 2642 | std::map<AutoFillFieldType, std::wstring> autofill_type_to_string; |
| 2643 | autofill_type_to_string[NAME_FIRST] = L"NAME_FIRST"; |
| 2644 | autofill_type_to_string[NAME_MIDDLE] = L"NAME_MIDDLE"; |
| 2645 | autofill_type_to_string[NAME_LAST] = L"NAME_LAST"; |
| 2646 | autofill_type_to_string[COMPANY_NAME] = L"COMPANY_NAME"; |
| 2647 | autofill_type_to_string[EMAIL_ADDRESS] = L"EMAIL_ADDRESS"; |
| 2648 | autofill_type_to_string[ADDRESS_HOME_LINE1] = L"ADDRESS_HOME_LINE1"; |
| 2649 | autofill_type_to_string[ADDRESS_HOME_LINE2] = L"ADDRESS_HOME_LINE2"; |
| 2650 | autofill_type_to_string[ADDRESS_HOME_CITY] = L"ADDRESS_HOME_CITY"; |
| 2651 | autofill_type_to_string[ADDRESS_HOME_STATE] = L"ADDRESS_HOME_STATE"; |
| 2652 | autofill_type_to_string[ADDRESS_HOME_ZIP] = L"ADDRESS_HOME_ZIP"; |
| 2653 | autofill_type_to_string[ADDRESS_HOME_COUNTRY] = L"ADDRESS_HOME_COUNTRY"; |
| 2654 | autofill_type_to_string[PHONE_HOME_NUMBER] = L"PHONE_HOME_NUMBER"; |
| 2655 | autofill_type_to_string[PHONE_FAX_NUMBER] = L"PHONE_FAX_NUMBER"; |
| 2656 | autofill_type_to_string[NAME_FIRST] = L"NAME_FIRST"; |
| 2657 | return autofill_type_to_string; |
| 2658 | } |
| 2659 | |
| 2660 | /* static */ |
| 2661 | std::map<AutoFillFieldType, std::wstring> |
| 2662 | AutomationProvider::GetCreditCardFieldToStringMap() { |
| 2663 | std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string; |
| 2664 | credit_card_type_to_string[CREDIT_CARD_NAME] = L"CREDIT_CARD_NAME"; |
| 2665 | credit_card_type_to_string[CREDIT_CARD_NUMBER] = L"CREDIT_CARD_NUMBER"; |
| 2666 | credit_card_type_to_string[CREDIT_CARD_TYPE] = L"CREDIT_CARD_TYPE"; |
| 2667 | credit_card_type_to_string[CREDIT_CARD_EXP_MONTH] = L"CREDIT_CARD_EXP_MONTH"; |
| 2668 | credit_card_type_to_string[CREDIT_CARD_EXP_4_DIGIT_YEAR] = |
| 2669 | L"CREDIT_CARD_EXP_4_DIGIT_YEAR"; |
| 2670 | return credit_card_type_to_string; |
| 2671 | } |
| 2672 | |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2673 | void AutomationProvider::SendJSONRequest(int handle, |
| 2674 | std::string json_request, |
| 2675 | IPC::Message* reply_message) { |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 2676 | Browser* browser = NULL; |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 2677 | scoped_ptr<Value> values; |
| 2678 | |
| 2679 | // Basic error checking. |
| 2680 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2681 | browser = browser_tracker_->GetResource(handle); |
| 2682 | } |
| 2683 | if (!browser) { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2684 | AutomationJSONReply(this, reply_message).SendError("no browser object"); |
| 2685 | return; |
| 2686 | } |
| 2687 | base::JSONReader reader; |
| 2688 | std::string error; |
| 2689 | values.reset(reader.ReadAndReturnError(json_request, true, NULL, &error)); |
| 2690 | if (!error.empty()) { |
| 2691 | AutomationJSONReply(this, reply_message).SendError(error); |
| 2692 | return; |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | // Make sure input is a dict with a string command. |
| 2696 | std::string command; |
| 2697 | DictionaryValue* dict_value = NULL; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2698 | if (values->GetType() != Value::TYPE_DICTIONARY) { |
| 2699 | AutomationJSONReply(this, reply_message).SendError("not a dict"); |
| 2700 | return; |
| 2701 | } |
| 2702 | // Ownership remains with "values" variable. |
| 2703 | dict_value = static_cast<DictionaryValue*>(values.get()); |
| 2704 | if (!dict_value->GetStringASCII(std::string("command"), &command)) { |
| 2705 | AutomationJSONReply(this, reply_message).SendError( |
| 2706 | "no command key in dict or not a string command"); |
| 2707 | return; |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 2708 | } |
| 2709 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2710 | // Map json commands to their handlers. |
| 2711 | std::map<std::string, JsonHandler> handler_map; |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2712 | handler_map["DisablePlugin"] = &AutomationProvider::DisablePlugin; |
| 2713 | handler_map["EnablePlugin"] = &AutomationProvider::EnablePlugin; |
| 2714 | handler_map["GetPluginsInfo"] = &AutomationProvider::GetPluginsInfo; |
| 2715 | |
[email protected] | a9ff2c0 | 2010-05-13 17:33:05 | [diff] [blame] | 2716 | handler_map["GetBrowserInfo"] = &AutomationProvider::GetBrowserInfo; |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2717 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2718 | handler_map["GetHistoryInfo"] = &AutomationProvider::GetHistoryInfo; |
[email protected] | bbe6aa0 | 2010-05-07 17:27:29 | [diff] [blame] | 2719 | handler_map["AddHistoryItem"] = &AutomationProvider::AddHistoryItem; |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2720 | |
[email protected] | 5332958 | 2010-05-14 21:10:58 | [diff] [blame] | 2721 | handler_map["GetOmniboxInfo"] = &AutomationProvider::GetOmniboxInfo; |
| 2722 | handler_map["SetOmniboxText"] = &AutomationProvider::SetOmniboxText; |
| 2723 | handler_map["OmniboxAcceptInput"] = &AutomationProvider::OmniboxAcceptInput; |
| 2724 | handler_map["OmniboxMovePopupSelection"] = |
| 2725 | &AutomationProvider::OmniboxMovePopupSelection; |
| 2726 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2727 | handler_map["GetPrefsInfo"] = &AutomationProvider::GetPrefsInfo; |
| 2728 | handler_map["SetPrefs"] = &AutomationProvider::SetPrefs; |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2729 | |
[email protected] | ef413ca | 2010-05-25 21:09:14 | [diff] [blame] | 2730 | handler_map["SetWindowDimensions"] = &AutomationProvider::SetWindowDimensions; |
| 2731 | |
[email protected] | f7d4801 | 2010-05-06 08:17:05 | [diff] [blame] | 2732 | handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 2733 | handler_map["WaitForAllDownloadsToComplete"] = |
| 2734 | &AutomationProvider::WaitForDownloadsToComplete; |
| 2735 | |
[email protected] | a3cd502 | 2010-06-16 18:25:29 | [diff] [blame] | 2736 | handler_map["GetInitialLoadTimes"] = &AutomationProvider::GetInitialLoadTimes; |
| 2737 | |
[email protected] | 7060bb29 | 2010-06-24 00:52:49 | [diff] [blame] | 2738 | handler_map["SaveTabContents"] = &AutomationProvider::SaveTabContents; |
| 2739 | |
[email protected] | c5aa532 | 2010-07-15 19:00:07 | [diff] [blame] | 2740 | handler_map["ImportSettings"] = &AutomationProvider::ImportSettings; |
| 2741 | |
[email protected] | a0fc50d7 | 2010-07-14 21:14:19 | [diff] [blame] | 2742 | handler_map["ClearBrowsingData"] = &AutomationProvider::ClearBrowsingData; |
| 2743 | |
[email protected] | 4d1929f1 | 2010-07-10 00:09:03 | [diff] [blame] | 2744 | // SetTheme() implemented using InstallExtension(). |
| 2745 | handler_map["GetThemeInfo"] = &AutomationProvider::GetThemeInfo; |
| 2746 | |
[email protected] | 55846ad84 | 2010-07-09 18:22:56 | [diff] [blame] | 2747 | handler_map["GetAutoFillProfile"] = &AutomationProvider::GetAutoFillProfile; |
| 2748 | handler_map["FillAutoFillProfile"] = &AutomationProvider::FillAutoFillProfile; |
| 2749 | |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2750 | if (handler_map.find(std::string(command)) != handler_map.end()) { |
| 2751 | (this->*handler_map[command])(browser, dict_value, reply_message); |
[email protected] | 1ac875d2 | 2010-07-16 09:57:58 | [diff] [blame] | 2752 | } else { |
[email protected] | 7c983cc | 2010-07-16 11:33:34 | [diff] [blame^] | 2753 | std::string error_string = "Unknown command. Options: "; |
| 2754 | for (std::map<std::string, JsonHandler>::const_iterator it = |
| 2755 | handler_map.begin(); it != handler_map.end(); ++it) { |
| 2756 | error_string += it->first + ", "; |
| 2757 | } |
| 2758 | AutomationJSONReply(this, reply_message).SendError(error_string); |
[email protected] | 1ac875d2 | 2010-07-16 09:57:58 | [diff] [blame] | 2759 | } |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 2760 | } |
| 2761 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2762 | void AutomationProvider::HandleInspectElementRequest( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2763 | int handle, int x, int y, IPC::Message* reply_message) { |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2764 | TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
| 2765 | if (tab_contents) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2766 | DCHECK(reply_message_ == NULL); |
| 2767 | reply_message_ = reply_message; |
| 2768 | |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 2769 | DevToolsManager::GetInstance()->InspectElement( |
| 2770 | tab_contents->render_view_host(), x, y); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2771 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2772 | AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); |
| 2773 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | void AutomationProvider::ReceivedInspectElementResponse(int num_resources) { |
[email protected] | 396c3b3 | 2009-03-12 22:26:09 | [diff] [blame] | 2778 | if (reply_message_) { |
| 2779 | AutomationMsg_InspectElement::WriteReplyParams(reply_message_, |
| 2780 | num_resources); |
| 2781 | Send(reply_message_); |
| 2782 | reply_message_ = NULL; |
| 2783 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2784 | } |
| 2785 | |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2786 | class SetProxyConfigTask : public Task { |
| 2787 | public: |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2788 | SetProxyConfigTask(URLRequestContextGetter* request_context_getter, |
| 2789 | const std::string& new_proxy_config) |
[email protected] | 2aa336e | 2010-04-06 21:05:25 | [diff] [blame] | 2790 | : request_context_getter_(request_context_getter), |
| 2791 | proxy_config_(new_proxy_config) {} |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2792 | virtual void Run() { |
| 2793 | // First, deserialize the JSON string. If this fails, log and bail. |
| 2794 | JSONStringValueSerializer deserializer(proxy_config_); |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 2795 | std::string error_msg; |
| 2796 | scoped_ptr<Value> root(deserializer.Deserialize(NULL, &error_msg)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2797 | if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { |
| 2798 | DLOG(WARNING) << "Received bad JSON string for ProxyConfig: " |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 2799 | << error_msg; |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2800 | return; |
| 2801 | } |
| 2802 | |
| 2803 | scoped_ptr<DictionaryValue> dict( |
| 2804 | static_cast<DictionaryValue*>(root.release())); |
| 2805 | // Now put together a proxy configuration from the deserialized string. |
| 2806 | net::ProxyConfig pc; |
| 2807 | PopulateProxyConfig(*dict.get(), &pc); |
| 2808 | |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2809 | net::ProxyService* proxy_service = |
| 2810 | request_context_getter_->GetURLRequestContext()->proxy_service(); |
| 2811 | DCHECK(proxy_service); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2812 | scoped_ptr<net::ProxyConfigService> proxy_config_service( |
| 2813 | new net::ProxyConfigServiceFixed(pc)); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2814 | proxy_service->ResetConfigService(proxy_config_service.release()); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { |
| 2818 | DCHECK(pc); |
| 2819 | bool no_proxy = false; |
| 2820 | if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { |
| 2821 | // Make no changes to the ProxyConfig. |
| 2822 | return; |
| 2823 | } |
| 2824 | bool auto_config; |
| 2825 | if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 2826 | pc->set_auto_detect(true); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2827 | } |
| 2828 | std::string pac_url; |
| 2829 | if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 2830 | pc->set_pac_url(GURL(pac_url)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2831 | } |
| 2832 | std::string proxy_bypass_list; |
| 2833 | if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 2834 | pc->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_list); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2835 | } |
| 2836 | std::string proxy_server; |
| 2837 | if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 2838 | pc->proxy_rules().ParseFromString(proxy_server); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | private: |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2843 | scoped_refptr<URLRequestContextGetter> request_context_getter_; |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2844 | std::string proxy_config_; |
| 2845 | }; |
| 2846 | |
| 2847 | |
| 2848 | void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2849 | URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); |
| 2850 | if (!context_getter) { |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2851 | FilePath user_data_dir; |
| 2852 | PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 2853 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 2854 | DCHECK(profile_manager); |
| 2855 | Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); |
| 2856 | DCHECK(profile); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2857 | context_getter = profile->GetRequestContext(); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2858 | } |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2859 | DCHECK(context_getter); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2860 | |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 2861 | ChromeThread::PostTask( |
| 2862 | ChromeThread::IO, FROM_HERE, |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 2863 | new SetProxyConfigTask(context_getter, new_proxy_config)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 2864 | } |
| 2865 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2866 | void AutomationProvider::GetDownloadDirectory( |
[email protected] | 1f733cf | 2009-09-30 20:46:33 | [diff] [blame] | 2867 | int handle, FilePath* download_directory) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2868 | DLOG(INFO) << "Handling download directory request"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2869 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2870 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2871 | DownloadManager* dlm = tab->profile()->GetDownloadManager(); |
| 2872 | DCHECK(dlm); |
[email protected] | 1f733cf | 2009-09-30 20:46:33 | [diff] [blame] | 2873 | *download_directory = dlm->download_path(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2874 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2875 | } |
| 2876 | |
[email protected] | 6a5670d2 | 2009-10-27 16:21:34 | [diff] [blame] | 2877 | void AutomationProvider::OpenNewBrowserWindow(bool show, |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 2878 | IPC::Message* reply_message) { |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 2879 | OpenNewBrowserWindowOfType(static_cast<int>(Browser::TYPE_NORMAL), show, |
| 2880 | reply_message); |
| 2881 | } |
| 2882 | |
| 2883 | void AutomationProvider::OpenNewBrowserWindowOfType( |
| 2884 | int type, bool show, IPC::Message* reply_message) { |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 2885 | new BrowserOpenedNotificationObserver(this, reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2886 | // We may have no current browser windows open so don't rely on |
| 2887 | // asking an existing browser to execute the IDC_NEWWINDOW command |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 2888 | Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_); |
| 2889 | browser->CreateBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 2890 | browser->AddBlankTab(true); |
[email protected] | 3683cbb | 2009-04-09 21:46:15 | [diff] [blame] | 2891 | if (show) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 2892 | browser->window()->Show(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2893 | } |
| 2894 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2895 | void AutomationProvider::GetWindowForBrowser(int browser_handle, |
| 2896 | bool* success, |
| 2897 | int* handle) { |
| 2898 | *success = false; |
| 2899 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2900 | |
| 2901 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2902 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 2903 | gfx::NativeWindow win = browser->window()->GetNativeHandle(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2904 | // Add() returns the existing handle for the resource if any. |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 2905 | *handle = window_tracker_->Add(win); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2906 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2907 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | void AutomationProvider::GetAutocompleteEditForBrowser( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2911 | int browser_handle, |
| 2912 | bool* success, |
| 2913 | int* autocomplete_edit_handle) { |
| 2914 | *success = false; |
| 2915 | *autocomplete_edit_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2916 | |
| 2917 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2918 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2919 | LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 2920 | AutocompleteEditView* edit_view = loc_bar->location_entry(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2921 | // Add() returns the existing handle for the resource if any. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2922 | *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view); |
| 2923 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2924 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2925 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2926 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2927 | void AutomationProvider::ShowInterstitialPage(int tab_handle, |
| 2928 | const std::string& html_text, |
| 2929 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2930 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2931 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2932 | TabContents* tab_contents = controller->tab_contents(); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2933 | |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2934 | AddNavigationStatusListener(controller, reply_message, 1, false); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2935 | AutomationInterstitialPage* interstitial = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2936 | new AutomationInterstitialPage(tab_contents, |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2937 | GURL("about:interstitial"), |
| 2938 | html_text); |
| 2939 | interstitial->Show(); |
| 2940 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2941 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2942 | |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2943 | AutomationMsg_ShowInterstitialPage::WriteReplyParams( |
| 2944 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2945 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2946 | } |
| 2947 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2948 | void AutomationProvider::HideInterstitialPage(int tab_handle, |
| 2949 | bool* success) { |
| 2950 | *success = false; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2951 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL); |
| 2952 | if (tab_contents && tab_contents->interstitial_page()) { |
| 2953 | tab_contents->interstitial_page()->DontProceed(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2954 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2955 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2956 | } |
| 2957 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2958 | void AutomationProvider::CloseTab(int tab_handle, |
| 2959 | bool wait_until_closed, |
| 2960 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2961 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2962 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
| 2963 | int index; |
| 2964 | Browser* browser = Browser::GetBrowserForController(controller, &index); |
| 2965 | DCHECK(browser); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2966 | new TabClosedNotificationObserver(this, wait_until_closed, reply_message); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2967 | browser->CloseContents(controller->tab_contents()); |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2968 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2969 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2970 | |
| 2971 | AutomationMsg_CloseTab::WriteReplyParams(reply_message, false); |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 2972 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2973 | } |
| 2974 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2975 | void AutomationProvider::CloseBrowser(int browser_handle, |
| 2976 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2977 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2978 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2979 | new BrowserClosedNotificationObserver(browser, this, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2980 | reply_message); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 2981 | browser->window()->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2982 | } else { |
| 2983 | NOTREACHED(); |
| 2984 | } |
| 2985 | } |
| 2986 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2987 | void AutomationProvider::CloseBrowserAsync(int browser_handle) { |
| 2988 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2989 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
| 2990 | browser->window()->Close(); |
| 2991 | } else { |
| 2992 | NOTREACHED(); |
| 2993 | } |
| 2994 | } |
| 2995 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2996 | void AutomationProvider::WaitForTabToBeRestored(int tab_handle, |
| 2997 | IPC::Message* reply_message) { |
| 2998 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2999 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 3000 | restore_tracker_.reset( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 3001 | new NavigationControllerRestoredObserver(this, tab, reply_message)); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3002 | } |
| 3003 | } |
| 3004 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3005 | void AutomationProvider::GetSecurityState(int handle, bool* success, |
| 3006 | SecurityStyle* security_style, |
| 3007 | int* ssl_cert_status, |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 3008 | int* insecure_content_status) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3009 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3010 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 3011 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3012 | *success = true; |
| 3013 | *security_style = entry->ssl().security_style(); |
| 3014 | *ssl_cert_status = entry->ssl().cert_status(); |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 3015 | *insecure_content_status = entry->ssl().content_status(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3016 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3017 | *success = false; |
| 3018 | *security_style = SECURITY_STYLE_UNKNOWN; |
| 3019 | *ssl_cert_status = 0; |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 3020 | *insecure_content_status = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3024 | void AutomationProvider::GetPageType(int handle, bool* success, |
| 3025 | NavigationEntry::PageType* page_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3026 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3027 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 3028 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3029 | *page_type = entry->page_type(); |
| 3030 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3031 | // In order to return the proper result when an interstitial is shown and |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3032 | // no navigation entry were created for it we need to ask the TabContents. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3033 | if (*page_type == NavigationEntry::NORMAL_PAGE && |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3034 | tab->tab_contents()->showing_interstitial_page()) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3035 | *page_type = NavigationEntry::INTERSTITIAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3036 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3037 | *success = false; |
| 3038 | *page_type = NavigationEntry::NORMAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 3042 | void AutomationProvider::GetMetricEventDuration(const std::string& event_name, |
| 3043 | int* duration_ms) { |
| 3044 | *duration_ms = metric_event_duration_observer_->GetEventDurationMs( |
| 3045 | event_name); |
| 3046 | } |
| 3047 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3048 | void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, |
| 3049 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3050 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3051 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 3052 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 3053 | if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 3054 | TabContents* tab_contents = tab->tab_contents(); |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 3055 | InterstitialPage* ssl_blocking_page = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3056 | InterstitialPage::GetInterstitialPage(tab_contents); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3057 | if (ssl_blocking_page) { |
| 3058 | if (proceed) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3059 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3060 | ssl_blocking_page->Proceed(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3061 | return; |
| 3062 | } |
| 3063 | ssl_blocking_page->DontProceed(); |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 3064 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| 3065 | reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3066 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3067 | return; |
| 3068 | } |
| 3069 | } |
| 3070 | } |
| 3071 | // We failed. |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 3072 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| 3073 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3074 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3075 | } |
| 3076 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3077 | void AutomationProvider::BringBrowserToFront(int browser_handle, |
| 3078 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3079 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 3080 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | cd7ffc2 | 2008-11-12 00:26:06 | [diff] [blame] | 3081 | browser->window()->Activate(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3082 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3083 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3084 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3085 | } |
| 3086 | } |
| 3087 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3088 | void AutomationProvider::IsPageMenuCommandEnabled(int browser_handle, |
| 3089 | int message_num, |
| 3090 | bool* menu_item_enabled) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3091 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 3092 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3093 | *menu_item_enabled = |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3094 | browser->command_updater()->IsCommandEnabled(message_num); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3095 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3096 | *menu_item_enabled = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3100 | void AutomationProvider::PrintNow(int tab_handle, |
| 3101 | IPC::Message* reply_message) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 3102 | NavigationController* tab = NULL; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3103 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 3104 | if (tab_contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3105 | FindAndActivateTab(tab); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 3106 | notification_observer_list_.AddObserver( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 3107 | new DocumentPrintedNotificationObserver(this, reply_message)); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3108 | if (tab_contents->PrintNow()) |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 3109 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3110 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3111 | AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); |
| 3112 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3113 | } |
[email protected] | d301c95 | 2009-07-13 15:02:41 | [diff] [blame] | 3114 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3115 | void AutomationProvider::SavePage(int tab_handle, |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 3116 | const FilePath& file_name, |
| 3117 | const FilePath& dir_path, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3118 | int type, |
| 3119 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3120 | if (!tab_tracker_->ContainsHandle(tab_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3121 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3122 | return; |
| 3123 | } |
| 3124 | |
| 3125 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 3126 | Browser* browser = FindAndActivateTab(nav); |
| 3127 | DCHECK(browser); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 3128 | if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3129 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3130 | return; |
| 3131 | } |
| 3132 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3133 | SavePackage::SavePackageType save_type = |
| 3134 | static_cast<SavePackage::SavePackageType>(type); |
| 3135 | DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML && |
| 3136 | save_type <= SavePackage::SAVE_AS_COMPLETE_HTML); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3137 | nav->tab_contents()->SavePage(file_name, dir_path, save_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3138 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3139 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3140 | } |
| 3141 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3142 | void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle, |
| 3143 | bool* success, |
| 3144 | std::wstring* text) { |
| 3145 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3146 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3147 | *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 3148 | GetText(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3149 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3150 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3151 | } |
| 3152 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3153 | void AutomationProvider::SetAutocompleteEditText(int autocomplete_edit_handle, |
| 3154 | const std::wstring& text, |
| 3155 | bool* success) { |
| 3156 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3157 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 3158 | autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
| 3159 | SetUserText(text); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3160 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3161 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | void AutomationProvider::AutocompleteEditGetMatches( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3165 | int autocomplete_edit_handle, |
| 3166 | bool* success, |
| 3167 | std::vector<AutocompleteMatchData>* matches) { |
| 3168 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3169 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 8deeb95 | 2008-10-09 18:21:27 | [diff] [blame] | 3170 | const AutocompleteResult& result = autocomplete_edit_tracker_-> |
| 3171 | GetResource(autocomplete_edit_handle)->model()->result(); |
| 3172 | for (AutocompleteResult::const_iterator i = result.begin(); |
| 3173 | i != result.end(); ++i) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3174 | matches->push_back(AutocompleteMatchData(*i)); |
| 3175 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3176 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | void AutomationProvider::AutocompleteEditIsQueryInProgress( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3180 | int autocomplete_edit_handle, |
| 3181 | bool* success, |
| 3182 | bool* query_in_progress) { |
| 3183 | *success = false; |
| 3184 | *query_in_progress = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3185 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3186 | *query_in_progress = autocomplete_edit_tracker_-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 3187 | GetResource(autocomplete_edit_handle)->model()->query_in_progress(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3188 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3189 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3190 | } |
| 3191 | |
[email protected] | 63514af | 2010-03-30 17:17:23 | [diff] [blame] | 3192 | #if !defined(OS_MACOSX) |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 3193 | |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 3194 | #endif // !defined(OS_MACOSX) |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 3195 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3196 | TabContents* AutomationProvider::GetTabContentsForHandle( |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 3197 | int handle, NavigationController** tab) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 3198 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3199 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3200 | if (tab) |
| 3201 | *tab = nav_controller; |
| 3202 | return nav_controller->tab_contents(); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 3203 | } |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3204 | return NULL; |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 3205 | } |
| 3206 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3207 | TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
| 3208 | : AutomationProvider(profile) { |
| 3209 | BrowserList::AddObserver(this); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 3210 | registrar_.Add(this, NotificationType::SESSION_END, |
| 3211 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | TestingAutomationProvider::~TestingAutomationProvider() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3215 | BrowserList::RemoveObserver(this); |
| 3216 | } |
| 3217 | |
| 3218 | void TestingAutomationProvider::OnChannelError() { |
[email protected] | a932444 | 2009-10-12 04:32:14 | [diff] [blame] | 3219 | BrowserList::CloseAllBrowsersAndExit(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3220 | AutomationProvider::OnChannelError(); |
| 3221 | } |
| 3222 | |
| 3223 | void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) { |
| 3224 | // For backwards compatibility with the testing automation interface, we |
| 3225 | // want the automation provider (and hence the process) to go away when the |
| 3226 | // last browser goes away. |
| 3227 | if (BrowserList::size() == 1) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3228 | // If you change this, update Observer for NotificationType::SESSION_END |
| 3229 | // below. |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 3230 | MessageLoop::current()->PostTask(FROM_HERE, |
| 3231 | NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3232 | } |
| 3233 | } |
| 3234 | |
| 3235 | void TestingAutomationProvider::Observe(NotificationType type, |
| 3236 | const NotificationSource& source, |
| 3237 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 3238 | DCHECK(type == NotificationType::SESSION_END); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3239 | // OnBrowserRemoving does a ReleaseLater. When session end is received we exit |
| 3240 | // before the task runs resulting in this object not being deleted. This |
| 3241 | // Release balance out the Release scheduled by OnBrowserRemoving. |
| 3242 | Release(); |
| 3243 | } |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 3244 | |
| 3245 | void TestingAutomationProvider::OnRemoveProvider() { |
| 3246 | AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 3247 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3248 | |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 3249 | void AutomationProvider::GetInfoBarCount(int handle, int* count) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3250 | *count = -1; // -1 means error. |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3251 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3252 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 3253 | if (nav_controller) |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 3254 | *count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3255 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3256 | } |
| 3257 | |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 3258 | void AutomationProvider::ClickInfoBarAccept(int handle, |
| 3259 | int info_bar_index, |
| 3260 | bool wait_for_navigation, |
| 3261 | IPC::Message* reply_message) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3262 | bool success = false; |
| 3263 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3264 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 3265 | if (nav_controller) { |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 3266 | int count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3267 | if (info_bar_index >= 0 && info_bar_index < count) { |
| 3268 | if (wait_for_navigation) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3269 | AddNavigationStatusListener(nav_controller, reply_message, 1, false); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3270 | } |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 3271 | InfoBarDelegate* delegate = |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 3272 | nav_controller->tab_contents()->GetInfoBarDelegateAt( |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 3273 | info_bar_index); |
| 3274 | if (delegate->AsConfirmInfoBarDelegate()) |
| 3275 | delegate->AsConfirmInfoBarDelegate()->Accept(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3276 | success = true; |
| 3277 | } |
| 3278 | } |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3279 | } |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 3280 | |
| 3281 | // This "!wait_for_navigation || !success condition" logic looks suspicious. |
| 3282 | // It will send a failure message when success is true but |
| 3283 | // |wait_for_navigation| is false. |
| 3284 | // TODO(phajdan.jr): investgate whether the reply param (currently |
| 3285 | // AUTOMATION_MSG_NAVIGATION_ERROR) should depend on success. |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3286 | if (!wait_for_navigation || !success) |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 3287 | AutomationMsg_ClickInfoBarAccept::WriteReplyParams( |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 3288 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3289 | } |
| 3290 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3291 | void AutomationProvider::GetLastNavigationTime(int handle, |
| 3292 | int64* last_navigation_time) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3293 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3294 | *last_navigation_time = time.ToInternalValue(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3295 | } |
| 3296 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3297 | void AutomationProvider::WaitForNavigation(int handle, |
| 3298 | int64 last_navigation_time, |
| 3299 | IPC::Message* reply_message) { |
[email protected] | 5fa7acd | 2009-09-25 20:04:25 | [diff] [blame] | 3300 | NavigationController* controller = tab_tracker_->GetResource(handle); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3301 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
[email protected] | 5fa7acd | 2009-09-25 20:04:25 | [diff] [blame] | 3302 | |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3303 | if (time.ToInternalValue() > last_navigation_time || !controller) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3304 | AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message, |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 3305 | controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR : |
| 3306 | AUTOMATION_MSG_NAVIGATION_SUCCESS); |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 3307 | Send(reply_message); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3308 | return; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3309 | } |
| 3310 | |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3311 | AddNavigationStatusListener(controller, reply_message, 1, true); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3312 | } |
| 3313 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3314 | void AutomationProvider::SetIntPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3315 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3316 | int value, |
| 3317 | bool* success) { |
| 3318 | *success = false; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3319 | if (browser_tracker_->ContainsHandle(handle)) { |
| 3320 | Browser* browser = browser_tracker_->GetResource(handle); |
| 3321 | browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3322 | *success = true; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3323 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 3324 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3325 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3326 | void AutomationProvider::SetStringPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3327 | const std::wstring& name, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 3328 | const std::string& value, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3329 | bool* success) { |
| 3330 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3331 | if (browser_tracker_->ContainsHandle(handle)) { |
| 3332 | Browser* browser = browser_tracker_->GetResource(handle); |
| 3333 | browser->profile()->GetPrefs()->SetString(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3334 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3335 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3336 | } |
| 3337 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3338 | void AutomationProvider::GetBooleanPreference(int handle, |
| 3339 | const std::wstring& name, |
[email protected] | b8f48d1 | 2009-11-09 20:14:36 | [diff] [blame] | 3340 | bool* success, |
| 3341 | bool* value) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3342 | *success = false; |
| 3343 | *value = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3344 | if (browser_tracker_->ContainsHandle(handle)) { |
| 3345 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3346 | *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str()); |
| 3347 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3348 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3349 | } |
| 3350 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3351 | void AutomationProvider::SetBooleanPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3352 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3353 | bool value, |
| 3354 | bool* success) { |
| 3355 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3356 | if (browser_tracker_->ContainsHandle(handle)) { |
| 3357 | Browser* browser = browser_tracker_->GetResource(handle); |
| 3358 | browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3359 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3360 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3364 | void AutomationProvider::GetPageCurrentEncoding( |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 3365 | int tab_handle, std::string* current_encoding) { |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3366 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 3367 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 3368 | Browser* browser = FindAndActivateTab(nav); |
| 3369 | DCHECK(browser); |
| 3370 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 3371 | if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) |
| 3372 | *current_encoding = nav->tab_contents()->encoding(); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3373 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3374 | } |
| 3375 | |
[email protected] | b8f48d1 | 2009-11-09 20:14:36 | [diff] [blame] | 3376 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3377 | void AutomationProvider::OverrideEncoding(int tab_handle, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 3378 | const std::string& encoding_name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3379 | bool* success) { |
| 3380 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3381 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 3382 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 3383 | if (!nav) |
| 3384 | return; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3385 | Browser* browser = FindAndActivateTab(nav); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3386 | |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 3387 | // If the browser has UI, simulate what a user would do. |
| 3388 | // Activate the tab and then click the encoding menu. |
| 3389 | if (browser && |
| 3390 | browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3391 | int selected_encoding_id = |
| 3392 | CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name); |
| 3393 | if (selected_encoding_id) { |
| 3394 | browser->OverrideEncoding(selected_encoding_id); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 3395 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3396 | } |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 3397 | } else { |
| 3398 | // There is no UI, Chrome probably runs as Chrome-Frame mode. |
| 3399 | // Try to get TabContents and call its override_encoding method. |
| 3400 | TabContents* contents = nav->tab_contents(); |
| 3401 | if (!contents) |
| 3402 | return; |
| 3403 | const std::string selected_encoding = |
| 3404 | CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding_name); |
| 3405 | if (selected_encoding.empty()) |
| 3406 | return; |
| 3407 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3408 | } |
| 3409 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 3410 | } |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 3411 | |
[email protected] | 4d434a1a | 2009-02-11 21:06:57 | [diff] [blame] | 3412 | void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) { |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 3413 | SavePackage::SetShouldPromptUser(should_prompt); |
| 3414 | } |
[email protected] | 87eab22 | 2009-03-13 00:47:45 | [diff] [blame] | 3415 | |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 3416 | void AutomationProvider::GetBlockedPopupCount(int handle, int* count) { |
| 3417 | *count = -1; // -1 is the error code |
| 3418 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3419 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 3420 | TabContents* tab_contents = nav_controller->tab_contents(); |
| 3421 | if (tab_contents) { |
| 3422 | BlockedPopupContainer* container = |
| 3423 | tab_contents->blocked_popup_container(); |
| 3424 | if (container) { |
| 3425 | *count = static_cast<int>(container->GetBlockedPopupCount()); |
| 3426 | } else { |
| 3427 | // If we don't have a container, we don't have any blocked popups to |
| 3428 | // contain! |
| 3429 | *count = 0; |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | } |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 3434 | |
| 3435 | void AutomationProvider::SelectAll(int tab_handle) { |
| 3436 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3437 | if (!view) { |
| 3438 | NOTREACHED(); |
| 3439 | return; |
| 3440 | } |
| 3441 | |
| 3442 | view->SelectAll(); |
| 3443 | } |
| 3444 | |
| 3445 | void AutomationProvider::Cut(int tab_handle) { |
| 3446 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3447 | if (!view) { |
| 3448 | NOTREACHED(); |
| 3449 | return; |
| 3450 | } |
| 3451 | |
| 3452 | view->Cut(); |
| 3453 | } |
| 3454 | |
| 3455 | void AutomationProvider::Copy(int tab_handle) { |
| 3456 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3457 | if (!view) { |
| 3458 | NOTREACHED(); |
| 3459 | return; |
| 3460 | } |
| 3461 | |
| 3462 | view->Copy(); |
| 3463 | } |
| 3464 | |
| 3465 | void AutomationProvider::Paste(int tab_handle) { |
| 3466 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3467 | if (!view) { |
| 3468 | NOTREACHED(); |
| 3469 | return; |
| 3470 | } |
| 3471 | |
| 3472 | view->Paste(); |
| 3473 | } |
| 3474 | |
| 3475 | void AutomationProvider::ReloadAsync(int tab_handle) { |
| 3476 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 3477 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 3478 | if (!tab) { |
| 3479 | NOTREACHED(); |
| 3480 | return; |
| 3481 | } |
| 3482 | |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 3483 | const bool check_for_repost = true; |
| 3484 | tab->Reload(check_for_repost); |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 3485 | } |
| 3486 | } |
| 3487 | |
| 3488 | void AutomationProvider::StopAsync(int tab_handle) { |
| 3489 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 3490 | if (!view) { |
[email protected] | 8b2b331 | 2009-09-14 18:38:36 | [diff] [blame] | 3491 | // We tolerate StopAsync being called even before a view has been created. |
| 3492 | // So just log a warning instead of a NOTREACHED(). |
| 3493 | DLOG(WARNING) << "StopAsync: no view for handle " << tab_handle; |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 3494 | return; |
| 3495 | } |
| 3496 | |
| 3497 | view->Stop(); |
| 3498 | } |
| 3499 | |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 3500 | void AutomationProvider::OnSetPageFontSize(int tab_handle, |
| 3501 | int font_size) { |
| 3502 | AutomationPageFontSize automation_font_size = |
| 3503 | static_cast<AutomationPageFontSize>(font_size); |
| 3504 | |
| 3505 | if (automation_font_size < SMALLEST_FONT || |
| 3506 | automation_font_size > LARGEST_FONT) { |
| 3507 | DLOG(ERROR) << "Invalid font size specified : " |
| 3508 | << font_size; |
| 3509 | return; |
| 3510 | } |
| 3511 | |
| 3512 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 3513 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 3514 | DCHECK(tab != NULL); |
| 3515 | if (tab && tab->tab_contents()) { |
| 3516 | DCHECK(tab->tab_contents()->profile() != NULL); |
| 3517 | tab->tab_contents()->profile()->GetPrefs()->SetInteger( |
| 3518 | prefs::kWebKitDefaultFontSize, font_size); |
| 3519 | } |
| 3520 | } |
| 3521 | } |
| 3522 | |
[email protected] | bc73b4e5 | 2010-03-26 04:16:20 | [diff] [blame] | 3523 | void AutomationProvider::RemoveBrowsingData(int remove_mask) { |
| 3524 | BrowsingDataRemover* remover; |
| 3525 | remover = new BrowsingDataRemover(profile(), |
| 3526 | BrowsingDataRemover::EVERYTHING, // All time periods. |
| 3527 | base::Time()); |
| 3528 | remover->Remove(remove_mask); |
| 3529 | // BrowsingDataRemover deletes itself. |
| 3530 | } |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 3531 | |
[email protected] | 2949e90d | 2009-08-21 15:32:52 | [diff] [blame] | 3532 | void AutomationProvider::WaitForBrowserWindowCountToBecome( |
| 3533 | int target_count, IPC::Message* reply_message) { |
| 3534 | if (static_cast<int>(BrowserList::size()) == target_count) { |
| 3535 | AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( |
| 3536 | reply_message, true); |
| 3537 | Send(reply_message); |
| 3538 | return; |
| 3539 | } |
| 3540 | |
| 3541 | // Set up an observer (it will delete itself). |
| 3542 | new BrowserCountChangeNotificationObserver(target_count, this, reply_message); |
| 3543 | } |
| 3544 | |
| 3545 | void AutomationProvider::WaitForAppModalDialogToBeShown( |
| 3546 | IPC::Message* reply_message) { |
| 3547 | if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) { |
| 3548 | AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( |
| 3549 | reply_message, true); |
| 3550 | Send(reply_message); |
| 3551 | return; |
| 3552 | } |
| 3553 | |
| 3554 | // Set up an observer (it will delete itself). |
| 3555 | new AppModalDialogShownObserver(this, reply_message); |
| 3556 | } |
| 3557 | |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 3558 | void AutomationProvider::GoBackBlockUntilNavigationsComplete( |
| 3559 | int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 3560 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3561 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 3562 | Browser* browser = FindAndActivateTab(tab); |
| 3563 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3564 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 3565 | false); |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 3566 | browser->GoBack(CURRENT_TAB); |
| 3567 | return; |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams( |
| 3572 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 3573 | Send(reply_message); |
| 3574 | } |
| 3575 | |
| 3576 | void AutomationProvider::GoForwardBlockUntilNavigationsComplete( |
| 3577 | int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 3578 | if (tab_tracker_->ContainsHandle(handle)) { |
| 3579 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 3580 | Browser* browser = FindAndActivateTab(tab); |
| 3581 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3582 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 3583 | false); |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 3584 | browser->GoForward(CURRENT_TAB); |
| 3585 | return; |
| 3586 | } |
| 3587 | } |
| 3588 | |
| 3589 | AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( |
| 3590 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 3591 | Send(reply_message); |
| 3592 | } |
| 3593 | |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 3594 | RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { |
| 3595 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 3596 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 3597 | if (!tab) { |
| 3598 | NOTREACHED(); |
| 3599 | return NULL; |
| 3600 | } |
| 3601 | |
| 3602 | TabContents* tab_contents = tab->tab_contents(); |
| 3603 | if (!tab_contents) { |
| 3604 | NOTREACHED(); |
| 3605 | return NULL; |
| 3606 | } |
| 3607 | |
| 3608 | RenderViewHost* view_host = tab_contents->render_view_host(); |
| 3609 | return view_host; |
| 3610 | } |
| 3611 | |
| 3612 | return NULL; |
| 3613 | } |
[email protected] | 675595f | 2009-08-26 22:32:04 | [diff] [blame] | 3614 | |
| 3615 | void AutomationProvider::GetBrowserForWindow(int window_handle, |
| 3616 | bool* success, |
| 3617 | int* browser_handle) { |
| 3618 | *success = false; |
| 3619 | *browser_handle = 0; |
| 3620 | |
| 3621 | gfx::NativeWindow window = window_tracker_->GetResource(window_handle); |
| 3622 | if (!window) |
| 3623 | return; |
| 3624 | |
| 3625 | BrowserList::const_iterator iter = BrowserList::begin(); |
| 3626 | for (;iter != BrowserList::end(); ++iter) { |
| 3627 | gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle(); |
| 3628 | if (window == this_window) { |
| 3629 | // Add() returns the existing handle for the resource if any. |
| 3630 | *browser_handle = browser_tracker_->Add(*iter); |
| 3631 | *success = true; |
| 3632 | return; |
| 3633 | } |
| 3634 | } |
| 3635 | } |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 3636 | |
| 3637 | void AutomationProvider::InstallExtension(const FilePath& crx_path, |
| 3638 | IPC::Message* reply_message) { |
| 3639 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3640 | if (service) { |
| 3641 | // The observer will delete itself when done. |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 3642 | new ExtensionInstallNotificationObserver(this, |
| 3643 | AutomationMsg_InstallExtension::ID, |
| 3644 | reply_message); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 3645 | |
| 3646 | const FilePath& install_dir = service->install_directory(); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 3647 | scoped_refptr<CrxInstaller> installer( |
| 3648 | new CrxInstaller(install_dir, |
| 3649 | service, |
| 3650 | NULL)); // silent install, no UI |
| 3651 | installer->set_allow_privilege_increase(true); |
| 3652 | installer->InstallCrx(crx_path); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 3653 | } else { |
| 3654 | AutomationMsg_InstallExtension::WriteReplyParams( |
| 3655 | reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); |
| 3656 | Send(reply_message); |
| 3657 | } |
| 3658 | } |
| 3659 | |
| 3660 | void AutomationProvider::LoadExpandedExtension( |
| 3661 | const FilePath& extension_dir, |
| 3662 | IPC::Message* reply_message) { |
[email protected] | a437825 | 2010-02-09 08:14:38 | [diff] [blame] | 3663 | if (profile_->GetExtensionsService()) { |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 3664 | // The observer will delete itself when done. |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 3665 | new ExtensionInstallNotificationObserver( |
| 3666 | this, |
| 3667 | AutomationMsg_LoadExpandedExtension::ID, |
| 3668 | reply_message); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 3669 | |
| 3670 | profile_->GetExtensionsService()->LoadExtension(extension_dir); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 3671 | } else { |
| 3672 | AutomationMsg_LoadExpandedExtension::WriteReplyParams( |
| 3673 | reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); |
| 3674 | Send(reply_message); |
| 3675 | } |
| 3676 | } |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 3677 | |
[email protected] | a1e62d1 | 2010-03-16 02:18:43 | [diff] [blame] | 3678 | void AutomationProvider::GetEnabledExtensions( |
| 3679 | std::vector<FilePath>* result) { |
| 3680 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3681 | DCHECK(service); |
| 3682 | if (service->extensions_enabled()) { |
| 3683 | const ExtensionList* extensions = service->extensions(); |
| 3684 | DCHECK(extensions); |
| 3685 | for (size_t i = 0; i < extensions->size(); ++i) { |
| 3686 | Extension* extension = (*extensions)[i]; |
| 3687 | DCHECK(extension); |
[email protected] | 472f099b | 2010-05-27 17:07:12 | [diff] [blame] | 3688 | if (extension->location() == Extension::INTERNAL || |
| 3689 | extension->location() == Extension::LOAD) { |
[email protected] | 237f28167 | 2010-03-20 12:37:07 | [diff] [blame] | 3690 | result->push_back(extension->path()); |
| 3691 | } |
[email protected] | a1e62d1 | 2010-03-16 02:18:43 | [diff] [blame] | 3692 | } |
| 3693 | } |
| 3694 | } |
| 3695 | |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 3696 | void AutomationProvider::WaitForExtensionTestResult( |
| 3697 | IPC::Message* reply_message) { |
| 3698 | DCHECK(reply_message_ == NULL); |
| 3699 | reply_message_ = reply_message; |
| 3700 | // Call MaybeSendResult, because the result might have come in before |
| 3701 | // we were waiting on it. |
| 3702 | extension_test_result_observer_->MaybeSendResult(); |
| 3703 | } |
| 3704 | |
| 3705 | void AutomationProvider::InstallExtensionAndGetHandle( |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 3706 | const FilePath& crx_path, bool with_ui, IPC::Message* reply_message) { |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 3707 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3708 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 3709 | if (service && manager) { |
| 3710 | // The observer will delete itself when done. |
| 3711 | new ExtensionReadyNotificationObserver( |
| 3712 | manager, |
| 3713 | this, |
| 3714 | AutomationMsg_InstallExtensionAndGetHandle::ID, |
| 3715 | reply_message); |
| 3716 | |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 3717 | ExtensionInstallUI* client = |
| 3718 | (with_ui ? new ExtensionInstallUI(profile_) : NULL); |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 3719 | scoped_refptr<CrxInstaller> installer( |
| 3720 | new CrxInstaller(service->install_directory(), |
| 3721 | service, |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 3722 | client)); |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 3723 | installer->set_allow_privilege_increase(true); |
| 3724 | installer->InstallCrx(crx_path); |
| 3725 | } else { |
| 3726 | AutomationMsg_InstallExtensionAndGetHandle::WriteReplyParams( |
| 3727 | reply_message, 0); |
| 3728 | Send(reply_message); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | void AutomationProvider::UninstallExtension(int extension_handle, |
| 3733 | bool* success) { |
| 3734 | *success = false; |
| 3735 | Extension* extension = GetExtension(extension_handle); |
| 3736 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3737 | if (extension && service) { |
| 3738 | ExtensionUnloadNotificationObserver observer; |
| 3739 | service->UninstallExtension(extension->id(), false); |
| 3740 | // The extension unload notification should have been sent synchronously |
| 3741 | // with the uninstall. Just to be safe, check that it was received. |
| 3742 | *success = observer.did_receive_unload_notification(); |
| 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | void AutomationProvider::EnableExtension(int extension_handle, |
| 3747 | IPC::Message* reply_message) { |
| 3748 | Extension* extension = GetDisabledExtension(extension_handle); |
| 3749 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3750 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 3751 | // Only enable if this extension is disabled. |
| 3752 | if (extension && service && manager) { |
| 3753 | // The observer will delete itself when done. |
| 3754 | new ExtensionReadyNotificationObserver( |
| 3755 | manager, |
| 3756 | this, |
| 3757 | AutomationMsg_EnableExtension::ID, |
| 3758 | reply_message); |
| 3759 | service->EnableExtension(extension->id()); |
| 3760 | } else { |
| 3761 | AutomationMsg_EnableExtension::WriteReplyParams(reply_message, false); |
| 3762 | Send(reply_message); |
| 3763 | } |
| 3764 | } |
| 3765 | |
| 3766 | void AutomationProvider::DisableExtension(int extension_handle, |
| 3767 | bool* success) { |
| 3768 | *success = false; |
| 3769 | Extension* extension = GetEnabledExtension(extension_handle); |
| 3770 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3771 | if (extension && service) { |
| 3772 | ExtensionUnloadNotificationObserver observer; |
| 3773 | service->DisableExtension(extension->id()); |
| 3774 | // The extension unload notification should have been sent synchronously |
| 3775 | // with the disable. Just to be safe, check that it was received. |
| 3776 | *success = observer.did_receive_unload_notification(); |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | void AutomationProvider::ExecuteExtensionActionInActiveTabAsync( |
| 3781 | int extension_handle, int browser_handle, |
| 3782 | IPC::Message* reply_message) { |
| 3783 | bool success = false; |
| 3784 | Extension* extension = GetEnabledExtension(extension_handle); |
| 3785 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3786 | ExtensionMessageService* message_service = |
| 3787 | profile_->GetExtensionMessageService(); |
| 3788 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
| 3789 | if (extension && service && message_service && browser) { |
| 3790 | int tab_id = ExtensionTabUtil::GetTabId(browser->GetSelectedTabContents()); |
| 3791 | if (extension->page_action()) { |
| 3792 | ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
| 3793 | browser->profile(), extension->id(), "action", tab_id, "", 1); |
| 3794 | success = true; |
| 3795 | } else if (extension->browser_action()) { |
| 3796 | ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( |
| 3797 | browser->profile(), extension->id(), browser); |
| 3798 | success = true; |
| 3799 | } |
| 3800 | } |
| 3801 | AutomationMsg_ExecuteExtensionActionInActiveTabAsync::WriteReplyParams( |
| 3802 | reply_message, success); |
| 3803 | Send(reply_message); |
| 3804 | } |
| 3805 | |
| 3806 | void AutomationProvider::MoveExtensionBrowserAction( |
| 3807 | int extension_handle, int index, bool* success) { |
| 3808 | *success = false; |
| 3809 | Extension* extension = GetEnabledExtension(extension_handle); |
| 3810 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3811 | if (extension && service) { |
| 3812 | ExtensionToolbarModel* toolbar = service->toolbar_model(); |
| 3813 | if (toolbar) { |
| 3814 | if (index >= 0 && index < static_cast<int>(toolbar->size())) { |
| 3815 | toolbar->MoveBrowserAction(extension, index); |
| 3816 | *success = true; |
| 3817 | } else { |
| 3818 | DLOG(WARNING) << "Attempted to move browser action to invalid index."; |
| 3819 | } |
| 3820 | } |
| 3821 | } |
| 3822 | } |
| 3823 | |
| 3824 | void AutomationProvider::GetExtensionProperty( |
| 3825 | int extension_handle, |
| 3826 | AutomationMsg_ExtensionProperty type, |
| 3827 | bool* success, |
| 3828 | std::string* value) { |
| 3829 | *success = false; |
| 3830 | Extension* extension = GetExtension(extension_handle); |
| 3831 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3832 | if (extension && service) { |
| 3833 | ExtensionToolbarModel* toolbar = service->toolbar_model(); |
| 3834 | int found_index = -1; |
| 3835 | int index = 0; |
| 3836 | switch (type) { |
| 3837 | case AUTOMATION_MSG_EXTENSION_ID: |
| 3838 | *value = extension->id(); |
| 3839 | *success = true; |
| 3840 | break; |
| 3841 | case AUTOMATION_MSG_EXTENSION_NAME: |
| 3842 | *value = extension->name(); |
| 3843 | *success = true; |
| 3844 | break; |
| 3845 | case AUTOMATION_MSG_EXTENSION_VERSION: |
| 3846 | *value = extension->VersionString(); |
| 3847 | *success = true; |
| 3848 | break; |
| 3849 | case AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX: |
| 3850 | if (toolbar) { |
| 3851 | for (ExtensionList::const_iterator iter = toolbar->begin(); |
| 3852 | iter != toolbar->end(); iter++) { |
| 3853 | // Skip this extension if we are in incognito mode |
| 3854 | // and it is not incognito-enabled. |
| 3855 | if (profile_->IsOffTheRecord() && |
| 3856 | !service->IsIncognitoEnabled(*iter)) |
| 3857 | continue; |
| 3858 | if (*iter == extension) { |
| 3859 | found_index = index; |
| 3860 | break; |
| 3861 | } |
| 3862 | index++; |
| 3863 | } |
| 3864 | *value = IntToString(found_index); |
| 3865 | *success = true; |
| 3866 | } |
| 3867 | break; |
| 3868 | default: |
| 3869 | LOG(WARNING) << "Trying to get undefined extension property"; |
| 3870 | break; |
| 3871 | } |
| 3872 | } |
| 3873 | } |
| 3874 | |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 3875 | void AutomationProvider::SaveAsAsync(int tab_handle) { |
| 3876 | NavigationController* tab = NULL; |
| 3877 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 3878 | if (tab_contents) |
| 3879 | tab_contents->OnSavePage(); |
| 3880 | } |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3881 | |
| 3882 | void AutomationProvider::SetContentSetting( |
| 3883 | int handle, |
| 3884 | const std::string& host, |
| 3885 | ContentSettingsType content_type, |
| 3886 | ContentSetting setting, |
| 3887 | bool* success) { |
| 3888 | *success = false; |
| 3889 | if (browser_tracker_->ContainsHandle(handle)) { |
| 3890 | Browser* browser = browser_tracker_->GetResource(handle); |
| 3891 | HostContentSettingsMap* map = |
| 3892 | browser->profile()->GetHostContentSettingsMap(); |
| 3893 | if (host.empty()) { |
| 3894 | map->SetDefaultContentSetting(content_type, setting); |
| 3895 | } else { |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 3896 | map->SetContentSetting(HostContentSettingsMap::Pattern(host), |
| 3897 | content_type, setting); |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3898 | } |
| 3899 | *success = true; |
| 3900 | } |
| 3901 | } |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 3902 | |
| 3903 | #if !defined(TOOLKIT_VIEWS) |
| 3904 | void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { |
| 3905 | NOTIMPLEMENTED(); |
| 3906 | }; |
| 3907 | |
| 3908 | void AutomationProvider::WaitForFocusedViewIDToChange( |
| 3909 | int handle, int previous_view_id, IPC::Message* reply_message) { |
| 3910 | NOTIMPLEMENTED(); |
| 3911 | } |
| 3912 | |
| 3913 | void AutomationProvider::StartTrackingPopupMenus( |
| 3914 | int browser_handle, bool* success) { |
| 3915 | NOTIMPLEMENTED(); |
| 3916 | } |
| 3917 | |
| 3918 | void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
| 3919 | NOTIMPLEMENTED(); |
| 3920 | } |
| 3921 | #endif // !defined(TOOLKIT_VIEWS) |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 3922 | |
| 3923 | void AutomationProvider::ResetToDefaultTheme() { |
| 3924 | profile_->ClearTheme(); |
| 3925 | } |