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 <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <memory> | 10 #include <memory> |
(...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1815 if (tab_id == -1) { | 1815 if (tab_id == -1) { |
1816 Browser* browser = chrome_details_.GetCurrentBrowser(); | 1816 Browser* browser = chrome_details_.GetCurrentBrowser(); |
1817 // Can happen during shutdown. | 1817 // Can happen during shutdown. |
1818 if (!browser) | 1818 if (!browser) |
1819 return set_init_result_error(keys::kNoCurrentWindowError); | 1819 return set_init_result_error(keys::kNoCurrentWindowError); |
1820 content::WebContents* web_contents = NULL; | 1820 content::WebContents* web_contents = NULL; |
1821 // Can happen during shutdown. | 1821 // Can happen during shutdown. |
1822 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) | 1822 if (!ExtensionTabUtil::GetDefaultTab(browser, &web_contents, &tab_id)) |
1823 return set_init_result_error(keys::kNoTabInBrowserWindowError); | 1823 return set_init_result_error(keys::kNoTabInBrowserWindowError); |
1824 } | 1824 } |
1825 | 1825 |
karandeepb
2017/07/18 19:26:59
Do we also need to update extension docs for this
Devlin
2017/07/18 20:53:46
I don't think so. We state in numerous places that
karandeepb
2017/07/18 21:06:25
Acknowledged.
| |
1826 execute_tab_id_ = tab_id; | 1826 execute_tab_id_ = tab_id; |
1827 details_ = std::move(details); | 1827 details_ = std::move(details); |
1828 set_host_id(HostID(HostID::EXTENSIONS, extension()->id())); | 1828 set_host_id(HostID(HostID::EXTENSIONS, extension()->id())); |
1829 return set_init_result(SUCCESS); | 1829 return set_init_result(SUCCESS); |
1830 } | 1830 } |
1831 | 1831 |
1832 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { | 1832 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { |
karandeepb
2017/07/18 19:26:59
So we don't do any checks in the browser process?
Devlin
2017/07/18 20:53:46
Funny thing - the URL in the browser side is actua
karandeepb
2017/07/18 21:06:25
Acknowledged.
| |
1833 content::WebContents* contents = NULL; | 1833 content::WebContents* contents = NULL; |
1834 | 1834 |
1835 // If |tab_id| is specified, look for the tab. Otherwise default to selected | 1835 // If |tab_id| is specified, look for the tab. Otherwise default to selected |
1836 // tab in the current window. | 1836 // tab in the current window. |
1837 LOG(WARNING) << "Checking host"; | |
1837 CHECK_GE(execute_tab_id_, 0); | 1838 CHECK_GE(execute_tab_id_, 0); |
1838 if (!GetTabById(execute_tab_id_, browser_context(), include_incognito(), | 1839 if (!GetTabById(execute_tab_id_, browser_context(), include_incognito(), |
1839 nullptr, nullptr, &contents, nullptr, &error_)) { | 1840 nullptr, nullptr, &contents, nullptr, &error_)) { |
1841 LOG(WARNING) << "No tab"; | |
1840 return false; | 1842 return false; |
1841 } | 1843 } |
1842 | 1844 |
1843 CHECK(contents); | 1845 CHECK(contents); |
1844 | 1846 |
1845 int frame_id = details_->frame_id ? *details_->frame_id | 1847 int frame_id = details_->frame_id ? *details_->frame_id |
1846 : ExtensionApiFrameIdMap::kTopFrameId; | 1848 : ExtensionApiFrameIdMap::kTopFrameId; |
1847 content::RenderFrameHost* rfh = | 1849 content::RenderFrameHost* rfh = |
1848 ExtensionApiFrameIdMap::GetRenderFrameHostById(contents, frame_id); | 1850 ExtensionApiFrameIdMap::GetRenderFrameHostById(contents, frame_id); |
1849 if (!rfh) { | 1851 if (!rfh) { |
1852 LOG(WARNING) << "No frame"; | |
karandeepb
2017/07/18 19:26:59
Remove logging.
Devlin
2017/07/18 20:53:46
Whoops, done.
| |
1850 error_ = ErrorUtils::FormatErrorMessage(keys::kFrameNotFoundError, | 1853 error_ = ErrorUtils::FormatErrorMessage(keys::kFrameNotFoundError, |
1851 base::IntToString(frame_id), | 1854 base::IntToString(frame_id), |
1852 base::IntToString(execute_tab_id_)); | 1855 base::IntToString(execute_tab_id_)); |
1853 return false; | 1856 return false; |
1854 } | 1857 } |
1855 | 1858 |
1856 // Content scripts declared in manifest.json can access frames at about:-URLs | 1859 // Content scripts declared in manifest.json can access frames at about:-URLs |
1857 // if the extension has permission to access the frame's origin, so also allow | 1860 // if the extension has permission to access the frame's origin, so also allow |
1858 // programmatic content scripts at about:-URLs for allowed origins. | 1861 // programmatic content scripts at about:-URLs for allowed origins. |
1859 GURL effective_document_url(rfh->GetLastCommittedURL()); | 1862 GURL effective_document_url(rfh->GetLastCommittedURL()); |
1863 LOG(WARNING) << "Effective1: " << effective_document_url; | |
1860 bool is_about_url = effective_document_url.SchemeIs(url::kAboutScheme); | 1864 bool is_about_url = effective_document_url.SchemeIs(url::kAboutScheme); |
1861 if (is_about_url && details_->match_about_blank && | 1865 if (is_about_url && details_->match_about_blank && |
1862 *details_->match_about_blank) { | 1866 *details_->match_about_blank) { |
1863 effective_document_url = GURL(rfh->GetLastCommittedOrigin().Serialize()); | 1867 effective_document_url = GURL(rfh->GetLastCommittedOrigin().Serialize()); |
1868 LOG(WARNING) << "Effective2: " << effective_document_url; | |
1864 } | 1869 } |
1865 | 1870 |
1866 if (!effective_document_url.is_valid()) { | 1871 if (!effective_document_url.is_valid()) { |
1872 LOG(WARNING) << "Invalid, skipping"; | |
1867 // Unknown URL, e.g. because no load was committed yet. Allow for now, the | 1873 // Unknown URL, e.g. because no load was committed yet. Allow for now, the |
1868 // renderer will check again and fail the injection if needed. | 1874 // renderer will check again and fail the injection if needed. |
1869 return true; | 1875 return true; |
1870 } | 1876 } |
1871 | 1877 |
1872 // NOTE: This can give the wrong answer due to race conditions, but it is OK, | 1878 // NOTE: This can give the wrong answer due to race conditions, but it is OK, |
1873 // we check again in the renderer. | 1879 // we check again in the renderer. |
1874 if (!extension()->permissions_data()->CanAccessPage( | 1880 if (!extension()->permissions_data()->CanAccessPage( |
1875 extension(), effective_document_url, execute_tab_id_, &error_)) { | 1881 extension(), effective_document_url, execute_tab_id_, &error_)) { |
1882 LOG(WARNING) << "Denied"; | |
1876 if (is_about_url && | 1883 if (is_about_url && |
1877 extension()->permissions_data()->active_permissions().HasAPIPermission( | 1884 extension()->permissions_data()->active_permissions().HasAPIPermission( |
1878 APIPermission::kTab)) { | 1885 APIPermission::kTab)) { |
1879 error_ = ErrorUtils::FormatErrorMessage( | 1886 error_ = ErrorUtils::FormatErrorMessage( |
1880 manifest_errors::kCannotAccessAboutUrl, | 1887 manifest_errors::kCannotAccessAboutUrl, |
1881 rfh->GetLastCommittedURL().spec(), | 1888 rfh->GetLastCommittedURL().spec(), |
1882 rfh->GetLastCommittedOrigin().Serialize()); | 1889 rfh->GetLastCommittedOrigin().Serialize()); |
1883 } | 1890 } |
1884 return false; | 1891 return false; |
1885 } | 1892 } |
1886 | 1893 |
1894 LOG(WARNING) << "Accepted"; | |
1887 return true; | 1895 return true; |
1888 } | 1896 } |
1889 | 1897 |
1890 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { | 1898 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { |
1891 Browser* browser = NULL; | 1899 Browser* browser = NULL; |
1892 content::WebContents* contents = NULL; | 1900 content::WebContents* contents = NULL; |
1893 | 1901 |
1894 bool success = | 1902 bool success = |
1895 GetTabById(execute_tab_id_, browser_context(), include_incognito(), | 1903 GetTabById(execute_tab_id_, browser_context(), include_incognito(), |
1896 &browser, nullptr, &contents, nullptr, &error_) && | 1904 &browser, nullptr, &contents, nullptr, &error_) && |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2102 params->tab_id | 2110 params->tab_id |
2103 ? ErrorUtils::FormatErrorMessage(keys::kCannotDiscardTab, | 2111 ? ErrorUtils::FormatErrorMessage(keys::kCannotDiscardTab, |
2104 base::IntToString(*params->tab_id)) | 2112 base::IntToString(*params->tab_id)) |
2105 : keys::kCannotFindTabToDiscard)); | 2113 : keys::kCannotFindTabToDiscard)); |
2106 } | 2114 } |
2107 | 2115 |
2108 TabsDiscardFunction::TabsDiscardFunction() {} | 2116 TabsDiscardFunction::TabsDiscardFunction() {} |
2109 TabsDiscardFunction::~TabsDiscardFunction() {} | 2117 TabsDiscardFunction::~TabsDiscardFunction() {} |
2110 | 2118 |
2111 } // namespace extensions | 2119 } // namespace extensions |
OLD | NEW |