[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 | |||||
11 | #include "chrome/common/extensions/extension_set.h" | ||||
12 | #include "chrome/common/extensions/url_pattern_set.h" | ||||
13 | #include "content/public/browser/notification_observer.h" | ||||
14 | #include "content/public/browser/notification_registrar.h" | ||||
15 | #include "content/public/browser/web_contents_observer.h" | ||||
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; | ||||
26 | |||||
27 | // Responsible for granting and revoking tab-specific permissions to extensions | ||||
28 | // with the activeTab permission. | ||||
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame^] | 29 | class ActiveTabPermissionGranter : public content::WebContentsObserver, |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 30 | public content::NotificationObserver { |
31 | public: | ||||
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame^] | 32 | ActiveTabPermissionGranter(content::WebContents* web_contents, |
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 33 | int tab_id, |
34 | Profile* profile); | ||||
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame^] | 35 | virtual ~ActiveTabPermissionGranter(); |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 36 | |
37 | // If |extension| has the activeTab permission, grants tab-specific | ||||
38 | // permissions to it until the next page navigation or refresh. | ||||
39 | void GrantIfRequested(const Extension* extension); | ||||
40 | |||||
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 41 | // Returns true if |extension| has been granted tab-specific permissions |
42 | // for this tab. | ||||
43 | bool IsGranted(const Extension* extension); | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 44 | |
45 | private: | ||||
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 46 | // content::WebContentsObserver implementation. |
47 | virtual void DidNavigateMainFrame( | ||||
48 | const content::LoadCommittedDetails& details, | ||||
49 | const content::FrameNavigateParams& params) OVERRIDE; | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 50 | virtual void WebContentsDestroyed(content::WebContents* web_contents) |
51 | OVERRIDE; | ||||
52 | |||||
53 | // content::NotificationObserver implementation. | ||||
54 | virtual void Observe(int type, | ||||
55 | const content::NotificationSource& source, | ||||
56 | const content::NotificationDetails& details) OVERRIDE; | ||||
57 | |||||
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 58 | // Clears any tab-specific permissions for all extensions on |tab_id_| and |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 59 | // notifies renderers. |
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 60 | void ClearActiveExtensionsAndNotify(); |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 61 | |
62 | // Gets the current page id. | ||||
63 | int32 GetPageID(); | ||||
64 | |||||
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 65 | // The tab ID for this tab. |
66 | int tab_id_; | ||||
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 67 | |
68 | // Extensions with the activeTab permission that have been granted | ||||
69 | // tab-specific permissions until the next navigation/refresh. | ||||
[email protected] | 6c4f0a99 | 2012-07-18 07:41:06 | [diff] [blame] | 70 | ExtensionSet granted_extensions_; |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 71 | |
72 | // Listen to extension unloaded notifications. | ||||
73 | content::NotificationRegistrar registrar_; | ||||
74 | |||||
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame^] | 75 | DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter); |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 76 | }; |
77 | |||||
78 | } // namespace extensions | ||||
79 | |||||
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame^] | 80 | #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_ |