Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / active_tab_permission_granter.h
blob07d7154ce3e264e602e3e84b4e31477e3b7b5dff
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 "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "content/public/browser/web_contents_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;
27 // Responsible for granting and revoking tab-specific permissions to extensions
28 // with the activeTab or tabCapture permission.
29 class ActiveTabPermissionGranter : public content::WebContentsObserver,
30 public content::NotificationObserver {
31 public:
32 ActiveTabPermissionGranter(content::WebContents* web_contents,
33 int tab_id,
34 Profile* profile);
35 virtual ~ActiveTabPermissionGranter();
37 // If |extension| has the activeTab or tabCapture permission, grants
38 // tab-specific permissions to it until the next page navigation or refresh.
39 void GrantIfRequested(const Extension* extension);
41 private:
42 // content::WebContentsObserver implementation.
43 virtual void DidNavigateMainFrame(
44 const content::LoadCommittedDetails& details,
45 const content::FrameNavigateParams& params) OVERRIDE;
46 virtual void WebContentsDestroyed(content::WebContents* web_contents)
47 OVERRIDE;
49 // content::NotificationObserver implementation.
50 virtual void Observe(int type,
51 const content::NotificationSource& source,
52 const content::NotificationDetails& details) OVERRIDE;
54 // Clears any tab-specific permissions for all extensions on |tab_id_| and
55 // notifies renderers.
56 void ClearActiveExtensionsAndNotify();
58 // The tab ID for this tab.
59 int tab_id_;
61 // Extensions with the activeTab permission that have been granted
62 // tab-specific permissions until the next navigation/refresh.
63 ExtensionSet granted_extensions_;
65 // Listen to extension unloaded notifications.
66 content::NotificationRegistrar registrar_;
68 DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter);
71 } // namespace extensions
73 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_