[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_ |
6 | #define CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_ | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 7 | |
8 | #include <set> | ||||
9 | #include <string> | ||||
10 | |||||
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | 01d3a96 | 2014-04-11 17:54:07 | [diff] [blame] | 12 | #include "base/scoped_observer.h" |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 13 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 01d3a96 | 2014-04-11 17:54:07 | [diff] [blame] | 14 | #include "extensions/browser/extension_registry_observer.h" |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 15 | #include "extensions/common/extension_set.h" |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 16 | #include "extensions/common/url_pattern_set.h" |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 17 | |
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 18 | class Profile; |
19 | |||||
20 | namespace content { | ||||
21 | class WebContents; | ||||
22 | } | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 23 | |
24 | namespace extensions { | ||||
25 | |||||
26 | class Extension; | ||||
[email protected] | 01d3a96 | 2014-04-11 17:54:07 | [diff] [blame] | 27 | class ExtensionRegistry; |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 28 | |
29 | // Responsible for granting and revoking tab-specific permissions to extensions | ||||
[email protected] | 70b84c6 | 2013-04-18 10:51:59 | [diff] [blame] | 30 | // with the activeTab or tabCapture permission. |
[email protected] | 01d3a96 | 2014-04-11 17:54:07 | [diff] [blame] | 31 | class ActiveTabPermissionGranter |
32 | : public content::WebContentsObserver, | ||||
33 | public extensions::ExtensionRegistryObserver { | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 34 | public: |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 35 | ActiveTabPermissionGranter(content::WebContents* web_contents, |
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 36 | int tab_id, |
37 | Profile* profile); | ||||
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 38 | ~ActiveTabPermissionGranter() override; |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 39 | |
[email protected] | 70b84c6 | 2013-04-18 10:51:59 | [diff] [blame] | 40 | // If |extension| has the activeTab or tabCapture permission, grants |
41 | // tab-specific permissions to it until the next page navigation or refresh. | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 42 | void GrantIfRequested(const Extension* extension); |
43 | |||||
rdevlin.cronin | 9a62870f | 2016-02-11 23:25:58 | [diff] [blame^] | 44 | // Clears tab-specific permissions for all extensions. Used only for testing. |
45 | void RevokeForTesting(); | ||||
46 | |||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 47 | private: |
[email protected] | 053ac71 | 2013-10-18 19:52:42 | [diff] [blame] | 48 | // content::WebContentsObserver implementation. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 49 | void DidNavigateMainFrame( |
[email protected] | 053ac71 | 2013-10-18 19:52:42 | [diff] [blame] | 50 | const content::LoadCommittedDetails& details, |
mostynb | a15bee1 | 2014-10-04 00:40:32 | [diff] [blame] | 51 | const content::FrameNavigateParams& params) override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 52 | void WebContentsDestroyed() override; |
[email protected] | 053ac71 | 2013-10-18 19:52:42 | [diff] [blame] | 53 | |
[email protected] | 01d3a96 | 2014-04-11 17:54:07 | [diff] [blame] | 54 | // extensions::ExtensionRegistryObserver implementation. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 55 | void OnExtensionUnloaded(content::BrowserContext* browser_context, |
56 | const Extension* extension, | ||||
57 | UnloadedExtensionInfo::Reason reason) override; | ||||
[email protected] | 053ac71 | 2013-10-18 19:52:42 | [diff] [blame] | 58 | |
59 | // Clears any tab-specific permissions for all extensions on |tab_id_| and | ||||
60 | // notifies renderers. | ||||
61 | void ClearActiveExtensionsAndNotify(); | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 62 | |
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 63 | // The tab ID for this tab. |
64 | int tab_id_; | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 65 | |
[email protected] | 053ac71 | 2013-10-18 19:52:42 | [diff] [blame] | 66 | // Extensions with the activeTab permission that have been granted |
67 | // tab-specific permissions until the next navigation/refresh. | ||||
68 | ExtensionSet granted_extensions_; | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 69 | |
[email protected] | 053ac71 | 2013-10-18 19:52:42 | [diff] [blame] | 70 | // Listen to extension unloaded notifications. |
[email protected] | 96ac596 | 2014-04-22 19:49:58 | [diff] [blame] | 71 | ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
72 | extension_registry_observer_; | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 73 | |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter); |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 75 | }; |
76 | |||||
77 | } // namespace extensions | ||||
78 | |||||
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 79 | #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_ |