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