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