Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 5998006: Clean up Automation and Chrome Frame IPC code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include "app/message_box_flags.h" 7 #include "app/message_box_flags.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 CloseBrowserAsync) 210 CloseBrowserAsync)
211 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) 211 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab)
212 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) 212 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab)
213 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex) 213 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex)
214 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab) 214 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab)
215 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) 215 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
216 IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie) 216 IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
217 IPC_MESSAGE_HANDLER(AutomationMsg_DeleteCookie, DeleteCookie) 217 IPC_MESSAGE_HANDLER(AutomationMsg_DeleteCookie, DeleteCookie)
218 IPC_MESSAGE_HANDLER(AutomationMsg_ShowCollectedCookiesDialog, 218 IPC_MESSAGE_HANDLER(AutomationMsg_ShowCollectedCookiesDialog,
219 ShowCollectedCookiesDialog) 219 ShowCollectedCookiesDialog)
220 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL)
221 IPC_MESSAGE_HANDLER_DELAY_REPLY( 220 IPC_MESSAGE_HANDLER_DELAY_REPLY(
222 AutomationMsg_NavigateToURLBlockUntilNavigationsComplete, 221 AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
223 NavigateToURLBlockUntilNavigationsComplete) 222 NavigateToURLBlockUntilNavigationsComplete)
224 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync) 223 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
225 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsyncWithDisposition, 224 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsyncWithDisposition,
226 NavigationAsyncWithDisposition) 225 NavigationAsyncWithDisposition)
227 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack)
228 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward)
229 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload) 226 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload)
230 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth) 227 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth)
231 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth) 228 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth)
232 IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth) 229 IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth)
233 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom, 230 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom,
234 GetRedirectsFrom) 231 GetRedirectsFrom)
235 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount) 232 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount)
236 IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount, 233 IPC_MESSAGE_HANDLER(AutomationMsg_NormalBrowserWindowCount,
237 GetNormalBrowserWindowCount) 234 GetNormalBrowserWindowCount)
238 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow) 235 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText, 270 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetText,
274 GetAutocompleteEditText) 271 GetAutocompleteEditText)
275 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText, 272 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditSetText,
276 SetAutocompleteEditText) 273 SetAutocompleteEditText)
277 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress, 274 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditIsQueryInProgress,
278 AutocompleteEditIsQueryInProgress) 275 AutocompleteEditIsQueryInProgress)
279 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches, 276 IPC_MESSAGE_HANDLER(AutomationMsg_AutocompleteEditGetMatches,
280 AutocompleteEditGetMatches) 277 AutocompleteEditGetMatches)
281 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForAutocompleteEditFocus, 278 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForAutocompleteEditFocus,
282 WaitForAutocompleteEditFocus) 279 WaitForAutocompleteEditFocus)
283 IPC_MESSAGE_HANDLER(AutomationMsg_ApplyAccelerator, ApplyAccelerator)
284 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation, 280 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_DomOperation,
285 ExecuteJavascript) 281 ExecuteJavascript)
286 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount, 282 IPC_MESSAGE_HANDLER(AutomationMsg_ConstrainedWindowCount,
287 GetConstrainedWindowCount) 283 GetConstrainedWindowCount)
288 #if defined(TOOLKIT_VIEWS) 284 #if defined(TOOLKIT_VIEWS)
289 IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID) 285 IPC_MESSAGE_HANDLER(AutomationMsg_GetFocusedViewID, GetFocusedViewID)
290 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForFocusedViewIDToChange, 286 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForFocusedViewIDToChange,
291 WaitForFocusedViewIDToChange) 287 WaitForFocusedViewIDToChange)
292 IPC_MESSAGE_HANDLER(AutomationMsg_StartTrackingPopupMenus, 288 IPC_MESSAGE_HANDLER(AutomationMsg_StartTrackingPopupMenus,
293 StartTrackingPopupMenus) 289 StartTrackingPopupMenus)
294 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForPopupMenuToOpen, 290 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForPopupMenuToOpen,
295 WaitForPopupMenuToOpen) 291 WaitForPopupMenuToOpen)
296 #endif // defined(TOOLKIT_VIEWS) 292 #endif // defined(TOOLKIT_VIEWS)
297 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement, 293 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_InspectElement,
298 HandleInspectElementRequest) 294 HandleInspectElementRequest)
299 IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory) 295 IPC_MESSAGE_HANDLER(AutomationMsg_DownloadDirectory, GetDownloadDirectory)
300 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindow,
301 OpenNewBrowserWindow)
302 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType, 296 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_OpenNewBrowserWindowOfType,
303 OpenNewBrowserWindowOfType) 297 OpenNewBrowserWindowOfType)
304 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser) 298 IPC_MESSAGE_HANDLER(AutomationMsg_WindowForBrowser, GetWindowForBrowser)
305 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow) 299 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserForWindow, GetBrowserForWindow)
306 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage, 300 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_ShowInterstitialPage,
307 ShowInterstitialPage) 301 ShowInterstitialPage)
308 IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage, 302 IPC_MESSAGE_HANDLER(AutomationMsg_HideInterstitialPage,
309 HideInterstitialPage) 303 HideInterstitialPage)
310 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored, 304 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WaitForTabToBeRestored,
311 WaitForTabToBeRestored) 305 WaitForTabToBeRestored)
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 int handle, bool* success) { 555 int handle, bool* success) {
562 *success = false; 556 *success = false;
563 if (tab_tracker_->ContainsHandle(handle)) { 557 if (tab_tracker_->ContainsHandle(handle)) {
564 TabContents* tab_contents = 558 TabContents* tab_contents =
565 tab_tracker_->GetResource(handle)->tab_contents(); 559 tab_tracker_->GetResource(handle)->tab_contents();
566 tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents); 560 tab_contents->delegate()->ShowCollectedCookiesDialog(tab_contents);
567 *success = true; 561 *success = true;
568 } 562 }
569 } 563 }
570 564
571 void TestingAutomationProvider::NavigateToURL(int handle,
572 const GURL& url,
573 IPC::Message* reply_message) {
574 NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message);
575 }
576
577 void TestingAutomationProvider::NavigateToURLBlockUntilNavigationsComplete( 565 void TestingAutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
578 int handle, const GURL& url, int number_of_navigations, 566 int handle, const GURL& url, int number_of_navigations,
579 IPC::Message* reply_message) { 567 IPC::Message* reply_message) {
580 if (tab_tracker_->ContainsHandle(handle)) { 568 if (tab_tracker_->ContainsHandle(handle)) {
581 NavigationController* tab = tab_tracker_->GetResource(handle); 569 NavigationController* tab = tab_tracker_->GetResource(handle);
582 570
583 // Simulate what a user would do. Activate the tab and then navigate. 571 // Simulate what a user would do. Activate the tab and then navigate.
584 // We could allow navigating in a background tab in future. 572 // We could allow navigating in a background tab in future.
585 Browser* browser = FindAndActivateTab(tab); 573 Browser* browser = FindAndActivateTab(tab);
586 574
587 if (browser) { 575 if (browser) {
588 AddNavigationStatusListener(tab, reply_message, number_of_navigations, 576 AddNavigationStatusListener(tab, reply_message, number_of_navigations,
589 false); 577 false);
590 578
591 // TODO(darin): avoid conversion to GURL. 579 // TODO(darin): avoid conversion to GURL.
592 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); 580 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
593 return; 581 return;
594 } 582 }
595 } 583 }
596 584
597 AutomationMsg_NavigateToURL::WriteReplyParams( 585 AutomationMsg_NavigateToURLBlockUntilNavigationsComplete::WriteReplyParams(
598 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); 586 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
599 Send(reply_message); 587 Send(reply_message);
600 } 588 }
601 589
602 void TestingAutomationProvider::NavigationAsync(int handle, 590 void TestingAutomationProvider::NavigationAsync(int handle,
603 const GURL& url, 591 const GURL& url,
604 bool* status) { 592 bool* status) {
605 NavigationAsyncWithDisposition(handle, url, CURRENT_TAB, status); 593 NavigationAsyncWithDisposition(handle, url, CURRENT_TAB, status);
606 } 594 }
607 595
(...skipping 13 matching lines...) Expand all
621 609
622 if (browser) { 610 if (browser) {
623 // Don't add any listener unless a callback mechanism is desired. 611 // Don't add any listener unless a callback mechanism is desired.
624 // TODO(vibhor): Do this if such a requirement arises in future. 612 // TODO(vibhor): Do this if such a requirement arises in future.
625 browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED); 613 browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED);
626 *status = true; 614 *status = true;
627 } 615 }
628 } 616 }
629 } 617 }
630 618
631 void TestingAutomationProvider::GoBack(int handle,
632 IPC::Message* reply_message) {
633 if (tab_tracker_->ContainsHandle(handle)) {
634 NavigationController* tab = tab_tracker_->GetResource(handle);
635 Browser* browser = FindAndActivateTab(tab);
636 if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) {
637 AddNavigationStatusListener(tab, reply_message, 1, false);
638 browser->GoBack(CURRENT_TAB);
639 return;
640 }
641 }
642
643 AutomationMsg_GoBack::WriteReplyParams(
644 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
645 Send(reply_message);
646 }
647
648 void TestingAutomationProvider::GoForward(int handle,
649 IPC::Message* reply_message) {
650 if (tab_tracker_->ContainsHandle(handle)) {
651 NavigationController* tab = tab_tracker_->GetResource(handle);
652 Browser* browser = FindAndActivateTab(tab);
653 if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) {
654 AddNavigationStatusListener(tab, reply_message, 1, false);
655 browser->GoForward(CURRENT_TAB);
656 return;
657 }
658 }
659
660 AutomationMsg_GoForward::WriteReplyParams(
661 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
662 Send(reply_message);
663 }
664
665 void TestingAutomationProvider::Reload(int handle, 619 void TestingAutomationProvider::Reload(int handle,
666 IPC::Message* reply_message) { 620 IPC::Message* reply_message) {
667 if (tab_tracker_->ContainsHandle(handle)) { 621 if (tab_tracker_->ContainsHandle(handle)) {
668 NavigationController* tab = tab_tracker_->GetResource(handle); 622 NavigationController* tab = tab_tracker_->GetResource(handle);
669 Browser* browser = FindAndActivateTab(tab); 623 Browser* browser = FindAndActivateTab(tab);
670 if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { 624 if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) {
671 AddNavigationStatusListener(tab, reply_message, 1, false); 625 AddNavigationStatusListener(tab, reply_message, 1, false);
672 browser->Reload(CURRENT_TAB); 626 browser->Reload(CURRENT_TAB);
673 return; 627 return;
674 } 628 }
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 bool* query_in_progress) { 1094 bool* query_in_progress) {
1141 *success = false; 1095 *success = false;
1142 *query_in_progress = false; 1096 *query_in_progress = false;
1143 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { 1097 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) {
1144 *query_in_progress = autocomplete_edit_tracker_-> 1098 *query_in_progress = autocomplete_edit_tracker_->
1145 GetResource(autocomplete_edit_handle)->model()->query_in_progress(); 1099 GetResource(autocomplete_edit_handle)->model()->query_in_progress();
1146 *success = true; 1100 *success = true;
1147 } 1101 }
1148 } 1102 }
1149 1103
1150 void TestingAutomationProvider::ApplyAccelerator(int handle, int id) {
1151 LOG(ERROR) << "ApplyAccelerator has been deprecated. "
1152 << "Please use ExecuteBrowserCommandAsync instead.";
1153 }
1154
1155 void TestingAutomationProvider::ExecuteJavascript( 1104 void TestingAutomationProvider::ExecuteJavascript(
1156 int handle, 1105 int handle,
1157 const std::wstring& frame_xpath, 1106 const std::wstring& frame_xpath,
1158 const std::wstring& script, 1107 const std::wstring& script,
1159 IPC::Message* reply_message) { 1108 IPC::Message* reply_message) {
1160 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); 1109 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL);
1161 if (!tab_contents) { 1110 if (!tab_contents) {
1162 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); 1111 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string());
1163 Send(reply_message); 1112 Send(reply_message);
1164 return; 1113 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 1159
1211 void TestingAutomationProvider::GetDownloadDirectory( 1160 void TestingAutomationProvider::GetDownloadDirectory(
1212 int handle, FilePath* download_directory) { 1161 int handle, FilePath* download_directory) {
1213 if (tab_tracker_->ContainsHandle(handle)) { 1162 if (tab_tracker_->ContainsHandle(handle)) {
1214 NavigationController* tab = tab_tracker_->GetResource(handle); 1163 NavigationController* tab = tab_tracker_->GetResource(handle);
1215 DownloadManager* dlm = tab->profile()->GetDownloadManager(); 1164 DownloadManager* dlm = tab->profile()->GetDownloadManager();
1216 *download_directory = dlm->download_prefs()->download_path(); 1165 *download_directory = dlm->download_prefs()->download_path();
1217 } 1166 }
1218 } 1167 }
1219 1168
1220 void TestingAutomationProvider::OpenNewBrowserWindow(
1221 bool show, IPC::Message* reply_message) {
1222 OpenNewBrowserWindowOfType(static_cast<int>(Browser::TYPE_NORMAL), show,
1223 reply_message);
1224 }
1225
1226 void TestingAutomationProvider::OpenNewBrowserWindowOfType( 1169 void TestingAutomationProvider::OpenNewBrowserWindowOfType(
1227 int type, bool show, IPC::Message* reply_message) { 1170 int type, bool show, IPC::Message* reply_message) {
1228 new BrowserOpenedNotificationObserver(this, reply_message); 1171 new BrowserOpenedNotificationObserver(this, reply_message);
1229 // We may have no current browser windows open so don't rely on 1172 // We may have no current browser windows open so don't rely on
1230 // asking an existing browser to execute the IDC_NEWWINDOW command 1173 // asking an existing browser to execute the IDC_NEWWINDOW command
1231 Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_); 1174 Browser* browser = new Browser(static_cast<Browser::Type>(type), profile_);
1232 browser->CreateBrowserWindow(); 1175 browser->CreateBrowserWindow();
1233 browser->AddBlankTab(true); 1176 browser->AddBlankTab(true);
1234 if (show) 1177 if (show)
1235 browser->window()->Show(); 1178 browser->window()->Show();
(...skipping 3287 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 // If you change this, update Observer for NotificationType::SESSION_END 4466 // If you change this, update Observer for NotificationType::SESSION_END
4524 // below. 4467 // below.
4525 MessageLoop::current()->PostTask(FROM_HERE, 4468 MessageLoop::current()->PostTask(FROM_HERE,
4526 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); 4469 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider));
4527 } 4470 }
4528 } 4471 }
4529 4472
4530 void TestingAutomationProvider::OnRemoveProvider() { 4473 void TestingAutomationProvider::OnRemoveProvider() {
4531 AutomationProviderList::GetInstance()->RemoveProvider(this); 4474 AutomationProviderList::GetInstance()->RemoveProvider(this);
4532 } 4475 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.h ('k') | chrome/browser/automation/url_request_automation_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698