blob: e71b0cb8aa1d07c086a0af964ca562fd9deda2fe [file] [log] [blame]
[email protected]fc5e65d6b2012-06-13 00:22:571// 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]78ce3022012-09-24 01:48:485#ifndef CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_
6#define CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_
[email protected]fc5e65d6b2012-06-13 00:22:577
8#include <set>
9#include <string>
10
avia2f4804a2015-12-24 23:11:1311#include "base/macros.h"
[email protected]01d3a962014-04-11 17:54:0712#include "base/scoped_observer.h"
[email protected]fc5e65d6b2012-06-13 00:22:5713#include "content/public/browser/web_contents_observer.h"
[email protected]01d3a962014-04-11 17:54:0714#include "extensions/browser/extension_registry_observer.h"
[email protected]289c44b2013-12-17 03:26:5715#include "extensions/common/extension_set.h"
[email protected]e9f541a2012-11-19 21:52:3116#include "extensions/common/url_pattern_set.h"
[email protected]fc5e65d6b2012-06-13 00:22:5717
[email protected]6c4f0a992012-07-18 07:41:0618class Profile;
19
20namespace content {
21class WebContents;
22}
[email protected]fc5e65d6b2012-06-13 00:22:5723
24namespace extensions {
25
26class Extension;
[email protected]01d3a962014-04-11 17:54:0727class ExtensionRegistry;
[email protected]fc5e65d6b2012-06-13 00:22:5728
29// Responsible for granting and revoking tab-specific permissions to extensions
[email protected]70b84c62013-04-18 10:51:5930// with the activeTab or tabCapture permission.
[email protected]01d3a962014-04-11 17:54:0731class ActiveTabPermissionGranter
32 : public content::WebContentsObserver,
33 public extensions::ExtensionRegistryObserver {
[email protected]fc5e65d6b2012-06-13 00:22:5734 public:
[email protected]78ce3022012-09-24 01:48:4835 ActiveTabPermissionGranter(content::WebContents* web_contents,
[email protected]6c4f0a992012-07-18 07:41:0636 int tab_id,
37 Profile* profile);
dchengae36a4a2014-10-21 12:36:3638 ~ActiveTabPermissionGranter() override;
[email protected]fc5e65d6b2012-06-13 00:22:5739
[email protected]70b84c62013-04-18 10:51:5940 // If |extension| has the activeTab or tabCapture permission, grants
41 // tab-specific permissions to it until the next page navigation or refresh.
[email protected]fc5e65d6b2012-06-13 00:22:5742 void GrantIfRequested(const Extension* extension);
43
rdevlin.cronin9a62870f2016-02-11 23:25:5844 // Clears tab-specific permissions for all extensions. Used only for testing.
45 void RevokeForTesting();
46
[email protected]fc5e65d6b2012-06-13 00:22:5747 private:
[email protected]053ac712013-10-18 19:52:4248 // content::WebContentsObserver implementation.
dchengae36a4a2014-10-21 12:36:3649 void DidNavigateMainFrame(
[email protected]053ac712013-10-18 19:52:4250 const content::LoadCommittedDetails& details,
mostynba15bee12014-10-04 00:40:3251 const content::FrameNavigateParams& params) override;
dchengae36a4a2014-10-21 12:36:3652 void WebContentsDestroyed() override;
[email protected]053ac712013-10-18 19:52:4253
[email protected]01d3a962014-04-11 17:54:0754 // extensions::ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:3655 void OnExtensionUnloaded(content::BrowserContext* browser_context,
56 const Extension* extension,
57 UnloadedExtensionInfo::Reason reason) override;
[email protected]053ac712013-10-18 19:52:4258
59 // Clears any tab-specific permissions for all extensions on |tab_id_| and
60 // notifies renderers.
61 void ClearActiveExtensionsAndNotify();
[email protected]fc5e65d6b2012-06-13 00:22:5762
[email protected]6c4f0a992012-07-18 07:41:0663 // The tab ID for this tab.
64 int tab_id_;
[email protected]fc5e65d6b2012-06-13 00:22:5765
[email protected]053ac712013-10-18 19:52:4266 // Extensions with the activeTab permission that have been granted
67 // tab-specific permissions until the next navigation/refresh.
68 ExtensionSet granted_extensions_;
[email protected]fc5e65d6b2012-06-13 00:22:5769
[email protected]053ac712013-10-18 19:52:4270 // Listen to extension unloaded notifications.
[email protected]96ac5962014-04-22 19:49:5871 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
72 extension_registry_observer_;
[email protected]fc5e65d6b2012-06-13 00:22:5773
[email protected]78ce3022012-09-24 01:48:4874 DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter);
[email protected]fc5e65d6b2012-06-13 00:22:5775};
76
77} // namespace extensions
78
[email protected]78ce3022012-09-24 01:48:4879#endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_