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

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

Issue 174015: Add automation call to wait for multiple navigations. (Closed)
Patch Set: backwards compatibility, properly done Created 11 years, 4 months 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
« no previous file with comments | « chrome/browser/automation/automation_provider.h ('k') | chrome/browser/errorpage_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/automation_provider.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/message_box_flags.h" 8 #include "app/message_box_flags.h"
9 #include "base/file_version_info.h" 9 #include "base/file_version_info.h"
10 #include "base/json_reader.h" 10 #include "base/json_reader.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 NavigationController* controller_; 219 NavigationController* controller_;
220 IPC::Message* reply_message_; 220 IPC::Message* reply_message_;
221 221
222 DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver); 222 DISALLOW_COPY_AND_ASSIGN(NavigationControllerRestoredObserver);
223 }; 223 };
224 224
225 class NavigationNotificationObserver : public NotificationObserver { 225 class NavigationNotificationObserver : public NotificationObserver {
226 public: 226 public:
227 NavigationNotificationObserver(NavigationController* controller, 227 NavigationNotificationObserver(NavigationController* controller,
228 AutomationProvider* automation, 228 AutomationProvider* automation,
229 IPC::Message* reply_message) 229 IPC::Message* reply_message,
230 int number_of_navigations)
230 : automation_(automation), 231 : automation_(automation),
231 reply_message_(reply_message), 232 reply_message_(reply_message),
232 controller_(controller), 233 controller_(controller),
234 navigations_remaining_(number_of_navigations),
233 navigation_started_(false) { 235 navigation_started_(false) {
236 DCHECK_LT(0, navigations_remaining_);
234 Source<NavigationController> source(controller_); 237 Source<NavigationController> source(controller_);
235 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source); 238 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source);
236 registrar_.Add(this, NotificationType::LOAD_START, source); 239 registrar_.Add(this, NotificationType::LOAD_START, source);
237 registrar_.Add(this, NotificationType::LOAD_STOP, source); 240 registrar_.Add(this, NotificationType::LOAD_STOP, source);
238 registrar_.Add(this, NotificationType::AUTH_NEEDED, source); 241 registrar_.Add(this, NotificationType::AUTH_NEEDED, source);
239 registrar_.Add(this, NotificationType::AUTH_SUPPLIED, source); 242 registrar_.Add(this, NotificationType::AUTH_SUPPLIED, source);
240 } 243 }
241 244
242 ~NavigationNotificationObserver() { 245 ~NavigationNotificationObserver() {
243 if (reply_message_) { 246 if (reply_message_) {
(...skipping 29 matching lines...) Expand all
273 // WaitForNavigation compares times of the last navigation). 276 // WaitForNavigation compares times of the last navigation).
274 // - when this is used with a page requiring authentication, we will not get 277 // - when this is used with a page requiring authentication, we will not get
275 // a NotificationType::NAV_ENTRY_COMMITTED until after we authenticate, so 278 // a NotificationType::NAV_ENTRY_COMMITTED until after we authenticate, so
276 // we need the NotificationType::LOAD_START. 279 // we need the NotificationType::LOAD_START.
277 if (type == NotificationType::NAV_ENTRY_COMMITTED || 280 if (type == NotificationType::NAV_ENTRY_COMMITTED ||
278 type == NotificationType::LOAD_START) { 281 type == NotificationType::LOAD_START) {
279 navigation_started_ = true; 282 navigation_started_ = true;
280 } else if (type == NotificationType::LOAD_STOP) { 283 } else if (type == NotificationType::LOAD_STOP) {
281 if (navigation_started_) { 284 if (navigation_started_) {
282 navigation_started_ = false; 285 navigation_started_ = false;
283 ConditionMet(AUTOMATION_MSG_NAVIGATION_SUCCESS); 286 if (--navigations_remaining_ == 0)
287 ConditionMet(AUTOMATION_MSG_NAVIGATION_SUCCESS);
284 } 288 }
285 } else if (type == NotificationType::AUTH_SUPPLIED) { 289 } else if (type == NotificationType::AUTH_SUPPLIED) {
286 // The LoginHandler for this tab is no longer valid. 290 // The LoginHandler for this tab is no longer valid.
287 automation_->RemoveLoginHandler(controller_); 291 automation_->RemoveLoginHandler(controller_);
288 292
289 // Treat this as if navigation started again, since load start/stop don't 293 // Treat this as if navigation started again, since load start/stop don't
290 // occur while authentication is ongoing. 294 // occur while authentication is ongoing.
291 navigation_started_ = true; 295 navigation_started_ = true;
292 } else if (type == NotificationType::AUTH_NEEDED) { 296 } else if (type == NotificationType::AUTH_NEEDED) {
293 #if defined(OS_WIN) 297 #if defined(OS_WIN)
(...skipping 16 matching lines...) Expand all
310 } else { 314 } else {
311 NOTREACHED(); 315 NOTREACHED();
312 } 316 }
313 } 317 }
314 318
315 private: 319 private:
316 NotificationRegistrar registrar_; 320 NotificationRegistrar registrar_;
317 AutomationProvider* automation_; 321 AutomationProvider* automation_;
318 IPC::Message* reply_message_; 322 IPC::Message* reply_message_;
319 NavigationController* controller_; 323 NavigationController* controller_;
324 int navigations_remaining_;
320 bool navigation_started_; 325 bool navigation_started_;
321 }; 326 };
322 327
323 class TabStripNotificationObserver : public NotificationObserver { 328 class TabStripNotificationObserver : public NotificationObserver {
324 public: 329 public:
325 TabStripNotificationObserver(NotificationType notification, 330 TabStripNotificationObserver(NotificationType notification,
326 AutomationProvider* automation) 331 AutomationProvider* automation)
327 : automation_(automation), 332 : automation_(automation),
328 notification_(notification) { 333 notification_(notification) {
329 registrar_.Add(this, notification_, NotificationService::AllSources()); 334 registrar_.Add(this, notification_, NotificationService::AllSources());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 reply_message_(reply_message) { 370 reply_message_(reply_message) {
366 } 371 }
367 372
368 virtual void ObserveTab(NavigationController* controller) { 373 virtual void ObserveTab(NavigationController* controller) {
369 if (automation_->GetIndexForNavigationController(controller, parent_) == 374 if (automation_->GetIndexForNavigationController(controller, parent_) ==
370 TabStripModel::kNoTab) { 375 TabStripModel::kNoTab) {
371 // This tab notification doesn't belong to the parent_. 376 // This tab notification doesn't belong to the parent_.
372 return; 377 return;
373 } 378 }
374 379
375 automation_->AddNavigationStatusListener(controller, reply_message_); 380 automation_->AddNavigationStatusListener(controller, reply_message_, 1);
376 } 381 }
377 382
378 protected: 383 protected:
379 Browser* parent_; 384 Browser* parent_;
380 IPC::Message* reply_message_; 385 IPC::Message* reply_message_;
381 }; 386 };
382 387
383 class TabClosedNotificationObserver : public TabStripNotificationObserver { 388 class TabClosedNotificationObserver : public TabStripNotificationObserver {
384 public: 389 public:
385 TabClosedNotificationObserver(AutomationProvider* automation, 390 TabClosedNotificationObserver(AutomationProvider* automation,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 TabClosedNotificationObserver* observer = 544 TabClosedNotificationObserver* observer =
540 new TabClosedNotificationObserver(automation, true, reply_message); 545 new TabClosedNotificationObserver(automation, true, reply_message);
541 observer->set_for_browser_command(true); 546 observer->set_for_browser_command(true);
542 break; 547 break;
543 } 548 }
544 case IDC_BACK: 549 case IDC_BACK:
545 case IDC_FORWARD: 550 case IDC_FORWARD:
546 case IDC_RELOAD: { 551 case IDC_RELOAD: {
547 automation->AddNavigationStatusListener( 552 automation->AddNavigationStatusListener(
548 &browser->GetSelectedTabContents()->controller(), 553 &browser->GetSelectedTabContents()->controller(),
549 reply_message); 554 reply_message, 1);
550 break; 555 break;
551 } 556 }
552 default: { 557 default: {
553 ExecuteBrowserCommandObserver* observer = 558 ExecuteBrowserCommandObserver* observer =
554 new ExecuteBrowserCommandObserver(automation, reply_message); 559 new ExecuteBrowserCommandObserver(automation, reply_message);
555 if (!observer->Register(command)) { 560 if (!observer->Register(command)) {
556 delete observer; 561 delete observer;
557 result = false; 562 result = false;
558 } 563 }
559 break; 564 break;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 832
828 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) { 833 void AutomationProvider::SetExpectedTabCount(size_t expected_tabs) {
829 if (expected_tabs == 0) { 834 if (expected_tabs == 0) {
830 Send(new AutomationMsg_InitialLoadsComplete(0)); 835 Send(new AutomationMsg_InitialLoadsComplete(0));
831 } else { 836 } else {
832 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this)); 837 initial_load_observer_.reset(new InitialLoadObserver(expected_tabs, this));
833 } 838 }
834 } 839 }
835 840
836 NotificationObserver* AutomationProvider::AddNavigationStatusListener( 841 NotificationObserver* AutomationProvider::AddNavigationStatusListener(
837 NavigationController* tab, IPC::Message* reply_message) { 842 NavigationController* tab, IPC::Message* reply_message,
843 int number_of_navigations) {
838 NotificationObserver* observer = 844 NotificationObserver* observer =
839 new NavigationNotificationObserver(tab, this, reply_message); 845 new NavigationNotificationObserver(tab, this, reply_message,
846 number_of_navigations);
840 847
841 notification_observer_list_.AddObserver(observer); 848 notification_observer_list_.AddObserver(observer);
842 return observer; 849 return observer;
843 } 850 }
844 851
845 void AutomationProvider::RemoveNavigationStatusListener( 852 void AutomationProvider::RemoveNavigationStatusListener(
846 NotificationObserver* obs) { 853 NotificationObserver* obs) {
847 notification_observer_list_.RemoveObserver(obs); 854 notification_observer_list_.RemoveObserver(obs);
848 } 855 }
849 856
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) 919 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser)
913 IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync, 920 IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync,
914 CloseBrowserAsync) 921 CloseBrowserAsync)
915 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) 922 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab)
916 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex) 923 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveTabIndex, GetActiveTabIndex)
917 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) 924 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab)
918 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab) 925 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseTab, CloseTab)
919 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies) 926 IPC_MESSAGE_HANDLER(AutomationMsg_GetCookies, GetCookies)
920 IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie) 927 IPC_MESSAGE_HANDLER(AutomationMsg_SetCookie, SetCookie)
921 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL) 928 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_NavigateToURL, NavigateToURL)
929 IPC_MESSAGE_HANDLER_DELAY_REPLY(
930 AutomationMsg_NavigateToURLBlockUntilNavigationsComplete,
931 NavigateToURLBlockUntilNavigationsComplete)
922 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync) 932 IPC_MESSAGE_HANDLER(AutomationMsg_NavigationAsync, NavigationAsync)
923 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack) 933 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoBack, GoBack)
924 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward) 934 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_GoForward, GoForward)
925 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload) 935 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_Reload, Reload)
926 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth) 936 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_SetAuth, SetAuth)
927 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth) 937 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CancelAuth, CancelAuth)
928 IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth) 938 IPC_MESSAGE_HANDLER(AutomationMsg_NeedsAuth, NeedsAuth)
929 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom, 939 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_RedirectsFrom,
930 GetRedirectsFrom) 940 GetRedirectsFrom)
931 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount) 941 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindowCount, GetBrowserWindowCount)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 } 1118 }
1109 1119
1110 AutomationMsg_AppendTab::WriteReplyParams(reply_message, 1120 AutomationMsg_AppendTab::WriteReplyParams(reply_message,
1111 append_tab_response); 1121 append_tab_response);
1112 Send(reply_message); 1122 Send(reply_message);
1113 } 1123 }
1114 } 1124 }
1115 1125
1116 void AutomationProvider::NavigateToURL(int handle, const GURL& url, 1126 void AutomationProvider::NavigateToURL(int handle, const GURL& url,
1117 IPC::Message* reply_message) { 1127 IPC::Message* reply_message) {
1128 NavigateToURLBlockUntilNavigationsComplete(handle, url, 1, reply_message);
1129 }
1130
1131 void AutomationProvider::NavigateToURLBlockUntilNavigationsComplete(
1132 int handle, const GURL& url, int number_of_navigations,
1133 IPC::Message* reply_message) {
1118 if (tab_tracker_->ContainsHandle(handle)) { 1134 if (tab_tracker_->ContainsHandle(handle)) {
1119 NavigationController* tab = tab_tracker_->GetResource(handle); 1135 NavigationController* tab = tab_tracker_->GetResource(handle);
1120 1136
1121 // Simulate what a user would do. Activate the tab and then navigate. 1137 // Simulate what a user would do. Activate the tab and then navigate.
1122 // We could allow navigating in a background tab in future. 1138 // We could allow navigating in a background tab in future.
1123 Browser* browser = FindAndActivateTab(tab); 1139 Browser* browser = FindAndActivateTab(tab);
1124 1140
1125 if (browser) { 1141 if (browser) {
1126 AddNavigationStatusListener(tab, reply_message); 1142 AddNavigationStatusListener(tab, reply_message, number_of_navigations);
1127 1143
1128 // TODO(darin): avoid conversion to GURL 1144 // TODO(darin): avoid conversion to GURL
1129 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); 1145 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
1130 return; 1146 return;
1131 } 1147 }
1132 } 1148 }
1133 1149
1134 AutomationMsg_NavigateToURL::WriteReplyParams( 1150 AutomationMsg_NavigateToURL::WriteReplyParams(
1135 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); 1151 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1136 Send(reply_message); 1152 Send(reply_message);
1137 } 1153 }
1138
1139 void AutomationProvider::NavigationAsync(int handle, const GURL& url, 1154 void AutomationProvider::NavigationAsync(int handle, const GURL& url,
1140 bool* status) { 1155 bool* status) {
1141 *status = false; 1156 *status = false;
1142 1157
1143 if (tab_tracker_->ContainsHandle(handle)) { 1158 if (tab_tracker_->ContainsHandle(handle)) {
1144 NavigationController* tab = tab_tracker_->GetResource(handle); 1159 NavigationController* tab = tab_tracker_->GetResource(handle);
1145 1160
1146 // Simulate what a user would do. Activate the tab and then navigate. 1161 // Simulate what a user would do. Activate the tab and then navigate.
1147 // We could allow navigating in a background tab in future. 1162 // We could allow navigating in a background tab in future.
1148 Browser* browser = FindAndActivateTab(tab); 1163 Browser* browser = FindAndActivateTab(tab);
1149 1164
1150 if (browser) { 1165 if (browser) {
1151 // Don't add any listener unless a callback mechanism is desired. 1166 // Don't add any listener unless a callback mechanism is desired.
1152 // TODO(vibhor): Do this if such a requirement arises in future. 1167 // TODO(vibhor): Do this if such a requirement arises in future.
1153 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED); 1168 browser->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
1154 *status = true; 1169 *status = true;
1155 } 1170 }
1156 } 1171 }
1157 } 1172 }
1158 1173
1159 void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) { 1174 void AutomationProvider::GoBack(int handle, IPC::Message* reply_message) {
1160 if (tab_tracker_->ContainsHandle(handle)) { 1175 if (tab_tracker_->ContainsHandle(handle)) {
1161 NavigationController* tab = tab_tracker_->GetResource(handle); 1176 NavigationController* tab = tab_tracker_->GetResource(handle);
1162 Browser* browser = FindAndActivateTab(tab); 1177 Browser* browser = FindAndActivateTab(tab);
1163 if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) { 1178 if (browser && browser->command_updater()->IsCommandEnabled(IDC_BACK)) {
1164 AddNavigationStatusListener(tab, reply_message); 1179 AddNavigationStatusListener(tab, reply_message, 1);
1165 browser->GoBack(CURRENT_TAB); 1180 browser->GoBack(CURRENT_TAB);
1166 return; 1181 return;
1167 } 1182 }
1168 } 1183 }
1169 1184
1170 AutomationMsg_GoBack::WriteReplyParams( 1185 AutomationMsg_GoBack::WriteReplyParams(
1171 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); 1186 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1172 Send(reply_message); 1187 Send(reply_message);
1173 } 1188 }
1174 1189
1175 void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) { 1190 void AutomationProvider::GoForward(int handle, IPC::Message* reply_message) {
1176 if (tab_tracker_->ContainsHandle(handle)) { 1191 if (tab_tracker_->ContainsHandle(handle)) {
1177 NavigationController* tab = tab_tracker_->GetResource(handle); 1192 NavigationController* tab = tab_tracker_->GetResource(handle);
1178 Browser* browser = FindAndActivateTab(tab); 1193 Browser* browser = FindAndActivateTab(tab);
1179 if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) { 1194 if (browser && browser->command_updater()->IsCommandEnabled(IDC_FORWARD)) {
1180 AddNavigationStatusListener(tab, reply_message); 1195 AddNavigationStatusListener(tab, reply_message, 1);
1181 browser->GoForward(CURRENT_TAB); 1196 browser->GoForward(CURRENT_TAB);
1182 return; 1197 return;
1183 } 1198 }
1184 } 1199 }
1185 1200
1186 AutomationMsg_GoForward::WriteReplyParams( 1201 AutomationMsg_GoForward::WriteReplyParams(
1187 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); 1202 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1188 Send(reply_message); 1203 Send(reply_message);
1189 } 1204 }
1190 1205
1191 void AutomationProvider::Reload(int handle, IPC::Message* reply_message) { 1206 void AutomationProvider::Reload(int handle, IPC::Message* reply_message) {
1192 if (tab_tracker_->ContainsHandle(handle)) { 1207 if (tab_tracker_->ContainsHandle(handle)) {
1193 NavigationController* tab = tab_tracker_->GetResource(handle); 1208 NavigationController* tab = tab_tracker_->GetResource(handle);
1194 Browser* browser = FindAndActivateTab(tab); 1209 Browser* browser = FindAndActivateTab(tab);
1195 if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) { 1210 if (browser && browser->command_updater()->IsCommandEnabled(IDC_RELOAD)) {
1196 AddNavigationStatusListener(tab, reply_message); 1211 AddNavigationStatusListener(tab, reply_message, 1);
1197 browser->Reload(); 1212 browser->Reload();
1198 return; 1213 return;
1199 } 1214 }
1200 } 1215 }
1201 1216
1202 AutomationMsg_Reload::WriteReplyParams( 1217 AutomationMsg_Reload::WriteReplyParams(
1203 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); 1218 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
1204 Send(reply_message); 1219 Send(reply_message);
1205 } 1220 }
1206 1221
1207 void AutomationProvider::SetAuth(int tab_handle, 1222 void AutomationProvider::SetAuth(int tab_handle,
1208 const std::wstring& username, 1223 const std::wstring& username,
1209 const std::wstring& password, 1224 const std::wstring& password,
1210 IPC::Message* reply_message) { 1225 IPC::Message* reply_message) {
1211 if (tab_tracker_->ContainsHandle(tab_handle)) { 1226 if (tab_tracker_->ContainsHandle(tab_handle)) {
1212 NavigationController* tab = tab_tracker_->GetResource(tab_handle); 1227 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
1213 LoginHandlerMap::iterator iter = login_handler_map_.find(tab); 1228 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
1214 1229
1215 if (iter != login_handler_map_.end()) { 1230 if (iter != login_handler_map_.end()) {
1216 // If auth is needed again after this, assume login has failed. This is 1231 // If auth is needed again after this, assume login has failed. This is
1217 // not strictly correct, because a navigation can require both proxy and 1232 // not strictly correct, because a navigation can require both proxy and
1218 // server auth, but it should be OK for now. 1233 // server auth, but it should be OK for now.
1219 LoginHandler* handler = iter->second; 1234 LoginHandler* handler = iter->second;
1220 AddNavigationStatusListener(tab, reply_message); 1235 AddNavigationStatusListener(tab, reply_message, 1);
1221 handler->SetAuth(username, password); 1236 handler->SetAuth(username, password);
1222 return; 1237 return;
1223 } 1238 }
1224 } 1239 }
1225 1240
1226 AutomationMsg_SetAuth::WriteReplyParams( 1241 AutomationMsg_SetAuth::WriteReplyParams(
1227 reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); 1242 reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED);
1228 Send(reply_message); 1243 Send(reply_message);
1229 } 1244 }
1230 1245
1231 void AutomationProvider::CancelAuth(int tab_handle, 1246 void AutomationProvider::CancelAuth(int tab_handle,
1232 IPC::Message* reply_message) { 1247 IPC::Message* reply_message) {
1233 if (tab_tracker_->ContainsHandle(tab_handle)) { 1248 if (tab_tracker_->ContainsHandle(tab_handle)) {
1234 NavigationController* tab = tab_tracker_->GetResource(tab_handle); 1249 NavigationController* tab = tab_tracker_->GetResource(tab_handle);
1235 LoginHandlerMap::iterator iter = login_handler_map_.find(tab); 1250 LoginHandlerMap::iterator iter = login_handler_map_.find(tab);
1236 1251
1237 if (iter != login_handler_map_.end()) { 1252 if (iter != login_handler_map_.end()) {
1238 // If auth is needed again after this, something is screwy. 1253 // If auth is needed again after this, something is screwy.
1239 LoginHandler* handler = iter->second; 1254 LoginHandler* handler = iter->second;
1240 AddNavigationStatusListener(tab, reply_message); 1255 AddNavigationStatusListener(tab, reply_message, 1);
1241 handler->CancelAuth(); 1256 handler->CancelAuth();
1242 return; 1257 return;
1243 } 1258 }
1244 } 1259 }
1245 1260
1246 AutomationMsg_CancelAuth::WriteReplyParams( 1261 AutomationMsg_CancelAuth::WriteReplyParams(
1247 reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED); 1262 reply_message, AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED);
1248 Send(reply_message); 1263 Send(reply_message);
1249 } 1264 }
1250 1265
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 } 2282 }
2268 #endif // defined(OS_WIN) 2283 #endif // defined(OS_WIN)
2269 2284
2270 void AutomationProvider::ShowInterstitialPage(int tab_handle, 2285 void AutomationProvider::ShowInterstitialPage(int tab_handle,
2271 const std::string& html_text, 2286 const std::string& html_text,
2272 IPC::Message* reply_message) { 2287 IPC::Message* reply_message) {
2273 if (tab_tracker_->ContainsHandle(tab_handle)) { 2288 if (tab_tracker_->ContainsHandle(tab_handle)) {
2274 NavigationController* controller = tab_tracker_->GetResource(tab_handle); 2289 NavigationController* controller = tab_tracker_->GetResource(tab_handle);
2275 TabContents* tab_contents = controller->tab_contents(); 2290 TabContents* tab_contents = controller->tab_contents();
2276 2291
2277 AddNavigationStatusListener(controller, reply_message); 2292 AddNavigationStatusListener(controller, reply_message, 1);
2278 AutomationInterstitialPage* interstitial = 2293 AutomationInterstitialPage* interstitial =
2279 new AutomationInterstitialPage(tab_contents, 2294 new AutomationInterstitialPage(tab_contents,
2280 GURL("about:interstitial"), 2295 GURL("about:interstitial"),
2281 html_text); 2296 html_text);
2282 interstitial->Show(); 2297 interstitial->Show();
2283 return; 2298 return;
2284 } 2299 }
2285 2300
2286 AutomationMsg_ShowInterstitialPage::WriteReplyParams( 2301 AutomationMsg_ShowInterstitialPage::WriteReplyParams(
2287 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); 2302 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 IPC::Message* reply_message) { 2480 IPC::Message* reply_message) {
2466 if (tab_tracker_->ContainsHandle(handle)) { 2481 if (tab_tracker_->ContainsHandle(handle)) {
2467 NavigationController* tab = tab_tracker_->GetResource(handle); 2482 NavigationController* tab = tab_tracker_->GetResource(handle);
2468 NavigationEntry* entry = tab->GetActiveEntry(); 2483 NavigationEntry* entry = tab->GetActiveEntry();
2469 if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) { 2484 if (entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE) {
2470 TabContents* tab_contents = tab->tab_contents(); 2485 TabContents* tab_contents = tab->tab_contents();
2471 InterstitialPage* ssl_blocking_page = 2486 InterstitialPage* ssl_blocking_page =
2472 InterstitialPage::GetInterstitialPage(tab_contents); 2487 InterstitialPage::GetInterstitialPage(tab_contents);
2473 if (ssl_blocking_page) { 2488 if (ssl_blocking_page) {
2474 if (proceed) { 2489 if (proceed) {
2475 AddNavigationStatusListener(tab, reply_message); 2490 AddNavigationStatusListener(tab, reply_message, 1);
2476 ssl_blocking_page->Proceed(); 2491 ssl_blocking_page->Proceed();
2477 return; 2492 return;
2478 } 2493 }
2479 ssl_blocking_page->DontProceed(); 2494 ssl_blocking_page->DontProceed();
2480 AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams( 2495 AutomationMsg_ActionOnSSLBlockingPage::WriteReplyParams(
2481 reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS); 2496 reply_message, AUTOMATION_MSG_NAVIGATION_SUCCESS);
2482 Send(reply_message); 2497 Send(reply_message);
2483 return; 2498 return;
2484 } 2499 }
2485 } 2500 }
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
2770 int info_bar_index, 2785 int info_bar_index,
2771 bool wait_for_navigation, 2786 bool wait_for_navigation,
2772 IPC::Message* reply_message) { 2787 IPC::Message* reply_message) {
2773 bool success = false; 2788 bool success = false;
2774 if (tab_tracker_->ContainsHandle(handle)) { 2789 if (tab_tracker_->ContainsHandle(handle)) {
2775 NavigationController* nav_controller = tab_tracker_->GetResource(handle); 2790 NavigationController* nav_controller = tab_tracker_->GetResource(handle);
2776 if (nav_controller) { 2791 if (nav_controller) {
2777 int count = nav_controller->tab_contents()->infobar_delegate_count(); 2792 int count = nav_controller->tab_contents()->infobar_delegate_count();
2778 if (info_bar_index >= 0 && info_bar_index < count) { 2793 if (info_bar_index >= 0 && info_bar_index < count) {
2779 if (wait_for_navigation) { 2794 if (wait_for_navigation) {
2780 AddNavigationStatusListener(nav_controller, reply_message); 2795 AddNavigationStatusListener(nav_controller, reply_message, 1);
2781 } 2796 }
2782 InfoBarDelegate* delegate = 2797 InfoBarDelegate* delegate =
2783 nav_controller->tab_contents()->GetInfoBarDelegateAt( 2798 nav_controller->tab_contents()->GetInfoBarDelegateAt(
2784 info_bar_index); 2799 info_bar_index);
2785 if (delegate->AsConfirmInfoBarDelegate()) 2800 if (delegate->AsConfirmInfoBarDelegate())
2786 delegate->AsConfirmInfoBarDelegate()->Accept(); 2801 delegate->AsConfirmInfoBarDelegate()->Accept();
2787 success = true; 2802 success = true;
2788 } 2803 }
2789 } 2804 }
2790 } 2805 }
(...skipping 16 matching lines...) Expand all
2807 controller = tab_tracker_->GetResource(handle); 2822 controller = tab_tracker_->GetResource(handle);
2808 2823
2809 Time time = tab_tracker_->GetLastNavigationTime(handle); 2824 Time time = tab_tracker_->GetLastNavigationTime(handle);
2810 if (time.ToInternalValue() > last_navigation_time || !controller) { 2825 if (time.ToInternalValue() > last_navigation_time || !controller) {
2811 AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message, 2826 AutomationMsg_WaitForNavigation::WriteReplyParams(reply_message,
2812 controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR : 2827 controller == NULL ? AUTOMATION_MSG_NAVIGATION_ERROR :
2813 AUTOMATION_MSG_NAVIGATION_SUCCESS); 2828 AUTOMATION_MSG_NAVIGATION_SUCCESS);
2814 return; 2829 return;
2815 } 2830 }
2816 2831
2817 AddNavigationStatusListener(controller, reply_message); 2832 AddNavigationStatusListener(controller, reply_message, 1);
2818 } 2833 }
2819 2834
2820 void AutomationProvider::SetIntPreference(int handle, 2835 void AutomationProvider::SetIntPreference(int handle,
2821 const std::wstring& name, 2836 const std::wstring& name,
2822 int value, 2837 int value,
2823 bool* success) { 2838 bool* success) {
2824 *success = false; 2839 *success = false;
2825 if (browser_tracker_->ContainsHandle(handle)) { 2840 if (browser_tracker_->ContainsHandle(handle)) {
2826 Browser* browser = browser_tracker_->GetResource(handle); 2841 Browser* browser = browser_tracker_->GetResource(handle);
2827 browser->profile()->GetPrefs()->SetInteger(name.c_str(), value); 2842 browser->profile()->GetPrefs()->SetInteger(name.c_str(), value);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 NOTREACHED(); 3080 NOTREACHED();
3066 return NULL; 3081 return NULL;
3067 } 3082 }
3068 3083
3069 RenderViewHost* view_host = tab_contents->render_view_host(); 3084 RenderViewHost* view_host = tab_contents->render_view_host();
3070 return view_host; 3085 return view_host;
3071 } 3086 }
3072 3087
3073 return NULL; 3088 return NULL;
3074 } 3089 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.h ('k') | chrome/browser/errorpage_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698