| 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 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 | 1403 |
| 1403 // Don't let the extension crash the browser or renderers. | 1404 // Don't let the extension crash the browser or renderers. |
| 1404 if (ExtensionTabUtil::IsCrashURL(url)) { | 1405 if (ExtensionTabUtil::IsCrashURL(url)) { |
| 1405 error_ = keys::kNoCrashBrowserError; | 1406 error_ = keys::kNoCrashBrowserError; |
| 1406 return false; | 1407 return false; |
| 1407 } | 1408 } |
| 1408 | 1409 |
| 1409 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so | 1410 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so |
| 1410 // we need to check host permissions before allowing them. | 1411 // we need to check host permissions before allowing them. |
| 1411 if (url.SchemeIs(chrome::kJavaScriptScheme)) { | 1412 if (url.SchemeIs(chrome::kJavaScriptScheme)) { |
| 1412 if (!GetExtension()->CanExecuteScriptOnPage( | 1413 if (!extensions::PermissionsData::CanExecuteScriptOnPage( |
| 1414 GetExtension(), |
| 1413 web_contents_->GetURL(), | 1415 web_contents_->GetURL(), |
| 1414 web_contents_->GetURL(), | 1416 web_contents_->GetURL(), |
| 1415 tab_id, | 1417 tab_id, |
| 1416 NULL, | 1418 NULL, |
| 1417 &error_)) { | 1419 &error_)) { |
| 1418 return false; | 1420 return false; |
| 1419 } | 1421 } |
| 1420 | 1422 |
| 1421 extensions::TabHelper::FromWebContents(web_contents_)-> | 1423 extensions::TabHelper::FromWebContents(web_contents_)-> |
| 1422 script_executor()->ExecuteScript( | 1424 script_executor()->ExecuteScript( |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 // committed. A canonical example of this is interstitials, which show the | 1735 // committed. A canonical example of this is interstitials, which show the |
| 1734 // URL of the new/loading page (active) but would capture the content of the | 1736 // URL of the new/loading page (active) but would capture the content of the |
| 1735 // old page (last committed). | 1737 // old page (last committed). |
| 1736 // | 1738 // |
| 1737 // TODO(creis): Use WebContents::GetLastCommittedURL instead. | 1739 // TODO(creis): Use WebContents::GetLastCommittedURL instead. |
| 1738 // http://crbug.com/237908. | 1740 // http://crbug.com/237908. |
| 1739 NavigationEntry* last_committed_entry = | 1741 NavigationEntry* last_committed_entry = |
| 1740 web_contents->GetController().GetLastCommittedEntry(); | 1742 web_contents->GetController().GetLastCommittedEntry(); |
| 1741 GURL last_committed_url = last_committed_entry ? | 1743 GURL last_committed_url = last_committed_entry ? |
| 1742 last_committed_entry->GetURL() : GURL(); | 1744 last_committed_entry->GetURL() : GURL(); |
| 1743 if (!GetExtension()->CanCaptureVisiblePage(last_committed_url, | 1745 if (!extensions::PermissionsData::CanCaptureVisiblePage( |
| 1744 SessionID::IdForTab(web_contents), | 1746 GetExtension(), |
| 1745 &error_)) { | 1747 last_committed_url, |
| 1748 SessionID::IdForTab(web_contents), |
| 1749 &error_)) { |
| 1746 return false; | 1750 return false; |
| 1747 } | 1751 } |
| 1748 | 1752 |
| 1749 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); | 1753 RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); |
| 1750 content::RenderWidgetHostView* view = render_view_host->GetView(); | 1754 content::RenderWidgetHostView* view = render_view_host->GetView(); |
| 1751 if (!view) { | 1755 if (!view) { |
| 1752 error_ = keys::kInternalVisibleTabCaptureError; | 1756 error_ = keys::kInternalVisibleTabCaptureError; |
| 1753 return false; | 1757 return false; |
| 1754 } | 1758 } |
| 1755 render_view_host->CopyFromBackingStore( | 1759 render_view_host->CopyFromBackingStore( |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 } | 1947 } |
| 1944 | 1948 |
| 1945 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() | 1949 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() |
| 1946 : execute_tab_id_(-1) { | 1950 : execute_tab_id_(-1) { |
| 1947 } | 1951 } |
| 1948 | 1952 |
| 1949 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} | 1953 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} |
| 1950 | 1954 |
| 1951 bool ExecuteCodeInTabFunction::HasPermission() { | 1955 bool ExecuteCodeInTabFunction::HasPermission() { |
| 1952 if (Init() && | 1956 if (Init() && |
| 1953 extension_->HasAPIPermissionForTab(execute_tab_id_, | 1957 extensions::PermissionsData::HasAPIPermissionForTab( |
| 1954 extensions::APIPermission::kTab)) { | 1958 extension_, execute_tab_id_, extensions::APIPermission::kTab)) { |
| 1955 return true; | 1959 return true; |
| 1956 } | 1960 } |
| 1957 return ExtensionFunction::HasPermission(); | 1961 return ExtensionFunction::HasPermission(); |
| 1958 } | 1962 } |
| 1959 | 1963 |
| 1960 bool ExecuteCodeInTabFunction::RunImpl() { | 1964 bool ExecuteCodeInTabFunction::RunImpl() { |
| 1961 EXTENSION_FUNCTION_VALIDATE(Init()); | 1965 EXTENSION_FUNCTION_VALIDATE(Init()); |
| 1962 | 1966 |
| 1963 if (!details_->code.get() && !details_->file.get()) { | 1967 if (!details_->code.get() && !details_->file.get()) { |
| 1964 error_ = keys::kNoCodeOrFileToExecuteError; | 1968 error_ = keys::kNoCodeOrFileToExecuteError; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1976 CHECK_GE(execute_tab_id_, 0); | 1980 CHECK_GE(execute_tab_id_, 0); |
| 1977 if (!GetTabById(execute_tab_id_, profile(), | 1981 if (!GetTabById(execute_tab_id_, profile(), |
| 1978 include_incognito(), | 1982 include_incognito(), |
| 1979 NULL, NULL, &contents, NULL, &error_)) { | 1983 NULL, NULL, &contents, NULL, &error_)) { |
| 1980 return false; | 1984 return false; |
| 1981 } | 1985 } |
| 1982 | 1986 |
| 1983 // NOTE: This can give the wrong answer due to race conditions, but it is OK, | 1987 // NOTE: This can give the wrong answer due to race conditions, but it is OK, |
| 1984 // we check again in the renderer. | 1988 // we check again in the renderer. |
| 1985 CHECK(contents); | 1989 CHECK(contents); |
| 1986 if (!GetExtension()->CanExecuteScriptOnPage(contents->GetURL(), | 1990 if (!extensions::PermissionsData::CanExecuteScriptOnPage(GetExtension(), |
| 1987 contents->GetURL(), | 1991 contents->GetURL(), |
| 1988 execute_tab_id_, | 1992 contents->GetURL(), |
| 1989 NULL, | 1993 execute_tab_id_, |
| 1990 &error_)) { | 1994 NULL, |
| 1995 &error_)) { |
| 1991 return false; | 1996 return false; |
| 1992 } | 1997 } |
| 1993 | 1998 |
| 1994 if (details_->code.get()) | 1999 if (details_->code.get()) |
| 1995 return Execute(*details_->code); | 2000 return Execute(*details_->code); |
| 1996 | 2001 |
| 1997 CHECK(details_->file.get()); | 2002 CHECK(details_->file.get()); |
| 1998 resource_ = GetExtension()->GetResource(*details_->file); | 2003 resource_ = GetExtension()->GetResource(*details_->file); |
| 1999 | 2004 |
| 2000 if (resource_.extension_root().empty() || resource_.relative_path().empty()) { | 2005 if (resource_.extension_root().empty() || resource_.relative_path().empty()) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 extension->id(), | 2176 extension->id(), |
| 2172 script_type, | 2177 script_type, |
| 2173 code_string, | 2178 code_string, |
| 2174 frame_scope, | 2179 frame_scope, |
| 2175 run_at, | 2180 run_at, |
| 2176 ScriptExecutor::ISOLATED_WORLD, | 2181 ScriptExecutor::ISOLATED_WORLD, |
| 2177 false /* is_web_view */, | 2182 false /* is_web_view */, |
| 2178 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); | 2183 base::Bind(&ExecuteCodeInTabFunction::OnExecuteCodeFinished, this)); |
| 2179 return true; | 2184 return true; |
| 2180 } | 2185 } |
| OLD | NEW |