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