| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 bool IsAllowed(const scoped_refptr<const Extension>& extension, | 100 bool IsAllowed(const scoped_refptr<const Extension>& extension, |
| 101 const GURL& url, | 101 const GURL& url, |
| 102 PermittedFeature feature) { | 102 PermittedFeature feature) { |
| 103 return IsAllowed(extension, url, feature, tab_id()); | 103 return IsAllowed(extension, url, feature, tab_id()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool IsAllowed(const scoped_refptr<const Extension>& extension, | 106 bool IsAllowed(const scoped_refptr<const Extension>& extension, |
| 107 const GURL& url, | 107 const GURL& url, |
| 108 PermittedFeature feature, | 108 PermittedFeature feature, |
| 109 int tab_id) { | 109 int tab_id) { |
| 110 bool script = PermissionsData::CanExecuteScriptOnPage( | 110 const PermissionsData* permissions_data = |
| 111 extension.get(), url, url, tab_id, NULL, -1, NULL); | 111 PermissionsData::ForExtension(extension); |
| 112 bool script = permissions_data->CanExecuteScriptOnPage( |
| 113 extension, url, url, tab_id, NULL, -1, NULL); |
| 112 bool capture = HasTabsPermission(extension, tab_id) && | 114 bool capture = HasTabsPermission(extension, tab_id) && |
| 113 PermissionsData::CanCaptureVisiblePage(extension.get(), tab_id, NULL); | 115 permissions_data->CanCaptureVisiblePage(tab_id, NULL); |
| 114 switch (feature) { | 116 switch (feature) { |
| 115 case PERMITTED_SCRIPT_ONLY: | 117 case PERMITTED_SCRIPT_ONLY: |
| 116 return script && !capture; | 118 return script && !capture; |
| 117 case PERMITTED_CAPTURE_ONLY: | 119 case PERMITTED_CAPTURE_ONLY: |
| 118 return capture && !script; | 120 return capture && !script; |
| 119 case PERMITTED_BOTH: | 121 case PERMITTED_BOTH: |
| 120 return script && capture; | 122 return script && capture; |
| 121 case PERMITTED_NONE: | 123 case PERMITTED_NONE: |
| 122 return !script && !capture; | 124 return !script && !capture; |
| 123 } | 125 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 135 int tab_id) { | 137 int tab_id) { |
| 136 return IsAllowed(extension, url, PERMITTED_NONE, tab_id); | 138 return IsAllowed(extension, url, PERMITTED_NONE, tab_id); |
| 137 } | 139 } |
| 138 | 140 |
| 139 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) { | 141 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) { |
| 140 return HasTabsPermission(extension, tab_id()); | 142 return HasTabsPermission(extension, tab_id()); |
| 141 } | 143 } |
| 142 | 144 |
| 143 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, | 145 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, |
| 144 int tab_id) { | 146 int tab_id) { |
| 145 return PermissionsData::HasAPIPermissionForTab( | 147 return PermissionsData::ForExtension(extension) |
| 146 extension.get(), tab_id, APIPermission::kTab); | 148 ->HasAPIPermissionForTab(tab_id, APIPermission::kTab); |
| 147 } | 149 } |
| 148 | 150 |
| 149 bool IsGrantedForTab(const Extension* extension, | 151 bool IsGrantedForTab(const Extension* extension, |
| 150 const content::WebContents* web_contents) { | 152 const content::WebContents* web_contents) { |
| 151 return PermissionsData::HasAPIPermissionForTab( | 153 return PermissionsData::ForExtension(extension)->HasAPIPermissionForTab( |
| 152 extension, | 154 SessionID::IdForTab(web_contents), APIPermission::kTab); |
| 153 SessionID::IdForTab(web_contents), | |
| 154 APIPermission::kTab); | |
| 155 } | 155 } |
| 156 | 156 |
| 157 // TODO(justinlin): Remove when tabCapture is moved to stable. | 157 // TODO(justinlin): Remove when tabCapture is moved to stable. |
| 158 ScopedCurrentChannel current_channel; | 158 ScopedCurrentChannel current_channel; |
| 159 | 159 |
| 160 // An extension with the activeTab permission. | 160 // An extension with the activeTab permission. |
| 161 scoped_refptr<const Extension> extension; | 161 scoped_refptr<const Extension> extension; |
| 162 | 162 |
| 163 // Another extension with activeTab (for good measure). | 163 // Another extension with activeTab (for good measure). |
| 164 scoped_refptr<const Extension> another_extension; | 164 scoped_refptr<const Extension> another_extension; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 362 } |
| 363 | 363 |
| 364 TEST_F(ActiveTabTest, ChromeUrlGrants) { | 364 TEST_F(ActiveTabTest, ChromeUrlGrants) { |
| 365 GURL internal("chrome://version"); | 365 GURL internal("chrome://version"); |
| 366 NavigateAndCommit(internal); | 366 NavigateAndCommit(internal); |
| 367 active_tab_permission_granter()->GrantIfRequested( | 367 active_tab_permission_granter()->GrantIfRequested( |
| 368 extension_with_tab_capture.get()); | 368 extension_with_tab_capture.get()); |
| 369 // Do not grant tabs/hosts permissions for tab. | 369 // Do not grant tabs/hosts permissions for tab. |
| 370 EXPECT_TRUE(IsAllowed(extension_with_tab_capture, internal, | 370 EXPECT_TRUE(IsAllowed(extension_with_tab_capture, internal, |
| 371 PERMITTED_CAPTURE_ONLY)); | 371 PERMITTED_CAPTURE_ONLY)); |
| 372 EXPECT_TRUE(PermissionsData::HasAPIPermissionForTab( | 372 const PermissionsData* permissions_data = |
| 373 extension_with_tab_capture.get(), | 373 PermissionsData::ForExtension(extension_with_tab_capture); |
| 374 tab_id(), | 374 EXPECT_TRUE(permissions_data->HasAPIPermissionForTab( |
| 375 APIPermission::kTabCaptureForTab)); | 375 tab_id(), APIPermission::kTabCaptureForTab)); |
| 376 | 376 |
| 377 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); | 377 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); |
| 378 EXPECT_FALSE(PermissionsData::HasAPIPermissionForTab( | 378 EXPECT_FALSE(permissions_data->HasAPIPermissionForTab( |
| 379 extension_with_tab_capture.get(), | 379 tab_id() + 1, APIPermission::kTabCaptureForTab)); |
| 380 tab_id() + 1, | |
| 381 APIPermission::kTabCaptureForTab)); | |
| 382 } | 380 } |
| 383 | 381 |
| 384 } // namespace | 382 } // namespace |
| 385 } // namespace extensions | 383 } // namespace extensions |
| OLD | NEW |