OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 if (redirect_query_) { | 710 if (redirect_query_) { |
711 LOG(ERROR) << "Can only handle one redirect query at once."; | 711 LOG(ERROR) << "Can only handle one redirect query at once."; |
712 } else if (tab_tracker_->ContainsHandle(tab_handle)) { | 712 } else if (tab_tracker_->ContainsHandle(tab_handle)) { |
713 NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 713 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
714 HistoryService* history_service = | 714 HistoryService* history_service = |
715 tab->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 715 tab->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
716 | 716 |
717 DCHECK(history_service) << "Tab " << tab_handle << "'s profile " << | 717 DCHECK(history_service) << "Tab " << tab_handle << "'s profile " << |
718 "has no history service"; | 718 "has no history service"; |
719 if (history_service) { | 719 if (history_service) { |
720 DCHECK(reply_message_ == NULL); | 720 DCHECK(!reply_message_); |
721 reply_message_ = reply_message; | 721 reply_message_ = reply_message; |
722 // Schedule a history query for redirects. The response will be sent | 722 // Schedule a history query for redirects. The response will be sent |
723 // asynchronously from the callback the history system uses to notify us | 723 // asynchronously from the callback the history system uses to notify us |
724 // that it's done: OnRedirectQueryComplete. | 724 // that it's done: OnRedirectQueryComplete. |
725 redirect_query_ = history_service->QueryRedirectsFrom( | 725 redirect_query_ = history_service->QueryRedirectsFrom( |
726 source_url, &consumer_, | 726 source_url, &consumer_, |
727 NewCallback(this, | 727 NewCallback(this, |
728 &TestingAutomationProvider::OnRedirectQueryComplete)); | 728 &TestingAutomationProvider::OnRedirectQueryComplete)); |
729 return; // Response will be sent when query completes. | 729 return; // Response will be sent when query completes. |
730 } | 730 } |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 | 1129 |
1130 // Set the routing id of this message with the controller. | 1130 // Set the routing id of this message with the controller. |
1131 // This routing id needs to be remembered for the reverse | 1131 // This routing id needs to be remembered for the reverse |
1132 // communication while sending back the response of | 1132 // communication while sending back the response of |
1133 // this javascript execution. | 1133 // this javascript execution. |
1134 std::string set_automation_id; | 1134 std::string set_automation_id; |
1135 base::SStringPrintf(&set_automation_id, | 1135 base::SStringPrintf(&set_automation_id, |
1136 "window.domAutomationController.setAutomationId(%d);", | 1136 "window.domAutomationController.setAutomationId(%d);", |
1137 reply_message->routing_id()); | 1137 reply_message->routing_id()); |
1138 | 1138 |
1139 DCHECK(reply_message_ == NULL); | 1139 DCHECK(!reply_message_); |
1140 reply_message_ = reply_message; | 1140 reply_message_ = reply_message; |
1141 | 1141 |
1142 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | 1142 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
1143 WideToUTF16Hack(frame_xpath), UTF8ToUTF16(set_automation_id)); | 1143 WideToUTF16Hack(frame_xpath), UTF8ToUTF16(set_automation_id)); |
1144 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | 1144 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
1145 WideToUTF16Hack(frame_xpath), WideToUTF16Hack(script)); | 1145 WideToUTF16Hack(frame_xpath), WideToUTF16Hack(script)); |
1146 } | 1146 } |
1147 | 1147 |
1148 void TestingAutomationProvider::GetConstrainedWindowCount(int handle, | 1148 void TestingAutomationProvider::GetConstrainedWindowCount(int handle, |
1149 int* count) { | 1149 int* count) { |
1150 *count = -1; // -1 is the error code | 1150 *count = -1; // -1 is the error code |
1151 if (tab_tracker_->ContainsHandle(handle)) { | 1151 if (tab_tracker_->ContainsHandle(handle)) { |
1152 NavigationController* nav_controller = tab_tracker_->GetResource(handle); | 1152 NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
1153 TabContents* tab_contents = nav_controller->tab_contents(); | 1153 TabContents* tab_contents = nav_controller->tab_contents(); |
1154 if (tab_contents) | 1154 if (tab_contents) |
1155 *count = static_cast<int>(tab_contents->child_windows_.size()); | 1155 *count = static_cast<int>(tab_contents->child_windows_.size()); |
1156 } | 1156 } |
1157 } | 1157 } |
1158 | 1158 |
1159 void TestingAutomationProvider::HandleInspectElementRequest( | 1159 void TestingAutomationProvider::HandleInspectElementRequest( |
1160 int handle, int x, int y, IPC::Message* reply_message) { | 1160 int handle, int x, int y, IPC::Message* reply_message) { |
1161 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); | 1161 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
1162 if (tab_contents) { | 1162 if (tab_contents) { |
1163 DCHECK(reply_message_ == NULL); | 1163 DCHECK(!reply_message_); |
1164 reply_message_ = reply_message; | 1164 reply_message_ = reply_message; |
1165 | 1165 |
1166 DevToolsManager::GetInstance()->InspectElement( | 1166 DevToolsManager::GetInstance()->InspectElement( |
1167 tab_contents->render_view_host(), x, y); | 1167 tab_contents->render_view_host(), x, y); |
1168 } else { | 1168 } else { |
1169 AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); | 1169 AutomationMsg_InspectElement::WriteReplyParams(reply_message, -1); |
1170 Send(reply_message); | 1170 Send(reply_message); |
1171 } | 1171 } |
1172 } | 1172 } |
1173 | 1173 |
(...skipping 3443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4617 IPC::Message* reply_message) { | 4617 IPC::Message* reply_message) { |
4618 new WaitForProcessLauncherThreadToGoIdleObserver(this, reply_message); | 4618 new WaitForProcessLauncherThreadToGoIdleObserver(this, reply_message); |
4619 } | 4619 } |
4620 | 4620 |
4621 // TODO(brettw) change this to accept GURLs when history supports it | 4621 // TODO(brettw) change this to accept GURLs when history supports it |
4622 void TestingAutomationProvider::OnRedirectQueryComplete( | 4622 void TestingAutomationProvider::OnRedirectQueryComplete( |
4623 HistoryService::Handle request_handle, | 4623 HistoryService::Handle request_handle, |
4624 GURL from_url, | 4624 GURL from_url, |
4625 bool success, | 4625 bool success, |
4626 history::RedirectList* redirects) { | 4626 history::RedirectList* redirects) { |
4627 DCHECK(request_handle == redirect_query_); | 4627 DCHECK_EQ(request_handle, redirect_query_); |
4628 DCHECK(reply_message_ != NULL); | 4628 DCHECK(reply_message_ != NULL); |
4629 | 4629 |
4630 std::vector<GURL> redirects_gurl; | 4630 std::vector<GURL> redirects_gurl; |
4631 reply_message_->WriteBool(success); | 4631 reply_message_->WriteBool(success); |
4632 if (success) { | 4632 if (success) { |
4633 for (size_t i = 0; i < redirects->size(); i++) | 4633 for (size_t i = 0; i < redirects->size(); i++) |
4634 redirects_gurl.push_back(redirects->at(i)); | 4634 redirects_gurl.push_back(redirects->at(i)); |
4635 } | 4635 } |
4636 | 4636 |
4637 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); | 4637 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
(...skipping 15 matching lines...) Expand all Loading... |
4653 // If you change this, update Observer for NotificationType::SESSION_END | 4653 // If you change this, update Observer for NotificationType::SESSION_END |
4654 // below. | 4654 // below. |
4655 MessageLoop::current()->PostTask(FROM_HERE, | 4655 MessageLoop::current()->PostTask(FROM_HERE, |
4656 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 4656 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
4657 } | 4657 } |
4658 } | 4658 } |
4659 | 4659 |
4660 void TestingAutomationProvider::OnRemoveProvider() { | 4660 void TestingAutomationProvider::OnRemoveProvider() { |
4661 AutomationProviderList::GetInstance()->RemoveProvider(this); | 4661 AutomationProviderList::GetInstance()->RemoveProvider(this); |
4662 } | 4662 } |
OLD | NEW |