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" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 12 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
13 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/sessions/session_id.h" | 15 #include "chrome/browser/sessions/session_tab_helper.h" |
16 #include "chrome/common/extensions/features/feature_channel.h" | 16 #include "chrome/common/extensions/features/feature_channel.h" |
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
20 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/frame_navigate_params.h" | 24 #include "content/public/common/frame_navigate_params.h" |
25 #include "content/public/common/page_transition_types.h" | 25 #include "content/public/common/page_transition_types.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 extension_with_tab_capture(CreateTestExtension("cafebeef", | 77 extension_with_tab_capture(CreateTestExtension("cafebeef", |
78 true, | 78 true, |
79 true)) {} | 79 true)) {} |
80 | 80 |
81 virtual void SetUp() OVERRIDE { | 81 virtual void SetUp() OVERRIDE { |
82 ChromeRenderViewHostTestHarness::SetUp(); | 82 ChromeRenderViewHostTestHarness::SetUp(); |
83 TabHelper::CreateForWebContents(web_contents()); | 83 TabHelper::CreateForWebContents(web_contents()); |
84 } | 84 } |
85 | 85 |
86 int tab_id() { | 86 int tab_id() { |
87 return SessionID::IdForTab(web_contents()); | 87 return SessionTabHelper::IdForTab(web_contents()); |
88 } | 88 } |
89 | 89 |
90 ActiveTabPermissionGranter* active_tab_permission_granter() { | 90 ActiveTabPermissionGranter* active_tab_permission_granter() { |
91 return extensions::TabHelper::FromWebContents(web_contents())-> | 91 return extensions::TabHelper::FromWebContents(web_contents())-> |
92 active_tab_permission_granter(); | 92 active_tab_permission_granter(); |
93 } | 93 } |
94 | 94 |
95 bool IsAllowed(const scoped_refptr<const Extension>& extension, | 95 bool IsAllowed(const scoped_refptr<const Extension>& extension, |
96 const GURL& url) { | 96 const GURL& url) { |
97 return IsAllowed(extension, url, PERMITTED_BOTH, tab_id()); | 97 return IsAllowed(extension, url, PERMITTED_BOTH, tab_id()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, | 144 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, |
145 int tab_id) { | 145 int tab_id) { |
146 return extension->permissions_data()->HasAPIPermissionForTab( | 146 return extension->permissions_data()->HasAPIPermissionForTab( |
147 tab_id, APIPermission::kTab); | 147 tab_id, APIPermission::kTab); |
148 } | 148 } |
149 | 149 |
150 bool IsGrantedForTab(const Extension* extension, | 150 bool IsGrantedForTab(const Extension* extension, |
151 const content::WebContents* web_contents) { | 151 const content::WebContents* web_contents) { |
152 return extension->permissions_data()->HasAPIPermissionForTab( | 152 return extension->permissions_data()->HasAPIPermissionForTab( |
153 SessionID::IdForTab(web_contents), APIPermission::kTab); | 153 SessionTabHelper::IdForTab(web_contents), APIPermission::kTab); |
154 } | 154 } |
155 | 155 |
156 // TODO(justinlin): Remove when tabCapture is moved to stable. | 156 // TODO(justinlin): Remove when tabCapture is moved to stable. |
157 ScopedCurrentChannel current_channel; | 157 ScopedCurrentChannel current_channel; |
158 | 158 |
159 // An extension with the activeTab permission. | 159 // An extension with the activeTab permission. |
160 scoped_refptr<const Extension> extension; | 160 scoped_refptr<const Extension> extension; |
161 | 161 |
162 // Another extension with activeTab (for good measure). | 162 // Another extension with activeTab (for good measure). |
163 scoped_refptr<const Extension> another_extension; | 163 scoped_refptr<const Extension> another_extension; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 EXPECT_TRUE(permissions_data->HasAPIPermissionForTab( | 373 EXPECT_TRUE(permissions_data->HasAPIPermissionForTab( |
374 tab_id(), APIPermission::kTabCaptureForTab)); | 374 tab_id(), APIPermission::kTabCaptureForTab)); |
375 | 375 |
376 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); | 376 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); |
377 EXPECT_FALSE(permissions_data->HasAPIPermissionForTab( | 377 EXPECT_FALSE(permissions_data->HasAPIPermissionForTab( |
378 tab_id() + 1, APIPermission::kTabCaptureForTab)); | 378 tab_id() + 1, APIPermission::kTabCaptureForTab)); |
379 } | 379 } |
380 | 380 |
381 } // namespace | 381 } // namespace |
382 } // namespace extensions | 382 } // namespace extensions |
OLD | NEW |