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 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 return; | 640 return; |
641 } | 641 } |
642 } | 642 } |
643 | 643 |
644 AutomationMsg_Reload::WriteReplyParams( | 644 AutomationMsg_Reload::WriteReplyParams( |
645 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); | 645 reply_message, AUTOMATION_MSG_NAVIGATION_ERROR); |
646 Send(reply_message); | 646 Send(reply_message); |
647 } | 647 } |
648 | 648 |
649 void TestingAutomationProvider::SetAuth(int tab_handle, | 649 void TestingAutomationProvider::SetAuth(int tab_handle, |
650 const std::wstring& username, | 650 const string16& username, |
651 const std::wstring& password, | 651 const string16& password, |
652 IPC::Message* reply_message) { | 652 IPC::Message* reply_message) { |
653 if (tab_tracker_->ContainsHandle(tab_handle)) { | 653 if (tab_tracker_->ContainsHandle(tab_handle)) { |
654 NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 654 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
655 LoginHandlerMap::iterator iter = login_handler_map_.find(tab); | 655 LoginHandlerMap::iterator iter = login_handler_map_.find(tab); |
656 | 656 |
657 if (iter != login_handler_map_.end()) { | 657 if (iter != login_handler_map_.end()) { |
658 // If auth is needed again after this, assume login has failed. This is | 658 // If auth is needed again after this, assume login has failed. This is |
659 // not strictly correct, because a navigation can require both proxy and | 659 // not strictly correct, because a navigation can require both proxy and |
660 // server auth, but it should be OK for now. | 660 // server auth, but it should be OK for now. |
661 LoginHandler* handler = iter->second; | 661 LoginHandler* handler = iter->second; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 TabContents* tab_contents = | 928 TabContents* tab_contents = |
929 tab_tracker_->GetResource(handle)->tab_contents(); | 929 tab_tracker_->GetResource(handle)->tab_contents(); |
930 RenderProcessHost* rph = tab_contents->GetRenderProcessHost(); | 930 RenderProcessHost* rph = tab_contents->GetRenderProcessHost(); |
931 if (rph) | 931 if (rph) |
932 *process_id = base::GetProcId(rph->GetHandle()); | 932 *process_id = base::GetProcId(rph->GetHandle()); |
933 } | 933 } |
934 } | 934 } |
935 | 935 |
936 void TestingAutomationProvider::GetTabTitle(int handle, | 936 void TestingAutomationProvider::GetTabTitle(int handle, |
937 int* title_string_size, | 937 int* title_string_size, |
938 std::wstring* title) { | 938 string16* title) { |
939 *title_string_size = -1; // -1 is the error code | 939 *title_string_size = -1; // -1 is the error code |
940 if (tab_tracker_->ContainsHandle(handle)) { | 940 if (tab_tracker_->ContainsHandle(handle)) { |
941 NavigationController* tab = tab_tracker_->GetResource(handle); | 941 NavigationController* tab = tab_tracker_->GetResource(handle); |
942 NavigationEntry* entry = tab->GetActiveEntry(); | 942 NavigationEntry* entry = tab->GetActiveEntry(); |
943 if (entry != NULL) { | 943 if (entry != NULL) { |
944 *title = UTF16ToWideHack(entry->title()); | 944 *title = entry->title(); |
945 } else { | 945 } else { |
946 *title = std::wstring(); | 946 *title = string16(); |
947 } | 947 } |
948 *title_string_size = static_cast<int>(title->size()); | 948 *title_string_size = static_cast<int>(title->size()); |
949 } | 949 } |
950 } | 950 } |
951 | 951 |
952 void TestingAutomationProvider::GetTabIndex(int handle, int* tabstrip_index) { | 952 void TestingAutomationProvider::GetTabIndex(int handle, int* tabstrip_index) { |
953 *tabstrip_index = -1; // -1 is the error code | 953 *tabstrip_index = -1; // -1 is the error code |
954 | 954 |
955 if (tab_tracker_->ContainsHandle(handle)) { | 955 if (tab_tracker_->ContainsHandle(handle)) { |
956 NavigationController* tab = tab_tracker_->GetResource(handle); | 956 NavigationController* tab = tab_tracker_->GetResource(handle); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 *query_in_progress = false; | 1109 *query_in_progress = false; |
1110 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { | 1110 if (autocomplete_edit_tracker_->ContainsHandle(autocomplete_edit_handle)) { |
1111 *query_in_progress = autocomplete_edit_tracker_-> | 1111 *query_in_progress = autocomplete_edit_tracker_-> |
1112 GetResource(autocomplete_edit_handle)->model()->query_in_progress(); | 1112 GetResource(autocomplete_edit_handle)->model()->query_in_progress(); |
1113 *success = true; | 1113 *success = true; |
1114 } | 1114 } |
1115 } | 1115 } |
1116 | 1116 |
1117 void TestingAutomationProvider::ExecuteJavascript( | 1117 void TestingAutomationProvider::ExecuteJavascript( |
1118 int handle, | 1118 int handle, |
1119 const std::wstring& frame_xpath, | 1119 const string16& frame_xpath, |
1120 const std::wstring& script, | 1120 const string16& script, |
1121 IPC::Message* reply_message) { | 1121 IPC::Message* reply_message) { |
1122 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); | 1122 TabContents* tab_contents = GetTabContentsForHandle(handle, NULL); |
1123 if (!tab_contents) { | 1123 if (!tab_contents) { |
1124 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); | 1124 AutomationMsg_DomOperation::WriteReplyParams(reply_message, std::string()); |
1125 Send(reply_message); | 1125 Send(reply_message); |
1126 return; | 1126 return; |
1127 } | 1127 } |
1128 | 1128 |
1129 // Set the routing id of this message with the controller. | 1129 // Set the routing id of this message with the controller. |
1130 // This routing id needs to be remembered for the reverse | 1130 // This routing id needs to be remembered for the reverse |
1131 // communication while sending back the response of | 1131 // communication while sending back the response of |
1132 // this javascript execution. | 1132 // this javascript execution. |
1133 std::string set_automation_id; | 1133 std::string set_automation_id; |
1134 base::SStringPrintf(&set_automation_id, | 1134 base::SStringPrintf(&set_automation_id, |
1135 "window.domAutomationController.setAutomationId(%d);", | 1135 "window.domAutomationController.setAutomationId(%d);", |
1136 reply_message->routing_id()); | 1136 reply_message->routing_id()); |
1137 | 1137 |
1138 DCHECK(reply_message_ == NULL); | 1138 DCHECK(reply_message_ == NULL); |
1139 reply_message_ = reply_message; | 1139 reply_message_ = reply_message; |
1140 | 1140 |
1141 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | 1141 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
1142 frame_xpath, UTF8ToWide(set_automation_id)); | 1142 frame_xpath, UTF8ToUTF16(set_automation_id)); |
1143 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( | 1143 tab_contents->render_view_host()->ExecuteJavascriptInWebFrame( |
1144 frame_xpath, script); | 1144 frame_xpath, script); |
1145 } | 1145 } |
1146 | 1146 |
1147 void TestingAutomationProvider::GetConstrainedWindowCount(int handle, | 1147 void TestingAutomationProvider::GetConstrainedWindowCount(int handle, |
1148 int* count) { | 1148 int* count) { |
1149 *count = -1; // -1 is the error code | 1149 *count = -1; // -1 is the error code |
1150 if (tab_tracker_->ContainsHandle(handle)) { | 1150 if (tab_tracker_->ContainsHandle(handle)) { |
1151 NavigationController* nav_controller = tab_tracker_->GetResource(handle); | 1151 NavigationController* nav_controller = tab_tracker_->GetResource(handle); |
1152 TabContents* tab_contents = nav_controller->tab_contents(); | 1152 TabContents* tab_contents = nav_controller->tab_contents(); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 // The observer will delete itself when done. | 1516 // The observer will delete itself when done. |
1517 new AutomationProviderBookmarkModelObserver(this, reply_message, | 1517 new AutomationProviderBookmarkModelObserver(this, reply_message, |
1518 model); | 1518 model); |
1519 } | 1519 } |
1520 } | 1520 } |
1521 } | 1521 } |
1522 | 1522 |
1523 void TestingAutomationProvider::AddBookmarkGroup(int handle, | 1523 void TestingAutomationProvider::AddBookmarkGroup(int handle, |
1524 int64 parent_id, | 1524 int64 parent_id, |
1525 int index, | 1525 int index, |
1526 std::wstring title, | 1526 const string16& title, |
1527 bool* success) { | 1527 bool* success) { |
1528 if (browser_tracker_->ContainsHandle(handle)) { | 1528 if (browser_tracker_->ContainsHandle(handle)) { |
1529 Browser* browser = browser_tracker_->GetResource(handle); | 1529 Browser* browser = browser_tracker_->GetResource(handle); |
1530 if (browser) { | 1530 if (browser) { |
1531 BookmarkModel* model = browser->profile()->GetBookmarkModel(); | 1531 BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
1532 if (!model->IsLoaded()) { | 1532 if (!model->IsLoaded()) { |
1533 *success = false; | 1533 *success = false; |
1534 return; | 1534 return; |
1535 } | 1535 } |
1536 const BookmarkNode* parent = model->GetNodeByID(parent_id); | 1536 const BookmarkNode* parent = model->GetNodeByID(parent_id); |
1537 DCHECK(parent); | 1537 DCHECK(parent); |
1538 if (parent) { | 1538 if (parent) { |
1539 const BookmarkNode* child = model->AddGroup(parent, index, | 1539 const BookmarkNode* child = model->AddGroup(parent, index, title); |
1540 WideToUTF16Hack(title)); | |
1541 DCHECK(child); | 1540 DCHECK(child); |
1542 if (child) | 1541 if (child) |
1543 *success = true; | 1542 *success = true; |
1544 } | 1543 } |
1545 } | 1544 } |
1546 } | 1545 } |
1547 *success = false; | 1546 *success = false; |
1548 } | 1547 } |
1549 | 1548 |
1550 void TestingAutomationProvider::AddBookmarkURL(int handle, | 1549 void TestingAutomationProvider::AddBookmarkURL(int handle, |
1551 int64 parent_id, | 1550 int64 parent_id, |
1552 int index, | 1551 int index, |
1553 std::wstring title, | 1552 const string16& title, |
1554 const GURL& url, | 1553 const GURL& url, |
1555 bool* success) { | 1554 bool* success) { |
1556 if (browser_tracker_->ContainsHandle(handle)) { | 1555 if (browser_tracker_->ContainsHandle(handle)) { |
1557 Browser* browser = browser_tracker_->GetResource(handle); | 1556 Browser* browser = browser_tracker_->GetResource(handle); |
1558 if (browser) { | 1557 if (browser) { |
1559 BookmarkModel* model = browser->profile()->GetBookmarkModel(); | 1558 BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
1560 if (!model->IsLoaded()) { | 1559 if (!model->IsLoaded()) { |
1561 *success = false; | 1560 *success = false; |
1562 return; | 1561 return; |
1563 } | 1562 } |
1564 const BookmarkNode* parent = model->GetNodeByID(parent_id); | 1563 const BookmarkNode* parent = model->GetNodeByID(parent_id); |
1565 DCHECK(parent); | 1564 DCHECK(parent); |
1566 if (parent) { | 1565 if (parent) { |
1567 const BookmarkNode* child = model->AddURL(parent, index, | 1566 const BookmarkNode* child = model->AddURL(parent, index, title, url); |
1568 WideToUTF16Hack(title), url); | |
1569 DCHECK(child); | 1567 DCHECK(child); |
1570 if (child) | 1568 if (child) |
1571 *success = true; | 1569 *success = true; |
1572 } | 1570 } |
1573 } | 1571 } |
1574 } | 1572 } |
1575 *success = false; | 1573 *success = false; |
1576 } | 1574 } |
1577 | 1575 |
1578 void TestingAutomationProvider::ReparentBookmark(int handle, | 1576 void TestingAutomationProvider::ReparentBookmark(int handle, |
(...skipping 17 matching lines...) Expand all Loading... |
1596 model->Move(node, new_parent, index); | 1594 model->Move(node, new_parent, index); |
1597 *success = true; | 1595 *success = true; |
1598 } | 1596 } |
1599 } | 1597 } |
1600 } | 1598 } |
1601 *success = false; | 1599 *success = false; |
1602 } | 1600 } |
1603 | 1601 |
1604 void TestingAutomationProvider::SetBookmarkTitle(int handle, | 1602 void TestingAutomationProvider::SetBookmarkTitle(int handle, |
1605 int64 id, | 1603 int64 id, |
1606 std::wstring title, | 1604 const string16& title, |
1607 bool* success) { | 1605 bool* success) { |
1608 if (browser_tracker_->ContainsHandle(handle)) { | 1606 if (browser_tracker_->ContainsHandle(handle)) { |
1609 Browser* browser = browser_tracker_->GetResource(handle); | 1607 Browser* browser = browser_tracker_->GetResource(handle); |
1610 if (browser) { | 1608 if (browser) { |
1611 BookmarkModel* model = browser->profile()->GetBookmarkModel(); | 1609 BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
1612 if (!model->IsLoaded()) { | 1610 if (!model->IsLoaded()) { |
1613 *success = false; | 1611 *success = false; |
1614 return; | 1612 return; |
1615 } | 1613 } |
1616 const BookmarkNode* node = model->GetNodeByID(id); | 1614 const BookmarkNode* node = model->GetNodeByID(id); |
1617 DCHECK(node); | 1615 DCHECK(node); |
1618 if (node) { | 1616 if (node) { |
1619 model->SetTitle(node, WideToUTF16Hack(title)); | 1617 model->SetTitle(node, title); |
1620 *success = true; | 1618 *success = true; |
1621 } | 1619 } |
1622 } | 1620 } |
1623 } | 1621 } |
1624 *success = false; | 1622 *success = false; |
1625 } | 1623 } |
1626 | 1624 |
1627 void TestingAutomationProvider::SetBookmarkURL(int handle, | 1625 void TestingAutomationProvider::SetBookmarkURL(int handle, |
1628 int64 id, | 1626 int64 id, |
1629 const GURL& url, | 1627 const GURL& url, |
(...skipping 3011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4641 // If you change this, update Observer for NotificationType::SESSION_END | 4639 // If you change this, update Observer for NotificationType::SESSION_END |
4642 // below. | 4640 // below. |
4643 MessageLoop::current()->PostTask(FROM_HERE, | 4641 MessageLoop::current()->PostTask(FROM_HERE, |
4644 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 4642 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
4645 } | 4643 } |
4646 } | 4644 } |
4647 | 4645 |
4648 void TestingAutomationProvider::OnRemoveProvider() { | 4646 void TestingAutomationProvider::OnRemoveProvider() { |
4649 AutomationProviderList::GetInstance()->RemoveProvider(this); | 4647 AutomationProviderList::GetInstance()->RemoveProvider(this); |
4650 } | 4648 } |
OLD | NEW |