| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 } | 1626 } |
| 1627 | 1627 |
| 1628 void TabsDetectLanguageFunction::GotLanguage(const std::string& language) { | 1628 void TabsDetectLanguageFunction::GotLanguage(const std::string& language) { |
| 1629 SetResult(new base::StringValue(language.c_str())); | 1629 SetResult(new base::StringValue(language.c_str())); |
| 1630 SendResponse(true); | 1630 SendResponse(true); |
| 1631 | 1631 |
| 1632 Release(); // Balanced in Run() | 1632 Release(); // Balanced in Run() |
| 1633 } | 1633 } |
| 1634 | 1634 |
| 1635 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() | 1635 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() |
| 1636 : execute_tab_id_(-1) { | 1636 : chrome_details_(this), execute_tab_id_(-1) { |
| 1637 } | 1637 } |
| 1638 | 1638 |
| 1639 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} | 1639 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} |
| 1640 | 1640 |
| 1641 bool ExecuteCodeInTabFunction::HasPermission() { | 1641 bool ExecuteCodeInTabFunction::HasPermission() { |
| 1642 if (Init() && | 1642 if (Init() && |
| 1643 extension_->permissions_data()->HasAPIPermissionForTab( | 1643 extension_->permissions_data()->HasAPIPermissionForTab( |
| 1644 execute_tab_id_, APIPermission::kTab)) { | 1644 execute_tab_id_, APIPermission::kTab)) { |
| 1645 return true; | 1645 return true; |
| 1646 } | 1646 } |
| 1647 return ExtensionFunction::HasPermission(); | 1647 return ExtensionFunction::HasPermission(); |
| 1648 } | 1648 } |
| 1649 | 1649 |
| 1650 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { | 1650 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { |
| 1651 content::WebContents* contents = NULL; | 1651 content::WebContents* contents = NULL; |
| 1652 | 1652 |
| 1653 // If |tab_id| is specified, look for the tab. Otherwise default to selected | 1653 // If |tab_id| is specified, look for the tab. Otherwise default to selected |
| 1654 // tab in the current window. | 1654 // tab in the current window. |
| 1655 CHECK_GE(execute_tab_id_, 0); | 1655 CHECK_GE(execute_tab_id_, 0); |
| 1656 if (!GetTabById(execute_tab_id_, | 1656 if (!GetTabById(execute_tab_id_, |
| 1657 GetProfile(), | 1657 chrome_details_.GetProfile(), |
| 1658 include_incognito(), | 1658 include_incognito(), |
| 1659 NULL, | 1659 NULL, |
| 1660 NULL, | 1660 NULL, |
| 1661 &contents, | 1661 &contents, |
| 1662 NULL, | 1662 NULL, |
| 1663 &error_)) { | 1663 &error_)) { |
| 1664 return false; | 1664 return false; |
| 1665 } | 1665 } |
| 1666 | 1666 |
| 1667 CHECK(contents); | 1667 CHECK(contents); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1680 } | 1680 } |
| 1681 | 1681 |
| 1682 return true; | 1682 return true; |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { | 1685 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { |
| 1686 Browser* browser = NULL; | 1686 Browser* browser = NULL; |
| 1687 content::WebContents* contents = NULL; | 1687 content::WebContents* contents = NULL; |
| 1688 | 1688 |
| 1689 bool success = GetTabById(execute_tab_id_, | 1689 bool success = GetTabById(execute_tab_id_, |
| 1690 GetProfile(), | 1690 chrome_details_.GetProfile(), |
| 1691 include_incognito(), | 1691 include_incognito(), |
| 1692 &browser, | 1692 &browser, |
| 1693 NULL, | 1693 NULL, |
| 1694 &contents, | 1694 &contents, |
| 1695 NULL, | 1695 NULL, |
| 1696 &error_) && | 1696 &error_) && |
| 1697 contents && browser; | 1697 contents && browser; |
| 1698 | 1698 |
| 1699 if (!success) | 1699 if (!success) |
| 1700 return NULL; | 1700 return NULL; |
| 1701 | 1701 |
| 1702 return TabHelper::FromWebContents(contents)->script_executor(); | 1702 return TabHelper::FromWebContents(contents)->script_executor(); |
| 1703 } | 1703 } |
| 1704 | 1704 |
| 1705 bool ExecuteCodeInTabFunction::IsWebView() const { | 1705 bool ExecuteCodeInTabFunction::IsWebView() const { |
| 1706 return false; | 1706 return false; |
| 1707 } | 1707 } |
| 1708 | 1708 |
| 1709 const GURL& ExecuteCodeInTabFunction::GetWebViewSrc() const { | 1709 const GURL& ExecuteCodeInTabFunction::GetWebViewSrc() const { |
| 1710 return GURL::EmptyGURL(); | 1710 return GURL::EmptyGURL(); |
| 1711 } | 1711 } |
| 1712 | 1712 |
| 1713 bool TabsExecuteScriptFunction::ShouldInsertCSS() const { | |
| 1714 return false; | |
| 1715 } | |
| 1716 | |
| 1717 void TabsExecuteScriptFunction::OnExecuteCodeFinished( | |
| 1718 const std::string& error, | |
| 1719 const GURL& on_url, | |
| 1720 const base::ListValue& result) { | |
| 1721 if (error.empty()) | |
| 1722 SetResult(result.DeepCopy()); | |
| 1723 ExecuteCodeInTabFunction::OnExecuteCodeFinished(error, on_url, result); | |
| 1724 } | |
| 1725 | |
| 1726 bool ExecuteCodeInTabFunction::Init() { | 1713 bool ExecuteCodeInTabFunction::Init() { |
| 1727 if (details_.get()) | 1714 if (details_.get()) |
| 1728 return true; | 1715 return true; |
| 1729 | 1716 |
| 1730 // |tab_id| is optional so it's ok if it's not there. | 1717 // |tab_id| is optional so it's ok if it's not there. |
| 1731 int tab_id = -1; | 1718 int tab_id = -1; |
| 1732 if (args_->GetInteger(0, &tab_id)) | 1719 if (args_->GetInteger(0, &tab_id)) |
| 1733 EXTENSION_FUNCTION_VALIDATE(tab_id >= 0); | 1720 EXTENSION_FUNCTION_VALIDATE(tab_id >= 0); |
| 1734 | 1721 |
| 1735 // |details| are not optional. | 1722 // |details| are not optional. |
| 1736 base::DictionaryValue* details_value = NULL; | 1723 base::DictionaryValue* details_value = NULL; |
| 1737 if (!args_->GetDictionary(1, &details_value)) | 1724 if (!args_->GetDictionary(1, &details_value)) |
| 1738 return false; | 1725 return false; |
| 1739 scoped_ptr<InjectDetails> details(new InjectDetails()); | 1726 scoped_ptr<InjectDetails> details(new InjectDetails()); |
| 1740 if (!InjectDetails::Populate(*details_value, details.get())) | 1727 if (!InjectDetails::Populate(*details_value, details.get())) |
| 1741 return false; | 1728 return false; |
| 1742 | 1729 |
| 1743 // If the tab ID wasn't given then it needs to be converted to the | 1730 // If the tab ID wasn't given then it needs to be converted to the |
| 1744 // currently active tab's ID. | 1731 // currently active tab's ID. |
| 1745 if (tab_id == -1) { | 1732 if (tab_id == -1) { |
| 1746 Browser* browser = GetCurrentBrowser(); | 1733 Browser* browser = chrome_details_.GetCurrentBrowser(); |
| 1747 if (!browser) | 1734 if (!browser) |
| 1748 return false; | 1735 return false; |
| 1749 content::WebContents* web_contents = NULL; | 1736 content::WebContents* web_contents = NULL; |
| 1750 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) | 1737 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) |
| 1751 return false; | 1738 return false; |
| 1752 } | 1739 } |
| 1753 | 1740 |
| 1754 execute_tab_id_ = tab_id; | 1741 execute_tab_id_ = tab_id; |
| 1755 details_ = details.Pass(); | 1742 details_ = details.Pass(); |
| 1756 return true; | 1743 return true; |
| 1757 } | 1744 } |
| 1758 | 1745 |
| 1746 bool TabsExecuteScriptFunction::ShouldInsertCSS() const { |
| 1747 return false; |
| 1748 } |
| 1749 |
| 1750 void TabsExecuteScriptFunction::OnExecuteCodeFinished( |
| 1751 const std::string& error, |
| 1752 const GURL& on_url, |
| 1753 const base::ListValue& result) { |
| 1754 if (error.empty()) |
| 1755 SetResult(result.DeepCopy()); |
| 1756 ExecuteCodeInTabFunction::OnExecuteCodeFinished(error, on_url, result); |
| 1757 } |
| 1758 |
| 1759 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 1759 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
| 1760 return true; | 1760 return true; |
| 1761 } | 1761 } |
| 1762 | 1762 |
| 1763 content::WebContents* ZoomAPIFunction::GetWebContents(int tab_id) { | 1763 content::WebContents* ZoomAPIFunction::GetWebContents(int tab_id) { |
| 1764 content::WebContents* web_contents = NULL; | 1764 content::WebContents* web_contents = NULL; |
| 1765 if (tab_id != -1) { | 1765 if (tab_id != -1) { |
| 1766 // We assume this call leaves web_contents unchanged if it is unsuccessful. | 1766 // We assume this call leaves web_contents unchanged if it is unsuccessful. |
| 1767 GetTabById(tab_id, | 1767 GetTabById(tab_id, |
| 1768 GetProfile(), | 1768 GetProfile(), |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); | 1895 ZoomController::ZoomMode zoom_mode = zoom_controller->zoom_mode(); |
| 1896 api::tabs::ZoomSettings zoom_settings; | 1896 api::tabs::ZoomSettings zoom_settings; |
| 1897 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 1897 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 1898 | 1898 |
| 1899 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 1899 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 1900 SendResponse(true); | 1900 SendResponse(true); |
| 1901 return true; | 1901 return true; |
| 1902 } | 1902 } |
| 1903 | 1903 |
| 1904 } // namespace extensions | 1904 } // namespace extensions |
| OLD | NEW |