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

Side by Side Diff: chrome/browser/extensions/active_tab_unittest.cc

Issue 14651017: Move RuntimeData and related permissions out of Extension class (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_permissions
Patch Set: Latest master Created 7 years, 7 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
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 <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.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/active_tab_permission_granter.h" 11 #include "chrome/browser/extensions/active_tab_permission_granter.h"
12 #include "chrome/browser/extensions/tab_helper.h" 12 #include "chrome/browser/extensions/tab_helper.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sessions/session_id.h" 14 #include "chrome/browser/sessions/session_id.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/extension_builder.h" 17 #include "chrome/common/extensions/extension_builder.h"
18 #include "chrome/common/extensions/features/feature.h" 18 #include "chrome/common/extensions/features/feature.h"
19 #include "chrome/common/extensions/permissions/permissions_data.h"
19 #include "chrome/common/extensions/value_builder.h" 20 #include "chrome/common/extensions/value_builder.h"
20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/navigation_details.h" 23 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/notification_types.h" 26 #include "content/public/browser/notification_types.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/frame_navigate_params.h" 28 #include "content/public/common/frame_navigate_params.h"
28 #include "content/public/common/page_transition_types.h" 29 #include "content/public/common/page_transition_types.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 77 }
77 78
78 bool IsAllowed(const scoped_refptr<const Extension>& extension, 79 bool IsAllowed(const scoped_refptr<const Extension>& extension,
79 const GURL& url) { 80 const GURL& url) {
80 return IsAllowed(extension, url, tab_id()); 81 return IsAllowed(extension, url, tab_id());
81 } 82 }
82 83
83 bool IsAllowed(const scoped_refptr<const Extension>& extension, 84 bool IsAllowed(const scoped_refptr<const Extension>& extension,
84 const GURL& url, 85 const GURL& url,
85 int tab_id) { 86 int tab_id) {
86 return extension->CanExecuteScriptOnPage(url, url, tab_id, NULL, NULL) && 87 return PermissionsData::CanExecuteScriptOnPage(
87 extension->CanCaptureVisiblePage(url, tab_id, NULL) && 88 extension, url, url, tab_id, NULL, NULL) &&
89 PermissionsData::CanCaptureVisiblePage(
90 extension, url, tab_id, NULL) &&
88 HasTabsPermission(extension, tab_id); 91 HasTabsPermission(extension, tab_id);
89 } 92 }
90 93
91 bool IsBlocked(const scoped_refptr<const Extension>& extension, 94 bool IsBlocked(const scoped_refptr<const Extension>& extension,
92 const GURL& url) { 95 const GURL& url) {
93 return IsBlocked(extension, url, tab_id()); 96 return IsBlocked(extension, url, tab_id());
94 } 97 }
95 98
96 bool IsBlocked(const scoped_refptr<const Extension>& extension, 99 bool IsBlocked(const scoped_refptr<const Extension>& extension,
97 const GURL& url, 100 const GURL& url,
98 int tab_id) { 101 int tab_id) {
99 // Note: can't check HasTabsPermission because it isn't URL specific. 102 // Note: can't check HasTabsPermission because it isn't URL specific.
100 return !extension->CanExecuteScriptOnPage(url, url, tab_id, NULL, NULL) && 103 return !PermissionsData::CanExecuteScriptOnPage(
101 !extension->CanCaptureVisiblePage(url, tab_id, NULL); 104 extension, url, url, tab_id, NULL, NULL) &&
105 !PermissionsData::CanCaptureVisiblePage(
106 extension, url, tab_id, NULL);
102 } 107 }
103 108
104 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) { 109 bool HasTabsPermission(const scoped_refptr<const Extension>& extension) {
105 return HasTabsPermission(extension, tab_id()); 110 return HasTabsPermission(extension, tab_id());
106 } 111 }
107 112
108 bool HasTabsPermission(const scoped_refptr<const Extension>& extension, 113 bool HasTabsPermission(const scoped_refptr<const Extension>& extension,
109 int tab_id) { 114 int tab_id) {
110 return extension->HasAPIPermissionForTab(tab_id, APIPermission::kTab); 115 return PermissionsData::HasAPIPermissionForTab(
116 extension.get(), tab_id, APIPermission::kTab);
111 } 117 }
112 118
113 // An extension with the activeTab permission. 119 // An extension with the activeTab permission.
114 scoped_refptr<const Extension> extension; 120 scoped_refptr<const Extension> extension;
115 121
116 // Another extension with activeTab (for good measure). 122 // Another extension with activeTab (for good measure).
117 scoped_refptr<const Extension> another_extension; 123 scoped_refptr<const Extension> another_extension;
118 124
119 // An extension without the activeTab permission. 125 // An extension without the activeTab permission.
120 scoped_refptr<const Extension> extension_without_active_tab; 126 scoped_refptr<const Extension> extension_without_active_tab;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 Reload(); 320 Reload();
315 321
316 EXPECT_FALSE(IsAllowed(extension, google, tab_id())); 322 EXPECT_FALSE(IsAllowed(extension, google, tab_id()));
317 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id())); 323 EXPECT_FALSE(IsAllowed(extension, google_h1, tab_id()));
318 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id())); 324 EXPECT_FALSE(IsAllowed(extension, chromium, tab_id()));
319 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id())); 325 EXPECT_FALSE(IsAllowed(extension, chromium_h1, tab_id()));
320 } 326 }
321 327
322 } // namespace 328 } // namespace
323 } // namespace extensions 329 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/active_tab_permission_granter.cc ('k') | chrome/browser/extensions/api/bluetooth/bluetooth_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698