Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / extensions / active_tab_permission_granter.h
blobbf51ed046da9e67d4d763af5dd74acb75ccc3a14
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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_
8 #include <set>
9 #include <string>
11 #include "base/scoped_observer.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "extensions/browser/extension_registry_observer.h"
14 #include "extensions/common/extension_set.h"
15 #include "extensions/common/url_pattern_set.h"
17 class Profile;
19 namespace content {
20 class WebContents;
23 namespace extensions {
25 class Extension;
26 class ExtensionRegistry;
28 // Responsible for granting and revoking tab-specific permissions to extensions
29 // with the activeTab or tabCapture permission.
30 class ActiveTabPermissionGranter
31 : public content::WebContentsObserver,
32 public extensions::ExtensionRegistryObserver {
33 public:
34 ActiveTabPermissionGranter(content::WebContents* web_contents,
35 int tab_id,
36 Profile* profile);
37 virtual ~ActiveTabPermissionGranter();
39 // If |extension| has the activeTab or tabCapture permission, grants
40 // tab-specific permissions to it until the next page navigation or refresh.
41 void GrantIfRequested(const Extension* extension);
43 private:
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;
51 // extensions::ExtensionRegistryObserver implementation.
52 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context,
53 const Extension* extension,
54 UnloadedExtensionInfo::Reason reason)
55 OVERRIDE;
57 // Clears any tab-specific permissions for all extensions on |tab_id_| and
58 // notifies renderers.
59 void ClearActiveExtensionsAndNotify();
61 // The tab ID for this tab.
62 int tab_id_;
64 // Extensions with the activeTab permission that have been granted
65 // tab-specific permissions until the next navigation/refresh.
66 ExtensionSet granted_extensions_;
68 // Listen to extension unloaded notifications.
69 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
70 extension_registry_observer_;
72 DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter);
75 } // namespace extensions
77 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_