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