| Index: chrome/browser/automation/automation_provider.cc
|
| diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
|
| index 1784eeac7ea03d64d23ff945e7ca1246d6d34dec..855b67827739b00dad2142febf0a60a468223879 100644
|
| --- a/chrome/browser/automation/automation_provider.cc
|
| +++ b/chrome/browser/automation/automation_provider.cc
|
| @@ -226,11 +226,14 @@ class NavigationNotificationObserver : public NotificationObserver {
|
| public:
|
| NavigationNotificationObserver(NavigationController* controller,
|
| AutomationProvider* automation,
|
| - IPC::Message* reply_message)
|
| + IPC::Message* reply_message,
|
| + int number_of_navigations)
|
| : automation_(automation),
|
| reply_message_(reply_message),
|
| controller_(controller),
|
| + navigations_remaining_(number_of_navigations),
|
| navigation_started_(false) {
|
| + DCHECK_LT(0, navigations_remaining_);
|
| Source<NavigationController> source(controller_);
|
| registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source);
|
| registrar_.Add(this, NotificationType::LOAD_START, source);
|
| @@ -280,7 +283,8 @@ class NavigationNotificationObserver : public NotificationObserver {
|
| } else if (type == NotificationType::LOAD_STOP) {
|
| if (navigation_started_) {
|
| navigation_started_ = false;
|
| - ConditionMet(AUTOMATION_MSG_NAVIGATION_SUCCESS);
|
| + if (--navigations_remaining_ == 0)
|
| + ConditionMet(AUTOMATION_MSG_NAVIGATION_SUCCESS);
|
| }
|
| } else if (type == NotificationType::AUTH_SUPPLIED) {
|
| // The LoginHandler for this tab is no longer valid.
|
| @@ -317,6 +321,7 @@ class NavigationNotificationObserver : public NotificationObserver {
|
| AutomationProvider* automation_;
|
| IPC::Message* reply_message_;
|
| NavigationController* controller_;
|
| + int navigations_remaining_;
|
| bool navigation_started_;
|
| };
|
|
|
| @@ -372,7 +377,7 @@ class TabAppendedNotificationObserver : public TabStripNotificationObserver {
|
| return;
|
| }
|
|
|
| - automation_->AddNavigationStatusListener(controller, reply_message_);
|
| + automation_->AddNavigationStatusListener(controller, reply_message_, 1);
|
| }
|
|
|
| protected:
|
| @@ -546,7 +551,7 @@ class ExecuteBrowserCommandObserver : public NotificationObserver {
|
| case IDC_RELOAD: {
|
| automation->AddNavigationStatusListener(
|
| &browser->GetSelectedTabContents()->controller(),
|
| - reply_message);
|
| + reply_message, 1);
|
| break;
|
| }
|
| default: {
|
| @@ -834,9 +839,11 @@ void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) {
|
| }
|
|
|
| NotificationObserver* AutomationProvider::AddNavigationStatusListener(
|
| - NavigationController* tab, IPC::Message* reply_message) {
|
| + NavigationController* tab, IPC::Message* reply_message,
|
| + int number_of_navigations) {
|
| NotificationObserver* observer =
|
| - new NavigationNotificationObserver(tab, this, reply_message);
|
| + new NavigationNotificationObserver(tab, this, reply_message,
|
| + number_of_navigations);
|
|
|
| notification_observer_list_.AddObserver(observer);
|
| return observer;
|
| @@ -919,6 +926,9 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
|
| IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
|
| IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
|
| IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL)
|
| + IPC_MESSAGE_HANDLER_DELAY_REPLY(
|
| + AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
|
| + NavigateToURLBlockUntilNavigationsComplete)
|
| IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
|
| IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack)
|
| IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward)
|
| @@ -1115,6 +1125,12 @@ void AutomationProvider::AppendTab(int handle, const GURL& url,
|
|
|
| void AutomationProvider::NavigateToURL(int handle, const GURL& url,
|
| IPC::Message* reply_message) {
|
| + NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message);
|
| +}
|
| +
|
| +void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
|
| + int handle, const GURL& url, int number_of_navigations,
|
| + IPC::Message* reply_message) {
|
| if (tab_tracker_->ContainsHandle(handle)) {
|
| NavigationController* tab = tab_tracker_->GetResource(handle);
|
|
|
| @@ -1123,7 +1139,7 @@ void AutomationProvider::NavigateToURL(int handle, const GURL& url,
|
| Browser* browser = FindAndActivateTab(tab);
|
|
|
| if (browser) {
|
| - AddNavigationStatusListener(tab, reply_message);
|
| + AddNavigationStatusListener(tab, reply_message, number_of_navigations);
|
|
|
| // TODO(darin): avoid conversion to GURL
|
| browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
|
| @@ -1135,7 +1151,6 @@ void AutomationProvider::NavigateToURL(int handle, const GURL& url,
|
| reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
|
| Send(reply_message);
|
| }
|
| -
|
| void AutomationProvider::NavigationAsync(int handle, const GURL& url,
|
| bool* status) {
|
| *status = false;
|
| @@ -1161,7 +1176,7 @@ void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) {
|
| NavigationController* tab = tab_tracker_->GetResource(handle);
|
| Browser* browser = FindAndActivateTab(tab);
|
| if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) {
|
| - AddNavigationStatusListener(tab, reply_message);
|
| + AddNavigationStatusListener(tab, reply_message, 1);
|
| browser->GoBack(CURRENT_TAB);
|
| return;
|
| }
|
| @@ -1177,7 +1192,7 @@ void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) {
|
| NavigationController* tab = tab_tracker_->GetResource(handle);
|
| Browser* browser = FindAndActivateTab(tab);
|
| if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) {
|
| - AddNavigationStatusListener(tab, reply_message);
|
| + AddNavigationStatusListener(tab, reply_message, 1);
|
| browser->GoForward(CURRENT_TAB);
|
| return;
|
| }
|
| @@ -1193,7 +1208,7 @@ void AutomationProvider::Reload(int handle, IPC::Message* reply_message) {
|
| NavigationController* tab = tab_tracker_->GetResource(handle);
|
| Browser* browser = FindAndActivateTab(tab);
|
| if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) {
|
| - AddNavigationStatusListener(tab, reply_message);
|
| + AddNavigationStatusListener(tab, reply_message, 1);
|
| browser->Reload();
|
| return;
|
| }
|
| @@ -1217,7 +1232,7 @@ void AutomationProvider::SetAuth(int tab_handle,
|
| // not strictly correct, because a navigation can require both proxy and
|
| // server auth, but it should be OK for now.
|
| LoginHandler* handler = iter->second;
|
| - AddNavigationStatusListener(tab, reply_message);
|
| + AddNavigationStatusListener(tab, reply_message, 1);
|
| handler->SetAuth(username, password);
|
| return;
|
| }
|
| @@ -1237,7 +1252,7 @@ void AutomationProvider::CancelAuth(int tab_handle,
|
| if (iter != login_handler_map_.end()) {
|
| // If auth is needed again after this, something is screwy.
|
| LoginHandler* handler = iter->second;
|
| - AddNavigationStatusListener(tab, reply_message);
|
| + AddNavigationStatusListener(tab, reply_message, 1);
|
| handler->CancelAuth();
|
| return;
|
| }
|
| @@ -2274,7 +2289,7 @@ void AutomationProvider::ShowInterstitialPage(int tab_handle,
|
| NavigationController* controller = tab_tracker_->GetResource(tab_handle);
|
| TabContents* tab_contents = controller->tab_contents();
|
|
|
| - AddNavigationStatusListener(controller, reply_message);
|
| + AddNavigationStatusListener(controller, reply_message, 1);
|
| AutomationInterstitialPage* interstitial =
|
| new AutomationInterstitialPage(tab_contents,
|
| GURL("about:interstitial"),
|
| @@ -2472,7 +2487,7 @@ void AutomationProvider::ActionOnSSLBlockingPage(int handle, bool proceed,
|
| InterstitialPage::GetInterstitialPage(tab_contents);
|
| if (ssl_blocking_page) {
|
| if (proceed) {
|
| - AddNavigationStatusListener(tab, reply_message);
|
| + AddNavigationStatusListener(tab, reply_message, 1);
|
| ssl_blocking_page->Proceed();
|
| return;
|
| }
|
| @@ -2777,7 +2792,7 @@ void AutomationProvider::ClickSSLInfoBarLink(int handle,
|
| int count = nav_controller->tab_contents()->infobar_delegate_count();
|
| if (info_bar_index >= 0 && info_bar_index < count) {
|
| if (wait_for_navigation) {
|
| - AddNavigationStatusListener(nav_controller, reply_message);
|
| + AddNavigationStatusListener(nav_controller, reply_message, 1);
|
| }
|
| InfoBarDelegate* delegate =
|
| nav_controller->tab_contents()->GetInfoBarDelegateAt(
|
| @@ -2814,7 +2829,7 @@ void AutomationProvider::WaitForNavigation(int handle,
|
| return;
|
| }
|
|
|
| - AddNavigationStatusListener(controller, reply_message);
|
| + AddNavigationStatusListener(controller, reply_message, 1);
|
| }
|
|
|
| void AutomationProvider::SetIntPreference(int handle,
|
|
|