blob: addc2fd7fa6f37832bfcbae0de3d606ea26fcb29 [file] [log] [blame]
[email protected]3b5f7022010-03-25 20:37:401// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/automation/automation_provider.h"
6
[email protected]5ae5bed2009-08-21 18:52:447#include <set>
8
[email protected]202e7a72009-06-15 03:48:369#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3110#include "app/message_box_flags.h"
[email protected]2041cf342010-02-19 03:15:5911#include "base/callback.h"
[email protected]c6cb1992009-04-13 16:45:2912#include "base/file_version_info.h"
[email protected]93d49d72009-10-23 20:00:2013#include "base/json/json_reader.h"
[email protected]59a611242010-04-02 02:24:0414#include "base/json/json_writer.h"
[email protected]bc1407f2009-09-29 00:33:3515#include "base/keyboard_codes.h"
[email protected]5fac9622009-02-04 21:49:3816#include "base/message_loop.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/path_service.h"
[email protected]201b2732009-11-13 18:57:4618#include "base/process_util.h"
[email protected]f44265b2009-05-19 18:52:5019#include "base/stl_util-inl.h"
[email protected]4c4d8d22009-03-04 05:29:2720#include "base/string_util.h"
[email protected]5fac9622009-02-04 21:49:3821#include "base/thread.h"
[email protected]6d8ffc9f2010-03-12 18:27:5322#include "base/utf_string_conversions.h"
[email protected]a7eee32f2009-05-22 18:08:1723#include "base/values.h"
[email protected]4f3dc372009-02-24 00:10:2924#include "chrome/app/chrome_dll_resource.h"
[email protected]0bfa713f2009-04-07 20:18:2825#include "chrome/browser/app_modal_dialog.h"
[email protected]464146e2009-04-09 18:17:0926#include "chrome/browser/app_modal_dialog_queue.h"
[email protected]b83e4602009-05-15 22:58:3327#include "chrome/browser/automation/automation_extension_function.h"
[email protected]790788ac2010-04-06 17:52:1928#include "chrome/browser/automation/automation_extension_tracker.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/browser/automation/automation_provider_list.h"
[email protected]e12de87e2009-08-28 00:02:0830#include "chrome/browser/automation/automation_provider_observers.h"
[email protected]a9024892009-06-16 23:13:5531#include "chrome/browser/automation/extension_automation_constants.h"
[email protected]f44265b2009-05-19 18:52:5032#include "chrome/browser/automation/extension_port_container.h"
[email protected]66ba4932009-06-04 19:22:1333#include "chrome/browser/blocked_popup_container.h"
[email protected]6d8ffc9f2010-03-12 18:27:5334#include "chrome/browser/bookmarks/bookmark_model.h"
35#include "chrome/browser/bookmarks/bookmark_storage.h"
[email protected]5c238752009-06-13 10:29:0736#include "chrome/browser/browser_process.h"
[email protected]f3e99e32008-07-30 04:48:3937#include "chrome/browser/browser_window.h"
[email protected]bc73b4e52010-03-26 04:16:2038#include "chrome/browser/browsing_data_remover.h"
[email protected]fae20792009-10-28 20:31:5839#include "chrome/browser/chrome_thread.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/browser/dom_operation_notification_details.h"
[email protected]d9f9b792009-06-24 13:17:1241#include "chrome/browser/debugger/devtools_manager.h"
[email protected]cdaa8652008-09-13 02:48:5942#include "chrome/browser/download/download_manager.h"
[email protected]59560e0b2009-06-04 03:30:2243#include "chrome/browser/download/download_shelf.h"
[email protected]d11c8e92009-10-20 23:26:4044#include "chrome/browser/extensions/crx_installer.h"
[email protected]790788ac2010-04-06 17:52:1945#include "chrome/browser/extensions/extension_browser_event_router.h"
[email protected]d11c8e92009-10-20 23:26:4046#include "chrome/browser/extensions/extension_install_ui.h"
[email protected]a9024892009-06-16 23:13:5547#include "chrome/browser/extensions/extension_message_service.h"
[email protected]790788ac2010-04-06 17:52:1948#include "chrome/browser/extensions/extension_tabs_module.h"
49#include "chrome/browser/extensions/extension_toolbar_model.h"
50#include "chrome/browser/extensions/extensions_service.h"
[email protected]8cb5d5b2010-02-09 11:36:1651#include "chrome/browser/extensions/user_script_master.h"
[email protected]4801ecc2009-04-05 04:52:5852#include "chrome/browser/find_bar.h"
53#include "chrome/browser/find_bar_controller.h"
initial.commit09911bf2008-07-26 23:55:2954#include "chrome/browser/find_notification_details.h"
[email protected]7dad3d5f2010-03-04 00:27:0155#include "chrome/browser/host_content_settings_map.h"
[email protected]0ac83682010-01-22 17:46:2756#include "chrome/browser/io_thread.h"
[email protected]13869dd2009-05-05 00:40:0657#include "chrome/browser/location_bar.h"
[email protected]3fcac682009-08-13 02:28:0158#include "chrome/browser/login_prompt.h"
[email protected]be180c802009-10-23 06:33:3159#include "chrome/browser/net/url_request_context_getter.h"
[email protected]f732c1e2009-07-30 15:48:5360#include "chrome/browser/net/url_request_mock_util.h"
[email protected]052313b2010-02-19 09:43:0861#include "chrome/browser/pref_service.h"
[email protected]a7eee32f2009-05-22 18:08:1762#include "chrome/browser/profile_manager.h"
[email protected]1db6ff152009-10-12 15:32:0763#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]6524b5f92009-01-22 17:48:2564#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]3b073b22009-01-16 03:29:0365#include "chrome/browser/ssl/ssl_manager.h"
66#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]57c6a652009-05-04 07:58:3467#include "chrome/browser/tab_contents/tab_contents.h"
[email protected]81af9392009-04-21 02:37:4568#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]a7eee32f2009-05-22 18:08:1769#include "chrome/common/automation_constants.h"
initial.commit09911bf2008-07-26 23:55:2970#include "chrome/common/chrome_paths.h"
[email protected]790788ac2010-04-06 17:52:1971#include "chrome/common/extensions/extension.h"
[email protected]a7eee32f2009-05-22 18:08:1772#include "chrome/common/json_value_serializer.h"
[email protected]1c58a5c2009-05-21 18:47:1473#include "chrome/common/notification_service.h"
[email protected]3753f522009-04-14 23:15:4774#include "chrome/common/platform_util.h"
[email protected]1bb5f892009-10-06 01:44:5775#include "chrome/common/pref_names.h"
[email protected]f5bf8ccf2010-02-05 18:19:2576#include "chrome/common/url_constants.h"
[email protected]71f65dd2009-02-11 19:14:5677#include "chrome/test/automation/automation_messages.h"
[email protected]1bb5f892009-10-06 01:44:5778#include "chrome/test/automation/tab_proxy.h"
[email protected]a7eee32f2009-05-22 18:08:1779#include "net/proxy/proxy_service.h"
80#include "net/proxy/proxy_config_service_fixed.h"
[email protected]319d9e6f2009-02-18 19:47:2181#include "net/url_request/url_request_context.h"
[email protected]9a08bcf2009-08-12 19:56:2882#include "views/event.h"
initial.commit09911bf2008-07-26 23:55:2983
[email protected]de246f52009-02-25 18:25:4584#if defined(OS_WIN)
85// TODO(port): Port these headers.
[email protected]de246f52009-02-25 18:25:4586#include "chrome/browser/character_encoding.h"
87#include "chrome/browser/download/save_package.h"
88#include "chrome/browser/external_tab_container.h"
[email protected]de246f52009-02-25 18:25:4589#include "chrome/browser/printing/print_job.h"
[email protected]de246f52009-02-25 18:25:4590#endif // defined(OS_WIN)
91
[email protected]5ae5bed2009-08-21 18:52:4492#if !defined(OS_MACOSX)
[email protected]e8382172009-06-19 22:16:2893// TODO(port): Port these to the mac.
[email protected]9a08bcf2009-08-12 19:56:2894#include "chrome/browser/automation/ui_controls.h"
[email protected]5ae5bed2009-08-21 18:52:4495#endif // !defined(OS_MACOSX)
[email protected]13869dd2009-05-05 00:40:0696
[email protected]e1acf6f2008-10-27 20:43:3397using base::Time;
98
[email protected]cbab76d2008-10-13 22:42:4799class AutomationInterstitialPage : public InterstitialPage {
100 public:
[email protected]57c6a652009-05-04 07:58:34101 AutomationInterstitialPage(TabContents* tab,
[email protected]cbab76d2008-10-13 22:42:47102 const GURL& url,
103 const std::string& contents)
104 : InterstitialPage(tab, true, url),
105 contents_(contents) {
106 }
107
108 virtual std::string GetHTMLContents() { return contents_; }
109
110 private:
111 std::string contents_;
[email protected]4f3dc372009-02-24 00:10:29112
[email protected]cbab76d2008-10-13 22:42:47113 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage);
114};
115
[email protected]c2cb8542009-08-20 21:16:51116#if !defined(OS_MACOSX)
117class ClickTask : public Task {
118 public:
[email protected]fc2e0872009-08-21 22:14:41119 explicit ClickTask(int flags) : flags_(flags) {}
[email protected]c2cb8542009-08-20 21:16:51120 virtual ~ClickTask() {}
121
122 virtual void Run() {
123 ui_controls::MouseButton button = ui_controls::LEFT;
124 if ((flags_ & views::Event::EF_LEFT_BUTTON_DOWN) ==
125 views::Event::EF_LEFT_BUTTON_DOWN) {
126 button = ui_controls::LEFT;
127 } else if ((flags_ & views::Event::EF_RIGHT_BUTTON_DOWN) ==
128 views::Event::EF_RIGHT_BUTTON_DOWN) {
129 button = ui_controls::RIGHT;
130 } else if ((flags_ & views::Event::EF_MIDDLE_BUTTON_DOWN) ==
131 views::Event::EF_MIDDLE_BUTTON_DOWN) {
132 button = ui_controls::MIDDLE;
133 } else {
134 NOTREACHED();
135 }
136
[email protected]fc2e0872009-08-21 22:14:41137 ui_controls::SendMouseClick(button);
[email protected]c2cb8542009-08-20 21:16:51138 }
139
140 private:
[email protected]c2cb8542009-08-20 21:16:51141 int flags_;
142
143 DISALLOW_COPY_AND_ASSIGN(ClickTask);
144};
145#endif
146
initial.commit09911bf2008-07-26 23:55:29147AutomationProvider::AutomationProvider(Profile* profile)
[email protected]295039bd2008-08-15 04:32:57148 : redirect_query_(0),
[email protected]71f65dd2009-02-11 19:14:56149 profile_(profile),
[email protected]cc824372010-03-31 15:33:01150 reply_message_(NULL),
151 popup_menu_waiter_(NULL) {
initial.commit09911bf2008-07-26 23:55:29152 browser_tracker_.reset(new AutomationBrowserTracker(this));
[email protected]790788ac2010-04-06 17:52:19153 extension_tracker_.reset(new AutomationExtensionTracker(this));
initial.commit09911bf2008-07-26 23:55:29154 tab_tracker_.reset(new AutomationTabTracker(this));
[email protected]0e9f4ee2009-04-08 01:44:20155 window_tracker_.reset(new AutomationWindowTracker(this));
initial.commit09911bf2008-07-26 23:55:29156 autocomplete_edit_tracker_.reset(
157 new AutomationAutocompleteEditTracker(this));
initial.commit09911bf2008-07-26 23:55:29158 new_tab_ui_load_observer_.reset(new NewTabUILoadObserver(this));
159 dom_operation_observer_.reset(new DomOperationNotificationObserver(this));
[email protected]84abba62009-10-07 17:01:44160 metric_event_duration_observer_.reset(new MetricEventDurationObserver());
[email protected]790788ac2010-04-06 17:52:19161 extension_test_result_observer_.reset(
162 new ExtensionTestResultNotificationObserver(this));
[email protected]528211a2010-01-14 15:25:13163 g_browser_process->AddRefModule();
initial.commit09911bf2008-07-26 23:55:29164}
165
166AutomationProvider::~AutomationProvider() {
[email protected]f44265b2009-05-19 18:52:50167 STLDeleteContainerPairSecondPointers(port_containers_.begin(),
168 port_containers_.end());
169 port_containers_.clear();
170
[email protected]0da050b92008-08-19 19:29:47171 // Make sure that any outstanding NotificationObservers also get destroyed.
172 ObserverList<NotificationObserver>::Iterator it(notification_observer_list_);
[email protected]5a52f162008-08-27 04:15:31173 NotificationObserver* observer;
[email protected]0da050b92008-08-19 19:29:47174 while ((observer = it.GetNext()) != NULL)
175 delete observer;
[email protected]528211a2010-01-14 15:25:13176
177 if (channel_.get()) {
178 channel_->Close();
179 }
180 g_browser_process->ReleaseModule();
initial.commit09911bf2008-07-26 23:55:29181}
182
[email protected]9a3a293b2009-06-04 22:28:16183void AutomationProvider::ConnectToChannel(const std::string& channel_id) {
[email protected]2e4633c2009-07-09 16:58:06184 automation_resource_message_filter_ = new AutomationResourceMessageFilter;
[email protected]295039bd2008-08-15 04:32:57185 channel_.reset(
[email protected]2e4633c2009-07-09 16:58:06186 new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this,
187 automation_resource_message_filter_,
188 g_browser_process->io_thread()->message_loop(),
189 true, g_browser_process->shutdown_event()));
[email protected]79e966832009-04-21 14:23:05190 scoped_ptr<FileVersionInfo> file_version_info(
191 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
[email protected]cf620752009-04-24 17:05:40192 std::string version_string;
193 if (file_version_info != NULL) {
194 version_string = WideToASCII(file_version_info->file_version());
195 }
[email protected]c6cb1992009-04-13 16:45:29196
197 // Send a hello message with our current automation protocol version.
198 channel_->Send(new AutomationMsg_Hello(0, version_string.c_str()));
initial.commit09911bf2008-07-26 23:55:29199}
200
201void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) {
202 if (expected_tabs == 0) {
203 Send(new AutomationMsg_InitialLoadsComplete(0));
204 } else {
205 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this));
206 }
207}
208
209NotificationObserver* AutomationProvider::AddNavigationStatusListener(
[email protected]2e028a082009-08-19 20:32:58210 NavigationController* tab, IPC::Message* reply_message,
[email protected]7dad3d5f2010-03-04 00:27:01211 int number_of_navigations, bool include_current_navigation) {
initial.commit09911bf2008-07-26 23:55:29212 NotificationObserver* observer =
[email protected]2e028a082009-08-19 20:32:58213 new NavigationNotificationObserver(tab, this, reply_message,
[email protected]7dad3d5f2010-03-04 00:27:01214 number_of_navigations,
215 include_current_navigation);
initial.commit09911bf2008-07-26 23:55:29216
[email protected]71f65dd2009-02-11 19:14:56217 notification_observer_list_.AddObserver(observer);
initial.commit09911bf2008-07-26 23:55:29218 return observer;
219}
220
221void AutomationProvider::RemoveNavigationStatusListener(
222 NotificationObserver* obs) {
223 notification_observer_list_.RemoveObserver(obs);
224}
225
226NotificationObserver* AutomationProvider::AddTabStripObserver(
[email protected]1c58a5c2009-05-21 18:47:14227 Browser* parent,
228 IPC::Message* reply_message) {
[email protected]71f65dd2009-02-11 19:14:56229 NotificationObserver* observer =
[email protected]1c58a5c2009-05-21 18:47:14230 new TabAppendedNotificationObserver(parent, this, reply_message);
initial.commit09911bf2008-07-26 23:55:29231 notification_observer_list_.AddObserver(observer);
232
233 return observer;
234}
235
236void AutomationProvider::RemoveTabStripObserver(NotificationObserver* obs) {
237 notification_observer_list_.RemoveObserver(obs);
238}
239
240void AutomationProvider::AddLoginHandler(NavigationController* tab,
241 LoginHandler* handler) {
242 login_handler_map_[tab] = handler;
243}
244
245void AutomationProvider::RemoveLoginHandler(NavigationController* tab) {
246 DCHECK(login_handler_map_[tab]);
247 login_handler_map_.erase(tab);
248}
249
[email protected]f44265b2009-05-19 18:52:50250void AutomationProvider::AddPortContainer(ExtensionPortContainer* port) {
251 int port_id = port->port_id();
252 DCHECK_NE(-1, port_id);
253 DCHECK(port_containers_.find(port_id) == port_containers_.end());
254
255 port_containers_[port_id] = port;
256}
257
258void AutomationProvider::RemovePortContainer(ExtensionPortContainer* port) {
259 int port_id = port->port_id();
260 DCHECK_NE(-1, port_id);
261
262 PortContainerMap::iterator it = port_containers_.find(port_id);
263 DCHECK(it != port_containers_.end());
264
265 if (it != port_containers_.end()) {
266 delete it->second;
267 port_containers_.erase(it);
268 }
269}
270
271ExtensionPortContainer* AutomationProvider::GetPortContainer(
272 int port_id) const {
273 PortContainerMap::const_iterator it = port_containers_.find(port_id);
274 if (it == port_containers_.end())
275 return NULL;
276
277 return it->second;
278}
279
initial.commit09911bf2008-07-26 23:55:29280int AutomationProvider::GetIndexForNavigationController(
281 const NavigationController* controller, const Browser* parent) const {
282 DCHECK(parent);
[email protected]902cdf772009-05-06 15:08:12283 return parent->GetIndexOfController(controller);
initial.commit09911bf2008-07-26 23:55:29284}
285
[email protected]790788ac2010-04-06 17:52:19286int AutomationProvider::AddExtension(Extension* extension) {
287 DCHECK(extension);
288 return extension_tracker_->Add(extension);
289}
290
291Extension* AutomationProvider::GetExtension(int extension_handle) {
292 return extension_tracker_->GetResource(extension_handle);
293}
294
295Extension* AutomationProvider::GetEnabledExtension(int extension_handle) {
296 Extension* extension = extension_tracker_->GetResource(extension_handle);
297 ExtensionsService* service = profile_->GetExtensionsService();
298 if (extension && service &&
299 service->GetExtensionById(extension->id(), false))
300 return extension;
301 return NULL;
302}
303
304Extension* AutomationProvider::GetDisabledExtension(int extension_handle) {
305 Extension* extension = extension_tracker_->GetResource(extension_handle);
306 ExtensionsService* service = profile_->GetExtensionsService();
307 if (extension && service &&
308 service->GetExtensionById(extension->id(), true) &&
309 !service->GetExtensionById(extension->id(), false))
310 return extension;
311 return NULL;
312}
313
initial.commit09911bf2008-07-26 23:55:29314void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
315 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message)
[email protected]1c58a5c2009-05-21 18:47:14316 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser)
[email protected]71f65dd2009-02-11 19:14:56317 IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync,
318 CloseBrowserAsync)
319 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab)
320 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex)
321 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab)
322 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab)
323 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
324 IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
[email protected]1c58a5c2009-05-21 18:47:14325 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL)
[email protected]2e028a082009-08-19 20:32:58326 IPC_MESSAGE_HANDLER_DELAY_REPLY(
327 AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
328 NavigateToURLBlockUntilNavigationsComplete)
[email protected]71f65dd2009-02-11 19:14:56329 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
330 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack)
331 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward)
332 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload)
333 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth)
[email protected]1c58a5c2009-05-21 18:47:14334 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth)
[email protected]71f65dd2009-02-11 19:14:56335 IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth)
336 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom,
337 GetRedirectsFrom)
[email protected]1c58a5c2009-05-21 18:47:14338 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount)
[email protected]24497032009-05-01 17:00:29339 IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount,
340 GetNormalBrowserWindowCount)
[email protected]71f65dd2009-02-11 19:14:56341 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow)
[email protected]202e7a72009-06-15 03:48:36342 IPC_MESSAGE_HANDLER(AutomationMsg_GetBrowserLocale, GetBrowserLocale)
[email protected]71f65dd2009-02-11 19:14:56343 IPC_MESSAGE_HANDLER(AutomationMsg_LastActiveBrowserWindow,
initial.commit09911bf2008-07-26 23:55:29344 GetLastActiveBrowserWindow)
[email protected]71f65dd2009-02-11 19:14:56345 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveWindow, GetActiveWindow)
[email protected]24497032009-05-01 17:00:29346 IPC_MESSAGE_HANDLER(AutomationMsg_FindNormalBrowserWindow,
347 FindNormalBrowserWindow)
[email protected]71f65dd2009-02-11 19:14:56348 IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActive, IsWindowActive)
[email protected]1c58a5c2009-05-21 18:47:14349 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow)
[email protected]8dd404bb2009-09-22 19:57:24350 IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowMaximized, IsWindowMaximized)
[email protected]49a14a82009-03-31 04:16:44351 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync,
[email protected]4f6381ee2009-04-16 02:46:33352 ExecuteBrowserCommandAsync)
[email protected]49a14a82009-03-31 04:16:44353 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand,
[email protected]4f6381ee2009-04-16 02:46:33354 ExecuteBrowserCommand)
[email protected]8dd404bb2009-09-22 19:57:24355 IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession)
[email protected]1c58a5c2009-05-21 18:47:14356 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds)
[email protected]8dd404bb2009-09-22 19:57:24357 IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds)
[email protected]8f04ff92009-07-08 02:37:15358 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds)
[email protected]1c58a5c2009-05-21 18:47:14359 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible)
[email protected]5ae5bed2009-08-21 18:52:44360#if !defined(OS_MACOSX)
[email protected]d1a5941e2009-08-13 23:34:24361 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick)
[email protected]60507b12009-11-02 23:51:35362 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove)
[email protected]1c58a5c2009-05-21 18:47:14363 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress)
[email protected]71f65dd2009-02-11 19:14:56364 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag,
365 WindowSimulateDrag)
[email protected]b2aa3ed72010-02-01 18:37:14366#endif
[email protected]71f65dd2009-02-11 19:14:56367 IPC_MESSAGE_HANDLER(AutomationMsg_TabCount, GetTabCount)
[email protected]982921f12009-10-27 21:43:53368 IPC_MESSAGE_HANDLER(AutomationMsg_Type, GetType)
[email protected]71f65dd2009-02-11 19:14:56369 IPC_MESSAGE_HANDLER(AutomationMsg_Tab, GetTab)
[email protected]d7fa7552009-03-20 21:06:37370#if defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:56371 IPC_MESSAGE_HANDLER(AutomationMsg_TabHWND, GetTabHWND)
[email protected]de246f52009-02-25 18:25:45372#endif // defined(OS_WIN)
[email protected]71f65dd2009-02-11 19:14:56373 IPC_MESSAGE_HANDLER(AutomationMsg_TabProcessID, GetTabProcessID)
374 IPC_MESSAGE_HANDLER(AutomationMsg_TabTitle, GetTabTitle)
[email protected]77bc6732009-04-20 22:01:03375 IPC_MESSAGE_HANDLER(AutomationMsg_TabIndex, GetTabIndex)
[email protected]71f65dd2009-02-11 19:14:56376 IPC_MESSAGE_HANDLER(AutomationMsg_TabURL, GetTabURL)
[email protected]1c58a5c2009-05-21 18:47:14377 IPC_MESSAGE_HANDLER(AutomationMsg_ShelfVisibility, GetShelfVisibility)
[email protected]34930432009-11-09 00:12:09378 IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreen, IsFullscreen)
379 IPC_MESSAGE_HANDLER(AutomationMsg_IsFullscreenBubbleVisible,
380 GetFullscreenBubbleVisibility)
initial.commit09911bf2008-07-26 23:55:29381 IPC_MESSAGE_HANDLER(AutomationMsg_HandleUnused, HandleUnused)
[email protected]1c58a5c2009-05-21 18:47:14382 IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator)
[email protected]71f65dd2009-02-11 19:14:56383 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation,
384 ExecuteJavascript)
385 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount,
initial.commit09911bf2008-07-26 23:55:29386 GetConstrainedWindowCount)
[email protected]1c58a5c2009-05-21 18:47:14387 IPC_MESSAGE_HANDLER(AutomationMsg_FindInPage, HandleFindInPageRequest)
388 IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID)
[email protected]71f65dd2009-02-11 19:14:56389 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement,
390 HandleInspectElementRequest)
[email protected]1c58a5c2009-05-21 18:47:14391 IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory)
[email protected]a7eee32f2009-05-22 18:08:17392 IPC_MESSAGE_HANDLER(AutomationMsg_SetProxyConfig, SetProxyConfig);
[email protected]14c0a032009-04-13 18:15:14393 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow,
[email protected]1c58a5c2009-05-21 18:47:14394 OpenNewBrowserWindow)
[email protected]982921f12009-10-27 21:43:53395 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType,
396 OpenNewBrowserWindowOfType)
[email protected]1c58a5c2009-05-21 18:47:14397 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser)
[email protected]71f65dd2009-02-11 19:14:56398 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditForBrowser,
[email protected]1c58a5c2009-05-21 18:47:14399 GetAutocompleteEditForBrowser)
400 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow)
[email protected]de246f52009-02-25 18:25:45401#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29402 IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab)
[email protected]d2cc6ed2009-04-24 00:26:17403#endif
[email protected]71f65dd2009-02-11 19:14:56404 IPC_MESSAGE_HANDLER(AutomationMsg_NavigateInExternalTab,
initial.commit09911bf2008-07-26 23:55:29405 NavigateInExternalTab)
[email protected]4150ef02009-08-19 23:14:26406 IPC_MESSAGE_HANDLER(AutomationMsg_NavigateExternalTabAtIndex,
407 NavigateExternalTabAtIndex)
[email protected]71f65dd2009-02-11 19:14:56408 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage,
[email protected]1c58a5c2009-05-21 18:47:14409 ShowInterstitialPage)
[email protected]71f65dd2009-02-11 19:14:56410 IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage,
[email protected]1c58a5c2009-05-21 18:47:14411 HideInterstitialPage)
[email protected]d2cc6ed2009-04-24 00:26:17412#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:29413 IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator,
414 ProcessUnhandledAccelerator)
[email protected]d2cc6ed2009-04-24 00:26:17415#endif
[email protected]71f65dd2009-02-11 19:14:56416 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored,
417 WaitForTabToBeRestored)
[email protected]1c58a5c2009-05-21 18:47:14418 IPC_MESSAGE_HANDLER(AutomationMsg_SetInitialFocus, SetInitialFocus)
[email protected]d2cc6ed2009-04-24 00:26:17419#if defined(OS_WIN)
[email protected]5a9708432009-09-23 22:15:04420 IPC_MESSAGE_HANDLER(AutomationMsg_TabReposition, OnTabReposition)
[email protected]e943d6662009-06-12 03:50:39421 IPC_MESSAGE_HANDLER(AutomationMsg_ForwardContextMenuCommandToChrome,
422 OnForwardContextMenuCommandToChrome)
[email protected]d2cc6ed2009-04-24 00:26:17423#endif
[email protected]1c58a5c2009-05-21 18:47:14424 IPC_MESSAGE_HANDLER(AutomationMsg_GetSecurityState, GetSecurityState)
425 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageType, GetPageType)
[email protected]84abba62009-10-07 17:01:44426 IPC_MESSAGE_HANDLER(AutomationMsg_GetMetricEventDuration,
427 GetMetricEventDuration)
[email protected]71f65dd2009-02-11 19:14:56428 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ActionOnSSLBlockingPage,
429 ActionOnSSLBlockingPage)
initial.commit09911bf2008-07-26 23:55:29430 IPC_MESSAGE_HANDLER(AutomationMsg_BringBrowserToFront, BringBrowserToFront)
431 IPC_MESSAGE_HANDLER(AutomationMsg_IsPageMenuCommandEnabled,
432 IsPageMenuCommandEnabled)
[email protected]71f65dd2009-02-11 19:14:56433 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_PrintNow, PrintNow)
[email protected]d301c952009-07-13 15:02:41434 IPC_MESSAGE_HANDLER(AutomationMsg_PrintAsync, PrintAsync)
[email protected]71f65dd2009-02-11 19:14:56435 IPC_MESSAGE_HANDLER(AutomationMsg_SavePage, SavePage)
436 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText,
initial.commit09911bf2008-07-26 23:55:29437 GetAutocompleteEditText)
[email protected]71f65dd2009-02-11 19:14:56438 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText,
initial.commit09911bf2008-07-26 23:55:29439 SetAutocompleteEditText)
[email protected]71f65dd2009-02-11 19:14:56440 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress,
initial.commit09911bf2008-07-26 23:55:29441 AutocompleteEditIsQueryInProgress)
[email protected]71f65dd2009-02-11 19:14:56442 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches,
initial.commit09911bf2008-07-26 23:55:29443 AutocompleteEditGetMatches)
[email protected]71f65dd2009-02-11 19:14:56444 IPC_MESSAGE_HANDLER(AutomationMsg_OpenFindInPage,
[email protected]5f8af2a2008-08-06 22:49:45445 HandleOpenFindInPageRequest)
[email protected]18cb2572008-08-21 20:34:45446 IPC_MESSAGE_HANDLER(AutomationMsg_HandleMessageFromExternalHost,
447 OnMessageFromExternalHost)
[email protected]1c58a5c2009-05-21 18:47:14448 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Find, HandleFindRequest)
[email protected]71f65dd2009-02-11 19:14:56449 IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowVisibility,
[email protected]20e93d12008-08-28 16:31:57450 GetFindWindowVisibility)
[email protected]71f65dd2009-02-11 19:14:56451 IPC_MESSAGE_HANDLER(AutomationMsg_FindWindowLocation,
[email protected]20e93d12008-08-28 16:31:57452 HandleFindWindowLocationRequest)
[email protected]71f65dd2009-02-11 19:14:56453 IPC_MESSAGE_HANDLER(AutomationMsg_BookmarkBarVisibility,
454 GetBookmarkBarVisibility)
[email protected]6d8ffc9f2010-03-12 18:27:53455 IPC_MESSAGE_HANDLER(AutomationMsg_GetBookmarksAsJSON,
456 GetBookmarksAsJSON)
457 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForBookmarkModelToLoad,
458 WaitForBookmarkModelToLoad)
459 IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkGroup,
460 AddBookmarkGroup)
461 IPC_MESSAGE_HANDLER(AutomationMsg_AddBookmarkURL,
462 AddBookmarkURL)
463 IPC_MESSAGE_HANDLER(AutomationMsg_ReparentBookmark,
464 ReparentBookmark)
465 IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkTitle,
466 SetBookmarkTitle)
467 IPC_MESSAGE_HANDLER(AutomationMsg_SetBookmarkURL,
468 SetBookmarkURL)
469 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBookmark,
470 RemoveBookmark)
[email protected]59a611242010-04-02 02:24:04471 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SendJSONRequest,
472 SendJSONRequest)
[email protected]816633a2009-11-11 21:48:18473 IPC_MESSAGE_HANDLER(AutomationMsg_GetInfoBarCount, GetInfoBarCount)
474 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ClickInfoBarAccept,
475 ClickInfoBarAccept)
[email protected]71f65dd2009-02-11 19:14:56476 IPC_MESSAGE_HANDLER(AutomationMsg_GetLastNavigationTime,
[email protected]8a3422c92008-09-24 17:42:42477 GetLastNavigationTime)
[email protected]71f65dd2009-02-11 19:14:56478 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForNavigation,
479 WaitForNavigation)
[email protected]1c58a5c2009-05-21 18:47:14480 IPC_MESSAGE_HANDLER(AutomationMsg_SetIntPreference, SetIntPreference)
[email protected]71f65dd2009-02-11 19:14:56481 IPC_MESSAGE_HANDLER(AutomationMsg_ShowingAppModalDialog,
[email protected]c274acc2008-11-11 20:13:44482 GetShowingAppModalDialog)
[email protected]71f65dd2009-02-11 19:14:56483 IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButton,
[email protected]fad84eab2008-12-05 00:37:20484 ClickAppModalDialogButton)
[email protected]1c58a5c2009-05-21 18:47:14485 IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreference, SetStringPreference)
[email protected]71f65dd2009-02-11 19:14:56486 IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreference,
[email protected]97fa6ce32008-12-19 01:48:16487 GetBooleanPreference)
[email protected]71f65dd2009-02-11 19:14:56488 IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreference,
[email protected]97fa6ce32008-12-19 01:48:16489 SetBooleanPreference)
[email protected]71f65dd2009-02-11 19:14:56490 IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding,
[email protected]97fa6ce32008-12-19 01:48:16491 GetPageCurrentEncoding)
[email protected]1c58a5c2009-05-21 18:47:14492 IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding)
[email protected]5bcdb312009-01-07 21:43:20493 IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser,
494 SavePackageShouldPromptUser)
[email protected]1c58a5c2009-05-21 18:47:14495 IPC_MESSAGE_HANDLER(AutomationMsg_WindowTitle, GetWindowTitle)
[email protected]4cfc1d922009-11-08 14:02:58496#if defined(OS_WIN)
497 // Depends on ExternalTabContainer, so Windows-only
[email protected]b83e4602009-05-15 22:58:33498 IPC_MESSAGE_HANDLER(AutomationMsg_SetEnableExtensionAutomation,
499 SetEnableExtensionAutomation)
[email protected]4cfc1d922009-11-08 14:02:58500#endif
[email protected]59560e0b2009-06-04 03:30:22501 IPC_MESSAGE_HANDLER(AutomationMsg_SetShelfVisibility, SetShelfVisibility)
[email protected]66ba4932009-06-04 19:22:13502 IPC_MESSAGE_HANDLER(AutomationMsg_BlockedPopupCount, GetBlockedPopupCount)
[email protected]f7a68432009-07-29 23:18:19503 IPC_MESSAGE_HANDLER(AutomationMsg_SelectAll, SelectAll)
504 IPC_MESSAGE_HANDLER(AutomationMsg_Cut, Cut)
505 IPC_MESSAGE_HANDLER(AutomationMsg_Copy, Copy)
506 IPC_MESSAGE_HANDLER(AutomationMsg_Paste, Paste)
507 IPC_MESSAGE_HANDLER(AutomationMsg_ReloadAsync, ReloadAsync)
508 IPC_MESSAGE_HANDLER(AutomationMsg_StopAsync, StopAsync)
[email protected]2949e90d2009-08-21 15:32:52509 IPC_MESSAGE_HANDLER_DELAY_REPLY(
510 AutomationMsg_WaitForBrowserWindowCountToBecome,
511 WaitForBrowserWindowCountToBecome)
512 IPC_MESSAGE_HANDLER_DELAY_REPLY(
513 AutomationMsg_WaitForAppModalDialogToBeShown,
514 WaitForAppModalDialogToBeShown)
[email protected]1126a1d32009-08-26 15:39:26515 IPC_MESSAGE_HANDLER_DELAY_REPLY(
516 AutomationMsg_GoBackBlockUntilNavigationsComplete,
517 GoBackBlockUntilNavigationsComplete)
518 IPC_MESSAGE_HANDLER_DELAY_REPLY(
519 AutomationMsg_GoForwardBlockUntilNavigationsComplete,
520 GoForwardBlockUntilNavigationsComplete)
[email protected]632fbb12009-09-06 15:27:14521#if defined(OS_WIN)
522 IPC_MESSAGE_HANDLER(AutomationMsg_ConnectExternalTab, ConnectExternalTab)
523#endif
[email protected]1bb5f892009-10-06 01:44:57524 IPC_MESSAGE_HANDLER(AutomationMsg_SetPageFontSize, OnSetPageFontSize)
[email protected]d11c8e92009-10-20 23:26:40525 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InstallExtension,
526 InstallExtension)
527 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoadExpandedExtension,
528 LoadExpandedExtension)
[email protected]a1e62d12010-03-16 02:18:43529 IPC_MESSAGE_HANDLER(AutomationMsg_GetEnabledExtensions,
530 GetEnabledExtensions)
[email protected]790788ac2010-04-06 17:52:19531 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForExtensionTestResult,
532 WaitForExtensionTestResult)
533 IPC_MESSAGE_HANDLER_DELAY_REPLY(
534 AutomationMsg_InstallExtensionAndGetHandle,
535 InstallExtensionAndGetHandle)
536 IPC_MESSAGE_HANDLER(AutomationMsg_UninstallExtension,
537 UninstallExtension)
538 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EnableExtension,
539 EnableExtension)
540 IPC_MESSAGE_HANDLER(AutomationMsg_DisableExtension,
541 DisableExtension)
542 IPC_MESSAGE_HANDLER_DELAY_REPLY(
543 AutomationMsg_ExecuteExtensionActionInActiveTabAsync,
544 ExecuteExtensionActionInActiveTabAsync)
545 IPC_MESSAGE_HANDLER(AutomationMsg_MoveExtensionBrowserAction,
546 MoveExtensionBrowserAction)
547 IPC_MESSAGE_HANDLER(AutomationMsg_GetExtensionProperty,
548 GetExtensionProperty)
[email protected]fedaa7d2010-01-26 20:34:57549 IPC_MESSAGE_HANDLER(AutomationMsg_ShutdownSessionService,
550 ShutdownSessionService)
[email protected]673fd2c02010-02-04 23:10:00551 IPC_MESSAGE_HANDLER(AutomationMsg_SaveAsAsync, SaveAsAsync)
[email protected]2b19e2fe2010-02-16 02:24:18552#if defined(OS_WIN)
553 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserMove, OnBrowserMoved)
554#endif
[email protected]7dad3d5f2010-03-04 00:27:01555 IPC_MESSAGE_HANDLER(AutomationMsg_SetContentSetting, SetContentSetting)
[email protected]566a0f762010-03-10 04:14:57556#if defined(OS_CHROMEOS)
557 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoginWithUserAndPass,
558 LoginWithUserAndPass)
559#endif
[email protected]bc73b4e52010-03-26 04:16:20560 IPC_MESSAGE_HANDLER(AutomationMsg_RemoveBrowsingData, RemoveBrowsingData)
[email protected]cc824372010-03-31 15:33:01561#if defined(TOOLKIT_VIEWS)
562 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForFocusedViewIDToChange,
563 WaitForFocusedViewIDToChange)
564 IPC_MESSAGE_HANDLER(AutomationMsg_StartTrackingPopupMenus,
565 StartTrackingPopupMenus)
566 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForPopupMenuToOpen,
567 WaitForPopupMenuToOpen)
568#endif
initial.commit09911bf2008-07-26 23:55:29569 IPC_END_MESSAGE_MAP()
570}
571
[email protected]71f65dd2009-02-11 19:14:56572void AutomationProvider::ActivateTab(int handle, int at_index, int* status) {
573 *status = -1;
initial.commit09911bf2008-07-26 23:55:29574 if (browser_tracker_->ContainsHandle(handle) && at_index > -1) {
575 Browser* browser = browser_tracker_->GetResource(handle);
576 if (at_index >= 0 && at_index < browser->tab_count()) {
577 browser->SelectTabContentsAt(at_index, true);
[email protected]71f65dd2009-02-11 19:14:56578 *status = 0;
initial.commit09911bf2008-07-26 23:55:29579 }
580 }
initial.commit09911bf2008-07-26 23:55:29581}
582
[email protected]71f65dd2009-02-11 19:14:56583void AutomationProvider::AppendTab(int handle, const GURL& url,
584 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29585 int append_tab_response = -1; // -1 is the error code
586 NotificationObserver* observer = NULL;
587
588 if (browser_tracker_->ContainsHandle(handle)) {
589 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]1c58a5c2009-05-21 18:47:14590 observer = AddTabStripObserver(browser, reply_message);
[email protected]22735af62009-04-07 21:09:58591 TabContents* tab_contents = browser->AddTabWithURL(url, GURL(),
592 PageTransition::TYPED,
[email protected]5a4940be2009-05-06 06:44:39593 true, -1, false, NULL);
initial.commit09911bf2008-07-26 23:55:29594 if (tab_contents) {
595 append_tab_response =
[email protected]ce3fa3c2009-04-20 19:55:57596 GetIndexForNavigationController(&tab_contents->controller(), browser);
initial.commit09911bf2008-07-26 23:55:29597 }
598 }
599
600 if (append_tab_response < 0) {
601 // The append tab failed. Remove the TabStripObserver
602 if (observer) {
603 RemoveTabStripObserver(observer);
604 delete observer;
605 }
606
[email protected]71f65dd2009-02-11 19:14:56607 AutomationMsg_AppendTab::WriteReplyParams(reply_message,
608 append_tab_response);
609 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29610 }
611}
612
[email protected]71f65dd2009-02-11 19:14:56613void AutomationProvider::NavigateToURL(int handle, const GURL& url,
614 IPC::Message* reply_message) {
[email protected]2e028a082009-08-19 20:32:58615 NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message);
616}
617
618void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
619 int handle, const GURL& url, int number_of_navigations,
620 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29621 if (tab_tracker_->ContainsHandle(handle)) {
622 NavigationController* tab = tab_tracker_->GetResource(handle);
623
624 // Simulate what a user would do. Activate the tab and then navigate.
625 // We could allow navigating in a background tab in future.
626 Browser* browser = FindAndActivateTab(tab);
627
628 if (browser) {
[email protected]7dad3d5f2010-03-04 00:27:01629 AddNavigationStatusListener(tab, reply_message, number_of_navigations,
630 false);
[email protected]71f65dd2009-02-11 19:14:56631
initial.commit09911bf2008-07-26 23:55:29632 // TODO(darin): avoid conversion to GURL
[email protected]c0588052008-10-27 23:01:50633 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
initial.commit09911bf2008-07-26 23:55:29634 return;
635 }
636 }
[email protected]71f65dd2009-02-11 19:14:56637
638 AutomationMsg_NavigateToURL::WriteReplyParams(
639 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
640 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29641}
[email protected]2949e90d2009-08-21 15:32:52642
[email protected]71f65dd2009-02-11 19:14:56643void AutomationProvider::NavigationAsync(int handle, const GURL& url,
644 bool* status) {
645 *status = false;
initial.commit09911bf2008-07-26 23:55:29646
647 if (tab_tracker_->ContainsHandle(handle)) {
648 NavigationController* tab = tab_tracker_->GetResource(handle);
649
650 // Simulate what a user would do. Activate the tab and then navigate.
651 // We could allow navigating in a background tab in future.
652 Browser* browser = FindAndActivateTab(tab);
653
654 if (browser) {
655 // Don't add any listener unless a callback mechanism is desired.
656 // TODO(vibhor): Do this if such a requirement arises in future.
[email protected]c0588052008-10-27 23:01:50657 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
[email protected]71f65dd2009-02-11 19:14:56658 *status = true;
initial.commit09911bf2008-07-26 23:55:29659 }
660 }
initial.commit09911bf2008-07-26 23:55:29661}
662
[email protected]71f65dd2009-02-11 19:14:56663void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29664 if (tab_tracker_->ContainsHandle(handle)) {
665 NavigationController* tab = tab_tracker_->GetResource(handle);
666 Browser* browser = FindAndActivateTab(tab);
[email protected]1fc025202009-01-20 23:03:14667 if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) {
[email protected]7dad3d5f2010-03-04 00:27:01668 AddNavigationStatusListener(tab, reply_message, 1, false);
[email protected]485fba42009-03-24 23:27:29669 browser->GoBack(CURRENT_TAB);
initial.commit09911bf2008-07-26 23:55:29670 return;
671 }
672 }
[email protected]71f65dd2009-02-11 19:14:56673
674 AutomationMsg_GoBack::WriteReplyParams(
675 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
676 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29677}
678
[email protected]71f65dd2009-02-11 19:14:56679void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29680 if (tab_tracker_->ContainsHandle(handle)) {
681 NavigationController* tab = tab_tracker_->GetResource(handle);
682 Browser* browser = FindAndActivateTab(tab);
[email protected]1fc025202009-01-20 23:03:14683 if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) {
[email protected]7dad3d5f2010-03-04 00:27:01684 AddNavigationStatusListener(tab, reply_message, 1, false);
[email protected]485fba42009-03-24 23:27:29685 browser->GoForward(CURRENT_TAB);
initial.commit09911bf2008-07-26 23:55:29686 return;
687 }
688 }
[email protected]71f65dd2009-02-11 19:14:56689
690 AutomationMsg_GoForward::WriteReplyParams(
691 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
692 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29693}
694
[email protected]71f65dd2009-02-11 19:14:56695void AutomationProvider::Reload(int handle, IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29696 if (tab_tracker_->ContainsHandle(handle)) {
697 NavigationController* tab = tab_tracker_->GetResource(handle);
698 Browser* browser = FindAndActivateTab(tab);
[email protected]1fc025202009-01-20 23:03:14699 if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) {
[email protected]7dad3d5f2010-03-04 00:27:01700 AddNavigationStatusListener(tab, reply_message, 1, false);
initial.commit09911bf2008-07-26 23:55:29701 browser->Reload();
702 return;
703 }
704 }
[email protected]71f65dd2009-02-11 19:14:56705
706 AutomationMsg_Reload::WriteReplyParams(
707 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
708 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29709}
710
[email protected]71f65dd2009-02-11 19:14:56711void AutomationProvider::SetAuth(int tab_handle,
initial.commit09911bf2008-07-26 23:55:29712 const std::wstring& username,
[email protected]71f65dd2009-02-11 19:14:56713 const std::wstring& password,
714 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29715 if (tab_tracker_->ContainsHandle(tab_handle)) {
716 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
717 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
718
719 if (iter != login_handler_map_.end()) {
720 // If auth is needed again after this, assume login has failed. This is
721 // not strictly correct, because a navigation can require both proxy and
722 // server auth, but it should be OK for now.
723 LoginHandler* handler = iter->second;
[email protected]7dad3d5f2010-03-04 00:27:01724 AddNavigationStatusListener(tab, reply_message, 1, false);
initial.commit09911bf2008-07-26 23:55:29725 handler->SetAuth(username, password);
[email protected]457f5cf2009-08-18 16:37:52726 return;
initial.commit09911bf2008-07-26 23:55:29727 }
728 }
[email protected]de246f52009-02-25 18:25:45729
[email protected]457f5cf2009-08-18 16:37:52730 AutomationMsg_SetAuth::WriteReplyParams(
731 reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED);
732 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29733}
734
[email protected]71f65dd2009-02-11 19:14:56735void AutomationProvider::CancelAuth(int tab_handle,
736 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29737 if (tab_tracker_->ContainsHandle(tab_handle)) {
738 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
739 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
740
741 if (iter != login_handler_map_.end()) {
742 // If auth is needed again after this, something is screwy.
743 LoginHandler* handler = iter->second;
[email protected]7dad3d5f2010-03-04 00:27:01744 AddNavigationStatusListener(tab, reply_message, 1, false);
initial.commit09911bf2008-07-26 23:55:29745 handler->CancelAuth();
[email protected]457f5cf2009-08-18 16:37:52746 return;
initial.commit09911bf2008-07-26 23:55:29747 }
748 }
[email protected]de246f52009-02-25 18:25:45749
[email protected]457f5cf2009-08-18 16:37:52750 AutomationMsg_CancelAuth::WriteReplyParams(
751 reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED);
752 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29753}
754
[email protected]71f65dd2009-02-11 19:14:56755void AutomationProvider::NeedsAuth(int tab_handle, bool* needs_auth) {
756 *needs_auth = false;
initial.commit09911bf2008-07-26 23:55:29757
758 if (tab_tracker_->ContainsHandle(tab_handle)) {
759 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
760 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
761
762 if (iter != login_handler_map_.end()) {
763 // The LoginHandler will be in our map IFF the tab needs auth.
[email protected]71f65dd2009-02-11 19:14:56764 *needs_auth = true;
initial.commit09911bf2008-07-26 23:55:29765 }
766 }
initial.commit09911bf2008-07-26 23:55:29767}
768
[email protected]71f65dd2009-02-11 19:14:56769void AutomationProvider::GetRedirectsFrom(int tab_handle,
770 const GURL& source_url,
771 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:29772 DCHECK(!redirect_query_) << "Can only handle one redirect query at once.";
773 if (tab_tracker_->ContainsHandle(tab_handle)) {
774 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
775 HistoryService* history_service =
776 tab->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
777
778 DCHECK(history_service) << "Tab " << tab_handle << "'s profile " <<
779 "has no history service";
780 if (history_service) {
[email protected]71f65dd2009-02-11 19:14:56781 DCHECK(reply_message_ == NULL);
782 reply_message_ = reply_message;
initial.commit09911bf2008-07-26 23:55:29783 // Schedule a history query for redirects. The response will be sent
784 // asynchronously from the callback the history system uses to notify us
785 // that it's done: OnRedirectQueryComplete.
initial.commit09911bf2008-07-26 23:55:29786 redirect_query_ = history_service->QueryRedirectsFrom(
787 source_url, &consumer_,
788 NewCallback(this, &AutomationProvider::OnRedirectQueryComplete));
789 return; // Response will be sent when query completes.
790 }
791 }
792
793 // Send failure response.
[email protected]deb57402009-02-06 01:35:30794 std::vector<GURL> empty;
[email protected]71f65dd2009-02-11 19:14:56795 AutomationMsg_RedirectsFrom::WriteReplyParams(reply_message, false, empty);
796 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:29797}
798
[email protected]71f65dd2009-02-11 19:14:56799void AutomationProvider::GetActiveTabIndex(int handle, int* active_tab_index) {
800 *active_tab_index = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:29801 if (browser_tracker_->ContainsHandle(handle)) {
802 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:56803 *active_tab_index = browser->selected_index();
initial.commit09911bf2008-07-26 23:55:29804 }
initial.commit09911bf2008-07-26 23:55:29805}
806
[email protected]202e7a72009-06-15 03:48:36807void AutomationProvider::GetBrowserLocale(string16* locale) {
808 DCHECK(g_browser_process);
[email protected]d70539de2009-06-24 22:17:06809 *locale = ASCIIToUTF16(g_browser_process->GetApplicationLocale());
[email protected]202e7a72009-06-15 03:48:36810}
811
[email protected]71f65dd2009-02-11 19:14:56812void AutomationProvider::GetBrowserWindowCount(int* window_count) {
813 *window_count = static_cast<int>(BrowserList::size());
initial.commit09911bf2008-07-26 23:55:29814}
815
[email protected]24497032009-05-01 17:00:29816void AutomationProvider::GetNormalBrowserWindowCount(int* window_count) {
817 *window_count = static_cast<int>(
818 BrowserList::GetBrowserCountForType(profile_, Browser::TYPE_NORMAL));
819}
820
[email protected]71f65dd2009-02-11 19:14:56821void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog,
822 int* dialog_button) {
[email protected]1f460072009-05-28 17:02:07823 AppModalDialog* dialog_delegate =
824 Singleton<AppModalDialogQueue>()->active_dialog();
[email protected]b3a70332009-02-25 02:40:50825 *showing_dialog = (dialog_delegate != NULL);
826 if (*showing_dialog)
827 *dialog_button = dialog_delegate->GetDialogButtons();
828 else
[email protected]478ff2ed2009-04-21 23:49:18829 *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE;
[email protected]fad84eab2008-12-05 00:37:20830}
831
[email protected]71f65dd2009-02-11 19:14:56832void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) {
833 *success = false;
[email protected]fad84eab2008-12-05 00:37:20834
[email protected]1f460072009-05-28 17:02:07835 AppModalDialog* dialog_delegate =
836 Singleton<AppModalDialogQueue>()->active_dialog();
[email protected]b3a70332009-02-25 02:40:50837 if (dialog_delegate &&
838 (dialog_delegate->GetDialogButtons() & button) == button) {
[email protected]478ff2ed2009-04-21 23:49:18839 if ((button & MessageBoxFlags::DIALOGBUTTON_OK) ==
840 MessageBoxFlags::DIALOGBUTTON_OK) {
[email protected]0bfa713f2009-04-07 20:18:28841 dialog_delegate->AcceptWindow();
[email protected]71f65dd2009-02-11 19:14:56842 *success = true;
[email protected]fad84eab2008-12-05 00:37:20843 }
[email protected]478ff2ed2009-04-21 23:49:18844 if ((button & MessageBoxFlags::DIALOGBUTTON_CANCEL) ==
845 MessageBoxFlags::DIALOGBUTTON_CANCEL) {
[email protected]71f65dd2009-02-11 19:14:56846 DCHECK(!*success) << "invalid param, OK and CANCEL specified";
[email protected]0bfa713f2009-04-07 20:18:28847 dialog_delegate->CancelWindow();
[email protected]71f65dd2009-02-11 19:14:56848 *success = true;
[email protected]fad84eab2008-12-05 00:37:20849 }
850 }
[email protected]c274acc2008-11-11 20:13:44851}
852
[email protected]fedaa7d2010-01-26 20:34:57853void AutomationProvider::ShutdownSessionService(int handle, bool* result) {
854 if (browser_tracker_->ContainsHandle(handle)) {
855 Browser* browser = browser_tracker_->GetResource(handle);
856 browser->profile()->ShutdownSessionService();
857 *result = true;
858 } else {
859 *result = false;
860 }
861}
862
[email protected]71f65dd2009-02-11 19:14:56863void AutomationProvider::GetBrowserWindow(int index, int* handle) {
864 *handle = 0;
initial.commit09911bf2008-07-26 23:55:29865 if (index >= 0) {
866 BrowserList::const_iterator iter = BrowserList::begin();
[email protected]24497032009-05-01 17:00:29867 for (; (iter != BrowserList::end()) && (index > 0); ++iter, --index);
initial.commit09911bf2008-07-26 23:55:29868 if (iter != BrowserList::end()) {
[email protected]71f65dd2009-02-11 19:14:56869 *handle = browser_tracker_->Add(*iter);
initial.commit09911bf2008-07-26 23:55:29870 }
871 }
initial.commit09911bf2008-07-26 23:55:29872}
873
[email protected]24497032009-05-01 17:00:29874void AutomationProvider::FindNormalBrowserWindow(int* handle) {
875 *handle = 0;
876 Browser* browser = BrowserList::FindBrowserWithType(profile_,
[email protected]62b0b532010-03-26 22:44:31877 Browser::TYPE_NORMAL,
878 false);
[email protected]24497032009-05-01 17:00:29879 if (browser)
880 *handle = browser_tracker_->Add(browser);
881}
882
[email protected]71f65dd2009-02-11 19:14:56883void AutomationProvider::GetLastActiveBrowserWindow(int* handle) {
884 *handle = 0;
initial.commit09911bf2008-07-26 23:55:29885 Browser* browser = BrowserList::GetLastActive();
886 if (browser)
[email protected]71f65dd2009-02-11 19:14:56887 *handle = browser_tracker_->Add(browser);
initial.commit09911bf2008-07-26 23:55:29888}
889
[email protected]b2aa3ed72010-02-01 18:37:14890#if defined(OS_POSIX)
[email protected]9a08bcf2009-08-12 19:56:28891// TODO(estade): use this implementation for all platforms?
892void AutomationProvider::GetActiveWindow(int* handle) {
893 gfx::NativeWindow window =
894 BrowserList::GetLastActive()->window()->GetNativeHandle();
895 *handle = window_tracker_->Add(window);
896}
897#endif
898
[email protected]4f6381ee2009-04-16 02:46:33899void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command,
900 bool* success) {
[email protected]71f65dd2009-02-11 19:14:56901 *success = false;
[email protected]4ae62752008-08-04 23:28:47902 if (browser_tracker_->ContainsHandle(handle)) {
903 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]1fc025202009-01-20 23:03:14904 if (browser->command_updater()->SupportsCommand(command) &&
905 browser->command_updater()->IsCommandEnabled(command)) {
[email protected]4ae62752008-08-04 23:28:47906 browser->ExecuteCommand(command);
[email protected]71f65dd2009-02-11 19:14:56907 *success = true;
[email protected]4ae62752008-08-04 23:28:47908 }
909 }
[email protected]4ae62752008-08-04 23:28:47910}
911
[email protected]4f6381ee2009-04-16 02:46:33912void AutomationProvider::ExecuteBrowserCommand(
[email protected]56e71b7c2009-03-27 03:05:56913 int handle, int command, IPC::Message* reply_message) {
[email protected]12887da72009-09-16 19:15:53914 // List of commands which just finish synchronously and don't require
915 // setting up an observer.
916 static const int kSynchronousCommands[] = {
917 IDC_HOME,
918 IDC_SELECT_NEXT_TAB,
919 IDC_SELECT_PREVIOUS_TAB,
920 IDC_SHOW_DOWNLOADS,
921 IDC_SHOW_HISTORY,
[email protected]3b5f7022010-03-25 20:37:40922 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]12887da72009-09-16 19:15:53923 };
[email protected]56e71b7c2009-03-27 03:05:56924 if (browser_tracker_->ContainsHandle(handle)) {
925 Browser* browser = browser_tracker_->GetResource(handle);
926 if (browser->command_updater()->SupportsCommand(command) &&
927 browser->command_updater()->IsCommandEnabled(command)) {
[email protected]12887da72009-09-16 19:15:53928 // First check if we can handle the command without using an observer.
929 for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) {
930 if (command == kSynchronousCommands[i]) {
931 browser->ExecuteCommand(command);
932 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message,
933 true);
934 Send(reply_message);
935 return;
936 }
937 }
938
939 // Use an observer if we have one, otherwise fail.
[email protected]d79ffea2009-05-07 20:51:42940 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver(
941 this, browser, command, reply_message)) {
[email protected]4e41709d2009-04-08 00:04:27942 browser->ExecuteCommand(command);
[email protected]d79ffea2009-05-07 20:51:42943 return;
944 }
[email protected]56e71b7c2009-03-27 03:05:56945 }
946 }
[email protected]49a14a82009-03-31 04:16:44947 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false);
[email protected]56e71b7c2009-03-27 03:05:56948 Send(reply_message);
949}
950
[email protected]fc2e0872009-08-21 22:14:41951// This task just adds another task to the event queue. This is useful if
952// you want to ensure that any tasks added to the event queue after this one
953// have already been processed by the time |task| is run.
954class InvokeTaskLaterTask : public Task {
955 public:
956 explicit InvokeTaskLaterTask(Task* task) : task_(task) {}
957 virtual ~InvokeTaskLaterTask() {}
958
959 virtual void Run() {
960 MessageLoop::current()->PostTask(FROM_HERE, task_);
961 }
962
963 private:
964 Task* task_;
965
966 DISALLOW_COPY_AND_ASSIGN(InvokeTaskLaterTask);
967};
968
[email protected]b2aa3ed72010-02-01 18:37:14969#if !defined(OS_MACOSX)
initial.commit09911bf2008-07-26 23:55:29970void AutomationProvider::WindowSimulateClick(const IPC::Message& message,
971 int handle,
[email protected]d1a5941e2009-08-13 23:34:24972 const gfx::Point& click,
initial.commit09911bf2008-07-26 23:55:29973 int flags) {
[email protected]b410bc32009-08-14 01:11:14974 if (window_tracker_->ContainsHandle(handle)) {
[email protected]c2cb8542009-08-20 21:16:51975 ui_controls::SendMouseMoveNotifyWhenDone(click.x(), click.y(),
[email protected]fc2e0872009-08-21 22:14:41976 new ClickTask(flags));
initial.commit09911bf2008-07-26 23:55:29977 }
978}
979
[email protected]60507b12009-11-02 23:51:35980void AutomationProvider::WindowSimulateMouseMove(const IPC::Message& message,
981 int handle,
982 const gfx::Point& location) {
983 if (window_tracker_->ContainsHandle(handle))
984 ui_controls::SendMouseMove(location.x(), location.y());
985}
986
initial.commit09911bf2008-07-26 23:55:29987void AutomationProvider::WindowSimulateKeyPress(const IPC::Message& message,
988 int handle,
[email protected]bc1407f2009-09-29 00:33:35989 int key,
initial.commit09911bf2008-07-26 23:55:29990 int flags) {
[email protected]b410bc32009-08-14 01:11:14991 if (!window_tracker_->ContainsHandle(handle))
initial.commit09911bf2008-07-26 23:55:29992 return;
993
[email protected]b410bc32009-08-14 01:11:14994 gfx::NativeWindow window = window_tracker_->GetResource(handle);
initial.commit09911bf2008-07-26 23:55:29995 // The key event is sent to whatever window is active.
[email protected]bc1407f2009-09-29 00:33:35996 ui_controls::SendKeyPress(window, static_cast<base::KeyboardCode>(key),
[email protected]c2dacc92008-10-16 23:51:38997 ((flags & views::Event::EF_CONTROL_DOWN) ==
998 views::Event::EF_CONTROL_DOWN),
999 ((flags & views::Event::EF_SHIFT_DOWN) ==
1000 views::Event::EF_SHIFT_DOWN),
1001 ((flags & views::Event::EF_ALT_DOWN) ==
1002 views::Event::EF_ALT_DOWN));
initial.commit09911bf2008-07-26 23:55:291003}
[email protected]b2aa3ed72010-02-01 18:37:141004#endif // !defined(OS_MACOSX)
initial.commit09911bf2008-07-26 23:55:291005
[email protected]71f65dd2009-02-11 19:14:561006void AutomationProvider::IsWindowActive(int handle, bool* success,
1007 bool* is_active) {
initial.commit09911bf2008-07-26 23:55:291008 if (window_tracker_->ContainsHandle(handle)) {
[email protected]d2cc6ed2009-04-24 00:26:171009 *is_active =
1010 platform_util::IsWindowActive(window_tracker_->GetResource(handle));
[email protected]71f65dd2009-02-11 19:14:561011 *success = true;
initial.commit09911bf2008-07-26 23:55:291012 } else {
[email protected]71f65dd2009-02-11 19:14:561013 *success = false;
1014 *is_active = false;
initial.commit09911bf2008-07-26 23:55:291015 }
1016}
1017
[email protected]71f65dd2009-02-11 19:14:561018void AutomationProvider::GetTabCount(int handle, int* tab_count) {
1019 *tab_count = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:291020
1021 if (browser_tracker_->ContainsHandle(handle)) {
1022 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:561023 *tab_count = browser->tab_count();
initial.commit09911bf2008-07-26 23:55:291024 }
initial.commit09911bf2008-07-26 23:55:291025}
1026
[email protected]982921f12009-10-27 21:43:531027void AutomationProvider::GetType(int handle, int* type_as_int) {
1028 *type_as_int = -1; // -1 is the error code
1029
1030 if (browser_tracker_->ContainsHandle(handle)) {
1031 Browser* browser = browser_tracker_->GetResource(handle);
1032 *type_as_int = static_cast<int>(browser->type());
1033 }
1034}
1035
[email protected]71f65dd2009-02-11 19:14:561036void AutomationProvider::GetTab(int win_handle, int tab_index,
1037 int* tab_handle) {
[email protected]71f65dd2009-02-11 19:14:561038 *tab_handle = 0;
initial.commit09911bf2008-07-26 23:55:291039 if (browser_tracker_->ContainsHandle(win_handle) && (tab_index >= 0)) {
1040 Browser* browser = browser_tracker_->GetResource(win_handle);
1041 if (tab_index < browser->tab_count()) {
1042 TabContents* tab_contents =
1043 browser->GetTabContentsAt(tab_index);
[email protected]ce3fa3c2009-04-20 19:55:571044 *tab_handle = tab_tracker_->Add(&tab_contents->controller());
initial.commit09911bf2008-07-26 23:55:291045 }
1046 }
initial.commit09911bf2008-07-26 23:55:291047}
1048
[email protected]71f65dd2009-02-11 19:14:561049void AutomationProvider::GetTabTitle(int handle, int* title_string_size,
1050 std::wstring* title) {
1051 *title_string_size = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:291052 if (tab_tracker_->ContainsHandle(handle)) {
1053 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]c100dbd2009-04-29 23:44:361054 NavigationEntry* entry = tab->GetActiveEntry();
1055 if (entry != NULL) {
1056 *title = UTF16ToWideHack(entry->title());
1057 } else {
1058 *title = std::wstring();
1059 }
[email protected]71f65dd2009-02-11 19:14:561060 *title_string_size = static_cast<int>(title->size());
initial.commit09911bf2008-07-26 23:55:291061 }
initial.commit09911bf2008-07-26 23:55:291062}
1063
[email protected]77bc6732009-04-20 22:01:031064void AutomationProvider::GetTabIndex(int handle, int* tabstrip_index) {
1065 *tabstrip_index = -1; // -1 is the error code
1066
1067 if (tab_tracker_->ContainsHandle(handle)) {
1068 NavigationController* tab = tab_tracker_->GetResource(handle);
1069 Browser* browser = Browser::GetBrowserForController(tab, NULL);
[email protected]902cdf772009-05-06 15:08:121070 *tabstrip_index = browser->tabstrip_model()->GetIndexOfController(tab);
[email protected]77bc6732009-04-20 22:01:031071 }
1072}
1073
initial.commit09911bf2008-07-26 23:55:291074void AutomationProvider::HandleUnused(const IPC::Message& message, int handle) {
1075 if (window_tracker_->ContainsHandle(handle)) {
1076 window_tracker_->Remove(window_tracker_->GetResource(handle));
1077 }
1078}
1079
1080void AutomationProvider::OnChannelError() {
[email protected]2947cdcd2009-12-03 21:05:161081 LOG(INFO) << "AutomationProxy went away, shutting down app.";
[email protected]295039bd2008-08-15 04:32:571082 AutomationProviderList::GetInstance()->RemoveProvider(this);
initial.commit09911bf2008-07-26 23:55:291083}
1084
1085// TODO(brettw) change this to accept GURLs when history supports it
1086void AutomationProvider::OnRedirectQueryComplete(
1087 HistoryService::Handle request_handle,
[email protected]3e377c52009-08-06 07:46:371088 GURL from_url,
initial.commit09911bf2008-07-26 23:55:291089 bool success,
[email protected]379c2b12009-07-01 21:50:331090 history::RedirectList* redirects) {
initial.commit09911bf2008-07-26 23:55:291091 DCHECK(request_handle == redirect_query_);
[email protected]71f65dd2009-02-11 19:14:561092 DCHECK(reply_message_ != NULL);
initial.commit09911bf2008-07-26 23:55:291093
[email protected]deb57402009-02-06 01:35:301094 std::vector<GURL> redirects_gurl;
[email protected]0bc24482010-03-05 00:33:101095 reply_message_->WriteBool(success);
initial.commit09911bf2008-07-26 23:55:291096 if (success) {
initial.commit09911bf2008-07-26 23:55:291097 for (size_t i = 0; i < redirects->size(); i++)
[email protected]deb57402009-02-06 01:35:301098 redirects_gurl.push_back(redirects->at(i));
initial.commit09911bf2008-07-26 23:55:291099 }
1100
[email protected]4f3dc372009-02-24 00:10:291101 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl);
[email protected]deb57402009-02-06 01:35:301102
[email protected]71f65dd2009-02-11 19:14:561103 Send(reply_message_);
[email protected]5a3b9142009-08-28 21:03:171104 redirect_query_ = NULL;
[email protected]71f65dd2009-02-11 19:14:561105 reply_message_ = NULL;
initial.commit09911bf2008-07-26 23:55:291106}
1107
1108bool AutomationProvider::Send(IPC::Message* msg) {
[email protected]295039bd2008-08-15 04:32:571109 DCHECK(channel_.get());
1110 return channel_->Send(msg);
initial.commit09911bf2008-07-26 23:55:291111}
1112
1113Browser* AutomationProvider::FindAndActivateTab(
1114 NavigationController* controller) {
1115 int tab_index;
1116 Browser* browser = Browser::GetBrowserForController(controller, &tab_index);
1117 if (browser)
1118 browser->SelectTabContentsAt(tab_index, true);
1119
1120 return browser;
1121}
1122
[email protected]71f65dd2009-02-11 19:14:561123void AutomationProvider::GetCookies(const GURL& url, int handle,
1124 int* value_size,
1125 std::string* value) {
1126 *value_size = -1;
initial.commit09911bf2008-07-26 23:55:291127 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
1128 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]be180c802009-10-23 06:33:311129
1130 // Since we are running on the UI thread don't call GetURLRequestContext().
[email protected]70daf0b2010-03-02 19:13:001131 scoped_refptr<URLRequestContextGetter> request_context =
1132 tab->tab_contents()->request_context();
1133 if (!request_context.get())
1134 request_context = tab->profile()->GetRequestContext();
1135
1136 net::CookieStore* cookie_store = request_context->GetCookieStore();
[email protected]be180c802009-10-23 06:33:311137
1138 *value = cookie_store->GetCookies(url);
[email protected]71f65dd2009-02-11 19:14:561139 *value_size = static_cast<int>(value->size());
initial.commit09911bf2008-07-26 23:55:291140 }
initial.commit09911bf2008-07-26 23:55:291141}
1142
[email protected]71f65dd2009-02-11 19:14:561143void AutomationProvider::SetCookie(const GURL& url,
initial.commit09911bf2008-07-26 23:55:291144 const std::string value,
[email protected]71f65dd2009-02-11 19:14:561145 int handle,
1146 int* response_value) {
1147 *response_value = -1;
initial.commit09911bf2008-07-26 23:55:291148
1149 if (url.is_valid() && tab_tracker_->ContainsHandle(handle)) {
1150 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]be180c802009-10-23 06:33:311151
[email protected]dfa46e5f2009-11-17 18:48:431152 scoped_refptr<URLRequestContextGetter> request_context =
1153 tab->tab_contents()->request_context();
1154 if (!request_context.get())
1155 request_context = tab->profile()->GetRequestContext();
1156
[email protected]be180c802009-10-23 06:33:311157 // Since we are running on the UI thread don't call GetURLRequestContext().
1158 scoped_refptr<net::CookieStore> cookie_store =
[email protected]dfa46e5f2009-11-17 18:48:431159 request_context->GetCookieStore();
[email protected]be180c802009-10-23 06:33:311160
1161 if (cookie_store->SetCookie(url, value))
[email protected]71f65dd2009-02-11 19:14:561162 *response_value = 1;
initial.commit09911bf2008-07-26 23:55:291163 }
initial.commit09911bf2008-07-26 23:55:291164}
1165
[email protected]71f65dd2009-02-11 19:14:561166void AutomationProvider::GetTabURL(int handle, bool* success, GURL* url) {
1167 *success = false;
initial.commit09911bf2008-07-26 23:55:291168 if (tab_tracker_->ContainsHandle(handle)) {
1169 NavigationController* tab = tab_tracker_->GetResource(handle);
1170 // Return what the user would see in the location bar.
[email protected]ebe89e062009-08-13 23:16:541171 *url = tab->GetActiveEntry()->virtual_url();
[email protected]71f65dd2009-02-11 19:14:561172 *success = true;
initial.commit09911bf2008-07-26 23:55:291173 }
initial.commit09911bf2008-07-26 23:55:291174}
1175
[email protected]71f65dd2009-02-11 19:14:561176void AutomationProvider::GetTabProcessID(int handle, int* process_id) {
1177 *process_id = -1;
initial.commit09911bf2008-07-26 23:55:291178
1179 if (tab_tracker_->ContainsHandle(handle)) {
[email protected]71f65dd2009-02-11 19:14:561180 *process_id = 0;
[email protected]57c6a652009-05-04 07:58:341181 TabContents* tab_contents =
1182 tab_tracker_->GetResource(handle)->tab_contents();
[email protected]8cb5d5b2010-02-09 11:36:161183 RenderProcessHost* rph = tab_contents->GetRenderProcessHost();
1184 if (rph)
1185 *process_id = base::GetProcId(rph->GetHandle());
initial.commit09911bf2008-07-26 23:55:291186 }
initial.commit09911bf2008-07-26 23:55:291187}
1188
1189void AutomationProvider::ApplyAccelerator(int handle, int id) {
[email protected]4f6381ee2009-04-16 02:46:331190 NOTREACHED() << "This function has been deprecated. "
1191 << "Please use ExecuteBrowserCommandAsync instead.";
initial.commit09911bf2008-07-26 23:55:291192}
1193
[email protected]71f65dd2009-02-11 19:14:561194void AutomationProvider::ExecuteJavascript(int handle,
initial.commit09911bf2008-07-26 23:55:291195 const std::wstring& frame_xpath,
[email protected]71f65dd2009-02-11 19:14:561196 const std::wstring& script,
1197 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291198 bool succeeded = false;
[email protected]57c6a652009-05-04 07:58:341199 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL);
1200 if (tab_contents) {
[email protected]20e93d12008-08-28 16:31:571201 // Set the routing id of this message with the controller.
1202 // This routing id needs to be remembered for the reverse
1203 // communication while sending back the response of
1204 // this javascript execution.
[email protected]f29acf52008-11-03 20:08:331205 std::wstring set_automation_id;
1206 SStringPrintf(&set_automation_id,
1207 L"window.domAutomationController.setAutomationId(%d);",
[email protected]71f65dd2009-02-11 19:14:561208 reply_message->routing_id());
1209
1210 DCHECK(reply_message_ == NULL);
1211 reply_message_ = reply_message;
initial.commit09911bf2008-07-26 23:55:291212
[email protected]57c6a652009-05-04 07:58:341213 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
[email protected]f29acf52008-11-03 20:08:331214 frame_xpath, set_automation_id);
[email protected]57c6a652009-05-04 07:58:341215 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame(
[email protected]1f5af4442008-09-25 22:11:061216 frame_xpath, script);
[email protected]20e93d12008-08-28 16:31:571217 succeeded = true;
initial.commit09911bf2008-07-26 23:55:291218 }
1219
1220 if (!succeeded) {
[email protected]71f65dd2009-02-11 19:14:561221 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string());
1222 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291223 }
1224}
1225
[email protected]71f65dd2009-02-11 19:14:561226void AutomationProvider::GetShelfVisibility(int handle, bool* visible) {
1227 *visible = false;
[email protected]20e93d12008-08-28 16:31:571228
[email protected]59560e0b2009-06-04 03:30:221229 if (browser_tracker_->ContainsHandle(handle)) {
[email protected]f5bf8ccf2010-02-05 18:19:251230#if defined(OS_CHROMEOS)
1231 // Chromium OS shows FileBrowse ui rather than download shelf. So we
1232 // enumerate all browsers and look for a chrome://filebrowse... pop up.
1233 for (BrowserList::const_iterator it = BrowserList::begin();
1234 it != BrowserList::end(); ++it) {
1235 if ((*it)->type() == Browser::TYPE_POPUP) {
1236 const GURL& url =
1237 (*it)->GetTabContentsAt((*it)->selected_index())->GetURL();
1238
1239 if (url.SchemeIs(chrome::kChromeUIScheme) &&
1240 url.host() == chrome::kChromeUIFileBrowseHost) {
1241 *visible = true;
1242 break;
1243 }
1244 }
1245 }
1246#else
[email protected]59560e0b2009-06-04 03:30:221247 Browser* browser = browser_tracker_->GetResource(handle);
1248 if (browser) {
1249 *visible = browser->window()->IsDownloadShelfVisible();
1250 }
[email protected]f5bf8ccf2010-02-05 18:19:251251#endif
[email protected]59560e0b2009-06-04 03:30:221252 }
initial.commit09911bf2008-07-26 23:55:291253}
1254
[email protected]59560e0b2009-06-04 03:30:221255void AutomationProvider::SetShelfVisibility(int handle, bool visible) {
1256 if (browser_tracker_->ContainsHandle(handle)) {
1257 Browser* browser = browser_tracker_->GetResource(handle);
1258 if (browser) {
1259 if (visible)
1260 browser->window()->GetDownloadShelf()->Show();
1261 else
1262 browser->window()->GetDownloadShelf()->Close();
1263 }
1264 }
1265}
1266
[email protected]34930432009-11-09 00:12:091267void AutomationProvider::IsFullscreen(int handle, bool* visible) {
1268 *visible = false;
1269
1270 if (browser_tracker_->ContainsHandle(handle)) {
1271 Browser* browser = browser_tracker_->GetResource(handle);
1272 if (browser)
1273 *visible = browser->window()->IsFullscreen();
1274 }
1275}
1276
1277void AutomationProvider::GetFullscreenBubbleVisibility(int handle,
1278 bool* visible) {
1279 *visible = false;
1280
1281 if (browser_tracker_->ContainsHandle(handle)) {
1282 Browser* browser = browser_tracker_->GetResource(handle);
1283 if (browser)
1284 *visible = browser->window()->IsFullscreenBubbleVisible();
1285 }
1286}
[email protected]59560e0b2009-06-04 03:30:221287
[email protected]71f65dd2009-02-11 19:14:561288void AutomationProvider::GetConstrainedWindowCount(int handle, int* count) {
1289 *count = -1; // -1 is the error code
initial.commit09911bf2008-07-26 23:55:291290 if (tab_tracker_->ContainsHandle(handle)) {
1291 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
[email protected]7f0005a2009-04-15 03:25:111292 TabContents* tab_contents = nav_controller->tab_contents();
initial.commit09911bf2008-07-26 23:55:291293 if (tab_contents) {
[email protected]71f65dd2009-02-11 19:14:561294 *count = static_cast<int>(tab_contents->child_windows_.size());
initial.commit09911bf2008-07-26 23:55:291295 }
1296 }
initial.commit09911bf2008-07-26 23:55:291297}
1298
initial.commit09911bf2008-07-26 23:55:291299void AutomationProvider::HandleFindInPageRequest(
[email protected]71f65dd2009-02-11 19:14:561300 int handle, const std::wstring& find_request,
1301 int forward, int match_case, int* active_ordinal, int* matches_found) {
[email protected]5a52f162008-08-27 04:15:311302 NOTREACHED() << "This function has been deprecated."
1303 << "Please use HandleFindRequest instead.";
[email protected]71f65dd2009-02-11 19:14:561304 *matches_found = -1;
[email protected]5a52f162008-08-27 04:15:311305 return;
1306}
1307
[email protected]4f999132009-03-31 18:08:401308void AutomationProvider::HandleFindRequest(
1309 int handle,
1310 const AutomationMsg_Find_Params& params,
1311 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291312 if (!tab_tracker_->ContainsHandle(handle)) {
[email protected]71f65dd2009-02-11 19:14:561313 AutomationMsg_FindInPage::WriteReplyParams(reply_message, -1, -1);
1314 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291315 return;
1316 }
1317
1318 NavigationController* nav = tab_tracker_->GetResource(handle);
[email protected]7f0005a2009-04-15 03:25:111319 TabContents* tab_contents = nav->tab_contents();
initial.commit09911bf2008-07-26 23:55:291320
1321 find_in_page_observer_.reset(new
[email protected]1c58a5c2009-05-21 18:47:141322 FindInPageNotificationObserver(this, tab_contents, reply_message));
initial.commit09911bf2008-07-26 23:55:291323
[email protected]57c6a652009-05-04 07:58:341324 tab_contents->set_current_find_request_id(
1325 FindInPageNotificationObserver::kFindInPageRequestId);
1326 tab_contents->render_view_host()->StartFinding(
1327 FindInPageNotificationObserver::kFindInPageRequestId,
1328 params.search_string, params.forward, params.match_case,
1329 params.find_next);
initial.commit09911bf2008-07-26 23:55:291330}
1331
[email protected]5f8af2a2008-08-06 22:49:451332void AutomationProvider::HandleOpenFindInPageRequest(
1333 const IPC::Message& message, int handle) {
[email protected]4f3dc372009-02-24 00:10:291334 if (browser_tracker_->ContainsHandle(handle)) {
1335 Browser* browser = browser_tracker_->GetResource(handle);
1336 browser->FindInPage(false, false);
[email protected]5f8af2a2008-08-06 22:49:451337 }
1338}
1339
[email protected]71f65dd2009-02-11 19:14:561340void AutomationProvider::GetFindWindowVisibility(int handle, bool* visible) {
[email protected]71f65dd2009-02-11 19:14:561341 *visible = false;
[email protected]855c0142009-09-28 22:35:241342 Browser* browser = browser_tracker_->GetResource(handle);
1343 if (browser) {
[email protected]4801ecc2009-04-05 04:52:581344 FindBarTesting* find_bar =
[email protected]b77cb302009-10-29 04:09:171345 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
[email protected]855c0142009-09-28 22:35:241346 find_bar->GetFindBarWindowInfo(NULL, visible);
[email protected]4f3dc372009-02-24 00:10:291347 }
[email protected]20e93d12008-08-28 16:31:571348}
1349
[email protected]71f65dd2009-02-11 19:14:561350void AutomationProvider::HandleFindWindowLocationRequest(int handle, int* x,
1351 int* y) {
[email protected]9e0534b2008-10-21 15:03:011352 gfx::Point position(0, 0);
1353 bool visible = false;
[email protected]4f3dc372009-02-24 00:10:291354 if (browser_tracker_->ContainsHandle(handle)) {
1355 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]4801ecc2009-04-05 04:52:581356 FindBarTesting* find_bar =
[email protected]b77cb302009-10-29 04:09:171357 browser->GetFindBarController()->find_bar()->GetFindBarTesting();
[email protected]4801ecc2009-04-05 04:52:581358 find_bar->GetFindBarWindowInfo(&position, &visible);
[email protected]4f3dc372009-02-24 00:10:291359 }
[email protected]20e93d12008-08-28 16:31:571360
[email protected]71f65dd2009-02-11 19:14:561361 *x = position.x();
1362 *y = position.y();
[email protected]20e93d12008-08-28 16:31:571363}
1364
[email protected]4512cb52010-04-05 19:50:251365// Bookmark bar visibility is based on the pref (e.g. is it in the toolbar).
1366// Presence in the NTP is NOT considered visible by this call.
[email protected]c3240722010-03-05 21:52:581367void AutomationProvider::GetBookmarkBarVisibility(int handle,
1368 bool* visible,
1369 bool* animating) {
1370 *visible = false;
1371 *animating = false;
1372
1373 if (browser_tracker_->ContainsHandle(handle)) {
1374 Browser* browser = browser_tracker_->GetResource(handle);
1375 if (browser) {
[email protected]4512cb52010-04-05 19:50:251376 // The commented-out IsBookmarkBarVisible() line looks correct
1377 // but is not consistent across platforms. Specifically, on
1378 // Mac/Linux, it returns false if the bar is hidden in a pref
1379 // (even if visible on the NTP). On ChromeOS, it returned true
1380 // if on NTP independent of the pref. Making the code more
1381 // consistent caused a perf bot regression on Windows (which
1382 // shares views). See http://crbug.com/40225
1383 // // *visible = browser->window()->IsBookmarkBarVisible();
[email protected]7e4cd4e82010-04-05 20:59:401384#if defined(TOOLKIT_VIEWS) && defined(OS_LINUX)
[email protected]4512cb52010-04-05 19:50:251385 *visible = browser->profile()->GetPrefs()->GetBoolean(
1386 prefs::kShowBookmarkBar);
[email protected]7e4cd4e82010-04-05 20:59:401387#else
1388 *visible = browser->window()->IsBookmarkBarVisible();
1389#endif
[email protected]c3240722010-03-05 21:52:581390 *animating = browser->window()->IsBookmarkBarAnimating();
1391 }
1392 }
1393}
1394
[email protected]6d8ffc9f2010-03-12 18:27:531395void AutomationProvider::GetBookmarksAsJSON(int handle,
1396 std::string* bookmarks_as_json,
1397 bool *success) {
1398 *success = false;
1399 if (browser_tracker_->ContainsHandle(handle)) {
1400 Browser* browser = browser_tracker_->GetResource(handle);
1401 if (browser) {
1402 if (!browser->profile()->GetBookmarkModel()->IsLoaded()) {
1403 return;
1404 }
1405 scoped_refptr<BookmarkStorage> storage = new BookmarkStorage(
1406 browser->profile(),
1407 browser->profile()->GetBookmarkModel());
1408 *success = storage->SerializeData(bookmarks_as_json);
1409 }
1410 }
1411}
1412
1413void AutomationProvider::WaitForBookmarkModelToLoad(
1414 int handle,
1415 IPC::Message* reply_message) {
1416 if (browser_tracker_->ContainsHandle(handle)) {
1417 Browser* browser = browser_tracker_->GetResource(handle);
1418 BookmarkModel* model = browser->profile()->GetBookmarkModel();
1419 if (model->IsLoaded()) {
1420 AutomationMsg_WaitForBookmarkModelToLoad::WriteReplyParams(
1421 reply_message, true);
1422 Send(reply_message);
1423 } else {
1424 // The observer will delete itself when done.
1425 new AutomationProviderBookmarkModelObserver(this, reply_message,
1426 model);
1427 }
1428 }
1429}
1430
1431void AutomationProvider::AddBookmarkGroup(int handle,
1432 int64 parent_id, int index,
1433 std::wstring title,
1434 bool* success) {
1435 if (browser_tracker_->ContainsHandle(handle)) {
1436 Browser* browser = browser_tracker_->GetResource(handle);
1437 if (browser) {
1438 BookmarkModel* model = browser->profile()->GetBookmarkModel();
1439 if (!model->IsLoaded()) {
1440 *success = false;
1441 return;
1442 }
1443 const BookmarkNode* parent = model->GetNodeByID(parent_id);
1444 DCHECK(parent);
1445 if (parent) {
1446 const BookmarkNode* child = model->AddGroup(parent, index,
1447 WideToUTF16(title));
1448 DCHECK(child);
1449 if (child)
1450 *success = true;
1451 }
1452 }
1453 }
1454 *success = false;
1455}
1456
1457void AutomationProvider::AddBookmarkURL(int handle,
1458 int64 parent_id, int index,
1459 std::wstring title, const GURL& url,
1460 bool* success) {
1461 if (browser_tracker_->ContainsHandle(handle)) {
1462 Browser* browser = browser_tracker_->GetResource(handle);
1463 if (browser) {
1464 BookmarkModel* model = browser->profile()->GetBookmarkModel();
1465 if (!model->IsLoaded()) {
1466 *success = false;
1467 return;
1468 }
1469 const BookmarkNode* parent = model->GetNodeByID(parent_id);
1470 DCHECK(parent);
1471 if (parent) {
1472 const BookmarkNode* child = model->AddURL(parent, index,
1473 WideToUTF16(title), url);
1474 DCHECK(child);
1475 if (child)
1476 *success = true;
1477 }
1478 }
1479 }
1480 *success = false;
1481}
1482
1483void AutomationProvider::ReparentBookmark(int handle,
1484 int64 id, int64 new_parent_id,
1485 int index,
1486 bool* success) {
1487 if (browser_tracker_->ContainsHandle(handle)) {
1488 Browser* browser = browser_tracker_->GetResource(handle);
1489 if (browser) {
1490 BookmarkModel* model = browser->profile()->GetBookmarkModel();
1491 if (!model->IsLoaded()) {
1492 *success = false;
1493 return;
1494 }
1495 const BookmarkNode* node = model->GetNodeByID(id);
1496 DCHECK(node);
1497 const BookmarkNode* new_parent = model->GetNodeByID(new_parent_id);
1498 DCHECK(new_parent);
1499 if (node && new_parent) {
1500 model->Move(node, new_parent, index);
1501 *success = true;
1502 }
1503 }
1504 }
1505 *success = false;
1506}
1507
1508void AutomationProvider::SetBookmarkTitle(int handle,
1509 int64 id, std::wstring title,
1510 bool* success) {
1511 if (browser_tracker_->ContainsHandle(handle)) {
1512 Browser* browser = browser_tracker_->GetResource(handle);
1513 if (browser) {
1514 BookmarkModel* model = browser->profile()->GetBookmarkModel();
1515 if (!model->IsLoaded()) {
1516 *success = false;
1517 return;
1518 }
1519 const BookmarkNode* node = model->GetNodeByID(id);
1520 DCHECK(node);
1521 if (node) {
1522 model->SetTitle(node, WideToUTF16(title));
1523 *success = true;
1524 }
1525 }
1526 }
1527 *success = false;
1528}
1529
1530void AutomationProvider::SetBookmarkURL(int handle,
1531 int64 id, const GURL& url,
1532 bool* success) {
1533 if (browser_tracker_->ContainsHandle(handle)) {
1534 Browser* browser = browser_tracker_->GetResource(handle);
1535 if (browser) {
1536 BookmarkModel* model = browser->profile()->GetBookmarkModel();
1537 if (!model->IsLoaded()) {
1538 *success = false;
1539 return;
1540 }
1541 const BookmarkNode* node = model->GetNodeByID(id);
1542 DCHECK(node);
1543 if (node) {
1544 model->SetURL(node, url);
1545 *success = true;
1546 }
1547 }
1548 }
1549 *success = false;
1550}
1551
1552void AutomationProvider::RemoveBookmark(int handle,
1553 int64 id,
1554 bool* success) {
1555 if (browser_tracker_->ContainsHandle(handle)) {
1556 Browser* browser = browser_tracker_->GetResource(handle);
1557 if (browser) {
1558 BookmarkModel* model = browser->profile()->GetBookmarkModel();
1559 if (!model->IsLoaded()) {
1560 *success = false;
1561 return;
1562 }
1563 const BookmarkNode* node = model->GetNodeByID(id);
1564 DCHECK(node);
1565 if (node) {
1566 const BookmarkNode* parent = node->GetParent();
1567 DCHECK(parent);
1568 model->Remove(parent, parent->IndexOfChild(node));
1569 *success = true;
1570 }
1571 }
1572 }
1573 *success = false;
1574}
1575
[email protected]59a611242010-04-02 02:24:041576void AutomationProvider::WaitForDownloadsToComplete(
1577 DictionaryValue* args,
1578 IPC::Message* reply_message) {
1579 std::string json_return;
1580 bool reply_return = true;
1581 AutomationProviderDownloadManagerObserver observer;
1582 std::vector<DownloadItem*> downloads;
1583
1584 // Look for a quick return.
1585 if (!profile_->HasCreatedDownloadManager()) {
1586 json_return = "{'error': 'no download manager'}";
1587 reply_return = false;
1588 } else {
1589 profile_->GetDownloadManager()->GetCurrentDownloads(&observer,
1590 FilePath());
1591 downloads = observer.Downloads();
1592 if (downloads.size() == 0) {
1593 json_return = "{}";
1594 }
1595 }
1596 if (!json_return.empty()) {
1597 AutomationMsg_SendJSONRequest::WriteReplyParams(
1598 reply_message, json_return, reply_return);
1599 Send(reply_message);
1600 }
1601
1602 // The observer owns itself. When the last observed item pings, it
1603 // deletes itself.
1604 AutomationProviderDownloadItemObserver* item_observer =
1605 new AutomationProviderDownloadItemObserver(
1606 this, reply_message, downloads.size());
1607 for (std::vector<DownloadItem*>::iterator i = downloads.begin();
1608 i != downloads.end();
1609 i++) {
1610 (*i)->AddObserver(item_observer);
1611 }
1612}
1613
1614void AutomationProvider::SendJSONRequest(
1615 int handle,
1616 std::string json_request,
1617 IPC::Message* reply_message) {
1618 Browser* browser = NULL;
1619 std::string error_string;
1620 scoped_ptr<Value> values;
1621
1622 // Basic error checking.
1623 if (browser_tracker_->ContainsHandle(handle)) {
1624 browser = browser_tracker_->GetResource(handle);
1625 }
1626 if (!browser) {
1627 error_string = "no browser object";
1628 } else {
1629 base::JSONReader reader;
1630 std::string error;
[email protected]ba399672010-04-06 15:42:391631 values.reset(reader.ReadAndReturnError(json_request, true, NULL, &error));
[email protected]59a611242010-04-02 02:24:041632 if (!error.empty()) {
1633 error_string = error;
1634 }
1635 }
1636
1637 // Make sure input is a dict with a string command.
1638 std::string command;
1639 DictionaryValue* dict_value = NULL;
1640 if (error_string.empty()) {
1641 if (values->GetType() != Value::TYPE_DICTIONARY) {
1642 error_string = "not a dict or no command key in dict";
1643 } else {
1644 // Ownership remains with "values" variable.
1645 dict_value = static_cast<DictionaryValue*>(values.get());
1646 if (!dict_value->GetStringASCII(std::string("command"), &command)) {
1647 error_string = "no command key in dict or not a string command";
1648 }
1649 }
1650 }
1651
1652 if (error_string.empty()) {
1653 // TODO(jrg): table of calls; async gets passed reply_message,
1654 // sync methods gets passed an output json dict which we package
1655 // up and send. Right now we only have one.
1656 if (command == "WaitForAllDownloadsToComplete") {
1657 this->WaitForDownloadsToComplete(dict_value, reply_message);
1658 return;
1659 } else {
1660 error_string = "unknown command";
1661 }
1662 }
1663
1664 // If we hit an error, return info.
1665 // Return a dict of {'error', 'descriptive_string_for_error'}.
1666 // Else return an empty dict.
1667 std::string json_string;
1668 bool success = true;
1669 if (!error_string.empty()) {
1670 scoped_ptr<DictionaryValue> dict(new DictionaryValue);
1671 dict->SetString(L"error", error_string);
1672 base::JSONWriter::Write(dict.get(), false, &json_string);
1673 success = false;
1674 } else {
1675 json_string = "{}";
1676 }
1677 AutomationMsg_SendJSONRequest::WriteReplyParams(
1678 reply_message, json_string, success);
1679 Send(reply_message);
1680}
1681
initial.commit09911bf2008-07-26 23:55:291682void AutomationProvider::HandleInspectElementRequest(
[email protected]71f65dd2009-02-11 19:14:561683 int handle, int x, int y, IPC::Message* reply_message) {
[email protected]57c6a652009-05-04 07:58:341684 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL);
1685 if (tab_contents) {
[email protected]71f65dd2009-02-11 19:14:561686 DCHECK(reply_message_ == NULL);
1687 reply_message_ = reply_message;
1688
[email protected]d9f9b792009-06-24 13:17:121689 DevToolsManager::GetInstance()->InspectElement(
1690 tab_contents->render_view_host(), x, y);
initial.commit09911bf2008-07-26 23:55:291691 } else {
[email protected]71f65dd2009-02-11 19:14:561692 AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1);
1693 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291694 }
1695}
1696
1697void AutomationProvider::ReceivedInspectElementResponse(int num_resources) {
[email protected]396c3b32009-03-12 22:26:091698 if (reply_message_) {
1699 AutomationMsg_InspectElement::WriteReplyParams(reply_message_,
1700 num_resources);
1701 Send(reply_message_);
1702 reply_message_ = NULL;
1703 }
initial.commit09911bf2008-07-26 23:55:291704}
1705
[email protected]a7eee32f2009-05-22 18:08:171706class SetProxyConfigTask : public Task {
1707 public:
[email protected]be180c802009-10-23 06:33:311708 SetProxyConfigTask(URLRequestContextGetter* request_context_getter,
1709 const std::string& new_proxy_config)
1710 : request_context_getter_(request_context_getter), proxy_config_(new_proxy_config) {}
[email protected]a7eee32f2009-05-22 18:08:171711 virtual void Run() {
1712 // First, deserialize the JSON string. If this fails, log and bail.
1713 JSONStringValueSerializer deserializer(proxy_config_);
[email protected]ba399672010-04-06 15:42:391714 std::string error_msg;
1715 scoped_ptr<Value> root(deserializer.Deserialize(NULL, &error_msg));
[email protected]a7eee32f2009-05-22 18:08:171716 if (!root.get() || root->GetType() != Value::TYPE_DICTIONARY) {
1717 DLOG(WARNING) << "Received bad JSON string for ProxyConfig: "
[email protected]ba399672010-04-06 15:42:391718 << error_msg;
[email protected]a7eee32f2009-05-22 18:08:171719 return;
1720 }
1721
1722 scoped_ptr<DictionaryValue> dict(
1723 static_cast<DictionaryValue*>(root.release()));
1724 // Now put together a proxy configuration from the deserialized string.
1725 net::ProxyConfig pc;
1726 PopulateProxyConfig(*dict.get(), &pc);
1727
[email protected]be180c802009-10-23 06:33:311728 net::ProxyService* proxy_service =
1729 request_context_getter_->GetURLRequestContext()->proxy_service();
1730 DCHECK(proxy_service);
[email protected]a7eee32f2009-05-22 18:08:171731 scoped_ptr<net::ProxyConfigService> proxy_config_service(
1732 new net::ProxyConfigServiceFixed(pc));
[email protected]be180c802009-10-23 06:33:311733 proxy_service->ResetConfigService(proxy_config_service.release());
[email protected]a7eee32f2009-05-22 18:08:171734 }
1735
1736 void PopulateProxyConfig(const DictionaryValue& dict, net::ProxyConfig* pc) {
1737 DCHECK(pc);
1738 bool no_proxy = false;
1739 if (dict.GetBoolean(automation::kJSONProxyNoProxy, &no_proxy)) {
1740 // Make no changes to the ProxyConfig.
1741 return;
1742 }
1743 bool auto_config;
1744 if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) {
[email protected]ed4ed0f2010-02-24 00:20:481745 pc->set_auto_detect(true);
[email protected]a7eee32f2009-05-22 18:08:171746 }
1747 std::string pac_url;
1748 if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) {
[email protected]ed4ed0f2010-02-24 00:20:481749 pc->set_pac_url(GURL(pac_url));
[email protected]a7eee32f2009-05-22 18:08:171750 }
1751 std::string proxy_bypass_list;
1752 if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) {
[email protected]ed4ed0f2010-02-24 00:20:481753 pc->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_list);
[email protected]a7eee32f2009-05-22 18:08:171754 }
1755 std::string proxy_server;
1756 if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) {
[email protected]ed4ed0f2010-02-24 00:20:481757 pc->proxy_rules().ParseFromString(proxy_server);
[email protected]a7eee32f2009-05-22 18:08:171758 }
1759 }
1760
1761 private:
[email protected]be180c802009-10-23 06:33:311762 scoped_refptr<URLRequestContextGetter> request_context_getter_;
[email protected]a7eee32f2009-05-22 18:08:171763 std::string proxy_config_;
1764};
1765
1766
1767void AutomationProvider::SetProxyConfig(const std::string& new_proxy_config) {
[email protected]be180c802009-10-23 06:33:311768 URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext();
1769 if (!context_getter) {
[email protected]a7eee32f2009-05-22 18:08:171770 FilePath user_data_dir;
1771 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
1772 ProfileManager* profile_manager = g_browser_process->profile_manager();
1773 DCHECK(profile_manager);
1774 Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
1775 DCHECK(profile);
[email protected]be180c802009-10-23 06:33:311776 context_getter = profile->GetRequestContext();
[email protected]a7eee32f2009-05-22 18:08:171777 }
[email protected]be180c802009-10-23 06:33:311778 DCHECK(context_getter);
[email protected]a7eee32f2009-05-22 18:08:171779
[email protected]fae20792009-10-28 20:31:581780 ChromeThread::PostTask(
1781 ChromeThread::IO, FROM_HERE,
[email protected]be180c802009-10-23 06:33:311782 new SetProxyConfigTask(context_getter, new_proxy_config));
[email protected]a7eee32f2009-05-22 18:08:171783}
1784
[email protected]4f3dc372009-02-24 00:10:291785void AutomationProvider::GetDownloadDirectory(
[email protected]1f733cf2009-09-30 20:46:331786 int handle, FilePath* download_directory) {
initial.commit09911bf2008-07-26 23:55:291787 DLOG(INFO) << "Handling download directory request";
initial.commit09911bf2008-07-26 23:55:291788 if (tab_tracker_->ContainsHandle(handle)) {
1789 NavigationController* tab = tab_tracker_->GetResource(handle);
1790 DownloadManager* dlm = tab->profile()->GetDownloadManager();
1791 DCHECK(dlm);
[email protected]1f733cf2009-09-30 20:46:331792 *download_directory = dlm->download_path();
initial.commit09911bf2008-07-26 23:55:291793 }
initial.commit09911bf2008-07-26 23:55:291794}
1795
[email protected]6a5670d22009-10-27 16:21:341796void AutomationProvider::OpenNewBrowserWindow(bool show,
[email protected]14c0a032009-04-13 18:15:141797 IPC::Message* reply_message) {
[email protected]982921f12009-10-27 21:43:531798 OpenNewBrowserWindowOfType(static_cast<int>(Browser::TYPE_NORMAL), show,
1799 reply_message);
1800}
1801
1802void AutomationProvider::OpenNewBrowserWindowOfType(
1803 int type, bool show, IPC::Message* reply_message) {
[email protected]14c0a032009-04-13 18:15:141804 new BrowserOpenedNotificationObserver(this, reply_message);
initial.commit09911bf2008-07-26 23:55:291805 // We may have no current browser windows open so don't rely on
1806 // asking an existing browser to execute the IDC_NEWWINDOW command
[email protected]982921f12009-10-27 21:43:531807 Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_);
1808 browser->CreateBrowserWindow();
[email protected]15952e462008-11-14 00:29:051809 browser->AddBlankTab(true);
[email protected]3683cbb2009-04-09 21:46:151810 if (show)
[email protected]15952e462008-11-14 00:29:051811 browser->window()->Show();
initial.commit09911bf2008-07-26 23:55:291812}
1813
[email protected]71f65dd2009-02-11 19:14:561814void AutomationProvider::GetWindowForBrowser(int browser_handle,
1815 bool* success,
1816 int* handle) {
1817 *success = false;
1818 *handle = 0;
initial.commit09911bf2008-07-26 23:55:291819
1820 if (browser_tracker_->ContainsHandle(browser_handle)) {
1821 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]0e9f4ee2009-04-08 01:44:201822 gfx::NativeWindow win = browser->window()->GetNativeHandle();
initial.commit09911bf2008-07-26 23:55:291823 // Add() returns the existing handle for the resource if any.
[email protected]0e9f4ee2009-04-08 01:44:201824 *handle = window_tracker_->Add(win);
[email protected]71f65dd2009-02-11 19:14:561825 *success = true;
initial.commit09911bf2008-07-26 23:55:291826 }
initial.commit09911bf2008-07-26 23:55:291827}
1828
initial.commit09911bf2008-07-26 23:55:291829void AutomationProvider::GetAutocompleteEditForBrowser(
[email protected]71f65dd2009-02-11 19:14:561830 int browser_handle,
1831 bool* success,
1832 int* autocomplete_edit_handle) {
1833 *success = false;
1834 *autocomplete_edit_handle = 0;
initial.commit09911bf2008-07-26 23:55:291835
1836 if (browser_tracker_->ContainsHandle(browser_handle)) {
1837 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]13869dd2009-05-05 00:40:061838 LocationBar* loc_bar = browser->window()->GetLocationBar();
1839 AutocompleteEditView* edit_view = loc_bar->location_entry();
initial.commit09911bf2008-07-26 23:55:291840 // Add() returns the existing handle for the resource if any.
[email protected]71f65dd2009-02-11 19:14:561841 *autocomplete_edit_handle = autocomplete_edit_tracker_->Add(edit_view);
1842 *success = true;
initial.commit09911bf2008-07-26 23:55:291843 }
initial.commit09911bf2008-07-26 23:55:291844}
initial.commit09911bf2008-07-26 23:55:291845
[email protected]71f65dd2009-02-11 19:14:561846void AutomationProvider::ShowInterstitialPage(int tab_handle,
1847 const std::string& html_text,
1848 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291849 if (tab_tracker_->ContainsHandle(tab_handle)) {
1850 NavigationController* controller = tab_tracker_->GetResource(tab_handle);
[email protected]7f0005a2009-04-15 03:25:111851 TabContents* tab_contents = controller->tab_contents();
[email protected]965524b2009-04-04 21:32:401852
[email protected]7dad3d5f2010-03-04 00:27:011853 AddNavigationStatusListener(controller, reply_message, 1, false);
[email protected]965524b2009-04-04 21:32:401854 AutomationInterstitialPage* interstitial =
[email protected]57c6a652009-05-04 07:58:341855 new AutomationInterstitialPage(tab_contents,
[email protected]965524b2009-04-04 21:32:401856 GURL("about:interstitial"),
1857 html_text);
1858 interstitial->Show();
1859 return;
initial.commit09911bf2008-07-26 23:55:291860 }
[email protected]71f65dd2009-02-11 19:14:561861
[email protected]457f5cf2009-08-18 16:37:521862 AutomationMsg_ShowInterstitialPage::WriteReplyParams(
1863 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
[email protected]71f65dd2009-02-11 19:14:561864 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291865}
1866
[email protected]71f65dd2009-02-11 19:14:561867void AutomationProvider::HideInterstitialPage(int tab_handle,
1868 bool* success) {
1869 *success = false;
[email protected]57c6a652009-05-04 07:58:341870 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, NULL);
1871 if (tab_contents && tab_contents->interstitial_page()) {
1872 tab_contents->interstitial_page()->DontProceed();
[email protected]71f65dd2009-02-11 19:14:561873 *success = true;
initial.commit09911bf2008-07-26 23:55:291874 }
initial.commit09911bf2008-07-26 23:55:291875}
1876
[email protected]71f65dd2009-02-11 19:14:561877void AutomationProvider::CloseTab(int tab_handle,
1878 bool wait_until_closed,
1879 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291880 if (tab_tracker_->ContainsHandle(tab_handle)) {
1881 NavigationController* controller = tab_tracker_->GetResource(tab_handle);
1882 int index;
1883 Browser* browser = Browser::GetBrowserForController(controller, &index);
1884 DCHECK(browser);
[email protected]1c58a5c2009-05-21 18:47:141885 new TabClosedNotificationObserver(this, wait_until_closed, reply_message);
[email protected]7f0005a2009-04-15 03:25:111886 browser->CloseContents(controller->tab_contents());
[email protected]de246f52009-02-25 18:25:451887 return;
initial.commit09911bf2008-07-26 23:55:291888 }
[email protected]de246f52009-02-25 18:25:451889
1890 AutomationMsg_CloseTab::WriteReplyParams(reply_message, false);
[email protected]58f622a62009-10-04 01:17:551891 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:291892}
1893
[email protected]71f65dd2009-02-11 19:14:561894void AutomationProvider::CloseBrowser(int browser_handle,
1895 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291896 if (browser_tracker_->ContainsHandle(browser_handle)) {
1897 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]71f65dd2009-02-11 19:14:561898 new BrowserClosedNotificationObserver(browser, this,
[email protected]71f65dd2009-02-11 19:14:561899 reply_message);
[email protected]f3e99e32008-07-30 04:48:391900 browser->window()->Close();
initial.commit09911bf2008-07-26 23:55:291901 } else {
1902 NOTREACHED();
1903 }
1904}
1905
[email protected]71f65dd2009-02-11 19:14:561906void AutomationProvider::CloseBrowserAsync(int browser_handle) {
1907 if (browser_tracker_->ContainsHandle(browser_handle)) {
1908 Browser* browser = browser_tracker_->GetResource(browser_handle);
1909 browser->window()->Close();
1910 } else {
1911 NOTREACHED();
1912 }
1913}
1914
[email protected]71f65dd2009-02-11 19:14:561915void AutomationProvider::NavigateInExternalTab(
[email protected]b36a9f92009-10-19 17:34:571916 int handle, const GURL& url, const GURL& referrer,
[email protected]71f65dd2009-02-11 19:14:561917 AutomationMsg_NavigationResponseValues* status) {
1918 *status = AUTOMATION_MSG_NAVIGATION_ERROR;
initial.commit09911bf2008-07-26 23:55:291919
1920 if (tab_tracker_->ContainsHandle(handle)) {
1921 NavigationController* tab = tab_tracker_->GetResource(handle);
[email protected]b36a9f92009-10-19 17:34:571922 tab->LoadURL(url, referrer, PageTransition::TYPED);
[email protected]71f65dd2009-02-11 19:14:561923 *status = AUTOMATION_MSG_NAVIGATION_SUCCESS;
initial.commit09911bf2008-07-26 23:55:291924 }
initial.commit09911bf2008-07-26 23:55:291925}
1926
[email protected]4150ef02009-08-19 23:14:261927void AutomationProvider::NavigateExternalTabAtIndex(
1928 int handle, int navigation_index,
1929 AutomationMsg_NavigationResponseValues* status) {
1930 *status = AUTOMATION_MSG_NAVIGATION_ERROR;
1931
1932 if (tab_tracker_->ContainsHandle(handle)) {
1933 NavigationController* tab = tab_tracker_->GetResource(handle);
1934 tab->GoToIndex(navigation_index);
1935 *status = AUTOMATION_MSG_NAVIGATION_SUCCESS;
1936 }
1937}
1938
[email protected]71f65dd2009-02-11 19:14:561939void AutomationProvider::WaitForTabToBeRestored(int tab_handle,
1940 IPC::Message* reply_message) {
1941 if (tab_tracker_->ContainsHandle(tab_handle)) {
1942 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
1943 restore_tracker_.reset(
[email protected]1c58a5c2009-05-21 18:47:141944 new NavigationControllerRestoredObserver(this, tab, reply_message));
[email protected]71f65dd2009-02-11 19:14:561945 }
1946}
1947
[email protected]71f65dd2009-02-11 19:14:561948void AutomationProvider::GetSecurityState(int handle, bool* success,
1949 SecurityStyle* security_style,
1950 int* ssl_cert_status,
1951 int* mixed_content_status) {
initial.commit09911bf2008-07-26 23:55:291952 if (tab_tracker_->ContainsHandle(handle)) {
1953 NavigationController* tab = tab_tracker_->GetResource(handle);
1954 NavigationEntry* entry = tab->GetActiveEntry();
[email protected]71f65dd2009-02-11 19:14:561955 *success = true;
1956 *security_style = entry->ssl().security_style();
1957 *ssl_cert_status = entry->ssl().cert_status();
1958 *mixed_content_status = entry->ssl().content_status();
initial.commit09911bf2008-07-26 23:55:291959 } else {
[email protected]71f65dd2009-02-11 19:14:561960 *success = false;
1961 *security_style = SECURITY_STYLE_UNKNOWN;
1962 *ssl_cert_status = 0;
1963 *mixed_content_status = 0;
initial.commit09911bf2008-07-26 23:55:291964 }
1965}
1966
[email protected]71f65dd2009-02-11 19:14:561967void AutomationProvider::GetPageType(int handle, bool* success,
1968 NavigationEntry::PageType* page_type) {
initial.commit09911bf2008-07-26 23:55:291969 if (tab_tracker_->ContainsHandle(handle)) {
1970 NavigationController* tab = tab_tracker_->GetResource(handle);
1971 NavigationEntry* entry = tab->GetActiveEntry();
[email protected]71f65dd2009-02-11 19:14:561972 *page_type = entry->page_type();
1973 *success = true;
initial.commit09911bf2008-07-26 23:55:291974 // In order to return the proper result when an interstitial is shown and
[email protected]57c6a652009-05-04 07:58:341975 // no navigation entry were created for it we need to ask the TabContents.
[email protected]71f65dd2009-02-11 19:14:561976 if (*page_type == NavigationEntry::NORMAL_PAGE &&
[email protected]57c6a652009-05-04 07:58:341977 tab->tab_contents()->showing_interstitial_page())
[email protected]71f65dd2009-02-11 19:14:561978 *page_type = NavigationEntry::INTERSTITIAL_PAGE;
initial.commit09911bf2008-07-26 23:55:291979 } else {
[email protected]71f65dd2009-02-11 19:14:561980 *success = false;
1981 *page_type = NavigationEntry::NORMAL_PAGE;
initial.commit09911bf2008-07-26 23:55:291982 }
1983}
1984
[email protected]84abba62009-10-07 17:01:441985void AutomationProvider::GetMetricEventDuration(const std::string& event_name,
1986 int* duration_ms) {
1987 *duration_ms = metric_event_duration_observer_->GetEventDurationMs(
1988 event_name);
1989}
1990
[email protected]71f65dd2009-02-11 19:14:561991void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed,
1992 IPC::Message* reply_message) {
initial.commit09911bf2008-07-26 23:55:291993 if (tab_tracker_->ContainsHandle(handle)) {
1994 NavigationController* tab = tab_tracker_->GetResource(handle);
1995 NavigationEntry* entry = tab->GetActiveEntry();
[email protected]1e5645ff2008-08-27 18:09:071996 if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) {
[email protected]965524b2009-04-04 21:32:401997 TabContents* tab_contents = tab->tab_contents();
[email protected]cbab76d2008-10-13 22:42:471998 InterstitialPage* ssl_blocking_page =
[email protected]57c6a652009-05-04 07:58:341999 InterstitialPage::GetInterstitialPage(tab_contents);
initial.commit09911bf2008-07-26 23:55:292000 if (ssl_blocking_page) {
2001 if (proceed) {
[email protected]7dad3d5f2010-03-04 00:27:012002 AddNavigationStatusListener(tab, reply_message, 1, false);
[email protected]71f65dd2009-02-11 19:14:562003 ssl_blocking_page->Proceed();
initial.commit09911bf2008-07-26 23:55:292004 return;
2005 }
2006 ssl_blocking_page->DontProceed();
[email protected]457f5cf2009-08-18 16:37:522007 AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams(
2008 reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS);
[email protected]71f65dd2009-02-11 19:14:562009 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292010 return;
2011 }
2012 }
2013 }
2014 // We failed.
[email protected]457f5cf2009-08-18 16:37:522015 AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams(
2016 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
[email protected]71f65dd2009-02-11 19:14:562017 Send(reply_message);
initial.commit09911bf2008-07-26 23:55:292018}
2019
[email protected]71f65dd2009-02-11 19:14:562020void AutomationProvider::BringBrowserToFront(int browser_handle,
2021 bool* success) {
initial.commit09911bf2008-07-26 23:55:292022 if (browser_tracker_->ContainsHandle(browser_handle)) {
2023 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]cd7ffc22008-11-12 00:26:062024 browser->window()->Activate();
[email protected]71f65dd2009-02-11 19:14:562025 *success = true;
initial.commit09911bf2008-07-26 23:55:292026 } else {
[email protected]71f65dd2009-02-11 19:14:562027 *success = false;
initial.commit09911bf2008-07-26 23:55:292028 }
2029}
2030
[email protected]71f65dd2009-02-11 19:14:562031void AutomationProvider::IsPageMenuCommandEnabled(int browser_handle,
2032 int message_num,
2033 bool* menu_item_enabled) {
initial.commit09911bf2008-07-26 23:55:292034 if (browser_tracker_->ContainsHandle(browser_handle)) {
2035 Browser* browser = browser_tracker_->GetResource(browser_handle);
[email protected]71f65dd2009-02-11 19:14:562036 *menu_item_enabled =
[email protected]1fc025202009-01-20 23:03:142037 browser->command_updater()->IsCommandEnabled(message_num);
initial.commit09911bf2008-07-26 23:55:292038 } else {
[email protected]71f65dd2009-02-11 19:14:562039 *menu_item_enabled = false;
initial.commit09911bf2008-07-26 23:55:292040 }
2041}
2042
[email protected]71f65dd2009-02-11 19:14:562043void AutomationProvider::PrintNow(int tab_handle,
2044 IPC::Message* reply_message) {
[email protected]5ae5bed2009-08-21 18:52:442045#if defined(OS_WIN)
[email protected]20e93d12008-08-28 16:31:572046 NavigationController* tab = NULL;
[email protected]57c6a652009-05-04 07:58:342047 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab);
2048 if (tab_contents) {
initial.commit09911bf2008-07-26 23:55:292049 FindAndActivateTab(tab);
[email protected]20e93d12008-08-28 16:31:572050 notification_observer_list_.AddObserver(
[email protected]1c58a5c2009-05-21 18:47:142051 new DocumentPrintedNotificationObserver(this, reply_message));
[email protected]57c6a652009-05-04 07:58:342052 if (tab_contents->PrintNow())
[email protected]20e93d12008-08-28 16:31:572053 return;
initial.commit09911bf2008-07-26 23:55:292054 }
[email protected]71f65dd2009-02-11 19:14:562055 AutomationMsg_PrintNow::WriteReplyParams(reply_message, false);
2056 Send(reply_message);
[email protected]5ae5bed2009-08-21 18:52:442057#else
2058 // TODO(port): Remove once DocumentPrintedNotificationObserver is implemented.
2059 NOTIMPLEMENTED();
2060#endif // defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:292061}
[email protected]d301c952009-07-13 15:02:412062
[email protected]71f65dd2009-02-11 19:14:562063void AutomationProvider::SavePage(int tab_handle,
[email protected]828cabe2009-09-26 22:47:112064 const FilePath& file_name,
2065 const FilePath& dir_path,
[email protected]71f65dd2009-02-11 19:14:562066 int type,
2067 bool* success) {
initial.commit09911bf2008-07-26 23:55:292068 if (!tab_tracker_->ContainsHandle(tab_handle)) {
[email protected]71f65dd2009-02-11 19:14:562069 *success = false;
initial.commit09911bf2008-07-26 23:55:292070 return;
2071 }
2072
2073 NavigationController* nav = tab_tracker_->GetResource(tab_handle);
2074 Browser* browser = FindAndActivateTab(nav);
2075 DCHECK(browser);
[email protected]1fc025202009-01-20 23:03:142076 if (!browser->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)) {
[email protected]71f65dd2009-02-11 19:14:562077 *success = false;
initial.commit09911bf2008-07-26 23:55:292078 return;
2079 }
2080
initial.commit09911bf2008-07-26 23:55:292081 SavePackage::SavePackageType save_type =
2082 static_cast<SavePackage::SavePackageType>(type);
2083 DCHECK(save_type >= SavePackage::SAVE_AS_ONLY_HTML &&
2084 save_type <= SavePackage::SAVE_AS_COMPLETE_HTML);
[email protected]57c6a652009-05-04 07:58:342085 nav->tab_contents()->SavePage(file_name, dir_path, save_type);
initial.commit09911bf2008-07-26 23:55:292086
[email protected]71f65dd2009-02-11 19:14:562087 *success = true;
initial.commit09911bf2008-07-26 23:55:292088}
2089
[email protected]71f65dd2009-02-11 19:14:562090void AutomationProvider::GetAutocompleteEditText(int autocomplete_edit_handle,
2091 bool* success,
2092 std::wstring* text) {
2093 *success = false;
initial.commit09911bf2008-07-26 23:55:292094 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]71f65dd2009-02-11 19:14:562095 *text = autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)->
[email protected]81c21222008-09-10 19:35:522096 GetText();
[email protected]71f65dd2009-02-11 19:14:562097 *success = true;
initial.commit09911bf2008-07-26 23:55:292098 }
initial.commit09911bf2008-07-26 23:55:292099}
2100
[email protected]71f65dd2009-02-11 19:14:562101void AutomationProvider::SetAutocompleteEditText(int autocomplete_edit_handle,
2102 const std::wstring& text,
2103 bool* success) {
2104 *success = false;
initial.commit09911bf2008-07-26 23:55:292105 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]81c21222008-09-10 19:35:522106 autocomplete_edit_tracker_->GetResource(autocomplete_edit_handle)->
2107 SetUserText(text);
[email protected]71f65dd2009-02-11 19:14:562108 *success = true;
initial.commit09911bf2008-07-26 23:55:292109 }
initial.commit09911bf2008-07-26 23:55:292110}
2111
2112void AutomationProvider::AutocompleteEditGetMatches(
[email protected]71f65dd2009-02-11 19:14:562113 int autocomplete_edit_handle,
2114 bool* success,
2115 std::vector<AutocompleteMatchData>* matches) {
2116 *success = false;
initial.commit09911bf2008-07-26 23:55:292117 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]8deeb952008-10-09 18:21:272118 const AutocompleteResult& result = autocomplete_edit_tracker_->
2119 GetResource(autocomplete_edit_handle)->model()->result();
2120 for (AutocompleteResult::const_iterator i = result.begin();
2121 i != result.end(); ++i)
[email protected]71f65dd2009-02-11 19:14:562122 matches->push_back(AutocompleteMatchData(*i));
2123 *success = true;
initial.commit09911bf2008-07-26 23:55:292124 }
initial.commit09911bf2008-07-26 23:55:292125}
2126
2127void AutomationProvider::AutocompleteEditIsQueryInProgress(
[email protected]71f65dd2009-02-11 19:14:562128 int autocomplete_edit_handle,
2129 bool* success,
2130 bool* query_in_progress) {
2131 *success = false;
2132 *query_in_progress = false;
initial.commit09911bf2008-07-26 23:55:292133 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
[email protected]71f65dd2009-02-11 19:14:562134 *query_in_progress = autocomplete_edit_tracker_->
[email protected]81c21222008-09-10 19:35:522135 GetResource(autocomplete_edit_handle)->model()->query_in_progress();
[email protected]71f65dd2009-02-11 19:14:562136 *success = true;
initial.commit09911bf2008-07-26 23:55:292137 }
initial.commit09911bf2008-07-26 23:55:292138}
2139
[email protected]63514af2010-03-30 17:17:232140#if !defined(OS_MACOSX)
[email protected]28790922009-03-09 19:48:372141void AutomationProvider::OnMessageFromExternalHost(int handle,
2142 const std::string& message,
2143 const std::string& origin,
2144 const std::string& target) {
[email protected]f7a68432009-07-29 23:18:192145 RenderViewHost* view_host = GetViewForTab(handle);
2146 if (!view_host) {
2147 return;
[email protected]fa83e762008-08-15 21:41:392148 }
[email protected]f7a68432009-07-29 23:18:192149
2150 if (AutomationExtensionFunction::InterceptMessageFromExternalHost(
2151 view_host, message, origin, target)) {
2152 // Message was diverted.
2153 return;
2154 }
2155
2156 if (ExtensionPortContainer::InterceptMessageFromExternalHost(message,
2157 origin, target, this, view_host, handle)) {
2158 // Message was diverted.
2159 return;
2160 }
2161
2162 if (InterceptBrowserEventMessageFromExternalHost(message, origin, target)) {
2163 // Message was diverted.
2164 return;
2165 }
2166
2167 view_host->ForwardMessageFromExternalHost(message, origin, target);
[email protected]fa83e762008-08-15 21:41:392168}
[email protected]a9024892009-06-16 23:13:552169
2170bool AutomationProvider::InterceptBrowserEventMessageFromExternalHost(
2171 const std::string& message, const std::string& origin,
2172 const std::string& target) {
2173 if (target !=
2174 extension_automation_constants::kAutomationBrowserEventRequestTarget)
2175 return false;
2176
2177 if (origin != extension_automation_constants::kAutomationOrigin) {
2178 LOG(WARNING) << "Wrong origin on automation browser event " << origin;
2179 return false;
2180 }
2181
2182 // The message is a JSON-encoded array with two elements, both strings. The
2183 // first is the name of the event to dispatch. The second is a JSON-encoding
2184 // of the arguments specific to that event.
[email protected]93d49d72009-10-23 20:00:202185 scoped_ptr<Value> message_value(base::JSONReader::Read(message, false));
[email protected]a9024892009-06-16 23:13:552186 if (!message_value.get() || !message_value->IsType(Value::TYPE_LIST)) {
2187 LOG(WARNING) << "Invalid browser event specified through automation";
2188 return false;
2189 }
2190
2191 const ListValue* args = static_cast<const ListValue*>(message_value.get());
2192
2193 std::string event_name;
2194 if (!args->GetString(0, &event_name)) {
2195 LOG(WARNING) << "No browser event name specified through automation";
2196 return false;
2197 }
2198
2199 std::string json_args;
2200 if (!args->GetString(1, &json_args)) {
2201 LOG(WARNING) << "No browser event args specified through automation";
2202 return false;
2203 }
2204
[email protected]7120f132009-07-20 21:05:372205 if (profile()->GetExtensionMessageService()) {
[email protected]db7331a2010-02-25 22:10:502206 profile()->GetExtensionMessageService()->DispatchEventToRenderers(
2207 event_name, json_args, profile()->IsOffTheRecord());
[email protected]7120f132009-07-20 21:05:372208 }
[email protected]a9024892009-06-16 23:13:552209
2210 return true;
2211}
[email protected]5ae5bed2009-08-21 18:52:442212#endif // !defined(OS_MACOSX)
[email protected]fa83e762008-08-15 21:41:392213
[email protected]57c6a652009-05-04 07:58:342214TabContents* AutomationProvider::GetTabContentsForHandle(
[email protected]20e93d12008-08-28 16:31:572215 int handle, NavigationController** tab) {
[email protected]20e93d12008-08-28 16:31:572216 if (tab_tracker_->ContainsHandle(handle)) {
2217 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
[email protected]57c6a652009-05-04 07:58:342218 if (tab)
2219 *tab = nav_controller;
2220 return nav_controller->tab_contents();
[email protected]20e93d12008-08-28 16:31:572221 }
[email protected]57c6a652009-05-04 07:58:342222 return NULL;
[email protected]20e93d12008-08-28 16:31:572223}
2224
initial.commit09911bf2008-07-26 23:55:292225TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
2226 : AutomationProvider(profile) {
2227 BrowserList::AddObserver(this);
[email protected]1c58a5c2009-05-21 18:47:142228 registrar_.Add(this, NotificationType::SESSION_END,
2229 NotificationService::AllSources());
initial.commit09911bf2008-07-26 23:55:292230}
2231
2232TestingAutomationProvider::~TestingAutomationProvider() {
initial.commit09911bf2008-07-26 23:55:292233 BrowserList::RemoveObserver(this);
2234}
2235
2236void TestingAutomationProvider::OnChannelError() {
[email protected]a9324442009-10-12 04:32:142237 BrowserList::CloseAllBrowsersAndExit();
initial.commit09911bf2008-07-26 23:55:292238 AutomationProvider::OnChannelError();
2239}
2240
2241void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) {
2242 // For backwards compatibility with the testing automation interface, we
2243 // want the automation provider (and hence the process) to go away when the
2244 // last browser goes away.
2245 if (BrowserList::size() == 1) {
[email protected]4f3dc372009-02-24 00:10:292246 // If you change this, update Observer for NotificationType::SESSION_END
2247 // below.
[email protected]295039bd2008-08-15 04:32:572248 MessageLoop::current()->PostTask(FROM_HERE,
2249 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
initial.commit09911bf2008-07-26 23:55:292250 }
2251}
2252
2253void TestingAutomationProvider::Observe(NotificationType type,
2254 const NotificationSource& source,
2255 const NotificationDetails& details) {
[email protected]bfd04a62009-02-01 18:16:562256 DCHECK(type == NotificationType::SESSION_END);
initial.commit09911bf2008-07-26 23:55:292257 // OnBrowserRemoving does a ReleaseLater. When session end is received we exit
2258 // before the task runs resulting in this object not being deleted. This
2259 // Release balance out the Release scheduled by OnBrowserRemoving.
2260 Release();
2261}
[email protected]295039bd2008-08-15 04:32:572262
2263void TestingAutomationProvider::OnRemoveProvider() {
2264 AutomationProviderList::GetInstance()->RemoveProvider(this);
2265}
[email protected]8a3422c92008-09-24 17:42:422266
[email protected]816633a2009-11-11 21:48:182267void AutomationProvider::GetInfoBarCount(int handle, int* count) {
[email protected]71f65dd2009-02-11 19:14:562268 *count = -1; // -1 means error.
[email protected]8a3422c92008-09-24 17:42:422269 if (tab_tracker_->ContainsHandle(handle)) {
2270 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
[email protected]eb9ba192008-12-02 02:41:342271 if (nav_controller)
[email protected]7f0005a2009-04-15 03:25:112272 *count = nav_controller->tab_contents()->infobar_delegate_count();
[email protected]8a3422c92008-09-24 17:42:422273 }
[email protected]8a3422c92008-09-24 17:42:422274}
2275
[email protected]816633a2009-11-11 21:48:182276void AutomationProvider::ClickInfoBarAccept(int handle,
2277 int info_bar_index,
2278 bool wait_for_navigation,
2279 IPC::Message* reply_message) {
[email protected]8a3422c92008-09-24 17:42:422280 bool success = false;
2281 if (tab_tracker_->ContainsHandle(handle)) {
2282 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
2283 if (nav_controller) {
[email protected]7f0005a2009-04-15 03:25:112284 int count = nav_controller->tab_contents()->infobar_delegate_count();
[email protected]8a3422c92008-09-24 17:42:422285 if (info_bar_index >= 0 && info_bar_index < count) {
2286 if (wait_for_navigation) {
[email protected]7dad3d5f2010-03-04 00:27:012287 AddNavigationStatusListener(nav_controller, reply_message, 1, false);
[email protected]8a3422c92008-09-24 17:42:422288 }
[email protected]eb9ba192008-12-02 02:41:342289 InfoBarDelegate* delegate =
[email protected]7f0005a2009-04-15 03:25:112290 nav_controller->tab_contents()->GetInfoBarDelegateAt(
[email protected]eb9ba192008-12-02 02:41:342291 info_bar_index);
2292 if (delegate->AsConfirmInfoBarDelegate())
2293 delegate->AsConfirmInfoBarDelegate()->Accept();
[email protected]8a3422c92008-09-24 17:42:422294 success = true;
2295 }
2296 }
[email protected]4f3dc372009-02-24 00:10:292297 }
[email protected]58f622a62009-10-04 01:17:552298
2299 // This "!wait_for_navigation || !success condition" logic looks suspicious.
2300 // It will send a failure message when success is true but
2301 // |wait_for_navigation| is false.
2302 // TODO(phajdan.jr): investgate whether the reply param (currently
2303 // AUTOMATION_MSG_NAVIGATION_ERROR) should depend on success.
[email protected]8a3422c92008-09-24 17:42:422304 if (!wait_for_navigation || !success)
[email protected]816633a2009-11-11 21:48:182305 AutomationMsg_ClickInfoBarAccept::WriteReplyParams(
[email protected]457f5cf2009-08-18 16:37:522306 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
[email protected]8a3422c92008-09-24 17:42:422307}
2308
[email protected]71f65dd2009-02-11 19:14:562309void AutomationProvider::GetLastNavigationTime(int handle,
2310 int64* last_navigation_time) {
[email protected]8a3422c92008-09-24 17:42:422311 Time time = tab_tracker_->GetLastNavigationTime(handle);
[email protected]71f65dd2009-02-11 19:14:562312 *last_navigation_time = time.ToInternalValue();
[email protected]8a3422c92008-09-24 17:42:422313}
2314
[email protected]71f65dd2009-02-11 19:14:562315void AutomationProvider::WaitForNavigation(int handle,
2316 int64 last_navigation_time,
2317 IPC::Message* reply_message) {
[email protected]5fa7acd2009-09-25 20:04:252318 NavigationController* controller = tab_tracker_->GetResource(handle);
[email protected]8a3422c92008-09-24 17:42:422319 Time time = tab_tracker_->GetLastNavigationTime(handle);
[email protected]5fa7acd2009-09-25 20:04:252320
[email protected]8a3422c92008-09-24 17:42:422321 if (time.ToInternalValue() > last_navigation_time || !controller) {
[email protected]71f65dd2009-02-11 19:14:562322 AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message,
[email protected]457f5cf2009-08-18 16:37:522323 controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR :
2324 AUTOMATION_MSG_NAVIGATION_SUCCESS);
[email protected]58f622a62009-10-04 01:17:552325 Send(reply_message);
[email protected]4f3dc372009-02-24 00:10:292326 return;
[email protected]8a3422c92008-09-24 17:42:422327 }
2328
[email protected]7dad3d5f2010-03-04 00:27:012329 AddNavigationStatusListener(controller, reply_message, 1, true);
[email protected]8a3422c92008-09-24 17:42:422330}
2331
[email protected]71f65dd2009-02-11 19:14:562332void AutomationProvider::SetIntPreference(int handle,
[email protected]97fa6ce32008-12-19 01:48:162333 const std::wstring& name,
[email protected]71f65dd2009-02-11 19:14:562334 int value,
2335 bool* success) {
2336 *success = false;
[email protected]8a3422c92008-09-24 17:42:422337 if (browser_tracker_->ContainsHandle(handle)) {
2338 Browser* browser = browser_tracker_->GetResource(handle);
2339 browser->profile()->GetPrefs()->SetInteger(name.c_str(), value);
[email protected]71f65dd2009-02-11 19:14:562340 *success = true;
[email protected]8a3422c92008-09-24 17:42:422341 }
[email protected]8a3422c92008-09-24 17:42:422342}
[email protected]97fa6ce32008-12-19 01:48:162343
[email protected]71f65dd2009-02-11 19:14:562344void AutomationProvider::SetStringPreference(int handle,
[email protected]97fa6ce32008-12-19 01:48:162345 const std::wstring& name,
[email protected]71f65dd2009-02-11 19:14:562346 const std::wstring& value,
2347 bool* success) {
2348 *success = false;
[email protected]97fa6ce32008-12-19 01:48:162349 if (browser_tracker_->ContainsHandle(handle)) {
2350 Browser* browser = browser_tracker_->GetResource(handle);
2351 browser->profile()->GetPrefs()->SetString(name.c_str(), value);
[email protected]71f65dd2009-02-11 19:14:562352 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162353 }
[email protected]97fa6ce32008-12-19 01:48:162354}
2355
[email protected]71f65dd2009-02-11 19:14:562356void AutomationProvider::GetBooleanPreference(int handle,
2357 const std::wstring& name,
[email protected]b8f48d12009-11-09 20:14:362358 bool* success,
2359 bool* value) {
[email protected]71f65dd2009-02-11 19:14:562360 *success = false;
2361 *value = false;
[email protected]97fa6ce32008-12-19 01:48:162362 if (browser_tracker_->ContainsHandle(handle)) {
2363 Browser* browser = browser_tracker_->GetResource(handle);
[email protected]71f65dd2009-02-11 19:14:562364 *value = browser->profile()->GetPrefs()->GetBoolean(name.c_str());
2365 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162366 }
[email protected]97fa6ce32008-12-19 01:48:162367}
2368
[email protected]71f65dd2009-02-11 19:14:562369void AutomationProvider::SetBooleanPreference(int handle,
[email protected]97fa6ce32008-12-19 01:48:162370 const std::wstring& name,
[email protected]71f65dd2009-02-11 19:14:562371 bool value,
2372 bool* success) {
2373 *success = false;
[email protected]97fa6ce32008-12-19 01:48:162374 if (browser_tracker_->ContainsHandle(handle)) {
2375 Browser* browser = browser_tracker_->GetResource(handle);
2376 browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value);
[email protected]71f65dd2009-02-11 19:14:562377 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162378 }
[email protected]97fa6ce32008-12-19 01:48:162379}
2380
2381// Gets the current used encoding name of the page in the specified tab.
[email protected]71f65dd2009-02-11 19:14:562382void AutomationProvider::GetPageCurrentEncoding(
[email protected]41fc0322009-09-04 22:23:402383 int tab_handle, std::string* current_encoding) {
[email protected]97fa6ce32008-12-19 01:48:162384 if (tab_tracker_->ContainsHandle(tab_handle)) {
2385 NavigationController* nav = tab_tracker_->GetResource(tab_handle);
2386 Browser* browser = FindAndActivateTab(nav);
2387 DCHECK(browser);
2388
[email protected]57c6a652009-05-04 07:58:342389 if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU))
2390 *current_encoding = nav->tab_contents()->encoding();
[email protected]97fa6ce32008-12-19 01:48:162391 }
[email protected]97fa6ce32008-12-19 01:48:162392}
2393
[email protected]b8f48d12009-11-09 20:14:362394// Gets the current used encoding name of the page in the specified tab.
[email protected]71f65dd2009-02-11 19:14:562395void AutomationProvider::OverrideEncoding(int tab_handle,
[email protected]41fc0322009-09-04 22:23:402396 const std::string& encoding_name,
[email protected]71f65dd2009-02-11 19:14:562397 bool* success) {
2398 *success = false;
[email protected]de246f52009-02-25 18:25:452399#if defined(OS_WIN)
[email protected]97fa6ce32008-12-19 01:48:162400 if (tab_tracker_->ContainsHandle(tab_handle)) {
2401 NavigationController* nav = tab_tracker_->GetResource(tab_handle);
[email protected]2f2afba2010-04-01 01:53:192402 if (!nav)
2403 return;
[email protected]97fa6ce32008-12-19 01:48:162404 Browser* browser = FindAndActivateTab(nav);
[email protected]97fa6ce32008-12-19 01:48:162405
[email protected]2f2afba2010-04-01 01:53:192406 // If the browser has UI, simulate what a user would do.
2407 // Activate the tab and then click the encoding menu.
2408 if (browser &&
2409 browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) {
[email protected]97fa6ce32008-12-19 01:48:162410 int selected_encoding_id =
2411 CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name);
2412 if (selected_encoding_id) {
2413 browser->OverrideEncoding(selected_encoding_id);
[email protected]71f65dd2009-02-11 19:14:562414 *success = true;
[email protected]97fa6ce32008-12-19 01:48:162415 }
[email protected]2f2afba2010-04-01 01:53:192416 } else {
2417 // There is no UI, Chrome probably runs as Chrome-Frame mode.
2418 // Try to get TabContents and call its override_encoding method.
2419 TabContents* contents = nav->tab_contents();
2420 if (!contents)
2421 return;
2422 const std::string selected_encoding =
2423 CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding_name);
2424 if (selected_encoding.empty())
2425 return;
2426 contents->SetOverrideEncoding(selected_encoding);
[email protected]97fa6ce32008-12-19 01:48:162427 }
2428 }
[email protected]de246f52009-02-25 18:25:452429#else
2430 // TODO(port): Enable when encoding-related parts of Browser are ported.
2431 NOTIMPLEMENTED();
2432#endif
[email protected]97fa6ce32008-12-19 01:48:162433}
[email protected]5bcdb312009-01-07 21:43:202434
[email protected]4d434a1a2009-02-11 21:06:572435void AutomationProvider::SavePackageShouldPromptUser(bool should_prompt) {
[email protected]5bcdb312009-01-07 21:43:202436 SavePackage::SetShouldPromptUser(should_prompt);
2437}
[email protected]87eab222009-03-13 00:47:452438
[email protected]66ba4932009-06-04 19:22:132439void AutomationProvider::GetBlockedPopupCount(int handle, int* count) {
2440 *count = -1; // -1 is the error code
2441 if (tab_tracker_->ContainsHandle(handle)) {
2442 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
2443 TabContents* tab_contents = nav_controller->tab_contents();
2444 if (tab_contents) {
2445 BlockedPopupContainer* container =
2446 tab_contents->blocked_popup_container();
2447 if (container) {
2448 *count = static_cast<int>(container->GetBlockedPopupCount());
2449 } else {
2450 // If we don't have a container, we don't have any blocked popups to
2451 // contain!
2452 *count = 0;
2453 }
2454 }
2455 }
2456}
[email protected]f7a68432009-07-29 23:18:192457
2458void AutomationProvider::SelectAll(int tab_handle) {
2459 RenderViewHost* view = GetViewForTab(tab_handle);
2460 if (!view) {
2461 NOTREACHED();
2462 return;
2463 }
2464
2465 view->SelectAll();
2466}
2467
2468void AutomationProvider::Cut(int tab_handle) {
2469 RenderViewHost* view = GetViewForTab(tab_handle);
2470 if (!view) {
2471 NOTREACHED();
2472 return;
2473 }
2474
2475 view->Cut();
2476}
2477
2478void AutomationProvider::Copy(int tab_handle) {
2479 RenderViewHost* view = GetViewForTab(tab_handle);
2480 if (!view) {
2481 NOTREACHED();
2482 return;
2483 }
2484
2485 view->Copy();
2486}
2487
2488void AutomationProvider::Paste(int tab_handle) {
2489 RenderViewHost* view = GetViewForTab(tab_handle);
2490 if (!view) {
2491 NOTREACHED();
2492 return;
2493 }
2494
2495 view->Paste();
2496}
2497
2498void AutomationProvider::ReloadAsync(int tab_handle) {
2499 if (tab_tracker_->ContainsHandle(tab_handle)) {
2500 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
2501 if (!tab) {
2502 NOTREACHED();
2503 return;
2504 }
2505
[email protected]106a0812010-03-18 00:15:122506 const bool check_for_repost = true;
2507 tab->Reload(check_for_repost);
[email protected]f7a68432009-07-29 23:18:192508 }
2509}
2510
2511void AutomationProvider::StopAsync(int tab_handle) {
2512 RenderViewHost* view = GetViewForTab(tab_handle);
2513 if (!view) {
[email protected]8b2b3312009-09-14 18:38:362514 // We tolerate StopAsync being called even before a view has been created.
2515 // So just log a warning instead of a NOTREACHED().
2516 DLOG(WARNING) << "StopAsync: no view for handle " << tab_handle;
[email protected]f7a68432009-07-29 23:18:192517 return;
2518 }
2519
2520 view->Stop();
2521}
2522
[email protected]1bb5f892009-10-06 01:44:572523void AutomationProvider::OnSetPageFontSize(int tab_handle,
2524 int font_size) {
2525 AutomationPageFontSize automation_font_size =
2526 static_cast<AutomationPageFontSize>(font_size);
2527
2528 if (automation_font_size < SMALLEST_FONT ||
2529 automation_font_size > LARGEST_FONT) {
2530 DLOG(ERROR) << "Invalid font size specified : "
2531 << font_size;
2532 return;
2533 }
2534
2535 if (tab_tracker_->ContainsHandle(tab_handle)) {
2536 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
2537 DCHECK(tab != NULL);
2538 if (tab && tab->tab_contents()) {
2539 DCHECK(tab->tab_contents()->profile() != NULL);
2540 tab->tab_contents()->profile()->GetPrefs()->SetInteger(
2541 prefs::kWebKitDefaultFontSize, font_size);
2542 }
2543 }
2544}
2545
[email protected]bc73b4e52010-03-26 04:16:202546void AutomationProvider::RemoveBrowsingData(int remove_mask) {
2547 BrowsingDataRemover* remover;
2548 remover = new BrowsingDataRemover(profile(),
2549 BrowsingDataRemover::EVERYTHING, // All time periods.
2550 base::Time());
2551 remover->Remove(remove_mask);
2552 // BrowsingDataRemover deletes itself.
2553}
[email protected]1bb5f892009-10-06 01:44:572554
[email protected]2949e90d2009-08-21 15:32:522555void AutomationProvider::WaitForBrowserWindowCountToBecome(
2556 int target_count, IPC::Message* reply_message) {
2557 if (static_cast<int>(BrowserList::size()) == target_count) {
2558 AutomationMsg_WaitForBrowserWindowCountToBecome::WriteReplyParams(
2559 reply_message, true);
2560 Send(reply_message);
2561 return;
2562 }
2563
2564 // Set up an observer (it will delete itself).
2565 new BrowserCountChangeNotificationObserver(target_count, this, reply_message);
2566}
2567
2568void AutomationProvider::WaitForAppModalDialogToBeShown(
2569 IPC::Message* reply_message) {
2570 if (Singleton<AppModalDialogQueue>()->HasActiveDialog()) {
2571 AutomationMsg_WaitForAppModalDialogToBeShown::WriteReplyParams(
2572 reply_message, true);
2573 Send(reply_message);
2574 return;
2575 }
2576
2577 // Set up an observer (it will delete itself).
2578 new AppModalDialogShownObserver(this, reply_message);
2579}
2580
[email protected]1126a1d32009-08-26 15:39:262581void AutomationProvider::GoBackBlockUntilNavigationsComplete(
2582 int handle, int number_of_navigations, IPC::Message* reply_message) {
2583 if (tab_tracker_->ContainsHandle(handle)) {
2584 NavigationController* tab = tab_tracker_->GetResource(handle);
2585 Browser* browser = FindAndActivateTab(tab);
2586 if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) {
[email protected]7dad3d5f2010-03-04 00:27:012587 AddNavigationStatusListener(tab, reply_message, number_of_navigations,
2588 false);
[email protected]1126a1d32009-08-26 15:39:262589 browser->GoBack(CURRENT_TAB);
2590 return;
2591 }
2592 }
2593
2594 AutomationMsg_GoBackBlockUntilNavigationsComplete::WriteReplyParams(
2595 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
2596 Send(reply_message);
2597}
2598
2599void AutomationProvider::GoForwardBlockUntilNavigationsComplete(
2600 int handle, int number_of_navigations, IPC::Message* reply_message) {
2601 if (tab_tracker_->ContainsHandle(handle)) {
2602 NavigationController* tab = tab_tracker_->GetResource(handle);
2603 Browser* browser = FindAndActivateTab(tab);
2604 if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) {
[email protected]7dad3d5f2010-03-04 00:27:012605 AddNavigationStatusListener(tab, reply_message, number_of_navigations,
2606 false);
[email protected]1126a1d32009-08-26 15:39:262607 browser->GoForward(CURRENT_TAB);
2608 return;
2609 }
2610 }
2611
2612 AutomationMsg_GoForwardBlockUntilNavigationsComplete::WriteReplyParams(
2613 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
2614 Send(reply_message);
2615}
2616
[email protected]f7a68432009-07-29 23:18:192617RenderViewHost* AutomationProvider::GetViewForTab(int tab_handle) {
2618 if (tab_tracker_->ContainsHandle(tab_handle)) {
2619 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
2620 if (!tab) {
2621 NOTREACHED();
2622 return NULL;
2623 }
2624
2625 TabContents* tab_contents = tab->tab_contents();
2626 if (!tab_contents) {
2627 NOTREACHED();
2628 return NULL;
2629 }
2630
2631 RenderViewHost* view_host = tab_contents->render_view_host();
2632 return view_host;
2633 }
2634
2635 return NULL;
2636}
[email protected]675595f2009-08-26 22:32:042637
2638void AutomationProvider::GetBrowserForWindow(int window_handle,
2639 bool* success,
2640 int* browser_handle) {
2641 *success = false;
2642 *browser_handle = 0;
2643
2644 gfx::NativeWindow window = window_tracker_->GetResource(window_handle);
2645 if (!window)
2646 return;
2647
2648 BrowserList::const_iterator iter = BrowserList::begin();
2649 for (;iter != BrowserList::end(); ++iter) {
2650 gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle();
2651 if (window == this_window) {
2652 // Add() returns the existing handle for the resource if any.
2653 *browser_handle = browser_tracker_->Add(*iter);
2654 *success = true;
2655 return;
2656 }
2657 }
2658}
[email protected]d11c8e92009-10-20 23:26:402659
2660void AutomationProvider::InstallExtension(const FilePath& crx_path,
2661 IPC::Message* reply_message) {
2662 ExtensionsService* service = profile_->GetExtensionsService();
2663 if (service) {
2664 // The observer will delete itself when done.
[email protected]790788ac2010-04-06 17:52:192665 new ExtensionInstallNotificationObserver(this,
2666 AutomationMsg_InstallExtension::ID,
2667 reply_message);
[email protected]d11c8e92009-10-20 23:26:402668
2669 const FilePath& install_dir = service->install_directory();
[email protected]6dfbbf82010-03-12 23:09:162670 scoped_refptr<CrxInstaller> installer(
2671 new CrxInstaller(install_dir,
2672 service,
2673 NULL)); // silent install, no UI
2674 installer->set_allow_privilege_increase(true);
2675 installer->InstallCrx(crx_path);
[email protected]d11c8e92009-10-20 23:26:402676 } else {
2677 AutomationMsg_InstallExtension::WriteReplyParams(
2678 reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED);
2679 Send(reply_message);
2680 }
2681}
2682
2683void AutomationProvider::LoadExpandedExtension(
2684 const FilePath& extension_dir,
2685 IPC::Message* reply_message) {
[email protected]a4378252010-02-09 08:14:382686 if (profile_->GetExtensionsService()) {
[email protected]d11c8e92009-10-20 23:26:402687 // The observer will delete itself when done.
[email protected]790788ac2010-04-06 17:52:192688 new ExtensionInstallNotificationObserver(
2689 this,
2690 AutomationMsg_LoadExpandedExtension::ID,
2691 reply_message);
[email protected]d11c8e92009-10-20 23:26:402692
2693 profile_->GetExtensionsService()->LoadExtension(extension_dir);
[email protected]d11c8e92009-10-20 23:26:402694 } else {
2695 AutomationMsg_LoadExpandedExtension::WriteReplyParams(
2696 reply_message, AUTOMATION_MSG_EXTENSION_INSTALL_FAILED);
2697 Send(reply_message);
2698 }
2699}
[email protected]673fd2c02010-02-04 23:10:002700
[email protected]a1e62d12010-03-16 02:18:432701void AutomationProvider::GetEnabledExtensions(
2702 std::vector<FilePath>* result) {
2703 ExtensionsService* service = profile_->GetExtensionsService();
2704 DCHECK(service);
2705 if (service->extensions_enabled()) {
2706 const ExtensionList* extensions = service->extensions();
2707 DCHECK(extensions);
2708 for (size_t i = 0; i < extensions->size(); ++i) {
2709 Extension* extension = (*extensions)[i];
2710 DCHECK(extension);
[email protected]237f281672010-03-20 12:37:072711 if (extension->location() == Extension::INTERNAL) {
2712 result->push_back(extension->path());
2713 }
[email protected]a1e62d12010-03-16 02:18:432714 }
2715 }
2716}
2717
[email protected]790788ac2010-04-06 17:52:192718void AutomationProvider::WaitForExtensionTestResult(
2719 IPC::Message* reply_message) {
2720 DCHECK(reply_message_ == NULL);
2721 reply_message_ = reply_message;
2722 // Call MaybeSendResult, because the result might have come in before
2723 // we were waiting on it.
2724 extension_test_result_observer_->MaybeSendResult();
2725}
2726
2727void AutomationProvider::InstallExtensionAndGetHandle(
2728 const FilePath& crx_path, IPC::Message* reply_message) {
2729 ExtensionsService* service = profile_->GetExtensionsService();
2730 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager();
2731 if (service && manager) {
2732 // The observer will delete itself when done.
2733 new ExtensionReadyNotificationObserver(
2734 manager,
2735 this,
2736 AutomationMsg_InstallExtensionAndGetHandle::ID,
2737 reply_message);
2738
2739 scoped_refptr<CrxInstaller> installer(
2740 new CrxInstaller(service->install_directory(),
2741 service,
2742 NULL)); // silent install, no UI
2743 installer->set_allow_privilege_increase(true);
2744 installer->InstallCrx(crx_path);
2745 } else {
2746 AutomationMsg_InstallExtensionAndGetHandle::WriteReplyParams(
2747 reply_message, 0);
2748 Send(reply_message);
2749 }
2750}
2751
2752void AutomationProvider::UninstallExtension(int extension_handle,
2753 bool* success) {
2754 *success = false;
2755 Extension* extension = GetExtension(extension_handle);
2756 ExtensionsService* service = profile_->GetExtensionsService();
2757 if (extension && service) {
2758 ExtensionUnloadNotificationObserver observer;
2759 service->UninstallExtension(extension->id(), false);
2760 // The extension unload notification should have been sent synchronously
2761 // with the uninstall. Just to be safe, check that it was received.
2762 *success = observer.did_receive_unload_notification();
2763 }
2764}
2765
2766void AutomationProvider::EnableExtension(int extension_handle,
2767 IPC::Message* reply_message) {
2768 Extension* extension = GetDisabledExtension(extension_handle);
2769 ExtensionsService* service = profile_->GetExtensionsService();
2770 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager();
2771 // Only enable if this extension is disabled.
2772 if (extension && service && manager) {
2773 // The observer will delete itself when done.
2774 new ExtensionReadyNotificationObserver(
2775 manager,
2776 this,
2777 AutomationMsg_EnableExtension::ID,
2778 reply_message);
2779 service->EnableExtension(extension->id());
2780 } else {
2781 AutomationMsg_EnableExtension::WriteReplyParams(reply_message, false);
2782 Send(reply_message);
2783 }
2784}
2785
2786void AutomationProvider::DisableExtension(int extension_handle,
2787 bool* success) {
2788 *success = false;
2789 Extension* extension = GetEnabledExtension(extension_handle);
2790 ExtensionsService* service = profile_->GetExtensionsService();
2791 if (extension && service) {
2792 ExtensionUnloadNotificationObserver observer;
2793 service->DisableExtension(extension->id());
2794 // The extension unload notification should have been sent synchronously
2795 // with the disable. Just to be safe, check that it was received.
2796 *success = observer.did_receive_unload_notification();
2797 }
2798}
2799
2800void AutomationProvider::ExecuteExtensionActionInActiveTabAsync(
2801 int extension_handle, int browser_handle,
2802 IPC::Message* reply_message) {
2803 bool success = false;
2804 Extension* extension = GetEnabledExtension(extension_handle);
2805 ExtensionsService* service = profile_->GetExtensionsService();
2806 ExtensionMessageService* message_service =
2807 profile_->GetExtensionMessageService();
2808 Browser* browser = browser_tracker_->GetResource(browser_handle);
2809 if (extension && service && message_service && browser) {
2810 int tab_id = ExtensionTabUtil::GetTabId(browser->GetSelectedTabContents());
2811 if (extension->page_action()) {
2812 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted(
2813 browser->profile(), extension->id(), "action", tab_id, "", 1);
2814 success = true;
2815 } else if (extension->browser_action()) {
2816 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted(
2817 browser->profile(), extension->id(), browser);
2818 success = true;
2819 }
2820 }
2821 AutomationMsg_ExecuteExtensionActionInActiveTabAsync::WriteReplyParams(
2822 reply_message, success);
2823 Send(reply_message);
2824}
2825
2826void AutomationProvider::MoveExtensionBrowserAction(
2827 int extension_handle, int index, bool* success) {
2828 *success = false;
2829 Extension* extension = GetEnabledExtension(extension_handle);
2830 ExtensionsService* service = profile_->GetExtensionsService();
2831 if (extension && service) {
2832 ExtensionToolbarModel* toolbar = service->toolbar_model();
2833 if (toolbar) {
2834 if (index >= 0 && index < static_cast<int>(toolbar->size())) {
2835 toolbar->MoveBrowserAction(extension, index);
2836 *success = true;
2837 } else {
2838 DLOG(WARNING) << "Attempted to move browser action to invalid index.";
2839 }
2840 }
2841 }
2842}
2843
2844void AutomationProvider::GetExtensionProperty(
2845 int extension_handle,
2846 AutomationMsg_ExtensionProperty type,
2847 bool* success,
2848 std::string* value) {
2849 *success = false;
2850 Extension* extension = GetExtension(extension_handle);
2851 ExtensionsService* service = profile_->GetExtensionsService();
2852 if (extension && service) {
2853 ExtensionToolbarModel* toolbar = service->toolbar_model();
2854 int found_index = -1;
2855 int index = 0;
2856 switch (type) {
2857 case AUTOMATION_MSG_EXTENSION_ID:
2858 *value = extension->id();
2859 *success = true;
2860 break;
2861 case AUTOMATION_MSG_EXTENSION_NAME:
2862 *value = extension->name();
2863 *success = true;
2864 break;
2865 case AUTOMATION_MSG_EXTENSION_VERSION:
2866 *value = extension->VersionString();
2867 *success = true;
2868 break;
2869 case AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX:
2870 if (toolbar) {
2871 for (ExtensionList::const_iterator iter = toolbar->begin();
2872 iter != toolbar->end(); iter++) {
2873 // Skip this extension if we are in incognito mode
2874 // and it is not incognito-enabled.
2875 if (profile_->IsOffTheRecord() &&
2876 !service->IsIncognitoEnabled(*iter))
2877 continue;
2878 if (*iter == extension) {
2879 found_index = index;
2880 break;
2881 }
2882 index++;
2883 }
2884 *value = IntToString(found_index);
2885 *success = true;
2886 }
2887 break;
2888 default:
2889 LOG(WARNING) << "Trying to get undefined extension property";
2890 break;
2891 }
2892 }
2893}
2894
[email protected]673fd2c02010-02-04 23:10:002895void AutomationProvider::SaveAsAsync(int tab_handle) {
2896 NavigationController* tab = NULL;
2897 TabContents* tab_contents = GetTabContentsForHandle(tab_handle, &tab);
2898 if (tab_contents)
2899 tab_contents->OnSavePage();
2900}
[email protected]7dad3d5f2010-03-04 00:27:012901
2902void AutomationProvider::SetContentSetting(
2903 int handle,
2904 const std::string& host,
2905 ContentSettingsType content_type,
2906 ContentSetting setting,
2907 bool* success) {
2908 *success = false;
2909 if (browser_tracker_->ContainsHandle(handle)) {
2910 Browser* browser = browser_tracker_->GetResource(handle);
2911 HostContentSettingsMap* map =
2912 browser->profile()->GetHostContentSettingsMap();
2913 if (host.empty()) {
2914 map->SetDefaultContentSetting(content_type, setting);
2915 } else {
2916 map->SetContentSetting(host, content_type, setting);
2917 }
2918 *success = true;
2919 }
2920}
[email protected]cc824372010-03-31 15:33:012921
2922#if !defined(TOOLKIT_VIEWS)
2923void AutomationProvider::GetFocusedViewID(int handle, int* view_id) {
2924 NOTIMPLEMENTED();
2925};
2926
2927void AutomationProvider::WaitForFocusedViewIDToChange(
2928 int handle, int previous_view_id, IPC::Message* reply_message) {
2929 NOTIMPLEMENTED();
2930}
2931
2932void AutomationProvider::StartTrackingPopupMenus(
2933 int browser_handle, bool* success) {
2934 NOTIMPLEMENTED();
2935}
2936
2937void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) {
2938 NOTIMPLEMENTED();
2939}
2940#endif // !defined(TOOLKIT_VIEWS)