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