blob: f00660996cc8627e1aa8a8bc99e315dcf2a05552 [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
Ivan Sandrke2b20c62018-09-10 16:23:538#include <memory>
[email protected]fc5e65d6b2012-06-13 00:22:579#include <set>
10#include <string>
11
avia2f4804a2015-12-24 23:11:1312#include "base/macros.h"
[email protected]01d3a962014-04-11 17:54:0713#include "base/scoped_observer.h"
[email protected]fc5e65d6b2012-06-13 00:22:5714#include "content/public/browser/web_contents_observer.h"
Evan Stade75872a62019-09-06 21:17:3815#include "extensions/browser/extension_registry.h"
[email protected]01d3a962014-04-11 17:54:0716#include "extensions/browser/extension_registry_observer.h"
[email protected]289c44b2013-12-17 03:26:5717#include "extensions/common/extension_set.h"
[email protected]e9f541a2012-11-19 21:52:3118#include "extensions/common/url_pattern_set.h"
[email protected]fc5e65d6b2012-06-13 00:22:5719
[email protected]6c4f0a992012-07-18 07:41:0620class Profile;
21
22namespace content {
23class WebContents;
24}
[email protected]fc5e65d6b2012-06-13 00:22:5725
26namespace extensions {
27
28class Extension;
[email protected]fc5e65d6b2012-06-13 00:22:5729
30// Responsible for granting and revoking tab-specific permissions to extensions
[email protected]70b84c62013-04-18 10:51:5931// with the activeTab or tabCapture permission.
[email protected]01d3a962014-04-11 17:54:0732class ActiveTabPermissionGranter
33 : public content::WebContentsObserver,
34 public extensions::ExtensionRegistryObserver {
[email protected]fc5e65d6b2012-06-13 00:22:5735 public:
isandrk98a3e4a12017-05-26 21:14:5036 // Platform specific delegate.
37 class Delegate {
38 public:
39 virtual ~Delegate() {}
40 // Platform specific check whether the activeTab permission is allowed.
Ivan Sandrkcca3f2d9c2018-06-19 10:53:4441 virtual bool ShouldGrantActiveTabOrPrompt(
42 const Extension* extension,
43 content::WebContents* web_contents) = 0;
isandrk98a3e4a12017-05-26 21:14:5044 };
45
[email protected]78ce3022012-09-24 01:48:4846 ActiveTabPermissionGranter(content::WebContents* web_contents,
[email protected]6c4f0a992012-07-18 07:41:0647 int tab_id,
48 Profile* profile);
dchengae36a4a2014-10-21 12:36:3649 ~ActiveTabPermissionGranter() override;
[email protected]fc5e65d6b2012-06-13 00:22:5750
Ivan Sandrke2b20c62018-09-10 16:23:5351 // Platform specific delegate should be set during startup.
52 static void SetPlatformDelegate(std::unique_ptr<Delegate> delegate);
isandrk98a3e4a12017-05-26 21:14:5053
[email protected]70b84c62013-04-18 10:51:5954 // If |extension| has the activeTab or tabCapture permission, grants
55 // tab-specific permissions to it until the next page navigation or refresh.
[email protected]fc5e65d6b2012-06-13 00:22:5756 void GrantIfRequested(const Extension* extension);
57
rdevlin.cronin9a62870f2016-02-11 23:25:5858 // Clears tab-specific permissions for all extensions. Used only for testing.
59 void RevokeForTesting();
60
[email protected]fc5e65d6b2012-06-13 00:22:5761 private:
[email protected]053ac712013-10-18 19:52:4262 // content::WebContentsObserver implementation.
jamca0cadf02017-02-07 05:16:4863 void DidFinishNavigation(
64 content::NavigationHandle* navigation_handle) override;
dchengae36a4a2014-10-21 12:36:3665 void WebContentsDestroyed() override;
[email protected]053ac712013-10-18 19:52:4266
[email protected]01d3a962014-04-11 17:54:0767 // extensions::ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:3668 void OnExtensionUnloaded(content::BrowserContext* browser_context,
69 const Extension* extension,
limasdf0deef2042017-05-03 19:17:1770 UnloadedExtensionReason reason) override;
[email protected]053ac712013-10-18 19:52:4271
72 // Clears any tab-specific permissions for all extensions on |tab_id_| and
73 // notifies renderers.
74 void ClearActiveExtensionsAndNotify();
[email protected]fc5e65d6b2012-06-13 00:22:5775
[email protected]6c4f0a992012-07-18 07:41:0676 // The tab ID for this tab.
77 int tab_id_;
[email protected]fc5e65d6b2012-06-13 00:22:5778
[email protected]053ac712013-10-18 19:52:4279 // Extensions with the activeTab permission that have been granted
80 // tab-specific permissions until the next navigation/refresh.
81 ExtensionSet granted_extensions_;
[email protected]fc5e65d6b2012-06-13 00:22:5782
[email protected]053ac712013-10-18 19:52:4283 // Listen to extension unloaded notifications.
[email protected]96ac5962014-04-22 19:49:5884 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
Evan Stade75872a62019-09-06 21:17:3885 extension_registry_observer_{this};
[email protected]fc5e65d6b2012-06-13 00:22:5786
[email protected]78ce3022012-09-24 01:48:4887 DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter);
[email protected]fc5e65d6b2012-06-13 00:22:5788};
89
90} // namespace extensions
91
[email protected]78ce3022012-09-24 01:48:4892#endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_