| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 PermittedFeature feature) { | 101 PermittedFeature feature) { |
| 102 return IsAllowed(extension, url, feature, tab_id()); | 102 return IsAllowed(extension, url, feature, tab_id()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool IsAllowed(const scoped_refptr<const Extension>& extension, | 105 bool IsAllowed(const scoped_refptr<const Extension>& extension, |
| 106 const GURL& url, | 106 const GURL& url, |
| 107 PermittedFeature feature, | 107 PermittedFeature feature, |
| 108 int tab_id) { | 108 int tab_id) { |
| 109 const PermissionsData* permissions_data = extension->permissions_data(); | 109 const PermissionsData* permissions_data = extension->permissions_data(); |
| 110 bool script = permissions_data->CanAccessPage( | 110 bool script = permissions_data->CanAccessPage( |
| 111 extension.get(), url, url, tab_id, -1, NULL); | 111 extension.get(), url, tab_id, -1, NULL); |
| 112 bool capture = HasTabsPermission(extension, tab_id) && | 112 bool capture = HasTabsPermission(extension, tab_id) && |
| 113 permissions_data->CanCaptureVisiblePage(tab_id, NULL); | 113 permissions_data->CanCaptureVisiblePage(tab_id, NULL); |
| 114 switch (feature) { | 114 switch (feature) { |
| 115 case PERMITTED_SCRIPT_ONLY: | 115 case PERMITTED_SCRIPT_ONLY: |
| 116 return script && !capture; | 116 return script && !capture; |
| 117 case PERMITTED_CAPTURE_ONLY: | 117 case PERMITTED_CAPTURE_ONLY: |
| 118 return capture && !script; | 118 return capture && !script; |
| 119 case PERMITTED_BOTH: | 119 case PERMITTED_BOTH: |
| 120 return script && capture; | 120 return script && capture; |
| 121 case PERMITTED_NONE: | 121 case PERMITTED_NONE: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 active_tab_permission_granter()->GrantIfRequested( | 269 active_tab_permission_granter()->GrantIfRequested( |
| 270 extension_without_active_tab.get()); | 270 extension_without_active_tab.get()); |
| 271 | 271 |
| 272 EXPECT_TRUE(IsAllowed(extension, google)); | 272 EXPECT_TRUE(IsAllowed(extension, google)); |
| 273 EXPECT_TRUE(IsAllowed(another_extension, google)); | 273 EXPECT_TRUE(IsAllowed(another_extension, google)); |
| 274 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); | 274 EXPECT_TRUE(IsBlocked(extension_without_active_tab, google)); |
| 275 | 275 |
| 276 EXPECT_TRUE(IsAllowed(extension, chromium, PERMITTED_CAPTURE_ONLY)); | 276 EXPECT_TRUE(IsAllowed(extension, chromium, PERMITTED_CAPTURE_ONLY)); |
| 277 EXPECT_TRUE(IsAllowed(another_extension, chromium, PERMITTED_CAPTURE_ONLY)); | 277 EXPECT_TRUE(IsAllowed(another_extension, chromium, PERMITTED_CAPTURE_ONLY)); |
| 278 EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium)); | 278 EXPECT_TRUE(IsBlocked(extension_without_active_tab, chromium)); |
| 279 }; | 279 } |
| 280 | 280 |
| 281 TEST_F(ActiveTabTest, Uninstalling) { | 281 TEST_F(ActiveTabTest, Uninstalling) { |
| 282 // Some semi-arbitrary setup. | 282 // Some semi-arbitrary setup. |
| 283 GURL google("http://www.google.com"); | 283 GURL google("http://www.google.com"); |
| 284 NavigateAndCommit(google); | 284 NavigateAndCommit(google); |
| 285 | 285 |
| 286 active_tab_permission_granter()->GrantIfRequested(extension.get()); | 286 active_tab_permission_granter()->GrantIfRequested(extension.get()); |
| 287 | 287 |
| 288 EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents())); | 288 EXPECT_TRUE(IsGrantedForTab(extension.get(), web_contents())); |
| 289 EXPECT_TRUE(IsAllowed(extension, google)); | 289 EXPECT_TRUE(IsAllowed(extension, google)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 EXPECT_TRUE(permissions_data->HasAPIPermissionForTab( | 372 EXPECT_TRUE(permissions_data->HasAPIPermissionForTab( |
| 373 tab_id(), APIPermission::kTabCaptureForTab)); | 373 tab_id(), APIPermission::kTabCaptureForTab)); |
| 374 | 374 |
| 375 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); | 375 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); |
| 376 EXPECT_FALSE(permissions_data->HasAPIPermissionForTab( | 376 EXPECT_FALSE(permissions_data->HasAPIPermissionForTab( |
| 377 tab_id() + 1, APIPermission::kTabCaptureForTab)); | 377 tab_id() + 1, APIPermission::kTabCaptureForTab)); |
| 378 } | 378 } |
| 379 | 379 |
| 380 } // namespace | 380 } // namespace |
| 381 } // namespace extensions | 381 } // namespace extensions |
| OLD | NEW |