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