blob: bf51ed046da9e67d4d763af5dd74acb75ccc3a14 [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
[email protected]01d3a962014-04-11 17:54:0711#include "base/scoped_observer.h"
[email protected]fc5e65d6b2012-06-13 00:22:5712#include "content/public/browser/web_contents_observer.h"
[email protected]01d3a962014-04-11 17:54:0713#include "extensions/browser/extension_registry_observer.h"
[email protected]289c44b2013-12-17 03:26:5714#include "extensions/common/extension_set.h"
[email protected]e9f541a2012-11-19 21:52:3115#include "extensions/common/url_pattern_set.h"
[email protected]fc5e65d6b2012-06-13 00:22:5716
[email protected]6c4f0a992012-07-18 07:41:0617class Profile;
18
19namespace content {
20class WebContents;
21}
[email protected]fc5e65d6b2012-06-13 00:22:5722
23namespace extensions {
24
25class Extension;
[email protected]01d3a962014-04-11 17:54:0726class ExtensionRegistry;
[email protected]fc5e65d6b2012-06-13 00:22:5727
28// Responsible for granting and revoking tab-specific permissions to extensions
[email protected]70b84c62013-04-18 10:51:5929// with the activeTab or tabCapture permission.
[email protected]01d3a962014-04-11 17:54:0730class ActiveTabPermissionGranter
31 : public content::WebContentsObserver,
32 public extensions::ExtensionRegistryObserver {
[email protected]fc5e65d6b2012-06-13 00:22:5733 public:
[email protected]78ce3022012-09-24 01:48:4834 ActiveTabPermissionGranter(content::WebContents* web_contents,
[email protected]6c4f0a992012-07-18 07:41:0635 int tab_id,
36 Profile* profile);
[email protected]78ce3022012-09-24 01:48:4837 virtual ~ActiveTabPermissionGranter();
[email protected]fc5e65d6b2012-06-13 00:22:5738
[email protected]70b84c62013-04-18 10:51:5939 // If |extension| has the activeTab or tabCapture permission, grants
40 // tab-specific permissions to it until the next page navigation or refresh.
[email protected]fc5e65d6b2012-06-13 00:22:5741 void GrantIfRequested(const Extension* extension);
42
[email protected]fc5e65d6b2012-06-13 00:22:5743 private:
[email protected]053ac712013-10-18 19:52:4244 // 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;
50
[email protected]01d3a962014-04-11 17:54:0751 // extensions::ExtensionRegistryObserver implementation.
52 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context,
[email protected]e51232f32014-04-18 20:05:3653 const Extension* extension,
54 UnloadedExtensionInfo::Reason reason)
55 OVERRIDE;
[email protected]053ac712013-10-18 19:52:4256
57 // Clears any tab-specific permissions for all extensions on |tab_id_| and
58 // notifies renderers.
59 void ClearActiveExtensionsAndNotify();
[email protected]fc5e65d6b2012-06-13 00:22:5760
[email protected]6c4f0a992012-07-18 07:41:0661 // The tab ID for this tab.
62 int tab_id_;
[email protected]fc5e65d6b2012-06-13 00:22:5763
[email protected]053ac712013-10-18 19:52:4264 // Extensions with the activeTab permission that have been granted
65 // tab-specific permissions until the next navigation/refresh.
66 ExtensionSet granted_extensions_;
[email protected]fc5e65d6b2012-06-13 00:22:5767
[email protected]053ac712013-10-18 19:52:4268 // Listen to extension unloaded notifications.
[email protected]96ac5962014-04-22 19:49:5869 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
70 extension_registry_observer_;
[email protected]fc5e65d6b2012-06-13 00:22:5771
[email protected]78ce3022012-09-24 01:48:4872 DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranter);
[email protected]fc5e65d6b2012-06-13 00:22:5773};
74
75} // namespace extensions
76
[email protected]78ce3022012-09-24 01:48:4877#endif // CHROME_BROWSER_EXTENSIONS_ACTIVE_TAB_PERMISSION_GRANTER_H_