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

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

Issue 309533007: Refactor PermissionsData pt1 (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::CanExecuteScriptOnPage( 1181 if (!PermissionsData::ForExtension(GetExtension())
1182 GetExtension(), 1182 ->CanExecuteScriptOnPage(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::CanCaptureVisiblePage(GetExtension(), 1507 if (!PermissionsData::ForExtension(GetExtension())
1508 SessionID::IdForTab(contents), 1508 ->CanCaptureVisiblePage(SessionID::IdForTab(contents), &error_)) {
1509 &error_)) {
1510 return NULL; 1509 return NULL;
1511 } 1510 }
1512 return contents; 1511 return contents;
1513 } 1512 }
1514 1513
1515 void TabsCaptureVisibleTabFunction::OnCaptureFailure(FailureReason reason) { 1514 void TabsCaptureVisibleTabFunction::OnCaptureFailure(FailureReason reason) {
1516 error_ = keys::kInternalVisibleTabCaptureError; 1515 error_ = keys::kInternalVisibleTabCaptureError;
1517 SendResponse(false); 1516 SendResponse(false);
1518 } 1517 }
1519 1518
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 Release(); // Balanced in Run() 1614 Release(); // Balanced in Run()
1616 } 1615 }
1617 1616
1618 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction() 1617 ExecuteCodeInTabFunction::ExecuteCodeInTabFunction()
1619 : execute_tab_id_(-1) { 1618 : execute_tab_id_(-1) {
1620 } 1619 }
1621 1620
1622 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {} 1621 ExecuteCodeInTabFunction::~ExecuteCodeInTabFunction() {}
1623 1622
1624 bool ExecuteCodeInTabFunction::HasPermission() { 1623 bool ExecuteCodeInTabFunction::HasPermission() {
1625 if (Init() && PermissionsData::HasAPIPermissionForTab( 1624 if (Init() &&
1626 extension_.get(), execute_tab_id_, APIPermission::kTab)) { 1625 PermissionsData::ForExtension(extension_)
1626 ->HasAPIPermissionForTab(execute_tab_id_, APIPermission::kTab)) {
1627 return true; 1627 return true;
1628 } 1628 }
1629 return ExtensionFunction::HasPermission(); 1629 return ExtensionFunction::HasPermission();
1630 } 1630 }
1631 1631
1632 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() { 1632 bool ExecuteCodeInTabFunction::CanExecuteScriptOnPage() {
1633 content::WebContents* contents = NULL; 1633 content::WebContents* contents = NULL;
1634 1634
1635 // If |tab_id| is specified, look for the tab. Otherwise default to selected 1635 // If |tab_id| is specified, look for the tab. Otherwise default to selected
1636 // tab in the current window. 1636 // tab in the current window.
1637 CHECK_GE(execute_tab_id_, 0); 1637 CHECK_GE(execute_tab_id_, 0);
1638 if (!GetTabById(execute_tab_id_, 1638 if (!GetTabById(execute_tab_id_,
1639 GetProfile(), 1639 GetProfile(),
1640 include_incognito(), 1640 include_incognito(),
1641 NULL, 1641 NULL,
1642 NULL, 1642 NULL,
1643 &contents, 1643 &contents,
1644 NULL, 1644 NULL,
1645 &error_)) { 1645 &error_)) {
1646 return false; 1646 return false;
1647 } 1647 }
1648 1648
1649 CHECK(contents); 1649 CHECK(contents);
1650 1650
1651 // NOTE: This can give the wrong answer due to race conditions, but it is OK, 1651 // NOTE: This can give the wrong answer due to race conditions, but it is OK,
1652 // we check again in the renderer. 1652 // we check again in the renderer.
1653 content::RenderProcessHost* process = contents->GetRenderProcessHost(); 1653 content::RenderProcessHost* process = contents->GetRenderProcessHost();
1654 if (!PermissionsData::CanExecuteScriptOnPage( 1654 if (!PermissionsData::ForExtension(GetExtension())
1655 GetExtension(), 1655 ->CanExecuteScriptOnPage(GetExtension(),
1656 contents->GetURL(), 1656 contents->GetURL(),
1657 contents->GetURL(), 1657 contents->GetURL(),
1658 execute_tab_id_, 1658 execute_tab_id_,
1659 NULL, 1659 NULL,
1660 process ? process->GetID() : -1, 1660 process ? process->GetID() : -1,
1661 &error_)) { 1661 &error_)) {
1662 return false; 1662 return false;
1663 } 1663 }
1664 1664
1665 return true; 1665 return true;
1666 } 1666 }
1667 1667
1668 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() { 1668 ScriptExecutor* ExecuteCodeInTabFunction::GetScriptExecutor() {
1669 Browser* browser = NULL; 1669 Browser* browser = NULL;
1670 content::WebContents* contents = NULL; 1670 content::WebContents* contents = NULL;
1671 1671
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 execute_tab_id_ = tab_id; 1739 execute_tab_id_ = tab_id;
1740 details_ = details.Pass(); 1740 details_ = details.Pass();
1741 return true; 1741 return true;
1742 } 1742 }
1743 1743
1744 bool TabsInsertCSSFunction::ShouldInsertCSS() const { 1744 bool TabsInsertCSSFunction::ShouldInsertCSS() const {
1745 return true; 1745 return true;
1746 } 1746 }
1747 1747
1748 } // namespace extensions 1748 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698