[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] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 40 | #include "chrome/browser/chrome_thread.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | #include "chrome/browser/dom_operation_notification_details.h" |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 42 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | cdaa865 | 2008-09-13 02:48:59 | [diff] [blame] | 43 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 44 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 45 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_message_service.h" |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_tabs_module.h" |
| 50 | #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 51 | #include "chrome/browser/extensions/extensions_service.h" |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 52 | #include "chrome/browser/extensions/user_script_master.h" |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 53 | #include "chrome/browser/find_bar.h" |
| 54 | #include "chrome/browser/find_bar_controller.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | #include "chrome/browser/find_notification_details.h" |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 56 | #include "chrome/browser/host_content_settings_map.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 57 | #include "chrome/browser/io_thread.h" |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 58 | #include "chrome/browser/location_bar.h" |
[email protected] | 3fcac68 | 2009-08-13 02:28:01 | [diff] [blame] | 59 | #include "chrome/browser/login_prompt.h" |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 60 | #include "chrome/browser/net/url_request_context_getter.h" |
[email protected] | f732c1e | 2009-07-30 15:48:53 | [diff] [blame] | 61 | #include "chrome/browser/net/url_request_mock_util.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 62 | #include "chrome/browser/platform_util.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 63 | #include "chrome/browser/pref_service.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 64 | #include "chrome/browser/profile_manager.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 65 | #include "chrome/browser/renderer_host/render_process_host.h" |
[email protected] | 6524b5f9 | 2009-01-22 17:48:25 | [diff] [blame] | 66 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 3b073b2 | 2009-01-16 03:29:03 | [diff] [blame] | 67 | #include "chrome/browser/ssl/ssl_manager.h" |
| 68 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 69 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 81af939 | 2009-04-21 02:37:45 | [diff] [blame] | 70 | #include "chrome/browser/tab_contents/tab_contents_view.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 71 | #include "chrome/common/automation_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 72 | #include "chrome/common/chrome_paths.h" |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 73 | #include "chrome/common/extensions/extension.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 74 | #include "chrome/common/json_value_serializer.h" |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 75 | #include "chrome/common/notification_service.h" |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 76 | #include "chrome/common/pref_names.h" |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 77 | #include "chrome/common/url_constants.h" |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 78 | #include "chrome/test/automation/automation_messages.h" |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 79 | #include "chrome/test/automation/tab_proxy.h" |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 80 | #include "net/proxy/proxy_service.h" |
| 81 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 82 | #include "net/url_request/url_request_context.h" |
[email protected] | 1b5a48c | 2010-04-29 23:08:30 | [diff] [blame^] | 83 | #include "chrome/browser/automation/ui_controls.h" |
[email protected] | 9a08bcf | 2009-08-12 19:56:28 | [diff] [blame] | 84 | #include "views/event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 86 | #if defined(OS_WIN) |
| 87 | // TODO(port): Port these headers. |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 88 | #include "chrome/browser/character_encoding.h" |
| 89 | #include "chrome/browser/download/save_package.h" |
| 90 | #include "chrome/browser/external_tab_container.h" |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 91 | #include "chrome/browser/printing/print_job.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 | |
| 216 | void AutomationProvider::RemoveNavigationStatusListener( |
| 217 | NotificationObserver* obs) { |
| 218 | notification_observer_list_.RemoveObserver(obs); |
| 219 | } |
| 220 | |
| 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 | |
| 231 | void AutomationProvider::RemoveTabStripObserver(NotificationObserver* obs) { |
| 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) { |
| 602 | RemoveTabStripObserver(observer); |
| 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] | 5a3b914 | 2009-08-28 21:03:17 | [diff] [blame] | 1110 | redirect_query_ = NULL; |
[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] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1619 | // Sample json input: { "command": "GetDownloadsInfo" } |
[email protected] | e6e376e | 2010-04-19 21:41:36 | [diff] [blame] | 1620 | // Refer chrome/test/pyautolib/download_info.py for sample json output. |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1621 | void AutomationProvider::GetDownloadsInfo( |
| 1622 | DictionaryValue* args, |
| 1623 | IPC::Message* reply_message) { |
| 1624 | std::string json_return; |
| 1625 | bool reply_return = true; |
| 1626 | AutomationProviderDownloadManagerObserver observer; |
| 1627 | std::vector<DownloadItem*> downloads; |
| 1628 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1629 | |
| 1630 | if (!profile_->HasCreatedDownloadManager()) { |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1631 | json_return = "{\"error\": \"no download manager\"}"; |
[email protected] | d4adc29 | 2010-04-15 18:06:39 | [diff] [blame] | 1632 | reply_return = false; |
| 1633 | } else { |
| 1634 | // Use DownloadManager's GetDownloads() method and not GetCurrentDownloads() |
| 1635 | // since that would be transient; a download might enter and empty out |
| 1636 | // the current download queue too soon to be noticed. |
| 1637 | profile_->GetDownloadManager()->GetDownloads(&observer, L""); |
| 1638 | downloads = observer.Downloads(); |
| 1639 | } |
| 1640 | |
| 1641 | std::map<DownloadItem::DownloadState, std::string> state_to_string; |
| 1642 | state_to_string[DownloadItem::IN_PROGRESS] = std::string("IN_PROGRESS"); |
| 1643 | state_to_string[DownloadItem::CANCELLED] = std::string("CANCELLED"); |
| 1644 | state_to_string[DownloadItem::REMOVING] = std::string("REMOVING"); |
| 1645 | state_to_string[DownloadItem::COMPLETE] = std::string("COMPLETE"); |
| 1646 | |
| 1647 | std::map<DownloadItem::SafetyState, std::string> safety_state_to_string; |
| 1648 | safety_state_to_string[DownloadItem::SAFE] = std::string("SAFE"); |
| 1649 | safety_state_to_string[DownloadItem::DANGEROUS] = std::string("DANGEROUS"); |
| 1650 | safety_state_to_string[DownloadItem::DANGEROUS_BUT_VALIDATED] = |
| 1651 | std::string("DANGEROUS_BUT_VALIDATED"); |
| 1652 | |
| 1653 | ListValue* list_of_downloads = new ListValue; |
| 1654 | for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 1655 | it != downloads.end(); |
| 1656 | it++) { // Fill info about each download item. |
| 1657 | DictionaryValue* dl_item_value = new DictionaryValue; |
| 1658 | dl_item_value->SetInteger(L"id", static_cast<int>((*it)->id())); |
| 1659 | dl_item_value->SetString(L"url", (*it)->url().spec()); |
| 1660 | dl_item_value->SetString(L"referrer_url", (*it)->referrer_url().spec()); |
| 1661 | dl_item_value->SetString(L"file_name", (*it)->file_name().value()); |
| 1662 | dl_item_value->SetString(L"full_path", (*it)->full_path().value()); |
| 1663 | dl_item_value->SetBoolean(L"is_paused", (*it)->is_paused()); |
| 1664 | dl_item_value->SetBoolean(L"open_when_complete", |
| 1665 | (*it)->open_when_complete()); |
| 1666 | dl_item_value->SetBoolean(L"is_extension_install", |
| 1667 | (*it)->is_extension_install()); |
| 1668 | dl_item_value->SetBoolean(L"is_temporary", (*it)->is_temporary()); |
| 1669 | dl_item_value->SetBoolean(L"is_otr", (*it)->is_otr()); // off-the-record |
| 1670 | dl_item_value->SetString(L"state", state_to_string[(*it)->state()]); |
| 1671 | dl_item_value->SetString(L"safety_state", |
| 1672 | safety_state_to_string[(*it)->safety_state()]); |
| 1673 | dl_item_value->SetInteger(L"PercentComplete", (*it)->PercentComplete()); |
| 1674 | list_of_downloads->Append(dl_item_value); |
| 1675 | } |
| 1676 | return_value->Set(L"downloads", list_of_downloads); |
| 1677 | base::JSONWriter::Write(return_value.get(), false, &json_return); |
| 1678 | |
| 1679 | AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 1680 | reply_message, json_return, reply_return); |
| 1681 | Send(reply_message); |
| 1682 | // All value objects allocated above are owned by |return_value| |
| 1683 | // and get freed by it. |
| 1684 | } |
| 1685 | |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1686 | void AutomationProvider::WaitForDownloadsToComplete( |
| 1687 | DictionaryValue* args, |
| 1688 | IPC::Message* reply_message) { |
| 1689 | std::string json_return; |
| 1690 | bool reply_return = true; |
| 1691 | AutomationProviderDownloadManagerObserver observer; |
| 1692 | std::vector<DownloadItem*> downloads; |
| 1693 | |
| 1694 | // Look for a quick return. |
| 1695 | if (!profile_->HasCreatedDownloadManager()) { |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1696 | json_return = "{\"error\": \"no download manager\"}"; |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1697 | reply_return = false; |
| 1698 | } else { |
| 1699 | profile_->GetDownloadManager()->GetCurrentDownloads(&observer, |
| 1700 | FilePath()); |
| 1701 | downloads = observer.Downloads(); |
| 1702 | if (downloads.size() == 0) { |
| 1703 | json_return = "{}"; |
| 1704 | } |
| 1705 | } |
| 1706 | if (!json_return.empty()) { |
| 1707 | AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 1708 | reply_message, json_return, reply_return); |
| 1709 | Send(reply_message); |
| 1710 | } |
| 1711 | |
| 1712 | // The observer owns itself. When the last observed item pings, it |
| 1713 | // deletes itself. |
| 1714 | AutomationProviderDownloadItemObserver* item_observer = |
| 1715 | new AutomationProviderDownloadItemObserver( |
| 1716 | this, reply_message, downloads.size()); |
| 1717 | for (std::vector<DownloadItem*>::iterator i = downloads.begin(); |
| 1718 | i != downloads.end(); |
| 1719 | i++) { |
| 1720 | (*i)->AddObserver(item_observer); |
| 1721 | } |
| 1722 | } |
| 1723 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1724 | // Sample json input: { "command": "GetPrefsInfo" } |
| 1725 | // Refer chrome/test/pyautolib/prefs_info.py for sample json output. |
| 1726 | void AutomationProvider::GetPrefsInfo(DictionaryValue* args, |
| 1727 | IPC::Message* reply_message) { |
| 1728 | std::string json_return; |
| 1729 | bool reply_return = true; |
| 1730 | |
| 1731 | const PrefService::PreferenceSet& prefs = |
| 1732 | profile_->GetPrefs()->preference_set(); |
| 1733 | DictionaryValue* items = new DictionaryValue; |
| 1734 | for (PrefService::PreferenceSet::const_iterator it = prefs.begin(); |
| 1735 | it != prefs.end(); ++it) { |
| 1736 | items->Set((*it)->name(), (*it)->GetValue()->DeepCopy()); |
| 1737 | } |
| 1738 | scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1739 | return_value->Set(L"prefs", items); // return_value owns items. |
| 1740 | |
| 1741 | base::JSONWriter::Write(return_value.get(), false, &json_return); |
| 1742 | AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 1743 | reply_message, json_return, reply_return); |
| 1744 | Send(reply_message); |
| 1745 | } |
| 1746 | |
| 1747 | // Sample json input: { "command": "SetPrefs", "path": path, "value": value } |
| 1748 | void AutomationProvider::SetPrefs(DictionaryValue* args, |
| 1749 | IPC::Message* reply_message) { |
| 1750 | bool reply_return = true; |
| 1751 | std::string json_return = "{}"; |
| 1752 | std::wstring path; |
| 1753 | Value* val; |
| 1754 | if (args->GetString(L"path", &path) && args->Get(L"value", &val)) { |
| 1755 | PrefService* pref_service = profile_->GetPrefs(); |
| 1756 | const PrefService::Preference* pref = |
| 1757 | pref_service->FindPreference(path.c_str()); |
| 1758 | if (!pref) { // Not a registered pref. |
| 1759 | json_return = "{\"error\": \"pref not registered.\"}"; |
| 1760 | reply_return = false; |
| 1761 | } else if (pref->IsManaged()) { // Do not attempt to change a managed pref. |
| 1762 | json_return = "{\"error\": \"pref is managed. cannot be changed.\"}"; |
| 1763 | reply_return = false; |
| 1764 | } else { // Set the pref. |
| 1765 | pref_service->Set(path.c_str(), *val); |
| 1766 | } |
| 1767 | } else { |
| 1768 | json_return = "{\"error\": \"no pref path or value given.\"}"; |
| 1769 | reply_return = false; |
| 1770 | } |
| 1771 | |
| 1772 | AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 1773 | reply_message, json_return, reply_return); |
| 1774 | Send(reply_message); |
| 1775 | } |
| 1776 | |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1777 | void AutomationProvider::SendJSONRequest( |
| 1778 | int handle, |
| 1779 | std::string json_request, |
| 1780 | IPC::Message* reply_message) { |
| 1781 | Browser* browser = NULL; |
| 1782 | std::string error_string; |
| 1783 | scoped_ptr<Value> values; |
| 1784 | |
| 1785 | // Basic error checking. |
| 1786 | if (browser_tracker_->ContainsHandle(handle)) { |
| 1787 | browser = browser_tracker_->GetResource(handle); |
| 1788 | } |
| 1789 | if (!browser) { |
| 1790 | error_string = "no browser object"; |
| 1791 | } else { |
| 1792 | base::JSONReader reader; |
| 1793 | std::string error; |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 1794 | values.reset(reader.ReadAndReturnError(json_request, true, NULL, &error)); |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1795 | if (!error.empty()) { |
| 1796 | error_string = error; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | // Make sure input is a dict with a string command. |
| 1801 | std::string command; |
| 1802 | DictionaryValue* dict_value = NULL; |
| 1803 | if (error_string.empty()) { |
| 1804 | if (values->GetType() != Value::TYPE_DICTIONARY) { |
| 1805 | error_string = "not a dict or no command key in dict"; |
| 1806 | } else { |
| 1807 | // Ownership remains with "values" variable. |
| 1808 | dict_value = static_cast<DictionaryValue*>(values.get()); |
| 1809 | if (!dict_value->GetStringASCII(std::string("command"), &command)) { |
| 1810 | error_string = "no command key in dict or not a string command"; |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1815 | // Map json commands to their handlers. |
| 1816 | std::map<std::string, JsonHandler> handler_map; |
| 1817 | handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo; |
| 1818 | handler_map["GetHistoryInfo"] = &AutomationProvider::GetHistoryInfo; |
| 1819 | handler_map["GetPrefsInfo"] = &AutomationProvider::GetPrefsInfo; |
| 1820 | handler_map["SetPrefs"] = &AutomationProvider::SetPrefs; |
| 1821 | handler_map["WaitForAllDownloadsToComplete"] = |
| 1822 | &AutomationProvider::WaitForDownloadsToComplete; |
| 1823 | |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1824 | if (error_string.empty()) { |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1825 | if (handler_map.find(std::string(command)) != handler_map.end()) { |
| 1826 | (this->*handler_map[command])(dict_value, reply_message); |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1827 | return; |
| 1828 | } else { |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1829 | error_string = "Unknown command. Options: "; |
| 1830 | for (std::map<std::string, JsonHandler>::const_iterator it = |
| 1831 | handler_map.begin(); it != handler_map.end(); ++it) { |
| 1832 | error_string += it->first + ", "; |
| 1833 | } |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | // If we hit an error, return info. |
[email protected] | 24e2b10 | 2010-04-29 17:56:47 | [diff] [blame] | 1838 | // Return a dict of {"error", "descriptive_string_for_error"}. |
[email protected] | 59a61124 | 2010-04-02 02:24:04 | [diff] [blame] | 1839 | // Else return an empty dict. |
| 1840 | std::string json_string; |
| 1841 | bool success = true; |
| 1842 | if (!error_string.empty()) { |
| 1843 | scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
| 1844 | dict->SetString(L"error", error_string); |
| 1845 | base::JSONWriter::Write(dict.get(), false, &json_string); |
| 1846 | success = false; |
| 1847 | } else { |
| 1848 | json_string = "{}"; |
| 1849 | } |
| 1850 | AutomationMsg_SendJSONRequest::WriteReplyParams( |
| 1851 | reply_message, json_string, success); |
| 1852 | Send(reply_message); |
| 1853 | } |
| 1854 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1855 | void AutomationProvider::HandleInspectElementRequest( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1856 | int handle, int x, int y, IPC::Message* reply_message) { |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1857 | TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
| 1858 | if (tab_contents) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1859 | DCHECK(reply_message_ == NULL); |
| 1860 | reply_message_ = reply_message; |
| 1861 | |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 1862 | DevToolsManager::GetInstance()->InspectElement( |
| 1863 | tab_contents->render_view_host(), x, y); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1864 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1865 | AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); |
| 1866 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | void AutomationProvider::ReceivedInspectElementResponse(int num_resources) { |
[email protected] | 396c3b3 | 2009-03-12 22:26:09 | [diff] [blame] | 1871 | if (reply_message_) { |
| 1872 | AutomationMsg_InspectElement::WriteReplyParams(reply_message_, |
| 1873 | num_resources); |
| 1874 | Send(reply_message_); |
| 1875 | reply_message_ = NULL; |
| 1876 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1877 | } |
| 1878 | |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1879 | class SetProxyConfigTask : public Task { |
| 1880 | public: |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1881 | SetProxyConfigTask(URLRequestContextGetter* request_context_getter, |
| 1882 | const std::string& new_proxy_config) |
[email protected] | 2aa336e | 2010-04-06 21:05:25 | [diff] [blame] | 1883 | : request_context_getter_(request_context_getter), |
| 1884 | proxy_config_(new_proxy_config) {} |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1885 | virtual void Run() { |
| 1886 | // First, deserialize the JSON string. If this fails, log and bail. |
| 1887 | JSONStringValueSerializer deserializer(proxy_config_); |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 1888 | std::string error_msg; |
| 1889 | scoped_ptr<Value> root(deserializer.Deserialize(NULL, &error_msg)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1890 | if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) { |
| 1891 | DLOG(WARNING) << "Received bad JSON string for ProxyConfig: " |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 1892 | << error_msg; |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1893 | return; |
| 1894 | } |
| 1895 | |
| 1896 | scoped_ptr<DictionaryValue> dict( |
| 1897 | static_cast<DictionaryValue*>(root.release())); |
| 1898 | // Now put together a proxy configuration from the deserialized string. |
| 1899 | net::ProxyConfig pc; |
| 1900 | PopulateProxyConfig(*dict.get(), &pc); |
| 1901 | |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1902 | net::ProxyService* proxy_service = |
| 1903 | request_context_getter_->GetURLRequestContext()->proxy_service(); |
| 1904 | DCHECK(proxy_service); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1905 | scoped_ptr<net::ProxyConfigService> proxy_config_service( |
| 1906 | new net::ProxyConfigServiceFixed(pc)); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1907 | proxy_service->ResetConfigService(proxy_config_service.release()); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) { |
| 1911 | DCHECK(pc); |
| 1912 | bool no_proxy = false; |
| 1913 | if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) { |
| 1914 | // Make no changes to the ProxyConfig. |
| 1915 | return; |
| 1916 | } |
| 1917 | bool auto_config; |
| 1918 | if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1919 | pc->set_auto_detect(true); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1920 | } |
| 1921 | std::string pac_url; |
| 1922 | if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1923 | pc->set_pac_url(GURL(pac_url)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1924 | } |
| 1925 | std::string proxy_bypass_list; |
| 1926 | if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1927 | pc->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_list); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1928 | } |
| 1929 | std::string proxy_server; |
| 1930 | if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) { |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 1931 | pc->proxy_rules().ParseFromString(proxy_server); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | private: |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1936 | scoped_refptr<URLRequestContextGetter> request_context_getter_; |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1937 | std::string proxy_config_; |
| 1938 | }; |
| 1939 | |
| 1940 | |
| 1941 | void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) { |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1942 | URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); |
| 1943 | if (!context_getter) { |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1944 | FilePath user_data_dir; |
| 1945 | PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 1946 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1947 | DCHECK(profile_manager); |
| 1948 | Profile* profile = profile_manager->GetDefaultProfile(user_data_dir); |
| 1949 | DCHECK(profile); |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1950 | context_getter = profile->GetRequestContext(); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1951 | } |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1952 | DCHECK(context_getter); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1953 | |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 1954 | ChromeThread::PostTask( |
| 1955 | ChromeThread::IO, FROM_HERE, |
[email protected] | be180c80 | 2009-10-23 06:33:31 | [diff] [blame] | 1956 | new SetProxyConfigTask(context_getter, new_proxy_config)); |
[email protected] | a7eee32f | 2009-05-22 18:08:17 | [diff] [blame] | 1957 | } |
| 1958 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 1959 | void AutomationProvider::GetDownloadDirectory( |
[email protected] | 1f733cf | 2009-09-30 20:46:33 | [diff] [blame] | 1960 | int handle, FilePath* download_directory) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1961 | DLOG(INFO) << "Handling download directory request"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1962 | if (tab_tracker_->ContainsHandle(handle)) { |
| 1963 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 1964 | DownloadManager* dlm = tab->profile()->GetDownloadManager(); |
| 1965 | DCHECK(dlm); |
[email protected] | 1f733cf | 2009-09-30 20:46:33 | [diff] [blame] | 1966 | *download_directory = dlm->download_path(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1967 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1968 | } |
| 1969 | |
[email protected] | 6a5670d2 | 2009-10-27 16:21:34 | [diff] [blame] | 1970 | void AutomationProvider::OpenNewBrowserWindow(bool show, |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 1971 | IPC::Message* reply_message) { |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 1972 | OpenNewBrowserWindowOfType(static_cast<int>(Browser::TYPE_NORMAL), show, |
| 1973 | reply_message); |
| 1974 | } |
| 1975 | |
| 1976 | void AutomationProvider::OpenNewBrowserWindowOfType( |
| 1977 | int type, bool show, IPC::Message* reply_message) { |
[email protected] | 14c0a03 | 2009-04-13 18:15:14 | [diff] [blame] | 1978 | new BrowserOpenedNotificationObserver(this, reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1979 | // We may have no current browser windows open so don't rely on |
| 1980 | // asking an existing browser to execute the IDC_NEWWINDOW command |
[email protected] | 982921f1 | 2009-10-27 21:43:53 | [diff] [blame] | 1981 | Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_); |
| 1982 | browser->CreateBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1983 | browser->AddBlankTab(true); |
[email protected] | 3683cbb | 2009-04-09 21:46:15 | [diff] [blame] | 1984 | if (show) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1985 | browser->window()->Show(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1986 | } |
| 1987 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1988 | void AutomationProvider::GetWindowForBrowser(int browser_handle, |
| 1989 | bool* success, |
| 1990 | int* handle) { |
| 1991 | *success = false; |
| 1992 | *handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1993 | |
| 1994 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 1995 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 1996 | gfx::NativeWindow win = browser->window()->GetNativeHandle(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1997 | // Add() returns the existing handle for the resource if any. |
[email protected] | 0e9f4ee | 2009-04-08 01:44:20 | [diff] [blame] | 1998 | *handle = window_tracker_->Add(win); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 1999 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2000 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void AutomationProvider::GetAutocompleteEditForBrowser( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2004 | int browser_handle, |
| 2005 | bool* success, |
| 2006 | int* autocomplete_edit_handle) { |
| 2007 | *success = false; |
| 2008 | *autocomplete_edit_handle = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2009 | |
| 2010 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2011 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 13869dd | 2009-05-05 00:40:06 | [diff] [blame] | 2012 | LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 2013 | AutocompleteEditView* edit_view = loc_bar->location_entry(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2014 | // Add() returns the existing handle for the resource if any. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2015 | *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view); |
| 2016 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2017 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2018 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2019 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2020 | void AutomationProvider::ShowInterstitialPage(int tab_handle, |
| 2021 | const std::string& html_text, |
| 2022 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2023 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2024 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2025 | TabContents* tab_contents = controller->tab_contents(); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2026 | |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2027 | AddNavigationStatusListener(controller, reply_message, 1, false); |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2028 | AutomationInterstitialPage* interstitial = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2029 | new AutomationInterstitialPage(tab_contents, |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2030 | GURL("about:interstitial"), |
| 2031 | html_text); |
| 2032 | interstitial->Show(); |
| 2033 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2034 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2035 | |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2036 | AutomationMsg_ShowInterstitialPage::WriteReplyParams( |
| 2037 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2038 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2039 | } |
| 2040 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2041 | void AutomationProvider::HideInterstitialPage(int tab_handle, |
| 2042 | bool* success) { |
| 2043 | *success = false; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2044 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL); |
| 2045 | if (tab_contents && tab_contents->interstitial_page()) { |
| 2046 | tab_contents->interstitial_page()->DontProceed(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2047 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2048 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2049 | } |
| 2050 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2051 | void AutomationProvider::CloseTab(int tab_handle, |
| 2052 | bool wait_until_closed, |
| 2053 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2054 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2055 | NavigationController* controller = tab_tracker_->GetResource(tab_handle); |
| 2056 | int index; |
| 2057 | Browser* browser = Browser::GetBrowserForController(controller, &index); |
| 2058 | DCHECK(browser); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2059 | new TabClosedNotificationObserver(this, wait_until_closed, reply_message); |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2060 | browser->CloseContents(controller->tab_contents()); |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2061 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2062 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2063 | |
| 2064 | AutomationMsg_CloseTab::WriteReplyParams(reply_message, false); |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 2065 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2066 | } |
| 2067 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2068 | void AutomationProvider::CloseBrowser(int browser_handle, |
| 2069 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2070 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2071 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2072 | new BrowserClosedNotificationObserver(browser, this, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2073 | reply_message); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 2074 | browser->window()->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2075 | } else { |
| 2076 | NOTREACHED(); |
| 2077 | } |
| 2078 | } |
| 2079 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2080 | void AutomationProvider::CloseBrowserAsync(int browser_handle) { |
| 2081 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2082 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
| 2083 | browser->window()->Close(); |
| 2084 | } else { |
| 2085 | NOTREACHED(); |
| 2086 | } |
| 2087 | } |
| 2088 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2089 | void AutomationProvider::NavigateInExternalTab( |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 2090 | int handle, const GURL& url, const GURL& referrer, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2091 | AutomationMsg_NavigationResponseValues* status) { |
| 2092 | *status = AUTOMATION_MSG_NAVIGATION_ERROR; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2093 | |
| 2094 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2095 | NavigationController* tab = tab_tracker_->GetResource(handle); |
[email protected] | b36a9f9 | 2009-10-19 17:34:57 | [diff] [blame] | 2096 | tab->LoadURL(url, referrer, PageTransition::TYPED); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2097 | *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2098 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2099 | } |
| 2100 | |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 2101 | void AutomationProvider::NavigateExternalTabAtIndex( |
| 2102 | int handle, int navigation_index, |
| 2103 | AutomationMsg_NavigationResponseValues* status) { |
| 2104 | *status = AUTOMATION_MSG_NAVIGATION_ERROR; |
| 2105 | |
| 2106 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2107 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2108 | tab->GoToIndex(navigation_index); |
| 2109 | *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; |
| 2110 | } |
| 2111 | } |
| 2112 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2113 | void AutomationProvider::WaitForTabToBeRestored(int tab_handle, |
| 2114 | IPC::Message* reply_message) { |
| 2115 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2116 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2117 | restore_tracker_.reset( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2118 | new NavigationControllerRestoredObserver(this, tab, reply_message)); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2122 | void AutomationProvider::GetSecurityState(int handle, bool* success, |
| 2123 | SecurityStyle* security_style, |
| 2124 | int* ssl_cert_status, |
| 2125 | int* mixed_content_status) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2126 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2127 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2128 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2129 | *success = true; |
| 2130 | *security_style = entry->ssl().security_style(); |
| 2131 | *ssl_cert_status = entry->ssl().cert_status(); |
| 2132 | *mixed_content_status = entry->ssl().content_status(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2133 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2134 | *success = false; |
| 2135 | *security_style = SECURITY_STYLE_UNKNOWN; |
| 2136 | *ssl_cert_status = 0; |
| 2137 | *mixed_content_status = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2141 | void AutomationProvider::GetPageType(int handle, bool* success, |
| 2142 | NavigationEntry::PageType* page_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2143 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2144 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2145 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2146 | *page_type = entry->page_type(); |
| 2147 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2148 | // In order to return the proper result when an interstitial is shown and |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2149 | // no navigation entry were created for it we need to ask the TabContents. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2150 | if (*page_type == NavigationEntry::NORMAL_PAGE && |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2151 | tab->tab_contents()->showing_interstitial_page()) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2152 | *page_type = NavigationEntry::INTERSTITIAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2153 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2154 | *success = false; |
| 2155 | *page_type = NavigationEntry::NORMAL_PAGE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2156 | } |
| 2157 | } |
| 2158 | |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 2159 | void AutomationProvider::GetMetricEventDuration(const std::string& event_name, |
| 2160 | int* duration_ms) { |
| 2161 | *duration_ms = metric_event_duration_observer_->GetEventDurationMs( |
| 2162 | event_name); |
| 2163 | } |
| 2164 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2165 | void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed, |
| 2166 | IPC::Message* reply_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2167 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2168 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2169 | NavigationEntry* entry = tab->GetActiveEntry(); |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 2170 | if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 2171 | TabContents* tab_contents = tab->tab_contents(); |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 2172 | InterstitialPage* ssl_blocking_page = |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2173 | InterstitialPage::GetInterstitialPage(tab_contents); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2174 | if (ssl_blocking_page) { |
| 2175 | if (proceed) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2176 | AddNavigationStatusListener(tab, reply_message, 1, false); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2177 | ssl_blocking_page->Proceed(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2178 | return; |
| 2179 | } |
| 2180 | ssl_blocking_page->DontProceed(); |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2181 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| 2182 | reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2183 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2184 | return; |
| 2185 | } |
| 2186 | } |
| 2187 | } |
| 2188 | // We failed. |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2189 | AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( |
| 2190 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2191 | Send(reply_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2192 | } |
| 2193 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2194 | void AutomationProvider::BringBrowserToFront(int browser_handle, |
| 2195 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2196 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2197 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | cd7ffc2 | 2008-11-12 00:26:06 | [diff] [blame] | 2198 | browser->window()->Activate(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2199 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2200 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2201 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2205 | void AutomationProvider::IsPageMenuCommandEnabled(int browser_handle, |
| 2206 | int message_num, |
| 2207 | bool* menu_item_enabled) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2208 | if (browser_tracker_->ContainsHandle(browser_handle)) { |
| 2209 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2210 | *menu_item_enabled = |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2211 | browser->command_updater()->IsCommandEnabled(message_num); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2212 | } else { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2213 | *menu_item_enabled = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2214 | } |
| 2215 | } |
| 2216 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2217 | void AutomationProvider::PrintNow(int tab_handle, |
| 2218 | IPC::Message* reply_message) { |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 2219 | #if defined(OS_WIN) |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2220 | NavigationController* tab = NULL; |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2221 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 2222 | if (tab_contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2223 | FindAndActivateTab(tab); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2224 | notification_observer_list_.AddObserver( |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2225 | new DocumentPrintedNotificationObserver(this, reply_message)); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2226 | if (tab_contents->PrintNow()) |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2227 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2228 | } |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2229 | AutomationMsg_PrintNow::WriteReplyParams(reply_message, false); |
| 2230 | Send(reply_message); |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 2231 | #else |
| 2232 | // TODO(port): Remove once DocumentPrintedNotificationObserver is implemented. |
| 2233 | NOTIMPLEMENTED(); |
| 2234 | #endif // defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2235 | } |
[email protected] | d301c95 | 2009-07-13 15:02:41 | [diff] [blame] | 2236 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2237 | void AutomationProvider::SavePage(int tab_handle, |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 2238 | const FilePath& file_name, |
| 2239 | const FilePath& dir_path, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2240 | int type, |
| 2241 | bool* success) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2242 | if (!tab_tracker_->ContainsHandle(tab_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2243 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2244 | return; |
| 2245 | } |
| 2246 | |
| 2247 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 2248 | Browser* browser = FindAndActivateTab(nav); |
| 2249 | DCHECK(browser); |
[email protected] | 1fc02520 | 2009-01-20 23:03:14 | [diff] [blame] | 2250 | if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2251 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2252 | return; |
| 2253 | } |
| 2254 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2255 | SavePackage::SavePackageType save_type = |
| 2256 | static_cast<SavePackage::SavePackageType>(type); |
| 2257 | DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML && |
| 2258 | save_type <= SavePackage::SAVE_AS_COMPLETE_HTML); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2259 | nav->tab_contents()->SavePage(file_name, dir_path, save_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2260 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2261 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2262 | } |
| 2263 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2264 | void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle, |
| 2265 | bool* success, |
| 2266 | std::wstring* text) { |
| 2267 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2268 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2269 | *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 2270 | GetText(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2271 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2272 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2273 | } |
| 2274 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2275 | void AutomationProvider::SetAutocompleteEditText(int autocomplete_edit_handle, |
| 2276 | const std::wstring& text, |
| 2277 | bool* success) { |
| 2278 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2279 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 2280 | autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)-> |
| 2281 | SetUserText(text); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2282 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2283 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | void AutomationProvider::AutocompleteEditGetMatches( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2287 | int autocomplete_edit_handle, |
| 2288 | bool* success, |
| 2289 | std::vector<AutocompleteMatchData>* matches) { |
| 2290 | *success = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2291 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 8deeb95 | 2008-10-09 18:21:27 | [diff] [blame] | 2292 | const AutocompleteResult& result = autocomplete_edit_tracker_-> |
| 2293 | GetResource(autocomplete_edit_handle)->model()->result(); |
| 2294 | for (AutocompleteResult::const_iterator i = result.begin(); |
| 2295 | i != result.end(); ++i) |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2296 | matches->push_back(AutocompleteMatchData(*i)); |
| 2297 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2298 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | void AutomationProvider::AutocompleteEditIsQueryInProgress( |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2302 | int autocomplete_edit_handle, |
| 2303 | bool* success, |
| 2304 | bool* query_in_progress) { |
| 2305 | *success = false; |
| 2306 | *query_in_progress = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2307 | if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2308 | *query_in_progress = autocomplete_edit_tracker_-> |
[email protected] | 81c2122 | 2008-09-10 19:35:52 | [diff] [blame] | 2309 | GetResource(autocomplete_edit_handle)->model()->query_in_progress(); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2310 | *success = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2311 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2312 | } |
| 2313 | |
[email protected] | 63514af | 2010-03-30 17:17:23 | [diff] [blame] | 2314 | #if !defined(OS_MACOSX) |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 2315 | void AutomationProvider::OnMessageFromExternalHost(int handle, |
| 2316 | const std::string& message, |
| 2317 | const std::string& origin, |
| 2318 | const std::string& target) { |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2319 | RenderViewHost* view_host = GetViewForTab(handle); |
| 2320 | if (!view_host) { |
| 2321 | return; |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 2322 | } |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2323 | |
| 2324 | if (AutomationExtensionFunction::InterceptMessageFromExternalHost( |
| 2325 | view_host, message, origin, target)) { |
| 2326 | // Message was diverted. |
| 2327 | return; |
| 2328 | } |
| 2329 | |
| 2330 | if (ExtensionPortContainer::InterceptMessageFromExternalHost(message, |
| 2331 | origin, target, this, view_host, handle)) { |
| 2332 | // Message was diverted. |
| 2333 | return; |
| 2334 | } |
| 2335 | |
| 2336 | if (InterceptBrowserEventMessageFromExternalHost(message, origin, target)) { |
| 2337 | // Message was diverted. |
| 2338 | return; |
| 2339 | } |
| 2340 | |
| 2341 | view_host->ForwardMessageFromExternalHost(message, origin, target); |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 2342 | } |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 2343 | |
| 2344 | bool AutomationProvider::InterceptBrowserEventMessageFromExternalHost( |
| 2345 | const std::string& message, const std::string& origin, |
| 2346 | const std::string& target) { |
| 2347 | if (target != |
| 2348 | extension_automation_constants::kAutomationBrowserEventRequestTarget) |
| 2349 | return false; |
| 2350 | |
| 2351 | if (origin != extension_automation_constants::kAutomationOrigin) { |
| 2352 | LOG(WARNING) << "Wrong origin on automation browser event " << origin; |
| 2353 | return false; |
| 2354 | } |
| 2355 | |
| 2356 | // The message is a JSON-encoded array with two elements, both strings. The |
| 2357 | // first is the name of the event to dispatch. The second is a JSON-encoding |
| 2358 | // of the arguments specific to that event. |
[email protected] | 93d49d7 | 2009-10-23 20:00:20 | [diff] [blame] | 2359 | scoped_ptr<Value> message_value(base::JSONReader::Read(message, false)); |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 2360 | if (!message_value.get() || !message_value->IsType(Value::TYPE_LIST)) { |
| 2361 | LOG(WARNING) << "Invalid browser event specified through automation"; |
| 2362 | return false; |
| 2363 | } |
| 2364 | |
| 2365 | const ListValue* args = static_cast<const ListValue*>(message_value.get()); |
| 2366 | |
| 2367 | std::string event_name; |
| 2368 | if (!args->GetString(0, &event_name)) { |
| 2369 | LOG(WARNING) << "No browser event name specified through automation"; |
| 2370 | return false; |
| 2371 | } |
| 2372 | |
| 2373 | std::string json_args; |
| 2374 | if (!args->GetString(1, &json_args)) { |
| 2375 | LOG(WARNING) << "No browser event args specified through automation"; |
| 2376 | return false; |
| 2377 | } |
| 2378 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 2379 | if (profile()->GetExtensionMessageService()) { |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 2380 | profile()->GetExtensionMessageService()->DispatchEventToRenderers( |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 2381 | event_name, json_args, profile()->IsOffTheRecord(), GURL()); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 2382 | } |
[email protected] | a902489 | 2009-06-16 23:13:55 | [diff] [blame] | 2383 | |
| 2384 | return true; |
| 2385 | } |
[email protected] | 5ae5bed | 2009-08-21 18:52:44 | [diff] [blame] | 2386 | #endif // !defined(OS_MACOSX) |
[email protected] | fa83e76 | 2008-08-15 21:41:39 | [diff] [blame] | 2387 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2388 | TabContents* AutomationProvider::GetTabContentsForHandle( |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2389 | int handle, NavigationController** tab) { |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2390 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2391 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2392 | if (tab) |
| 2393 | *tab = nav_controller; |
| 2394 | return nav_controller->tab_contents(); |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2395 | } |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2396 | return NULL; |
[email protected] | 20e93d1 | 2008-08-28 16:31:57 | [diff] [blame] | 2397 | } |
| 2398 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2399 | TestingAutomationProvider::TestingAutomationProvider(Profile* profile) |
| 2400 | : AutomationProvider(profile) { |
| 2401 | BrowserList::AddObserver(this); |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 2402 | registrar_.Add(this, NotificationType::SESSION_END, |
| 2403 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | TestingAutomationProvider::~TestingAutomationProvider() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2407 | BrowserList::RemoveObserver(this); |
| 2408 | } |
| 2409 | |
| 2410 | void TestingAutomationProvider::OnChannelError() { |
[email protected] | a932444 | 2009-10-12 04:32:14 | [diff] [blame] | 2411 | BrowserList::CloseAllBrowsersAndExit(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2412 | AutomationProvider::OnChannelError(); |
| 2413 | } |
| 2414 | |
| 2415 | void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) { |
| 2416 | // For backwards compatibility with the testing automation interface, we |
| 2417 | // want the automation provider (and hence the process) to go away when the |
| 2418 | // last browser goes away. |
| 2419 | if (BrowserList::size() == 1) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2420 | // If you change this, update Observer for NotificationType::SESSION_END |
| 2421 | // below. |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 2422 | MessageLoop::current()->PostTask(FROM_HERE, |
| 2423 | NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | void TestingAutomationProvider::Observe(NotificationType type, |
| 2428 | const NotificationSource& source, |
| 2429 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 2430 | DCHECK(type == NotificationType::SESSION_END); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2431 | // OnBrowserRemoving does a ReleaseLater. When session end is received we exit |
| 2432 | // before the task runs resulting in this object not being deleted. This |
| 2433 | // Release balance out the Release scheduled by OnBrowserRemoving. |
| 2434 | Release(); |
| 2435 | } |
[email protected] | 295039bd | 2008-08-15 04:32:57 | [diff] [blame] | 2436 | |
| 2437 | void TestingAutomationProvider::OnRemoveProvider() { |
| 2438 | AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 2439 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2440 | |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 2441 | void AutomationProvider::GetInfoBarCount(int handle, int* count) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2442 | *count = -1; // -1 means error. |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2443 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2444 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2445 | if (nav_controller) |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2446 | *count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2447 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2448 | } |
| 2449 | |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 2450 | void AutomationProvider::ClickInfoBarAccept(int handle, |
| 2451 | int info_bar_index, |
| 2452 | bool wait_for_navigation, |
| 2453 | IPC::Message* reply_message) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2454 | bool success = false; |
| 2455 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2456 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 2457 | if (nav_controller) { |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2458 | int count = nav_controller->tab_contents()->infobar_delegate_count(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2459 | if (info_bar_index >= 0 && info_bar_index < count) { |
| 2460 | if (wait_for_navigation) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2461 | AddNavigationStatusListener(nav_controller, reply_message, 1, false); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2462 | } |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2463 | InfoBarDelegate* delegate = |
[email protected] | 7f0005a | 2009-04-15 03:25:11 | [diff] [blame] | 2464 | nav_controller->tab_contents()->GetInfoBarDelegateAt( |
[email protected] | eb9ba19 | 2008-12-02 02:41:34 | [diff] [blame] | 2465 | info_bar_index); |
| 2466 | if (delegate->AsConfirmInfoBarDelegate()) |
| 2467 | delegate->AsConfirmInfoBarDelegate()->Accept(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2468 | success = true; |
| 2469 | } |
| 2470 | } |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2471 | } |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 2472 | |
| 2473 | // This "!wait_for_navigation || !success condition" logic looks suspicious. |
| 2474 | // It will send a failure message when success is true but |
| 2475 | // |wait_for_navigation| is false. |
| 2476 | // TODO(phajdan.jr): investgate whether the reply param (currently |
| 2477 | // AUTOMATION_MSG_NAVIGATION_ERROR) should depend on success. |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2478 | if (!wait_for_navigation || !success) |
[email protected] | 816633a | 2009-11-11 21:48:18 | [diff] [blame] | 2479 | AutomationMsg_ClickInfoBarAccept::WriteReplyParams( |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2480 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2481 | } |
| 2482 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2483 | void AutomationProvider::GetLastNavigationTime(int handle, |
| 2484 | int64* last_navigation_time) { |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2485 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2486 | *last_navigation_time = time.ToInternalValue(); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2487 | } |
| 2488 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2489 | void AutomationProvider::WaitForNavigation(int handle, |
| 2490 | int64 last_navigation_time, |
| 2491 | IPC::Message* reply_message) { |
[email protected] | 5fa7acd | 2009-09-25 20:04:25 | [diff] [blame] | 2492 | NavigationController* controller = tab_tracker_->GetResource(handle); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2493 | Time time = tab_tracker_->GetLastNavigationTime(handle); |
[email protected] | 5fa7acd | 2009-09-25 20:04:25 | [diff] [blame] | 2494 | |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2495 | if (time.ToInternalValue() > last_navigation_time || !controller) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2496 | AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message, |
[email protected] | 457f5cf | 2009-08-18 16:37:52 | [diff] [blame] | 2497 | controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR : |
| 2498 | AUTOMATION_MSG_NAVIGATION_SUCCESS); |
[email protected] | 58f622a6 | 2009-10-04 01:17:55 | [diff] [blame] | 2499 | Send(reply_message); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2500 | return; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2501 | } |
| 2502 | |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2503 | AddNavigationStatusListener(controller, reply_message, 1, true); |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2504 | } |
| 2505 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2506 | void AutomationProvider::SetIntPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2507 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2508 | int value, |
| 2509 | bool* success) { |
| 2510 | *success = false; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2511 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2512 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2513 | browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2514 | *success = true; |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2515 | } |
[email protected] | 8a3422c9 | 2008-09-24 17:42:42 | [diff] [blame] | 2516 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2517 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2518 | void AutomationProvider::SetStringPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2519 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2520 | const std::wstring& value, |
| 2521 | bool* success) { |
| 2522 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2523 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2524 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2525 | browser->profile()->GetPrefs()->SetString(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2526 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2527 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2528 | } |
| 2529 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2530 | void AutomationProvider::GetBooleanPreference(int handle, |
| 2531 | const std::wstring& name, |
[email protected] | b8f48d1 | 2009-11-09 20:14:36 | [diff] [blame] | 2532 | bool* success, |
| 2533 | bool* value) { |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2534 | *success = false; |
| 2535 | *value = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2536 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2537 | Browser* browser = browser_tracker_->GetResource(handle); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2538 | *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str()); |
| 2539 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2540 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2541 | } |
| 2542 | |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2543 | void AutomationProvider::SetBooleanPreference(int handle, |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2544 | const std::wstring& name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2545 | bool value, |
| 2546 | bool* success) { |
| 2547 | *success = false; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2548 | if (browser_tracker_->ContainsHandle(handle)) { |
| 2549 | Browser* browser = browser_tracker_->GetResource(handle); |
| 2550 | browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2551 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2552 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2556 | void AutomationProvider::GetPageCurrentEncoding( |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2557 | int tab_handle, std::string* current_encoding) { |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2558 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2559 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
| 2560 | Browser* browser = FindAndActivateTab(nav); |
| 2561 | DCHECK(browser); |
| 2562 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2563 | if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) |
| 2564 | *current_encoding = nav->tab_contents()->encoding(); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2565 | } |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2566 | } |
| 2567 | |
[email protected] | b8f48d1 | 2009-11-09 20:14:36 | [diff] [blame] | 2568 | // Gets the current used encoding name of the page in the specified tab. |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2569 | void AutomationProvider::OverrideEncoding(int tab_handle, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2570 | const std::string& encoding_name, |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2571 | bool* success) { |
| 2572 | *success = false; |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2573 | #if defined(OS_WIN) |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2574 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2575 | NavigationController* nav = tab_tracker_->GetResource(tab_handle); |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 2576 | if (!nav) |
| 2577 | return; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2578 | Browser* browser = FindAndActivateTab(nav); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2579 | |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 2580 | // If the browser has UI, simulate what a user would do. |
| 2581 | // Activate the tab and then click the encoding menu. |
| 2582 | if (browser && |
| 2583 | browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) { |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2584 | int selected_encoding_id = |
| 2585 | CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name); |
| 2586 | if (selected_encoding_id) { |
| 2587 | browser->OverrideEncoding(selected_encoding_id); |
[email protected] | 71f65dd | 2009-02-11 19:14:56 | [diff] [blame] | 2588 | *success = true; |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2589 | } |
[email protected] | 2f2afba | 2010-04-01 01:53:19 | [diff] [blame] | 2590 | } else { |
| 2591 | // There is no UI, Chrome probably runs as Chrome-Frame mode. |
| 2592 | // Try to get TabContents and call its override_encoding method. |
| 2593 | TabContents* contents = nav->tab_contents(); |
| 2594 | if (!contents) |
| 2595 | return; |
| 2596 | const std::string selected_encoding = |
| 2597 | CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding_name); |
| 2598 | if (selected_encoding.empty()) |
| 2599 | return; |
| 2600 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2601 | } |
| 2602 | } |
[email protected] | de246f5 | 2009-02-25 18:25:45 | [diff] [blame] | 2603 | #else |
| 2604 | // TODO(port): Enable when encoding-related parts of Browser are ported. |
| 2605 | NOTIMPLEMENTED(); |
| 2606 | #endif |
[email protected] | 97fa6ce3 | 2008-12-19 01:48:16 | [diff] [blame] | 2607 | } |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 2608 | |
[email protected] | 4d434a1a | 2009-02-11 21:06:57 | [diff] [blame] | 2609 | void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) { |
[email protected] | 5bcdb31 | 2009-01-07 21:43:20 | [diff] [blame] | 2610 | SavePackage::SetShouldPromptUser(should_prompt); |
| 2611 | } |
[email protected] | 87eab22 | 2009-03-13 00:47:45 | [diff] [blame] | 2612 | |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 2613 | void AutomationProvider::GetBlockedPopupCount(int handle, int* count) { |
| 2614 | *count = -1; // -1 is the error code |
| 2615 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2616 | NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
| 2617 | TabContents* tab_contents = nav_controller->tab_contents(); |
| 2618 | if (tab_contents) { |
| 2619 | BlockedPopupContainer* container = |
| 2620 | tab_contents->blocked_popup_container(); |
| 2621 | if (container) { |
| 2622 | *count = static_cast<int>(container->GetBlockedPopupCount()); |
| 2623 | } else { |
| 2624 | // If we don't have a container, we don't have any blocked popups to |
| 2625 | // contain! |
| 2626 | *count = 0; |
| 2627 | } |
| 2628 | } |
| 2629 | } |
| 2630 | } |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2631 | |
| 2632 | void AutomationProvider::SelectAll(int tab_handle) { |
| 2633 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2634 | if (!view) { |
| 2635 | NOTREACHED(); |
| 2636 | return; |
| 2637 | } |
| 2638 | |
| 2639 | view->SelectAll(); |
| 2640 | } |
| 2641 | |
| 2642 | void AutomationProvider::Cut(int tab_handle) { |
| 2643 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2644 | if (!view) { |
| 2645 | NOTREACHED(); |
| 2646 | return; |
| 2647 | } |
| 2648 | |
| 2649 | view->Cut(); |
| 2650 | } |
| 2651 | |
| 2652 | void AutomationProvider::Copy(int tab_handle) { |
| 2653 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2654 | if (!view) { |
| 2655 | NOTREACHED(); |
| 2656 | return; |
| 2657 | } |
| 2658 | |
| 2659 | view->Copy(); |
| 2660 | } |
| 2661 | |
| 2662 | void AutomationProvider::Paste(int tab_handle) { |
| 2663 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2664 | if (!view) { |
| 2665 | NOTREACHED(); |
| 2666 | return; |
| 2667 | } |
| 2668 | |
| 2669 | view->Paste(); |
| 2670 | } |
| 2671 | |
| 2672 | void AutomationProvider::ReloadAsync(int tab_handle) { |
| 2673 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2674 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2675 | if (!tab) { |
| 2676 | NOTREACHED(); |
| 2677 | return; |
| 2678 | } |
| 2679 | |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 2680 | const bool check_for_repost = true; |
| 2681 | tab->Reload(check_for_repost); |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | void AutomationProvider::StopAsync(int tab_handle) { |
| 2686 | RenderViewHost* view = GetViewForTab(tab_handle); |
| 2687 | if (!view) { |
[email protected] | 8b2b331 | 2009-09-14 18:38:36 | [diff] [blame] | 2688 | // We tolerate StopAsync being called even before a view has been created. |
| 2689 | // So just log a warning instead of a NOTREACHED(). |
| 2690 | DLOG(WARNING) << "StopAsync: no view for handle " << tab_handle; |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2691 | return; |
| 2692 | } |
| 2693 | |
| 2694 | view->Stop(); |
| 2695 | } |
| 2696 | |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 2697 | void AutomationProvider::OnSetPageFontSize(int tab_handle, |
| 2698 | int font_size) { |
| 2699 | AutomationPageFontSize automation_font_size = |
| 2700 | static_cast<AutomationPageFontSize>(font_size); |
| 2701 | |
| 2702 | if (automation_font_size < SMALLEST_FONT || |
| 2703 | automation_font_size > LARGEST_FONT) { |
| 2704 | DLOG(ERROR) << "Invalid font size specified : " |
| 2705 | << font_size; |
| 2706 | return; |
| 2707 | } |
| 2708 | |
| 2709 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2710 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2711 | DCHECK(tab != NULL); |
| 2712 | if (tab && tab->tab_contents()) { |
| 2713 | DCHECK(tab->tab_contents()->profile() != NULL); |
| 2714 | tab->tab_contents()->profile()->GetPrefs()->SetInteger( |
| 2715 | prefs::kWebKitDefaultFontSize, font_size); |
| 2716 | } |
| 2717 | } |
| 2718 | } |
| 2719 | |
[email protected] | bc73b4e5 | 2010-03-26 04:16:20 | [diff] [blame] | 2720 | void AutomationProvider::RemoveBrowsingData(int remove_mask) { |
| 2721 | BrowsingDataRemover* remover; |
| 2722 | remover = new BrowsingDataRemover(profile(), |
| 2723 | BrowsingDataRemover::EVERYTHING, // All time periods. |
| 2724 | base::Time()); |
| 2725 | remover->Remove(remove_mask); |
| 2726 | // BrowsingDataRemover deletes itself. |
| 2727 | } |
[email protected] | 1bb5f89 | 2009-10-06 01:44:57 | [diff] [blame] | 2728 | |
[email protected] | 2949e90d | 2009-08-21 15:32:52 | [diff] [blame] | 2729 | void AutomationProvider::WaitForBrowserWindowCountToBecome( |
| 2730 | int target_count, IPC::Message* reply_message) { |
| 2731 | if (static_cast<int>(BrowserList::size()) == target_count) { |
| 2732 | AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams( |
| 2733 | reply_message, true); |
| 2734 | Send(reply_message); |
| 2735 | return; |
| 2736 | } |
| 2737 | |
| 2738 | // Set up an observer (it will delete itself). |
| 2739 | new BrowserCountChangeNotificationObserver(target_count, this, reply_message); |
| 2740 | } |
| 2741 | |
| 2742 | void AutomationProvider::WaitForAppModalDialogToBeShown( |
| 2743 | IPC::Message* reply_message) { |
| 2744 | if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) { |
| 2745 | AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams( |
| 2746 | reply_message, true); |
| 2747 | Send(reply_message); |
| 2748 | return; |
| 2749 | } |
| 2750 | |
| 2751 | // Set up an observer (it will delete itself). |
| 2752 | new AppModalDialogShownObserver(this, reply_message); |
| 2753 | } |
| 2754 | |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 2755 | void AutomationProvider::GoBackBlockUntilNavigationsComplete( |
| 2756 | int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 2757 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2758 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2759 | Browser* browser = FindAndActivateTab(tab); |
| 2760 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2761 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 2762 | false); |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 2763 | browser->GoBack(CURRENT_TAB); |
| 2764 | return; |
| 2765 | } |
| 2766 | } |
| 2767 | |
| 2768 | AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams( |
| 2769 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 2770 | Send(reply_message); |
| 2771 | } |
| 2772 | |
| 2773 | void AutomationProvider::GoForwardBlockUntilNavigationsComplete( |
| 2774 | int handle, int number_of_navigations, IPC::Message* reply_message) { |
| 2775 | if (tab_tracker_->ContainsHandle(handle)) { |
| 2776 | NavigationController* tab = tab_tracker_->GetResource(handle); |
| 2777 | Browser* browser = FindAndActivateTab(tab); |
| 2778 | if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 2779 | AddNavigationStatusListener(tab, reply_message, number_of_navigations, |
| 2780 | false); |
[email protected] | 1126a1d3 | 2009-08-26 15:39:26 | [diff] [blame] | 2781 | browser->GoForward(CURRENT_TAB); |
| 2782 | return; |
| 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams( |
| 2787 | reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
| 2788 | Send(reply_message); |
| 2789 | } |
| 2790 | |
[email protected] | f7a6843 | 2009-07-29 23:18:19 | [diff] [blame] | 2791 | RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) { |
| 2792 | if (tab_tracker_->ContainsHandle(tab_handle)) { |
| 2793 | NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 2794 | if (!tab) { |
| 2795 | NOTREACHED(); |
| 2796 | return NULL; |
| 2797 | } |
| 2798 | |
| 2799 | TabContents* tab_contents = tab->tab_contents(); |
| 2800 | if (!tab_contents) { |
| 2801 | NOTREACHED(); |
| 2802 | return NULL; |
| 2803 | } |
| 2804 | |
| 2805 | RenderViewHost* view_host = tab_contents->render_view_host(); |
| 2806 | return view_host; |
| 2807 | } |
| 2808 | |
| 2809 | return NULL; |
| 2810 | } |
[email protected] | 675595f | 2009-08-26 22:32:04 | [diff] [blame] | 2811 | |
| 2812 | void AutomationProvider::GetBrowserForWindow(int window_handle, |
| 2813 | bool* success, |
| 2814 | int* browser_handle) { |
| 2815 | *success = false; |
| 2816 | *browser_handle = 0; |
| 2817 | |
| 2818 | gfx::NativeWindow window = window_tracker_->GetResource(window_handle); |
| 2819 | if (!window) |
| 2820 | return; |
| 2821 | |
| 2822 | BrowserList::const_iterator iter = BrowserList::begin(); |
| 2823 | for (;iter != BrowserList::end(); ++iter) { |
| 2824 | gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle(); |
| 2825 | if (window == this_window) { |
| 2826 | // Add() returns the existing handle for the resource if any. |
| 2827 | *browser_handle = browser_tracker_->Add(*iter); |
| 2828 | *success = true; |
| 2829 | return; |
| 2830 | } |
| 2831 | } |
| 2832 | } |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2833 | |
| 2834 | void AutomationProvider::InstallExtension(const FilePath& crx_path, |
| 2835 | IPC::Message* reply_message) { |
| 2836 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2837 | if (service) { |
| 2838 | // The observer will delete itself when done. |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 2839 | new ExtensionInstallNotificationObserver(this, |
| 2840 | AutomationMsg_InstallExtension::ID, |
| 2841 | reply_message); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2842 | |
| 2843 | const FilePath& install_dir = service->install_directory(); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2844 | scoped_refptr<CrxInstaller> installer( |
| 2845 | new CrxInstaller(install_dir, |
| 2846 | service, |
| 2847 | NULL)); // silent install, no UI |
| 2848 | installer->set_allow_privilege_increase(true); |
| 2849 | installer->InstallCrx(crx_path); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2850 | } else { |
| 2851 | AutomationMsg_InstallExtension::WriteReplyParams( |
| 2852 | reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); |
| 2853 | Send(reply_message); |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | void AutomationProvider::LoadExpandedExtension( |
| 2858 | const FilePath& extension_dir, |
| 2859 | IPC::Message* reply_message) { |
[email protected] | a437825 | 2010-02-09 08:14:38 | [diff] [blame] | 2860 | if (profile_->GetExtensionsService()) { |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2861 | // The observer will delete itself when done. |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 2862 | new ExtensionInstallNotificationObserver( |
| 2863 | this, |
| 2864 | AutomationMsg_LoadExpandedExtension::ID, |
| 2865 | reply_message); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2866 | |
| 2867 | profile_->GetExtensionsService()->LoadExtension(extension_dir); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2868 | } else { |
| 2869 | AutomationMsg_LoadExpandedExtension::WriteReplyParams( |
| 2870 | reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED); |
| 2871 | Send(reply_message); |
| 2872 | } |
| 2873 | } |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 2874 | |
[email protected] | a1e62d1 | 2010-03-16 02:18:43 | [diff] [blame] | 2875 | void AutomationProvider::GetEnabledExtensions( |
| 2876 | std::vector<FilePath>* result) { |
| 2877 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2878 | DCHECK(service); |
| 2879 | if (service->extensions_enabled()) { |
| 2880 | const ExtensionList* extensions = service->extensions(); |
| 2881 | DCHECK(extensions); |
| 2882 | for (size_t i = 0; i < extensions->size(); ++i) { |
| 2883 | Extension* extension = (*extensions)[i]; |
| 2884 | DCHECK(extension); |
[email protected] | 237f28167 | 2010-03-20 12:37:07 | [diff] [blame] | 2885 | if (extension->location() == Extension::INTERNAL) { |
| 2886 | result->push_back(extension->path()); |
| 2887 | } |
[email protected] | a1e62d1 | 2010-03-16 02:18:43 | [diff] [blame] | 2888 | } |
| 2889 | } |
| 2890 | } |
| 2891 | |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 2892 | void AutomationProvider::WaitForExtensionTestResult( |
| 2893 | IPC::Message* reply_message) { |
| 2894 | DCHECK(reply_message_ == NULL); |
| 2895 | reply_message_ = reply_message; |
| 2896 | // Call MaybeSendResult, because the result might have come in before |
| 2897 | // we were waiting on it. |
| 2898 | extension_test_result_observer_->MaybeSendResult(); |
| 2899 | } |
| 2900 | |
| 2901 | void AutomationProvider::InstallExtensionAndGetHandle( |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 2902 | const FilePath& crx_path, bool with_ui, IPC::Message* reply_message) { |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 2903 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2904 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 2905 | if (service && manager) { |
| 2906 | // The observer will delete itself when done. |
| 2907 | new ExtensionReadyNotificationObserver( |
| 2908 | manager, |
| 2909 | this, |
| 2910 | AutomationMsg_InstallExtensionAndGetHandle::ID, |
| 2911 | reply_message); |
| 2912 | |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 2913 | ExtensionInstallUI* client = |
| 2914 | (with_ui ? new ExtensionInstallUI(profile_) : NULL); |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 2915 | scoped_refptr<CrxInstaller> installer( |
| 2916 | new CrxInstaller(service->install_directory(), |
| 2917 | service, |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 2918 | client)); |
[email protected] | 790788ac | 2010-04-06 17:52:19 | [diff] [blame] | 2919 | installer->set_allow_privilege_increase(true); |
| 2920 | installer->InstallCrx(crx_path); |
| 2921 | } else { |
| 2922 | AutomationMsg_InstallExtensionAndGetHandle::WriteReplyParams( |
| 2923 | reply_message, 0); |
| 2924 | Send(reply_message); |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | void AutomationProvider::UninstallExtension(int extension_handle, |
| 2929 | bool* success) { |
| 2930 | *success = false; |
| 2931 | Extension* extension = GetExtension(extension_handle); |
| 2932 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2933 | if (extension && service) { |
| 2934 | ExtensionUnloadNotificationObserver observer; |
| 2935 | service->UninstallExtension(extension->id(), false); |
| 2936 | // The extension unload notification should have been sent synchronously |
| 2937 | // with the uninstall. Just to be safe, check that it was received. |
| 2938 | *success = observer.did_receive_unload_notification(); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | void AutomationProvider::EnableExtension(int extension_handle, |
| 2943 | IPC::Message* reply_message) { |
| 2944 | Extension* extension = GetDisabledExtension(extension_handle); |
| 2945 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2946 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 2947 | // Only enable if this extension is disabled. |
| 2948 | if (extension && service && manager) { |
| 2949 | // The observer will delete itself when done. |
| 2950 | new ExtensionReadyNotificationObserver( |
| 2951 | manager, |
| 2952 | this, |
| 2953 | AutomationMsg_EnableExtension::ID, |
| 2954 | reply_message); |
| 2955 | service->EnableExtension(extension->id()); |
| 2956 | } else { |
| 2957 | AutomationMsg_EnableExtension::WriteReplyParams(reply_message, false); |
| 2958 | Send(reply_message); |
| 2959 | } |
| 2960 | } |
| 2961 | |
| 2962 | void AutomationProvider::DisableExtension(int extension_handle, |
| 2963 | bool* success) { |
| 2964 | *success = false; |
| 2965 | Extension* extension = GetEnabledExtension(extension_handle); |
| 2966 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2967 | if (extension && service) { |
| 2968 | ExtensionUnloadNotificationObserver observer; |
| 2969 | service->DisableExtension(extension->id()); |
| 2970 | // The extension unload notification should have been sent synchronously |
| 2971 | // with the disable. Just to be safe, check that it was received. |
| 2972 | *success = observer.did_receive_unload_notification(); |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | void AutomationProvider::ExecuteExtensionActionInActiveTabAsync( |
| 2977 | int extension_handle, int browser_handle, |
| 2978 | IPC::Message* reply_message) { |
| 2979 | bool success = false; |
| 2980 | Extension* extension = GetEnabledExtension(extension_handle); |
| 2981 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 2982 | ExtensionMessageService* message_service = |
| 2983 | profile_->GetExtensionMessageService(); |
| 2984 | Browser* browser = browser_tracker_->GetResource(browser_handle); |
| 2985 | if (extension && service && message_service && browser) { |
| 2986 | int tab_id = ExtensionTabUtil::GetTabId(browser->GetSelectedTabContents()); |
| 2987 | if (extension->page_action()) { |
| 2988 | ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( |
| 2989 | browser->profile(), extension->id(), "action", tab_id, "", 1); |
| 2990 | success = true; |
| 2991 | } else if (extension->browser_action()) { |
| 2992 | ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( |
| 2993 | browser->profile(), extension->id(), browser); |
| 2994 | success = true; |
| 2995 | } |
| 2996 | } |
| 2997 | AutomationMsg_ExecuteExtensionActionInActiveTabAsync::WriteReplyParams( |
| 2998 | reply_message, success); |
| 2999 | Send(reply_message); |
| 3000 | } |
| 3001 | |
| 3002 | void AutomationProvider::MoveExtensionBrowserAction( |
| 3003 | int extension_handle, int index, bool* success) { |
| 3004 | *success = false; |
| 3005 | Extension* extension = GetEnabledExtension(extension_handle); |
| 3006 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3007 | if (extension && service) { |
| 3008 | ExtensionToolbarModel* toolbar = service->toolbar_model(); |
| 3009 | if (toolbar) { |
| 3010 | if (index >= 0 && index < static_cast<int>(toolbar->size())) { |
| 3011 | toolbar->MoveBrowserAction(extension, index); |
| 3012 | *success = true; |
| 3013 | } else { |
| 3014 | DLOG(WARNING) << "Attempted to move browser action to invalid index."; |
| 3015 | } |
| 3016 | } |
| 3017 | } |
| 3018 | } |
| 3019 | |
| 3020 | void AutomationProvider::GetExtensionProperty( |
| 3021 | int extension_handle, |
| 3022 | AutomationMsg_ExtensionProperty type, |
| 3023 | bool* success, |
| 3024 | std::string* value) { |
| 3025 | *success = false; |
| 3026 | Extension* extension = GetExtension(extension_handle); |
| 3027 | ExtensionsService* service = profile_->GetExtensionsService(); |
| 3028 | if (extension && service) { |
| 3029 | ExtensionToolbarModel* toolbar = service->toolbar_model(); |
| 3030 | int found_index = -1; |
| 3031 | int index = 0; |
| 3032 | switch (type) { |
| 3033 | case AUTOMATION_MSG_EXTENSION_ID: |
| 3034 | *value = extension->id(); |
| 3035 | *success = true; |
| 3036 | break; |
| 3037 | case AUTOMATION_MSG_EXTENSION_NAME: |
| 3038 | *value = extension->name(); |
| 3039 | *success = true; |
| 3040 | break; |
| 3041 | case AUTOMATION_MSG_EXTENSION_VERSION: |
| 3042 | *value = extension->VersionString(); |
| 3043 | *success = true; |
| 3044 | break; |
| 3045 | case AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX: |
| 3046 | if (toolbar) { |
| 3047 | for (ExtensionList::const_iterator iter = toolbar->begin(); |
| 3048 | iter != toolbar->end(); iter++) { |
| 3049 | // Skip this extension if we are in incognito mode |
| 3050 | // and it is not incognito-enabled. |
| 3051 | if (profile_->IsOffTheRecord() && |
| 3052 | !service->IsIncognitoEnabled(*iter)) |
| 3053 | continue; |
| 3054 | if (*iter == extension) { |
| 3055 | found_index = index; |
| 3056 | break; |
| 3057 | } |
| 3058 | index++; |
| 3059 | } |
| 3060 | *value = IntToString(found_index); |
| 3061 | *success = true; |
| 3062 | } |
| 3063 | break; |
| 3064 | default: |
| 3065 | LOG(WARNING) << "Trying to get undefined extension property"; |
| 3066 | break; |
| 3067 | } |
| 3068 | } |
| 3069 | } |
| 3070 | |
[email protected] | 673fd2c0 | 2010-02-04 23:10:00 | [diff] [blame] | 3071 | void AutomationProvider::SaveAsAsync(int tab_handle) { |
| 3072 | NavigationController* tab = NULL; |
| 3073 | TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab); |
| 3074 | if (tab_contents) |
| 3075 | tab_contents->OnSavePage(); |
| 3076 | } |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3077 | |
| 3078 | void AutomationProvider::SetContentSetting( |
| 3079 | int handle, |
| 3080 | const std::string& host, |
| 3081 | ContentSettingsType content_type, |
| 3082 | ContentSetting setting, |
| 3083 | bool* success) { |
| 3084 | *success = false; |
| 3085 | if (browser_tracker_->ContainsHandle(handle)) { |
| 3086 | Browser* browser = browser_tracker_->GetResource(handle); |
| 3087 | HostContentSettingsMap* map = |
| 3088 | browser->profile()->GetHostContentSettingsMap(); |
| 3089 | if (host.empty()) { |
| 3090 | map->SetDefaultContentSetting(content_type, setting); |
| 3091 | } else { |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 3092 | map->SetContentSetting(HostContentSettingsMap::Pattern(host), |
| 3093 | content_type, setting); |
[email protected] | 7dad3d5f | 2010-03-04 00:27:01 | [diff] [blame] | 3094 | } |
| 3095 | *success = true; |
| 3096 | } |
| 3097 | } |
[email protected] | cc82437 | 2010-03-31 15:33:01 | [diff] [blame] | 3098 | |
| 3099 | #if !defined(TOOLKIT_VIEWS) |
| 3100 | void AutomationProvider::GetFocusedViewID(int handle, int* view_id) { |
| 3101 | NOTIMPLEMENTED(); |
| 3102 | }; |
| 3103 | |
| 3104 | void AutomationProvider::WaitForFocusedViewIDToChange( |
| 3105 | int handle, int previous_view_id, IPC::Message* reply_message) { |
| 3106 | NOTIMPLEMENTED(); |
| 3107 | } |
| 3108 | |
| 3109 | void AutomationProvider::StartTrackingPopupMenus( |
| 3110 | int browser_handle, bool* success) { |
| 3111 | NOTIMPLEMENTED(); |
| 3112 | } |
| 3113 | |
| 3114 | void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
| 3115 | NOTIMPLEMENTED(); |
| 3116 | } |
| 3117 | #endif // !defined(TOOLKIT_VIEWS) |
[email protected] | d7e5525d | 2010-04-20 14:37:09 | [diff] [blame] | 3118 | |
| 3119 | void AutomationProvider::ResetToDefaultTheme() { |
| 3120 | profile_->ClearTheme(); |
| 3121 | } |