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 "chrome/browser/extensions/active_tab_permission_manager.h" | 5 #include "chrome/browser/extensions/active_tab_permission_manager.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/extensions/extension_system.h" | 8 #include "chrome/browser/extensions/extension_system.h" |
9 #include "chrome/browser/extensions/extension_tab_helper.h" | 9 #include "chrome/browser/extensions/extension_tab_helper.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/extension_messages.h" | 14 #include "chrome/common/extensions/extension_messages.h" |
15 #include "chrome/common/extensions/extension_permission_set.h" | 15 #include "chrome/common/extensions/permissions/permission_set.h" |
16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
20 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 | 22 |
23 using content::RenderProcessHost; | 23 using content::RenderProcessHost; |
24 using content::WebContentsObserver; | 24 using content::WebContentsObserver; |
| 25 using extensions::APIPermission; |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 | 28 |
28 ActiveTabPermissionManager::ActiveTabPermissionManager( | 29 ActiveTabPermissionManager::ActiveTabPermissionManager( |
29 TabContents* tab_contents) | 30 TabContents* tab_contents) |
30 : WebContentsObserver(tab_contents->web_contents()), | 31 : WebContentsObserver(tab_contents->web_contents()), |
31 tab_contents_(tab_contents) { | 32 tab_contents_(tab_contents) { |
32 InsertActiveURL(web_contents()->GetURL()); | 33 InsertActiveURL(web_contents()->GetURL()); |
33 registrar_.Add(this, | 34 registrar_.Add(this, |
34 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 35 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
35 content::Source<Profile>(tab_contents->profile())); | 36 content::Source<Profile>(tab_contents->profile())); |
36 } | 37 } |
37 | 38 |
38 ActiveTabPermissionManager::~ActiveTabPermissionManager() {} | 39 ActiveTabPermissionManager::~ActiveTabPermissionManager() {} |
39 | 40 |
40 void ActiveTabPermissionManager::GrantIfRequested(const Extension* extension) { | 41 void ActiveTabPermissionManager::GrantIfRequested(const Extension* extension) { |
41 if (!extension->HasAPIPermission(ExtensionAPIPermission::kActiveTab)) | 42 if (!extension->HasAPIPermission(APIPermission::kActiveTab)) |
42 return; | 43 return; |
43 | 44 |
44 if (active_urls_.is_empty()) | 45 if (active_urls_.is_empty()) |
45 return; | 46 return; |
46 | 47 |
47 // Only need to check the number of permissions here rather than the URLs | 48 // Only need to check the number of permissions here rather than the URLs |
48 // themselves, because the set can only ever grow. | 49 // themselves, because the set can only ever grow. |
49 const URLPatternSet* old_permissions = | 50 const URLPatternSet* old_permissions = |
50 extension->GetTabSpecificHostPermissions(tab_id()); | 51 extension->GetTabSpecificHostPermissions(tab_id()); |
51 if (old_permissions && (old_permissions->size() == active_urls_.size())) | 52 if (old_permissions && (old_permissions->size() == active_urls_.size())) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 int32 ActiveTabPermissionManager::tab_id() { | 125 int32 ActiveTabPermissionManager::tab_id() { |
125 return tab_contents_->extension_tab_helper()->tab_id(); | 126 return tab_contents_->extension_tab_helper()->tab_id(); |
126 } | 127 } |
127 | 128 |
128 int32 ActiveTabPermissionManager::GetPageID() { | 129 int32 ActiveTabPermissionManager::GetPageID() { |
129 return tab_contents_->web_contents()->GetController().GetActiveEntry()-> | 130 return tab_contents_->web_contents()->GetController().GetActiveEntry()-> |
130 GetPageID(); | 131 GetPageID(); |
131 } | 132 } |
132 | 133 |
133 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |