| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "chrome/common/extensions/api/tabs.h" | 53 #include "chrome/common/extensions/api/tabs.h" |
| 54 #include "chrome/common/extensions/api/windows.h" | 54 #include "chrome/common/extensions/api/windows.h" |
| 55 #include "chrome/common/extensions/extension.h" | 55 #include "chrome/common/extensions/extension.h" |
| 56 #include "chrome/common/extensions/extension_constants.h" | 56 #include "chrome/common/extensions/extension_constants.h" |
| 57 #include "chrome/common/extensions/extension_file_util.h" | 57 #include "chrome/common/extensions/extension_file_util.h" |
| 58 #include "chrome/common/extensions/extension_l10n_util.h" | 58 #include "chrome/common/extensions/extension_l10n_util.h" |
| 59 #include "chrome/common/extensions/extension_manifest_constants.h" | 59 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 60 #include "chrome/common/extensions/extension_messages.h" | 60 #include "chrome/common/extensions/extension_messages.h" |
| 61 #include "chrome/common/extensions/incognito_handler.h" | 61 #include "chrome/common/extensions/incognito_handler.h" |
| 62 #include "chrome/common/extensions/message_bundle.h" | 62 #include "chrome/common/extensions/message_bundle.h" |
| 63 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 63 #include "chrome/common/extensions/user_script.h" | 64 #include "chrome/common/extensions/user_script.h" |
| 64 #include "chrome/common/pref_names.h" | 65 #include "chrome/common/pref_names.h" |
| 65 #include "chrome/common/url_constants.h" | 66 #include "chrome/common/url_constants.h" |
| 66 #include "components/user_prefs/pref_registry_syncable.h" | 67 #include "components/user_prefs/pref_registry_syncable.h" |
| 67 #include "content/public/browser/navigation_controller.h" | 68 #include "content/public/browser/navigation_controller.h" |
| 68 #include "content/public/browser/navigation_entry.h" | 69 #include "content/public/browser/navigation_entry.h" |
| 69 #include "content/public/browser/notification_details.h" | 70 #include "content/public/browser/notification_details.h" |
| 70 #include "content/public/browser/notification_source.h" | 71 #include "content/public/browser/notification_source.h" |
| 71 #include "content/public/browser/render_view_host.h" | 72 #include "content/public/browser/render_view_host.h" |
| 72 #include "content/public/browser/render_widget_host_view.h" | 73 #include "content/public/browser/render_widget_host_view.h" |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 | 1388 |
| 1388 // Don't let the extension crash the browser or renderers. | 1389 // Don't let the extension crash the browser or renderers. |
| 1389 if (ExtensionTabUtil::IsCrashURL(url)) { | 1390 if (ExtensionTabUtil::IsCrashURL(url)) { |
| 1390 error_ = keys::kNoCrashBrowserError; | 1391 error_ = keys::kNoCrashBrowserError; |
| 1391 return false; | 1392 return false; |
| 1392 } | 1393 } |
| 1393 | 1394 |
| 1394 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so | 1395 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so |
| 1395 // we need to check host permissions before allowing them. | 1396 // we need to check host permissions before allowing them. |
| 1396 if (url.SchemeIs(chrome::kJavaScriptScheme)) { | 1397 if (url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 1397 if (!GetExtension()->CanExecuteScriptOnPage( | 1398 if (!PermissionsData::CanExecuteScriptOnPage( |
| 1399 GetExtension(), |
| 1398 web_contents_->GetURL(), | 1400 web_contents_->GetURL(), |
| 1399 web_contents_->GetURL(), | 1401 web_contents_->GetURL(), |
| 1400 tab_id, | 1402 tab_id, |
| 1401 NULL, | 1403 NULL, |
| 1402 &error_)) { | 1404 &error_)) { |
| 1403 return false; | 1405 return false; |
| 1404 } | 1406 } |
| 1405 | 1407 |
| 1406 TabHelper::FromWebContents(web_contents_)-> | 1408 TabHelper::FromWebContents(web_contents_)-> |
| 1407 script_executor()->ExecuteScript( | 1409 script_executor()->ExecuteScript( |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1731 // committed. A canonical example of this is interstitials, which show the | 1733 // committed. A canonical example of this is interstitials, which show the |
| 1732 // URL of the new/loading page (active) but would capture the content of the | 1734 // URL of the new/loading page (active) but would capture the content of the |
| 1733 // old page (last committed). | 1735 // old page (last committed). |
| 1734 // | 1736 // |
| 1735 // TODO(creis): Use WebContents::GetLastCommittedURL instead. | 1737 // TODO(creis): Use WebContents::GetLastCommittedURL instead. |
| 1736 // http://crbug.com/237908. | 1738 // http://crbug.com/237908. |
| 1737 NavigationEntry* last_committed_entry = | 1739 NavigationEntry* last_committed_entry = |
| 1738 web_contents->GetController().GetLastCommittedEntry(); | 1740 web_contents->GetController().GetLastCommittedEntry(); |
| 1739 GURL last_committed_url = last_committed_entry ? | 1741 GURL last_committed_url = last_committed_entry ? |
| 1740 last_committed_entry->GetURL() : GURL(); | 1742 last_committed_entry->GetURL() : GURL(); |
| 1741 if (!GetExtension()->CanCaptureVisiblePage(last_committed_url, | 1743 if (!PermissionsData::CanCaptureVisiblePage( |
| 1742 SessionID::IdForTab(web_contents), | 1744 GetExtension(), |
| 1743 &error_)) { | 1745 last_committed_url, |
| 1746 SessionID::IdForTab(web_contents), |
| 1747 &error_)) { |
| 1744 return false; | 1748 return false; |
| 1745 } | 1749 } |
| 1746 | 1750 |
| 1747 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); | 1751 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); |
| 1748 content::RenderWidgetHostView* view = render_view_host->GetView(); | 1752 content::RenderWidgetHostView* view = render_view_host->GetView(); |
| 1749 if (!view) { | 1753 if (!view) { |
| 1750 error_ = keys::kInternalVisibleTabCaptureError; | 1754 error_ = keys::kInternalVisibleTabCaptureError; |
| 1751 return false; | 1755 return false; |
| 1752 } | 1756 } |
| 1753 render_view_host->CopyFromBackingStore( | 1757 render_view_host->CopyFromBackingStore( |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1945 } | 1949 } |
| 1946 | 1950 |
| 1947 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() | 1951 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() |
| 1948 : execute_tab_id_(-1) { | 1952 : execute_tab_id_(-1) { |
| 1949 } | 1953 } |
| 1950 | 1954 |
| 1951 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} | 1955 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} |
| 1952 | 1956 |
| 1953 bool ExecuteCodeInTabFunction::HasPermission() { | 1957 bool ExecuteCodeInTabFunction::HasPermission() { |
| 1954 if (Init() && | 1958 if (Init() && |
| 1955 extension_->HasAPIPermissionForTab(execute_tab_id_, | 1959 PermissionsData::HasAPIPermissionForTab( |
| 1956 APIPermission::kTab)) { | 1960 extension_, execute_tab_id_, APIPermission::kTab)) { |
| 1957 return true; | 1961 return true; |
| 1958 } | 1962 } |
| 1959 return ExtensionFunction::HasPermission(); | 1963 return ExtensionFunction::HasPermission(); |
| 1960 } | 1964 } |
| 1961 | 1965 |
| 1962 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { | 1966 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { |
| 1963 content::WebContents* contents = NULL; | 1967 content::WebContents* contents = NULL; |
| 1964 | 1968 |
| 1965 // If |tab_id| is specified, look for the tab. Otherwise default to selected | 1969 // If |tab_id| is specified, look for the tab. Otherwise default to selected |
| 1966 // tab in the current window. | 1970 // tab in the current window. |
| 1967 CHECK_GE(execute_tab_id_, 0); | 1971 CHECK_GE(execute_tab_id_, 0); |
| 1968 if (!GetTabById(execute_tab_id_, profile(), | 1972 if (!GetTabById(execute_tab_id_, profile(), |
| 1969 include_incognito(), | 1973 include_incognito(), |
| 1970 NULL, NULL, &contents, NULL, &error_)) { | 1974 NULL, NULL, &contents, NULL, &error_)) { |
| 1971 return false; | 1975 return false; |
| 1972 } | 1976 } |
| 1973 | 1977 |
| 1974 CHECK(contents); | 1978 CHECK(contents); |
| 1975 | 1979 |
| 1976 // NOTE: This can give the wrong answer due to race conditions, but it is OK, | 1980 // NOTE: This can give the wrong answer due to race conditions, but it is OK, |
| 1977 // we check again in the renderer. | 1981 // we check again in the renderer. |
| 1978 if (!GetExtension()->CanExecuteScriptOnPage(contents->GetURL(), | 1982 if (!PermissionsData::CanExecuteScriptOnPage(GetExtension(), |
| 1979 contents->GetURL(), | 1983 contents->GetURL(), |
| 1980 execute_tab_id_, | 1984 contents->GetURL(), |
| 1981 NULL, | 1985 execute_tab_id_, |
| 1982 &error_)) { | 1986 NULL, |
| 1987 &error_)) { |
| 1983 return false; | 1988 return false; |
| 1984 } | 1989 } |
| 1985 | 1990 |
| 1986 return true; | 1991 return true; |
| 1987 } | 1992 } |
| 1988 | 1993 |
| 1989 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { | 1994 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { |
| 1990 Browser* browser = NULL; | 1995 Browser* browser = NULL; |
| 1991 content::WebContents* contents = NULL; | 1996 content::WebContents* contents = NULL; |
| 1992 | 1997 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2049 execute_tab_id_ = tab_id; | 2054 execute_tab_id_ = tab_id; |
| 2050 details_ = details.Pass(); | 2055 details_ = details.Pass(); |
| 2051 return true; | 2056 return true; |
| 2052 } | 2057 } |
| 2053 | 2058 |
| 2054 bool TabsInsertCSSFunction::ShouldInsertCSS() const { | 2059 bool TabsInsertCSSFunction::ShouldInsertCSS() const { |
| 2055 return true; | 2060 return true; |
| 2056 } | 2061 } |
| 2057 | 2062 |
| 2058 } // namespace extensions | 2063 } // namespace extensions |
| OLD | NEW |