| OLD | NEW |
| 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/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "app/message_box_flags.h" | 9 #include "app/message_box_flags.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 if (browser) { | 1580 if (browser) { |
| 1581 BookmarkModel* model = browser->profile()->GetBookmarkModel(); | 1581 BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1582 if (!model->IsLoaded()) { | 1582 if (!model->IsLoaded()) { |
| 1583 *success = false; | 1583 *success = false; |
| 1584 return; | 1584 return; |
| 1585 } | 1585 } |
| 1586 const BookmarkNode* parent = model->GetNodeByID(parent_id); | 1586 const BookmarkNode* parent = model->GetNodeByID(parent_id); |
| 1587 DCHECK(parent); | 1587 DCHECK(parent); |
| 1588 if (parent) { | 1588 if (parent) { |
| 1589 const BookmarkNode* child = model->AddGroup(parent, index, | 1589 const BookmarkNode* child = model->AddGroup(parent, index, |
| 1590 WideToUTF16(title)); | 1590 WideToUTF16Hack(title)); |
| 1591 DCHECK(child); | 1591 DCHECK(child); |
| 1592 if (child) | 1592 if (child) |
| 1593 *success = true; | 1593 *success = true; |
| 1594 } | 1594 } |
| 1595 } | 1595 } |
| 1596 } | 1596 } |
| 1597 *success = false; | 1597 *success = false; |
| 1598 } | 1598 } |
| 1599 | 1599 |
| 1600 void AutomationProvider::AddBookmarkURL(int handle, | 1600 void AutomationProvider::AddBookmarkURL(int handle, |
| 1601 int64 parent_id, int index, | 1601 int64 parent_id, int index, |
| 1602 std::wstring title, const GURL& url, | 1602 std::wstring title, const GURL& url, |
| 1603 bool* success) { | 1603 bool* success) { |
| 1604 if (browser_tracker_->ContainsHandle(handle)) { | 1604 if (browser_tracker_->ContainsHandle(handle)) { |
| 1605 Browser* browser = browser_tracker_->GetResource(handle); | 1605 Browser* browser = browser_tracker_->GetResource(handle); |
| 1606 if (browser) { | 1606 if (browser) { |
| 1607 BookmarkModel* model = browser->profile()->GetBookmarkModel(); | 1607 BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1608 if (!model->IsLoaded()) { | 1608 if (!model->IsLoaded()) { |
| 1609 *success = false; | 1609 *success = false; |
| 1610 return; | 1610 return; |
| 1611 } | 1611 } |
| 1612 const BookmarkNode* parent = model->GetNodeByID(parent_id); | 1612 const BookmarkNode* parent = model->GetNodeByID(parent_id); |
| 1613 DCHECK(parent); | 1613 DCHECK(parent); |
| 1614 if (parent) { | 1614 if (parent) { |
| 1615 const BookmarkNode* child = model->AddURL(parent, index, | 1615 const BookmarkNode* child = model->AddURL(parent, index, |
| 1616 WideToUTF16(title), url); | 1616 WideToUTF16Hack(title), url); |
| 1617 DCHECK(child); | 1617 DCHECK(child); |
| 1618 if (child) | 1618 if (child) |
| 1619 *success = true; | 1619 *success = true; |
| 1620 } | 1620 } |
| 1621 } | 1621 } |
| 1622 } | 1622 } |
| 1623 *success = false; | 1623 *success = false; |
| 1624 } | 1624 } |
| 1625 | 1625 |
| 1626 void AutomationProvider::ReparentBookmark(int handle, | 1626 void AutomationProvider::ReparentBookmark(int handle, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1655 Browser* browser = browser_tracker_->GetResource(handle); | 1655 Browser* browser = browser_tracker_->GetResource(handle); |
| 1656 if (browser) { | 1656 if (browser) { |
| 1657 BookmarkModel* model = browser->profile()->GetBookmarkModel(); | 1657 BookmarkModel* model = browser->profile()->GetBookmarkModel(); |
| 1658 if (!model->IsLoaded()) { | 1658 if (!model->IsLoaded()) { |
| 1659 *success = false; | 1659 *success = false; |
| 1660 return; | 1660 return; |
| 1661 } | 1661 } |
| 1662 const BookmarkNode* node = model->GetNodeByID(id); | 1662 const BookmarkNode* node = model->GetNodeByID(id); |
| 1663 DCHECK(node); | 1663 DCHECK(node); |
| 1664 if (node) { | 1664 if (node) { |
| 1665 model->SetTitle(node, WideToUTF16(title)); | 1665 model->SetTitle(node, WideToUTF16Hack(title)); |
| 1666 *success = true; | 1666 *success = true; |
| 1667 } | 1667 } |
| 1668 } | 1668 } |
| 1669 } | 1669 } |
| 1670 *success = false; | 1670 *success = false; |
| 1671 } | 1671 } |
| 1672 | 1672 |
| 1673 void AutomationProvider::SetBookmarkURL(int handle, | 1673 void AutomationProvider::SetBookmarkURL(int handle, |
| 1674 int64 id, const GURL& url, | 1674 int64 id, const GURL& url, |
| 1675 bool* success) { | 1675 bool* success) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 // Sample json input: { "command": "SetWindowDimensions", | 1719 // Sample json input: { "command": "SetWindowDimensions", |
| 1720 // "x": 20, # optional | 1720 // "x": 20, # optional |
| 1721 // "y": 20, # optional | 1721 // "y": 20, # optional |
| 1722 // "width": 800, # optional | 1722 // "width": 800, # optional |
| 1723 // "height": 600 } # optional | 1723 // "height": 600 } # optional |
| 1724 void AutomationProvider::SetWindowDimensions(Browser* browser, | 1724 void AutomationProvider::SetWindowDimensions(Browser* browser, |
| 1725 DictionaryValue* args, | 1725 DictionaryValue* args, |
| 1726 IPC::Message* reply_message) { | 1726 IPC::Message* reply_message) { |
| 1727 gfx::Rect rect = browser->window()->GetRestoredBounds(); | 1727 gfx::Rect rect = browser->window()->GetRestoredBounds(); |
| 1728 int x, y, width, height; | 1728 int x, y, width, height; |
| 1729 if (args->GetInteger(L"x", &x)) | 1729 if (args->GetInteger("x", &x)) |
| 1730 rect.set_x(x); | 1730 rect.set_x(x); |
| 1731 if (args->GetInteger(L"y", &y)) | 1731 if (args->GetInteger("y", &y)) |
| 1732 rect.set_y(y); | 1732 rect.set_y(y); |
| 1733 if (args->GetInteger(L"width", &width)) | 1733 if (args->GetInteger("width", &width)) |
| 1734 rect.set_width(width); | 1734 rect.set_width(width); |
| 1735 if (args->GetInteger(L"height", &height)) | 1735 if (args->GetInteger("height", &height)) |
| 1736 rect.set_height(height); | 1736 rect.set_height(height); |
| 1737 browser->window()->SetBounds(rect); | 1737 browser->window()->SetBounds(rect); |
| 1738 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 1738 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 1739 } | 1739 } |
| 1740 | 1740 |
| 1741 ListValue* AutomationProvider::GetInfobarsInfo(TabContents* tc) { | 1741 ListValue* AutomationProvider::GetInfobarsInfo(TabContents* tc) { |
| 1742 // Each infobar may have different properties depending on the type. | 1742 // Each infobar may have different properties depending on the type. |
| 1743 ListValue* infobars = new ListValue; | 1743 ListValue* infobars = new ListValue; |
| 1744 for (int infobar_index = 0; | 1744 for (int infobar_index = 0; |
| 1745 infobar_index < tc->infobar_delegate_count(); | 1745 infobar_index < tc->infobar_delegate_count(); |
| 1746 ++infobar_index) { | 1746 ++infobar_index) { |
| 1747 DictionaryValue* infobar_item = new DictionaryValue; | 1747 DictionaryValue* infobar_item = new DictionaryValue; |
| 1748 InfoBarDelegate* infobar = tc->GetInfoBarDelegateAt(infobar_index); | 1748 InfoBarDelegate* infobar = tc->GetInfoBarDelegateAt(infobar_index); |
| 1749 if (infobar->AsConfirmInfoBarDelegate()) { | 1749 if (infobar->AsConfirmInfoBarDelegate()) { |
| 1750 // Also covers ThemeInstalledInfoBarDelegate and | 1750 // Also covers ThemeInstalledInfoBarDelegate and |
| 1751 // CrashedExtensionInfoBarDelegate. | 1751 // CrashedExtensionInfoBarDelegate. |
| 1752 infobar_item->SetString(L"type", "confirm_infobar"); | 1752 infobar_item->SetString("type", "confirm_infobar"); |
| 1753 ConfirmInfoBarDelegate* confirm_infobar = | 1753 ConfirmInfoBarDelegate* confirm_infobar = |
| 1754 infobar->AsConfirmInfoBarDelegate(); | 1754 infobar->AsConfirmInfoBarDelegate(); |
| 1755 infobar_item->SetString(L"text", confirm_infobar->GetMessageText()); | 1755 infobar_item->SetString("text", |
| 1756 infobar_item->SetString(L"link_text", confirm_infobar->GetLinkText()); | 1756 WideToUTF16Hack(confirm_infobar->GetMessageText())); |
| 1757 infobar_item->SetString("link_text", |
| 1758 WideToUTF16Hack(confirm_infobar->GetLinkText())); |
| 1757 ListValue* buttons_list = new ListValue; | 1759 ListValue* buttons_list = new ListValue; |
| 1758 int buttons = confirm_infobar->GetButtons(); | 1760 int buttons = confirm_infobar->GetButtons(); |
| 1759 if (ConfirmInfoBarDelegate::BUTTON_OK & buttons) { | 1761 if (ConfirmInfoBarDelegate::BUTTON_OK & buttons) { |
| 1760 StringValue* button_label = new StringValue( | 1762 StringValue* button_label = new StringValue( |
| 1761 confirm_infobar->GetButtonLabel( | 1763 confirm_infobar->GetButtonLabel( |
| 1762 ConfirmInfoBarDelegate::BUTTON_OK)); | 1764 ConfirmInfoBarDelegate::BUTTON_OK)); |
| 1763 buttons_list->Append(button_label); | 1765 buttons_list->Append(button_label); |
| 1764 } | 1766 } |
| 1765 if (ConfirmInfoBarDelegate::BUTTON_CANCEL & buttons) { | 1767 if (ConfirmInfoBarDelegate::BUTTON_CANCEL & buttons) { |
| 1766 StringValue* button_label = new StringValue( | 1768 StringValue* button_label = new StringValue( |
| 1767 confirm_infobar->GetButtonLabel( | 1769 confirm_infobar->GetButtonLabel( |
| 1768 ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 1770 ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 1769 buttons_list->Append(button_label); | 1771 buttons_list->Append(button_label); |
| 1770 } | 1772 } |
| 1771 infobar_item->Set(L"buttons", buttons_list); | 1773 infobar_item->Set("buttons", buttons_list); |
| 1772 } else if (infobar->AsAlertInfoBarDelegate()) { | 1774 } else if (infobar->AsAlertInfoBarDelegate()) { |
| 1773 infobar_item->SetString(L"type", "alert_infobar"); | 1775 infobar_item->SetString("type", "alert_infobar"); |
| 1774 AlertInfoBarDelegate* alert_infobar = | 1776 AlertInfoBarDelegate* alert_infobar = |
| 1775 infobar->AsAlertInfoBarDelegate(); | 1777 infobar->AsAlertInfoBarDelegate(); |
| 1776 infobar_item->SetString(L"text", alert_infobar->GetMessageText()); | 1778 infobar_item->SetString("text", |
| 1779 WideToUTF16Hack(alert_infobar->GetMessageText())); |
| 1777 } else if (infobar->AsLinkInfoBarDelegate()) { | 1780 } else if (infobar->AsLinkInfoBarDelegate()) { |
| 1778 infobar_item->SetString(L"type", "link_infobar"); | 1781 infobar_item->SetString("type", "link_infobar"); |
| 1779 LinkInfoBarDelegate* link_infobar = infobar->AsLinkInfoBarDelegate(); | 1782 LinkInfoBarDelegate* link_infobar = infobar->AsLinkInfoBarDelegate(); |
| 1780 infobar_item->SetString(L"link_text", link_infobar->GetLinkText()); | 1783 infobar_item->SetString("link_text", |
| 1784 WideToUTF16Hack(link_infobar->GetLinkText())); |
| 1781 } else if (infobar->AsTranslateInfoBarDelegate()) { | 1785 } else if (infobar->AsTranslateInfoBarDelegate()) { |
| 1782 infobar_item->SetString(L"type", "translate_infobar"); | 1786 infobar_item->SetString("type", "translate_infobar"); |
| 1783 TranslateInfoBarDelegate* translate_infobar = | 1787 TranslateInfoBarDelegate* translate_infobar = |
| 1784 infobar->AsTranslateInfoBarDelegate(); | 1788 infobar->AsTranslateInfoBarDelegate(); |
| 1785 infobar_item->SetString(L"original_lang_code", | 1789 infobar_item->SetString("original_lang_code", |
| 1786 translate_infobar->GetOriginalLanguageCode()); | 1790 translate_infobar->GetOriginalLanguageCode()); |
| 1787 infobar_item->SetString(L"target_lang_code", | 1791 infobar_item->SetString("target_lang_code", |
| 1788 translate_infobar->GetTargetLanguageCode()); | 1792 translate_infobar->GetTargetLanguageCode()); |
| 1789 } else if (infobar->AsExtensionInfoBarDelegate()) { | 1793 } else if (infobar->AsExtensionInfoBarDelegate()) { |
| 1790 infobar_item->SetString(L"type", "extension_infobar"); | 1794 infobar_item->SetString("type", "extension_infobar"); |
| 1791 } else { | 1795 } else { |
| 1792 infobar_item->SetString(L"type", "unknown_infobar"); | 1796 infobar_item->SetString("type", "unknown_infobar"); |
| 1793 } | 1797 } |
| 1794 infobars->Append(infobar_item); | 1798 infobars->Append(infobar_item); |
| 1795 } | 1799 } |
| 1796 return infobars; | 1800 return infobars; |
| 1797 } | 1801 } |
| 1798 | 1802 |
| 1799 // Sample json input: { "command": "WaitForInfobarCount", | 1803 // Sample json input: { "command": "WaitForInfobarCount", |
| 1800 // "count": COUNT, | 1804 // "count": COUNT, |
| 1801 // "tab_index": INDEX } | 1805 // "tab_index": INDEX } |
| 1802 // Sample output: {} | 1806 // Sample output: {} |
| 1803 void AutomationProvider::WaitForInfobarCount(Browser* browser, | 1807 void AutomationProvider::WaitForInfobarCount(Browser* browser, |
| 1804 DictionaryValue* args, | 1808 DictionaryValue* args, |
| 1805 IPC::Message* reply_message) { | 1809 IPC::Message* reply_message) { |
| 1806 int tab_index; | 1810 int tab_index; |
| 1807 int count; | 1811 int count; |
| 1808 if (!args->GetInteger(L"count", &count) || count < 0 || | 1812 if (!args->GetInteger("count", &count) || count < 0 || |
| 1809 !args->GetInteger(L"tab_index", &tab_index) || tab_index < 0) { | 1813 !args->GetInteger("tab_index", &tab_index) || tab_index < 0) { |
| 1810 AutomationJSONReply(this, reply_message).SendError( | 1814 AutomationJSONReply(this, reply_message).SendError( |
| 1811 "Missing or invalid args: 'count', 'tab_index'."); | 1815 "Missing or invalid args: 'count', 'tab_index'."); |
| 1812 return; | 1816 return; |
| 1813 } | 1817 } |
| 1814 | 1818 |
| 1815 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); | 1819 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); |
| 1816 // Observer deletes itself. | 1820 // Observer deletes itself. |
| 1817 new WaitForInfobarCountObserver(this, reply_message, tab_contents, count); | 1821 new WaitForInfobarCountObserver(this, reply_message, tab_contents, count); |
| 1818 } | 1822 } |
| 1819 | 1823 |
| 1820 // Sample json input: { "command": "PerformActionOnInfobar", | 1824 // Sample json input: { "command": "PerformActionOnInfobar", |
| 1821 // "action": "dismiss", | 1825 // "action": "dismiss", |
| 1822 // "infobar_index": 0, | 1826 // "infobar_index": 0, |
| 1823 // "tab_index": 0 } | 1827 // "tab_index": 0 } |
| 1824 // Sample output: {} | 1828 // Sample output: {} |
| 1825 void AutomationProvider::PerformActionOnInfobar(Browser* browser, | 1829 void AutomationProvider::PerformActionOnInfobar(Browser* browser, |
| 1826 DictionaryValue* args, | 1830 DictionaryValue* args, |
| 1827 IPC::Message* reply_message) { | 1831 IPC::Message* reply_message) { |
| 1828 AutomationJSONReply reply(this, reply_message); | 1832 AutomationJSONReply reply(this, reply_message); |
| 1829 int tab_index; | 1833 int tab_index; |
| 1830 int infobar_index; | 1834 int infobar_index; |
| 1831 std::string action; | 1835 std::string action; |
| 1832 if (!args->GetInteger(L"tab_index", &tab_index) || | 1836 if (!args->GetInteger("tab_index", &tab_index) || |
| 1833 !args->GetInteger(L"infobar_index", &infobar_index) || | 1837 !args->GetInteger("infobar_index", &infobar_index) || |
| 1834 !args->GetString(L"action", &action)) { | 1838 !args->GetString("action", &action)) { |
| 1835 reply.SendError("Invalid or missing args"); | 1839 reply.SendError("Invalid or missing args"); |
| 1836 return; | 1840 return; |
| 1837 } | 1841 } |
| 1838 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); | 1842 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); |
| 1839 if (!tab_contents) { | 1843 if (!tab_contents) { |
| 1840 reply.SendError(StringPrintf("No such tab at index %d", tab_index)); | 1844 reply.SendError(StringPrintf("No such tab at index %d", tab_index)); |
| 1841 return; | 1845 return; |
| 1842 } | 1846 } |
| 1843 InfoBarDelegate* infobar = NULL; | 1847 InfoBarDelegate* infobar = NULL; |
| 1844 if (infobar_index < 0 || | 1848 if (infobar_index < 0 || |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 virtual void Run() { | 1891 virtual void Run() { |
| 1888 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 1892 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 1889 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { | 1893 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { |
| 1890 // Only add processes which are already started, | 1894 // Only add processes which are already started, |
| 1891 // since we need their handle. | 1895 // since we need their handle. |
| 1892 if ((*iter)->handle() == base::kNullProcessHandle) { | 1896 if ((*iter)->handle() == base::kNullProcessHandle) { |
| 1893 continue; | 1897 continue; |
| 1894 } | 1898 } |
| 1895 ChildProcessInfo* info = *iter; | 1899 ChildProcessInfo* info = *iter; |
| 1896 DictionaryValue* item = new DictionaryValue; | 1900 DictionaryValue* item = new DictionaryValue; |
| 1897 item->SetString(L"name", info->name()); | 1901 item->SetString("name", WideToUTF16Hack(info->name())); |
| 1898 item->SetString(L"type", | 1902 item->SetString("type", |
| 1899 ChildProcessInfo::GetTypeNameInEnglish(info->type())); | 1903 WideToUTF16Hack(ChildProcessInfo::GetTypeNameInEnglish( |
| 1900 item->SetInteger(L"pid", base::GetProcId(info->handle())); | 1904 info->type()))); |
| 1905 item->SetInteger("pid", base::GetProcId(info->handle())); |
| 1901 child_processes_->Append(item); | 1906 child_processes_->Append(item); |
| 1902 } | 1907 } |
| 1903 event_->Signal(); | 1908 event_->Signal(); |
| 1904 } | 1909 } |
| 1905 | 1910 |
| 1906 private: | 1911 private: |
| 1907 base::WaitableEvent* const event_; // weak | 1912 base::WaitableEvent* const event_; // weak |
| 1908 ListValue* child_processes_; | 1913 ListValue* child_processes_; |
| 1909 | 1914 |
| 1910 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); | 1915 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); |
| 1911 }; | 1916 }; |
| 1912 | 1917 |
| 1913 } // namespace | 1918 } // namespace |
| 1914 | 1919 |
| 1915 // Sample json input: { "command": "GetBrowserInfo" } | 1920 // Sample json input: { "command": "GetBrowserInfo" } |
| 1916 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for | 1921 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for |
| 1917 // sample json output. | 1922 // sample json output. |
| 1918 void AutomationProvider::GetBrowserInfo(Browser* browser, | 1923 void AutomationProvider::GetBrowserInfo(Browser* browser, |
| 1919 DictionaryValue* args, | 1924 DictionaryValue* args, |
| 1920 IPC::Message* reply_message) { | 1925 IPC::Message* reply_message) { |
| 1921 DictionaryValue* properties = new DictionaryValue; | 1926 DictionaryValue* properties = new DictionaryValue; |
| 1922 properties->SetString(L"ChromeVersion", chrome::kChromeVersion); | 1927 properties->SetString("ChromeVersion", chrome::kChromeVersion); |
| 1923 properties->SetString(L"BrowserProcessExecutableName", | 1928 properties->SetString("BrowserProcessExecutableName", |
| 1924 chrome::kBrowserProcessExecutableName); | 1929 WideToUTF16Hack(chrome::kBrowserProcessExecutableName)); |
| 1925 properties->SetString(L"HelperProcessExecutableName", | 1930 properties->SetString("HelperProcessExecutableName", |
| 1926 chrome::kHelperProcessExecutableName); | 1931 WideToUTF16Hack(chrome::kHelperProcessExecutableName)); |
| 1927 properties->SetString(L"BrowserProcessExecutablePath", | 1932 properties->SetString("BrowserProcessExecutablePath", |
| 1928 chrome::kBrowserProcessExecutablePath); | 1933 WideToUTF16Hack(chrome::kBrowserProcessExecutablePath)); |
| 1929 properties->SetString(L"HelperProcessExecutablePath", | 1934 properties->SetString("HelperProcessExecutablePath", |
| 1930 chrome::kHelperProcessExecutablePath); | 1935 chrome::kHelperProcessExecutablePath); |
| 1931 properties->SetString(L"command_line_string", | 1936 properties->SetString("command_line_string", |
| 1932 CommandLine::ForCurrentProcess()->command_line_string()); | 1937 CommandLine::ForCurrentProcess()->command_line_string()); |
| 1933 | 1938 |
| 1934 std::string branding; | 1939 std::string branding; |
| 1935 #if defined(GOOGLE_CHROME_BUILD) | 1940 #if defined(GOOGLE_CHROME_BUILD) |
| 1936 branding = "Google Chrome"; | 1941 branding = "Google Chrome"; |
| 1937 #elif defined(CHROMIUM_BUILD) | 1942 #elif defined(CHROMIUM_BUILD) |
| 1938 branding = "Chromium"; | 1943 branding = "Chromium"; |
| 1939 #else | 1944 #else |
| 1940 branding = "Unknown Branding"; | 1945 branding = "Unknown Branding"; |
| 1941 #endif | 1946 #endif |
| 1942 properties->SetString(L"branding", branding); | 1947 properties->SetString("branding", branding); |
| 1943 | 1948 |
| 1944 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 1949 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 1945 return_value->Set(L"properties", properties); | 1950 return_value->Set("properties", properties); |
| 1946 | 1951 |
| 1947 return_value->SetInteger(L"browser_pid", base::GetCurrentProcId()); | 1952 return_value->SetInteger("browser_pid", base::GetCurrentProcId()); |
| 1948 // Add info about all windows in a list of dictionaries, one dictionary | 1953 // Add info about all windows in a list of dictionaries, one dictionary |
| 1949 // item per window. | 1954 // item per window. |
| 1950 ListValue* windows = new ListValue; | 1955 ListValue* windows = new ListValue; |
| 1951 int windex = 0; | 1956 int windex = 0; |
| 1952 for (BrowserList::const_iterator it = BrowserList::begin(); | 1957 for (BrowserList::const_iterator it = BrowserList::begin(); |
| 1953 it != BrowserList::end(); | 1958 it != BrowserList::end(); |
| 1954 ++it, ++windex) { | 1959 ++it, ++windex) { |
| 1955 DictionaryValue* browser_item = new DictionaryValue; | 1960 DictionaryValue* browser_item = new DictionaryValue; |
| 1956 browser = *it; | 1961 browser = *it; |
| 1957 browser_item->SetInteger(L"index", windex); | 1962 browser_item->SetInteger("index", windex); |
| 1958 // Window properties | 1963 // Window properties |
| 1959 gfx::Rect rect = browser->window()->GetRestoredBounds(); | 1964 gfx::Rect rect = browser->window()->GetRestoredBounds(); |
| 1960 browser_item->SetInteger(L"x", rect.x()); | 1965 browser_item->SetInteger("x", rect.x()); |
| 1961 browser_item->SetInteger(L"y", rect.y()); | 1966 browser_item->SetInteger("y", rect.y()); |
| 1962 browser_item->SetInteger(L"width", rect.width()); | 1967 browser_item->SetInteger("width", rect.width()); |
| 1963 browser_item->SetInteger(L"height", rect.height()); | 1968 browser_item->SetInteger("height", rect.height()); |
| 1964 browser_item->SetBoolean(L"fullscreen", | 1969 browser_item->SetBoolean("fullscreen", |
| 1965 browser->window()->IsFullscreen()); | 1970 browser->window()->IsFullscreen()); |
| 1966 browser_item->SetInteger(L"selected_tab", browser->selected_index()); | 1971 browser_item->SetInteger("selected_tab", browser->selected_index()); |
| 1967 browser_item->SetBoolean(L"incognito", | 1972 browser_item->SetBoolean("incognito", |
| 1968 browser->profile()->IsOffTheRecord()); | 1973 browser->profile()->IsOffTheRecord()); |
| 1969 // For each window, add info about all tabs in a list of dictionaries, | 1974 // For each window, add info about all tabs in a list of dictionaries, |
| 1970 // one dictionary item per tab. | 1975 // one dictionary item per tab. |
| 1971 ListValue* tabs = new ListValue; | 1976 ListValue* tabs = new ListValue; |
| 1972 for (int i = 0; i < browser->tab_count(); ++i) { | 1977 for (int i = 0; i < browser->tab_count(); ++i) { |
| 1973 TabContents* tc = browser->GetTabContentsAt(i); | 1978 TabContents* tc = browser->GetTabContentsAt(i); |
| 1974 DictionaryValue* tab = new DictionaryValue; | 1979 DictionaryValue* tab = new DictionaryValue; |
| 1975 tab->SetInteger(L"index", i); | 1980 tab->SetInteger("index", i); |
| 1976 tab->SetString(L"url", tc->GetURL().spec()); | 1981 tab->SetString("url", tc->GetURL().spec()); |
| 1977 tab->SetInteger(L"renderer_pid", | 1982 tab->SetInteger("renderer_pid", |
| 1978 base::GetProcId(tc->GetRenderProcessHost()->GetHandle())); | 1983 base::GetProcId(tc->GetRenderProcessHost()->GetHandle())); |
| 1979 tab->Set(L"infobars", GetInfobarsInfo(tc)); | 1984 tab->Set("infobars", GetInfobarsInfo(tc)); |
| 1980 tabs->Append(tab); | 1985 tabs->Append(tab); |
| 1981 } | 1986 } |
| 1982 browser_item->Set(L"tabs", tabs); | 1987 browser_item->Set("tabs", tabs); |
| 1983 | 1988 |
| 1984 windows->Append(browser_item); | 1989 windows->Append(browser_item); |
| 1985 } | 1990 } |
| 1986 return_value->Set(L"windows", windows); | 1991 return_value->Set("windows", windows); |
| 1987 | 1992 |
| 1988 return_value->SetString(L"child_process_path", | 1993 return_value->SetString("child_process_path", |
| 1989 ChildProcessHost::GetChildPath(true).value()); | 1994 ChildProcessHost::GetChildPath(true).value()); |
| 1990 // Child processes are the processes for plugins and other workers. | 1995 // Child processes are the processes for plugins and other workers. |
| 1991 // Add all child processes in a list of dictionaries, one dictionary item | 1996 // Add all child processes in a list of dictionaries, one dictionary item |
| 1992 // per child process. | 1997 // per child process. |
| 1993 ListValue* child_processes = new ListValue; | 1998 ListValue* child_processes = new ListValue; |
| 1994 base::WaitableEvent event(true /* manual reset */, | 1999 base::WaitableEvent event(true /* manual reset */, |
| 1995 false /* not initially signaled */); | 2000 false /* not initially signaled */); |
| 1996 CHECK(ChromeThread::PostTask( | 2001 CHECK(ChromeThread::PostTask( |
| 1997 ChromeThread::IO, FROM_HERE, | 2002 ChromeThread::IO, FROM_HERE, |
| 1998 new GetChildProcessHostInfoTask(&event, child_processes))); | 2003 new GetChildProcessHostInfoTask(&event, child_processes))); |
| 1999 event.Wait(); | 2004 event.Wait(); |
| 2000 return_value->Set(L"child_processes", child_processes); | 2005 return_value->Set("child_processes", child_processes); |
| 2001 | 2006 |
| 2002 // Add all extension processes in a list of dictionaries, one dictionary | 2007 // Add all extension processes in a list of dictionaries, one dictionary |
| 2003 // item per extension process. | 2008 // item per extension process. |
| 2004 ListValue* extension_processes = new ListValue; | 2009 ListValue* extension_processes = new ListValue; |
| 2005 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 2010 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 2006 for (ProfileManager::const_iterator it = profile_manager->begin(); | 2011 for (ProfileManager::const_iterator it = profile_manager->begin(); |
| 2007 it != profile_manager->end(); ++it) { | 2012 it != profile_manager->end(); ++it) { |
| 2008 ExtensionProcessManager* process_manager = | 2013 ExtensionProcessManager* process_manager = |
| 2009 (*it)->GetExtensionProcessManager(); | 2014 (*it)->GetExtensionProcessManager(); |
| 2010 ExtensionProcessManager::const_iterator jt; | 2015 ExtensionProcessManager::const_iterator jt; |
| 2011 for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) { | 2016 for (jt = process_manager->begin(); jt != process_manager->end(); ++jt) { |
| 2012 ExtensionHost* ex_host = *jt; | 2017 ExtensionHost* ex_host = *jt; |
| 2013 // Don't add dead extension processes. | 2018 // Don't add dead extension processes. |
| 2014 if (!ex_host->IsRenderViewLive()) | 2019 if (!ex_host->IsRenderViewLive()) |
| 2015 continue; | 2020 continue; |
| 2016 DictionaryValue* item = new DictionaryValue; | 2021 DictionaryValue* item = new DictionaryValue; |
| 2017 item->SetString(L"name", ex_host->extension()->name()); | 2022 item->SetString("name", ex_host->extension()->name()); |
| 2018 item->SetInteger( | 2023 item->SetInteger( |
| 2019 L"pid", | 2024 "pid", |
| 2020 base::GetProcId(ex_host->render_process_host()->GetHandle())); | 2025 base::GetProcId(ex_host->render_process_host()->GetHandle())); |
| 2021 extension_processes->Append(item); | 2026 extension_processes->Append(item); |
| 2022 } | 2027 } |
| 2023 } | 2028 } |
| 2024 return_value->Set(L"extension_processes", extension_processes); | 2029 return_value->Set("extension_processes", extension_processes); |
| 2025 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2030 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 2026 } | 2031 } |
| 2027 | 2032 |
| 2028 // Sample json input: { "command": "GetHistoryInfo", | 2033 // Sample json input: { "command": "GetHistoryInfo", |
| 2029 // "search_text": "some text" } | 2034 // "search_text": "some text" } |
| 2030 // Refer chrome/test/pyautolib/history_info.py for sample json output. | 2035 // Refer chrome/test/pyautolib/history_info.py for sample json output. |
| 2031 void AutomationProvider::GetHistoryInfo(Browser* browser, | 2036 void AutomationProvider::GetHistoryInfo(Browser* browser, |
| 2032 DictionaryValue* args, | 2037 DictionaryValue* args, |
| 2033 IPC::Message* reply_message) { | 2038 IPC::Message* reply_message) { |
| 2034 consumer_.CancelAllRequests(); | 2039 consumer_.CancelAllRequests(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2053 // Sample json input: { "command": "AddHistoryItem", | 2058 // Sample json input: { "command": "AddHistoryItem", |
| 2054 // "item": { "URL": "http://www.google.com", | 2059 // "item": { "URL": "http://www.google.com", |
| 2055 // "title": "Google", # optional | 2060 // "title": "Google", # optional |
| 2056 // "time": 12345 # optional (time_t) | 2061 // "time": 12345 # optional (time_t) |
| 2057 // } } | 2062 // } } |
| 2058 // Refer chrome/test/pyautolib/pyauto.py for details on input. | 2063 // Refer chrome/test/pyautolib/pyauto.py for details on input. |
| 2059 void AutomationProvider::AddHistoryItem(Browser* browser, | 2064 void AutomationProvider::AddHistoryItem(Browser* browser, |
| 2060 DictionaryValue* args, | 2065 DictionaryValue* args, |
| 2061 IPC::Message* reply_message) { | 2066 IPC::Message* reply_message) { |
| 2062 DictionaryValue* item = NULL; | 2067 DictionaryValue* item = NULL; |
| 2063 args->GetDictionary(L"item", &item); | 2068 args->GetDictionary("item", &item); |
| 2064 string16 url_text; | 2069 string16 url_text; |
| 2065 string16 title; | 2070 string16 title; |
| 2066 base::Time time = base::Time::Now(); | 2071 base::Time time = base::Time::Now(); |
| 2067 AutomationJSONReply reply(this, reply_message); | 2072 AutomationJSONReply reply(this, reply_message); |
| 2068 | 2073 |
| 2069 if (!item->GetString("url", &url_text)) { | 2074 if (!item->GetString("url", &url_text)) { |
| 2070 reply.SendError("bad args (no URL in dict?)"); | 2075 reply.SendError("bad args (no URL in dict?)"); |
| 2071 return; | 2076 return; |
| 2072 } | 2077 } |
| 2073 GURL gurl(url_text); | 2078 GURL gurl(url_text); |
| 2074 item->GetString("title", &title); // Don't care if it fails. | 2079 item->GetString("title", &title); // Don't care if it fails. |
| 2075 int it; | 2080 int it; |
| 2076 double dt; | 2081 double dt; |
| 2077 if (item->GetInteger(L"time", &it)) | 2082 if (item->GetInteger("time", &it)) |
| 2078 time = base::Time::FromTimeT(it); | 2083 time = base::Time::FromTimeT(it); |
| 2079 else if (item->GetReal(L"time", &dt)) | 2084 else if (item->GetReal("time", &dt)) |
| 2080 time = base::Time::FromDoubleT(dt); | 2085 time = base::Time::FromDoubleT(dt); |
| 2081 | 2086 |
| 2082 // Ideas for "dummy" values (e.g. id_scope) came from | 2087 // Ideas for "dummy" values (e.g. id_scope) came from |
| 2083 // chrome/browser/autocomplete/history_contents_provider_unittest.cc | 2088 // chrome/browser/autocomplete/history_contents_provider_unittest.cc |
| 2084 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 2089 HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 2085 const void* id_scope = reinterpret_cast<void*>(1); | 2090 const void* id_scope = reinterpret_cast<void*>(1); |
| 2086 hs->AddPage(gurl, time, | 2091 hs->AddPage(gurl, time, |
| 2087 id_scope, | 2092 id_scope, |
| 2088 0, | 2093 0, |
| 2089 GURL(), | 2094 GURL(), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2121 safety_state_to_string[DownloadItem::SAFE] = std::string("SAFE"); | 2126 safety_state_to_string[DownloadItem::SAFE] = std::string("SAFE"); |
| 2122 safety_state_to_string[DownloadItem::DANGEROUS] = std::string("DANGEROUS"); | 2127 safety_state_to_string[DownloadItem::DANGEROUS] = std::string("DANGEROUS"); |
| 2123 safety_state_to_string[DownloadItem::DANGEROUS_BUT_VALIDATED] = | 2128 safety_state_to_string[DownloadItem::DANGEROUS_BUT_VALIDATED] = |
| 2124 std::string("DANGEROUS_BUT_VALIDATED"); | 2129 std::string("DANGEROUS_BUT_VALIDATED"); |
| 2125 | 2130 |
| 2126 ListValue* list_of_downloads = new ListValue; | 2131 ListValue* list_of_downloads = new ListValue; |
| 2127 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 2132 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 2128 it != downloads.end(); | 2133 it != downloads.end(); |
| 2129 it++) { // Fill info about each download item. | 2134 it++) { // Fill info about each download item. |
| 2130 DictionaryValue* dl_item_value = new DictionaryValue; | 2135 DictionaryValue* dl_item_value = new DictionaryValue; |
| 2131 dl_item_value->SetInteger(L"id", static_cast<int>((*it)->id())); | 2136 dl_item_value->SetInteger("id", static_cast<int>((*it)->id())); |
| 2132 dl_item_value->SetString(L"url", (*it)->url().spec()); | 2137 dl_item_value->SetString("url", (*it)->url().spec()); |
| 2133 dl_item_value->SetString(L"referrer_url", (*it)->referrer_url().spec()); | 2138 dl_item_value->SetString("referrer_url", (*it)->referrer_url().spec()); |
| 2134 dl_item_value->SetString(L"file_name", (*it)->GetFileName().value()); | 2139 dl_item_value->SetString("file_name", (*it)->GetFileName().value()); |
| 2135 dl_item_value->SetString(L"full_path", (*it)->full_path().value()); | 2140 dl_item_value->SetString("full_path", (*it)->full_path().value()); |
| 2136 dl_item_value->SetBoolean(L"is_paused", (*it)->is_paused()); | 2141 dl_item_value->SetBoolean("is_paused", (*it)->is_paused()); |
| 2137 dl_item_value->SetBoolean(L"open_when_complete", | 2142 dl_item_value->SetBoolean("open_when_complete", |
| 2138 (*it)->open_when_complete()); | 2143 (*it)->open_when_complete()); |
| 2139 dl_item_value->SetBoolean(L"is_extension_install", | 2144 dl_item_value->SetBoolean("is_extension_install", |
| 2140 (*it)->is_extension_install()); | 2145 (*it)->is_extension_install()); |
| 2141 dl_item_value->SetBoolean(L"is_temporary", (*it)->is_temporary()); | 2146 dl_item_value->SetBoolean("is_temporary", (*it)->is_temporary()); |
| 2142 dl_item_value->SetBoolean(L"is_otr", (*it)->is_otr()); // off-the-record | 2147 dl_item_value->SetBoolean("is_otr", (*it)->is_otr()); // off-the-record |
| 2143 dl_item_value->SetString(L"state", state_to_string[(*it)->state()]); | 2148 dl_item_value->SetString("state", state_to_string[(*it)->state()]); |
| 2144 dl_item_value->SetString(L"safety_state", | 2149 dl_item_value->SetString("safety_state", |
| 2145 safety_state_to_string[(*it)->safety_state()]); | 2150 safety_state_to_string[(*it)->safety_state()]); |
| 2146 dl_item_value->SetInteger(L"PercentComplete", (*it)->PercentComplete()); | 2151 dl_item_value->SetInteger("PercentComplete", (*it)->PercentComplete()); |
| 2147 list_of_downloads->Append(dl_item_value); | 2152 list_of_downloads->Append(dl_item_value); |
| 2148 } | 2153 } |
| 2149 return_value->Set(L"downloads", list_of_downloads); | 2154 return_value->Set("downloads", list_of_downloads); |
| 2150 | 2155 |
| 2151 reply.SendSuccess(return_value.get()); | 2156 reply.SendSuccess(return_value.get()); |
| 2152 // All value objects allocated above are owned by |return_value| | 2157 // All value objects allocated above are owned by |return_value| |
| 2153 // and get freed by it. | 2158 // and get freed by it. |
| 2154 } | 2159 } |
| 2155 | 2160 |
| 2156 void AutomationProvider::WaitForDownloadsToComplete( | 2161 void AutomationProvider::WaitForDownloadsToComplete( |
| 2157 Browser* browser, | 2162 Browser* browser, |
| 2158 DictionaryValue* args, | 2163 DictionaryValue* args, |
| 2159 IPC::Message* reply_message) { | 2164 IPC::Message* reply_message) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2189 DictionaryValue* args, | 2194 DictionaryValue* args, |
| 2190 IPC::Message* reply_message) { | 2195 IPC::Message* reply_message) { |
| 2191 const PrefService::PreferenceSet& prefs = | 2196 const PrefService::PreferenceSet& prefs = |
| 2192 profile_->GetPrefs()->preference_set(); | 2197 profile_->GetPrefs()->preference_set(); |
| 2193 DictionaryValue* items = new DictionaryValue; | 2198 DictionaryValue* items = new DictionaryValue; |
| 2194 for (PrefService::PreferenceSet::const_iterator it = prefs.begin(); | 2199 for (PrefService::PreferenceSet::const_iterator it = prefs.begin(); |
| 2195 it != prefs.end(); ++it) { | 2200 it != prefs.end(); ++it) { |
| 2196 items->Set((*it)->name(), (*it)->GetValue()->DeepCopy()); | 2201 items->Set((*it)->name(), (*it)->GetValue()->DeepCopy()); |
| 2197 } | 2202 } |
| 2198 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2203 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2199 return_value->Set(L"prefs", items); // return_value owns items. | 2204 return_value->Set("prefs", items); // return_value owns items. |
| 2200 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2205 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 2201 } | 2206 } |
| 2202 | 2207 |
| 2203 // Sample json input: { "command": "SetPrefs", "path": path, "value": value } | 2208 // Sample json input: { "command": "SetPrefs", "path": path, "value": value } |
| 2204 void AutomationProvider::SetPrefs(Browser* browser, | 2209 void AutomationProvider::SetPrefs(Browser* browser, |
| 2205 DictionaryValue* args, | 2210 DictionaryValue* args, |
| 2206 IPC::Message* reply_message) { | 2211 IPC::Message* reply_message) { |
| 2207 std::wstring path; | 2212 std::wstring path; |
| 2208 Value* val; | 2213 Value* val; |
| 2209 AutomationJSONReply reply(this, reply_message); | 2214 AutomationJSONReply reply(this, reply_message); |
| 2210 if (args->GetString(L"path", &path) && args->Get(L"value", &val)) { | 2215 if (args->GetString(L"path", &path) && args->Get("value", &val)) { |
| 2211 PrefService* pref_service = profile_->GetPrefs(); | 2216 PrefService* pref_service = profile_->GetPrefs(); |
| 2212 const PrefService::Preference* pref = | 2217 const PrefService::Preference* pref = |
| 2213 pref_service->FindPreference(path.c_str()); | 2218 pref_service->FindPreference(path.c_str()); |
| 2214 if (!pref) { // Not a registered pref. | 2219 if (!pref) { // Not a registered pref. |
| 2215 reply.SendError("pref not registered."); | 2220 reply.SendError("pref not registered."); |
| 2216 return; | 2221 return; |
| 2217 } else if (pref->IsManaged()) { // Do not attempt to change a managed pref. | 2222 } else if (pref->IsManaged()) { // Do not attempt to change a managed pref. |
| 2218 reply.SendError("pref is managed. cannot be changed."); | 2223 reply.SendError("pref is managed. cannot be changed."); |
| 2219 return; | 2224 return; |
| 2220 } else { // Set the pref. | 2225 } else { // Set the pref. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2239 AutocompleteEditView* edit_view = loc_bar->location_entry(); | 2244 AutocompleteEditView* edit_view = loc_bar->location_entry(); |
| 2240 AutocompleteEditModel* model = edit_view->model(); | 2245 AutocompleteEditModel* model = edit_view->model(); |
| 2241 | 2246 |
| 2242 // Fill up matches. | 2247 // Fill up matches. |
| 2243 ListValue* matches = new ListValue; | 2248 ListValue* matches = new ListValue; |
| 2244 const AutocompleteResult& result = model->result(); | 2249 const AutocompleteResult& result = model->result(); |
| 2245 for (AutocompleteResult::const_iterator i = result.begin(); | 2250 for (AutocompleteResult::const_iterator i = result.begin(); |
| 2246 i != result.end(); ++i) { | 2251 i != result.end(); ++i) { |
| 2247 const AutocompleteMatch& match = *i; | 2252 const AutocompleteMatch& match = *i; |
| 2248 DictionaryValue* item = new DictionaryValue; // owned by return_value | 2253 DictionaryValue* item = new DictionaryValue; // owned by return_value |
| 2249 item->SetString(L"type", AutocompleteMatch::TypeToString(match.type)); | 2254 item->SetString("type", AutocompleteMatch::TypeToString(match.type)); |
| 2250 item->SetBoolean(L"starred", match.starred); | 2255 item->SetBoolean("starred", match.starred); |
| 2251 item->SetString(L"destination_url", match.destination_url.spec()); | 2256 item->SetString("destination_url", match.destination_url.spec()); |
| 2252 item->SetString(L"contents", match.contents); | 2257 item->SetString("contents", WideToUTF16Hack(match.contents)); |
| 2253 item->SetString(L"description", match.description); | 2258 item->SetString("description", WideToUTF16Hack(match.description)); |
| 2254 matches->Append(item); | 2259 matches->Append(item); |
| 2255 } | 2260 } |
| 2256 return_value->Set(L"matches", matches); | 2261 return_value->Set("matches", matches); |
| 2257 | 2262 |
| 2258 // Fill up other properties. | 2263 // Fill up other properties. |
| 2259 DictionaryValue* properties = new DictionaryValue; // owned by return_value | 2264 DictionaryValue* properties = new DictionaryValue; // owned by return_value |
| 2260 properties->SetBoolean(L"has_focus", model->has_focus()); | 2265 properties->SetBoolean("has_focus", model->has_focus()); |
| 2261 properties->SetBoolean(L"query_in_progress", model->query_in_progress()); | 2266 properties->SetBoolean("query_in_progress", model->query_in_progress()); |
| 2262 properties->SetString(L"keyword", model->keyword()); | 2267 properties->SetString("keyword", WideToUTF16Hack(model->keyword())); |
| 2263 properties->SetString(L"text", edit_view->GetText()); | 2268 properties->SetString("text", WideToUTF16Hack(edit_view->GetText())); |
| 2264 return_value->Set(L"properties", properties); | 2269 return_value->Set("properties", properties); |
| 2265 | 2270 |
| 2266 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2271 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 2267 } | 2272 } |
| 2268 | 2273 |
| 2269 // Sample json input: { "command": "SetOmniboxText", | 2274 // Sample json input: { "command": "SetOmniboxText", |
| 2270 // "text": "goog" } | 2275 // "text": "goog" } |
| 2271 void AutomationProvider::SetOmniboxText(Browser* browser, | 2276 void AutomationProvider::SetOmniboxText(Browser* browser, |
| 2272 DictionaryValue* args, | 2277 DictionaryValue* args, |
| 2273 IPC::Message* reply_message) { | 2278 IPC::Message* reply_message) { |
| 2274 std::wstring text; | 2279 std::wstring text; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2288 // Sample json input: { "command": "OmniboxMovePopupSelection", | 2293 // Sample json input: { "command": "OmniboxMovePopupSelection", |
| 2289 // "count": 1 } | 2294 // "count": 1 } |
| 2290 // Negative count implies up, positive implies down. Count values will be | 2295 // Negative count implies up, positive implies down. Count values will be |
| 2291 // capped by the size of the popup list. | 2296 // capped by the size of the popup list. |
| 2292 void AutomationProvider::OmniboxMovePopupSelection( | 2297 void AutomationProvider::OmniboxMovePopupSelection( |
| 2293 Browser* browser, | 2298 Browser* browser, |
| 2294 DictionaryValue* args, | 2299 DictionaryValue* args, |
| 2295 IPC::Message* reply_message) { | 2300 IPC::Message* reply_message) { |
| 2296 int count; | 2301 int count; |
| 2297 AutomationJSONReply reply(this, reply_message); | 2302 AutomationJSONReply reply(this, reply_message); |
| 2298 if (!args->GetInteger(L"count", &count)) { | 2303 if (!args->GetInteger("count", &count)) { |
| 2299 reply.SendError("count missing"); | 2304 reply.SendError("count missing"); |
| 2300 return; | 2305 return; |
| 2301 } | 2306 } |
| 2302 LocationBar* loc_bar = browser->window()->GetLocationBar(); | 2307 LocationBar* loc_bar = browser->window()->GetLocationBar(); |
| 2303 AutocompleteEditModel* model = loc_bar->location_entry()->model(); | 2308 AutocompleteEditModel* model = loc_bar->location_entry()->model(); |
| 2304 model->OnUpOrDownKeyPressed(count); | 2309 model->OnUpOrDownKeyPressed(count); |
| 2305 reply.SendSuccess(NULL); | 2310 reply.SendSuccess(NULL); |
| 2306 } | 2311 } |
| 2307 | 2312 |
| 2308 // Sample json input: { "command": "OmniboxAcceptInput" } | 2313 // Sample json input: { "command": "OmniboxAcceptInput" } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2340 void AutomationProvider::GetPluginsInfo(Browser* browser, | 2345 void AutomationProvider::GetPluginsInfo(Browser* browser, |
| 2341 DictionaryValue* args, | 2346 DictionaryValue* args, |
| 2342 IPC::Message* reply_message) { | 2347 IPC::Message* reply_message) { |
| 2343 std::vector<WebPluginInfo> plugins; | 2348 std::vector<WebPluginInfo> plugins; |
| 2344 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); | 2349 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); |
| 2345 ListValue* items = new ListValue; | 2350 ListValue* items = new ListValue; |
| 2346 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); | 2351 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin(); |
| 2347 it != plugins.end(); | 2352 it != plugins.end(); |
| 2348 ++it) { | 2353 ++it) { |
| 2349 DictionaryValue* item = new DictionaryValue; | 2354 DictionaryValue* item = new DictionaryValue; |
| 2350 item->SetStringFromUTF16(L"name", it->name); | 2355 item->SetString("name", it->name); |
| 2351 item->SetString(L"path", it->path.value()); | 2356 item->SetString("path", it->path.value()); |
| 2352 item->SetStringFromUTF16(L"version", it->version); | 2357 item->SetString("version", it->version); |
| 2353 item->SetStringFromUTF16(L"desc", it->desc); | 2358 item->SetString("desc", it->desc); |
| 2354 item->SetBoolean(L"enabled", it->enabled); | 2359 item->SetBoolean("enabled", it->enabled); |
| 2355 // Add info about mime types. | 2360 // Add info about mime types. |
| 2356 ListValue* mime_types = new ListValue(); | 2361 ListValue* mime_types = new ListValue(); |
| 2357 for (std::vector<WebPluginMimeType>::const_iterator type_it = | 2362 for (std::vector<WebPluginMimeType>::const_iterator type_it = |
| 2358 it->mime_types.begin(); | 2363 it->mime_types.begin(); |
| 2359 type_it != it->mime_types.end(); | 2364 type_it != it->mime_types.end(); |
| 2360 ++type_it) { | 2365 ++type_it) { |
| 2361 DictionaryValue* mime_type = new DictionaryValue(); | 2366 DictionaryValue* mime_type = new DictionaryValue(); |
| 2362 mime_type->SetString(L"mimeType", type_it->mime_type); | 2367 mime_type->SetString("mimeType", type_it->mime_type); |
| 2363 mime_type->SetStringFromUTF16(L"description", type_it->description); | 2368 mime_type->SetString("description", type_it->description); |
| 2364 | 2369 |
| 2365 ListValue* file_extensions = new ListValue(); | 2370 ListValue* file_extensions = new ListValue(); |
| 2366 for (std::vector<std::string>::const_iterator ext_it = | 2371 for (std::vector<std::string>::const_iterator ext_it = |
| 2367 type_it->file_extensions.begin(); | 2372 type_it->file_extensions.begin(); |
| 2368 ext_it != type_it->file_extensions.end(); | 2373 ext_it != type_it->file_extensions.end(); |
| 2369 ++ext_it) { | 2374 ++ext_it) { |
| 2370 file_extensions->Append(new StringValue(*ext_it)); | 2375 file_extensions->Append(new StringValue(*ext_it)); |
| 2371 } | 2376 } |
| 2372 mime_type->Set(L"fileExtensions", file_extensions); | 2377 mime_type->Set("fileExtensions", file_extensions); |
| 2373 | 2378 |
| 2374 mime_types->Append(mime_type); | 2379 mime_types->Append(mime_type); |
| 2375 } | 2380 } |
| 2376 item->Set(L"mimeTypes", mime_types); | 2381 item->Set("mimeTypes", mime_types); |
| 2377 items->Append(item); | 2382 items->Append(item); |
| 2378 } | 2383 } |
| 2379 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2384 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2380 return_value->Set(L"plugins", items); // return_value owns items. | 2385 return_value->Set("plugins", items); // return_value owns items. |
| 2381 | 2386 |
| 2382 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2387 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 2383 } | 2388 } |
| 2384 | 2389 |
| 2385 // Sample json input: | 2390 // Sample json input: |
| 2386 // { "command": "EnablePlugin", | 2391 // { "command": "EnablePlugin", |
| 2387 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 2392 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
| 2388 void AutomationProvider::EnablePlugin(Browser* browser, | 2393 void AutomationProvider::EnablePlugin(Browser* browser, |
| 2389 DictionaryValue* args, | 2394 DictionaryValue* args, |
| 2390 IPC::Message* reply_message) { | 2395 IPC::Message* reply_message) { |
| 2391 FilePath::StringType path; | 2396 FilePath::StringType path; |
| 2392 AutomationJSONReply reply(this, reply_message); | 2397 AutomationJSONReply reply(this, reply_message); |
| 2393 if (!args->GetString(L"path", &path)) { | 2398 if (!args->GetString("path", &path)) { |
| 2394 reply.SendError("path not specified."); | 2399 reply.SendError("path not specified."); |
| 2395 return; | 2400 return; |
| 2396 } else if (!NPAPI::PluginList::Singleton()->EnablePlugin(FilePath(path))) { | 2401 } else if (!NPAPI::PluginList::Singleton()->EnablePlugin(FilePath(path))) { |
| 2397 reply.SendError(StringPrintf("Could not enable plugin for path %s.", | 2402 reply.SendError(StringPrintf("Could not enable plugin for path %s.", |
| 2398 path.c_str())); | 2403 path.c_str())); |
| 2399 return; | 2404 return; |
| 2400 } | 2405 } |
| 2401 reply.SendSuccess(NULL); | 2406 reply.SendSuccess(NULL); |
| 2402 } | 2407 } |
| 2403 | 2408 |
| 2404 // Sample json input: | 2409 // Sample json input: |
| 2405 // { "command": "DisablePlugin", | 2410 // { "command": "DisablePlugin", |
| 2406 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } | 2411 // "path": "/Library/Internet Plug-Ins/Flash Player.plugin" } |
| 2407 void AutomationProvider::DisablePlugin(Browser* browser, | 2412 void AutomationProvider::DisablePlugin(Browser* browser, |
| 2408 DictionaryValue* args, | 2413 DictionaryValue* args, |
| 2409 IPC::Message* reply_message) { | 2414 IPC::Message* reply_message) { |
| 2410 FilePath::StringType path; | 2415 FilePath::StringType path; |
| 2411 AutomationJSONReply reply(this, reply_message); | 2416 AutomationJSONReply reply(this, reply_message); |
| 2412 if (!args->GetString(L"path", &path)) { | 2417 if (!args->GetString("path", &path)) { |
| 2413 reply.SendError("path not specified."); | 2418 reply.SendError("path not specified."); |
| 2414 return; | 2419 return; |
| 2415 } else if (!NPAPI::PluginList::Singleton()->DisablePlugin(FilePath(path))) { | 2420 } else if (!NPAPI::PluginList::Singleton()->DisablePlugin(FilePath(path))) { |
| 2416 reply.SendError(StringPrintf("Could not disable plugin for path %s.", | 2421 reply.SendError(StringPrintf("Could not disable plugin for path %s.", |
| 2417 path.c_str())); | 2422 path.c_str())); |
| 2418 return; | 2423 return; |
| 2419 } | 2424 } |
| 2420 reply.SendSuccess(NULL); | 2425 reply.SendSuccess(NULL); |
| 2421 } | 2426 } |
| 2422 | 2427 |
| 2423 // Sample json input: | 2428 // Sample json input: |
| 2424 // { "command": "SaveTabContents", | 2429 // { "command": "SaveTabContents", |
| 2425 // "tab_index": 0, | 2430 // "tab_index": 0, |
| 2426 // "filename": <a full pathname> } | 2431 // "filename": <a full pathname> } |
| 2427 // Sample json output: | 2432 // Sample json output: |
| 2428 // {} | 2433 // {} |
| 2429 void AutomationProvider::SaveTabContents(Browser* browser, | 2434 void AutomationProvider::SaveTabContents(Browser* browser, |
| 2430 DictionaryValue* args, | 2435 DictionaryValue* args, |
| 2431 IPC::Message* reply_message) { | 2436 IPC::Message* reply_message) { |
| 2432 int tab_index = 0; | 2437 int tab_index = 0; |
| 2433 FilePath::StringType filename; | 2438 FilePath::StringType filename; |
| 2434 FilePath::StringType parent_directory; | 2439 FilePath::StringType parent_directory; |
| 2435 TabContents* tab_contents = NULL; | 2440 TabContents* tab_contents = NULL; |
| 2436 | 2441 |
| 2437 if (!args->GetInteger(L"tab_index", &tab_index) || | 2442 if (!args->GetInteger("tab_index", &tab_index) || |
| 2438 !args->GetString(L"filename", &filename)) { | 2443 !args->GetString("filename", &filename)) { |
| 2439 AutomationJSONReply(this, reply_message).SendError( | 2444 AutomationJSONReply(this, reply_message).SendError( |
| 2440 "tab_index or filename param missing"); | 2445 "tab_index or filename param missing"); |
| 2441 return; | 2446 return; |
| 2442 } else { | 2447 } else { |
| 2443 tab_contents = browser->GetTabContentsAt(tab_index); | 2448 tab_contents = browser->GetTabContentsAt(tab_index); |
| 2444 if (!tab_contents) { | 2449 if (!tab_contents) { |
| 2445 AutomationJSONReply(this, reply_message).SendError( | 2450 AutomationJSONReply(this, reply_message).SendError( |
| 2446 "no tab at tab_index"); | 2451 "no tab at tab_index"); |
| 2447 return; | 2452 return; |
| 2448 } | 2453 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2476 string_to_import_item["SEARCH_ENGINES"] = importer::SEARCH_ENGINES; | 2481 string_to_import_item["SEARCH_ENGINES"] = importer::SEARCH_ENGINES; |
| 2477 string_to_import_item["HOME_PAGE"] = importer::HOME_PAGE; | 2482 string_to_import_item["HOME_PAGE"] = importer::HOME_PAGE; |
| 2478 string_to_import_item["ALL"] = importer::ALL; | 2483 string_to_import_item["ALL"] = importer::ALL; |
| 2479 | 2484 |
| 2480 std::wstring browser_name; | 2485 std::wstring browser_name; |
| 2481 int import_items = 0; | 2486 int import_items = 0; |
| 2482 ListValue* import_items_list = NULL; | 2487 ListValue* import_items_list = NULL; |
| 2483 bool first_run; | 2488 bool first_run; |
| 2484 | 2489 |
| 2485 if (!args->GetString(L"import_from", &browser_name) || | 2490 if (!args->GetString(L"import_from", &browser_name) || |
| 2486 !args->GetBoolean(L"first_run", &first_run) || | 2491 !args->GetBoolean("first_run", &first_run) || |
| 2487 !args->GetList(L"import_items", &import_items_list)) { | 2492 !args->GetList("import_items", &import_items_list)) { |
| 2488 AutomationJSONReply(this, reply_message).SendError( | 2493 AutomationJSONReply(this, reply_message).SendError( |
| 2489 "Incorrect type for one or more of the arguments."); | 2494 "Incorrect type for one or more of the arguments."); |
| 2490 return; | 2495 return; |
| 2491 } | 2496 } |
| 2492 | 2497 |
| 2493 int num_items = import_items_list->GetSize(); | 2498 int num_items = import_items_list->GetSize(); |
| 2494 for (int i = 0; i < num_items; i++) { | 2499 for (int i = 0; i < num_items; i++) { |
| 2495 std::string item; | 2500 std::string item; |
| 2496 import_items_list->GetString(i, &item); | 2501 import_items_list->GetString(i, &item); |
| 2497 // If the provided string is not part of the map, error out. | 2502 // If the provided string is not part of the map, error out. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2533 namespace { | 2538 namespace { |
| 2534 | 2539 |
| 2535 // Translates a dictionary password to a PasswordForm struct. | 2540 // Translates a dictionary password to a PasswordForm struct. |
| 2536 webkit_glue::PasswordForm GetPasswordFormFromDict( | 2541 webkit_glue::PasswordForm GetPasswordFormFromDict( |
| 2537 const DictionaryValue& password_dict) { | 2542 const DictionaryValue& password_dict) { |
| 2538 | 2543 |
| 2539 // If the time is specified, change time to the specified time. | 2544 // If the time is specified, change time to the specified time. |
| 2540 base::Time time = base::Time::Now(); | 2545 base::Time time = base::Time::Now(); |
| 2541 int it; | 2546 int it; |
| 2542 double dt; | 2547 double dt; |
| 2543 if (password_dict.GetInteger(L"time", &it)) | 2548 if (password_dict.GetInteger("time", &it)) |
| 2544 time = base::Time::FromTimeT(it); | 2549 time = base::Time::FromTimeT(it); |
| 2545 else if (password_dict.GetReal(L"time", &dt)) | 2550 else if (password_dict.GetReal("time", &dt)) |
| 2546 time = base::Time::FromDoubleT(dt); | 2551 time = base::Time::FromDoubleT(dt); |
| 2547 | 2552 |
| 2548 std::string signon_realm; | 2553 std::string signon_realm; |
| 2549 string16 username_value; | 2554 string16 username_value; |
| 2550 string16 password_value; | 2555 string16 password_value; |
| 2551 string16 origin_url_text; | 2556 string16 origin_url_text; |
| 2552 string16 username_element; | 2557 string16 username_element; |
| 2553 string16 password_element; | 2558 string16 password_element; |
| 2554 string16 submit_element; | 2559 string16 submit_element; |
| 2555 string16 action_target_text; | 2560 string16 action_target_text; |
| 2556 bool blacklist = false; | 2561 bool blacklist = false; |
| 2557 string16 old_password_element; | 2562 string16 old_password_element; |
| 2558 string16 old_password_value; | 2563 string16 old_password_value; |
| 2559 | 2564 |
| 2560 // We don't care if any of these fail - they are either optional or checked | 2565 // We don't care if any of these fail - they are either optional or checked |
| 2561 // before this function is called. | 2566 // before this function is called. |
| 2562 password_dict.GetString(L"signon_realm", &signon_realm); | 2567 password_dict.GetString("signon_realm", &signon_realm); |
| 2563 password_dict.GetStringAsUTF16(L"username_value", &username_value); | 2568 password_dict.GetStringAsUTF16("username_value", &username_value); |
| 2564 password_dict.GetStringAsUTF16(L"password_value", &password_value); | 2569 password_dict.GetStringAsUTF16("password_value", &password_value); |
| 2565 password_dict.GetStringAsUTF16(L"origin_url", &origin_url_text); | 2570 password_dict.GetStringAsUTF16("origin_url", &origin_url_text); |
| 2566 password_dict.GetStringAsUTF16(L"username_element", &username_element); | 2571 password_dict.GetStringAsUTF16("username_element", &username_element); |
| 2567 password_dict.GetStringAsUTF16(L"password_element", &password_element); | 2572 password_dict.GetStringAsUTF16("password_element", &password_element); |
| 2568 password_dict.GetStringAsUTF16(L"submit_element", &submit_element); | 2573 password_dict.GetStringAsUTF16("submit_element", &submit_element); |
| 2569 password_dict.GetStringAsUTF16(L"action_target", &action_target_text); | 2574 password_dict.GetStringAsUTF16("action_target", &action_target_text); |
| 2570 password_dict.GetBoolean(L"blacklist", &blacklist); | 2575 password_dict.GetBoolean("blacklist", &blacklist); |
| 2571 | 2576 |
| 2572 GURL origin_gurl(origin_url_text); | 2577 GURL origin_gurl(origin_url_text); |
| 2573 GURL action_target(action_target_text); | 2578 GURL action_target(action_target_text); |
| 2574 | 2579 |
| 2575 webkit_glue::PasswordForm password_form; | 2580 webkit_glue::PasswordForm password_form; |
| 2576 password_form.signon_realm = signon_realm; | 2581 password_form.signon_realm = signon_realm; |
| 2577 password_form.username_value = username_value; | 2582 password_form.username_value = username_value; |
| 2578 password_form.password_value = password_value; | 2583 password_form.password_value = password_value; |
| 2579 password_form.origin = origin_gurl; | 2584 password_form.origin = origin_gurl; |
| 2580 password_form.username_element = username_element; | 2585 password_form.username_element = username_element; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2591 | 2596 |
| 2592 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json | 2597 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json |
| 2593 // input. | 2598 // input. |
| 2594 // Sample json output: { "password_added": true } | 2599 // Sample json output: { "password_added": true } |
| 2595 void AutomationProvider::AddSavedPassword(Browser* browser, | 2600 void AutomationProvider::AddSavedPassword(Browser* browser, |
| 2596 DictionaryValue* args, | 2601 DictionaryValue* args, |
| 2597 IPC::Message* reply_message) { | 2602 IPC::Message* reply_message) { |
| 2598 AutomationJSONReply reply(this, reply_message); | 2603 AutomationJSONReply reply(this, reply_message); |
| 2599 DictionaryValue* password_dict = NULL; | 2604 DictionaryValue* password_dict = NULL; |
| 2600 | 2605 |
| 2601 if (!args->GetDictionary(L"password", &password_dict)) { | 2606 if (!args->GetDictionary("password", &password_dict)) { |
| 2602 reply.SendError("Password must be a dictionary."); | 2607 reply.SendError("Password must be a dictionary."); |
| 2603 return; | 2608 return; |
| 2604 } | 2609 } |
| 2605 | 2610 |
| 2606 // The signon realm is effectively the primary key and must be included. | 2611 // The signon realm is effectively the primary key and must be included. |
| 2607 // Check here before calling GetPasswordFormFromDict. | 2612 // Check here before calling GetPasswordFormFromDict. |
| 2608 if (!password_dict->HasKey(L"signon_realm")) { | 2613 if (!password_dict->HasKey("signon_realm")) { |
| 2609 reply.SendError("Password must include signon_realm."); | 2614 reply.SendError("Password must include signon_realm."); |
| 2610 return; | 2615 return; |
| 2611 } | 2616 } |
| 2612 webkit_glue::PasswordForm new_password = | 2617 webkit_glue::PasswordForm new_password = |
| 2613 GetPasswordFormFromDict(*password_dict); | 2618 GetPasswordFormFromDict(*password_dict); |
| 2614 | 2619 |
| 2615 Profile* profile = browser->profile(); | 2620 Profile* profile = browser->profile(); |
| 2616 // Use IMPLICIT_ACCESS since new passwords aren't added off the record. | 2621 // Use IMPLICIT_ACCESS since new passwords aren't added off the record. |
| 2617 PasswordStore* password_store = | 2622 PasswordStore* password_store = |
| 2618 profile->GetPasswordStore(Profile::IMPLICIT_ACCESS); | 2623 profile->GetPasswordStore(Profile::IMPLICIT_ACCESS); |
| 2619 | 2624 |
| 2620 // Set the return based on whether setting the password succeeded. | 2625 // Set the return based on whether setting the password succeeded. |
| 2621 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2626 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2622 | 2627 |
| 2623 // It will be null if it's accessed in an incognito window. | 2628 // It will be null if it's accessed in an incognito window. |
| 2624 if (password_store != NULL) { | 2629 if (password_store != NULL) { |
| 2625 password_store->AddLogin(new_password); | 2630 password_store->AddLogin(new_password); |
| 2626 return_value->SetBoolean(L"password_added", true); | 2631 return_value->SetBoolean("password_added", true); |
| 2627 } else { | 2632 } else { |
| 2628 return_value->SetBoolean(L"password_added", false); | 2633 return_value->SetBoolean("password_added", false); |
| 2629 } | 2634 } |
| 2630 | 2635 |
| 2631 reply.SendSuccess(return_value.get()); | 2636 reply.SendSuccess(return_value.get()); |
| 2632 } | 2637 } |
| 2633 | 2638 |
| 2634 // See RemoveSavedPassword() in chrome/test/functional/pyauto.py for sample | 2639 // See RemoveSavedPassword() in chrome/test/functional/pyauto.py for sample |
| 2635 // json input. | 2640 // json input. |
| 2636 // Sample json output: {} | 2641 // Sample json output: {} |
| 2637 void AutomationProvider::RemoveSavedPassword(Browser* browser, | 2642 void AutomationProvider::RemoveSavedPassword(Browser* browser, |
| 2638 DictionaryValue* args, | 2643 DictionaryValue* args, |
| 2639 IPC::Message* reply_message) { | 2644 IPC::Message* reply_message) { |
| 2640 AutomationJSONReply reply(this, reply_message); | 2645 AutomationJSONReply reply(this, reply_message); |
| 2641 DictionaryValue* password_dict = NULL; | 2646 DictionaryValue* password_dict = NULL; |
| 2642 | 2647 |
| 2643 if (!args->GetDictionary(L"password", &password_dict)) { | 2648 if (!args->GetDictionary("password", &password_dict)) { |
| 2644 reply.SendError("Password must be a dictionary."); | 2649 reply.SendError("Password must be a dictionary."); |
| 2645 return; | 2650 return; |
| 2646 } | 2651 } |
| 2647 | 2652 |
| 2648 // The signon realm is effectively the primary key and must be included. | 2653 // The signon realm is effectively the primary key and must be included. |
| 2649 // Check here before calling GetPasswordFormFromDict. | 2654 // Check here before calling GetPasswordFormFromDict. |
| 2650 if (!password_dict->HasKey(L"signon_realm")) { | 2655 if (!password_dict->HasKey("signon_realm")) { |
| 2651 reply.SendError("Password must include signon_realm."); | 2656 reply.SendError("Password must include signon_realm."); |
| 2652 return; | 2657 return; |
| 2653 } | 2658 } |
| 2654 webkit_glue::PasswordForm to_remove = | 2659 webkit_glue::PasswordForm to_remove = |
| 2655 GetPasswordFormFromDict(*password_dict); | 2660 GetPasswordFormFromDict(*password_dict); |
| 2656 | 2661 |
| 2657 Profile* profile = browser->profile(); | 2662 Profile* profile = browser->profile(); |
| 2658 // Use EXPLICIT_ACCESS since passwords can be removed off the record. | 2663 // Use EXPLICIT_ACCESS since passwords can be removed off the record. |
| 2659 PasswordStore* password_store = | 2664 PasswordStore* password_store = |
| 2660 profile->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 2665 profile->GetPasswordStore(Profile::EXPLICIT_ACCESS); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2694 std::map<std::string, int> string_to_mask_value; | 2699 std::map<std::string, int> string_to_mask_value; |
| 2695 string_to_mask_value["HISTORY"] = BrowsingDataRemover::REMOVE_HISTORY; | 2700 string_to_mask_value["HISTORY"] = BrowsingDataRemover::REMOVE_HISTORY; |
| 2696 string_to_mask_value["DOWNLOADS"] = BrowsingDataRemover::REMOVE_DOWNLOADS; | 2701 string_to_mask_value["DOWNLOADS"] = BrowsingDataRemover::REMOVE_DOWNLOADS; |
| 2697 string_to_mask_value["COOKIES"] = BrowsingDataRemover::REMOVE_COOKIES; | 2702 string_to_mask_value["COOKIES"] = BrowsingDataRemover::REMOVE_COOKIES; |
| 2698 string_to_mask_value["PASSWORDS"] = BrowsingDataRemover::REMOVE_PASSWORDS; | 2703 string_to_mask_value["PASSWORDS"] = BrowsingDataRemover::REMOVE_PASSWORDS; |
| 2699 string_to_mask_value["FORM_DATA"] = BrowsingDataRemover::REMOVE_FORM_DATA; | 2704 string_to_mask_value["FORM_DATA"] = BrowsingDataRemover::REMOVE_FORM_DATA; |
| 2700 string_to_mask_value["CACHE"] = BrowsingDataRemover::REMOVE_CACHE; | 2705 string_to_mask_value["CACHE"] = BrowsingDataRemover::REMOVE_CACHE; |
| 2701 | 2706 |
| 2702 std::string time_period; | 2707 std::string time_period; |
| 2703 ListValue* to_remove; | 2708 ListValue* to_remove; |
| 2704 if (!args->GetString(L"time_period", &time_period) || | 2709 if (!args->GetString("time_period", &time_period) || |
| 2705 !args->GetList(L"to_remove", &to_remove)) { | 2710 !args->GetList("to_remove", &to_remove)) { |
| 2706 AutomationJSONReply(this, reply_message).SendError( | 2711 AutomationJSONReply(this, reply_message).SendError( |
| 2707 "time_period must be a string and to_remove a list."); | 2712 "time_period must be a string and to_remove a list."); |
| 2708 return; | 2713 return; |
| 2709 } | 2714 } |
| 2710 | 2715 |
| 2711 int remove_mask = 0; | 2716 int remove_mask = 0; |
| 2712 int num_removals = to_remove->GetSize(); | 2717 int num_removals = to_remove->GetSize(); |
| 2713 for (int i = 0; i < num_removals; i++) { | 2718 for (int i = 0; i < num_removals; i++) { |
| 2714 std::string removal; | 2719 std::string removal; |
| 2715 to_remove->GetString(i, &removal); | 2720 to_remove->GetString(i, &removal); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2738 // The observer also deletes itself after sending the reply. | 2743 // The observer also deletes itself after sending the reply. |
| 2739 } | 2744 } |
| 2740 | 2745 |
| 2741 namespace { | 2746 namespace { |
| 2742 | 2747 |
| 2743 // Get the TabContents from a dictionary of arguments. | 2748 // Get the TabContents from a dictionary of arguments. |
| 2744 TabContents* GetTabContentsFromDict(const Browser* browser, | 2749 TabContents* GetTabContentsFromDict(const Browser* browser, |
| 2745 const DictionaryValue* args, | 2750 const DictionaryValue* args, |
| 2746 std::string* error_message) { | 2751 std::string* error_message) { |
| 2747 int tab_index; | 2752 int tab_index; |
| 2748 if (!args->GetInteger(L"tab_index", &tab_index)) { | 2753 if (!args->GetInteger("tab_index", &tab_index)) { |
| 2749 *error_message = "Must include tab_index."; | 2754 *error_message = "Must include tab_index."; |
| 2750 return NULL; | 2755 return NULL; |
| 2751 } | 2756 } |
| 2752 | 2757 |
| 2753 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); | 2758 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); |
| 2754 if (!tab_contents) { | 2759 if (!tab_contents) { |
| 2755 *error_message = StringPrintf("No tab at index %d.", tab_index); | 2760 *error_message = StringPrintf("No tab at index %d.", tab_index); |
| 2756 return NULL; | 2761 return NULL; |
| 2757 } | 2762 } |
| 2758 return tab_contents; | 2763 return tab_contents; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2818 } | 2823 } |
| 2819 | 2824 |
| 2820 TranslateInfoBarDelegate* translate_bar = | 2825 TranslateInfoBarDelegate* translate_bar = |
| 2821 GetTranslateInfoBarDelegate(tab_contents); | 2826 GetTranslateInfoBarDelegate(tab_contents); |
| 2822 if (!translate_bar) { | 2827 if (!translate_bar) { |
| 2823 AutomationJSONReply(this, reply_message) | 2828 AutomationJSONReply(this, reply_message) |
| 2824 .SendError("There is no translate bar open."); | 2829 .SendError("There is no translate bar open."); |
| 2825 return; | 2830 return; |
| 2826 } | 2831 } |
| 2827 | 2832 |
| 2828 if (!args->GetString(L"option", &option)) { | 2833 if (!args->GetString("option", &option)) { |
| 2829 AutomationJSONReply(this, reply_message).SendError("Must include option"); | 2834 AutomationJSONReply(this, reply_message).SendError("Must include option"); |
| 2830 return; | 2835 return; |
| 2831 } | 2836 } |
| 2832 | 2837 |
| 2833 if (option == "translate_page") { | 2838 if (option == "translate_page") { |
| 2834 // Make a new notification observer which will send the reply. | 2839 // Make a new notification observer which will send the reply. |
| 2835 new PageTranslatedObserver(this, reply_message, tab_contents); | 2840 new PageTranslatedObserver(this, reply_message, tab_contents); |
| 2836 translate_bar->Translate(); | 2841 translate_bar->Translate(); |
| 2837 return; | 2842 return; |
| 2838 } | 2843 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2881 new PageTranslatedObserver(this, reply_message, tab_contents); | 2886 new PageTranslatedObserver(this, reply_message, tab_contents); |
| 2882 return; | 2887 return; |
| 2883 } | 2888 } |
| 2884 // Otherwise send back the success or failure of the attempted translation | 2889 // Otherwise send back the success or failure of the attempted translation |
| 2885 // based on the translate bar state. | 2890 // based on the translate bar state. |
| 2886 AutomationJSONReply reply(this, reply_message); | 2891 AutomationJSONReply reply(this, reply_message); |
| 2887 TranslateInfoBarDelegate* translate_bar = | 2892 TranslateInfoBarDelegate* translate_bar = |
| 2888 GetTranslateInfoBarDelegate(tab_contents); | 2893 GetTranslateInfoBarDelegate(tab_contents); |
| 2889 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2894 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2890 if (!translate_bar) { | 2895 if (!translate_bar) { |
| 2891 return_value->SetBoolean(L"translation_success", false); | 2896 return_value->SetBoolean("translation_success", false); |
| 2892 } else { | 2897 } else { |
| 2893 return_value->SetBoolean( | 2898 return_value->SetBoolean( |
| 2894 L"translation_success", | 2899 "translation_success", |
| 2895 translate_bar->type() == TranslateInfoBarDelegate::AFTER_TRANSLATE); | 2900 translate_bar->type() == TranslateInfoBarDelegate::AFTER_TRANSLATE); |
| 2896 } | 2901 } |
| 2897 reply.SendSuccess(return_value.get()); | 2902 reply.SendSuccess(return_value.get()); |
| 2898 } | 2903 } |
| 2899 | 2904 |
| 2900 // Sample json input: { "command": "GetThemeInfo" } | 2905 // Sample json input: { "command": "GetThemeInfo" } |
| 2901 // Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output. | 2906 // Refer GetThemeInfo() in chrome/test/pyautolib/pyauto.py for sample output. |
| 2902 void AutomationProvider::GetThemeInfo(Browser* browser, | 2907 void AutomationProvider::GetThemeInfo(Browser* browser, |
| 2903 DictionaryValue* args, | 2908 DictionaryValue* args, |
| 2904 IPC::Message* reply_message) { | 2909 IPC::Message* reply_message) { |
| 2905 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2910 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2906 Extension* theme = browser->profile()->GetTheme(); | 2911 Extension* theme = browser->profile()->GetTheme(); |
| 2907 if (theme) { | 2912 if (theme) { |
| 2908 return_value->SetString(L"name", theme->name()); | 2913 return_value->SetString("name", theme->name()); |
| 2909 return_value->Set(L"images", theme->GetThemeImages()->DeepCopy()); | 2914 return_value->Set("images", theme->GetThemeImages()->DeepCopy()); |
| 2910 return_value->Set(L"colors", theme->GetThemeColors()->DeepCopy()); | 2915 return_value->Set("colors", theme->GetThemeColors()->DeepCopy()); |
| 2911 return_value->Set(L"tints", theme->GetThemeTints()->DeepCopy()); | 2916 return_value->Set("tints", theme->GetThemeTints()->DeepCopy()); |
| 2912 } | 2917 } |
| 2913 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 2918 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 2914 } | 2919 } |
| 2915 | 2920 |
| 2916 // Sample json input: { "command": "GetExtensionsInfo" } | 2921 // Sample json input: { "command": "GetExtensionsInfo" } |
| 2917 // See GetExtensionsInfo() in chrome/test/pyautolib/pyauto.py for sample json | 2922 // See GetExtensionsInfo() in chrome/test/pyautolib/pyauto.py for sample json |
| 2918 // output. | 2923 // output. |
| 2919 void AutomationProvider::GetExtensionsInfo(Browser* browser, | 2924 void AutomationProvider::GetExtensionsInfo(Browser* browser, |
| 2920 DictionaryValue* args, | 2925 DictionaryValue* args, |
| 2921 IPC::Message* reply_message) { | 2926 IPC::Message* reply_message) { |
| 2922 AutomationJSONReply reply(this, reply_message); | 2927 AutomationJSONReply reply(this, reply_message); |
| 2923 ExtensionsService* service = profile()->GetExtensionsService(); | 2928 ExtensionsService* service = profile()->GetExtensionsService(); |
| 2924 if (!service) { | 2929 if (!service) { |
| 2925 reply.SendError("No extensions service."); | 2930 reply.SendError("No extensions service."); |
| 2926 } | 2931 } |
| 2927 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2932 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2928 ListValue* extensions_values = new ListValue; | 2933 ListValue* extensions_values = new ListValue; |
| 2929 const ExtensionList* extensions = service->extensions(); | 2934 const ExtensionList* extensions = service->extensions(); |
| 2930 for (ExtensionList::const_iterator it = extensions->begin(); | 2935 for (ExtensionList::const_iterator it = extensions->begin(); |
| 2931 it != extensions->end(); ++it) { | 2936 it != extensions->end(); ++it) { |
| 2932 const Extension* extension = *it; | 2937 const Extension* extension = *it; |
| 2933 DictionaryValue* extension_value = new DictionaryValue; | 2938 DictionaryValue* extension_value = new DictionaryValue; |
| 2934 extension_value->SetString(L"id", extension->id()); | 2939 extension_value->SetString("id", extension->id()); |
| 2935 extension_value->SetString(L"version", extension->VersionString()); | 2940 extension_value->SetString("version", extension->VersionString()); |
| 2936 extension_value->SetString(L"name", extension->name()); | 2941 extension_value->SetString("name", extension->name()); |
| 2937 extension_value->SetString(L"public_key", extension->public_key()); | 2942 extension_value->SetString("public_key", extension->public_key()); |
| 2938 extension_value->SetString(L"description", extension->description()); | 2943 extension_value->SetString("description", extension->description()); |
| 2939 extension_value->SetString(L"background_url", | 2944 extension_value->SetString("background_url", |
| 2940 extension->background_url().spec()); | 2945 extension->background_url().spec()); |
| 2941 extension_value->SetString(L"options_url", | 2946 extension_value->SetString("options_url", |
| 2942 extension->options_url().spec()); | 2947 extension->options_url().spec()); |
| 2943 extensions_values->Append(extension_value); | 2948 extensions_values->Append(extension_value); |
| 2944 } | 2949 } |
| 2945 return_value->Set(L"extensions", extensions_values); | 2950 return_value->Set("extensions", extensions_values); |
| 2946 reply.SendSuccess(return_value.get()); | 2951 reply.SendSuccess(return_value.get()); |
| 2947 } | 2952 } |
| 2948 | 2953 |
| 2949 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample | 2954 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample |
| 2950 // json input. | 2955 // json input. |
| 2951 // Sample json output: {} | 2956 // Sample json output: {} |
| 2952 void AutomationProvider::UninstallExtensionById(Browser* browser, | 2957 void AutomationProvider::UninstallExtensionById(Browser* browser, |
| 2953 DictionaryValue* args, | 2958 DictionaryValue* args, |
| 2954 IPC::Message* reply_message) { | 2959 IPC::Message* reply_message) { |
| 2955 AutomationJSONReply reply(this, reply_message); | 2960 AutomationJSONReply reply(this, reply_message); |
| 2956 std::string id; | 2961 std::string id; |
| 2957 if (!args->GetString(L"id", &id)) { | 2962 if (!args->GetString("id", &id)) { |
| 2958 reply.SendError("Must include string id."); | 2963 reply.SendError("Must include string id."); |
| 2959 return; | 2964 return; |
| 2960 } | 2965 } |
| 2961 ExtensionsService* service = profile()->GetExtensionsService(); | 2966 ExtensionsService* service = profile()->GetExtensionsService(); |
| 2962 if (!service) { | 2967 if (!service) { |
| 2963 reply.SendError("No extensions service."); | 2968 reply.SendError("No extensions service."); |
| 2964 return; | 2969 return; |
| 2965 } | 2970 } |
| 2966 ExtensionUnloadNotificationObserver observer; | 2971 ExtensionUnloadNotificationObserver observer; |
| 2967 service->UninstallExtension(id, false); | 2972 service->UninstallExtension(id, false); |
| 2968 reply.SendSuccess(NULL); | 2973 reply.SendSuccess(NULL); |
| 2969 } | 2974 } |
| 2970 | 2975 |
| 2971 // Sample json input: | 2976 // Sample json input: |
| 2972 // { "command": "GetAutoFillProfile" } | 2977 // { "command": "GetAutoFillProfile" } |
| 2973 // Refer to GetAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample | 2978 // Refer to GetAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample |
| 2974 // json output. | 2979 // json output. |
| 2975 void AutomationProvider::GetAutoFillProfile(Browser* browser, | 2980 void AutomationProvider::GetAutoFillProfile(Browser* browser, |
| 2976 DictionaryValue* args, | 2981 DictionaryValue* args, |
| 2977 IPC::Message* reply_message) { | 2982 IPC::Message* reply_message) { |
| 2978 // Get the AutoFillProfiles currently in the database. | 2983 // Get the AutoFillProfiles currently in the database. |
| 2979 int tab_index = 0; | 2984 int tab_index = 0; |
| 2980 args->GetInteger(L"tab_index", &tab_index); | 2985 args->GetInteger("tab_index", &tab_index); |
| 2981 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); | 2986 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); |
| 2982 AutomationJSONReply reply(this, reply_message); | 2987 AutomationJSONReply reply(this, reply_message); |
| 2983 | 2988 |
| 2984 if (tab_contents) { | 2989 if (tab_contents) { |
| 2985 PersonalDataManager* pdm = tab_contents->profile()->GetOriginalProfile() | 2990 PersonalDataManager* pdm = tab_contents->profile()->GetOriginalProfile() |
| 2986 ->GetPersonalDataManager(); | 2991 ->GetPersonalDataManager(); |
| 2987 if (pdm) { | 2992 if (pdm) { |
| 2988 std::vector<AutoFillProfile*> autofill_profiles = pdm->profiles(); | 2993 std::vector<AutoFillProfile*> autofill_profiles = pdm->profiles(); |
| 2989 std::vector<CreditCard*> credit_cards = pdm->credit_cards(); | 2994 std::vector<CreditCard*> credit_cards = pdm->credit_cards(); |
| 2990 | 2995 |
| 2991 ListValue* profiles = GetListFromAutoFillProfiles(autofill_profiles); | 2996 ListValue* profiles = GetListFromAutoFillProfiles(autofill_profiles); |
| 2992 ListValue* cards = GetListFromCreditCards(credit_cards); | 2997 ListValue* cards = GetListFromCreditCards(credit_cards); |
| 2993 | 2998 |
| 2994 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 2999 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 2995 | 3000 |
| 2996 return_value->Set(L"profiles", profiles); | 3001 return_value->Set("profiles", profiles); |
| 2997 return_value->Set(L"credit_cards", cards); | 3002 return_value->Set("credit_cards", cards); |
| 2998 reply.SendSuccess(return_value.get()); | 3003 reply.SendSuccess(return_value.get()); |
| 2999 } else { | 3004 } else { |
| 3000 reply.SendError("No PersonalDataManager."); | 3005 reply.SendError("No PersonalDataManager."); |
| 3001 return; | 3006 return; |
| 3002 } | 3007 } |
| 3003 } else { | 3008 } else { |
| 3004 reply.SendError("No tab at that index."); | 3009 reply.SendError("No tab at that index."); |
| 3005 return; | 3010 return; |
| 3006 } | 3011 } |
| 3007 } | 3012 } |
| 3008 | 3013 |
| 3009 // Refer to FillAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample | 3014 // Refer to FillAutoFillProfile() in chrome/test/pyautolib/pyauto.py for sample |
| 3010 // json input. | 3015 // json input. |
| 3011 // Sample json output: {} | 3016 // Sample json output: {} |
| 3012 void AutomationProvider::FillAutoFillProfile(Browser* browser, | 3017 void AutomationProvider::FillAutoFillProfile(Browser* browser, |
| 3013 DictionaryValue* args, | 3018 DictionaryValue* args, |
| 3014 IPC::Message* reply_message) { | 3019 IPC::Message* reply_message) { |
| 3015 AutomationJSONReply reply(this, reply_message); | 3020 AutomationJSONReply reply(this, reply_message); |
| 3016 ListValue* profiles = NULL; | 3021 ListValue* profiles = NULL; |
| 3017 ListValue* cards = NULL; | 3022 ListValue* cards = NULL; |
| 3018 args->GetList(L"profiles", &profiles); | 3023 args->GetList("profiles", &profiles); |
| 3019 args->GetList(L"credit_cards", &cards); | 3024 args->GetList("credit_cards", &cards); |
| 3020 std::string error_mesg; | 3025 std::string error_mesg; |
| 3021 | 3026 |
| 3022 std::vector<AutoFillProfile> autofill_profiles; | 3027 std::vector<AutoFillProfile> autofill_profiles; |
| 3023 std::vector<CreditCard> credit_cards; | 3028 std::vector<CreditCard> credit_cards; |
| 3024 // Create an AutoFillProfile for each of the dictionary profiles. | 3029 // Create an AutoFillProfile for each of the dictionary profiles. |
| 3025 if (profiles) { | 3030 if (profiles) { |
| 3026 autofill_profiles = GetAutoFillProfilesFromList(*profiles, &error_mesg); | 3031 autofill_profiles = GetAutoFillProfilesFromList(*profiles, &error_mesg); |
| 3027 } | 3032 } |
| 3028 // Create a CreditCard for each of the dictionary values. | 3033 // Create a CreditCard for each of the dictionary values. |
| 3029 if (cards) { | 3034 if (cards) { |
| 3030 credit_cards = GetCreditCardsFromList(*cards, &error_mesg); | 3035 credit_cards = GetCreditCardsFromList(*cards, &error_mesg); |
| 3031 } | 3036 } |
| 3032 if (!error_mesg.empty()) { | 3037 if (!error_mesg.empty()) { |
| 3033 reply.SendError(error_mesg); | 3038 reply.SendError(error_mesg); |
| 3034 return; | 3039 return; |
| 3035 } | 3040 } |
| 3036 | 3041 |
| 3037 // Save the AutoFillProfiles. | 3042 // Save the AutoFillProfiles. |
| 3038 int tab_index = 0; | 3043 int tab_index = 0; |
| 3039 args->GetInteger(L"tab_index", &tab_index); | 3044 args->GetInteger("tab_index", &tab_index); |
| 3040 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); | 3045 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); |
| 3041 | 3046 |
| 3042 if (tab_contents) { | 3047 if (tab_contents) { |
| 3043 PersonalDataManager* pdm = tab_contents->profile() | 3048 PersonalDataManager* pdm = tab_contents->profile() |
| 3044 ->GetPersonalDataManager(); | 3049 ->GetPersonalDataManager(); |
| 3045 if (pdm) { | 3050 if (pdm) { |
| 3046 pdm->OnAutoFillDialogApply(profiles? &autofill_profiles : NULL, | 3051 pdm->OnAutoFillDialogApply(profiles? &autofill_profiles : NULL, |
| 3047 cards? &credit_cards : NULL); | 3052 cards? &credit_cards : NULL); |
| 3048 } else { | 3053 } else { |
| 3049 reply.SendError("No PersonalDataManager."); | 3054 reply.SendError("No PersonalDataManager."); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3062 ListValue* profiles = new ListValue; | 3067 ListValue* profiles = new ListValue; |
| 3063 | 3068 |
| 3064 std::map<AutoFillFieldType, std::wstring> autofill_type_to_string | 3069 std::map<AutoFillFieldType, std::wstring> autofill_type_to_string |
| 3065 = GetAutoFillFieldToStringMap(); | 3070 = GetAutoFillFieldToStringMap(); |
| 3066 | 3071 |
| 3067 // For each AutoFillProfile, transform it to a dictionary object to return. | 3072 // For each AutoFillProfile, transform it to a dictionary object to return. |
| 3068 for (std::vector<AutoFillProfile*>::iterator it = autofill_profiles.begin(); | 3073 for (std::vector<AutoFillProfile*>::iterator it = autofill_profiles.begin(); |
| 3069 it != autofill_profiles.end(); ++it) { | 3074 it != autofill_profiles.end(); ++it) { |
| 3070 AutoFillProfile* profile = *it; | 3075 AutoFillProfile* profile = *it; |
| 3071 DictionaryValue* profile_info = new DictionaryValue; | 3076 DictionaryValue* profile_info = new DictionaryValue; |
| 3072 profile_info->SetStringFromUTF16(L"label", profile->Label()); | 3077 profile_info->SetString("label", profile->Label()); |
| 3073 // For each of the types, if it has a value, add it to the dictionary. | 3078 // For each of the types, if it has a value, add it to the dictionary. |
| 3074 for (std::map<AutoFillFieldType, std::wstring>::iterator | 3079 for (std::map<AutoFillFieldType, std::wstring>::iterator |
| 3075 type_it = autofill_type_to_string.begin(); | 3080 type_it = autofill_type_to_string.begin(); |
| 3076 type_it != autofill_type_to_string.end(); ++type_it) { | 3081 type_it != autofill_type_to_string.end(); ++type_it) { |
| 3077 string16 value = profile->GetFieldText(AutoFillType(type_it->first)); | 3082 string16 value = profile->GetFieldText(AutoFillType(type_it->first)); |
| 3078 if (value.length()) { // If there was something stored for that value. | 3083 if (value.length()) { // If there was something stored for that value. |
| 3079 profile_info->SetStringFromUTF16(type_it->second, value); | 3084 profile_info->SetString(type_it->second, value); |
| 3080 } | 3085 } |
| 3081 } | 3086 } |
| 3082 profiles->Append(profile_info); | 3087 profiles->Append(profile_info); |
| 3083 } | 3088 } |
| 3084 return profiles; | 3089 return profiles; |
| 3085 } | 3090 } |
| 3086 | 3091 |
| 3087 /* static */ | 3092 /* static */ |
| 3088 ListValue* AutomationProvider::GetListFromCreditCards( | 3093 ListValue* AutomationProvider::GetListFromCreditCards( |
| 3089 std::vector<CreditCard*> credit_cards) { | 3094 std::vector<CreditCard*> credit_cards) { |
| 3090 ListValue* cards = new ListValue; | 3095 ListValue* cards = new ListValue; |
| 3091 | 3096 |
| 3092 std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string = | 3097 std::map<AutoFillFieldType, std::wstring> credit_card_type_to_string = |
| 3093 GetCreditCardFieldToStringMap(); | 3098 GetCreditCardFieldToStringMap(); |
| 3094 | 3099 |
| 3095 // For each AutoFillProfile, transform it to a dictionary object to return. | 3100 // For each AutoFillProfile, transform it to a dictionary object to return. |
| 3096 for (std::vector<CreditCard*>::iterator it = credit_cards.begin(); | 3101 for (std::vector<CreditCard*>::iterator it = credit_cards.begin(); |
| 3097 it != credit_cards.end(); ++it) { | 3102 it != credit_cards.end(); ++it) { |
| 3098 CreditCard* card = *it; | 3103 CreditCard* card = *it; |
| 3099 DictionaryValue* card_info = new DictionaryValue; | 3104 DictionaryValue* card_info = new DictionaryValue; |
| 3100 card_info->SetStringFromUTF16(L"label", card->Label()); | 3105 card_info->SetString("label", card->Label()); |
| 3101 // For each of the types, if it has a value, add it to the dictionary. | 3106 // For each of the types, if it has a value, add it to the dictionary. |
| 3102 for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = | 3107 for (std::map<AutoFillFieldType, std::wstring>::iterator type_it = |
| 3103 credit_card_type_to_string.begin(); | 3108 credit_card_type_to_string.begin(); |
| 3104 type_it != credit_card_type_to_string.end(); ++type_it) { | 3109 type_it != credit_card_type_to_string.end(); ++type_it) { |
| 3105 string16 value = card->GetFieldText(AutoFillType(type_it->first)); | 3110 string16 value = card->GetFieldText(AutoFillType(type_it->first)); |
| 3106 // If there was something stored for that value. | 3111 // If there was something stored for that value. |
| 3107 if (value.length()) { | 3112 if (value.length()) { |
| 3108 card_info->SetStringFromUTF16(type_it->second, value); | 3113 card_info->SetString(type_it->second, value); |
| 3109 } | 3114 } |
| 3110 } | 3115 } |
| 3111 cards->Append(card_info); | 3116 cards->Append(card_info); |
| 3112 } | 3117 } |
| 3113 return cards; | 3118 return cards; |
| 3114 } | 3119 } |
| 3115 | 3120 |
| 3116 /* static */ | 3121 /* static */ |
| 3117 std::vector<AutoFillProfile> AutomationProvider::GetAutoFillProfilesFromList( | 3122 std::vector<AutoFillProfile> AutomationProvider::GetAutoFillProfilesFromList( |
| 3118 const ListValue& profiles, std::string* error_message) { | 3123 const ListValue& profiles, std::string* error_message) { |
| (...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4485 } | 4490 } |
| 4486 | 4491 |
| 4487 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 4492 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
| 4488 NOTIMPLEMENTED(); | 4493 NOTIMPLEMENTED(); |
| 4489 } | 4494 } |
| 4490 #endif // !defined(TOOLKIT_VIEWS) | 4495 #endif // !defined(TOOLKIT_VIEWS) |
| 4491 | 4496 |
| 4492 void AutomationProvider::ResetToDefaultTheme() { | 4497 void AutomationProvider::ResetToDefaultTheme() { |
| 4493 profile_->ClearTheme(); | 4498 profile_->ClearTheme(); |
| 4494 } | 4499 } |
| OLD | NEW |