Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 315573003: Remove PermissionsData::ForExtension() completely (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 // Don't let the extension crash the browser or renderers. 1171 // Don't let the extension crash the browser or renderers.
1172 if (ExtensionTabUtil::IsCrashURL(url)) { 1172 if (ExtensionTabUtil::IsCrashURL(url)) {
1173 error_ = keys::kNoCrashBrowserError; 1173 error_ = keys::kNoCrashBrowserError;
1174 return false; 1174 return false;
1175 } 1175 }
1176 1176
1177 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so 1177 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so
1178 // we need to check host permissions before allowing them. 1178 // we need to check host permissions before allowing them.
1179 if (url.SchemeIs(url::kJavaScriptScheme)) { 1179 if (url.SchemeIs(url::kJavaScriptScheme)) {
1180 content::RenderProcessHost* process = web_contents_->GetRenderProcessHost(); 1180 content::RenderProcessHost* process = web_contents_->GetRenderProcessHost();
1181 if (!PermissionsData::ForExtension(GetExtension()) 1181 if (!GetExtension()->permissions_data()->CanExecuteScriptOnPage(
1182 ->CanExecuteScriptOnPage(GetExtension(), 1182 GetExtension(),
1183 web_contents_->GetURL(), 1183 web_contents_->GetURL(),
1184 web_contents_->GetURL(), 1184 web_contents_->GetURL(),
1185 tab_id, 1185 tab_id,
1186 NULL, 1186 NULL,
1187 process ? process->GetID() : -1, 1187 process ? process->GetID() : -1,
1188 &error_)) { 1188 &error_)) {
1189 return false; 1189 return false;
1190 } 1190 }
1191 1191
1192 TabHelper::FromWebContents(web_contents_)->script_executor()->ExecuteScript( 1192 TabHelper::FromWebContents(web_contents_)->script_executor()->ExecuteScript(
1193 extension_id(), 1193 extension_id(),
1194 ScriptExecutor::JAVASCRIPT, 1194 ScriptExecutor::JAVASCRIPT,
1195 url.GetContent(), 1195 url.GetContent(),
1196 ScriptExecutor::TOP_FRAME, 1196 ScriptExecutor::TOP_FRAME,
1197 ScriptExecutor::DONT_MATCH_ABOUT_BLANK, 1197 ScriptExecutor::DONT_MATCH_ABOUT_BLANK,
1198 UserScript::DOCUMENT_IDLE, 1198 UserScript::DOCUMENT_IDLE,
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 Browser* browser = NULL; 1497 Browser* browser = NULL;
1498 if (!GetBrowserFromWindowID(this, window_id, &browser)) 1498 if (!GetBrowserFromWindowID(this, window_id, &browser))
1499 return NULL; 1499 return NULL;
1500 1500
1501 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents(); 1501 WebContents* contents = browser->tab_strip_model()->GetActiveWebContents();
1502 if (!contents) { 1502 if (!contents) {
1503 error_ = keys::kInternalVisibleTabCaptureError; 1503 error_ = keys::kInternalVisibleTabCaptureError;
1504 return NULL; 1504 return NULL;
1505 } 1505 }
1506 1506
1507 if (!PermissionsData::ForExtension(GetExtension()) 1507 if (!GetExtension()->permissions_data()->CanCaptureVisiblePage(
1508 ->CanCaptureVisiblePage(SessionID::IdForTab(contents), &error_)) { 1508 SessionID::IdForTab(contents), &error_)) {
1509 return NULL; 1509 return NULL;
1510 } 1510 }
1511 return contents; 1511 return contents;
1512 } 1512 }
1513 1513
1514 void TabsCaptureVisibleTabFunction::OnCaptureFailure(FailureReason reason) { 1514 void TabsCaptureVisibleTabFunction::OnCaptureFailure(FailureReason reason) {
1515 error_ = keys::kInternalVisibleTabCaptureError; 1515 error_ = keys::kInternalVisibleTabCaptureError;
1516 SendResponse(false); 1516 SendResponse(false);
1517 } 1517 }
1518 1518
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 } 1620 }
1621 1621
1622 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() 1622 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
1623 : execute_tab_id_(-1) { 1623 : execute_tab_id_(-1) {
1624 } 1624 }
1625 1625
1626 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} 1626 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {}
1627 1627
1628 bool ExecuteCodeInTabFunction::HasPermission() { 1628 bool ExecuteCodeInTabFunction::HasPermission() {
1629 if (Init() && 1629 if (Init() &&
1630 PermissionsData::ForExtension(extension_) 1630 extension_->permissions_data()->HasAPIPermissionForTab(
1631 ->HasAPIPermissionForTab(execute_tab_id_, APIPermission::kTab)) { 1631 execute_tab_id_, APIPermission::kTab)) {
1632 return true; 1632 return true;
1633 } 1633 }
1634 return ExtensionFunction::HasPermission(); 1634 return ExtensionFunction::HasPermission();
1635 } 1635 }
1636 1636
1637 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { 1637 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() {
1638 content::WebContents* contents = NULL; 1638 content::WebContents* contents = NULL;
1639 1639
1640 // If |tab_id| is specified, look for the tab. Otherwise default to selected 1640 // If |tab_id| is specified, look for the tab. Otherwise default to selected
1641 // tab in the current window. 1641 // tab in the current window.
1642 CHECK_GE(execute_tab_id_, 0); 1642 CHECK_GE(execute_tab_id_, 0);
1643 if (!GetTabById(execute_tab_id_, 1643 if (!GetTabById(execute_tab_id_,
1644 GetProfile(), 1644 GetProfile(),
1645 include_incognito(), 1645 include_incognito(),
1646 NULL, 1646 NULL,
1647 NULL, 1647 NULL,
1648 &contents, 1648 &contents,
1649 NULL, 1649 NULL,
1650 &error_)) { 1650 &error_)) {
1651 return false; 1651 return false;
1652 } 1652 }
1653 1653
1654 CHECK(contents); 1654 CHECK(contents);
1655 1655
1656 // NOTE: This can give the wrong answer due to race conditions, but it is OK, 1656 // NOTE: This can give the wrong answer due to race conditions, but it is OK,
1657 // we check again in the renderer. 1657 // we check again in the renderer.
1658 content::RenderProcessHost* process = contents->GetRenderProcessHost(); 1658 content::RenderProcessHost* process = contents->GetRenderProcessHost();
1659 if (!PermissionsData::ForExtension(GetExtension()) 1659 if (!GetExtension()->permissions_data()->CanExecuteScriptOnPage(
1660 ->CanExecuteScriptOnPage(GetExtension(), 1660 GetExtension(),
1661 contents->GetURL(), 1661 contents->GetURL(),
1662 contents->GetURL(), 1662 contents->GetURL(),
1663 execute_tab_id_, 1663 execute_tab_id_,
1664 NULL, 1664 NULL,
1665 process ? process->GetID() : -1, 1665 process ? process->GetID() : -1,
1666 &error_)) { 1666 &error_)) {
1667 return false; 1667 return false;
1668 } 1668 }
1669 1669
1670 return true; 1670 return true;
1671 } 1671 }
1672 1672
1673 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { 1673 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() {
1674 Browser* browser = NULL; 1674 Browser* browser = NULL;
1675 content::WebContents* contents = NULL; 1675 content::WebContents* contents = NULL;
1676 1676
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 execute_tab_id_ = tab_id; 1744 execute_tab_id_ = tab_id;
1745 details_ = details.Pass(); 1745 details_ = details.Pass();
1746 return true; 1746 return true;
1747 } 1747 }
1748 1748
1749 bool TabsInsertCSSFunction::ShouldInsertCSS() const { 1749 bool TabsInsertCSSFunction::ShouldInsertCSS() const {
1750 return true; 1750 return true;
1751 } 1751 }
1752 1752
1753 } // namespace extensions 1753 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698